From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id g15iEQvwh2aueBwAWB0awg (envelope-from ) for ; Fri, 05 Jul 2024 09:07:23 -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=Lz87wsMx; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 314F91E0C3; Fri, 5 Jul 2024 09:07:23 -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 09A101E097 for ; Fri, 5 Jul 2024 09:07:21 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 676A538845FF for ; Fri, 5 Jul 2024 13:07:20 +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 D84B23884513 for ; Fri, 5 Jul 2024 13:06:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D84B23884513 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 D84B23884513 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=1720184822; cv=none; b=d2KJfUSGAtV6wTntxh8YNZenDNVNEks/3g3nJPbkP88lpXZnG/JKjTwztNDSxXLIEcvy44y4KndBkPEwZk6FrGa70uuTLiPNliLHeTYt+vEuwucWajwwDh1Ce8BdZ8CX6pNdX+lqs2jeGJdQTCMQNMLiZFLqn3nDN2KOh7uysCo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1720184822; c=relaxed/simple; bh=jD8l2SgEj57eiUUSB67jH0u0MxxmjZlJF3Wc45wGZw4=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=VfiRr6Lzq8Lf6IfiUAry/mjrTtJp86osAlt3VYBmxYRO5y/jVyDP7uENONOsJU+Q/kRTw7+yoqBjoyuLkUHKVCKuq4Ypurpwxo8lw7Kpgtj2P0iJfjn/bBSnqZa2Q9sJrIUPRDPmpuGqqsrkN4AdqmcUzMM+rZIVbqV/JXGyfG8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720184819; 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=KkMVSxkvX00rVLR+OcvcX6wmR59EDeOkkE7jW/9vKx4=; b=Lz87wsMxi+wObPkv/HDLREUh1OEJp+SPtteRcj0pdq3FY0dOAh2E7In5gDlUKXLhwsAZhM 4ffNYDkrdeV7vwJRz2009HWj+CAqC3qbF+kDlj9mSqdwRplEoTieMVGGvdeSjDTO/2Vznd OJsFBLuSqLWh94TbCyQes1WeSF5nRxk= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-283-bkignmLnNBSpNWyiq6dzcg-1; Fri, 05 Jul 2024 09:06:58 -0400 X-MC-Unique: bkignmLnNBSpNWyiq6dzcg-1 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-44504a0d3c3so32694801cf.1 for ; Fri, 05 Jul 2024 06:06:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720184817; x=1720789617; 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=KkMVSxkvX00rVLR+OcvcX6wmR59EDeOkkE7jW/9vKx4=; b=KsxfpEQf3QOtD2xnW6tSsGlIRal93WAwl68bLFK0veTwdg1s0gNYbyS/1Laoik6PMK BEzzUvpYNrC3yVRXlrlz3EyY6FyXVLhXnQvGlwsChU/ZbUA2Piramp42TF4xFA1cmKCB bSR1Xftr+wCrKHgyIaWaEC47zh+Ax7qxKwD6UE1A2RNP4TWEgTUaTqy1KkBS/EJ5Bfyi XYckHnkJS2C1iBCE95GpcFBJtfu5Di7XlH91lcOHCrzPLgYoGAv4A+egxVzDTBLY8QRq t7pf3N4C7fbgzVMGFnHHB9taPI1DqHF1ubgZIzIB4BEbQbtIev1Aa65MSWWjWzqXOPiN fT4g== X-Forwarded-Encrypted: i=1; AJvYcCXQaEYAYTiy7sAufasaUZ5Axq8mT8whjc8oFmTiu3VEzNccjbgZ7Y/kAAaGKFpm1+S32cpHAVjPVrdkVNbTunfvfTIgW4pBfguKbA== X-Gm-Message-State: AOJu0Yz8PVj4BOB7z3uFwG2UvXltBVtqu01CIKG0ZvJ5gfTWiWPkxRbq aSvvcThkasbuqleIUedwxtczLimkT0rCsUSWgUXqoAMV3ECtlGhP6aIpqFpx21J90W/N1AqZbeO 58rzLdmz0d4WXhtoiRVCQTxEg4yXvfgb0kI5VNObhlOQoQXF1Y+5nnLIOtxMeQ5QXN20= X-Received: by 2002:ac8:7dc5:0:b0:445:301:7bc5 with SMTP id d75a77b69052e-447cce9c69dmr66929751cf.5.1720184817095; Fri, 05 Jul 2024 06:06:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFQH19JTCw1djf6crapJtEQR0zrY2fuV0SFbCPMqk0Rn7/+lbAIwVUGDO7tMiD1pP6nEqqwmw== X-Received: by 2002:ac8:7dc5:0:b0:445:301:7bc5 with SMTP id d75a77b69052e-447cce9c69dmr66929261cf.5.1720184816502; Fri, 05 Jul 2024 06:06:56 -0700 (PDT) Received: from ?IPV6:2804:14d:8084:92c5::1001? ([2804:14d:8084:92c5::1001]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4465140aee8sm68853051cf.21.2024.07.05.06.06.55 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 05 Jul 2024 06:06:56 -0700 (PDT) Message-ID: Date: Fri, 5 Jul 2024 10:06:52 -0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3] gdb: fix "frame function" failure to get frame when call is it's last instruction To: Sahil Siddiq , gdb-patches@sourceware.org Cc: Sahil Siddiq References: <20240704163348.67304-1-sahilcdq@proton.me> From: Guinevere Larsen In-Reply-To: <20240704163348.67304-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: 7bit 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, 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/4/24 1:33 PM, Sahil Siddiq wrote: > "frame function" currently fails to retrieve the frame > associated with a function when the last instruction > in the frame is a call. This is because the instruction > pointer points to an address that lies outside the frame. > > Using "get_frame_address_in_block" instead of "get_frame_pc" > resolves this issue. > > Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30929 > --- Hi! Thanks for the quick turnaround on this! I have tested, it fixes the issue reported and adds no regressions! I have a minor nit inlined, but with that fixes, feel free to add my git trailer to the commit message: Reviewed-By: Guinevere Larsen I hope a maintainer approves this for pushing soon! > Changes v2 -> v3: > * frame-selection.exp: Merge with frame-selection-last-instr-call.exp. > * frame-selection.c: Merge with frame-selection-last-instr-call.c. > * frame-selection-last-instr-call.exp: Remove this. > * frame-selection-last-instr-call.c: Likewise. > > gdb/stack.c | 4 +- > gdb/testsuite/gdb.base/frame-selection.c | 14 +++-- > gdb/testsuite/gdb.base/frame-selection.exp | 67 +++++++++++++++++++++- > 3 files changed, 77 insertions(+), 8 deletions(-) > > 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.c b/gdb/testsuite/gdb.base/frame-selection.c > index 237e155b8c..f7893388ae 100644 > --- a/gdb/testsuite/gdb.base/frame-selection.c > +++ b/gdb/testsuite/gdb.base/frame-selection.c > @@ -40,13 +40,17 @@ recursive (int arg) > return v; > } > > +void > +call_abort (void) > +{ > + __builtin_abort(); > +} > + > int > main (void) > { > - int i, j; > - > - i = frame_1 (); > - j = recursive (0); > + frame_1 (); > + recursive (0); > > - return i + j; > + call_abort(); > } > diff --git a/gdb/testsuite/gdb.base/frame-selection.exp b/gdb/testsuite/gdb.base/frame-selection.exp > index e8d9c87c3a..4333f6a2d1 100644 > --- a/gdb/testsuite/gdb.base/frame-selection.exp > +++ b/gdb/testsuite/gdb.base/frame-selection.exp > @@ -63,7 +63,7 @@ proc check_frame { level address function } { > > set re [multi_line \ > "Stack level ${level}, frame at ($address):" \ > - ".* = $hex in ${function} \(\[^\r\n\]*\); saved .* = $hex" \ > + ".* = $hex in ${function}( \(\[^\r\n\]*\))*; saved .* = $hex" \ This looks like a spurious change. I removed the change and everything works. There's no need to send a new version for just this change though, just fix it locally and apply my review tag :) -- Cheers, Guinevere Larsen She/Her/Hers > ".*\r\n$gdb_prompt $" ] > > set testname "check frame level ${level}" > @@ -186,3 +186,68 @@ with_test_prefix "second frame_2 breakpoint" { > gdb_test "frame function recursive" "#1 $hex in recursive.*" \ > "select frame for function recursive, third attempt" > } > + > +with_test_prefix "call_is_last_instr_in_frame" { > + gdb_breakpoint abort > + gdb_continue_to_breakpoint abort > + > + # The last instruction in frame "call_abort" is a call > + gdb_test "bt" \ > + [multi_line \ > + "#0 .*abort \[^\r\n\]*" \ > + "#1 $hex in call_abort \[^\r\n\]*" \ > + "#2 $hex in main \[^\r\n\]*"] \ > + "backtrace at breakpoint" > + > + > + # Select frame using level, but relying on this being the default > + # action, so "frame 0" performs "frame level 0". > + gdb_test "frame 1" "#1 $hex in call_abort.*" > + 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 1" "#1 $hex in call_abort.*" > + gdb_test "frame level 2" "#2 $hex in main.*" > + > + # Select frame by address. > + gdb_test "frame address ${frame_1_address}" "#1 $hex in call_abort.*" \ > + "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 call_abort" "#1 $hex in call_abort.*" > + gdb_test "frame function main" "#2 $hex in main.*" > + > + with_test_prefix "select-frame, no keyword" { > + gdb_test_no_output "select-frame 1" > + check_frame "1" "${frame_1_address}" "call_abort" > + 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 1" > + check_frame "1" "${frame_1_address}" "call_abort" > + 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_1_address}" \ > + "select frame 1 by address" > + check_frame "1" "${frame_1_address}" "call_abort" > + 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 call_abort" > + check_frame "1" "${frame_1_address}" "call_abort" > + gdb_test_no_output "select-frame function main" > + check_frame "2" "${frame_2_address}" "main" > + } > +}