Using addresses of convenience variables in GDB

Viewed 358

Sometimes I come across functions that I want to call in my debugging that take a pointer as an argument and change the contents that are pointed to. Example:

int doFoo(int a, double* b)

I would like to call this function from gdb, but don't have a double* lying around. Is it possible to do this with convenience variables? Simply calling

set $foo = 1.0
call doFoo(0, &($foo))

does not work.

1 Answers

This appears to work:

set var $foo = &{1.0}
call doFoo(0, $foo)
p *$foo

Using {} makes GDB allocate a single item double array within the process's memory. Note that without & in the assignment, evaluating $foo will return a new address every time.

Related