]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: sniff runtime-gdb.py path from runtime/proc.go
authorAustin Clements <austin@google.com>
Tue, 3 Oct 2017 19:21:55 +0000 (15:21 -0400)
committerAustin Clements <austin@google.com>
Thu, 5 Oct 2017 02:02:50 +0000 (02:02 +0000)
Currently the linker figures out where runtime-gdb.py should be by
looking for the path to runtime/debug.go. However, debug.go contains
only a few symbols and can easily get dead-code eliminated entirely,
especially from simple binaries. When this happens, the resulting
binary lacks a reference to runtime-gdb.py, so the GDB helpers don't
get loaded.

Fix this by instead sniffing for runtime/proc.go. This contains
runtime.main and the scheduler, so it's not going anywhere.

Change-Id: Ie3380c77c840d28614fada68b8c5861625f2aff5
Reviewed-on: https://go-review.googlesource.com/68019
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
src/cmd/link/internal/ld/dwarf.go

index cf4c0939de19bdb79eeaec090630a5fce58a5150..40a2321f3a5a0e9e67b5082b2d508510ca1b3d0a 100644 (file)
@@ -846,7 +846,7 @@ func movetomodule(parent *dwarf.DWDie) {
        die.Link = parent.Child
 }
 
-// If the pcln table contains runtime/runtime.go, use that to set gdbscript path.
+// If the pcln table contains runtime/proc.go, use that to set gdbscript path.
 func finddebugruntimepath(s *Symbol) {
        if gdbscript != "" {
                return
@@ -854,7 +854,10 @@ func finddebugruntimepath(s *Symbol) {
 
        for i := range s.FuncInfo.File {
                f := s.FuncInfo.File[i]
-               if i := strings.Index(f.Name, "runtime/debug.go"); i >= 0 {
+               // We can't use something that may be dead-code
+               // eliminated from a binary here. proc.go contains
+               // main and the scheduler, so it's not going anywhere.
+               if i := strings.Index(f.Name, "runtime/proc.go"); i >= 0 {
                        gdbscript = f.Name[:i] + "runtime/runtime-gdb.py"
                        break
                }