英文:
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
这里有两个命令可以使用:args
和 locals
。
例如,对于这个(无意义的)示例代码:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论