public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/28589] New: cannot call a variadic C++ function
@ 2021-11-12 21:06 msebor at gmail dot com
  2021-11-13 17:13 ` [Bug c++/28589] " ssbssa at sourceware dot org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: msebor at gmail dot com @ 2021-11-12 21:06 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=28589

            Bug ID: 28589
           Summary: cannot call a variadic C++ function
           Product: gdb
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
          Assignee: unassigned at sourceware dot org
          Reporter: msebor at gmail dot com
  Target Milestone: ---

I'm sure this must be a known bug, but it makes debugging GCC (and presumably
other C++ code that uses its own printf-style message formatting) hard.  I've
found no way to call from within GDB a printf-like function defined in a C++
program except with no variable arguments.  Below is a simple test case.  It
works fine in C but not in C++.  GCC is a C++ code base that defines variadic
functions to print messages.  It's often convenient to display this or that
piece of internal data the way it would be presented to the user when formatted
by one of these functions.  But in GDB 11.1 it still doesn't appear to be
possible.

$ gcc -g -xc++ z.C && gdb -batch --silent -ex "break main" -ex "run" -ex step
-ex 'p print("x = %i\n", x)' a.out
#include <stdarg.h>
#include <stdio.h>

void printv (const char *f, va_list va)
{
  int x = va_arg (va, int);
  printf (f, x);
}


void print (const char *f, ...)
{
  va_list va;
  va_start (va, f);
  printv (f, va);
  va_end (va);
}

int main ()
{
  int x = 123;
  print ("x = %i\n", x);
}
gdb: warning: Couldn't determine a path for the index cache directory.
warning: File "/ssd/build/tmp/.gdbinit" auto-loading has been declined by your
`auto-load safe-path' set to "$debugdir:$datadir/auto-load".
To enable execution of this file add
        add-auto-load-safe-path /ssd/build/tmp/.gdbinit
line to your configuration file "$HOME/.gdbinit".
To completely disable this security protection add
        set auto-load safe-path /
line to your configuration file "$HOME/.gdbinit".
For more information about this security protection see the
"Auto-loading safe path" section in the GDB manual.  E.g., run from the shell:
        info "(gdb)Auto-loading safe path"
Breakpoint 1 at 0x401241: file z.C, line 21.

Breakpoint 1, main () at z.C:21
21        int x = 123;
22        print ("x = %i\n", x);
Cannot resolve function print to any overloaded instance

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-12-14 15:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-12 21:06 [Bug c++/28589] New: cannot call a variadic C++ function msebor at gmail dot com
2021-11-13 17:13 ` [Bug c++/28589] " ssbssa at sourceware dot org
2023-12-14 15:19 ` cvs-commit at gcc dot gnu.org
2023-12-14 15:21 ` ssbssa at sourceware dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).