Created
March 8, 2015 22:50
-
-
Save cevaris/a7a96d2ec61cd63dbc57 to your computer and use it in GitHub Desktop.
Debugging golang in GDB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
go build -gcflags '-N' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gdbtest (master|?) ~࿔ gdb gdbtest | |
GNU gdb (GDB) 7.8.1 | |
Copyright (C) 2014 Free Software Foundation, Inc. | |
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> | |
This is free software: you are free to change and redistribute it. | |
There is NO WARRANTY, to the extent permitted by law. Type "show copying" | |
and "show warranty" for details. | |
This GDB was configured as "x86_64-apple-darwin14.1.0". | |
Type "show configuration" for configuration details. | |
For bug reporting instructions, please see: | |
<http://www.gnu.org/software/gdb/bugs/>. | |
Find the GDB manual and other documentation resources online at: | |
<http://www.gnu.org/software/gdb/documentation/>. | |
For help, type "help". | |
Type "apropos word" to search for commands related to "word"... | |
Reading symbols from gdbtest...done. | |
(gdb) quit | |
gdbtest (master|?) ~࿔ build | |
zsh: command not found: build | |
gdbtest (master|?) ~࿔ build | |
gdbtest (master|?) ~࿔ make | |
go build -gcflags '-N' | |
gdbtest (master|?) ~࿔ gdb gdbtest | |
GNU gdb (GDB) 7.8.1 | |
Copyright (C) 2014 Free Software Foundation, Inc. | |
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> | |
This is free software: you are free to change and redistribute it. | |
There is NO WARRANTY, to the extent permitted by law. Type "show copying" | |
and "show warranty" for details. | |
This GDB was configured as "x86_64-apple-darwin14.1.0". | |
Type "show configuration" for configuration details. | |
For bug reporting instructions, please see: | |
<http://www.gnu.org/software/gdb/bugs/>. | |
Find the GDB manual and other documentation resources online at: | |
<http://www.gnu.org/software/gdb/documentation/>. | |
For help, type "help". | |
Type "apropos word" to search for commands related to "word"... | |
Reading symbols from gdbtest...done. | |
(gdb) l | |
1 package main | |
2 | |
3 import "fmt" | |
4 | |
5 type MyStruct struct { | |
6 x string | |
7 i int | |
8 f float64 | |
9 m map[string] int64 | |
10 } | |
(gdb) br 26 | |
Breakpoint 1 at 0x2443: file /go/src/github.com/cevaris/gdbtest/main.go, line 26. | |
(gdb) run | |
Starting program: /go/src/github.com/cevaris/gdbtest/gdbtest | |
3 | |
abc | |
[New Thread 0x1117 of process 3955] | |
[New Thread 0x1303 of process 3955] | |
Breakpoint 1, main.main () at /go/src/github.com/cevaris/gdbtest/main.go:26 | |
26 fmt.Println(ms) | |
(gdb) info locals | |
i = 3 | |
ms = 0x2081ba180 | |
x = 0xdb470 "abc" | |
(gdb) p x | |
$1 = 0xdb470 "abc" | |
(gdb) p ms | |
$2 = (struct main.MyStruct *) 0x2081ba180 | |
(gdb) p *ms | |
$3 = {x = 0xdbb10 "cba", i = 10, f = 11.103350000000001, m = 0x2081ba150} | |
(gdb) p ms.x | |
$4 = 0xdbb10 "cba" | |
(gdb) p *ms.m | |
$5 = {count = 2, flags = 0, hash0 = 1654797232, B = 0 '\000', buckets = 0x2081bc1a0, oldbuckets = 0x0, nevacuate = 0} | |
(gdb) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
type MyStruct struct { | |
x string | |
i int | |
f float64 | |
m map[string] int64 | |
} | |
func main() { | |
x := "abc" | |
i := 3 | |
fmt.Println(i) | |
fmt.Println(x) | |
ms := &MyStruct{ | |
x: "cba", | |
i: 10, | |
f: 11.10335, | |
m: make(map[string]int64), | |
} | |
ms.m["hello"] = int64(11) | |
ms.m["world"] = int64(22) | |
fmt.Println(ms) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment