I tried to debug Va_list argument and print the variable value sample code is :
#include <stdarg.h>
#include <stdio.h>
double average(int count, ...)
{
va_list ap;
int j;
double sum = 0;
va_start(ap, count); /* Requires the last fixed parameter (to get the address) */
for (j = 0; j < count; j++) {
sum += va_arg(ap, int); /* Increments ap to the next argument. */
}
va_end(ap);
return sum / count;
}
int main(int argc, char const *argv[])
{
printf("%f\n", average(3, 1, 2, 3) );
return 0;
}
so i tried to debug ap va_list argument and i wrote
(gdb) p *(int *)(((char *)ap[0].reg_save_area)+ap[0].gp_offset)
but i get as result from GDB
Attempt to dereference a generic pointer.
here is an image for the result:

When you stopped at line 8 in gdb, this line of code was not yet executed:
va_start(ap, count); /* Requires the last fixed parameter (to get the address) */
Therefore ap variable was not yet initialized and you can't print it. You should execute next line of code and print ap once again:
(gdb) n
9 for (j = 0; j < count; j++) {
(gdb) p *(int *)(((char *)ap[0].reg_save_area)+ap[0].gp_offset)
$1 = 1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With