1#!/usr/local/bin/bash
2# Copyright (C) 2018 Red Hat, Inc.
3# This file is part of elfutils.
4#
5# This file is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 3 of the License, or
8# (at your option) any later version.
9#
10# elfutils is distributed in the hope that it will be useful, but
11# WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18. $srcdir/test-subr.sh
19
20# See run-readelf-loc.sh
21
22testfiles testfileloc
23
24# Process values as offsets from base addresses and resolve to symbols.
25testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=ranges testfileloc<<\EOF
26
27DWARF section [34] '.debug_ranges' at offset 0xd94:
28
29 CU [     b] base: 0x0000000000400480 <main>
30 [     0] range 0, 2
31          0x0000000000400480 <main>..
32          0x0000000000400481 <main+0x1>
33          range 5, d
34          0x0000000000400485 <main+0x5>..
35          0x000000000040048c <main+0xc>
36
37 CU [    e0] base: 0x00000000004004a0 <say>
38 [    30] range d, f
39          0x00000000004004ad <say+0xd>..
40          0x00000000004004ae <say+0xe>
41          range 12, 1a
42          0x00000000004004b2 <say+0x12>..
43          0x00000000004004b9 <say+0x19>
44EOF
45
46# Don't resolve addresses to symbols.
47testrun_compare ${abs_top_builddir}/src/readelf -N --debug-dump=ranges testfileloc<<\EOF
48
49DWARF section [34] '.debug_ranges' at offset 0xd94:
50
51 CU [     b] base: 0x0000000000400480
52 [     0] range 0, 2
53          0x0000000000400480..
54          0x0000000000400481
55          range 5, d
56          0x0000000000400485..
57          0x000000000040048c
58
59 CU [    e0] base: 0x00000000004004a0
60 [    30] range d, f
61          0x00000000004004ad..
62          0x00000000004004ae
63          range 12, 1a
64          0x00000000004004b2..
65          0x00000000004004b9
66EOF
67
68# Produce "raw" unprocessed content.
69testrun_compare ${abs_top_builddir}/src/readelf -U --debug-dump=ranges testfileloc<<\EOF
70
71DWARF section [34] '.debug_ranges' at offset 0xd94:
72
73 CU [     b] base: 0x0000000000400480
74 [     0] range 0, 2
75          range 5, d
76
77 CU [    e0] base: 0x00000000004004a0
78 [    30] range d, f
79          range 12, 1a
80EOF
81
82# .debug_rnglists (DWARF5), see tests/testfile-dwarf-45.source
83testfiles testfile-dwarf-5
84testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=ranges testfile-dwarf-5<<\EOF
85
86DWARF section [33] '.debug_rnglists' at offset 0x1d9a:
87Table at Offset 0x0:
88
89 Length:               45
90 DWARF version:         5
91 Address size:          8
92 Segment size:          0
93 Offset entries:        0
94 CU [   218] base: 000000000000000000
95
96  Offset: c, Index: 0
97    base_address 0x400583
98      0x0000000000400583 <calc+0x13>
99    offset_pair 0, 2
100      0x0000000000400583 <calc+0x13>..
101      0x0000000000400584 <calc+0x14>
102    offset_pair 5, 15
103      0x0000000000400588 <calc+0x18>..
104      0x0000000000400597 <calc+0x27>
105    end_of_list
106
107  Offset: 1c, Index: 10
108    start_length 0x400570, 2b
109      0x0000000000400570 <calc>..
110      0x000000000040059a <calc+0x2a>
111    start_length 0x400410, 20
112      0x0000000000400410 <main>..
113      0x000000000040042f <main+0x1f>
114    end_of_list
115
116EOF
117
118# Same as above, but for DWARF4, note no header, and base address is not
119# given, but ranges are the same.
120testfiles testfile-dwarf-4
121testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=ranges testfile-dwarf-4<<\EOF
122
123DWARF section [32] '.debug_ranges' at offset 0x1f96:
124
125 CU [   21c] base: 000000000000000000
126 [     0] range 400583, 400585
127          0x0000000000400583 <calc+0x13>..
128          0x0000000000400584 <calc+0x14>
129          range 400588, 400598
130          0x0000000000400588 <calc+0x18>..
131          0x0000000000400597 <calc+0x27>
132 [    30] range 400570, 40059b
133          0x0000000000400570 <calc>..
134          0x000000000040059a <calc+0x2a>
135          range 400410, 400430
136          0x0000000000400410 <main>..
137          0x000000000040042f <main+0x1f>
138EOF
139
140# Now with split dwarf. See tests/testfile-dwarf-45.source.
141# Note that this will have an offsets table that the .dwo can refer to.
142testfiles testfile-splitdwarf-5 testfile-hello5.dwo testfile-world5.dwo
143testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=ranges testfile-splitdwarf-5<<\EOF
144
145DWARF section [35] '.debug_rnglists' at offset 0x393a:
146Table at Offset 0x0:
147
148 Length:               53
149 DWARF version:         5
150 Address size:          8
151 Segment size:          0
152 Offset entries:        2
153 CU [    49] base: 000000000000000000
154
155  Offsets starting at 0xc:
156   [     0] 0x8
157   [     1] 0x18
158
159  Offset: 14, Index: 8
160    base_address 0x4011d3
161      0x00000000004011d3 <calc+0x13>
162    offset_pair 0, 2
163      0x00000000004011d3 <calc+0x13>..
164      0x00000000004011d4 <calc+0x14>
165    offset_pair 5, 15
166      0x00000000004011d8 <calc+0x18>..
167      0x00000000004011e7 <calc+0x27>
168    end_of_list
169
170  Offset: 24, Index: 18
171    start_length 0x4011c0, 2b
172      0x00000000004011c0 <calc>..
173      0x00000000004011ea <calc+0x2a>
174    start_length 0x401060, 20
175      0x0000000000401060 <main>..
176      0x000000000040107f <main+0x1f>
177    end_of_list
178
179EOF
180
181# Note that the rnglist_base attribute of the second CU points to the offsets
182# above 0xc [c].
183testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=info testfile-splitdwarf-5<<\EOF
184
185DWARF section [28] '.debug_info' at offset 0x3102:
186 [Offset]
187 Compilation unit at offset 0:
188 Version: 5, Abbreviation section offset: 0, Address size: 8, Offset size: 4
189 Unit type: skeleton (4), Unit id: 0xc422aa5c31fec205
190 [    14]  skeleton_unit        abbrev: 1
191           low_pc               (addr) 0x0000000000401160 <foo>
192           high_pc              (data8) 81 (0x00000000004011b1)
193           stmt_list            (sec_offset) 0
194           dwo_name             (strp) "testfile-hello5.dwo"
195           comp_dir             (strp) "/home/mark/src/elfutils/tests"
196           GNU_pubnames         (flag_present) yes
197           addr_base            (sec_offset) address base [     8]
198 Compilation unit at offset 53:
199 Version: 5, Abbreviation section offset: 21, Address size: 8, Offset size: 4
200 Unit type: skeleton (4), Unit id: 0xb6c8b9d97e6dfdfe
201 [    49]  skeleton_unit        abbrev: 1
202           ranges               (sec_offset) range list [    24]
203           low_pc               (addr) 000000000000000000
204           stmt_list            (sec_offset) 655
205           dwo_name             (strp) "testfile-world5.dwo"
206           comp_dir             (strp) "/home/mark/src/elfutils/tests"
207           GNU_pubnames         (flag_present) yes
208           addr_base            (sec_offset) address base [    a8]
209           rnglists_base        (sec_offset) range list [     c]
210EOF
211
212# Same for DWARF4 GNU DebugFission. But now we need to scan the .dwo
213# explicitly to know it will use the first ranges.
214testfiles testfile-splitdwarf-4 testfile-hello4.dwo testfile-world4.dwo
215testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=ranges testfile-splitdwarf-4<<\EOF
216
217DWARF section [32] '.debug_ranges' at offset 0x3611:
218
219 CU [     b] base: 000000000000000000
220 [     0] range 4011d3, 4011d5
221          0x00000000004011d3 <calc+0x13>..
222          0x00000000004011d4 <calc+0x14>
223          range 4011d8, 4011e8
224          0x00000000004011d8 <calc+0x18>..
225          0x00000000004011e7 <calc+0x27>
226
227 CU [    3f] base: 000000000000000000
228 [    30] range 4011c0, 4011eb
229          0x00000000004011c0 <calc>..
230          0x00000000004011ea <calc+0x2a>
231          range 401060, 401080
232          0x0000000000401060 <main>..
233          0x000000000040107f <main+0x1f>
234EOF
235
236exit 0
237