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

* [Bug c++/28589] cannot call a variadic C++ function
  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 ` 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
  2 siblings, 0 replies; 4+ messages in thread
From: ssbssa at sourceware dot org @ 2021-11-13 17:13 UTC (permalink / raw)
  To: gdb-prs

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

Hannes Domani <ssbssa at sourceware dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ssbssa at sourceware dot org

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

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

* [Bug c++/28589] cannot call a variadic C++ function
  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
  2 siblings, 0 replies; 4+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-12-14 15:19 UTC (permalink / raw)
  To: gdb-prs

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

--- Comment #1 from Sourceware Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Hannes Domani <ssbssa@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=1d2f86b6b74e6caae77951353a4c353ce9816374

commit 1d2f86b6b74e6caae77951353a4c353ce9816374
Author: Hannes Domani <ssbssa@yahoo.de>
Date:   Sun Nov 14 16:19:31 2021 +0100

    Allow calling of variadic C++ functions

    Currently, it's not possible to call a variadic C++ function:
    ```
    (gdb) print sum_vararg_int(1, 10)
    Cannot resolve function sum_vararg_int to any overloaded instance
    (gdb) print sum_vararg_int(2, 20, 30)
    Cannot resolve function sum_vararg_int to any overloaded instance
    ```

    It's because all additional arguments get the TOO_FEW_PARAMS_BADNESS
    rank by rank_function, which disqualifies the function.

    To fix this, I've created the new VARARG_BADNESS rank, which is
    used only for additional arguments of variadic functions, allowing
    them to be called:
    ```
    (gdb) print sum_vararg_int(1, 10)
    $1 = 10
    (gdb) print sum_vararg_int(2, 20, 30)
    $2 = 50
    ```

    Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28589
    Approved-By: Tom Tromey <tom@tromey.com>

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

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

* [Bug c++/28589] cannot call a variadic C++ function
  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
  2 siblings, 0 replies; 4+ messages in thread
From: ssbssa at sourceware dot org @ 2023-12-14 15:21 UTC (permalink / raw)
  To: gdb-prs

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

Hannes Domani <ssbssa at sourceware dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|UNCONFIRMED                 |RESOLVED
   Target Milestone|---                         |15.1

--- Comment #2 from Hannes Domani <ssbssa at sourceware dot org> ---
Fixed.

-- 
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).