如何在 GDB 调试器中打印字符串值而不是十六进制?
(gdb) run hello
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program: /Users/doug/langs/c/test hello
Breakpoint 1, main (argc=2, argv=0xbffffa7c) at hw3b.c:14
14 if (argc != 2) {
(gdb) printf "%s", argv
??????(gdb)
我搜索了有关 SO 的其他问题,并尝试了找到的所有命令,但我不断收到???标记。这是为什么?
(gdb) run hello
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program: /Users/doug/langs/c/test hello
Breakpoint 1, main (argc=2, argv=0xbffffa7c) at hw3b.c:14
14 if (argc != 2) {
(gdb) printf "%s", argv
??????(gdb)
I searched other questions on SO and I tried all the commands that I found but I keep getting ??? marks. Why is that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
argv
不是一个字符串,它是一个char**
- 指向可能多个 C 字符串中第一个的指针。我认为您正在寻找:
或者如果您想使用 printf:
但在如此简单的情况下确实没有理由这样做,因为 gdb 确实知道如何打印
char*
字符串。或者,如果您想变得更奇特,这是可行的:
语法
FOO@NUM
告诉它打印从FOO
开始的NUM
元素数组。我不知道为什么解除引用会起作用,但它确实起作用 - 我想 gdb 就是这样。有人启发我吗?argv
isn't a string, it's achar**
- a pointer to the first of possibly multiple C strings.I think you're looking for:
Or if you want to use printf:
But there's really no reason to in such a simple case, since gdb does know how to print
char*
strings.Or, if you want to be fancy, this works:
The syntax
FOO@NUM
tells it to print an array ofNUM
elements starting atFOO
. And I have no idea why the dereferencing works, but it does - I guess gdb is just nice like that. Someone enlighten me?