From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 8REdBFGtdGn9wRIAWB0awg (envelope-from ) for ; Sat, 24 Jan 2026 06:30: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=cemL15N4; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 0A2B71E08D; Sat, 24 Jan 2026 06:30: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.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 45CE11E08D for ; Sat, 24 Jan 2026 06:30:24 -0500 (EST) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id A24544BC8943 for ; Sat, 24 Jan 2026 11:30:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A24544BC8943 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=cemL15N4 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 D011A4BA901E for ; Sat, 24 Jan 2026 11:29:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D011A4BA901E 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 D011A4BA901E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1769254172; cv=none; b=H9raX5KhA1maNwY3As9Ger45ULuEuxjfxUBvjitDZWO6zxg4MGYZbS9vNWiU1XZFOLTsIVxok0pGITV6CmVis2vptkVUJKtMkgJnpRpsgJ2iS7SzQokEW7hi6AQVTsI/K4im4vbIhj7OQLI7X7uiVRLZFN7T20R6RwGjxEpwYSc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1769254172; c=relaxed/simple; bh=TEweKm8BxFebbHJtG4xJ/xUdm3IyvuDeL/keUQM6G7k=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=QcO41biKOv9I/Mf90ei7D7NZOA7PNz3OcKEX+4SHaQU9sS37/NJFJjvdQ7lrZ/4qN5OLD+r2CNTMkrYm5QHOjIqalo6LSVvlSKuXcYcicV9J6RaPO+qBMyStPVrGGpIDoCILzjNg5SpwAFIOL68UW5gxA9KyU9H+egMNetKiZBI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D011A4BA901E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1769254172; 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=kAqH6BW+uRn25sFAXYNsvi0haWibkSiZfuo4UTSZ4n8=; b=cemL15N4/nawwKgevjUPPwTmEpw0j1FfPKOdWbxWp/I7BDZaiKPtcBJGrMKTOf2d2WyYDL C9x/mFEWXfvGPEZeNFLnsgSg1VgQRZeeNCLv4YBjjAYsTnLnR7iUS8s6weUARzo1hANlMH ZzZ+C5HKzaAmZce/ifQUojmr3U/i1v8= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-172-q9JI9P0YNqy-U7LDj36Vqw-1; Sat, 24 Jan 2026 06:29:30 -0500 X-MC-Unique: q9JI9P0YNqy-U7LDj36Vqw-1 X-Mimecast-MFC-AGG-ID: q9JI9P0YNqy-U7LDj36Vqw_1769254170 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-430fd96b2f5so3054209f8f.3 for ; Sat, 24 Jan 2026 03:29:30 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769254169; x=1769858969; 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=kAqH6BW+uRn25sFAXYNsvi0haWibkSiZfuo4UTSZ4n8=; b=SuQlxd8uH9CMNxr9VDVboFV/BjBFxdgR5RcV80bn+/N/coxw+E4QZkTmUw+l93Qyua QpQEOC92h0VEsyXV3FLKn1pRs21XgboEZqN6+yKTnQTtisWFNV32aLpsCTSugcRd3c2o 69jU+LOrwizq+84WS98iCWK+rV6W0TUobnk6uKI5yR0HfX5qnnTzys6z3+qLQGf9ipM7 v4pbQy7ITnoZ5REwOfOVRFZUFq1UMuLt3ygHFLZ1wlHoWWtN8m7ozfpFgCStbWoJG15h 8H21oinJWMinWpHYjkRi4o1U5oYywshOJT/g6Vd4xHurmxozkzoxM0EoE3piAubvgJeN Hlbw== X-Gm-Message-State: AOJu0YxZzSBa/69Z48/fCShGx80F5NA7QPvBJlEgtUKtowWiDeuV2m// H9r678UzHV/86rVo0D4bW5PpX8zpWXWNUHcjD345dHJRx6cE6x35Le2TG4+l32BVYcWXt0qs+XL U6jV9tMLMBeb1yQX8VKmNzNTq30gVGYq3GSyu8wAISSFhu6bBH6tuYhIkxQIHtl7IuScwbiotF2 L6jd4lM2AUmMfst71n9QHYt3NP87TbdFnGwb4MP0qPLN9F6v8= X-Gm-Gg: AZuq6aK4AivXcOdO4hF9P/gvDY/Q3RLAXAFXCTruEABilxeYZgvo9OFzugtBcXP2cKB /FJE8FDIGmAH9AVIe3Zu4Ccr42L4qOlDD38Tz5ZRMpwUNBlmRqEdvx4sRCePpOr5lFOdp7dNgaz PhctoTSPmHpHQDj1TG1+ENaglGLbadXd5zgBJoTx992civrETVwEmDsDGasjSRyB2zQKlf0li4m dFuTzFNCvlFA8B1721oGaw94QmNJqdI9Iv1Qp0XMUtG6rG46m/8L23sjUbshHfw2EQW84xSL+L0 sMWiNl4ChaPd0iQHgvxzAnmuKhNnW0CcWBL7R645eByFV4FHXuF1JV3FTC/XJlQqf0b5sbA1Igk p+kLGNvz2iHP3p6VAxkWsfVlQdcM5rwo= X-Received: by 2002:a05:6000:607:b0:431:344:5a2d with SMTP id ffacd0b85a97d-435b15f8072mr9869104f8f.41.1769254169291; Sat, 24 Jan 2026 03:29:29 -0800 (PST) X-Received: by 2002:a05:6000:607:b0:431:344:5a2d with SMTP id ffacd0b85a97d-435b15f8072mr9869073f8f.41.1769254168753; Sat, 24 Jan 2026 03:29:28 -0800 (PST) Received: from localhost (92.40.184.43.threembb.co.uk. [92.40.184.43]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-435b1f7b41asm15199665f8f.39.2026.01.24.03.29.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Jan 2026 03:29:28 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 4/4] gdb/python: fix gdb.FinishBreakpoint returning to a tail call frame Date: Sat, 24 Jan 2026 11:29:14 +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: DbhOFBRexdr6TQ2TqphUOpWUoduiaM42dCtz9lam-YE_1769254170 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 84d55c470a2..cc864f2e85c 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