This is taken from Fedora planet, somekind of blog aggregator of the member of Fedora Community. This post discusses about the way we can print array values in gdb.
Here is the link http://wagiaalla.com/2011/01/20/gdb-tricks-printing-arrays/, written by Sami Wagiaalla.
....And here is some excerpt from it:
int main(){
int *a;
int b[3] = {1,2,3};
a = b;
int *c[3] = {a, b, 0};
int **d = c;
return 0;
}
While debugging the above code if you do:
(gdb) print b
$4 = {1, 2, 3}
that works.
(gdb) print a
$5 = (int *) 0x7fffffffe0f0
that works too, but in order to print a as an array you must do:
(gdb) print (int []) *a
$7 = {1}
and when you specify the size it gets better:
(gdb) print (int [3]) *a
$8 = {1, 2, 3}
regards,
Mulyadi
A place where I share my daily experience in both technical and non technical issues. Expect to read Linux kernel related posts too.
Subscribe to:
Post Comments (Atom)
How to execute multiple commands directly as ssh argument?
Perhaps sometimes you need to do this: ssh user@10.1.2.3 ls It is easy understand the above: run ls after getting into 10.1.2.3 via ssh. Pi...
-
Ever saw something like below messages inside your KVM (Kernel Virtual Machine) guest's console? " BUG: soft lockup - CPU#0 stuck f...
-
Quick summary first: use gcc -save-temps ! Ever dig into Qemu (qemu.org) source code? OK, I assume you ever did that at least once... may ...
-
Dear readers This time I met interesting case, thus I think it is worth sharing it with you all. But first, big disclaimer. I AM NOT FREE ...
1 comment:
You can also use '@' variable.
(gdb) p *a@3
$4 = {1, 2, 3}
(gdb) p a[0]@3
$5 = {1, 2, 3}
Or to see addresses.
(gdb) p a@3
$3 = {0xbffff864, 0xbffff8f8, 0xb7e80e37}
Post a Comment