LEFT | RIGHT |
1 <!--{ | 1 <!--{ |
2 "Title": "Debugging Go Code with GDB", | 2 "Title": "Debugging Go Code with GDB", |
3 "Path": "/ref/gdb" | 3 "Path": "/ref/gdb" |
4 }--> | 4 }--> |
5 | 5 |
6 <p><i> | 6 <p><i> |
7 This applies to the gc toolchain. Gccgo has native gdb support. Besides this | 7 This applies to the <code>gc</code> toolchain. Gccgo has native gdb support. |
8 overview you might want to consult the | 8 Besides this overview you might want to consult the |
9 <a href="http://sourceware.org/gdb/current/onlinedocs/gdb/">GDB manual</a>. | 9 <a href="http://sourceware.org/gdb/current/onlinedocs/gdb/">GDB manual</a>. |
10 </i></p> | 10 </i></p> |
11 | 11 |
12 <h2 id="Introduction">Introduction</h2> | 12 <h2 id="Introduction">Introduction</h2> |
13 | 13 |
14 <p> | 14 <p> |
15 When you compile and link your Go programs with the 6g/6l or 8g/8l toolchains | 15 When you compile and link your Go programs with the <code>gc</code> toolchain |
16 on Linux, Mac OS X or FreeBSD, the resulting binaries contain DWARFv3 | 16 on Linux, Mac OS X or FreeBSD, the resulting binaries contain DWARFv3 |
17 debugging information that recent versions (>7.1) of the GDB debugger can | 17 debugging information that recent versions (>7.1) of the GDB debugger can |
18 use to inspect a live process or a core dump. | 18 use to inspect a live process or a core dump. |
19 </p> | 19 </p> |
20 | 20 |
21 <p> | 21 <p> |
22 Pass the <code>'-s'</code> flag to the linker to omit the debug information | 22 Pass the <code>'-s'</code> flag to the linker to omit the debug information |
23 (for example, <code>go build -ldflags "-s" prog.go</code>). | 23 (for example, <code>go build -ldflags "-s" prog.go</code>). |
24 </p> | 24 </p> |
25 | 25 |
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 $1 = (struct testing.T *) 0xf840688b60 | 346 $1 = (struct testing.T *) 0xf840688b60 |
347 (gdb) p t | 347 (gdb) p t |
348 $1 = (struct testing.T *) 0xf840688b60 | 348 $1 = (struct testing.T *) 0xf840688b60 |
349 (gdb) p *t | 349 (gdb) p *t |
350 $2 = {errors = "", failed = false, ch = 0xf8406f5690} | 350 $2 = {errors = "", failed = false, ch = 0xf8406f5690} |
351 (gdb) p *t->ch | 351 (gdb) p *t->ch |
352 $3 = struct hchan<*testing.T> | 352 $3 = struct hchan<*testing.T> |
353 </pre> | 353 </pre> |
354 | 354 |
355 <p> | 355 <p> |
356 That <code>struct hchan<*testing.T></code> is the runtime-internal represn
tation of a channel. It is currently empty, or gdb would have pretty-printed it
's contents. | 356 That <code>struct hchan<*testing.T></code> is the runtime-internal represe
ntation of a channel. It is currently empty, or gdb would have pretty-printed i
t's contents. |
357 </p> | 357 </p> |
358 | 358 |
359 <p> | 359 <p> |
360 Stepping forward: | 360 Stepping forward: |
361 </p> | 361 </p> |
362 | 362 |
363 <pre> | 363 <pre> |
364 (gdb) <b>n</b> <i># execute next line</i> | 364 (gdb) <b>n</b> <i># execute next line</i> |
365 149 for _, test := range findTests { | 365 149 for _, test := range findTests { |
366 (gdb) <i># enter is repeat</i> | 366 (gdb) <i># enter is repeat</i> |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 <pre> | 474 <pre> |
475 (gdb) <b>p i</b> | 475 (gdb) <b>p i</b> |
476 $4 = {str = "cbb"} | 476 $4 = {str = "cbb"} |
477 (gdb) <b>whatis i</b> | 477 (gdb) <b>whatis i</b> |
478 type = regexp.input | 478 type = regexp.input |
479 (gdb) <b>p $dtype(i)</b> | 479 (gdb) <b>p $dtype(i)</b> |
480 $26 = (struct regexp.inputBytes *) 0xf8400b4930 | 480 $26 = (struct regexp.inputBytes *) 0xf8400b4930 |
481 (gdb) <b>iface i</b> | 481 (gdb) <b>iface i</b> |
482 regexp.input: struct regexp.inputBytes * | 482 regexp.input: struct regexp.inputBytes * |
483 </pre> | 483 </pre> |
LEFT | RIGHT |