PDA

View Full Version : [SOLVED] gdb option to see from a memory address onwards?



IAMTubby
October 23rd, 2014, 02:13 AM
Hello,
I was wondering if there is an option in gdb to see from a particular memory address onwards. I normally print out the values using


(gdb) p *A1
(gdb) p *(A1+1)
(gdb) p *(A1+2)
(gdb) p *(A1+3)


Is there something where I can see the contents of the next n memory locations starting from A1?

Use Case :
I define my arrays using pointers.
So I would have something like


int* A1;
A1= malloc(10 * sizeof(int));

for(i=0;i<10;i++)
*(A1 + i) = i+1;


Now I want to see the array contents using gdb.

Please advise.
Thanks.

spjackson
October 23rd, 2014, 08:43 AM
(gdb) p *A1@10
$2 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}

See http://ftp.gnu.org/old-gnu/Manuals/gdb/html_chapter/gdb_9.html#SEC54

IAMTubby
October 25th, 2014, 04:03 AM
(gdb) p *A1@10
$2 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}

See http://ftp.gnu.org/old-gnu/Manuals/gdb/html_chapter/gdb_9.html#SEC54
spjackson, haha, this is insane :D