Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.dwarf2 / rnglists-multiple-cus.exp
1 # Copyright 2020-2022 Free Software Foundation, Inc.
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16 # Test to reproduce the crash described in PR 26813.
17 #
18 # When reading a list in any table in the .debug_rnglists section, GDB would
19 # read the header at offset 0 in the section (the header of the first table).
20 # When the index of the list we read was greater than the number of lists of
21 # the first table, GDB would erroneously report that the index is invalid.
22 #
23 # So this test creates a .debug_rnglists section with two tables. The second
24 # table has more lists than the first one and we try to read a high index in
25 # the second table.
26
27 load_lib dwarf.exp
28
29 if {![dwarf2_support]} {
30 return 0
31 }
32
33 # Test with 32-bit and 64-bit DWARF.
34 foreach_with_prefix is_64 {false true} {
35 if { $is_64 } {
36 standard_testfile main.c -dw64.S
37 set testfile ${testfile}-dw64
38 } else {
39 standard_testfile main.c -dw32.S
40 set testfile ${testfile}-dw32
41 }
42
43 set asm_file [standard_output_file $srcfile2]
44 Dwarf::assemble $asm_file {
45 global is_64
46
47 # The CU uses the DW_FORM_rnglistx form to refer to the .debug_rnglists
48 # section.
49 cu {
50 version 5
51 is_64 $is_64
52 } {
53 DW_TAG_compile_unit {
54 {DW_AT_ranges 1 DW_FORM_rnglistx}
55 {DW_AT_rnglists_base cu_table DW_FORM_sec_offset}
56 } {
57 # This tests a DW_AT_ranges attribute of form DW_FORM_rnglistx on a
58 # function, which was buggy at some point.
59 DW_TAG_subprogram {
60 {DW_AT_name "foo"}
61 {DW_AT_ranges 2 DW_FORM_rnglistx}
62 }
63 }
64 }
65
66 rnglists -is-64 $is_64 {
67 # This table is unused, but exists so that the used table is not at
68 # the beginning of the section.
69 table {
70 list_ {
71 start_end 0x1000 0x2000
72 }
73 }
74
75 # The lists in this table are accessed by index (DW_FORM_rnglistx).
76 table -post-header-label cu_table {
77 # This list is unused, but exists to offset the next ones.
78 list_ {
79 start_end 0x2000 0x3000
80 }
81
82 # For the CU.
83 list_ {
84 start_end 0x3000 0x4000
85 }
86
87 # For function foo.
88 list_ {
89 start_end 0x3000 0x3010
90 }
91 }
92 }
93 }
94
95 if { [prepare_for_testing "failed to prepare" ${testfile} \
96 [list $srcfile $asm_file] {nodebug}] } {
97 return -1
98 }
99
100 # Sanity checks to make sure GDB slurped the symbols correctly.
101 gdb_test "p/x &foo" " = 0x3000"
102 }
This page took 0.03228 seconds and 4 git commands to generate.