From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id KD9+DJU+B2vIuT0AWB0awg (envelope-from ) for ; Wed, 25 Nov 2026 15:01:25 -0500 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=aG/dfmQN; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 2129E1E023; Wed, 25 Nov 2026 15:01:25 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_SBL_CSS,WEIRD_PORT autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [IPv6:2620:52:6:3111::32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 71BC31E023 for ; Wed, 25 Nov 2026 15:01:23 -0500 (EST) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B8B434681817 for ; Wed, 25 Nov 2026 20:01:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B8B434681817 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=aG/dfmQN Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 8FE1F4681817 for ; Wed, 25 Nov 2026 20:00:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8FE1F4681817 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 8FE1F4681817 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1795636845; cv=none; b=C3KGCEYFe/eMbCjiglWMnAc8aySrWXELYK9os4BKx3+l08geIZQXiZ63mm6CoeMrn/dEaHThp2d1HuJNMRTSXqPYZWnInMDkVSOX3sUbbXinlgGEIwaHniobj1gRoJ6FX5WEgSCMD+KuhYv/CXa0G2/p1rSVJfeM4dJJV1GIW3A= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1795636845; c=relaxed/simple; bh=2AhGY2cUwxRC3KRwvQRgn6v6GUwNVUSo+9JHNDinNnE=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=kd2jg7HRWvWAwvHjdj8O7f3/GqKFqdSB0IQORhTVMizetjZQGTEulJ1mtmBLrOBssICONPX7oC9bQTllTR3f9vQquCsrvGHHbqEuQXX4zzxu0schmDJXmfNeQmSBHJvHmy6RgmHx9zO+8B1RE4Babef35jpR0ZFFcVOCOAE4A34= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=aG/dfmQN DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8FE1F4681817 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1795636845; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Rww0BCQOQivliCVFgfMs0BP2I+0eWl/aSp5d9jKkT1Y=; b=aG/dfmQN1z9sZp4XLf1WvskdtLhFIf34Y2KnBnBBkTGKMf454YUs9eXTYJDJ+q1y81pDV9 Tk5bhfd4P+bEjLNT30UVia2n4Hb55DWBNpXsOygiwr6VYrYgEi65rt2tlG1PDomNYjJs5v mHCxY55UODX3RI9re+ivNSRtZBkeTj8= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-44-4-K-VDX9P0uIEMlYrnyGfg-1; Wed, 25 Nov 2026 20:00:42 +0000 X-MC-Unique: 4-K-VDX9P0uIEMlYrnyGfg-1 X-Mimecast-MFC-AGG-ID: 4-K-VDX9P0uIEMlYrnyGfg_1795636841 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 919221955DC2 for ; Wed, 25 Nov 2026 20:00:36 +0000 (UTC) Received: from [100.90.172.125] (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A48531800548; Wed, 25 Nov 2026 20:00:35 +0000 (UTC) Message-ID: <54e4250f-99b3-4eb2-889b-17c82672b864@redhat.com> Date: Wed, 25 Nov 2026 13:00:33 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3] Add infcall support for C++ constructor-style expressions/casts To: Keith Seitz , gdb-patches@sourceware.org References: <04cf7b0e8ecb77bf2ab49e6854542273c85ebcba.1792687980.git.keiths@redhat.com> From: Kevin Buettner In-Reply-To: <04cf7b0e8ecb77bf2ab49e6854542273c85ebcba.1792687980.git.keiths@redhat.com> X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 9ggGS_PQNEY_okYAH9q_ffOLRkOh4yPFVlDXBVgUapc_1795636841 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org 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)