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