Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Debugging Go Programs with Delve

Avatar for Derek Parker Derek Parker
February 03, 2018
76

Debugging Go Programs with Delve

Avatar for Derek Parker

Derek Parker

February 03, 2018
Tweet

Transcript

  1. • Different execution model • Runtime / scheduler • Memory

    layout • Garbage Collector • Different type system • ...
  2. • Blocking syscall • Blocking IO • Function call (stack

    growth) • `runtime.Gosched` • Creating a new goroutine • ...
  3. Work stealing, cont’d P1 P2 T1 T3 T5 T2 T6

    G4 G1 G3 G8 G9 Local queue Goroutines Threads Processors Global queue
  4. • Better variable scope information • Ability to detect function

    arguments from return values • Better support for consts • Improved DWARF information when optimizations are enabled • Possibility of calling Go functions from Delve • Much more… (see `debugging` tag in issues)
  5. $ dlv debug Type 'help' for list of commands. (dlv)

    dlv debug Begin typical debug session. Can optionally take package path.
  6. $ dlv test Type 'help' for list of commands. (dlv)

    dlv test Begin debug session with test binary. Can optionally take package path.
  7. $ dlv attach $pid Type 'help' for list of commands.

    (dlv) dlv attach Attach to running process
  8. $ dlv trace <regexp> … [trace output] … dlv trace

    Begin tracing a Go program. Accepts regexp of functions to trace.
  9. # Ensure correct ulimit for core dumps. $ ulimit -c

    unlimited # Run binary with correct env var. $ GOTRACEBACK=crash ./my-prog dlv core Debug core dumps from a Go process. Before trying, ensure system can produce core dumps: $ dlv core <binary> <path/to/core/file>