From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id t1SQH1FfhWbNARoAWB0awg (envelope-from ) for ; Wed, 03 Jul 2024 10:25:21 -0400 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=IQbMwJld; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 725C31E0C3; Wed, 3 Jul 2024 10:25:21 -0400 (EDT) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (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 11EA21E030 for ; Wed, 3 Jul 2024 10:25:19 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8DA1A386100A for ; Wed, 3 Jul 2024 14:25:18 +0000 (GMT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 2893B3860C2E for ; Wed, 3 Jul 2024 14:24:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2893B3860C2E Authentication-Results: sourceware.org; dmarc=pass (p=none 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 2893B3860C2E 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=1720016693; cv=none; b=qFwlBy3k3YphPLpBirbOne1A21GCmRJQ1Ltw3xv9xuUO9rL9HiPh2843WpEKxH9UF7rsF+JLdPZIzBMJFi4fiuS9dCSeDISRKa06/HVKjr3SX3oOYM6BrIPKOk1/iYemZdmuZPE2L5/Q/0LHGgq1X8dCBJcu/8mbevwgA91LY3Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1720016693; c=relaxed/simple; bh=/PqjXX1ZkgwRqS/G86HRNsbRz5QnIC+Uh/Q7ZLzd3Gw=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=SF04Ez+wwMi85JmPBudA9uik45w6hkjm+czZw02F0GjezFHSqOHpWVN7Eb1K64LHSg0jDm/e7hbJs0d+Hh2rIcw9A4uW31RnyMZbIPLBKW7wYSRUCVq7iqgX2b0rwjCwvZ2tzssrXwPbLJlYduQSk+eVT5x2NBpz2/op8Z6UcYU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720016690; 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=jvVC0yzVAEMndUjaiN7znX/91+NDaTGep2xd5Fi6SGU=; b=IQbMwJldwg9S9dt9KBeSE+cXZ7BSPDluZcqGXr2N96Vmap1Nn0Hqp5tn+5lIhoCWIQkEe6 7M2ItTBji6noUjl8WP6W+dZfwXQA8re32QDDMvdxq6PoDV6ueH1MlFKoHbEDyxxNst/8hA f1Ag7ugYhP2KcmQBqq2WXurx09tdrbU= Received: from mail-pf1-f199.google.com (mail-pf1-f199.google.com [209.85.210.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-651-MtNgzFZhMWmI5gNXNxodRg-1; Wed, 03 Jul 2024 10:24:49 -0400 X-MC-Unique: MtNgzFZhMWmI5gNXNxodRg-1 Received: by mail-pf1-f199.google.com with SMTP id d2e1a72fcca58-7066502da3fso3876861b3a.1 for ; Wed, 03 Jul 2024 07:24:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720016688; x=1720621488; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=jvVC0yzVAEMndUjaiN7znX/91+NDaTGep2xd5Fi6SGU=; b=VWD69wIFl0TFj7dklqWzOMUzIHfvuFdsEgtS9+IarY9tI+wOWr9u6A2hYzHfwymXD4 XasalVqy4JOIBBwokCg1BuUduUgvNtICjcMDf5eE6DB2pYL+iSeuJ10XxdF1/vYOtfbR IZh9TcdXIe5Kkz09RTjKl381BqGvS6uMytapz9Yxknt7o9cMhxGByfTxN3TPDNiXXBDY 9XhqAjB1MdHJv4yzOcZ4hTE7lTQrpiREbrHVXc0wMY9/fMZN0/g+7Mdw4TF61qur+ztj FheSYW+xk7Gqx1GT0XHsTDCmhStd5mAxe2qoCikGlQayYfAtbfvh5PySdbvMqE06kC1X ZRag== X-Forwarded-Encrypted: i=1; AJvYcCU6LMYF3ynvKaKxsjPscYI0g983ej9ZoyRH4ZwDIis6GgreoOqDG29ACc8iQWEkCLJOIBiRxFFwCIT34I/S+qDmbRAaHMpnsjr1Bg== X-Gm-Message-State: AOJu0YyMb0sRYCuKwF4PJQFnwSDIDtrFtiMO8lXHJe49U3HFgzy8QHII +uq79dqZdbVaX7pCt/XzedI21+6DKbUmu0fywLGBcTWabipFWG9omxgznGhxKOR3VjgX4eNl31d dag80ZSiR1nzamRrVAEQ8t6/xLT9ovmsAVKU++Ew4SNMOzYTIYC9dQ/yCiXAYpfw44U0= X-Received: by 2002:a05:6a00:190c:b0:706:6c38:31f3 with SMTP id d2e1a72fcca58-70aaad46cd3mr11791533b3a.8.1720016688063; Wed, 03 Jul 2024 07:24:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGFVGozzlSAct6hLh2RKtJSDdv0r9DK8cHASNJtFu+fdbAIX9xCrluk+OalK/C68ZFGB9ms5g== X-Received: by 2002:a05:6a00:190c:b0:706:6c38:31f3 with SMTP id d2e1a72fcca58-70aaad46cd3mr11791508b3a.8.1720016687545; Wed, 03 Jul 2024 07:24:47 -0700 (PDT) Received: from ?IPV6:2804:14d:8084:92c5::1001? ([2804:14d:8084:92c5::1001]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7080256daa2sm10406233b3a.82.2024.07.03.07.24.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 03 Jul 2024 07:24:47 -0700 (PDT) Message-ID: <729a2a2f-d8d2-4f6a-a34c-781c0b8410d0@redhat.com> Date: Wed, 3 Jul 2024 11:24:43 -0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] gdb: fix "frame function" issue when call is last instruction To: Sahil Siddiq , gdb-patches@sourceware.org Cc: Sahil Siddiq References: <20240701195321.16591-1-sahilcdq@proton.me> From: Guinevere Larsen In-Reply-To: <20240701195321.16591-1-sahilcdq@proton.me> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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 7/1/24 4:53 PM, Sahil Siddiq wrote: > Currently, the "frame function" fails when the last > instruction is a call. In such a case, the $rip > register points to an address that lies outside the > frame. Hello! Thanks for working on this patch. I tested this patch and I can confirm it does fix the issue you linked, but I have a few inline comments. I would prefer if you wrote "the last instruction in a frame is a call" or something similar. I ask this because when I read the commit message, I thought "last instruction" was referring to last instruction executed, and couldn't understand  why I couldn't reproduce without __builtin_abort. > > Using "get_frame_address_in_block" instead of > "get_frame_pc" resolves this issue. > > Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30929 > --- > Changes since v1: > * frame-selection-last-instr-call.exp: Modify test to fix regressions on arm/aarch64 > > Patch v1: https://sourceware.org/pipermail/gdb-patches/2024-June/210251.html And responding to your v1 comment about why you created a new test file, you mention creating a new C file for this test. Have you tried extending the original frame-selection.c file with a new function that calls __builtin_abort instead? It seems to me that it should work, and you should be able to extend the existing frame-selection.exp file, but I might be missing something. I would prefer if we just extended the test, instead of added a new one, but if I indeed missed something and it isn't as easy to extend it as I think, we can have the new test :) > > gdb/stack.c | 4 +- > .../frame-selection-last-instr-call.c | 28 ++++ > .../frame-selection-last-instr-call.exp | 130 ++++++++++++++++++ > 3 files changed, 160 insertions(+), 2 deletions(-) > create mode 100644 gdb/testsuite/gdb.base/frame-selection-last-instr-call.c > create mode 100644 gdb/testsuite/gdb.base/frame-selection-last-instr-call.exp > > diff --git a/gdb/stack.c b/gdb/stack.c > index b36193be2f..8249866468 100644 > --- a/gdb/stack.c > +++ b/gdb/stack.c > @@ -2860,8 +2860,8 @@ find_frame_for_function (const char *function_name) > do > { > for (size_t i = 0; (i < sals.size () && !found); i++) > - found = (get_frame_pc (frame) >= func_bounds[i].low > - && get_frame_pc (frame) < func_bounds[i].high); > + found = (get_frame_address_in_block (frame) >= func_bounds[i].low > + && get_frame_address_in_block (frame) < func_bounds[i].high); > if (!found) > { > level = 1; > diff --git a/gdb/testsuite/gdb.base/frame-selection-last-instr-call.c b/gdb/testsuite/gdb.base/frame-selection-last-instr-call.c > new file mode 100644 > index 0000000000..4f056332af > --- /dev/null > +++ b/gdb/testsuite/gdb.base/frame-selection-last-instr-call.c > @@ -0,0 +1,28 @@ > +/* Copyright 2024 Free Software Foundation, Inc. > + > + This file is part of GDB. > + > + This program is free software; you can redistribute it and/or modify > + it under the terms of the GNU General Public License as published by > + the Free Software Foundation; either version 3 of the License, or > + (at your option) any later version. > + > + This program is distributed in the hope that it will be useful, > + but WITHOUT ANY WARRANTY; without even the implied warranty of > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > + GNU General Public License for more details. > + > + You should have received a copy of the GNU General Public License > + along with this program. If not, see . */ > + > +void > +frame_1 (void) > +{ > + __builtin_abort(); > +} > + > +int > +main (void) > +{ > + frame_1 (); > +} > diff --git a/gdb/testsuite/gdb.base/frame-selection-last-instr-call.exp b/gdb/testsuite/gdb.base/frame-selection-last-instr-call.exp > new file mode 100644 > index 0000000000..5ba52cc069 > --- /dev/null > +++ b/gdb/testsuite/gdb.base/frame-selection-last-instr-call.exp > @@ -0,0 +1,130 @@ > +# Copyright 2024 Free Software Foundation, Inc. If we do keep this test, the copyright year should be kept as 2018-2024, since the file is very close to an existing file. > + > +# This program is free software; you can redistribute it and/or modify > +# it under the terms of the GNU General Public License as published by > +# the Free Software Foundation; either version 3 of the License, or > +# (at your option) any later version. > +# > +# This program is distributed in the hope that it will be useful, > +# but WITHOUT ANY WARRANTY; without even the implied warranty of > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > +# GNU General Public License for more details. > +# > +# You should have received a copy of the GNU General Public License > +# along with this program. If not, see . > + > +# This tests GDB's frame selection as used by the 'frame', > +# 'select-frame', and 'info frame' commands in the corner case > +# when the last instruction in a frame is a call. > + > +standard_testfile > + > +if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug}]} { > + return -1 > +} > + > +runto_main > +gdb_breakpoint abort > +gdb_continue_to_breakpoint abort > + > +gdb_test "bt" "#0 $hex in abort .*#1 $hex in frame_1 .*#2 $hex in main.*" "backtrace at breakpoint" Similarly, if we keep this test, I would prefer if this backtrace test used the "multi_line". That's because ".*" could eat whole lines, and make the test pass when it shouldn't. Something like: gdb_test "bt" [multi_line "#0 $hex in abort \[^\\r\\n\]*" "#1 $hex in frame_1\[^\\r\\n\]*" "#2  $hex in main \[^\\r\\n\]*"] "backtrace at breakpoint" (with the appropriate line breaks, also I haven't tested the regexes, they probably have some error in them). -- Cheers, Guinevere Larsen She/Her/Hers > + > +# Perform "info frame" to extract the frame's address. > +proc get_frame_address { {testname ""} } { > + global hex gdb_prompt > + > + set frame_address "unknown" > + set testname "get_frame_address: ${testname}" > + gdb_test_multiple "info frame" $testname { > + -re ", frame at ($hex):\r\n.*\r\n$gdb_prompt $" { > + set frame_address $expect_out(1,string) > + pass $testname > + } > + } > + > + return $frame_address > +} > + > +# Check that the current frame is at stack depth LEVEL, at frame > +# address ADDRESS, and is in FUNCTION. > +proc check_frame { level address function } { > + global hex gdb_prompt > + > + set re [multi_line \ > + "Stack level ${level}, frame at ($address):" \ > + ".* = $hex in ${function}( \(\[^\r\n\]*\))*; saved .* = $hex" \ > + ".*\r\n$gdb_prompt $" ] > + > + set testname "check frame level ${level}" > + gdb_test_multiple "info frame" $testname { > + -re $re { > + pass $testname > + } > + } > +} > + > +# Select frame using level, but relying on this being the default > +# action, so "frame 0" performs "frame level 0". > +gdb_test "frame 0" "#0 $hex in abort.*" > +set frame_0_address [ get_frame_address "frame 0" ] > +gdb_test "frame 1" "#1 $hex in frame_1.*" > +set frame_1_address [ get_frame_address "frame 1" ] > +gdb_test "frame 2" "#2 $hex in main.*" > +set frame_2_address [ get_frame_address "frame 2" ] > + > +# Select frame using 'level' specification. > +gdb_test "frame level 0" "#0 $hex in abort.*" > +gdb_test "frame level 1" "#1 $hex in frame_1.*" > +gdb_test "frame level 2" "#2 $hex in main.*" > + > +# Select frame by address. > +gdb_test "frame address ${frame_0_address}" "#0 $hex in abort.*" \ > + "select frame 0 by address" > +gdb_test "frame address ${frame_1_address}" "#1 $hex in frame_1.*" \ > + "select frame 1 by address" > +gdb_test "frame address ${frame_2_address}" "#2 $hex in main.*" \ > + "select frame 2 by address" > + > +# Select frame by function. > +gdb_test "frame function abort" "#0 $hex in abort.*" > +gdb_test "frame function frame_1" "#1 $hex in frame_1.*" > +gdb_test "frame function main" "#2 $hex in main.*" > + > +with_test_prefix "select-frame, no keyword" { > + gdb_test_no_output "select-frame 0" > + check_frame "0" "${frame_0_address}" "abort" > + gdb_test_no_output "select-frame 1" > + check_frame "1" "${frame_1_address}" "frame_1" > + gdb_test_no_output "select-frame 2" > + check_frame "2" "${frame_2_address}" "main" > +} > + > +with_test_prefix "select-frame, keyword=level" { > + gdb_test_no_output "select-frame level 0" > + check_frame "0" "${frame_0_address}" "abort" > + gdb_test_no_output "select-frame level 1" > + check_frame "1" "${frame_1_address}" "frame_1" > + gdb_test_no_output "select-frame level 2" > + check_frame "2" "${frame_2_address}" "main" > +} > + > +with_test_prefix "select-frame, keyword=address" { > + gdb_test_no_output "select-frame address ${frame_0_address}" \ > + "select frame 0 by address" > + check_frame "0" "${frame_0_address}" "abort" > + gdb_test_no_output "select-frame address ${frame_1_address}" \ > + "select frame 1 by address" > + check_frame "1" "${frame_1_address}" "frame_1" > + gdb_test_no_output "select-frame address ${frame_2_address}" \ > + "select frame 2 by address" > + check_frame "2" "${frame_2_address}" "main" > +} > + > +with_test_prefix "select-frame, keyword=function" { > + gdb_test_no_output "select-frame function abort" > + check_frame "0" "${frame_0_address}" "abort" > + gdb_test_no_output "select-frame function frame_1" > + check_frame "1" "${frame_1_address}" "frame_1" > + gdb_test_no_output "select-frame function main" > + check_frame "2" "${frame_2_address}" "main" > +}