From patchwork Thu Feb 1 15:21:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Toby Lloyd Davies X-Patchwork-Id: 85138 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 ADA0C3858029 for ; Thu, 1 Feb 2024 15:24:51 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com [IPv6:2a00:1450:4864:20::12d]) by sourceware.org (Postfix) with ESMTPS id B811F3858C3A for ; Thu, 1 Feb 2024 15:23:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B811F3858C3A Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=undo.io Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=undo.io ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B811F3858C3A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::12d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706801009; cv=none; b=KeegM/GSV4hdOlAE5L/+IFx9ojtOyxi4m2Is5tPVwDf5bYZdCFt5G+zrKsetWi+6mjMT6xtB+x+4o4nkO3gChRe1eBx/Q+y8vk4NjWVuaQ3jIT+NkZNpiQ3Y78B9tRl7XJJX5DVH/vGZMgxyOdyjZl5QEpOxX2yBHiUirYu+f2Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706801009; c=relaxed/simple; bh=eW6FJ18vEQcnBewpxlLHTRc5+v8hpM8BAM9TA5rx0NY=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=n/CdvLFWcVFNwqRYXIav3QLpD5nA/K2HN5wD9VOvNlnh3HcoiG7C6bq8+4JzuhE+dAPHINEkRM2KJsKrzEVR7ssb+0yHUA46NSkn9NZQmbMr3fRYRjIN33BX2RXFlEcAyK72ehfaDDG5H1ZBsea+0jNfMIjW2/KJT4yvO9kLtlk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x12d.google.com with SMTP id 2adb3069b0e04-51109060d6aso1496846e87.2 for ; Thu, 01 Feb 2024 07:23:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=undo.io; s=google2; t=1706801005; x=1707405805; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=BiRjWJjJuCIpmeDlSC0xuaN18GS6GusednUg0c1XF84=; b=Hkz0oBDhG/yTjlRsbuvoAlW+bX4FCnUxjvqDJu9UFuzCSSJYkgJL+zfxKCSDLNA9oQ LudRvCpmLDf0x8gApf2SSV36TuidU7AsUbOHx8m0J4Tt+927Kv7uO2jBo7TCvZVJeApP D30PeiIA3Y/3gLnm3wSb6FJsjW9sNM200Ea7Dqbe7pnn2EgCHJYZQCg7xvxXTpniYAj6 iI7v3BPQ4lZFl4lFW3HPJz6FLvpONRKehjtDF33vzIx649JPyeWrE+80yEtcvH9gxq3S 6IIZGcRRiohTYyBunm5kPOHRqoDs6HJj8AuFajtTFKOtODxdKUpoaXDwv0cCW8Wh+EXa 7zyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706801005; x=1707405805; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BiRjWJjJuCIpmeDlSC0xuaN18GS6GusednUg0c1XF84=; b=afg+NoEH0W0wFP7r5+uo5XQmB96zGIc0Vrn+t2RNr3YurKCQTLIJRQlTfH7f+XjjxQ OpECXSlL7LemFOGIDEbbUhiLc8maiko8kQz7rhzWQdMb/7Q11V84s2sZdV6+3HtvkqwD 63NKR5Os5N+3LQ0vaATxEbardIGq+ocvLaVj/ss1wozW//LIHmQO2Pa+gK6YLwYUlev6 Q5qwHuaymfexV1dDRmUBLJSvf0h/H0kzKjUhH45ERqunmEWxPz/l6QP/5q7nbapHOcfU sBAOw1PlWXFy/DXKgAirG/So4pd3txxXrWmimjqDZSiB9Ljsjefa9wFaiKz8X+t83Sl1 u1Kg== X-Gm-Message-State: AOJu0YzgwMADuUPzfvmv7GRTaT25bQnFjdmijDs16UH+m1NhdlC+o4Kp 6DQ7aRuPTPZzRGnBByu8/b0kuh5t1NCy6mAc7v0cZA9EcK5tFIDEc6yHYzkAdPHtJ1hcJL1aR1T IsLwq2YfVs765VRJO+70zLMekI6V93XlHyKnazjxBAfPkEisiNXQjg0+URsy70LZpbWxjz9Wa+4 rIzC4lF5s+zWsiILZLRCoRQ3GMGEpSN2HsEhM43RG0eBQ= X-Google-Smtp-Source: AGHT+IHM6j4FTe6jm97fDZncFOYeWdBmQ3H4jt8GCOTvJr08Px4w/unuq7pX6v1AdmAV/91mrpLm4Q== X-Received: by 2002:ac2:4dae:0:b0:50e:69df:b067 with SMTP id h14-20020ac24dae000000b0050e69dfb067mr1946429lfe.11.1706801004584; Thu, 01 Feb 2024 07:23:24 -0800 (PST) Received: from redhawk-thinkpad.home (cfbb000029.b.cam.camfibre.uk. [185.219.110.154]) by smtp.gmail.com with ESMTPSA id r2-20020a05600c320200b0040ef04987e7sm4598093wmp.16.2024.02.01.07.23.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 07:23:23 -0800 (PST) From: Toby Lloyd Davies To: gdb-patches@sourceware.org Cc: Toby Lloyd Davies Subject: [PATCH 1/3] gdb: Fix missed inline callsite when the frame has changed Date: Thu, 1 Feb 2024 15:21:16 +0000 Message-Id: <20240201152118.598375-2-tlloyddavies@undo.io> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240201152118.598375-1-tlloyddavies@undo.io> References: <20240201152118.598375-1-tlloyddavies@undo.io> MIME-Version: 1.0 X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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 When the program has just returned from a function, gdb could incorrectly step over an inline callsite. This would occur when the line from the innermost inline function did not have is_stmt set. e.g. with the following assembly: foo (); call foo bar (); global_var++; /* start of bar. is_stmt false */ When stepping out of foo, gdb will not stop the program at the callsite of bar. This problem was occurring because the first part of logic that checked for "calls" to inlined functions was guarded by a check that the we were still stepping through the same function. This meant that it wasn't used when the frame had changed due to returning from a function. In this case we would incorrectly use the symtab_and_line from the innermost inline function which would mean we wouldn't stop if this line didn't have is_stmt set. This guard was necessary with the logic for detecting if we had stepped into another inline function being done later than the check for inline callsites. This is because otherwise we could decide to stop at an inline callsite before we detect that we have also stepped into a different inlined function we should step over. So fix the bug by swapping the order of the checks. --- gdb/infrun.c | 50 +++---- .../gdb.dwarf2/dw2-inline-stepping-2.c | 49 +++++++ .../gdb.dwarf2/dw2-inline-stepping-2.exp | 127 ++++++++++++++++++ 3 files changed, 202 insertions(+), 24 deletions(-) create mode 100644 gdb/testsuite/gdb.dwarf2/dw2-inline-stepping-2.c create mode 100644 gdb/testsuite/gdb.dwarf2/dw2-inline-stepping-2.exp diff --git a/gdb/infrun.c b/gdb/infrun.c index e99a1a83070..a782c115cad 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -8090,12 +8090,31 @@ process_event_stop_test (struct execution_control_state *ecs) return; } - /* Look for "calls" to inlined functions, part one. If the inline + /* Look for "calls" to inlined functions, part one. If we are still + in the same real function we were stepping through, but we have + to go further up to find the exact frame ID, we are stepping + through a more inlined call beyond its call site. */ + + if (get_frame_type (get_current_frame ()) == INLINE_FRAME + && (*curr_frame_id != original_frame_id) + && stepped_in_from (get_current_frame (), + ecs->event_thread->control.step_frame_id)) + { + infrun_debug_printf ("stepping through inlined function"); + + if (ecs->event_thread->control.step_over_calls == STEP_OVER_ALL + || inline_frame_is_marked_for_skip (false, ecs->event_thread)) + keep_going (ecs); + else + end_stepping_range (ecs); + return; + } + + /* Look for "calls" to inlined functions, part two. If the inline frame machinery detected some skipped call sites, we have entered a new inline function. */ - if ((*curr_frame_id == original_frame_id) - && inline_skipped_frames (ecs->event_thread)) + if (inline_skipped_frames (ecs->event_thread)) { infrun_debug_printf ("stepped into inlined function"); @@ -8108,7 +8127,8 @@ process_event_stop_test (struct execution_control_state *ecs) we were previously stepping, go down into the function first. Otherwise stop at the call site. */ - if (call_sal.line == ecs->event_thread->current_line + if (*curr_frame_id == original_frame_id + && call_sal.line == ecs->event_thread->current_line && call_sal.symtab == ecs->event_thread->current_symtab) { step_into_inline_frame (ecs->event_thread); @@ -8127,7 +8147,8 @@ process_event_stop_test (struct execution_control_state *ecs) /* For "next", we should stop at the call site if it is on a different source line. Otherwise continue through the inlined function. */ - if (call_sal.line == ecs->event_thread->current_line + if (*curr_frame_id == original_frame_id + && call_sal.line == ecs->event_thread->current_line && call_sal.symtab == ecs->event_thread->current_symtab) keep_going (ecs); else @@ -8136,25 +8157,6 @@ process_event_stop_test (struct execution_control_state *ecs) } } - /* Look for "calls" to inlined functions, part two. If we are still - in the same real function we were stepping through, but we have - to go further up to find the exact frame ID, we are stepping - through a more inlined call beyond its call site. */ - - if (get_frame_type (get_current_frame ()) == INLINE_FRAME - && (*curr_frame_id != original_frame_id) - && stepped_in_from (get_current_frame (), original_frame_id)) - { - infrun_debug_printf ("stepping through inlined function"); - - if (ecs->event_thread->control.step_over_calls == STEP_OVER_ALL - || inline_frame_is_marked_for_skip (false, ecs->event_thread)) - keep_going (ecs); - else - end_stepping_range (ecs); - return; - } - bool refresh_step_info = true; if ((ecs->event_thread->stop_pc () == stop_pc_sal.pc) && (ecs->event_thread->current_line != stop_pc_sal.line diff --git a/gdb/testsuite/gdb.dwarf2/dw2-inline-stepping-2.c b/gdb/testsuite/gdb.dwarf2/dw2-inline-stepping-2.c new file mode 100644 index 00000000000..9c2b3f95a26 --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/dw2-inline-stepping-2.c @@ -0,0 +1,49 @@ +/* Copyright 2019-2024 Free Software Foundation, Inc. + + 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 test relies on bar being inlined into main and foo not being + inlined. */ + +volatile int global_var; + +static inline int __attribute__ ((always_inline)) +bar () +{ + asm ("bar_label: .globl bar_label"); + global_var++; /* bar inc global_var*/ + asm ("bar_label2: .globl bar_label2"); + return global_var; /* bar return global_var */ +} /* bar end */ + +void +foo (void) +{ /* foo prologue */ + asm ("foo_label: .globl foo_label"); + global_var++; /* foo inc global_var */ +} /* foo end */ + +int +main () +{ /* main prologue */ + int ans; + asm ("main_label: .globl main_label"); + global_var = 0; /* main set global_var */ + asm ("main_label2: .globl main_label2"); + foo (); /* main call foo */ + asm ("main_label3: .globl main_label3"); + ans = bar (); /* main call bar */ + asm ("main_label4: .globl main_label4"); + return ans; +} /* main end */ diff --git a/gdb/testsuite/gdb.dwarf2/dw2-inline-stepping-2.exp b/gdb/testsuite/gdb.dwarf2/dw2-inline-stepping-2.exp new file mode 100644 index 00000000000..a97a1bfc44b --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/dw2-inline-stepping-2.exp @@ -0,0 +1,127 @@ +# Copyright 2019-2024 Free Software Foundation, Inc. + +# 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 test checks that we stop at an inline callsite when returning +# from a non-inlined function. Specifically when the first line of the +# inline function does not have is_stmt set. + +load_lib dwarf.exp + +# This test can only be run on targets which support DWARF-2 and use gas. +require dwarf2_support + +# The .c files use __attribute__. +require is_c_compiler_gcc + +standard_testfile .c .S + +set asm_file [standard_output_file $srcfile2] +Dwarf::assemble $asm_file { + global srcdir subdir srcfile srcfile2 + declare_labels ranges_label lines_label bar_prog + + lassign [function_range main [list ${srcdir}/${subdir}/$srcfile]] \ + main_start main_len + set main_end "$main_start + $main_len" + lassign [function_range foo [list ${srcdir}/${subdir}/$srcfile]] \ + foo_start foo_len + set foo_end "$foo_start + $foo_len" + + set bar_call_line [gdb_get_line_number "main call bar"] + + cu {} { + compile_unit { + {language @DW_LANG_C} + {name dw2-inline-stepping-2.c} + {low_pc 0 addr} + {stmt_list ${lines_label} DW_FORM_sec_offset} + {ranges ${ranges_label} DW_FORM_sec_offset} + } { + subprogram { + {external 1 flag} + {MACRO_AT_func {foo}} + } + bar_prog: subprogram { + {name bar} + {inline 3 data1} + } + subprogram { + {external 1 flag} + {name main} + {low_pc $main_start addr} + {high_pc "$main_start + $main_len" addr} + } { + inlined_subroutine { + {abstract_origin %$bar_prog} + {low_pc main_label3 addr} + {high_pc main_label4 addr} + {call_file 1 data1} + {call_line $bar_call_line data1} + } + } + } + } + + lines {version 2} lines_label { + include_dir "${srcdir}/${subdir}" + file_name "$srcfile" 1 + + program { + DW_LNE_set_address foo_label + line [gdb_get_line_number "foo inc global_var"] + DW_LNS_copy + DW_LNE_set_address $foo_end + DW_LNE_end_sequence + + DW_LNE_set_address main_label3 + line [gdb_get_line_number "bar inc global_var"] + DW_LNS_negate_stmt + DW_LNS_copy + + DW_LNS_negate_stmt + DW_LNE_set_address bar_label2 + line [gdb_get_line_number "bar return global_var"] + DW_LNS_copy + + DW_LNE_set_address main_label4 + line [gdb_get_line_number "return ans"] + DW_LNS_copy + DW_LNE_set_address $main_end + DW_LNE_end_sequence + } + } + + ranges {is_64 [is_64_target]} { + ranges_label: sequence { + range ${main_start} ${main_end} + range ${foo_start} ${foo_end} + } + } +} + +if { [prepare_for_testing "failed to prepare" ${testfile} \ + [list $srcfile $asm_file] {nodebug}] } { + return -1 +} + +if ![runto_main] { + return -1 +} + +gdb_breakpoint "foo" +gdb_continue_to_breakpoint "foo" + +# We should stop at bar callsite when returning from foo. +gdb_test "step" ".*main call bar.*" "step to bar callsite" From patchwork Thu Feb 1 15:21:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Toby Lloyd Davies X-Patchwork-Id: 85137 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 D06A83857C6B for ; Thu, 1 Feb 2024 15:24:03 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by sourceware.org (Postfix) with ESMTPS id 04BC038582A1 for ; Thu, 1 Feb 2024 15:23:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 04BC038582A1 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=undo.io Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=undo.io ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 04BC038582A1 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::334 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706801009; cv=none; b=OBDlgthSgvUpsZAqtSw/JuwC/Cvm17SZPxkWCyh+A2cdIpgx2GYX85NATz1G8+uvEiVLTg01KNZLH/Ssccsm8b9U+SRxi8z9DBQEsgjSTOrYtSFLcasKeVInxXQ5juB2Org7E794yqttC9NFNCgEpCEIYjnH1YqcxkpF+L9qIjU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706801009; c=relaxed/simple; bh=L2nEKK5Pikr2phEYBySOJNzJ5zXkYd9FSOLM2JiQCLE=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=qwWEpOYUVIaC5F/kFe6KF28yguDBzE7kFkPEXwQNsDW2htGgzv7Z02w5GpqmpCaHLc+EjMBm7Tw5AMFLDhGxV5Uw/bBY9vcMbWzjCPmj5XuyBn/O3foT5btC/LnwNaP9T+ezrn/bv5MwscJ+2dWu2m5MKy/BNhBi5QKGmOQBdcM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-40eacb4bfa0so9160655e9.1 for ; Thu, 01 Feb 2024 07:23:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=undo.io; s=google2; t=1706801005; x=1707405805; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=iCbQAH6KmvTp0dJp+EEs9BHy2FfmMPgsrq6opq7dIGk=; b=VRQ/yRgcCQEPO5BJNW0muykF5dq2vA5ZqS7ZWrh7pVZRxMjVVQOU0RfZNozlOoDWfl RO86Yr3I4r1FRvvjQRpcjiFgKZHwUPpBJibLqLE9afg76CetR1W1JSVPmZ7vqieqVnDd aDSnTrGK6hJ5Mk7R2pYlY/KUas1Ki54l2eH9RTUITDaNydjiZcuPKU+kX0jc4vUi/dYt rP3dCKsuFX3GqlJg7N1yvX+KdywoOIvGnxDXIegrU/vU4FyushNVwjtKNrmkK6DFSUaw +Z44uyaIRr8SCTQqxyN2W2bnmua8lnOjsMkJ01y9goRST/DrWLXw0YhrV6itf5iRYsxR x7+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706801005; x=1707405805; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iCbQAH6KmvTp0dJp+EEs9BHy2FfmMPgsrq6opq7dIGk=; b=NbNoBoCFHZ+Fxn6NmMBB6UvHiq8NLR6K3ekzuDHy8U2J9mCMD3XKsjw0yA7OHpIdZl VYMxLXUgSAyXOTZUpJBAtOrCt+UOwv/OMbXgLAL8wGcgzDQrAKBM1mnHp6p4tJe4YZKB oeGMScT+ZbkmoV1WlnseTHmG8+STEXhfH/hL66XvN8/lBpxFcYkpTe2QUX9M8lxo+Npw Z318nxxXXDB5hYLpKvIVth8GTVrWl+/tI6RxWLGUtN3p/q0b7TM52ExG/SrC5Eh1/Mq1 YsfbebarO8IUMGS52XWRWpMJsLmJmqJ1e+xnlVcCJkfWpgNLNzcce8piRf+lEXjSB7Xx mYpQ== X-Gm-Message-State: AOJu0Yy/TvpU5s2tSNP375KRxnPALdCMKrK3FEvyCTWZAxChr5DJQC5m EMTmra7czG6aGfxdGCMtF/m5BXjzJA2IqYDGz4wGVVXpppaZxGxLF0iZ1L7mM3jswW1kTZezdUr 8HrjUmK7kDEjVtUiyLM1f2OB7nPCbsQ36w97Vm3STwCvQcSClv3fFtV2Kh8MILrPCoHwrKTa5j8 BHNv7oqZ3ks6H926hX+TUdWLFA0UkcysxlLG8sOGcTgQ0= X-Google-Smtp-Source: AGHT+IFZwdDEItY+xK0ZYNABBsVnfPybl48e3bnDUX+MrfwtwvidzATPK4uqSIKfPTG/gzuONaeD+A== X-Received: by 2002:a05:600c:1c06:b0:40e:46b6:bc48 with SMTP id j6-20020a05600c1c0600b0040e46b6bc48mr2107016wms.41.1706801005286; Thu, 01 Feb 2024 07:23:25 -0800 (PST) Received: from redhawk-thinkpad.home (cfbb000029.b.cam.camfibre.uk. [185.219.110.154]) by smtp.gmail.com with ESMTPSA id r2-20020a05600c320200b0040ef04987e7sm4598093wmp.16.2024.02.01.07.23.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 07:23:25 -0800 (PST) From: Toby Lloyd Davies To: gdb-patches@sourceware.org Cc: Toby Lloyd Davies Subject: [PATCH 2/3] gdb: Don't stop at non-statement line after stepping into inline function Date: Thu, 1 Feb 2024 15:21:17 +0000 Message-Id: <20240201152118.598375-3-tlloyddavies@undo.io> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240201152118.598375-1-tlloyddavies@undo.io> References: <20240201152118.598375-1-tlloyddavies@undo.io> MIME-Version: 1.0 X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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 Generally when stepping we only want to stop at lines that mark the beginning of a statement i.e. have is_stmt set. However, when we stepped into an inline function we would always stop regardless of whether is_stmt was set on first line of the inline function. Fix this in infrun.c:process_event_stop_test by not immediately stopping when entering an inline function. Then code later in the function will decide whether to stop based on whether is_stmt is set on the line. Additionally, check if is_stmt is set on the line after stepping from an inline callsite in infcmd.c:prepare_one_step. This fixes the bug when the step starts directly at the inline function callsite. --- gdb/infcmd.c | 3 +- gdb/infrun.c | 32 ++-- .../gdb.dwarf2/dw2-inline-stepping-3.c | 50 ++++++ .../gdb.dwarf2/dw2-inline-stepping-3.exp | 153 ++++++++++++++++++ 4 files changed, 226 insertions(+), 12 deletions(-) create mode 100644 gdb/testsuite/gdb.dwarf2/dw2-inline-stepping-3.c create mode 100644 gdb/testsuite/gdb.dwarf2/dw2-inline-stepping-3.exp diff --git a/gdb/infcmd.c b/gdb/infcmd.c index 5e5f75021f2..22ab4dbebbc 100644 --- a/gdb/infcmd.c +++ b/gdb/infcmd.c @@ -964,7 +964,8 @@ prepare_one_step (thread_info *tp, struct step_command_fsm *sm) fn = sym->print_name (); if (sal.line == 0 - || !function_name_is_marked_for_skip (fn, sal)) + || ((inline_skipped_frames (tp) || sal.is_stmt) + && !function_name_is_marked_for_skip (fn, sal))) { sm->count--; return prepare_one_step (tp, sm); diff --git a/gdb/infrun.c b/gdb/infrun.c index a782c115cad..927e464e479 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -8104,10 +8104,10 @@ process_event_stop_test (struct execution_control_state *ecs) if (ecs->event_thread->control.step_over_calls == STEP_OVER_ALL || inline_frame_is_marked_for_skip (false, ecs->event_thread)) - keep_going (ecs); - else - end_stepping_range (ecs); - return; + { + keep_going (ecs); + return; + } } /* Look for "calls" to inlined functions, part two. If the inline @@ -8122,25 +8122,35 @@ process_event_stop_test (struct execution_control_state *ecs) if (ecs->event_thread->control.step_over_calls != STEP_OVER_ALL) { - /* For "step", we're going to stop. But if the call site - for this inlined function is on the same source line as - we were previously stepping, go down into the function - first. Otherwise stop at the call site. */ + /* For "step", if the call site for this inlined function is on the + same source line as we were previously stepping, go down into the + function first before deciding whether to stop. Otherwise stop at + the call site. */ if (*curr_frame_id == original_frame_id && call_sal.line == ecs->event_thread->current_line && call_sal.symtab == ecs->event_thread->current_symtab) { step_into_inline_frame (ecs->event_thread); + frame = get_current_frame (); if (inline_frame_is_marked_for_skip (false, ecs->event_thread)) { keep_going (ecs); return; } + else if (inline_skipped_frames (ecs->event_thread)) + { + end_stepping_range (ecs); + return; + } + /* We are no longer at an inline function callsite. + We use the checks further down to determine whether to stop. */ + } + else + { + end_stepping_range (ecs); + return; } - - end_stepping_range (ecs); - return; } else { diff --git a/gdb/testsuite/gdb.dwarf2/dw2-inline-stepping-3.c b/gdb/testsuite/gdb.dwarf2/dw2-inline-stepping-3.c new file mode 100644 index 00000000000..3b6bc84fb05 --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/dw2-inline-stepping-3.c @@ -0,0 +1,50 @@ +/* Copyright 2019-2024 Free Software Foundation, Inc. + + 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 test relies on foo and bar being inlined into main. */ + +volatile int global_var; + +static inline int __attribute__ ((always_inline)) +foo () +{ + asm ("foo_label: .globl foo_label"); + global_var++; /* foo inc global_var*/ + asm ("foo_label2: .globl foo_label2"); + return global_var; /* foo return global_var */ +} /* foo end */ + +static inline int __attribute__ ((always_inline)) +bar () +{ + asm ("bar_label: .globl bar_label"); + global_var++; /* bar inc global_var*/ + asm ("bar_label2: .globl bar_label2"); + return global_var; /* bar return global_var */ +} /* bar end */ + +int +main () +{ /* main prologue */ + int ans; + asm ("main_label: .globl main_label"); + global_var = 0; /* main set global_var */ + asm ("main_label2: .globl main_label2"); + ans = foo (); /* main call foo */ + asm ("main_label3: .globl main_label3"); + asm ("nop"); ans = bar (); /* main call bar */ + asm ("main_label4: .globl main_label4"); + return ans; +} /* main end */ diff --git a/gdb/testsuite/gdb.dwarf2/dw2-inline-stepping-3.exp b/gdb/testsuite/gdb.dwarf2/dw2-inline-stepping-3.exp new file mode 100644 index 00000000000..ef864d943b3 --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/dw2-inline-stepping-3.exp @@ -0,0 +1,153 @@ +# Copyright 2019-2024 Free Software Foundation, Inc. + +# 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 test checks that we stop at an inline callsite when returning +# from a non-inlined function. Specifically when the first line of the +# inline function does not have is_stmt set. +# +# Additionally, we check that when stepping into the inline function we +# step past this first line without is_stmt set. We check two cases. One +# where the inline callsite line contains no instructions (i.e. it +# begins at the same address that the inline function begins). This +# exercices the codepath in infcmd.c:prepare_one_step. The other is +# when the inline callsite line contains one instruction. This exercises +# the codepath in infrun.c:prepare_one_step. + +load_lib dwarf.exp + +# This test can only be run on targets which support DWARF-2 and use gas. +require dwarf2_support + +# The .c files use __attribute__. +require is_c_compiler_gcc + +standard_testfile .c .S + +set asm_file [standard_output_file $srcfile2] +Dwarf::assemble $asm_file { + global srcdir subdir srcfile srcfile2 + declare_labels ranges_label lines_label foo_prog bar_prog + + lassign [function_range main [list ${srcdir}/${subdir}/$srcfile]] \ + main_start main_len + set main_end "$main_start + $main_len" + + set foo_call_line [gdb_get_line_number "main call foo"] + set bar_call_line [gdb_get_line_number "main call bar"] + + cu {} { + compile_unit { + {language @DW_LANG_C} + {name dw2-inline-stepping-2.c} + {low_pc 0 addr} + {stmt_list ${lines_label} DW_FORM_sec_offset} + {ranges ${ranges_label} DW_FORM_sec_offset} + } { + bar_prog: subprogram { + {name bar} + {inline 3 data1} + } + foo_prog: subprogram { + {name foo} + {inline 3 data1} + } + subprogram { + {external 1 flag} + {name main} + {low_pc $main_start addr} + {high_pc "$main_start + $main_len" addr} + } { + inlined_subroutine { + {abstract_origin %$foo_prog} + {low_pc main_label2 addr} + {high_pc main_label3 addr} + {call_file 1 data1} + {call_line $foo_call_line data1} + } + inlined_subroutine { + {abstract_origin %$bar_prog} + {low_pc bar_label addr} + {high_pc main_label4 addr} + {call_file 1 data1} + {call_line $bar_call_line data1} + } + } + } + } + + lines {version 2} lines_label { + include_dir "${srcdir}/${subdir}" + file_name "$srcfile" 1 + + program { + + DW_LNE_set_address main_label + line [gdb_get_line_number "main set global_var"] + DW_LNS_copy + + DW_LNE_set_address main_label2 + DW_LNS_negate_stmt + line [gdb_get_line_number "foo inc global_var"] + DW_LNS_copy + DW_LNS_negate_stmt + + DW_LNE_set_address foo_label2 + line [gdb_get_line_number "foo return global_var"] + DW_LNS_copy + + DW_LNE_set_address main_label3 + line [gdb_get_line_number "main call bar"] + DW_LNS_copy + + DW_LNE_set_address bar_label + DW_LNS_negate_stmt + line [gdb_get_line_number "bar inc global_var"] + DW_LNS_copy + DW_LNS_negate_stmt + + DW_LNE_set_address bar_label2 + line [gdb_get_line_number "bar return global_var"] + DW_LNS_copy + + DW_LNE_set_address main_label4 + line [gdb_get_line_number "return ans"] + DW_LNS_copy + + DW_LNE_set_address $main_end + DW_LNE_end_sequence + } + } + + ranges {is_64 [is_64_target]} { + ranges_label: sequence { + range ${main_start} ${main_end} + } + } +} + +if { [prepare_for_testing "failed to prepare" ${testfile} \ + [list $srcfile $asm_file] {nodebug}] } { + return -1 +} + +if ![runto_main] { + return -1 +} + +gdb_test "next" ".* main call foo.*" "step to foo callsite" +gdb_test "step" ".* foo return global_var.*" "step to foo inc global_var" + +gdb_test "next" ".*main call bar.*" "step to bar callsite" +gdb_test "step" ".* bar return global_var.*" "step to bar inc global_var" From patchwork Thu Feb 1 15:21:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Toby Lloyd Davies X-Patchwork-Id: 85139 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 C263238582BC for ; Thu, 1 Feb 2024 15:24:53 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by sourceware.org (Postfix) with ESMTPS id 0EE4338582A7 for ; Thu, 1 Feb 2024 15:23:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0EE4338582A7 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=undo.io Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=undo.io ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 0EE4338582A7 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::32e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706801011; cv=none; b=ODtR1o1wxDRUAdMaDDRkLzFOZS5xRcWHnv03nCLXLkDoXvCHSudoLUyn6FQrIRj5SJc5EPa/FoyVQL5wavwkWC/bKVV6BPp86yX5sCEvFUfGgCF7Kn1bdnyCHhWkRAi1LyIllWtJ5E7XwTGnYTKRvXZsoTcZMT9Y6gcwZsYC0Nk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706801011; c=relaxed/simple; bh=CtBdLoHrTe7QixbdAlJBF3YmRWkns2UsRYHdBARKQ18=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=mXENNnEW1HSjRuza6Kn/rEYTxWkdBDnQCd2sHoynjwR/qGXquo6SqIvKZTMZspxIldgwh6YpqyEsjL/pCPlcRNXoxt+4ioHqkfchmgTluq0bRLsB3g02F5EfbIkixtImwIir7zHohsuFIKui8K7pxqMF6fbZYeGYfEMvtiZwiJk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-40fb94d42e4so8322215e9.2 for ; Thu, 01 Feb 2024 07:23:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=undo.io; s=google2; t=1706801006; x=1707405806; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=doI3kBbeDXhwM9GHcT6nVhXCOCJfM0qnkYeMcKaNd0I=; b=HnU4utwJ3VU4VZhkgaDP7QYmGk1dR1UlAtT9gp1gZl8ex2jo25mjGB87U4/aXuSk5D MdoyUZPgVmsRqUsqweDu2hsukj0uH85iMnV232FhgvV48jbCAcMwLFjakfrHxOaCyL62 U0MAX6MGrV45R3rfIw5sBnqwN5GJj3rfDfVko+wydy1bjA3YkuD0UP8Qip168VLo8J8w mPKVFafo4JcJMsxTLhCP0QAVakrdLYo/oC7XpFKQpQFVU2Epv8r4N0yuM/mIUN7sV1J7 RjFqIs/gmkeOYWC3c80PnkQ6/Tw64p7r0R6H8nfQgiS5UsWoN6R9agtRCI8U5S5qBUAG GSlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706801006; x=1707405806; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=doI3kBbeDXhwM9GHcT6nVhXCOCJfM0qnkYeMcKaNd0I=; b=MrB2A7/E4dD7UfPiTnU//KTTe9Q9t5CYVAtH9yBVxSDtDVaiOhANTKzHhPD6XF05M9 sfCo8ofuUcjwyssbSbI2UOStiLkcPbekBvDhN/ero7BNr49KgF4qyLV80k37cvAveWld 9+Q2fmUt75IdfPHOGghnNtUW584cE7IDCyj8jwAbobi86hNOQZ7xf5uodMcR4h2I5gD7 puVWPKdTtuz8Foenb7cg8YXYJ1vYe7cqhgTE5Xya+d6HXaxUqWRnC7PoC9FOMlw4wZnA 92K/nKkQCvkynKfoHaNSlm5Vsy5/WZVImzX0/uz43kpo7oFBCRsemR8IvR+D/SVhgbvV Vb/Q== X-Gm-Message-State: AOJu0YzoLqMCdOpIqsPqUTwY3H927MwezGFuOpOvOhqMLSlAoOXNmBq5 K49VXgrGc0jM8dGrebNxTtLfNyPVxNF8k7o/K+zzg9DBVhCZIPqLK78bXtvRrEaFT4/OYEp4Y7o Rr+6WWuNwQzaMbT+L96WQ1qylBekp3F4HNChIDK93M6fcFenvvUCmi8RJYkdMZss1p/4jVgjGLT Tjes4P4R+xGluRi3MnPcFLMQwtAy4TiasdMoUuBwzTJBU= X-Google-Smtp-Source: AGHT+IFXFBNB27MAwijSwHU19BK1aiQObEY7+2rPefwHLo8HdEWPTGiRUlxTDDooMT2YC50YA7LpGg== X-Received: by 2002:a05:600c:3c8a:b0:40f:be00:1465 with SMTP id bg10-20020a05600c3c8a00b0040fbe001465mr1316179wmb.39.1706801005806; Thu, 01 Feb 2024 07:23:25 -0800 (PST) Received: from redhawk-thinkpad.home (cfbb000029.b.cam.camfibre.uk. [185.219.110.154]) by smtp.gmail.com with ESMTPSA id r2-20020a05600c320200b0040ef04987e7sm4598093wmp.16.2024.02.01.07.23.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 07:23:25 -0800 (PST) From: Toby Lloyd Davies To: gdb-patches@sourceware.org Cc: Toby Lloyd Davies Subject: [PATCH 3/3] gdb: Fix 'next' skipping over remainder of inline function Date: Thu, 1 Feb 2024 15:21:18 +0000 Message-Id: <20240201152118.598375-4-tlloyddavies@undo.io> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240201152118.598375-1-tlloyddavies@undo.io> References: <20240201152118.598375-1-tlloyddavies@undo.io> MIME-Version: 1.0 X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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 An inline function's instructions are often interleaved with it's callers. When stepping out of the inline function and then back into it again we would treat this as stepping into a new inline function. Thus a 'next' command from within a inline function could skip over the rest of the inline function. This occurred because the step_frame_id was refreshed at the end of process_event_stop_test when it detected that we had changed frame. Fix this by refreshing step info only when the stack frame has changed. However, not refreshing the step info when we step out of an inline frame poses a problem if we subsequently step into a different inline frame. The code wouldn't be able to determine whether we had stepped into or out to this inline function, and thus whether a 'next' command should skip it. If that inline function was in the backtrace when we started stepping then we don't want to skip it but if it was not in the backtrace then we want to skip it. Therefore, to correctly determine when we have stepped into an inline frame requires knowledge of every inline frame that was being stepped through when the command was issued. So store these inline frame ids in a vector. Then we can treat us as having stepped into an inline function if we can't find the current frame in the vector and we haven't stepped into a different stack frame. Additionally, this fixes another bug. When stepping out of an inline function and immediately entering into another inline function we would not detect this as stepping into an inline function and thus a 'next' command wouldn't step over the new inline function. Note that in this case we would normally detect this as the entry point to the inline function and create a inline callsite here, but if we didn't detect this as an entry point then we would incorrectly step into the function. --- gdb/gdbthread.h | 6 + gdb/infrun.c | 57 +++--- .../gdb.dwarf2/dw2-inline-stepping-4.c | 59 +++++++ .../gdb.dwarf2/dw2-inline-stepping-4.exp | 167 ++++++++++++++++++ 4 files changed, 260 insertions(+), 29 deletions(-) create mode 100644 gdb/testsuite/gdb.dwarf2/dw2-inline-stepping-4.c create mode 100644 gdb/testsuite/gdb.dwarf2/dw2-inline-stepping-4.exp diff --git a/gdb/gdbthread.h b/gdb/gdbthread.h index e7035d40ad4..ddfd4ecc965 100644 --- a/gdb/gdbthread.h +++ b/gdb/gdbthread.h @@ -146,6 +146,12 @@ struct thread_control_state any inlined frames). */ struct frame_id step_stack_frame_id {}; + /* Frame IDs of inline frames as of when stepping command was issued. + From newest inline frame until newest non-inline frame + (exclusive). This is how we know when we step into an inlined + subroutine call. */ + std::vector step_inline_frame_ids {}; + /* True if the the thread is presently stepping over a breakpoint or a watchpoint, either with an inline step over or a displaced (out of line) step, and we're now expecting it to report a trap for diff --git a/gdb/infrun.c b/gdb/infrun.c index 927e464e479..845341b8fff 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -4780,6 +4780,13 @@ set_step_info (thread_info *tp, frame_info_ptr frame, tp->control.step_frame_id = get_frame_id (frame); tp->control.step_stack_frame_id = get_stack_frame_id (frame); + tp->control.step_inline_frame_ids.clear (); + for (frame_info_ptr f = frame; + f && get_frame_type (f) == INLINE_FRAME; + f = get_prev_frame (f)) + { + tp->control.step_inline_frame_ids.push_back (get_frame_id (f)); + } tp->current_symtab = sal.symtab; tp->current_line = sal.line; @@ -5002,23 +5009,6 @@ adjust_pc_after_break (struct thread_info *thread, } } -static bool -stepped_in_from (frame_info_ptr frame, struct frame_id step_frame_id) -{ - for (frame = get_prev_frame (frame); - frame != nullptr; - frame = get_prev_frame (frame)) - { - if (get_frame_id (frame) == step_frame_id) - return true; - - if (get_frame_type (frame) != INLINE_FRAME) - break; - } - - return false; -} - /* Look for an inline frame that is marked for skip. If PREV_FRAME is TRUE start at the previous frame, otherwise start at the current frame. Stop at the @@ -5039,11 +5029,16 @@ inline_frame_is_marked_for_skip (bool prev_frame, struct thread_info *tp) symtab_and_line sal; struct symbol *sym; - if (get_frame_id (frame) == tp->control.step_frame_id) - break; if (get_frame_type (frame) != INLINE_FRAME) break; + /* Don't skip frames we were already stepping through. */ + if (std::find (tp->control.step_inline_frame_ids.begin (), + tp->control.step_inline_frame_ids.end (), + get_frame_id (frame)) + != tp->control.step_inline_frame_ids.end ()) + break; + sal = find_frame_sal (frame); sym = get_frame_function (frame); @@ -8091,14 +8086,17 @@ process_event_stop_test (struct execution_control_state *ecs) } /* Look for "calls" to inlined functions, part one. If we are still - in the same real function we were stepping through, but we have - to go further up to find the exact frame ID, we are stepping + in the same real function we were stepping through, but we were not + previously stepping through this inline function, we are stepping through a more inlined call beyond its call site. */ if (get_frame_type (get_current_frame ()) == INLINE_FRAME - && (*curr_frame_id != original_frame_id) - && stepped_in_from (get_current_frame (), - ecs->event_thread->control.step_frame_id)) + && (std::find (ecs->event_thread->control.step_inline_frame_ids.begin (), + ecs->event_thread->control.step_inline_frame_ids.end (), + *curr_frame_id) + == ecs->event_thread->control.step_inline_frame_ids.end ()) + && (get_stack_frame_id (get_current_frame ()) + == ecs->event_thread->control.step_stack_frame_id)) { infrun_debug_printf ("stepping through inlined function"); @@ -8208,10 +8206,11 @@ process_event_stop_test (struct execution_control_state *ecs) end_stepping_range (ecs); return; } - else if (*curr_frame_id == original_frame_id) + else if (get_stack_frame_id (get_current_frame ()) + == ecs->event_thread->control.step_stack_frame_id) { /* We are not at the start of a statement, and we have not changed - frame. + stack frame. We ignore this line table entry, and continue stepping forward, looking for a better place to stop. */ @@ -8221,15 +8220,15 @@ process_event_stop_test (struct execution_control_state *ecs) } else { - /* We are not the start of a statement, and we have changed frame. + /* We are not the start of a statement, and we have changed stack frame. We ignore this line table entry, and continue stepping forward, looking for a better place to stop. Keep refresh_step_info at - true to note that the frame has changed, but ignore the line + true to note that the stack frame has changed, but ignore the line number to make sure we don't ignore a subsequent entry with the same line number. */ stop_pc_sal.line = 0; - infrun_debug_printf ("stepped to a different frame, but " + infrun_debug_printf ("stepped to a different stack frame, but " "it's not the start of a statement"); } } diff --git a/gdb/testsuite/gdb.dwarf2/dw2-inline-stepping-4.c b/gdb/testsuite/gdb.dwarf2/dw2-inline-stepping-4.c new file mode 100644 index 00000000000..3097fed5131 --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/dw2-inline-stepping-4.c @@ -0,0 +1,59 @@ +/* Copyright 2019-2024 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the FOOU 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 + FOOU General Public License for more details. + + You should have received a copy of the FOOU General Public License + along with this program. If not, see . */ + +/* This test relies on foo_a, foo_b and bar being inlined into main */ + +volatile int global_var; + +static inline void __attribute__ ((always_inline)) +foo_a () +{ + asm ("foo_label: .globl foo_label"); + global_var++; /* foo inc global_var */ +} + +static inline void __attribute__ ((always_inline)) +foo_b () +{ + asm ("foo_label2: .globl foo_label2"); + asm ("nop"); /* foo nop */ + asm ("foo_label3: .globl foo_label3"); + asm ("jmp bar_label2"); /* foo jmp bar */ +} /* foo end */ + +static inline void __attribute__ ((always_inline)) +bar () +{ + asm ("bar_label: .globl bar_label"); + asm ("nop"); /* bar nop */ + asm ("bar_label2: .globl bar_label2"); + global_var++; /* bar inc global_var */ +} /* bar end */ + +int +main () +{ /* main prologue */ + asm ("main_label: .globl main_label"); + global_var = 0; /* main set global_var */ + asm ("main_label2: .globl main_label2"); + foo_a (); /* main call foo */ + asm ("main_label3: .globl main_label3"); + asm ("jmp foo_label3"); /* main jmp foo */ + foo_b (); + asm ("main_label4: .globl main_label4"); + bar(); /* main call bar */ + asm ("main_label5: .globl main_label5"); + return global_var; /* main return global_var */ +} /* main end */ diff --git a/gdb/testsuite/gdb.dwarf2/dw2-inline-stepping-4.exp b/gdb/testsuite/gdb.dwarf2/dw2-inline-stepping-4.exp new file mode 100644 index 00000000000..6abba731c88 --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/dw2-inline-stepping-4.exp @@ -0,0 +1,167 @@ +# Copyright 2019-2024 Free Software Foundation, Inc. + +# 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 . +# +# Inline functions often have instructions interleaved with their +# callers. Test that when the 'next' command steps out of an inline +# function and then back into it again we do not skip the rest of the +# inline function. +# +# Additionally, test that when the 'next' command steps out of one +# inline function and immediately enters another inline function +# (without going to the callsite), we skip over the inline function. +# +# The testfile uses jumps into inline functions so that we do not stop +# at the inline callsite lines. + +load_lib dwarf.exp + +# This test can only be run on targets which support DWARF-2 and use gas. +require dwarf2_support + +# The .c files use __attribute__. +require is_c_compiler_gcc + +standard_testfile .c .S + +set asm_file [standard_output_file $srcfile2] +Dwarf::assemble $asm_file { + global srcdir subdir srcfile srcfile2 + declare_labels cu_ranges_label foo_ranges_label lines_label bar_prog foo_prog + + lassign [function_range main [list ${srcdir}/${subdir}/$srcfile]] \ + main_start main_len + set main_end "$main_start + $main_len" + + set bar_call_line [gdb_get_line_number "main call bar"] + set foo_call_line [gdb_get_line_number "main call foo"] + + cu {} { + compile_unit { + {language @DW_LANG_C} + {name dw2-inline-stepping-2.c} + {low_pc 0 addr} + {stmt_list ${lines_label} DW_FORM_sec_offset} + {ranges ${cu_ranges_label} DW_FORM_sec_offset} + } { + bar_prog: subprogram { + {name bar} + {inline 3 data1} + } + foo_prog: subprogram { + {name bar} + {inline 3 data1} + } + subprogram { + {external 1 flag} + {name main} + {low_pc $main_start addr} + {high_pc "$main_start + $main_len" addr} + } { + inlined_subroutine { + {abstract_origin %$foo_prog} + {ranges ${foo_ranges_label} DW_FORM_sec_offset} + {call_file 1 data1} + {call_line $foo_call_line data1} + } + inlined_subroutine { + {abstract_origin %$bar_prog} + {low_pc bar_label addr} + {high_pc main_label5 addr} + {call_file 1 data1} + {call_line $bar_call_line data1} + } + } + } + } + + lines {version 2} lines_label { + include_dir "${srcdir}/${subdir}" + file_name "$srcfile" 1 + + program { + + DW_LNE_set_address main_label + line [gdb_get_line_number "main set global_var"] + DW_LNS_copy + + DW_LNE_set_address main_label2 + line [gdb_get_line_number "main call foo"] + DW_LNS_copy + + DW_LNE_set_address foo_label + line [gdb_get_line_number "foo inc global_var"] + DW_LNS_copy + + DW_LNE_set_address main_label3 + line [gdb_get_line_number "main jmp foo"] + DW_LNS_negate_stmt + DW_LNS_copy + DW_LNS_negate_stmt + + + DW_LNE_set_address foo_label2 + line [gdb_get_line_number "bar nop"] + DW_LNS_copy + + DW_LNE_set_address foo_label3 + line [gdb_get_line_number "foo jmp bar"] + DW_LNS_copy + + DW_LNE_set_address main_label4 + line [gdb_get_line_number "main call bar"] + DW_LNS_copy + + DW_LNE_set_address bar_label + line [gdb_get_line_number "bar nop"] + DW_LNS_copy + + DW_LNE_set_address bar_label2 + line [gdb_get_line_number "bar inc global_var"] + DW_LNS_copy + + DW_LNE_set_address main_label5 + line [gdb_get_line_number "main return global_var"] + DW_LNS_copy + DW_LNE_set_address $main_end + DW_LNE_end_sequence + } + } + + ranges {is_64 [is_64_target]} { + cu_ranges_label: sequence { + range ${main_start} ${main_end} + } + foo_ranges_label: sequence { + range {foo_label} {main_label3} + range {foo_label2} {main_label4} + } + } +} + +if { [prepare_for_testing "failed to prepare" ${testfile} \ + [list $srcfile $asm_file] {nodebug}] } { + return -1 +} + +if ![runto_main] { + return -1 +} + +gdb_test "step" ".*main call foo.*" "step to foo callsite" +gdb_test "step" ".*foo inc global_var.*" "step into foo" + +gdb_test "next" ".foo jmp bar.*" "next within foo" + +gdb_test "next" ".*return global_var.*" "next over bar"