开发者

How can I print the string value and not the hex in GDB debugger?

开发者 https://www.devze.com 2023-02-22 15:40 出处:网络
(gdb) run hello The program being debugged has been started already. Start it from the beginning? (y or n) y
(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

Breakpoi开发者_如何转开发nt 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?


argv isn't a string, it's a char** - a pointer to the first of possibly multiple C strings.

I think you're looking for:

print argv[0]
print argv[1]
...

Or if you want to use printf:

printf "%s\n", argv[0]

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:

print *argv@argc

The syntax FOO@NUM tells it to print an array of NUM elements starting at FOO. And I have no idea why the dereferencing works, but it does - I guess gdb is just nice like that. Someone enlighten me?

0

精彩评论

暂无评论...
验证码 换一张
取 消