diff options
| author | Austin Clements <austin@google.com> | 2025-06-10 19:19:34 -0400 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2025-11-18 11:46:42 -0800 |
| commit | 8c41a482f9b7a101404cd0b417ac45abd441e598 (patch) | |
| tree | 17aeaf136352e9e8fd1bfd2c2e49441f03d7cf36 /src/runtime | |
| parent | e912618bd2de2121d6c9fed3473b5e0a47da138c (diff) | |
| download | go-8c41a482f9b7a101404cd0b417ac45abd441e598.tar.xz | |
runtime: add dlog.hexdump
Change-Id: I8149ab9314216bb8f9bf58da55633e2587d75851
Reviewed-on: https://go-review.googlesource.com/c/go/+/681376
Auto-Submit: Austin Clements <austin@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src/runtime')
| -rw-r--r-- | src/runtime/debuglog.go | 54 |
1 files changed, 51 insertions, 3 deletions
diff --git a/src/runtime/debuglog.go b/src/runtime/debuglog.go index e993e396c1..405f2455c6 100644 --- a/src/runtime/debuglog.go +++ b/src/runtime/debuglog.go @@ -196,7 +196,8 @@ const ( debugLogPtr debugLogString debugLogConstString - debugLogStringOverflow + debugLogHexdump + debugLogOverflow debugLogPC debugLogTraceback @@ -365,7 +366,7 @@ func (l *dloggerImpl) s(x string) *dloggerImpl { l.w.uvarint(uint64(len(b))) l.w.bytes(b) if len(b) != len(x) { - l.w.byte(debugLogStringOverflow) + l.w.byte(debugLogOverflow) l.w.uvarint(uint64(len(x) - len(b))) } } @@ -373,6 +374,32 @@ func (l *dloggerImpl) s(x string) *dloggerImpl { } //go:nosplit +func (l dloggerFake) hexdump(p unsafe.Pointer, bytes uintptr) dloggerFake { return l } + +//go:nosplit +func (l *dloggerImpl) hexdump(p unsafe.Pointer, bytes uintptr) *dloggerImpl { + var b []byte + bb := (*slice)(unsafe.Pointer(&b)) + bb.array = unsafe.Pointer(p) + bb.len, bb.cap = int(bytes), int(bytes) + if len(b) > debugLogStringLimit { + b = b[:debugLogStringLimit] + } + + l.w.byte(debugLogHexdump) + l.w.uvarint(uint64(uintptr(p))) + l.w.uvarint(uint64(len(b))) + l.w.bytes(b) + + if uintptr(len(b)) != bytes { + l.w.byte(debugLogOverflow) + l.w.uvarint(uint64(bytes) - uint64(len(b))) + } + + return l +} + +//go:nosplit func (l dloggerFake) pc(x uintptr) dloggerFake { return l } //go:nosplit @@ -708,9 +735,30 @@ func (r *debugLogReader) printVal() bool { s := *(*string)(unsafe.Pointer(&str)) print(s) - case debugLogStringOverflow: + case debugLogOverflow: print("..(", r.uvarint(), " more bytes)..") + case debugLogHexdump: + p := uintptr(r.uvarint()) + bl := r.uvarint() + if r.begin+bl > r.end { + r.begin = r.end + print("<hexdump length corrupted>") + break + } + println() // Start on a new line + hd := hexdumper{addr: p} + for bl > 0 { + b := r.data.b[r.begin%uint64(len(r.data.b)):] + if uint64(len(b)) > bl { + b = b[:bl] + } + r.begin += uint64(len(b)) + bl -= uint64(len(b)) + hd.write(b) + } + hd.close() + case debugLogPC: printDebugLogPC(uintptr(r.uvarint()), false) |
