From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id NZCVIHZONWr0ag8AWB0awg (envelope-from ) for ; Fri, 19 Jun 2026 10:13:10 -0400 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=EdcQlYIQ; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 6F5641E091; Fri, 19 Jun 2026 10:13:10 -0400 (EDT) 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 [38.145.34.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 77E4C1E091 for ; Fri, 19 Jun 2026 10:13:09 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0F6534BAE7E6 for ; Fri, 19 Jun 2026 14:13:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0F6534BAE7E6 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=EdcQlYIQ Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) by sourceware.org (Postfix) with ESMTPS id 6BE164BAD17B for ; Fri, 19 Jun 2026 14:12:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6BE164BAD17B 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 6BE164BAD17B Authentication-Results: sourceware.org; arc=none smtp.remote-ip=198.175.65.10 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1781878343; cv=none; b=a6fN/PROgB/feL1v+ZYtyrfEI1PzGhlOt/HvnEMusqSOHuYWSVHfigC/BRQNIZIWbaUVcYSTBNP4UMzqkOsEz5YCsFhlEw6Ovuc9k7frGDCu3VORjfDFS9S1Hipzfjw3EDHI96dEQ3tSryMZeTyg5eJaL9uDmV9xAx+f32lNV6g= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1781878343; c=relaxed/simple; bh=TKKJ1b361qrkBciF9/dUXE1dn2DWgP63dG8duSN2tDU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=QpVbJmilO96aXTIuOJodK7tx8mSMWm3YP3QyR/a5DgeBlqX1VkVarU1/Eqr8AHyoKifw42OtLpIK1VDgQKFuFHAz4EoRtJwvA9Pn9zGH3QVb1YhguVAHHag7IHJXQzb7F1kOwA1xpX8KpYWy5tWV239TREnbqTGssZkFVbnqOHE= 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=EdcQlYIQ DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6BE164BAD17B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1781878338; x=1813414338; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=TKKJ1b361qrkBciF9/dUXE1dn2DWgP63dG8duSN2tDU=; b=EdcQlYIQ+wNTqYE/aAQuyTXYa/4ySrD4gAXwkEDmHFVRQxYA3mSNFECx cp7LgTcRra8PPjqfzTyJhJZCBnRIl6taZLG7x0NJ3kE9U4XfGphVJMXVk cd2smzh/glogGSwU+EQsZhoA6wGKh4aJXwEl9uveci68IlPdESipgj9CZ UrytsJsmi4zK1lz+wzd7t+kCI8Z3O7TLcuoZS4XJXyMtqPTDvYCzPDo6Q 8G/Kn851sUq3QO0vSeuOn/zKAb083P9Tr6kafgk9TaElq/GqIEn3IIapS vCTmi3wRwiiS1WU07mYJtQkmIqTfe8ssPnwKVGRiPPbf8q0+WQzj/X8QZ g==; X-CSE-ConnectionGUID: 2I4zSS/lRGa//6WhRbGjNQ== X-CSE-MsgGUID: mJ7tzEHKRTebhT6QfwvqNQ== X-IronPort-AV: E=McAfee;i="6800,10657,11821"; a="100156763" X-IronPort-AV: E=Sophos;i="6.24,213,1774335600"; d="scan'208";a="100156763" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Jun 2026 07:12:18 -0700 X-CSE-ConnectionGUID: pzVaOu9uQ0Wqvohy23xIwQ== X-CSE-MsgGUID: 8+5HmuGVQOelqsVvBMS/VQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.24,213,1774335600"; d="scan'208";a="248692137" Received: from dut1049pvc.igk.intel.com (HELO localhost) ([10.211.177.244]) by orviesa007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Jun 2026 07:12:18 -0700 From: Stephan Rohr To: gdb-patches@sourceware.org Subject: [PATCH 1/1] gdb: discard saved state on error in recursive infcall Date: Fri, 19 Jun 2026 14:12:00 +0000 Message-ID: <20260619141200.97232-2-stephan.rohr@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260619141200.97232-1-stephan.rohr@intel.com> References: <20260619141200.97232-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 e6b24ff5310..e40724c6b83 100644 --- a/gdb/infcall.c +++ b/gdb/infcall.c @@ -1402,8 +1402,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_array_view (cctor_args, 2)); + try + { + call_function_by_hand (copy_ctor, default_return_type, + gdb::make_array_view (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 991 430, www.intel.de Managing Directors: Harry Demas, Jeffrey Schneiderman, Yin Chong Sorrell Chairperson of the Supervisory Board: Nicole Lau Registered Seat: Munich Commercial Register: Amtsgericht Muenchen HRB 186928