在 delve 调试器中打印所有局部变量。

huangapple go评论77阅读模式
英文:

Print all local variables in delve debugger

问题

如果我的dlv调试会话在一个函数中,并且我想列出该函数的所有局部变量,我该如何做呢?

英文:

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?

答案1

得分: 2

这里有两个命令可以使用:argslocals

例如,对于这个(无意义的)示例代码:

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)
}

当在打印语句处停下来时,输出结果如下:

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

有关可用命令的更多详细信息,请参考 Delve 的 cli/README.md

英文:

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.

huangapple
  • 本文由 发表于 2021年8月5日 18:28:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/68664890.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定