summaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.dwarf2
diff options
context:
space:
mode:
authorAndrew Burgess <andrew.burgess@embecosm.com>2015-10-16 10:08:19 +0200
committerAndrew Burgess <andrew.burgess@embecosm.com>2015-12-10 09:53:46 +0000
commit28d2bfb9c3e519a3b7619bbe5d061ebe520750ef (patch)
tree6d5d3817360c2c2ae738248ea453e7b1d8b68031 /gdb/testsuite/gdb.dwarf2
parentc74088593761f7e839aa9a97728df146f3dfb3d6 (diff)
downloadbinutils-gdb-28d2bfb9c3e519a3b7619bbe5d061ebe520750ef.tar.gz
gdb: Handle multiple base address in debug_ranges data.
It is possible to use multiple base addresses within a single address range series, within the .debug_ranges section. The following is a simplified example for 32-bit addresses: .section ".debug_ranges" .4byte 0xffffffff .4byte BASE_1 .4byte START_OFFSET_1 .4byte END_OFFSET_1 .4byte START_OFFSET_2 .4byte END_OFFSET_2 .4byte 0xffffffff .4byte BASE_2 .4byte START_OFFSET_3 .4byte END_OFFSET_3 .4byte 0 .4byte 0 In this example START/END 1 and 2 are relative to BASE_1, while START/END 3 are relative to BASE_2. Currently gdb does not correctly parse this DWARF, resulting in corrupted address range information. This commit fixes this issue, and adds a new test to cover this case. In order to support testing of this feature extensions were made to the testsuite dwarf assembler, additional functionality was added to the .debug_line generation function, and a new function for generating the .debug_ranges section was added. gdb/ChangeLog: * dwarf2read.c (dwarf2_ranges_read): Unify and fix base address reading code. gdb/testsuite/ChangeLog: * gdb.dwarf2/dw2-ranges-base.c: New file. * gdb.dwarf2/dw2-ranges-base.exp: New file. * lib/dwarf.exp (namespace eval Dwarf): Add new variables to support additional line table, and debug ranges generation. (Dwarf::ranges): New function, generate .debug_ranges. (Dwarf::lines): Support generating simple line table programs. (Dwarf::assemble): Initialise new namespace variables.
Diffstat (limited to 'gdb/testsuite/gdb.dwarf2')
-rw-r--r--gdb/testsuite/gdb.dwarf2/dw2-ranges-base.c36
-rw-r--r--gdb/testsuite/gdb.dwarf2/dw2-ranges-base.exp143
2 files changed, 179 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-ranges-base.c b/gdb/testsuite/gdb.dwarf2/dw2-ranges-base.c
new file mode 100644
index 00000000000..4d52b6e8726
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/dw2-ranges-base.c
@@ -0,0 +1,36 @@
+/*
+ Copyright 2015 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__ ((section (".text.3")))
+frame3 (void)
+{
+ asm ("frame3_label: .globl frame3_label");
+}
+
+void __attribute__ ((section (".text.2")))
+frame2 (void)
+{
+ asm ("frame2_label: .globl frame2_label");
+ frame3 ();
+}
+
+void __attribute__ ((section (".text.1")))
+main (void)
+{
+ asm ("main_label: .globl main_label");
+ frame2 ();
+}
+
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-ranges-base.exp b/gdb/testsuite/gdb.dwarf2/dw2-ranges-base.exp
new file mode 100644
index 00000000000..9d642703b9f
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/dw2-ranges-base.exp
@@ -0,0 +1,143 @@
+# Copyright 2015 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/>.
+load_lib dwarf.exp
+
+# Test DW_TAG_compile_unit with no children and with neither DW_AT_low_pc nor
+# DW_AT_high_pc but with DW_AT_ranges instead.
+
+# This test can only be run on targets which support DWARF-2 and use gas.
+if {![dwarf2_support]} {
+ verbose "Skipping DW_AT_ranges test."
+ return 0
+}
+
+# The .c files use __attribute__.
+if [get_compiler_info] {
+ return -1
+}
+if !$gcc_compiled {
+ verbose "Skipping DW_AT_ranges test."
+ return 0
+}
+
+standard_testfile dw2-ranges-base.c dw2-ranges-base-dw.S
+
+set asm_file [standard_output_file $srcfile2]
+Dwarf::assemble $asm_file {
+ global srcdir subdir srcfile srcfile2
+ declare_labels ranges_label
+ declare_labels L
+
+ # Find start address and length for our functions.
+ set main_func \
+ [function_range main [list ${srcdir}/${subdir}/$srcfile]]
+ set frame2_func \
+ [function_range frame2 [list ${srcdir}/${subdir}/$srcfile]]
+ set frame3_func \
+ [function_range frame3 [list ${srcdir}/${subdir}/$srcfile]]
+
+ # Very simple info for this test program. We don't care about
+ # this information being correct (w.r.t. funtion / argument types)
+ # just so long as the compilation using makes use of the
+ # .debug_ranges data then the test achieves its objective.
+ cu {} {
+ compile_unit {
+ {language @DW_LANG_C}
+ {name dw-ranges-base.c}
+ {stmt_list $L DW_FORM_sec_offset}
+ {ranges ${ranges_label} DW_FORM_sec_offset}
+ } {
+ subprogram {
+ {external 1 flag}
+ {name main}
+ }
+ subprogram {
+ {external 1 flag}
+ {name frame2}
+ }
+ subprogram {
+ {external 1 flag}
+ {name frame3}
+ }
+ }
+ }
+
+ lines {version 2} L {
+ include_dir "${srcdir}/${subdir}"
+ file_name "$srcfile" 1
+
+ # Generate simple line table program. The line table
+ # information contained here is not correct, and we really
+ # don't care, just so long as each function has some line
+ # table data associated with it. We do make use of the fake
+ # line numbers that we pick here in the tests below.
+ program {
+ {DW_LNE_set_address [lindex $main_func 0]}
+ {DW_LNS_advance_line 10}
+ {DW_LNS_copy}
+ {DW_LNS_advance_pc [lindex $main_func 1]}
+ {DW_LNS_advance_line 19}
+ {DW_LNS_copy}
+ {DW_LNE_end_sequence}
+
+ {DW_LNE_set_address [lindex $frame2_func 0]}
+ {DW_LNS_advance_line 20}
+ {DW_LNS_copy}
+ {DW_LNS_advance_pc [lindex $frame2_func 1]}
+ {DW_LNS_advance_line 29}
+ {DW_LNS_copy}
+ {DW_LNE_end_sequence}
+
+ {DW_LNE_set_address [lindex $frame3_func 0]}
+ {DW_LNS_advance_line 30}
+ {DW_LNS_copy}
+ {DW_LNS_advance_pc [lindex $frame3_func 1]}
+ {DW_LNS_advance_line 39}
+ {DW_LNS_copy}
+ {DW_LNE_end_sequence}
+ }
+ }
+
+ # Generate ranges data. This is the point of this whole test
+ # file, we must have multiple bases specified, so we use a new
+ # base for each function.
+ ranges {is_64 [is_64_target]} {
+ ranges_label: sequence {
+ {base [lindex $main_func 0]}
+ {range 0 [lindex $main_func 1]}
+ {base [lindex $frame2_func 0]}
+ {range 0 [lindex $frame2_func 1]}
+ {base [lindex $frame3_func 0]}
+ {range 0 [lindex $frame3_func 1]}
+ }
+ }
+}
+
+if { [prepare_for_testing ${testfile}.exp ${testfile} \
+ [list $srcfile $asm_file] {nodebug}] } {
+ return -1
+}
+
+if ![runto_main] {
+ return -1
+}
+
+# Make use of the line numbers we faked in the .debug_line table above.
+gdb_test "info line main" \
+ "Line 11 of .* starts at address .* and ends at .*"
+gdb_test "info line frame2" \
+ "Line 21 of .* starts at address .* and ends at .*"
+gdb_test "info line frame3" \
+ "Line 31 of .* starts at address .* and ends at .*"