KeithSmith
KeithSmith

Reputation: 774

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

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.

Upvotes: 5

Views: 7958

Answers (2)

firo
firo

Reputation: 1062

Yes, you can.

For example,

(gdb) set $a = (int [3]) {0}
(gdb) p $a
$14 = {0, 0, 0}

Upvotes: 3

Tom Tromey
Tom Tromey

Reputation: 22549

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

Upvotes: 4

Related Questions