Golang delve: Difference between revisions
From wikinotes
No edit summary |
No edit summary |
||
Line 15: | Line 15: | ||
|} | |} | ||
</blockquote><!-- Documentation --> | </blockquote><!-- Documentation --> | ||
= Locations = | |||
<blockquote> | |||
{| class="wikitable" | |||
|- | |||
| <code>~/.config/dlv/config.yml</code> || config options | |||
|- | |||
|} | |||
</blockquote><!-- Locations --> | |||
= Install = | = Install = | ||
Line 22: | Line 31: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
</blockquote><!-- Install --> | </blockquote><!-- Install --> | ||
= Configuration = | |||
<blockquote> | |||
== Persistent == | |||
<blockquote> | |||
<syntaxhighlight lang="yaml"> | |||
# ~/.config/dlv/config.yml | |||
max-string-len: 1000 | |||
max-array-values: 1000 | |||
</syntaxhighlight> | |||
</blockquote><!-- Persistent --> | |||
== Dynamic == | |||
<blockquote> | |||
Within a delve session, you can modify debugger config values. | |||
<syntaxhighlight lang="bash"> | |||
config max-string-len 1000 | |||
</syntaxhighlight> | |||
</blockquote><!-- Dynamic --> | |||
</blockquote><!-- Configuration --> | |||
= Usage = | = Usage = |
Revision as of 16:22, 9 July 2022
delve is a go debugger.
It is more knowledgeable about the go runtime than golang gdb .
There are also editor integrations.
Documentation
Locations
~/.config/dlv/config.yml
config options
Install
go install github.com/go-delve/delve/cmd/dlv@latest
Configuration
Persistent
# ~/.config/dlv/config.yml max-string-len: 1000 max-array-values: 1000Dynamic
Within a delve session, you can modify debugger config values.
config max-string-len 1000
Usage
Delve builds your executable automatically with flags required for it to debug your program.
Start Delve
# start debugger dlv debug [example.com/x/foo/package] [-- [--your-params]] # run program dlv test [example.com/x/foo/package] # run testsBreakpoint
You can add breakpoints in src, or interactively
runtime.Breakpoint() // delve breakpointb main.main # add breakpoint to 'main.go's 'main' method b main.go:10 # add breakpoint to 'main.go's line 10Session
Add your breakpoints, then continue to execute your program
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