From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id uSMlDmeHqWlhjxYAWB0awg (envelope-from ) for ; Thu, 05 Mar 2026 08:38:47 -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=Th9paio0; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 3461E1E0DD; Thu, 05 Mar 2026 08:38:47 -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.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,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED 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 704381E089 for ; Thu, 05 Mar 2026 08:38:46 -0500 (EST) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 311BC4BA2E3D for ; Thu, 5 Mar 2026 13:38:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 311BC4BA2E3D 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=Th9paio0 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 417284BA23CB for ; Thu, 5 Mar 2026 13:37:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 417284BA23CB 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 417284BA23CB Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1772717861; cv=none; b=SiDsNTKI/3Fl2DRI5FhjMLdZurMc3sWdxq24NCqXofwknJbMkh3UtGqjb6H+9fEa2rAwj9nXyHbTkHkdHsur+oDHA4niZEtt1ZtyZs/VUVgeL2N7S8mSeI0MOYhezARCppm98xY22YVZmUCTG6Jp+haRLMDsGC+C4WJ5/UtdQTY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1772717861; c=relaxed/simple; bh=Gni80yrnth2VcnCfxkiuDlVIae3G4rR9lu/g7tvfTHA=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=HWt+5FjzutFTH3rFN3Oe5KosLIEviV9rfca3jJsuZ8SjE03KXv/lCvly2Z4pXZUlzw7OLrro6mNtLjPubSuwU3Ub9Ltze/O7ny/2viqPz5jVSwB/2OtDUiErGjbXFJtsxkvEc7LxKOYQWz06ls6ScuFJIb2X1E6NJUYRUJVr/9I= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 417284BA23CB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1772717855; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eLwlkJmqzBqoqnQd2wW03yU+dtDhiXiQhhvwFM+citM=; b=Th9paio0qa4N0w6O/a+/nL92Ii6ofIv1Zp+kapdiEdyE7F2wEKdY96ppHRQCJ+l3ABDEd3 N5VThyIiNO2maPG1CWeaIXBczjD7/+wNjrR9tD8WjqSXNzPUzNJijj7AS2YemF+kL+mhMJ x4OigODHge7qzcc8qovoGvu+djgiYP8= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-81-HYC8L9lxN9yEFqZwUBdsig-1; Thu, 05 Mar 2026 08:37:31 -0500 X-MC-Unique: HYC8L9lxN9yEFqZwUBdsig-1 X-Mimecast-MFC-AGG-ID: HYC8L9lxN9yEFqZwUBdsig_1772717850 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4839fc4cef6so79741395e9.0 for ; Thu, 05 Mar 2026 05:37:30 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772717850; x=1773322650; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=eLwlkJmqzBqoqnQd2wW03yU+dtDhiXiQhhvwFM+citM=; b=JkQtSp5O75Pztf7FSINgbSBGn6xS61Hxw+KWeRWmv2frpNu6XCatfUsAhXPgX2auzU Y2ZbDkUErl6P8FgtkIdq4BRMiZvaXu7LZpcXq63OhV88V4Qpj1e3ubyLFlbnelhMmFZP EkgC1EHSxQPpibkRdEDwHMEjdYXXqPaYWJjN3Kh8W+zVshZwkD0nmvysTZO+uUXtwDL9 8NkjMgE6LOG/AEqy8nFoimAT5zOxqn6V3fFTNjmbtDFYemFA3uNzf8idQOpk3DtZSRo+ kCOISB2BsidYCzFKE7BhFRBm75J0rdsVZaF6AC7WfuvTwbOMACPs3H5z58y3LB+WbEuA Xbkg== X-Gm-Message-State: AOJu0YwfQYEtDK2vDgvcnvLFthU/iBuxfGeifp0qcWOc00VVTQLqIJmX XUfoLv2YNiKUSKQ0dVu1j8otIcw2r73J9CiDBUgcpqjRkpo8vAMXaW/X3SBZAljmCUCYtcmjcXz HFDfaNUSXcAlCyKG2UNsUA61/b41lANMcvPjq1rsqklafkDm9dKWXewhcg+mnK454Css096znoA N27HQOE/cxcL9fFCh2LG2fG7NcMS8rK2+XLJI+1CnyORicVWE= X-Gm-Gg: ATEYQzz/vZMUhjDwt+mk9A/xNvFbdHrEuAKrTwAhvhgYBR6HQNLLIMye3ha0Y9EIBbx UULwRuwcUcxNjRZD6lsz28+r7EoOQ7kMi32Er9lpIxoh10SBOv/3iI0wOBNWel3m1RqdjhDJMXu IuhsrF2ivq+jRW3hwWfVYWL7NXrRKE53ussP2HzMswV4RqhBQ4SgM4+NuLcprO8JObkNlaDmwtm IVb21Q4Z0emi/MIByvVg1BOWINBlFKXY8Q8xIWfx0b6tP8wNEvG6hPQiM0rbxFXcKYipoa4J0qr 80l6wZWeRX9iByk+oJ8k5g6Uw2PVtaAIeg930VD9mXAR5qHFYLAwKoZegqWB1zizEROZfrPM8ZS YaihN0V1136wkkdF/ X-Received: by 2002:a05:600c:c165:b0:47e:e981:78b4 with SMTP id 5b1f17b1804b1-4851ee974f9mr38548975e9.12.1772717849588; Thu, 05 Mar 2026 05:37:29 -0800 (PST) X-Received: by 2002:a05:600c:c165:b0:47e:e981:78b4 with SMTP id 5b1f17b1804b1-4851ee974f9mr38548535e9.12.1772717849040; Thu, 05 Mar 2026 05:37:29 -0800 (PST) Received: from localhost ([31.111.84.232]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4851ad1656bsm41308935e9.24.2026.03.05.05.37.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Mar 2026 05:37:27 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv2 4/4] gdb/python: fix gdb.FinishBreakpoint returning to a tail call frame Date: Thu, 5 Mar 2026 13:37:18 +0000 Message-Id: X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: XO9khwDetcLfEbOFkABqHOqu80Bax2yeLZqJ8DfgJTw_1772717850 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true 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 I noticed that gdb.FinishBreakpoint doesn't work if the parent function is a tail call function. In bpfinishpy_init we use get_frame_pc to find the address at which the finish breakpoint should be placed within the previous frame. However, if the previous frame is a tail call frame, then get_frame_pc will return an address outside of the tail call function, an address which will not be reached on the return path. Unlike other recent tail call fixes I've made, we cannot switch to using something like get_frame_address_in_block here as in the tail call case this will return an address within the function, but not an address that will be executed when we return. What we need to do in the tail call case is create the finish breakpoint in the frame that called the tail call function. Or if that frame is itself a tail call, then we should walk back up the call stack until we find a non-tail call function. This can be achieved by adding a call to skip_tailcall_frames into bpfinishpy_init after our existing call to get_prev_frame. I've extended the existing test case to cover this additional situation. --- gdb/python/py-finishbreakpoint.c | 3 ++ .../py-finish-breakpoint-tailcall.exp | 29 +++++++++++++++---- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/gdb/python/py-finishbreakpoint.c b/gdb/python/py-finishbreakpoint.c index 834f85037c0..fbbb705a864 100644 --- a/gdb/python/py-finishbreakpoint.c +++ b/gdb/python/py-finishbreakpoint.c @@ -201,6 +201,9 @@ bpfinishpy_init (PyObject *self, PyObject *args, PyObject *kwargs) else { prev_frame = get_prev_frame (frame); + if (prev_frame != nullptr) + prev_frame = skip_tailcall_frames (prev_frame); + if (prev_frame == nullptr) { PyErr_SetString (PyExc_ValueError, diff --git a/gdb/testsuite/gdb.python/py-finish-breakpoint-tailcall.exp b/gdb/testsuite/gdb.python/py-finish-breakpoint-tailcall.exp index 2ae61f389ef..6a266abd790 100644 --- a/gdb/testsuite/gdb.python/py-finish-breakpoint-tailcall.exp +++ b/gdb/testsuite/gdb.python/py-finish-breakpoint-tailcall.exp @@ -40,9 +40,17 @@ if {[build_executable "failed to build" $testfile $srcfile \ # For remote host testing. set pyfile [gdb_remote_download host ${srcdir}/${subdir}/${testfile}.py] -# Run to 'normal_function' and then try to create a FinishBreakpoint -# in the parent frame. -proc run_test {} { +# Run to 'normal_function' and then try to create a FinishBreakpoint. +# +# When USE_PARENT_FRAME_P is true we use the parent frame, which is +# for tailcall_function, to create the FinishBreakpoint. +# +# When USE_PARENT_FRAME_P is false we use the frame of normal_function +# to create the FinishBreakpoint. +# +# In both cases the finish breakpoint should be placed back in main, +# which is where the inferior should stop when resumed. +proc run_test { use_parent_frame_p } { clean_restart $::testfile if {![runto normal_function]} { @@ -59,7 +67,16 @@ proc run_test {} { gdb_test "source $::pyfile" "Python script imported" "import python scripts" set lineno [gdb_get_line_number "Temporary breakpoint here."] - gdb_test "python MyFinishBreakpoint(gdb.selected_frame().older())" \ + + if { $use_parent_frame_p } { + gdb_test_no_output "python frame=gdb.selected_frame().older()" \ + "store a reference to the parent frame" + } else { + gdb_test_no_output "python frame=gdb.selected_frame()" \ + "store a reference to the current frame" + } + + gdb_test "python MyFinishBreakpoint(frame)" \ "Temporary breakpoint $::decimal at $::hex: file \[^\r\n\]+/$::srcfile, line $lineno\\." \ "create finish breakpoint" @@ -96,4 +113,6 @@ proc run_test {} { } } -run_test +foreach_with_prefix parent_frame { true false } { + run_test $parent_frame +} -- 2.25.4