This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Debugging variable arguments functions (stdarg)


On 15 July 2010 17:47, G <tjmadwja@gmail.com> 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
around:
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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]