1 # Copyright
2020-2022 Free Software Foundation
, Inc.
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.
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.
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
/>.
16 # Create an example function that contains both addresses marked as
17 # statements and addresses marked as non
-statements
, and
then
18 # disassemble the function.
20 # Of particular interest is how
'disassemble /m' handles the
21 # non
-statement addresses
, we want to ensure that these addresses are
22 # included in the disassembly output.
For completeness we test both
23 #
'disassemble /m' and
'disassemble /s'.
27 # This test can only be run
on targets which support DWARF
-2 and use gas.
28 if {![dwarf2_support
]} {
32 # The .c files use __attribute__.
33 if [get_compiler_info
] {
40 # Reuse many of the test source files from dw2
-inline
-header
-1.exp.
41 standard_testfile dw2
-inline
-header
-lbls.c dw2
-inline
-header.S \
44 set asm_file
[standard_output_file $srcfile2
]
45 Dwarf
::assemble $asm_file
{
46 global srcdir subdir srcfile srcfile3
47 declare_labels lines_label
57 {stmt_list $
{lines_label
} DW_FORM_sec_offset
}
61 {MACRO_AT_func
{main
}}
66 lines
{version
2 default_is_stmt
1} lines_label
{
67 include_dir
"${srcdir}/${subdir}"
68 file_name
"$srcfile3" 1
71 DW_LNE_set_address $main_start
72 DW_LNS_advance_line
15
75 DW_LNE_set_address line_label_2
79 DW_LNE_set_address line_label_3
83 DW_LNE_set_address line_label_4
87 DW_LNE_set_address line_label_5
91 DW_LNE_set_address line_label_6
96 DW_LNE_set_address $main_end
103 if { [prepare_for_testing
"failed to prepare" ${testfile} \
104 [list $srcfile $asm_file
] {nodebug
} ] } {
112 # Global lines array
, maps lines numbers to the list of addresses
113 # associated with that line in the debug output.
116 # Look in the global LINES array and check that the disassembly
for
117 # line
LINENUM includes the address of LABEL.
118 proc check_disassembly_results
{ linenum label
} {
121 set address
[get_hexadecimal_valueof
"&${label}" "__unknown__"]
122 set testname
"check_disassembly_results $linenum $label"
123 if {![info exists lines
($
linenum)]} {
124 fail
"$testname (no disassembly for $linenum)"
128 # Use a loop to compare the addresses as the addresses extracted
129 # from the disassembly output can be padded with zeros
, while the
130 # address of the label will not be padded.
131 set addrs $lines
($
linenum)
133 if { $a
== $address
} {
141 foreach_with_prefix opt
{ m s
} {
142 # Disassemble
'main' and split up the disassembly output. We
143 # build an associative array
, for each line number store the list
144 # of addresses that were part of its disassembly output.
146 #
LINENUM is the line we are currently collecting the disassembly
147 # addresses
for, and ADDRS is the list of addresses collected
for
152 # Clear the global associative array used to hold the results.
156 gdb_test_multiple
"disassemble /${opt} main" "" {
157 -re
"Dump of assembler code for function main:\r\n" {
161 -re
"^\[^\r\n\]+${srcfile3}:" {
165 -re
"^(\\d+)\\s+\[^\r\n\]+\r\n" {
166 if { $
linenum != -1 } {
167 set lines
($
linenum) $addrs
170 set linenum $expect_out
(1,string
)
174 -re
"^(?:=>)?\\s*($hex)\\s*\[^\r\n\]+\r\n" {
175 set address $expect_out
(1,string
)
176 lappend addrs $address
184 -re
"^End of assembler dump\\.\r\n" {
185 if { $
linenum != -1 } {
186 set lines
($
linenum) $addrs
193 -re
"^$gdb_prompt $" {
198 # Now check that each label we expect to be associated with each line
199 # shows up in the disassembly output.
200 check_disassembly_results
16 "line_label_1"
201 check_disassembly_results
16 "line_label_2"
202 check_disassembly_results
17 "line_label_3"
203 check_disassembly_results
17 "line_label_4"
204 check_disassembly_results
17 "line_label_5"
205 check_disassembly_results
18 "line_label_6"