0

When stepping through functions one can end up in a function with a definition like handle_error (const char *fmt, ...).

How can I access the varargs for constructing a message to be seen in the GDB console?

Note: I do know from the implementation that it does

    va_list         ap;

    va_start (ap, fmt);
    vfprintf (stderr, fmt, ap);
    va_end (ap);

So the first though was to just call those functions - which isn't possible as va_start is a compiler builtin:

(gdb) call (void)va_start (ap, fmt)
No symbol "__builtin_va_start" in current context.
(gdb) call (int)vfprintf (stderr, fmt, ap)

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff6c0ada1 in vfprintf () from target:/usr/lib64/libc.so.6
The program being debugged was signaled while in a function called from GDB.
GDB remains in the frame where the signal was received.

To put that into the GDB console I guess I'd have to vsprintf to a temporary variable and then use that for output - but as all varargs functions need an initialized va_list...

The GDB is python enabled, but I didn't found any reasonable python handling for C varargs either...

Simon Sobisch
  • 6,263
  • 1
  • 18
  • 38
  • Print to a large string using `vsprintf` so you can see the message, then send the string to stderr. – Paul Ogilvie Mar 02 '21 at 11:30
  • Sounds good, but to do so I need an initialized va_list - and the "regular" way of achieving this is to use `va_start` which cannot be called from GDB... – Simon Sobisch Mar 02 '21 at 11:33
  • I have absolutely no idea how that other question's answer applies to this. The only solution given is "step until ´va_start` is executed" (which is explicit NOT what I can do here) and a workaround of effectively using `up` and inspect the 1 to possibly hundred arguments, which then likely comes as function return values that I don't want to execute because of its side effects)? – Simon Sobisch Mar 02 '21 at 11:42
  • If you are on Linux, maybe [this](https://stackoverflow.com/a/42073828/1983398) works for you. – ssbssa Mar 02 '21 at 11:55
  • that one only works reliably with a manual `jump` to the instruction that does this (which is only be possible in gdb commands if the source is available/not changed), then do the print, then `jump` to `va_end`, then `jump` back. It is likely the way I'll go in this specific case but I'd still would see a generic option (possibly calling `va_start` not from the builtin but from libc - if there's any [at least `objdump` showed nothing that looked right]). – Simon Sobisch Mar 02 '21 at 13:05

0 Answers0