aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.dwarf2
diff options
context:
space:
mode:
authorGuinevere Larsen <blarsen@redhat.com>2023-11-01 17:25:32 +0100
committerGuinevere Larsen <blarsen@redhat.com>2024-01-02 10:21:37 +0100
commit528b729be1a293a21f44149351f3eba5b4e2d870 (patch)
tree3959ec9a424c769dfeffe89440fc4c6165df3916 /gdb/testsuite/gdb.dwarf2
parentb22ee0e49ba2bac8a5295f0426c62e9bd2b311a1 (diff)
downloadgdb-528b729be1a293a21f44149351f3eba5b4e2d870.zip
gdb-528b729be1a293a21f44149351f3eba5b4e2d870.tar.gz
gdb-528b729be1a293a21f44149351f3eba5b4e2d870.tar.bz2
gdb/dwarf2: Add support for DW_LNS_set_epilogue_begin in line-table
This commit adds a mechanism for GDB to detect the linetable opcode DW_LNS_set_epilogue_begin. This opcode is set by compilers to indicate that a certain instruction marks the point where the frame is destroyed. While the standard allows for multiple points marked with epilogue_begin in the same function, for performance reasons, the function that searches for the epilogue address will only find the last address that sets this flag for a given block. This commit also changes amd64_stack_frame_destroyed_p_1 to attempt to use the epilogue begin directly, and only if an epilogue can't be found will it attempt heuristics based on the current instruction. Finally, this commit also changes the dwarf assembler to be able to emit epilogue-begin instructions, to make it easier to test this patch Approved-By: Tom Tromey <tom@tromey.com>
Diffstat (limited to 'gdb/testsuite/gdb.dwarf2')
-rw-r--r--gdb/testsuite/gdb.dwarf2/dw2-epilogue-begin.c51
-rw-r--r--gdb/testsuite/gdb.dwarf2/dw2-epilogue-begin.exp173
-rw-r--r--gdb/testsuite/gdb.dwarf2/dw2-ranges-base.exp2
3 files changed, 225 insertions, 1 deletions
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-epilogue-begin.c b/gdb/testsuite/gdb.dwarf2/dw2-epilogue-begin.c
new file mode 100644
index 0000000..b760099
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/dw2-epilogue-begin.c
@@ -0,0 +1,51 @@
+/* Copyright 2023 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 <http://www.gnu.org/licenses/>. */
+
+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
new file mode 100644
index 0000000..0109f3e
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/dw2-epilogue-begin.exp
@@ -0,0 +1,173 @@
+# Copyright 2022-2023 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 <http://www.gnu.org/licenses/>.
+
+# 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"
+
+# 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/gdb.dwarf2/dw2-ranges-base.exp b/gdb/testsuite/gdb.dwarf2/dw2-ranges-base.exp
index ee274ee..170b0a1 100644
--- a/gdb/testsuite/gdb.dwarf2/dw2-ranges-base.exp
+++ b/gdb/testsuite/gdb.dwarf2/dw2-ranges-base.exp
@@ -174,7 +174,7 @@ gdb_test_multiple "maint info line-table gdb.dwarf2/dw2-ranges-base.c" \
-re ".*linetable: \\(\\(struct linetable \\*\\) 0x0\\):\r\nNo line table.\r\n" {
exp_continue
}
- -re ".*linetable: \\(\\(struct linetable \\*\\) $hex\\):\r\nINDEX\[ \t\]+LINE\[ \t\]+REL-ADDRESS\[ \t\]+UNREL-ADDRESS\[ \t\]+IS-STMT\[ \t\]PROLOGUE-END *\r\n" {
+ -re ".*linetable: \\(\\(struct linetable \\*\\) $hex\\):\r\nINDEX\[ \t\]+LINE\[ \t\]+REL-ADDRESS\[ \t\]+UNREL-ADDRESS\[ \t\]+IS-STMT\[ \t\]PROLOGUE-END\[ \t\]EPILOGUE-BEGIN *\r\n" {
exp_continue
}
}