如何在gdb中检查此数组的这一部分?

Pal*_*han 13 arrays gdb

我在GDB调试会话中,我有一个长度为20,000的数组.大多数元素都是零,但有几个元素在索引周围10000是有意义的.不幸的是,当我说p the_array[10000]@30或"我得到的东西"时,只有内存中的值可以用'@'来扩展.如何在不必手动请求40-50个元素范围内的每个索引的情况下,可视化该阵列的区域?

Tom*_*mey 18

我希望这会奏效.它确实对我有用.我有这个小程序:

int x[10000];
Run Code Online (Sandbox Code Playgroud)

现在在gdb中:

(gdb) p x[50]@3
$2 = {0, 0, 0}
Run Code Online (Sandbox Code Playgroud)

您的问题中缺少许多细节.也许你的gdb有一个bug.或者也许你的阵列在某些方面是奇怪的.gdb版本和诸如"whatis the_array"之类的东西可能很有趣.


Pno*_*tNP 5

看起来我们不能使用地址来扩展内存区域

(gdb) p (struct tfc *)0x1d88a010@100
Only values in memory can be extended with '@'.
Run Code Online (Sandbox Code Playgroud)

但这很好用

(gdb) p *tfc->buckets@100
$87 = {0x0 <repeats 49 times>, 0x7f3b63a1b060, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x7f3b21816c90, 0x0 <repeats 18 times>, 0x7f3ae97f9e80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x7f3b49c96760, 0x0 <repeats 14 times>, 0x7f3adb16d8f0}
Run Code Online (Sandbox Code Playgroud)