Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I inspect this slice of this array in gdb?

Tags:

arrays

gdb

I am in a GDB debugging session and I have an array of length 20,000. Most of the elements are zero but there is a couple of them at around index 10000 which are of interest. Unfortunately, when I say p the_array[10000]@30 or something I get "only values in memory can be extended with '@'". How can I visualize a region of that array without having to manually request each index over a range of say 40-50 elements?

like image 867
Palace Chan Avatar asked Jun 19 '13 23:06

Palace Chan


2 Answers

I would expect this to work. And it does work for me. I have this little program:

int x[10000];

Now in gdb:

(gdb) p x[50]@3
$2 = {0, 0, 0}

Many details are missing from your question. Maybe your gdb has a bug. Or maybe your array is odd in some respect. The gdb version and things like "whatis the_array" might be interesting.

like image 83
Tom Tromey Avatar answered Oct 16 '22 14:10

Tom Tromey


Looks like we cannot use addresses to extend the memory regions

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

But this works fine

(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}
like image 45
JamesWebbTelescopeAlien Avatar answered Oct 16 '22 14:10

JamesWebbTelescopeAlien