Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to declare a GDB convenience variable as an array?

Tags:

gdb

I would like to declare an array convenience variable, such as

set $list[10]

but I get a syntax error.

Is it possible to create a vector using convenience variables?

I could use pointers, if I can find an absolute area memory GDB can use that the target program won't use.

Oh, BTW, I don't have a symbol table for the target program I am debugging, using a compiler not compatible with GDB.

The cross-target version of GDB I have does not support python.

like image 370
KeithSmith Avatar asked Jul 30 '13 20:07

KeithSmith


2 Answers

I think it is only possible if you allocate memory in the inferior. That is, try something like:

set $list = (int *) malloc (10 * sizeof (int))

Change the types to suit.

Another similar option is to use the {...} feature. I am not sure offhand, but I think this may allocate memory in the inferior in some cases. Anyway, try:

print {1,2,3,4}[2]

I get

$1 = 3
like image 111
Tom Tromey Avatar answered Sep 24 '22 21:09

Tom Tromey


Yes, you can.

For example,

(gdb) set $a = (int [3]) {0}
(gdb) p $a
$14 = {0, 0, 0}
like image 36
firo Avatar answered Sep 23 '22 21:09

firo