Golang delve: Difference between revisions
From wikinotes
(Created page with "delve is a go debugger.<br> It is more knowledgeable about the go runtime than golang gdb . = Documentation = <blockquote> {| class="wikitable" |- | github || https://github.com/go-delve/delve |- |} </blockquote><!-- Documentation --> = Install = <blockquote> <syntaxhighlight lang="bash"> go install github.com/go-delve/delve/cmd/dlv@latest </syntaxhighlight> </blockquote><!-- Install --> = Usage = <blockquote> <syntaxhighlight lang="bash"> dlv debug dlv debug exam...") |
(→Usage) |
||
Line 20: | Line 20: | ||
= Usage = | = Usage = | ||
<blockquote> | <blockquote> | ||
Delve builds your executable automatically with flags required for it to debug your program. | |||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
dlv debug | # start debugger | ||
dlv | dlv debug [example.com/x/foo/package] [-- [--your-params]] # run program | ||
dlv test [example.com/x/foo/package] # run tests | |||
</syntaxhighlight> | |||
Add your breakpoints, then continue to execute your program | |||
<syntaxhighlight lang="go"> | |||
b main.main # add breakpoint to 'main.go's 'main' method | |||
b main.go:10 # add breakpoint to 'main.go's line 10 | |||
c # continue (start executing) | |||
</syntaxhighlight> | |||
Inspect your program, learn | |||
<syntaxhighlight lang="go"> | |||
p yourVar # print var | |||
l # print location | |||
n # next line (enters loop, not skip to end) | |||
s # step into line | |||
<enter> # repeat last command | |||
</syntaxhighlight> | </syntaxhighlight> | ||
</blockquote><!-- Usage --> | </blockquote><!-- Usage --> |
Revision as of 16:43, 26 June 2022
delve is a go debugger.
It is more knowledgeable about the go runtime than golang gdb .
Documentation
github https://github.com/go-delve/delve
Install
go install github.com/go-delve/delve/cmd/dlv@latest
Usage
Delve builds your executable automatically with flags required for it to debug your program.
# start debugger dlv debug [example.com/x/foo/package] [-- [--your-params]] # run program dlv test [example.com/x/foo/package] # run testsAdd your breakpoints, then continue to execute your program
b main.main # add breakpoint to 'main.go's 'main' method b main.go:10 # add breakpoint to 'main.go's line 10 c # continue (start executing)Inspect your program, learn
p yourVar # print var l # print location n # next line (enters loop, not skip to end) s # step into line <enter> # repeat last command