GDB - Attach and release a running Go app

I compiled a simple move application with debug flags:

go build -gcflags "-N -l" -o main main.go

main.go

 package main import ( "fmt" "time" ) func main() { for i := 0; true; i++ { fmt.Println("number:", i) time.Sleep(time.Second) } } 

In gdb, I am tied to its pid and performed break and break 11 .

gdb --pid=<pid>

Gdb reports that breakpoints have been set successfully, but they are never hit. Is there any way to make this work?

+4
source share
2 answers

Note. The same setting (even when adding runtime-gdb.py to your .gdbrc ) runs the risk of not working with Ubuntu 13.10, where you get the message " SyntaxError ", as shown in the figure:

The problem is that Ubuntu 13.10 associates GDB with Python 3.3, while the script golang ships are for Python 2. Someone has already registered the problem and it seems to be fixed upstream (so expect Go 1.3 for Just Work).

Fortunately, backing up the fix is ​​easy. Just move the existing runtime-gdb.py to the side and download the original version in its place.

If your $GOROOT is /usr/local/go , then the following follows: Work Work

 sudo mv /usr/local/go/src/pkg/runtime/runtime-gdb.py /usr/local/go/src/pkg/runtime/runtime-gdb.py.orig cd /usr/local/go/src/pkg/runtime/ sudo wget https://go.googlecode.com/hg/src/pkg/runtime/runtime-gdb.py 
+1
source

go/src/pkg/runtime/runtime-gdb.py script needs to be loaded inside gdb in order to efficiently debug go programs.

You can add it to the .gdbrc file.

+1
source

Source: https://habr.com/ru/post/1489394/


All Articles