Jainam MJ
Jainam MJ

Reputation: 350

Print all local variables in delve debugger

If my dlv debugging session is in a function and I want to list all the local variables of that function, how do I do it?

Upvotes: 0

Views: 1838

Answers (1)

fizzie
fizzie

Reputation: 711

There are the args and locals commands for this.

For example, for this (nonsense) example code:

package main

import "fmt"

func example(a, b int) (c int) {
  d := a + b
  if true {
    e := d + 123
    c = e + 1
    fmt.Println("time for a breakpoint")
  }
  return c
}

func main() {
  example(2, 3)
}

The output, when stopped at the print statement, is as follows:

(dlv) args
a = 2
b = 3
c = 129
(dlv) locals
d = 5
e = 128

Refer to Delve's cli/README.md for more details on the available commands.

Upvotes: 2

Related Questions