public inbox for gdb-prs@sourceware.org help / color / mirror / Atom feed
From: "msebor at gmail dot com" <sourceware-bugzilla@sourceware.org> To: gdb-prs@sourceware.org Subject: [Bug c++/28589] New: cannot call a variadic C++ function Date: Fri, 12 Nov 2021 21:06:08 +0000 [thread overview] Message-ID: <bug-28589-4717@http.sourceware.org/bugzilla/> (raw) 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.
next reply other threads:[~2021-11-12 21:06 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-11-12 21:06 msebor at gmail dot com [this message] 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
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-28589-4717@http.sourceware.org/bugzilla/ \ --to=sourceware-bugzilla@sourceware.org \ --cc=gdb-prs@sourceware.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).