GDB 打印 char 数组中的所有值 [英] GDB print all values in char array

查看:82
本文介绍了GDB 打印 char 数组中的所有值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将各种文件名存储在我的数组中,这些文件名由空字节分区.调试时,我只能看到第一个文件名.因此,例如,如果我的数组是这样的:hello.txt00000hello2.txt,我只能看到 hello.txt.如何打印整个数组?我在其他地方找不到这样的命令.

I am storing various filenames in my array which are partitioned by null bytes. When debugging, I am only able to see the first filename. So, for instance if my array is like this: hello.txt00000hello2.txt, I am only able to see hello.txt. How can I print the entire array? I have trouble finding such command elsewhere.

推荐答案

您可以使用 x/999bc,其中 999 是数组的大小,例如:

You can use x/999bc, where 999 is the size of your array, for instance:

paul@thoth:~/src/sandbox$ gdb ./str
GNU gdb (GDB) 7.4.1-debian
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/paul/src/sandbox/str...done.
(gdb) list
1   int main(void) {
2       char * p = "helloworldhahaha";
3       return 0;
4   }
5   
(gdb) b 3
Breakpoint 1 at 0x4004b8: file str.c, line 3.
(gdb) run
Starting program: /home/paul/src/sandbox/str 

Breakpoint 1, main () at str.c:3
3       return 0;
(gdb) print p
$1 = 0x40056c "hello"
(gdb) x/19bc p
0x40056c:   104 'h' 101 'e' 108 'l' 108 'l' 111 'o' 0 '00'    119 'w' 111 'o'
0x400574:   114 'r' 108 'l' 100 'd' 0 '00'    104 'h' 97 'a'  104 'h' 97 'a'
0x40057c:   104 'h' 97 'a'  0 '00'
(gdb) 

这篇关于GDB 打印 char 数组中的所有值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆