From patchwork Thu Jul 4 16:33:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sahil X-Patchwork-Id: 93386 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D7297384A45F for ; Thu, 4 Jul 2024 16:34:39 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-oo1-xc32.google.com (mail-oo1-xc32.google.com [IPv6:2607:f8b0:4864:20::c32]) by sourceware.org (Postfix) with ESMTPS id B45D7386100D for ; Thu, 4 Jul 2024 16:34:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B45D7386100D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B45D7386100D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::c32 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1720110857; cv=none; b=hr5f7824Wrt75zRItlKwV607wZ5udv03FcnwaJ5u3hUIlyopDYCVdUkR4xRU6OOjGtscy0kL2d7U0GOeNIV2b6baG8WOzQB/NEZ+YqhxUznXxc571HLeKrRMDToPe9ZeEY8Y73yeRa6pHO3gF7pGJCunyMH1xmZur3DUIY2h5zg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1720110857; c=relaxed/simple; bh=NjPYxmIPmiPoUMtyK4/0p+fjf5FfVfe8RPpCfT9ZRhA=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=T8vM+vQj2EPGnBtCwYxqYb2CldHLKd0hLVyHympeCAA9NJXszZpFJNO7cJkEJdP9D66v8ezXpRzwAKDfXP3coRFnXL2ITpZp+1Q9Q3569nYISJVVB7P7kIJgim69xwJiHYqll2wf6aTAw3pbIAgBwgrIg/5F1JG+Ycb0W4y5VJY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-oo1-xc32.google.com with SMTP id 006d021491bc7-5c21f3fbdd3so400234eaf.2 for ; Thu, 04 Jul 2024 09:34:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720110854; x=1720715654; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=p2gfR+5zLe5fRTsdcTNLxQm39h2dcl71tiLRHi26+uI=; b=duKQZa49thahodS+iNCq0hxqywoTvcZnzDS4THbQR0uwtiDpbkRL+2SefmDHmkAy6X cS6tZzCN5iUGF8lQ/dPzKgQHF2nX/LT5On3LlaMs8A7fcjBkeT2Ji+DTw4kg1mfBXGEB zmX3UAAIe2fopQ09sGdbcwkWcVR2q9+EtBMFd+9V/xW8p1qS+kUpzmk+cKNM2C1LifdA NaTguvo6p4ZVPSpCnhYT7UHWbwU+pXCNKDh54iMg4kGQ3Rxknh0OpG0NUFVq/Oluc2oP XZmTTFaGy8IVY1abVF/eEhP2qPnb3tL5jsAMmh2aZ914cuHiF9rgk8byNehefrb9RPsG m/2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720110854; x=1720715654; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=p2gfR+5zLe5fRTsdcTNLxQm39h2dcl71tiLRHi26+uI=; b=glxWlC656VMBhBZwkcu4w894GCqgsEZaCy6JYoEdOQeKPvUiKO9BVasABeWgzGtiQE FOGHfMctbtoI+eKuqImtPn7jD8+il7PQqiD5MtC7v7UYXrum0pAZL2A9MjAbrzJgegXS kyRbjVX/nJKktAvrgyjGo8sI+zbPzf93me8a2ZhWUi68e8A88kZqt//XjaJo6t4GCQ0d 2Y5OrW35IhM90QinAWPbaR0cUaNFI4EJclHZFNMD/5OzNxWJcoul+R5HBf0aHMpTeDCF HPEbq3bKkjyRrEtJUzIK/qdd5bJafkVU/2ntL0ClOVtuaaKKUK6zSC3Ezfnb+S0D0j1C 1fPw== X-Gm-Message-State: AOJu0YwsvDr8r2zlGenGE40IPalT2mNzBg4Zzo6fxFKpvrLioCCZT7HN pbOOLgsWxDVddD3JPn7pok+i/7RsCRcSebL5ombpYVfxCxqRUeZkf8G5Cg== X-Google-Smtp-Source: AGHT+IFLpobWHn4LYF9c2NQvoAUplvjcNpwBQvAzSPhfrFnjutkRH1onvbcq1GUCNFlGs++hRo/ElA== X-Received: by 2002:a05:6358:2c8e:b0:1aa:a44d:45d5 with SMTP id e5c5f4694b2df-1aaa44d4674mr19619455d.7.1720110853730; Thu, 04 Jul 2024 09:34:13 -0700 (PDT) Received: from valdaarhun.. ([182.48.210.74]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-72c6d41655fsm9878188a12.92.2024.07.04.09.34.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jul 2024 09:34:13 -0700 (PDT) From: Sahil Siddiq X-Google-Original-From: Sahil Siddiq To: gdb-patches@sourceware.org Cc: Sahil Siddiq Subject: [PATCH v3] gdb: fix "frame function" failure to get frame when call is it's last instruction Date: Thu, 4 Jul 2024 22:03:48 +0530 Message-ID: <20240704163348.67304-1-sahilcdq@proton.me> X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 X-Spam-Status: No, score=-6.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_SBL_CSS, SPF_HELO_NONE, SPF_PASS, 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~patchwork=sourceware.org@sourceware.org "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 Reviewed-By: Guinevere Larsen --- 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" \ ".*\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" + } +}