]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: fix debuglog traceback printing off-by-one
authorAustin Clements <austin@google.com>
Wed, 7 Aug 2019 01:37:37 +0000 (21:37 -0400)
committerAustin Clements <austin@google.com>
Wed, 29 Apr 2020 20:33:30 +0000 (20:33 +0000)
The debuglog traceback printer wasn't adjusting for call/return PCs.

Change-Id: I98dda1c0f22cd78651d88124ea51dc166dc91c7a
Reviewed-on: https://go-review.googlesource.com/c/go/+/227646
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
src/runtime/debuglog.go

index 100f2d370a727489e96a433b0e720bea5568302b..3ce3273f4def09707d447e42e79dea6ef1d6221c 100644 (file)
@@ -665,13 +665,17 @@ func (r *debugLogReader) printVal() bool {
                print("..(", r.uvarint(), " more bytes)..")
 
        case debugLogPC:
-               printDebugLogPC(uintptr(r.uvarint()))
+               printDebugLogPC(uintptr(r.uvarint()), false)
 
        case debugLogTraceback:
                n := int(r.uvarint())
                for i := 0; i < n; i++ {
                        print("\n\t")
-                       printDebugLogPC(uintptr(r.uvarint()))
+                       // gentraceback PCs are always return PCs.
+                       // Convert them to call PCs.
+                       //
+                       // TODO(austin): Expand inlined frames.
+                       printDebugLogPC(uintptr(r.uvarint()), true)
                }
        }
 
@@ -794,9 +798,17 @@ func printDebugLog() {
        printunlock()
 }
 
-func printDebugLogPC(pc uintptr) {
-       print(hex(pc))
+// printDebugLogPC prints a single symbolized PC. If returnPC is true,
+// pc is a return PC that must first be converted to a call PC.
+func printDebugLogPC(pc uintptr, returnPC bool) {
        fn := findfunc(pc)
+       if returnPC && (!fn.valid() || pc > fn.entry) {
+               // TODO(austin): Don't back up if the previous frame
+               // was a sigpanic.
+               pc--
+       }
+
+       print(hex(pc))
        if !fn.valid() {
                print(" [unknown PC]")
        } else {