From patchwork Tue Apr 9 09:27:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 88231 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 BC6373858431 for ; Tue, 9 Apr 2024 09:28:25 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2a07:de40:b251:101:10:150:64:2]) by sourceware.org (Postfix) with ESMTPS id E68C5385840B for ; Tue, 9 Apr 2024 09:27:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E68C5385840B Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E68C5385840B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:2 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712654867; cv=none; b=oGLYWwt1xntQ/JKx7VMnVyn+wgJYhpTYtzNaeOPAYNGkdN6Jso21AEqQ8Upbra6qCb/4L10N4c4CcnnZ7BsaoT1mNHwCzkO+BycsKGsC0cphSHvMFfTPunJh0FJcPZWNGCVDDDXJjRDkGaEvsnkN6hJrnDnibeymGIfgTbvnl/I= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712654867; c=relaxed/simple; bh=zNtQOo+o7tQpPg48+hlZG5LM04jqcMSxQlZ8PCRNV28=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-Id:MIME-Version; b=xob/9+9TBJ9+r1Y8Prd4i3yiH28EWDGQcrolz0yNCgB3x2oojR1SBT0NyHmgtPIGLFNCpMvImylS9YifWAnlhJUGAV/A7x1TdLjAIyZEAa0CM9mb+h+rr6U/nkB/CO0QpwALC2/JMg33Rnh8wXJja4PO7f1hcR57m+AgnUBZ4aI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id D5EEC208EE for ; Tue, 9 Apr 2024 09:27:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1712654863; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tmz1rwxyskJxby1ixmZYZ7BIw6qyzxZsDKt7ivNRNVE=; b=IamZiOVxIU/NEjPL9Zo/W0kVXqRGLznDte7G5ddRvS40PpnjxVb/9czYXBfMTuQ4qeyAz/ 5UClUB/GILU8L4wKRyN+1X4QWKKcsJjZfy4PISHTOGlmfTZNe8KwBMSp35SsXlF0gCWylf mP4++G/IFlNpc0YBkas2ZDxpVxCzf0U= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1712654863; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tmz1rwxyskJxby1ixmZYZ7BIw6qyzxZsDKt7ivNRNVE=; b=ampD0A4fI7cFb2oeGbu2XGw7d42jSVxk0dxVIyVyJ+dmw5QS0PZuERa1esVSxHMq9wasWn t/WTGPoCvZRS0VCg== Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b="L/IR4THJ"; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=EJH0QTU1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1712654862; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tmz1rwxyskJxby1ixmZYZ7BIw6qyzxZsDKt7ivNRNVE=; b=L/IR4THJH+PeR5Oj2YDPu5o7g40ShFCV9lkzd9m/2q7dbgdh84rfBiIdH2d5GX7VNhZEOT SR5ps0LCukVUzPJ3j/30SDqQDTpEaKzcBalj8EpaUSdqoUHASVwNNIVQMPLhYJ4SXoiApV vnjIRIEK5pjTvQKau0cI+O4pXZwk5BM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1712654862; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tmz1rwxyskJxby1ixmZYZ7BIw6qyzxZsDKt7ivNRNVE=; b=EJH0QTU1DWn7H0d7Dzi++Pj2wmncae+0NUZjFqYjOnTC/us9J/nlJMMhaoMyeICqr5hcMu xu0gQXmWDDLSW7BQ== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id B718D13980 for ; Tue, 9 Apr 2024 09:27:42 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id sO6AKw4KFWbgWwAAD6G6ig (envelope-from ) for ; Tue, 09 Apr 2024 09:27:42 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH v5 2/2] [gdb/symtab] Handle two-linetable function in find_epilogue_using_linetable Date: Tue, 9 Apr 2024 11:27:53 +0200 Message-Id: <20240409092753.10567-2-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240409092753.10567-1-tdevries@suse.de> References: <20240409092753.10567-1-tdevries@suse.de> MIME-Version: 1.0 X-Spam-Score: -3.01 X-Rspamd-Action: no action X-Rspamd-Queue-Id: D5EEC208EE X-Spam-Level: X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; RCPT_COUNT_ONE(0.00)[1]; ARC_NA(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DKIM_TRACE(0.00)[suse.de:+]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; RCVD_TLS_ALL(0.00)[]; TO_DN_NONE(0.00)[]; DWL_DNSWL_BLOCKED(0.00)[suse.de:dkim]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; RCVD_VIA_SMTP_AUTH(0.00)[]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo, imap1.dmz-prg2.suse.org:rdns, suse.de:dkim, suse.de:email] X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, 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 From: Bernd Edlinger Consider the following test-case: ... $ cat hello.c int main() { printf("hello "); #include "world.inc" $ cat world.inc printf("world\n"); return 0; } $ gcc -g hello.c ... The line table for the compilation unit, consisting just of function main, is translated into these two gdb line tables, one for hello.c and one for world.inc: ... compunit_symtab: hello.c symtab: hello.c INDEX LINE REL-ADDRESS UNREL-ADDRESS IS-STMT PROLOGUE-END EPILOGUE-BEGIN 0 3 0x400557 0x400557 Y 1 4 0x40055b 0x40055b Y 2 END 0x40056a 0x40056a Y compunit_symtab: hello.c symtab: world.inc INDEX LINE REL-ADDRESS UNREL-ADDRESS IS-STMT PROLOGUE-END EPILOGUE-BEGIN 0 1 0x40056a 0x40056a Y 1 2 0x400574 0x400574 Y 2 3 0x400579 0x400579 Y 3 END 0x40057b 0x40057b Y ... The epilogue of main starts at 0x400579: ... 400579: 5d pop %rbp 40057a: c3 ret ... Now, say we have an epilogue_begin marker in the line table at 0x400579. We won't find it using find_epilogue_using_linetable, because it does: ... const struct symtab_and_line sal = find_pc_line (start_pc, 0); ... which gets us the line table for hello.c. Fix this by using "find_pc_line (end_pc - 1, 0)" instead. Tested on x86_64-linux. Co-Authored-By: Tom de Vries PR symtab/31622 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31622 --- gdb/symtab.c | 11 +- .../gdb.dwarf2/dw2-epilogue-begin-2.exp | 20 ++ .../gdb.dwarf2/dw2-epilogue-begin.c.inc | 51 +++++ .../gdb.dwarf2/dw2-epilogue-begin.exp | 157 +------------- .../gdb.dwarf2/dw2-epilogue-begin.exp.tcl | 199 ++++++++++++++++++ gdb/testsuite/lib/dwarf.exp | 5 +- 6 files changed, 284 insertions(+), 159 deletions(-) create mode 100644 gdb/testsuite/gdb.dwarf2/dw2-epilogue-begin-2.exp create mode 100644 gdb/testsuite/gdb.dwarf2/dw2-epilogue-begin.c.inc create mode 100644 gdb/testsuite/gdb.dwarf2/dw2-epilogue-begin.exp.tcl diff --git a/gdb/symtab.c b/gdb/symtab.c index e032178aaa6..034f71226b6 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -4158,8 +4158,15 @@ find_epilogue_using_linetable (CORE_ADDR func_addr) /* While the standard allows for multiple points marked with epilogue_begin in the same function, for performance reasons, this function will only - find the last address that sets this flag for a given block. */ - const struct symtab_and_line sal = find_pc_line (start_pc, 0); + find the last address that sets this flag for a given block. + + The lines of a function can be described by several line tables in case + there are different files involved. There's a corner case where a + function epilogue is in a different file than a function start, and using + start_pc as argument to find_pc_line will mean we won't find the + epilogue. Instead, use "end_pc - 1" to maximize our changes of picking + the line table containing an epilogue. */ + const struct symtab_and_line sal = find_pc_line (end_pc - 1, 0); if (sal.symtab != nullptr && sal.symtab->language () != language_asm) { struct objfile *objfile = sal.symtab->compunit ()->objfile (); diff --git a/gdb/testsuite/gdb.dwarf2/dw2-epilogue-begin-2.exp b/gdb/testsuite/gdb.dwarf2/dw2-epilogue-begin-2.exp new file mode 100644 index 00000000000..6302ef1ad05 --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/dw2-epilogue-begin-2.exp @@ -0,0 +1,20 @@ +# Copyright 2022-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 . + +standard_testfile dw2-epilogue-begin.c dw2-epilogue-begin.S + +set version 2 + +source $srcdir/$subdir/dw2-epilogue-begin.exp.tcl diff --git a/gdb/testsuite/gdb.dwarf2/dw2-epilogue-begin.c.inc b/gdb/testsuite/gdb.dwarf2/dw2-epilogue-begin.c.inc new file mode 100644 index 00000000000..4ff445cf37d --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/dw2-epilogue-begin.c.inc @@ -0,0 +1,51 @@ +/* Copyright 2023-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 . */ + +void +__attribute__((used)) +trivial (void) +{ + asm ("trivial_label: .global trivial_label"); /* trivial function */ +} + +char global; + +void +watch (void) +{ /* watch start */ + asm ("watch_label: .global watch_label"); + asm ("mov $0x0, %rax"); + int local = 0; /* watch prologue */ + + asm ("watch_start: .global watch_start"); + asm ("mov $0x1, %rax"); + local = 1; /* watch assign */ + asm ("watch_reassign: .global watch_reassign"); + asm ("mov $0x2, %rax"); + local = 2; /* watch reassign */ + asm ("watch_end: .global watch_end"); /* watch end */ +} + +int +main (void) +{ /* main prologue */ + asm ("main_label: .global main_label"); + global = 0; + asm ("main_fun_call: .global main_fun_call"); + watch (); /* main function call */ + asm ("main_epilogue: .global main_epilogue"); + global = 10; + return 0; /* main end */ +} diff --git a/gdb/testsuite/gdb.dwarf2/dw2-epilogue-begin.exp b/gdb/testsuite/gdb.dwarf2/dw2-epilogue-begin.exp index f646e23da62..9b9d6c71de4 100644 --- a/gdb/testsuite/gdb.dwarf2/dw2-epilogue-begin.exp +++ b/gdb/testsuite/gdb.dwarf2/dw2-epilogue-begin.exp @@ -13,161 +13,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -# Check that GDB can honor the epilogue_begin flag the compiler can place -# in the line-table data. -# We test 2 things: 1. that a software watchpoint triggered in an epilogue -# is correctly ignored -# 2. that GDB can mark the same line as both prologue and epilogue - -load_lib dwarf.exp - -# This test can only be run on targets which support DWARF-2 and use gas. -require dwarf2_support -# restricted to x86 to make it simpler to follow a variable -require is_x86_64_m64_target - standard_testfile .c .S -set trivial_line [gdb_get_line_number "trivial function"] -set main_prologue [gdb_get_line_number "main prologue"] -set main_epilogue [gdb_get_line_number "main end"] -set watch_start_line [gdb_get_line_number "watch start"] - -set asm_file [standard_output_file $srcfile2] - -# The producer will be set to clang because at the time of writing -# we only care about epilogues if the producer is clang. When the -# producer is GCC, variables use CFA locations, so watchpoints can -# continue working even on epilogues. -Dwarf::assemble $asm_file { - global srcdir subdir srcfile srcfile2 - global trivial_line main_prologue main_epilogue watch_start_line - declare_labels lines_label - - get_func_info main - get_func_info trivial - get_func_info watch - - cu {} { - compile_unit { - {language @DW_LANG_C} - {name dw2-prologue-end.c} - {stmt_list ${lines_label} DW_FORM_sec_offset} - {producer "clang version 17.0.1"} - } { - declare_labels char_label - - char_label: base_type { - {name char} - {encoding @DW_ATE_signed} - {byte_size 1 DW_FORM_sdata} - } - - subprogram { - {external 1 flag} - {name trivial} - {low_pc $trivial_start addr} - {high_pc "$trivial_start + $trivial_len" addr} - } - subprogram { - {external 1 flag} - {name watch} - {low_pc $watch_start addr} - {high_pc "$watch_start + $watch_len" addr} - } { - DW_TAG_variable { - {name local} - {type :$char_label} - {DW_AT_location {DW_OP_reg0} SPECIAL_expr} - } - } - subprogram { - {external 1 flag} - {name main} - {low_pc $main_start addr} - {high_pc "$main_start + $main_len" addr} - } - } - } - - lines {version 5} lines_label { - set diridx [include_dir "${srcdir}/${subdir}"] - file_name "$srcfile" $diridx - - program { - DW_LNS_set_file $diridx - DW_LNE_set_address $trivial_start - line $trivial_line - DW_LNS_set_prologue_end - DW_LNS_set_epilogue_begin - DW_LNS_copy - - DW_LNE_set_address watch - line $watch_start_line - DW_LNS_copy - - DW_LNE_set_address watch_start - line [gdb_get_line_number "watch assign"] - DW_LNS_set_prologue_end - DW_LNS_copy - - DW_LNE_set_address watch_reassign - line [gdb_get_line_number "watch reassign"] - DW_LNS_set_epilogue_begin - DW_LNS_copy - - DW_LNE_set_address watch_end - line [gdb_get_line_number "watch end"] - DW_LNS_copy - - DW_LNE_set_address $main_start - line $main_prologue - DW_LNS_set_prologue_end - DW_LNS_copy - - DW_LNE_set_address main_fun_call - line [gdb_get_line_number "main function call"] - DW_LNS_copy - - DW_LNE_set_address main_epilogue - line $main_epilogue - DW_LNS_set_epilogue_begin - DW_LNS_copy - - DW_LNE_end_sequence - } - } -} - -if { [prepare_for_testing "failed to prepare" ${testfile} \ - [list $srcfile $asm_file] {nodebug}] } { - return -1 -} - -if ![runto_main] { - return -1 -} - -# Moving to the scope with a local variable. -gdb_breakpoint $watch_start_line -gdb_continue_to_breakpoint "continuing to function" ".*" -gdb_test "next" "local = 2.*" "stepping to epilogue" - -# Forcing software watchpoints because hardware ones don't care if we -# are in the epilogue or not. -gdb_test_no_output "set can-use-hw-watchpoints 0" - -# Test that the software watchpoint will not trigger in this case -gdb_test "watch local" "\[W|w\]atchpoint .: local" "set watchpoint" -gdb_test "continue" ".*\[W|w\]atchpoint . deleted.*" \ - "confirm watchpoint doesn't trigger" +set version 1 -# First we test that the trivial function has a line with both a prologue -# and an epilogue. Do this by finding a line that has 3 Y columns -set sep "\[ \t\]" -set hex_number "0x\[0-9a-f\]+" -gdb_test_multiple "maint info line-table" "test epilogue in linetable" -lbl { - -re "\[0-9\]$sep+$trivial_line$sep+$hex_number$sep+$hex_number$sep+Y$sep+Y$sep+Y" { - pass $gdb_test_name - } -} +source $srcdir/$subdir/dw2-epilogue-begin.exp.tcl diff --git a/gdb/testsuite/gdb.dwarf2/dw2-epilogue-begin.exp.tcl b/gdb/testsuite/gdb.dwarf2/dw2-epilogue-begin.exp.tcl new file mode 100644 index 00000000000..155916b92df --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/dw2-epilogue-begin.exp.tcl @@ -0,0 +1,199 @@ +# Copyright 2022-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 . + +# Check that GDB can honor the epilogue_begin flag the compiler can place +# in the line-table data. +# We test 2 things: 1. that a software watchpoint triggered in an epilogue +# is correctly ignored +# 2. that GDB can mark the same line as both prologue and epilogue + +load_lib dwarf.exp + +# This test can only be run on targets which support DWARF-2 and use gas. +require dwarf2_support +# restricted to x86 to make it simpler to follow a variable +require is_x86_64_m64_target + +set trivial_line [gdb_get_line_number "trivial function"] +set main_prologue [gdb_get_line_number "main prologue"] +set main_epilogue [gdb_get_line_number "main end"] +set watch_start_line [gdb_get_line_number "watch start"] + +set asm_file [standard_output_file $srcfile2] + +# The producer will be set to clang because at the time of writing +# we only care about epilogues if the producer is clang. When the +# producer is GCC, variables use CFA locations, so watchpoints can +# continue working even on epilogues. +Dwarf::assemble $asm_file { + global srcdir subdir srcfile srcfile2 + global trivial_line main_prologue main_epilogue watch_start_line + declare_labels lines_label + + get_func_info main + get_func_info trivial + get_func_info watch + + if { $::version == 1 } { + set switch_file {} + } elseif { $::version == 2 } { + set switch_file { set f $f2 } + } else { + error "Unhandled version: $::version" + } + + cu {} { + compile_unit { + {language @DW_LANG_C} + {name dw2-prologue-end.c} + {stmt_list ${lines_label} DW_FORM_sec_offset} + {producer "clang version 17.0.1"} + } { + declare_labels char_label + + char_label: base_type { + {name char} + {encoding @DW_ATE_signed} + {byte_size 1 DW_FORM_sdata} + } + + subprogram { + {external 1 flag} + {name trivial} + {low_pc $trivial_start addr} + {high_pc "$trivial_start + $trivial_len" addr} + } + subprogram { + {external 1 flag} + {name watch} + {low_pc $watch_start addr} + {high_pc "$watch_start + $watch_len" addr} + } { + DW_TAG_variable { + {name local} + {type :$char_label} + {DW_AT_location {DW_OP_reg0} SPECIAL_expr} + } + } + subprogram { + {external 1 flag} + {name main} + {low_pc $main_start addr} + {high_pc "$main_start + $main_len" addr} + } + } + } + + lines {version 5} lines_label { + set diridx [include_dir "${srcdir}/${subdir}"] + set f1 [file_name "$srcfile" $diridx] + set f2 [file_name "$srcfile.inc" $diridx] + + set f $f1 + program { + DW_LNS_set_file $f + + DW_LNE_set_address $trivial_start + line $trivial_line + DW_LNS_set_prologue_end + DW_LNS_set_epilogue_begin + DW_LNS_copy + + DW_LNE_set_address $trivial_end + DW_LNE_end_sequence + + + DW_LNS_set_file $f + + DW_LNE_set_address $watch_start + line $watch_start_line + DW_LNS_copy + + DW_LNE_set_address watch_start + line [gdb_get_line_number "watch assign"] + DW_LNS_set_prologue_end + DW_LNS_copy + + eval $switch_file + DW_LNS_set_file $f + + DW_LNE_set_address watch_reassign + line [gdb_get_line_number "watch reassign"] + DW_LNS_set_epilogue_begin + DW_LNS_copy + + DW_LNE_set_address watch_end + line [gdb_get_line_number "watch end"] + DW_LNS_copy + + DW_LNE_set_address $watch_end + DW_LNE_end_sequence + + + DW_LNS_set_file $f + + DW_LNE_set_address $main_start + line $main_prologue + DW_LNS_set_prologue_end + DW_LNS_copy + + DW_LNE_set_address main_fun_call + line [gdb_get_line_number "main function call"] + DW_LNS_copy + + DW_LNE_set_address main_epilogue + line $main_epilogue + DW_LNS_set_epilogue_begin + DW_LNS_copy + + DW_LNE_set_address $main_end + DW_LNE_end_sequence + } + } +} + +if { [prepare_for_testing "failed to prepare" ${testfile} \ + [list $srcfile $asm_file] {nodebug}] } { + return -1 +} + +if ![runto_main] { + return -1 +} + +# Moving to the scope with a local variable. + +gdb_breakpoint $srcfile:$watch_start_line +gdb_continue_to_breakpoint "continuing to function" ".*" +gdb_test "next" "local = 2.*" "stepping to epilogue" + +# Forcing software watchpoints because hardware ones don't care if we +# are in the epilogue or not. +gdb_test_no_output "set can-use-hw-watchpoints 0" + +# Test that the software watchpoint will not trigger in this case +gdb_test "watch local" "\[W|w\]atchpoint .: local" "set watchpoint" +gdb_test "continue" ".*\[W|w\]atchpoint . deleted.*" \ + "confirm watchpoint doesn't trigger" + +# First we test that the trivial function has a line with both a prologue +# and an epilogue. Do this by finding a line that has 3 Y columns +set sep "\[ \t\]" +set hex_number "0x\[0-9a-f\]+" +gdb_test_multiple "maint info line-table" "test epilogue in linetable" -lbl { + -re "\[0-9\]$sep+$trivial_line$sep+$hex_number$sep+$hex_number$sep+Y$sep+Y$sep+Y" { + pass $gdb_test_name + } +} diff --git a/gdb/testsuite/lib/dwarf.exp b/gdb/testsuite/lib/dwarf.exp index d085f835f07..adc3a18ee4f 100644 --- a/gdb/testsuite/lib/dwarf.exp +++ b/gdb/testsuite/lib/dwarf.exp @@ -2427,10 +2427,11 @@ namespace eval Dwarf { variable _line_file_names lappend _line_file_names $filename $diridx + set nr_filenames [expr [llength $_line_file_names] / 2] if { $Dwarf::_line_unit_version >= 5 } { - return [expr [llength $_line_file_names] - 1] + return [expr $nr_filenames - 1] } else { - return [llength $_line_file_names] + return $nr_filenames } }