From: Kevin Buettner <kevinb@redhat.com>
To: Keith Seitz <keiths@redhat.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH v3] Add infcall support for C++ constructor-style expressions/casts
Date: Wed, 25 Nov 2026 13:00:33 -0700 [thread overview]
Message-ID: <54e4250f-99b3-4eb2-889b-17c82672b864@redhat.com> (raw)
In-Reply-To: <04cf7b0e8ecb77bf2ab49e6854542273c85ebcba.1792687980.git.keiths@redhat.com>
On 10/22/26 10:00 AM, Keith Seitz wrote:
> This patch adds an initial try at teaching the expression parser/evaluator
> to construct temporary objects requiring construction during an inferior
> function call.
>
> To accomplish this, I've chosen the route of modifying the parser to
> teach it that `Type(args)' is a function call when `Type' names a
> class/struct/union and is immediately followed by '(', that is, via look-
> ahead. A new parser token and grammar rule have been added to deal
> with this new production.
>
> The real work is dispatched to `type_operation::evaluate_funcall',
> allocating memory for the temporary and finding the most suitable constructor
> with `find_overload_match'. It then runs the inferior call, returning
> the newly constructed object.
>
> I've included many tests covering as many corner cases as I could invent,
> and these tests are clang clean. They also introduce no regressions on
> x86-64 Fedora 43 with GCC 15.2.1 and RHEL 9.4 with GCC 11.5.0.
>
> Example:
> Consider a C++ frame where 'struct S { int x; S(int); ... }' is in scope
>
> Before:
> (gdb) print S(42)
> ❌ A syntax error in expression, near `42)'.
>
> After:
> (gdb) print S(42)
> $1 = {x = 42}
>
> Note that no attempt has been made to deal with templates. Hopefully
> a follow-on patch can address that.
>
> Changes since v2:
> - Rework parser rules to eliminate previously added SR/RR conflicts.
> - Add TYPEOF_CTOR with lexer lookahead to handle typeof(T)(args) and
> typeof(expr)(args)
> - Implement functional-cast / value-init semantics (Type(arg), Type())
> - Address misc review comments from Kevin and Andrew
I had an AI reviewer look at it. It found a way to cause an internal
error. This was its demonstration, when I asked for one:
kevinb-claude@claude-1:~$ mkdir -p /tmp/ctor-demo && cd /tmp/ctor-demo
&& cp
/home/kevinb-claude/reviews/20261125-infcall-cxx-ctor-v3/probe/z2.cc .
&& cat z2.cc && g++ -g -O2 -o z2 z2.cc && nm -C z2 | grep 'Z::Z' ; echo
"(no Z::Z symbol above = ctor inlined away)"
struct Z { int x; Z () : x (0) {} };
int main () { Z z; return z.x; }
(no Z::Z symbol above = ctor inlined away)
kevinb-claude@claude-1:ctor-demo$
/home/kevinb-claude/builds/infcallv3-patched-install/bin/gdb -q -nx -iex
'set debuginfod enabled off' ./z2
Reading symbols from ./z2...
(gdb) start
Temporary breakpoint 1 at 0x400360: file z2.cc, line 2.
Starting program: /tmp/ctor-demo/z2
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
Temporary breakpoint 1, main () at z2.cc:2
2 int main () { Z z; return z.x; }
(gdb) ptype Z
type = struct Z {
int x;
Z(void);
}
(gdb) p Z()
/home/kevinb-claude/binutils-gdb-infcallv3/gdb/eval.c:1939:
internal-error: evaluate_funcall: Assertion `callee != nullptr' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
----- Backtrace -----
0x5296d9 gdb_internal_backtrace_1
/home/kevinb-claude/binutils-gdb-infcallv3/gdb/bt-utils.c:122
0x5296d9 _Z22gdb_internal_backtracev
/home/kevinb-claude/binutils-gdb-infcallv3/gdb/bt-utils.c:173
0xa2b164 internal_vproblem
/home/kevinb-claude/binutils-gdb-infcallv3/gdb/utils.c:437
0xa2b5d8 _Z15internal_verrorPKciS0_P13__va_list_tag
/home/kevinb-claude/binutils-gdb-infcallv3/gdb/utils.c:517
0xb9eed1 _Z18internal_error_locPKciS0_z
/home/kevinb-claude/binutils-gdb-infcallv3/gdbsupport/errors.cc:57
0x68f36f
_ZN4expr14type_operation16evaluate_funcallEP4typeP10expression6nosideRKSt6vectorISt10unique_ptrINS_9operationESt14default_deleteIS8_EESaISB_EE
/home/kevinb-claude/binutils-gdb-infcallv3/gdb/eval.c:1939
0x68af2e _ZN10expression8evaluateEP4type6noside
/home/kevinb-claude/binutils-gdb-infcallv3/gdb/eval.c:110
0x8051fe process_print_command_args
/home/kevinb-claude/binutils-gdb-infcallv3/gdb/printcmd.c:1352
0x805778 print_command_1
/home/kevinb-claude/binutils-gdb-infcallv3/gdb/printcmd.c:1365
0x572527 _Z8cmd_funcP16cmd_list_elementPKci
/home/kevinb-claude/binutils-gdb-infcallv3/gdb/cli/cli-decode.c:2810
0x99d794 _Z15execute_commandPKci
/home/kevinb-claude/binutils-gdb-infcallv3/gdb/top.c:628
0x6926df _Z15command_handlerPKc
/home/kevinb-claude/binutils-gdb-infcallv3/gdb/event-top.c:611
0x694baa _Z20command_line_handlerOSt10unique_ptrIcN3gdb13xfree_deleterIcEEE
/home/kevinb-claude/binutils-gdb-infcallv3/gdb/event-top.c:844
0x69385d gdb_rl_callback_handler
/home/kevinb-claude/binutils-gdb-infcallv3/gdb/event-top.c:288
0xa7a920 rl_callback_read_char
/home/kevinb-claude/binutils-gdb-infcallv3/readline/readline/callback.c:302
0x6939fd gdb_rl_callback_read_char_wrapper_sjlj
/home/kevinb-claude/binutils-gdb-infcallv3/gdb/event-top.c:197
0x693c6d gdb_rl_callback_read_char_wrapper_noexcept
/home/kevinb-claude/binutils-gdb-infcallv3/gdb/event-top.c:240
0x693c6d gdb_rl_callback_read_char_wrapper
/home/kevinb-claude/binutils-gdb-infcallv3/gdb/event-top.c:252
0x9e6d8f stdin_event_handler
/home/kevinb-claude/binutils-gdb-infcallv3/gdb/ui.c:161
0xb9fcd5 gdb_wait_for_event
/home/kevinb-claude/binutils-gdb-infcallv3/gdbsupport/event-loop.cc:694
0xba0a9f _Z16gdb_do_one_eventi
/home/kevinb-claude/binutils-gdb-infcallv3/gdbsupport/event-loop.cc:263
0x79e0e1 _ZN6interp12do_one_eventEi
/home/kevinb-claude/binutils-gdb-infcallv3/gdb/interps.h:90
0x79e0e1 start_event_loop
/home/kevinb-claude/binutils-gdb-infcallv3/gdb/main.c:401
0x79e0e1 captured_command_loop
/home/kevinb-claude/binutils-gdb-infcallv3/gdb/main.c:466
0x7a1f64 captured_main
/home/kevinb-claude/binutils-gdb-infcallv3/gdb/main.c:1373
0x7a1f64 _Z8gdb_mainP18captured_main_args
/home/kevinb-claude/binutils-gdb-infcallv3/gdb/main.c:1392
0x44d9a4 main
/home/kevinb-claude/binutils-gdb-infcallv3/gdb/gdb.c:38
---------------------
/home/kevinb-claude/binutils-gdb-infcallv3/gdb/eval.c:1939:
internal-error: evaluate_funcall: Assertion `callee != nullptr' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Quit this debugging session? (y or n)
prev parent reply other threads:[~2026-11-25 20:01 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-26 19:17 [PATCH] Add infcall support for C++ constructor-style expressions Keith Seitz
2026-03-27 5:50 ` Eli Zaretskii
2026-04-21 13:41 ` Andrew Burgess
2026-04-21 18:13 ` Keith Seitz
2026-04-27 16:43 ` [PATCH v2] " Keith Seitz
2026-06-19 17:21 ` Keith Seitz
2026-06-27 0:06 ` Kevin Buettner
2026-07-29 17:44 ` Keith Seitz
2026-09-17 14:41 ` Andrew Burgess
2026-09-17 16:05 ` Keith Seitz
2026-09-17 15:10 ` Andrew Burgess
2026-10-22 17:00 ` [PATCH v3] Add infcall support for C++ constructor-style expressions/casts Keith Seitz
2026-11-25 20:00 ` Kevin Buettner [this message]
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=54e4250f-99b3-4eb2-889b-17c82672b864@redhat.com \
--to=kevinb@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=keiths@redhat.com \
/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: link
Be 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