Commit | Line | Data |
---|---|---|
88b9d363 | 1 | # Copyright 2020-2022 Free Software Foundation, Inc. |
ecfda20d SM |
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_loclists 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_loclists 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 .c -dw64.S | |
37 | set testfile ${testfile}-dw64 | |
38 | } else { | |
39 | standard_testfile .c -dw32.S | |
40 | set testfile ${testfile}-dw32 | |
41 | } | |
42 | ||
43 | # Get the addresses / lengths of func1 and func2. | |
44 | lassign [function_range func1 $srcdir/$subdir/$srcfile] func1_addr func1_len | |
45 | lassign [function_range func2 $srcdir/$subdir/$srcfile] func2_addr func2_len | |
46 | ||
47 | set asm_file [standard_output_file $srcfile2] | |
48 | Dwarf::assemble $asm_file { | |
49 | global func1_addr func1_len | |
50 | global func2_addr func2_len | |
51 | global is_64 | |
52 | ||
53 | # The CU uses the DW_FORM_loclistx form to refer to the .debug_loclists | |
54 | # section. | |
55 | cu { | |
56 | version 5 | |
57 | is_64 $is_64 | |
58 | } { | |
59 | declare_labels int_type | |
60 | ||
61 | DW_TAG_compile_unit { | |
62 | {DW_AT_loclists_base cu_table DW_FORM_sec_offset} | |
63 | } { | |
64 | int_type: DW_TAG_base_type { | |
65 | {DW_AT_byte_size 4 DW_FORM_data1} | |
66 | {DW_AT_encoding @DW_ATE_signed} | |
67 | {DW_AT_name "int"} | |
68 | } | |
69 | ||
70 | DW_TAG_variable { | |
71 | {DW_AT_name "foo"} | |
72 | {DW_AT_location 1 DW_FORM_loclistx} | |
73 | {DW_AT_type :$int_type} | |
74 | } | |
75 | ||
76 | DW_TAG_subprogram { | |
77 | {DW_AT_name "func1"} | |
78 | {DW_AT_low_pc $func1_addr} | |
79 | {DW_AT_high_pc $func1_len DW_FORM_udata} | |
80 | } | |
81 | ||
82 | DW_TAG_subprogram { | |
83 | {DW_AT_name "func2"} | |
84 | {DW_AT_low_pc $func2_addr} | |
85 | {DW_AT_high_pc $func2_len DW_FORM_udata} | |
86 | } | |
87 | } | |
88 | } | |
89 | ||
90 | loclists -is-64 $is_64 { | |
91 | # This table is unused, but exists so that the used table is not at | |
92 | # the beginning of the section. | |
93 | table { | |
94 | list_ { | |
95 | start_length 0x1000 0x1000 { DW_OP_addr 0x100000 } | |
96 | } | |
97 | } | |
98 | ||
99 | # The lists in this table are accessed by index (DW_FORM_rnglistx). | |
100 | table -post-header-label cu_table { | |
101 | # This list is unused, but exists to offset the next ones. | |
102 | list_ { | |
103 | start_length 0x1000 0x1000 { DW_OP_addr 0x100000 } | |
104 | } | |
105 | ||
106 | # For variable foo. | |
107 | list_ { | |
108 | # When in func1. | |
109 | start_length $func1_addr $func1_len { | |
110 | DW_OP_constu 0x123456 | |
111 | DW_OP_stack_value | |
112 | } | |
113 | ||
114 | # When in func2. | |
115 | start_length $func2_addr $func2_len { | |
116 | DW_OP_constu 0x234567 | |
117 | DW_OP_stack_value | |
118 | } | |
119 | } | |
120 | } | |
121 | } | |
122 | } | |
123 | ||
124 | if { [prepare_for_testing "failed to prepare" ${testfile} \ | |
125 | [list $srcfile $asm_file] {nodebug}] } { | |
126 | return -1 | |
127 | } | |
128 | ||
129 | if { ![runto_main] } { | |
130 | fail "can't run to main" | |
131 | return | |
132 | } | |
133 | ||
134 | gdb_breakpoint "func1" | |
135 | gdb_breakpoint "func2" | |
136 | ||
137 | gdb_continue_to_breakpoint "func1" | |
138 | with_test_prefix "at func1" { | |
139 | gdb_test "print /x foo" " = 0x123456" | |
140 | } | |
141 | ||
142 | gdb_continue_to_breakpoint "func2" | |
143 | with_test_prefix "at func2" { | |
144 | gdb_test "print /x foo" " = 0x234567" | |
145 | } | |
146 | } |