From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id EZ1DN67sBmsg2zwAWB0awg (envelope-from ) for ; Wed, 25 Nov 2026 09:11:58 -0500 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=j9B0iSF1; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id DE09D1E166; Wed, 25 Nov 2026 09:11:58 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-6.4 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 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 34BB11E09B for ; Wed, 25 Nov 2026 09:11:58 -0500 (EST) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B59BA45941A7 for ; Wed, 25 Nov 2026 14:11:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B59BA45941A7 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=j9B0iSF1 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.18]) by sourceware.org (Postfix) with ESMTPS id 1E21846AFF0F for ; Wed, 25 Nov 2026 14:10:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1E21846AFF0F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=intel.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 1E21846AFF0F Authentication-Results: sourceware.org; arc=none smtp.remote-ip=198.175.65.18 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1795615860; cv=none; b=Wf4voCltCY4F6syqndyIZZ3/DKmeWFCzQA/TUv/+AfPgQJpBBJOeoEk8zmiZhDZml8iCDGCA3+eDd0OMb33AHT6t3brwnYW7D4n7e6bOezosgDDEP67BKwkMIxm4E81ppE6uTz+mkVPYXLky0e+YLVRrIlNkQkiaWwiTMpb0fDc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1795615860; c=relaxed/simple; bh=+d7Zm6cYv5NfBebjp3WV0W9pQZ+9Yyj5XKOCNZlVrFc=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=JoDCByEb+7J6GCr+fAsHuEWnx6CezvWhdyll7/eT1ma888bN9XexpqACpxFm59SnigPOwbKD8mbva95G3l6ucgZmbQ8CzMqdcu7DrIvn5xb5pN8jhs4FsPWXBklGGgXUIOUk1NrBkghknOdmt0X6yT/yvC0Oeva6ZWAgJDuFgSs= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=j9B0iSF1 DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1E21846AFF0F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1795615860; x=1827151860; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=+d7Zm6cYv5NfBebjp3WV0W9pQZ+9Yyj5XKOCNZlVrFc=; b=j9B0iSF1UpB/0sdxnPUHwFCv6KB5Wf0DY1YtAyjyh5tKKr7WDFq8Cdv8 UfnWbH3gF7ULy0D0GNYQIl1eJGdI+rNQrjAZ1G4KyAfpm/KG9no53qEAU JYpuNwMH945f+0KlAYBJNQbuPZ3O7dhlNh1T2NbYnPE7/CVDKiEuE0Er9 qlZb1Zl4aKEYx1F5eDXrn3Xf/6q9PShxtTv7KV5YA9VSxPrNSmYtYo32Z bQydaXN+H77V4lwWze2Jj0odFUG3VsXymn0GWNCsK73jMh6AVgSQisECu Ac3t4DGxGAlvS9yvRiqKAK/8yyDW3HrsSdxahwQGtY05ITjbd/RP+HgUx g==; X-CSE-ConnectionGUID: nVHCYdBKQzGY56yq4OUoQQ== X-CSE-MsgGUID: SA0Q8y0cT7qsuY/Zglug7A== X-IronPort-AV: E=McAfee;i="6800,10657,11977"; a="4513357" X-IronPort-AV: E=Sophos;i="6.27,233,1787036400"; d="scan'208";a="4513357" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Nov 2026 06:10:57 -0800 X-CSE-ConnectionGUID: RgnxgBl3TrKHrrB4gqN9kw== X-CSE-MsgGUID: /i6TpVWzTDqOsQ9/zC8TYw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,233,1787036400"; d="scan'208";a="12198652" Received: from dut1048pvc.igk.intel.com (HELO localhost) ([10.211.177.228]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Nov 2026 06:10:57 -0800 From: Stephan Rohr To: gdb-patches@sourceware.org Subject: [PATCH v2 1/1] gdb: discard saved state on error in recursive infcall Date: Wed, 25 Nov 2026 14:10:43 +0000 Message-ID: <20261125141043.178239-2-stephan.rohr@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261125141043.178239-1-stephan.rohr@intel.com> References: <20261125141043.178239-1-stephan.rohr@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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 From: "Rohr, Stephan" GDB invokes a ctor for all arguments not trivially copyable in an inferior call. The caller's registers and other state are restored, even if an exception inside the callee is raised. This hides the correct frame from the user in certain scenarios, e.g., when switching inferiors. The extra frame-cache reinit re-reads the restored registers such that 'backtrace' only shows the 'main' frame instead of the breakpoint hit in the inferior call. Discard the saved state on gdb_exception_error when invoking the ctor in inferior calls. --- gdb/infcall.c | 23 +++++++++++++++++++++-- gdb/testsuite/gdb.cp/pass-by-ref-2.exp | 22 ++++++++++++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/gdb/infcall.c b/gdb/infcall.c index 5f27f5ad259..de641a05675 100644 --- a/gdb/infcall.c +++ b/gdb/infcall.c @@ -1410,8 +1410,27 @@ call_function_by_hand_dummy (struct value *function, "constructor for the type '%s' could not be found " "(maybe inlined?)"), param_type->name ()); - call_function_by_hand (copy_ctor, default_return_type, - gdb::make_span (cctor_args, 2)); + try + { + call_function_by_hand (copy_ctor, default_return_type, + gdb::make_span (cctor_args, 2)); + } + catch (const gdb_exception_error &) + { + /* We hit an error in the ctor. + + Discard inferior status, we're not at the same point + we started at. */ + discard_infcall_control_state (inf_status.release ()); + + /* The nested call of the copy constructor may have set up a + dummy frame before throwing the error. Restoring the + caller's registers would leave that dummy frame unreachable + by the unwinder once the frame cache is invalidated. */ + discard_infcall_suspend_state (caller_state.release ()); + + throw; + } } /* If the argument has a destructor, remember it so that we diff --git a/gdb/testsuite/gdb.cp/pass-by-ref-2.exp b/gdb/testsuite/gdb.cp/pass-by-ref-2.exp index 3d704635901..42b67c1fba1 100644 --- a/gdb/testsuite/gdb.cp/pass-by-ref-2.exp +++ b/gdb/testsuite/gdb.cp/pass-by-ref-2.exp @@ -109,8 +109,30 @@ gdb_breakpoint $bp_location gdb_test "print cbvArrayContainerByRef (arrayContainerByRef)" \ ".*The program being debugged stopped.*" \ "call cbvArrayContainerByRef with BP" + +# Switching inferiors reinitializes the frame cache. +gdb_test "add-inferior" +gdb_test "inferior 2" +gdb_test "inferior 1" + gdb_test "backtrace" [multi_line \ "#0 ByRef\:\:ByRef .* at .*$srcfile:$bp_location" \ "#1 .* ArrayContainerByRef::ArrayContainerByRef .*" \ "#2 " \ "#3 main.*"] + +# Test GDB is able to finish the abandoned inferior call. + +delete_breakpoints + +gdb_test "finish" [multi_line \ + "Run till exit from #0 ByRef\:\:ByRef .* at .*$srcfile:$bp_location" \ + ".* in ArrayContainerByRef::ArrayContainerByRef .* at .*$srcfile:.*"] \ + "finish frame #0" + +gdb_test "finish" [multi_line \ + "Run till exit from #0 .* in ArrayContainerByRef::ArrayContainerByRef .* at .*$srcfile:.*" \ + "main \\(\\) at .*$srcfile:.*"] \ + "finish frame #1" + +gdb_continue_to_end -- 2.43.0 ________________________________________ Intel Deutschland GmbH Registered Address: Dornacher Strasse 1, 85622 Feldkirchen, Germany Tel: +49 (89) 99143-0 www.intel.de Managing Directors: Candice Moore, Jeffrey Schneiderman, Ramachandran Sitaraman Chairperson of the Supervisory Board: Sonja Pierer Registered Seat: Munich Commercial Register B: Amtsgericht Munich HRB 186928 This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.