Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/link: windows executable have no .debug_gdb_scripts section #20218

Closed
alexbrainman opened this issue May 3, 2017 · 3 comments

Comments

Projects
None yet
3 participants
@alexbrainman
Copy link
Member

commented May 3, 2017

What version of Go are you using (go version)?

go version devel +18fb670 Tue May 2 00:21:33 2017 +0000 windows/386

What operating system and processor architecture are you using (go env)?

set GOARCH=386
set GOBIN=
set GOEXE=.exe
set GOHOSTARCH=386
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=c:\dev
set GORACE=
set GOROOT=c:\dev\go
set GOTOOLDIR=c:\dev\go\pkg\tool\windows_386
set GCCGO=gccgo
set GO386=
set CC=gcc
set GOGCCFLAGS=-m32 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\DOCUME1\brainman\LOCALS1\Temp\go-build677740063=/tmp/go-build -gno-record-gcc-switches
set CXX=g++
set CGO_ENABLED=1
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config

What did you do?

I built this program:

package main

import (
        "fmt"
)

func main() {
        fmt.Println("hello\n")
}

and listed executable file sections with:

go build -o %TMP%\a.exe foo.go && objdump -h %TMP%\a.exe | grep debug

What did you expect to see?

  2 .debug_abbrev 00000102  0050f000  0050f000  000f8200  2**0
  3 .debug_line   00013fb8  00510000  00510000  000f8400  2**0
  4 .debug_frame  0000cfe8  00524000  00524000  0010c400  2**0
  5 .debug_pubnames 0000532a  00531000  00531000  00119400  2**0
  6 .debug_pubtypes 000081bf  00537000  00537000  0011e800  2**0
  7 .debug_aranges 00000020  00540000  00540000  00126a00  2**0
  8 .debug_info   000394be  00541000  00541000  00126c00  2**0
  9 .debug_gdb_scripts   ...

What did you see instead?

I see the above output, but without .debug_gdb_scripts section present.

I checked the .debug_gdb_scripts section is present on linux. In fact, if I make this change:

diff --git a/src/cmd/link/internal/ld/dwarf.go b/src/cmd/link/internal/ld/dwarf.go
index 205b395..e244197 100644
--- a/src/cmd/link/internal/ld/dwarf.go
+++ b/src/cmd/link/internal/ld/dwarf.go
@@ -873,6 +873,7 @@ func finddebugruntimepath(s *Symbol) {
 	for i := range s.FuncInfo.File {
 		f := s.FuncInfo.File[i]
 		if i := strings.Index(f.Name, "runtime/runtime.go"); i >= 0 {
+			fmt.Printf("ALEX: %v %v\n", s.Name, f.Name)
 			gdbscript = f.Name[:i] + "runtime/runtime-gdb.py"
 			break
 		}

I see this (on linux):

# go install -v cmd/link && go build -o /tmp/a t && objdump -h /tmp/a | grep debug
# t
ALEX: syscall.runtime_envs /root/go/src/runtime/runtime.go
 32 .debug_aranges 00000120  00000000  00000000  000ece38  2**3
 33 .debug_pubnames 00003492  00000000  00000000  000ecf58  2**0
 34 .debug_info   0003738e  00000000  00000000  000f03ea  2**0
 35 .debug_abbrev 00000ae9  00000000  00000000  00127778  2**0
 36 .debug_line   00013c97  00000000  00000000  00128261  2**0
 37 .debug_frame  0000d1bc  00000000  00000000  0013bef8  2**2
 38 .debug_str    000006a1  00000000  00000000  001490b4  2**0
 39 .debug_loc    0000052a  00000000  00000000  00149755  2**0
 40 .debug_pubtypes 0000818e  00000000  00000000  00149c7f  2**0
 41 .debug_ranges 00000018  00000000  00000000  00151e0d  2**0
 42 .debug_gdb_scripts 00000025  00000000  00000000  00151e25  2**0
#

which explains why it does not work on windows - there is no syscall.runtime_envs on windows.

Looking for suggestion what to look for in finddebugruntimepath so it works on windows too. Thank you.

Alex

@egonelbre

This comment has been minimized.

Copy link
Contributor

commented May 4, 2017

Maybe debug.go, hashmap.go, slice.go, string.go, error.go, iface.go or print.go... these should be included most of the time? Alternatively, add a file specifically for it?

Also, when you have a my/package/runtime/runtime.go the current approach could use the wrong thing.

gdb has an option to embed the script source (https://sourceware.org/gdb/onlinedocs/gdb/dotdebug_005fgdb_005fscripts-section.html). This would avoid the need to search for the script in the first place (of course, at the cost of 12kb in executable).

@alexbrainman

This comment has been minimized.

Copy link
Member Author

commented May 5, 2017

Maybe debug.go, hashmap.go, slice.go, string.go, error.go, iface.go or print.go... these should be included most of the time? Alternatively, add a file specifically for it?

Also, when you have a my/package/runtime/runtime.go the current approach could use the wrong thing.

I am not sure what the right approach is. But we need new test to check that .debug_gdb_scripts is included in the exe.

Alex

@gopherbot

This comment has been minimized.

Copy link

commented May 12, 2017

CL https://golang.org/cl/43331 mentions this issue.

@gopherbot gopherbot closed this in 1d44c4e May 15, 2017

@golang golang locked and limited conversation to collaborators May 15, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.