i wish use gdb print array elements of allocated memory.
int main() { int* p=(int*)malloc(7*sizeof(int)); for(size_t j=0;j<7;++j) { p[j]=j; } return 0; }
so compiled program -g3, use gdb start it, , set break
> print p@7
i expected print out 1-7, actual output was
$1 = {0x6160b0, 0x5, 0xff00000000, 0x615c60, 0x615c80, 0x615c20, 0x615c40}
why expectation!=actual result, wrong program?
the gdb manual says:
the left operand of `@' should first element of desired array , individual object. right operand should desired length of array. result array value elements of type of left argument
so if
print p@7
you tell gdb print array of 7 pointers.
what need is:
print *p@7
Comments
Post a Comment