1#! /bin/sh
2# Copyright (C) 2013 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# - hello.c
21# int say (const char *prefix);
22#
23# static char *
24# subject (char *word, int count)
25# {
26#   return count > 0 ? word : (word + count);
27# }
28#
29# int
30# main (int argc, char **argv)
31# {
32#    return say (subject (argv[0], argc));
33# }
34#
35# - world.c
36# static int
37# sad (char c)
38# {
39#   return c > 0 ? c : c + 1;
40# }
41#
42# static int
43# happy (const char *w)
44# {
45#   return sad (w[1]);
46# }
47#
48# int
49# say (const char *prefix)
50# {
51#   const char *world = "World";
52#   return prefix ? sad (prefix[0]) : happy (world);
53# }
54#
55# gcc -g -O2 -c hello.c
56# gcc -g -O2 -c world.c
57# gcc -g -o testfileloc hello.o world.o
58
59testfiles testfileloc
60
61# Process values as offsets from base addresses and resolve to symbols.
62testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=loc --debug-dump=ranges \
63  testfileloc<<\EOF
64
65DWARF section [33] '.debug_loc' at offset 0xd2a:
66
67 CU [     b] base: 0x0000000000400480 <main>
68 [     0] range 0, d
69          0x0000000000400480 <main>..
70          0x000000000040048c <main+0xc>
71           [ 0] reg5
72 [    23] range 5, d
73          0x0000000000400485 <main+0x5>..
74          0x000000000040048c <main+0xc>
75           [ 0] reg5
76
77 CU [    e0] base: 0x00000000004004a0 <say>
78 [    46] range 12, 1a
79          0x00000000004004b2 <say+0x12>..
80          0x00000000004004b9 <say+0x19>
81           [ 0] breg5 0
82
83DWARF section [34] '.debug_ranges' at offset 0xd94:
84
85 CU [     b] base: 0x0000000000400480 <main>
86 [     0] range 0, 2
87          0x0000000000400480 <main>..
88          0x0000000000400481 <main+0x1>
89          range 5, d
90          0x0000000000400485 <main+0x5>..
91          0x000000000040048c <main+0xc>
92
93 CU [    e0] base: 0x00000000004004a0 <say>
94 [    30] range d, f
95          0x00000000004004ad <say+0xd>..
96          0x00000000004004ae <say+0xe>
97          range 12, 1a
98          0x00000000004004b2 <say+0x12>..
99          0x00000000004004b9 <say+0x19>
100EOF
101
102# Don't resolve addresses to symbols.
103testrun_compare ${abs_top_builddir}/src/readelf -N --debug-dump=loc --debug-dump=ranges \
104  testfileloc<<\EOF
105
106DWARF section [33] '.debug_loc' at offset 0xd2a:
107
108 CU [     b] base: 0x0000000000400480
109 [     0] range 0, d
110          0x0000000000400480..
111          0x000000000040048c
112           [ 0] reg5
113 [    23] range 5, d
114          0x0000000000400485..
115          0x000000000040048c
116           [ 0] reg5
117
118 CU [    e0] base: 0x00000000004004a0
119 [    46] range 12, 1a
120          0x00000000004004b2..
121          0x00000000004004b9
122           [ 0] breg5 0
123
124DWARF section [34] '.debug_ranges' at offset 0xd94:
125
126 CU [     b] base: 0x0000000000400480
127 [     0] range 0, 2
128          0x0000000000400480..
129          0x0000000000400481
130          range 5, d
131          0x0000000000400485..
132          0x000000000040048c
133
134 CU [    e0] base: 0x00000000004004a0
135 [    30] range d, f
136          0x00000000004004ad..
137          0x00000000004004ae
138          range 12, 1a
139          0x00000000004004b2..
140          0x00000000004004b9
141EOF
142
143# Produce "raw" unprocessed content.
144testrun_compare ${abs_top_builddir}/src/readelf -U --debug-dump=loc --debug-dump=ranges \
145  testfileloc<<\EOF
146
147DWARF section [33] '.debug_loc' at offset 0xd2a:
148
149 CU [     b] base: 0x0000000000400480
150 [     0] range 0, d
151           [ 0] reg5
152 [    23] range 5, d
153           [ 0] reg5
154
155 CU [    e0] base: 0x00000000004004a0
156 [    46] range 12, 1a
157           [ 0] breg5 0
158
159DWARF section [34] '.debug_ranges' at offset 0xd94:
160
161 CU [     b] base: 0x0000000000400480
162 [     0] range 0, 2
163          range 5, d
164
165 CU [    e0] base: 0x00000000004004a0
166 [    30] range d, f
167          range 12, 1a
168EOF
169
170# .debug_rnglists (DWARF5), see tests/testfile-dwarf-45.source
171testfiles testfile-dwarf-5
172testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=loc testfile-dwarf-5<<\EOF
173
174DWARF section [31] '.debug_loclists' at offset 0x1c0c:
175Table at Offset 0x0:
176
177 Length:               96
178 DWARF version:         5
179 Address size:          8
180 Segment size:          0
181 Offset entries:        0
182 CU [     c] base: 0x0000000000400510 <foo>
183
184  Offset: c, Index: 0
185    offset_pair 0, a
186      0x0000000000400510 <foo>..
187      0x0000000000400519 <foo+0x9>
188        [ 0] reg5
189    offset_pair a, 34
190      0x000000000040051a <foo+0xa>..
191      0x0000000000400543 <foo+0x33>
192        [ 0] entry_value:
193             [ 0] reg5
194        [ 3] stack_value
195    end_of_list
196
197  Offset: 1a, Index: e
198    offset_pair 1b, 2d
199      0x000000000040052b <foo+0x1b>..
200      0x000000000040053c <foo+0x2c>
201        [ 0] addr 0x601038 <m>
202    end_of_list
203
204  Offset: 28, Index: 1c
205    offset_pair 1b, 21
206      0x000000000040052b <foo+0x1b>..
207      0x0000000000400530 <foo+0x20>
208        [ 0] reg5
209    end_of_list
210
211  Offset: 2e, Index: 22
212    offset_pair 1b, 27
213      0x000000000040052b <foo+0x1b>..
214      0x0000000000400536 <foo+0x26>
215        [ 0] reg5
216    offset_pair 29, 2d
217      0x0000000000400539 <foo+0x29>..
218      0x000000000040053c <foo+0x2c>
219        [ 0] reg5
220    end_of_list
221
222  Offset: 39, Index: 2d
223    offset_pair 21, 27
224      0x0000000000400531 <foo+0x21>..
225      0x0000000000400536 <foo+0x26>
226        [ 0] reg5
227    offset_pair 29, 2d
228      0x0000000000400539 <foo+0x29>..
229      0x000000000040053c <foo+0x2c>
230        [ 0] reg5
231    end_of_list
232
233  Offset: 44, Index: 38
234    offset_pair 21, 2d
235      0x0000000000400531 <foo+0x21>..
236      0x000000000040053c <foo+0x2c>
237        [ 0] reg5
238    end_of_list
239
240  Offset: 4a, Index: 3e
241    offset_pair 2d, 33
242      0x000000000040053d <foo+0x2d>..
243      0x0000000000400542 <foo+0x32>
244        [ 0] reg5
245    end_of_list
246
247  Offset: 50, Index: 44
248    offset_pair 40, 4f
249      0x0000000000400550 <baz>..
250      0x000000000040055e <baz+0xe>
251        [ 0] reg5
252    offset_pair 4f, 51
253      0x000000000040055f <baz+0xf>..
254      0x0000000000400560 <baz+0x10>
255        [ 0] entry_value:
256             [ 0] reg5
257        [ 3] stack_value
258    end_of_list
259
260  Offset: 5e, Index: 52
261    offset_pair 40, 50
262      0x0000000000400550 <baz>..
263      0x000000000040055f <baz+0xf>
264        [ 0] reg5
265    end_of_list
266
267Table at Offset 0x64:
268
269 Length:              159
270 DWARF version:         5
271 Address size:          8
272 Segment size:          0
273 Offset entries:        0
274 CU [   218] base: 000000000000000000
275
276  Offset: 70, Index: 0
277    base_address 0x400410
278      0x0000000000400410 <main>
279    offset_pair 0, 14
280      0x0000000000400410 <main>..
281      0x0000000000400423 <main+0x13>
282        [ 0] reg5
283    offset_pair 14, 20
284      0x0000000000400424 <main+0x14>..
285      0x000000000040042f <main+0x1f>
286        [ 0] entry_value:
287             [ 0] reg5
288        [ 3] stack_value
289    end_of_list
290
291  Offset: 87, Index: 17
292    base_address 0x400410
293      0x0000000000400410 <main>
294    offset_pair 0, 18
295      0x0000000000400410 <main>..
296      0x0000000000400427 <main+0x17>
297        [ 0] reg4
298    offset_pair 18, 20
299      0x0000000000400428 <main+0x18>..
300      0x000000000040042f <main+0x1f>
301        [ 0] entry_value:
302             [ 0] reg4
303        [ 3] stack_value
304    end_of_list
305
306  Offset: 9e, Index: 2e
307    start_length 0x400421, 7
308      0x0000000000400421 <main+0x11>..
309      0x0000000000400427 <main+0x17>
310        [ 0] reg0
311    end_of_list
312
313  Offset: ab, Index: 3b
314    base_address 0x400570
315      0x0000000000400570 <calc>
316    offset_pair 0, 8
317      0x0000000000400570 <calc>..
318      0x0000000000400577 <calc+0x7>
319        [ 0] reg5
320    offset_pair 8, 2b
321      0x0000000000400578 <calc+0x8>..
322      0x000000000040059a <calc+0x2a>
323        [ 0] entry_value:
324             [ 0] reg5
325        [ 3] stack_value
326    end_of_list
327
328  Offset: c2, Index: 52
329    start_length 0x400588, b
330      0x0000000000400588 <calc+0x18>..
331      0x0000000000400592 <calc+0x22>
332        [ 0] reg0
333    end_of_list
334
335  Offset: cf, Index: 5f
336    base_address 0x400588
337      0x0000000000400588 <calc+0x18>
338    offset_pair 0, 2
339      0x0000000000400588 <calc+0x18>..
340      0x0000000000400589 <calc+0x19>
341        [ 0] reg1
342    offset_pair 2, 7
343      0x000000000040058a <calc+0x1a>..
344      0x000000000040058e <calc+0x1e>
345        [ 0] reg5
346    offset_pair 7, b
347      0x000000000040058f <calc+0x1f>..
348      0x0000000000400592 <calc+0x22>
349        [ 0] entry_value:
350             [ 0] reg5
351        [ 3] deref_size 1
352        [ 5] const1u 56
353        [ 7] shl
354        [ 8] const1u 56
355        [10] shra
356        [11] stack_value
357    end_of_list
358
359  Offset: f3, Index: 83
360    base_address 0x400588
361      0x0000000000400588 <calc+0x18>
362    offset_pair 0, 2
363      0x0000000000400588 <calc+0x18>..
364      0x0000000000400589 <calc+0x19>
365        [ 0] reg1
366    offset_pair 2, b
367      0x000000000040058a <calc+0x1a>..
368      0x0000000000400592 <calc+0x22>
369        [ 0] reg5
370    end_of_list
371
372EOF
373
374# Same as above, but for DWARF4, note completely different encoding, but
375# the information is the same (check with diff -uwb).
376testfiles testfile-dwarf-4
377testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=loc testfile-dwarf-4<<\EOF
378
379DWARF section [31] '.debug_loc' at offset 0x1c86:
380
381 CU [     b] base: 0x0000000000400510 <foo>
382 [     0] range 0, a
383          0x0000000000400510 <foo>..
384          0x0000000000400519 <foo+0x9>
385           [ 0] reg5
386          range a, 34
387          0x000000000040051a <foo+0xa>..
388          0x0000000000400543 <foo+0x33>
389           [ 0] GNU_entry_value:
390                [ 0] reg5
391           [ 3] stack_value
392 [    39] range 1b, 2d
393          0x000000000040052b <foo+0x1b>..
394          0x000000000040053c <foo+0x2c>
395           [ 0] addr 0x601038 <m>
396 [    64] range 1b, 21
397          0x000000000040052b <foo+0x1b>..
398          0x0000000000400530 <foo+0x20>
399           [ 0] reg5
400 [    87] range 1b, 27
401          0x000000000040052b <foo+0x1b>..
402          0x0000000000400536 <foo+0x26>
403           [ 0] reg5
404          range 29, 2d
405          0x0000000000400539 <foo+0x29>..
406          0x000000000040053c <foo+0x2c>
407           [ 0] reg5
408 [    bd] range 21, 27
409          0x0000000000400531 <foo+0x21>..
410          0x0000000000400536 <foo+0x26>
411           [ 0] reg5
412          range 29, 2d
413          0x0000000000400539 <foo+0x29>..
414          0x000000000040053c <foo+0x2c>
415           [ 0] reg5
416 [    f3] range 21, 2d
417          0x0000000000400531 <foo+0x21>..
418          0x000000000040053c <foo+0x2c>
419           [ 0] reg5
420 [   116] range 2d, 33
421          0x000000000040053d <foo+0x2d>..
422          0x0000000000400542 <foo+0x32>
423           [ 0] reg5
424 [   139] range 40, 4f
425          0x0000000000400550 <baz>..
426          0x000000000040055e <baz+0xe>
427           [ 0] reg5
428          range 4f, 51
429          0x000000000040055f <baz+0xf>..
430          0x0000000000400560 <baz+0x10>
431           [ 0] GNU_entry_value:
432                [ 0] reg5
433           [ 3] stack_value
434 [   172] range 40, 50
435          0x0000000000400550 <baz>..
436          0x000000000040055f <baz+0xf>
437           [ 0] reg5
438
439 CU [   21c] base: 000000000000000000
440 [   195] range 400410, 400424
441          0x0000000000400410 <main>..
442          0x0000000000400423 <main+0x13>
443           [ 0] reg5
444          range 400424, 400430
445          0x0000000000400424 <main+0x14>..
446          0x000000000040042f <main+0x1f>
447           [ 0] GNU_entry_value:
448                [ 0] reg5
449           [ 3] stack_value
450 [   1ce] range 400410, 400428
451          0x0000000000400410 <main>..
452          0x0000000000400427 <main+0x17>
453           [ 0] reg4
454          range 400428, 400430
455          0x0000000000400428 <main+0x18>..
456          0x000000000040042f <main+0x1f>
457           [ 0] GNU_entry_value:
458                [ 0] reg4
459           [ 3] stack_value
460 [   207] range 400421, 400428
461          0x0000000000400421 <main+0x11>..
462          0x0000000000400427 <main+0x17>
463           [ 0] reg0
464 [   22a] range 400570, 400578
465          0x0000000000400570 <calc>..
466          0x0000000000400577 <calc+0x7>
467           [ 0] reg5
468          range 400578, 40059b
469          0x0000000000400578 <calc+0x8>..
470          0x000000000040059a <calc+0x2a>
471           [ 0] GNU_entry_value:
472                [ 0] reg5
473           [ 3] stack_value
474 [   263] range 400588, 400593
475          0x0000000000400588 <calc+0x18>..
476          0x0000000000400592 <calc+0x22>
477           [ 0] reg0
478 [   286] range 400588, 40058a
479          0x0000000000400588 <calc+0x18>..
480          0x0000000000400589 <calc+0x19>
481           [ 0] reg1
482          range 40058a, 40058f
483          0x000000000040058a <calc+0x1a>..
484          0x000000000040058e <calc+0x1e>
485           [ 0] reg5
486          range 40058f, 400593
487          0x000000000040058f <calc+0x1f>..
488          0x0000000000400592 <calc+0x22>
489           [ 0] GNU_entry_value:
490                [ 0] reg5
491           [ 3] deref_size 1
492           [ 5] const1u 56
493           [ 7] shl
494           [ 8] const1u 56
495           [10] shra
496           [11] stack_value
497 [   2da] range 400588, 40058a
498          0x0000000000400588 <calc+0x18>..
499          0x0000000000400589 <calc+0x19>
500           [ 0] reg1
501          range 40058a, 400593
502          0x000000000040058a <calc+0x1a>..
503          0x0000000000400592 <calc+0x22>
504           [ 0] reg5
505EOF
506
507# Split DWARF5 variant. Note that the .debug_loclists moved to the .dwo file
508# and now uses an index and addrx indirections.
509testfiles testfile-splitdwarf-5 testfile-hello5.dwo testfile-world5.dwo
510testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=loc --dwarf-skeleton=testfile-splitdwarf-5 testfile-hello5.dwo testfile-world5.dwo <<\EOF
511
512testfile-hello5.dwo:
513
514
515DWARF section [ 3] '.debug_loclists.dwo' at offset 0x236:
516Table at Offset 0x0:
517
518 Length:              125
519 DWARF version:         5
520 Address size:          8
521 Segment size:          0
522 Offset entries:        9
523 CU [    14] base: 0x0000000000401160 <foo>
524
525  Offsets starting at 0xc:
526   [     0] 0x24
527   [     1] 0x32
528   [     2] 0x39
529   [     3] 0x3f
530   [     4] 0x4a
531   [     5] 0x55
532   [     6] 0x5b
533   [     7] 0x61
534   [     8] 0x6f
535
536  Offset: 30, Index: 24
537    startx_length f, a
538      0x0000000000401160 <foo>..
539      0x0000000000401169 <foo+0x9>
540        [ 0] reg5
541    startx_length 0, 2a
542      0x000000000040116a <foo+0xa>..
543      0x0000000000401193 <foo+0x33>
544        [ 0] entry_value:
545             [ 0] reg5
546        [ 3] stack_value
547    end_of_list
548
549  Offset: 3e, Index: 32
550    startx_length 11, 12
551      0x000000000040117b <foo+0x1b>..
552      0x000000000040118c <foo+0x2c>
553        [ 0] addrx [18] 0x404038 <m>
554    end_of_list
555
556  Offset: 45, Index: 39
557    startx_length 11, 6
558      0x000000000040117b <foo+0x1b>..
559      0x0000000000401180 <foo+0x20>
560        [ 0] reg5
561    end_of_list
562
563  Offset: 4b, Index: 3f
564    startx_length 11, c
565      0x000000000040117b <foo+0x1b>..
566      0x0000000000401186 <foo+0x26>
567        [ 0] reg5
568    startx_length 1, 4
569      0x0000000000401189 <foo+0x29>..
570      0x000000000040118c <foo+0x2c>
571        [ 0] reg5
572    end_of_list
573
574  Offset: 56, Index: 4a
575    startx_length 4, 6
576      0x0000000000401181 <foo+0x21>..
577      0x0000000000401186 <foo+0x26>
578        [ 0] reg5
579    startx_length 1, 4
580      0x0000000000401189 <foo+0x29>..
581      0x000000000040118c <foo+0x2c>
582        [ 0] reg5
583    end_of_list
584
585  Offset: 61, Index: 55
586    startx_length 4, c
587      0x0000000000401181 <foo+0x21>..
588      0x000000000040118c <foo+0x2c>
589        [ 0] reg5
590    end_of_list
591
592  Offset: 67, Index: 5b
593    startx_length 2, 6
594      0x000000000040118d <foo+0x2d>..
595      0x0000000000401192 <foo+0x32>
596        [ 0] reg5
597    end_of_list
598
599  Offset: 6d, Index: 61
600    startx_length 9, f
601      0x00000000004011a0 <baz>..
602      0x00000000004011ae <baz+0xe>
603        [ 0] reg5
604    startx_length 5, 2
605      0x00000000004011af <baz+0xf>..
606      0x00000000004011b0 <baz+0x10>
607        [ 0] entry_value:
608             [ 0] reg5
609        [ 3] stack_value
610    end_of_list
611
612  Offset: 7b, Index: 6f
613    startx_length 9, 10
614      0x00000000004011a0 <baz>..
615      0x00000000004011af <baz+0xf>
616        [ 0] reg5
617    end_of_list
618
619
620testfile-world5.dwo:
621
622
623DWARF section [ 3] '.debug_loclists.dwo' at offset 0x217:
624Table at Offset 0x0:
625
626 Length:              128
627 DWARF version:         5
628 Address size:          8
629 Segment size:          0
630 Offset entries:        7
631 CU [    14] base: 000000000000000000
632
633  Offsets starting at 0xc:
634   [     0] 0x1c
635   [     1] 0x2a
636   [     2] 0x38
637   [     3] 0x3e
638   [     4] 0x4c
639   [     5] 0x52
640   [     6] 0x6d
641
642  Offset: 28, Index: 1c
643    startx_length 2, 14
644      0x0000000000401060 <main>..
645      0x0000000000401073 <main+0x13>
646        [ 0] reg5
647    startx_length 4, c
648      0x0000000000401074 <main+0x14>..
649      0x000000000040107f <main+0x1f>
650        [ 0] entry_value:
651             [ 0] reg5
652        [ 3] stack_value
653    end_of_list
654
655  Offset: 36, Index: 2a
656    startx_length 2, 18
657      0x0000000000401060 <main>..
658      0x0000000000401077 <main+0x17>
659        [ 0] reg4
660    startx_length 7, 6
661      0x0000000000401078 <main+0x18>..
662      0x000000000040107d <main+0x1d>
663        [ 0] entry_value:
664             [ 0] reg4
665        [ 3] stack_value
666    end_of_list
667
668  Offset: 44, Index: 38
669    startx_length 3, 7
670      0x0000000000401071 <main+0x11>..
671      0x0000000000401077 <main+0x17>
672        [ 0] reg0
673    end_of_list
674
675  Offset: 4a, Index: 3e
676    startx_length d, 8
677      0x00000000004011c0 <calc>..
678      0x00000000004011c7 <calc+0x7>
679        [ 0] reg5
680    startx_length e, 23
681      0x00000000004011c8 <calc+0x8>..
682      0x00000000004011ea <calc+0x2a>
683        [ 0] entry_value:
684             [ 0] reg5
685        [ 3] stack_value
686    end_of_list
687
688  Offset: 58, Index: 4c
689    startx_length f, b
690      0x00000000004011d8 <calc+0x18>..
691      0x00000000004011e2 <calc+0x22>
692        [ 0] reg0
693    end_of_list
694
695  Offset: 5e, Index: 52
696    startx_length f, 2
697      0x00000000004011d8 <calc+0x18>..
698      0x00000000004011d9 <calc+0x19>
699        [ 0] reg1
700    startx_length 10, 5
701      0x00000000004011da <calc+0x1a>..
702      0x00000000004011de <calc+0x1e>
703        [ 0] reg5
704    startx_length 0, 4
705      0x00000000004011df <calc+0x1f>..
706      0x00000000004011e2 <calc+0x22>
707        [ 0] entry_value:
708             [ 0] reg5
709        [ 3] deref_size 1
710        [ 5] const1u 56
711        [ 7] shl
712        [ 8] const1u 56
713        [10] shra
714        [11] stack_value
715    end_of_list
716
717  Offset: 79, Index: 6d
718    startx_length f, 2
719      0x00000000004011d8 <calc+0x18>..
720      0x00000000004011d9 <calc+0x19>
721        [ 0] reg1
722    startx_length 10, 9
723      0x00000000004011da <calc+0x1a>..
724      0x00000000004011e2 <calc+0x22>
725        [ 0] reg5
726    end_of_list
727
728EOF
729
730# GNU DebugFission split-dwarf variant. Still uses .debug_loc, but now in
731# .dwo file, with somewhat similar, but different encoding from DWARF5.
732testfiles testfile-splitdwarf-4 testfile-hello4.dwo testfile-world4.dwo
733testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=loc --dwarf-skeleton=testfile-splitdwarf-4 testfile-hello4.dwo testfile-world4.dwo <<\EOF
734
735testfile-hello4.dwo:
736
737
738DWARF section [ 3] '.debug_loc.dwo' at offset 0x253:
739
740 CU [     b] base: 0x0000000000401160 <foo>
741 [     0] range 401160, 40116a
742          0x0000000000401160 <foo>..
743          0x0000000000401169 <foo+0x9>
744           [ 0] reg5
745          range 40116a, 401194
746          0x000000000040116a <foo+0xa>..
747          0x0000000000401193 <foo+0x33>
748           [ 0] GNU_entry_value:
749                [ 0] reg5
750           [ 3] stack_value
751 [    16] range 40117b, 40118d
752          0x000000000040117b <foo+0x1b>..
753          0x000000000040118c <foo+0x2c>
754           [ 0] GNU_addr_index [18] 0x404038 <m>
755 [    21] range 40117b, 401181
756          0x000000000040117b <foo+0x1b>..
757          0x0000000000401180 <foo+0x20>
758           [ 0] reg5
759 [    2b] range 40117b, 401187
760          0x000000000040117b <foo+0x1b>..
761          0x0000000000401186 <foo+0x26>
762           [ 0] reg5
763          range 401189, 40118d
764          0x0000000000401189 <foo+0x29>..
765          0x000000000040118c <foo+0x2c>
766           [ 0] reg5
767 [    3e] range 401181, 401187
768          0x0000000000401181 <foo+0x21>..
769          0x0000000000401186 <foo+0x26>
770           [ 0] reg5
771          range 401189, 40118d
772          0x0000000000401189 <foo+0x29>..
773          0x000000000040118c <foo+0x2c>
774           [ 0] reg5
775 [    51] range 401181, 40118d
776          0x0000000000401181 <foo+0x21>..
777          0x000000000040118c <foo+0x2c>
778           [ 0] reg5
779 [    5b] range 40118d, 401193
780          0x000000000040118d <foo+0x2d>..
781          0x0000000000401192 <foo+0x32>
782           [ 0] reg5
783 [    65] range 4011a0, 4011af
784          0x00000000004011a0 <baz>..
785          0x00000000004011ae <baz+0xe>
786           [ 0] reg5
787          range 4011af, 4011b1
788          0x00000000004011af <baz+0xf>..
789          0x00000000004011b0 <baz+0x10>
790           [ 0] GNU_entry_value:
791                [ 0] reg5
792           [ 3] stack_value
793 [    7b] range 4011a0, 4011b0
794          0x00000000004011a0 <baz>..
795          0x00000000004011af <baz+0xf>
796           [ 0] reg5
797
798testfile-world4.dwo:
799
800
801DWARF section [ 3] '.debug_loc.dwo' at offset 0x225:
802
803 CU [     b] base: 000000000000000000
804 [     0] range 401060, 401074
805          0x0000000000401060 <main>..
806          0x0000000000401073 <main+0x13>
807           [ 0] reg5
808          range 401074, 401080
809          0x0000000000401074 <main+0x14>..
810          0x000000000040107f <main+0x1f>
811           [ 0] GNU_entry_value:
812                [ 0] reg5
813           [ 3] stack_value
814 [    16] range 401060, 401078
815          0x0000000000401060 <main>..
816          0x0000000000401077 <main+0x17>
817           [ 0] reg4
818          range 401078, 40107e
819          0x0000000000401078 <main+0x18>..
820          0x000000000040107d <main+0x1d>
821           [ 0] GNU_entry_value:
822                [ 0] reg4
823           [ 3] stack_value
824 [    2c] range 401071, 401078
825          0x0000000000401071 <main+0x11>..
826          0x0000000000401077 <main+0x17>
827           [ 0] reg0
828 [    36] range 4011c0, 4011c8
829          0x00000000004011c0 <calc>..
830          0x00000000004011c7 <calc+0x7>
831           [ 0] reg5
832          range 4011c8, 4011eb
833          0x00000000004011c8 <calc+0x8>..
834          0x00000000004011ea <calc+0x2a>
835           [ 0] GNU_entry_value:
836                [ 0] reg5
837           [ 3] stack_value
838 [    4c] range 4011d8, 4011e3
839          0x00000000004011d8 <calc+0x18>..
840          0x00000000004011e2 <calc+0x22>
841           [ 0] reg0
842 [    56] range 4011d8, 4011da
843          0x00000000004011d8 <calc+0x18>..
844          0x00000000004011d9 <calc+0x19>
845           [ 0] reg1
846          range 4011da, 4011df
847          0x00000000004011da <calc+0x1a>..
848          0x00000000004011de <calc+0x1e>
849           [ 0] reg5
850          range 4011df, 4011e3
851          0x00000000004011df <calc+0x1f>..
852          0x00000000004011e2 <calc+0x22>
853           [ 0] GNU_entry_value:
854                [ 0] reg5
855           [ 3] deref_size 1
856           [ 5] const1u 56
857           [ 7] shl
858           [ 8] const1u 56
859           [10] shra
860           [11] stack_value
861 [    7d] range 4011d8, 4011da
862          0x00000000004011d8 <calc+0x18>..
863          0x00000000004011d9 <calc+0x19>
864           [ 0] reg1
865          range 4011da, 4011e3
866          0x00000000004011da <calc+0x1a>..
867          0x00000000004011e2 <calc+0x22>
868           [ 0] reg5
869EOF
870
871# Partial dwarf-4 and partial GNU DebugFission split-dwarf.
872#
873# = popcount.c =
874#
875# int popcount (unsigned char u)
876# {
877#   int c = 0;
878#   while (u != 0)
879#     {
880#       if ((u & 1) == 1)
881#         c++;
882#       u >>= 1;
883#     }
884#   return c;
885# }
886#
887# = splitdwarf4-not-split4.c =
888#
889# extern int popcount (unsigned char);
890#
891# int main (int argc, char **argv)
892# {
893#   int i;
894#   int p = argc;
895#   for (i = 0; i < argc;  ++i)
896#     p += popcount (argv[i][0]);
897#   i += p;
898#   return i;
899# }
900#
901# gcc -gdwarf-4 -O2 -c popcount.c
902# gcc -gdwarf-4 -gsplit-dwarf -O2 -c splitdwarf4-not-split4.c
903# gcc -o testfile-splitdwarf4-not-split4 splitdwarf4-not-split4.o popcount.o
904# eu-strip -f testfile-splitdwarf4-not-split4.debug \
905#   testfile-splitdwarf4-not-split4
906
907testfiles testfile-splitdwarf4-not-split4.debug
908testfiles splitdwarf4-not-split4.dwo
909
910testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=info+ --debug-dump=loc testfile-splitdwarf4-not-split4.debug <<\EOF
911
912DWARF section [28] '.debug_info' at offset 0x330:
913 [Offset]
914 Compilation unit at offset 0:
915 Version: 4, Abbreviation section offset: 0, Address size: 8, Offset size: 4
916 Unit type: skeleton (4), Unit id: 0x3d909d7bd0e69c0b
917 [     b]  compile_unit         abbrev: 1
918           ranges               (sec_offset) range list [     0]
919           low_pc               (addr) 000000000000000000
920           stmt_list            (sec_offset) 0
921           GNU_dwo_name         (strp) "splitdwarf4-not-split4.dwo"
922           comp_dir             (strp) "/tmp"
923           GNU_pubnames         (flag_present) yes
924           GNU_addr_base        (sec_offset) address base [     0]
925           GNU_dwo_id           (data8) 0x3d909d7bd0e69c0b
926           GNU_ranges_base      (sec_offset) 0
927 Split compilation unit at offset 0:
928 Version: 4, Abbreviation section offset: 0, Address size: 8, Offset size: 4
929 Unit type: skeleton (4), Unit id: 0x3d909d7bd0e69c0b
930 {     b}  compile_unit         abbrev: 1
931           producer             (GNU_str_index) "GNU C17 9.0.0 20180528 (experimental) -mtune=generic -march=x86-64 -gdwarf-4 -gsplit-dwarf -O2"
932           language             (data1) C99 (12)
933           name                 (GNU_str_index) "splitdwarf4-not-split4.c"
934           comp_dir             (GNU_str_index) "/tmp"
935           GNU_dwo_id           (data8) 0x3d909d7bd0e69c0b
936 {    18}    subprogram           abbrev: 2
937             external             (flag_present) yes
938             name                 (GNU_str_index) "main"
939             decl_file            (data1) splitdwarf4-not-split4.c (1)
940             decl_line            (data1) 3
941             decl_column          (data1) 5
942             prototyped           (flag_present) yes
943             type                 (ref4) {    6d}
944             low_pc               (GNU_addr_index) [4] 0x0000000000401050 <main>
945             high_pc              (data8) 76 (0x000000000040109c <_start>)
946             frame_base           (exprloc)
947              [ 0] call_frame_cfa
948             GNU_all_call_sites   (flag_present) yes
949             sibling              (ref4) {    6d}
950 {    30}      formal_parameter     abbrev: 3
951               name                 (GNU_str_index) "argc"
952               decl_file            (data1) splitdwarf4-not-split4.c (1)
953               decl_line            (data1) 3
954               decl_column          (data1) 15
955               type                 (ref4) {    6d}
956               location             (sec_offset) location list [     0]
957 {    3d}      formal_parameter     abbrev: 3
958               name                 (GNU_str_index) "argv"
959               decl_file            (data1) splitdwarf4-not-split4.c (1)
960               decl_line            (data1) 3
961               decl_column          (data1) 28
962               type                 (ref4) {    74}
963               location             (sec_offset) location list [    28]
964 {    4a}      variable             abbrev: 4
965               name                 (string) "i"
966               decl_file            (data1) splitdwarf4-not-split4.c (1)
967               decl_line            (data1) 5
968               decl_column          (data1) 7
969               type                 (ref4) {    6d}
970               location             (sec_offset) location list [    47]
971 {    58}      variable             abbrev: 4
972               name                 (string) "p"
973               decl_file            (data1) splitdwarf4-not-split4.c (1)
974               decl_line            (data1) 6
975               decl_column          (data1) 7
976               type                 (ref4) {    6d}
977               location             (sec_offset) location list [    73]
978 {    66}      GNU_call_site        abbrev: 5
979               low_pc               (GNU_addr_index) [1] 0x000000000040107f <main+0x2f>
980               abstract_origin      (ref4) {    84}
981 {    6d}    base_type            abbrev: 6
982             byte_size            (data1) 4
983             encoding             (data1) signed (5)
984             name                 (string) "int"
985 {    74}    pointer_type         abbrev: 7
986             byte_size            (data1) 8
987             type                 (ref4) {    7a}
988 {    7a}    pointer_type         abbrev: 7
989             byte_size            (data1) 8
990             type                 (ref4) {    80}
991 {    80}    base_type            abbrev: 8
992             byte_size            (data1) 1
993             encoding             (data1) signed_char (6)
994             name                 (GNU_str_index) "char"
995 {    84}    subprogram           abbrev: 9
996             external             (flag_present) yes
997             declaration          (flag_present) yes
998             linkage_name         (GNU_str_index) "popcount"
999             name                 (GNU_str_index) "popcount"
1000             decl_file            (data1) splitdwarf4-not-split4.c (1)
1001             decl_line            (data1) 1
1002             decl_column          (data1) 12
1003 Compilation unit at offset 52:
1004 Version: 4, Abbreviation section offset: 29, Address size: 8, Offset size: 4
1005 [    3f]  compile_unit         abbrev: 1
1006           producer             (strp) "GNU C17 9.0.0 20180528 (experimental) -mtune=generic -march=x86-64 -gdwarf-4 -O2"
1007           language             (data1) C99 (12)
1008           name                 (strp) "popcount.c"
1009           comp_dir             (strp) "/tmp"
1010           low_pc               (addr) 0x0000000000401180 <popcount>
1011           high_pc              (data8) 33 (0x00000000004011a1)
1012           stmt_list            (sec_offset) 145
1013 [    61]    subprogram           abbrev: 2
1014             external             (flag_present) yes
1015             name                 (strp) "popcount"
1016             decl_file            (data1) popcount.c (1)
1017             decl_line            (data1) 1
1018             decl_column          (data1) 5
1019             prototyped           (flag_present) yes
1020             type                 (ref4) [    a0]
1021             low_pc               (addr) 0x0000000000401180 <popcount>
1022             high_pc              (data8) 33 (0x00000000004011a1)
1023             frame_base           (exprloc)
1024              [ 0] call_frame_cfa
1025             GNU_all_call_sites   (flag_present) yes
1026             sibling              (ref4) [    a0]
1027 [    83]      formal_parameter     abbrev: 3
1028               name                 (string) "u"
1029               decl_file            (data1) popcount.c (1)
1030               decl_line            (data1) 1
1031               decl_column          (data1) 29
1032               type                 (ref4) [    a7]
1033               location             (sec_offset) location list [     0]
1034 [    91]      variable             abbrev: 4
1035               name                 (string) "c"
1036               decl_file            (data1) popcount.c (1)
1037               decl_line            (data1) 3
1038               decl_column          (data1) 7
1039               type                 (ref4) [    a0]
1040               location             (sec_offset) location list [    60]
1041 [    a0]    base_type            abbrev: 5
1042             byte_size            (data1) 4
1043             encoding             (data1) signed (5)
1044             name                 (string) "int"
1045 [    a7]    base_type            abbrev: 6
1046             byte_size            (data1) 1
1047             encoding             (data1) unsigned_char (8)
1048             name                 (strp) "unsigned char"
1049
1050DWARF section [32] '.debug_loc' at offset 0x5ef:
1051
1052 CU [    3f] base: 0x0000000000401180 <popcount>
1053 [     0] range 0, 9
1054          0x0000000000401180 <popcount>..
1055          0x0000000000401188 <popcount+0x8>
1056           [ 0] reg5
1057          range 9, 1b
1058          0x0000000000401189 <popcount+0x9>..
1059          0x000000000040119a <popcount+0x1a>
1060           [ 0] reg1
1061          range 1b, 1d
1062          0x000000000040119b <popcount+0x1b>..
1063          0x000000000040119c <popcount+0x1c>
1064           [ 0] breg1 0
1065           [ 2] lit1
1066           [ 3] shr
1067           [ 4] stack_value
1068          range 1d, 21
1069          0x000000000040119d <popcount+0x1d>..
1070          0x00000000004011a0 <popcount+0x20>
1071           [ 0] reg1
1072 [    60] range 0, 9
1073          0x0000000000401180 <popcount>..
1074          0x0000000000401188 <popcount+0x8>
1075           [ 0] lit0
1076           [ 1] stack_value
1077          range 9, 20
1078          0x0000000000401189 <popcount+0x9>..
1079          0x000000000040119f <popcount+0x1f>
1080           [ 0] reg0
1081          range 20, 21
1082          0x00000000004011a0 <popcount+0x20>..
1083          0x00000000004011a0 <popcount+0x20>
1084           [ 0] lit0
1085           [ 1] stack_value
1086EOF
1087
1088testrun_compare ${abs_top_builddir}/src/readelf --dwarf-skeleton=testfile-splitdwarf4-not-split4.debug --debug-dump=loc splitdwarf4-not-split4.dwo <<\EOF
1089
1090DWARF section [ 3] '.debug_loc.dwo' at offset 0x15b:
1091
1092 CU [     b] base: 000000000000000000
1093 [     0] range 401050, 40106e
1094          0x0000000000401050 <main>..
1095          0x000000000040106d <main+0x1d>
1096           [ 0] reg5
1097          range 40106e, 401086
1098          0x000000000040106e <main+0x1e>..
1099          0x0000000000401085 <main+0x35>
1100           [ 0] reg12
1101          range 401086, 401095
1102          0x0000000000401086 <main+0x36>..
1103          0x0000000000401094 <main+0x44>
1104           [ 0] GNU_entry_value:
1105                [ 0] reg5
1106           [ 3] stack_value
1107          range 401095, 40109c
1108          0x0000000000401095 <main+0x45>..
1109          0x000000000040109b <main+0x4b>
1110           [ 0] reg5
1111 [    28] range 401050, 40106e
1112          0x0000000000401050 <main>..
1113          0x000000000040106d <main+0x1d>
1114           [ 0] reg4
1115          range 40106e, 401095
1116          0x000000000040106e <main+0x1e>..
1117          0x0000000000401094 <main+0x44>
1118           [ 0] GNU_entry_value:
1119                [ 0] reg4
1120           [ 3] stack_value
1121          range 401095, 40109c
1122          0x0000000000401095 <main+0x45>..
1123          0x000000000040109b <main+0x4b>
1124           [ 0] reg4
1125 [    47] range 401050, 40106e
1126          0x0000000000401050 <main>..
1127          0x000000000040106d <main+0x1d>
1128           [ 0] lit0
1129           [ 1] stack_value
1130          range 401086, 40108e
1131          0x0000000000401086 <main+0x36>..
1132          0x000000000040108d <main+0x3d>
1133           [ 0] breg12 0
1134           [ 2] breg6 0
1135           [ 4] plus
1136           [ 5] stack_value
1137          range 40108e, 401095
1138          0x000000000040108e <main+0x3e>..
1139          0x0000000000401094 <main+0x44>
1140           [ 0] reg0
1141          range 401095, 40109c
1142          0x0000000000401095 <main+0x45>..
1143          0x000000000040109b <main+0x4b>
1144           [ 0] lit0
1145           [ 1] stack_value
1146 [    73] range 401050, 40106e
1147          0x0000000000401050 <main>..
1148          0x000000000040106d <main+0x1d>
1149           [ 0] reg5
1150          range 40106e, 401090
1151          0x000000000040106e <main+0x1e>..
1152          0x000000000040108f <main+0x3f>
1153           [ 0] reg6
1154          range 401095, 40109c
1155          0x0000000000401095 <main+0x45>..
1156          0x000000000040109b <main+0x4b>
1157           [ 0] reg5
1158EOF
1159
1160exit 0
1161