Golang gdb: Difference between revisions
From wikinotes
(Created page with "Instructions for debugging go with gdb.<br> Instructions vary by compiler = gc = <blockquote> If compiled with <code>gc</code> (default). <syntaxhighlight lang="bash"> go build -ldflags=-w . gdb your-executable </syntaxhighlight> </blockquote><!-- gc -->") |
No edit summary |
||
(6 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
Instructions for debugging go with [[gdb]].<br> | Instructions for debugging go with [[gdb]].<br> | ||
Instructions vary by compiler | Instructions vary by compiler | ||
= Documentation = | |||
<blockquote> | |||
{| class="wikitable" | |||
|- | |||
| go blog || https://go.dev/doc/gdb | |||
|- | |||
|} | |||
</blockquote><!-- Documentation --> | |||
= Tutorials = | |||
<blockquote> | |||
{| class="wikitable" | |||
|- | |||
| cloudbees tutorial || https://www.cloudbees.com/blog/using-gdb-debugger-with-go | |||
|- | |||
|} | |||
</blockquote><!-- Tutorials --> | |||
= gc = | = gc = | ||
Line 7: | Line 25: | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
go build - | go build -gcflags "-N -l" # build, disabling optimizations | ||
gdb your- | gdb executable | ||
#> run # begin running executable | |||
</syntaxhighlight> | |||
Then it's regular gdb commands | |||
<syntaxhighlight lang="bash"> | |||
# configure gdb for your execution | |||
break file.go:123 # set breakpoint in file.go, line:123 | |||
layout src # split-screen, displaying location in code | |||
# begin running code | |||
run | |||
# at breakpoints, inspect your code | |||
bt # show backtrace | |||
p yourVar # print a variable | |||
l | |||
s # step into method | |||
n # next line | |||
exit # quit | |||
</syntaxhighlight> | </syntaxhighlight> | ||
</blockquote><!-- gc --> | </blockquote><!-- gc --> | ||
= gcc = | |||
<blockquote> | |||
</blockquote><!-- gcc --> | |||
= clang = | |||
<blockquote> | |||
</blockquote><!-- clang --> |
Latest revision as of 16:27, 26 June 2022
Instructions for debugging go with gdb.
Instructions vary by compiler
Documentation
go blog https://go.dev/doc/gdb
Tutorials
cloudbees tutorial https://www.cloudbees.com/blog/using-gdb-debugger-with-go
gc
If compiled with
gc
(default).go build -gcflags "-N -l" # build, disabling optimizations gdb executable #> run # begin running executableThen it's regular gdb commands
# configure gdb for your execution break file.go:123 # set breakpoint in file.go, line:123 layout src # split-screen, displaying location in code # begin running code run # at breakpoints, inspect your code bt # show backtrace p yourVar # print a variable l s # step into method n # next line exit # quit