Debugging variable arguments functions (stdarg)

Petr Hluzín
Fri Jul 16 18:58:00 GMT 2010

On 15 July 2010 17:47, G <> wrote:
> Hello,
> How can I look at the values of "..." in a function which can
> take a variable number of arguments (i.e. uses va_start(),
> va_end() etc.) in gdb?

There is no nice way to do that. GCC does not record the actual types
used in a call site of a variadic function, e.g. what is on the
call-site of WriteLog(int,int,char*,...) in MysqlWrapper.

Workaround A:
Alter source code of the caller to:
const char * msg = mysql_error(sql_handle)
WriteLog(stuff1,stuff1,stuff3, query, msg);
and hope the compiler does not optimize the local variable.

Workaround B:
Get value of stack pointer (RSP?) of frame MysqlWrapper() and dump raw
memory around the address. You should see these values somewhere
0x00000000004041e2 (return address in MysqlWrapper)
0x406bf0 (the third argument to WriteLog)
Between these two values should be the values of 3rd and 4th argument.
(You have to cast them to char*.)

Petr Hluzin

More information about the Gdb mailing list