Skip to content

gdb: can't load debug symbols for cgo in 1.8 #18745

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

Closed
JayNakrani opened this issue Jan 22, 2017 · 9 comments
Closed

gdb: can't load debug symbols for cgo in 1.8 #18745

JayNakrani opened this issue Jan 22, 2017 · 9 comments
Milestone

Comments

@JayNakrani
Copy link
Contributor

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

go1.8rc2

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

linux-amd64

What did you do?

Tried debugging a cgo binary compiled with 1.8rc2. gdb can't seem to load debug symbols for it, but works for pure go binary. gdb also works fine in 1.7 for both go and cgo. Here's full matrix.

Version Binary Type gdb works?
1.8rc2 cgo no
1.8rc2 go yes
1.7.3 cgo yes
1.7.3 go yes

dhananjay92/cgo_debug_info has the simple repro code.

$ cd $GOPATH/src/github.com/dhananjay92/cgo_debug_info
$ ./run.sh 	# compiles for all combinations

$ gdb cgo/1.8main
...
(gdb) list
1   go: No such file or directory.
(gdb) info source
No current source file.
(gdb) q

The same works in 1.7 compiled cgo binary.

$ gdb cgo/1.7main 
...
(gdb) list
2	package main
3	
4	import "C"
5	
6	import (
7		"fmt"
8		"github.com/dhananjay92/cgo_debug_info/a"
9	)
10	
11	func main() {
(gdb) info source
Current source file is .../src/github.com/dhananjay92/cgo_debug_info/cgo/main.go
Compilation directory is .../src/github.com/dhananjay92/cgo_debug_info/cgo
Located in .../src/github.com/dhananjay92/cgo_debug_info/cgo/main.go
Contains 13 lines.
Source language is unknown.
Compiled with (null) debugging format.
Does not include preprocessor macro info.
@JayNakrani JayNakrani added this to the Go1.8Maybe milestone Jan 22, 2017
@JayNakrani
Copy link
Contributor Author

Keeping 1.8Maybe for now, since this is a regression from 1.7. Please feel free to change the priority.

@JayNakrani
Copy link
Contributor Author

Couple of observations:

  1. start gdb command seems to work with 1.8rc2 compiled cgo binary, though.
$ gdb cgo/1.8main
...
(gdb) list
1   go: No such file or directory.
(gdb) info source
No current source file.
(gdb) start
Temporary breakpoint 1 at 0x47bd90: file .../src/github.com/dhananjay92/cgo_debug_info/cgo/main.go, line 11.
Starting program: .../src/github.com/dhananjay92/cgo_debug_info/cgo/1.8main 
...

Temporary breakpoint 1, main.main () at .../src/github.com/dhananjay92/cgo_debug_info/cgo/main.go:11
11  func main() {
(gdb) list
6   import (
7       "fmt"
8       "github.com/dhananjay92/cgo_debug_info/a"
9   )
10  
11  func main() {
12      fmt.Println(a.A())
13  }
  1. objdump --debugging shows that user-defined packages have 0x0 in cgo-1.8 but are non-zero for pure a go binary. Also, .debug_pubnames section is missing entry for github.com/dhananjay92/cgo_debug_info/a.A in 1.8rc2 compiled binary compared to 1.7 compiled binary (but that happens in both go and cgo).

@JayNakrani
Copy link
Contributor Author

git-bisect points at 795ad07 as the first bad commit.

That commit seems very likely, because it moved DWARF symbol generation from linker to compiler. This works for pure Go binaries, but for cgo it seems to miss some symbols. CCing people involved in that change.

/cc @matloob, @crawshaw

@ianlancetaylor
Copy link
Contributor

Your test case seems to work for me.

> go version
go version devel +1106512db5 Fri Dec 16 22:30:12 2016 +0000 linux/amd64
> go build
> objdump --debugging ./cgo > /tmp/foo.txt
> grep "a\.A" -B 2 -A 4 /tmp/foo.txt
 <2><27a05>: Abbrev Number: 0
 <1><27a06>: Abbrev Number: 2 (DW_TAG_subprogram)
    <27a07>   DW_AT_name        : github.com/dhananjay92/cgo_debug_info/a.A	
    <27a31>   DW_AT_low_pc      : 0x0	
    <27a39>   DW_AT_high_pc     : 0x0	
    <27a41>   DW_AT_external    : 1	
 <2><27a42>: Abbrev Number: 5 (DW_TAG_formal_parameter)

Simple uses of gdb seem to work too. I don't see any problems.

What do you see in the objdump output?

@JayNakrani
Copy link
Contributor Author

objdump shows same output like yours (0x0 for DW_AT_low_pc and DW_AT_high_pc): https://gist.github.com/dhananjay92/b5c0c318a2bf47e337680de9975cc964

Does list gdb command work for you? For me it doesn't.

$ cd $GOPATH/src/github.com/dhananjay92/cgo_debug_info/cgo
$ go18 version
go version go1.8rc2 linux/amd64
$ go18 build
$ ls
cgo  main.go
$ gdb cgo
...
(gdb) list
1 go: No such file or directory.
(gdb) q

$ rm cgo
$ go version
go version go1.7.3 linux/amd64
$ go build 
$ ls 
cgo  main.go
$ gdb cgo 
...
(gdb) list
1 // A cgo binary
2 package main
3 
4 import "C"
5 
6 import (
7   "fmt"
8   "github.com/dhananjay92/cgo_debug_info/a"
9 )
10  
(gdb) q

I also tried doing the same at 1106512 (just in case), but I get the same result (gdb can't list).

@ianlancetaylor
Copy link
Contributor

Thanks. I see what you mean now.

@ianlancetaylor
Copy link
Contributor

https://golang.org/cl/35590

@JayNakrani JayNakrani modified the milestones: Go1.8, Go1.8Maybe Jan 24, 2017
@JayNakrani
Copy link
Contributor Author

Thank you. :)

A silly question: Will this automatically get picked up in next 1.8 candidate? Or do I need to ask someone to cherry-pick it?

@ianlancetaylor
Copy link
Contributor

This will be in the next release candidate (1.8rc3).

@golang golang locked and limited conversation to collaborators Jan 24, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants