1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
|
#! /bin/sh
# Copyright (C) 2013 Red Hat, Inc.
# This file is part of elfutils.
#
# This file is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# elfutils is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
. $srcdir/test-subr.sh
# - hello.c
# int say (const char *prefix);
#
# static char *
# subject (char *word, int count)
# {
# return count > 0 ? word : (word + count);
# }
#
# int
# main (int argc, char **argv)
# {
# return say (subject (argv[0], argc));
# }
#
# - world.c
# static int
# sad (char c)
# {
# return c > 0 ? c : c + 1;
# }
#
# static int
# happy (const char *w)
# {
# return sad (w[1]);
# }
#
# int
# say (const char *prefix)
# {
# const char *world = "World";
# return prefix ? sad (prefix[0]) : happy (world);
# }
#
# gcc -g -O2 -c hello.c
# gcc -g -O2 -c world.c
# gcc -g -o testfileloc hello.o world.o
testfiles testfileloc
# Process values as offsets from base addresses and resolve to symbols.
testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=loc --debug-dump=ranges \
testfileloc<<\EOF
DWARF section [33] '.debug_loc' at offset 0xd2a:
CU [ b] base: 0x0000000000400480 <main>
[ 0] range 0, d
0x0000000000400480 <main>..
0x000000000040048c <main+0xc>
[ 0] reg5
[ 23] range 5, d
0x0000000000400485 <main+0x5>..
0x000000000040048c <main+0xc>
[ 0] reg5
CU [ e0] base: 0x00000000004004a0 <say>
[ 46] range 12, 1a
0x00000000004004b2 <say+0x12>..
0x00000000004004b9 <say+0x19>
[ 0] breg5 0
DWARF section [34] '.debug_ranges' at offset 0xd94:
CU [ b] base: 0x0000000000400480 <main>
[ 0] range 0, 2
0x0000000000400480 <main>..
0x0000000000400481 <main+0x1>
range 5, d
0x0000000000400485 <main+0x5>..
0x000000000040048c <main+0xc>
CU [ e0] base: 0x00000000004004a0 <say>
[ 30] range d, f
0x00000000004004ad <say+0xd>..
0x00000000004004ae <say+0xe>
range 12, 1a
0x00000000004004b2 <say+0x12>..
0x00000000004004b9 <say+0x19>
EOF
# Don't resolve addresses to symbols.
testrun_compare ${abs_top_builddir}/src/readelf -N --debug-dump=loc --debug-dump=ranges \
testfileloc<<\EOF
DWARF section [33] '.debug_loc' at offset 0xd2a:
CU [ b] base: 0x0000000000400480
[ 0] range 0, d
0x0000000000400480..
0x000000000040048c
[ 0] reg5
[ 23] range 5, d
0x0000000000400485..
0x000000000040048c
[ 0] reg5
CU [ e0] base: 0x00000000004004a0
[ 46] range 12, 1a
0x00000000004004b2..
0x00000000004004b9
[ 0] breg5 0
DWARF section [34] '.debug_ranges' at offset 0xd94:
CU [ b] base: 0x0000000000400480
[ 0] range 0, 2
0x0000000000400480..
0x0000000000400481
range 5, d
0x0000000000400485..
0x000000000040048c
CU [ e0] base: 0x00000000004004a0
[ 30] range d, f
0x00000000004004ad..
0x00000000004004ae
range 12, 1a
0x00000000004004b2..
0x00000000004004b9
EOF
# Produce "raw" unprocessed content.
testrun_compare ${abs_top_builddir}/src/readelf -U --debug-dump=loc --debug-dump=ranges \
testfileloc<<\EOF
DWARF section [33] '.debug_loc' at offset 0xd2a:
CU [ b] base: 0x0000000000400480
[ 0] range 0, d
[ 0] reg5
[ 23] range 5, d
[ 0] reg5
CU [ e0] base: 0x00000000004004a0
[ 46] range 12, 1a
[ 0] breg5 0
DWARF section [34] '.debug_ranges' at offset 0xd94:
CU [ b] base: 0x0000000000400480
[ 0] range 0, 2
range 5, d
CU [ e0] base: 0x00000000004004a0
[ 30] range d, f
range 12, 1a
EOF
# .debug_rnglists (DWARF5), see tests/testfile-dwarf-45.source
testfiles testfile-dwarf-5
testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=loc testfile-dwarf-5<<\EOF
DWARF section [31] '.debug_loclists' at offset 0x1c0c:
Table at Offset 0x0:
Length: 96
DWARF version: 5
Address size: 8
Segment size: 0
Offset entries: 0
CU [ c] base: 0x0000000000400510 <foo>
Offset: c, Index: 0
offset_pair 0, a
0x0000000000400510 <foo>..
0x0000000000400519 <foo+0x9>
[ 0] reg5
offset_pair a, 34
0x000000000040051a <foo+0xa>..
0x0000000000400543 <foo+0x33>
[ 0] entry_value:
[ 0] reg5
[ 3] stack_value
end_of_list
Offset: 1a, Index: e
offset_pair 1b, 2d
0x000000000040052b <foo+0x1b>..
0x000000000040053c <foo+0x2c>
[ 0] addr 0x601038 <m>
end_of_list
Offset: 28, Index: 1c
offset_pair 1b, 21
0x000000000040052b <foo+0x1b>..
0x0000000000400530 <foo+0x20>
[ 0] reg5
end_of_list
Offset: 2e, Index: 22
offset_pair 1b, 27
0x000000000040052b <foo+0x1b>..
0x0000000000400536 <foo+0x26>
[ 0] reg5
offset_pair 29, 2d
0x0000000000400539 <foo+0x29>..
0x000000000040053c <foo+0x2c>
[ 0] reg5
end_of_list
Offset: 39, Index: 2d
offset_pair 21, 27
0x0000000000400531 <foo+0x21>..
0x0000000000400536 <foo+0x26>
[ 0] reg5
offset_pair 29, 2d
0x0000000000400539 <foo+0x29>..
0x000000000040053c <foo+0x2c>
[ 0] reg5
end_of_list
Offset: 44, Index: 38
offset_pair 21, 2d
0x0000000000400531 <foo+0x21>..
0x000000000040053c <foo+0x2c>
[ 0] reg5
end_of_list
Offset: 4a, Index: 3e
offset_pair 2d, 33
0x000000000040053d <foo+0x2d>..
0x0000000000400542 <foo+0x32>
[ 0] reg5
end_of_list
Offset: 50, Index: 44
offset_pair 40, 4f
0x0000000000400550 <baz>..
0x000000000040055e <baz+0xe>
[ 0] reg5
offset_pair 4f, 51
0x000000000040055f <baz+0xf>..
0x0000000000400560 <baz+0x10>
[ 0] entry_value:
[ 0] reg5
[ 3] stack_value
end_of_list
Offset: 5e, Index: 52
offset_pair 40, 50
0x0000000000400550 <baz>..
0x000000000040055f <baz+0xf>
[ 0] reg5
end_of_list
Table at Offset 0x64:
Length: 159
DWARF version: 5
Address size: 8
Segment size: 0
Offset entries: 0
CU [ 218] base: 000000000000000000
Offset: 70, Index: 0
base_address 0x400410
0x0000000000400410 <main>
offset_pair 0, 14
0x0000000000400410 <main>..
0x0000000000400423 <main+0x13>
[ 0] reg5
offset_pair 14, 20
0x0000000000400424 <main+0x14>..
0x000000000040042f <main+0x1f>
[ 0] entry_value:
[ 0] reg5
[ 3] stack_value
end_of_list
Offset: 87, Index: 17
base_address 0x400410
0x0000000000400410 <main>
offset_pair 0, 18
0x0000000000400410 <main>..
0x0000000000400427 <main+0x17>
[ 0] reg4
offset_pair 18, 20
0x0000000000400428 <main+0x18>..
0x000000000040042f <main+0x1f>
[ 0] entry_value:
[ 0] reg4
[ 3] stack_value
end_of_list
Offset: 9e, Index: 2e
start_length 0x400421, 7
0x0000000000400421 <main+0x11>..
0x0000000000400427 <main+0x17>
[ 0] reg0
end_of_list
Offset: ab, Index: 3b
base_address 0x400570
0x0000000000400570 <calc>
offset_pair 0, 8
0x0000000000400570 <calc>..
0x0000000000400577 <calc+0x7>
[ 0] reg5
offset_pair 8, 2b
0x0000000000400578 <calc+0x8>..
0x000000000040059a <calc+0x2a>
[ 0] entry_value:
[ 0] reg5
[ 3] stack_value
end_of_list
Offset: c2, Index: 52
start_length 0x400588, b
0x0000000000400588 <calc+0x18>..
0x0000000000400592 <calc+0x22>
[ 0] reg0
end_of_list
Offset: cf, Index: 5f
base_address 0x400588
0x0000000000400588 <calc+0x18>
offset_pair 0, 2
0x0000000000400588 <calc+0x18>..
0x0000000000400589 <calc+0x19>
[ 0] reg1
offset_pair 2, 7
0x000000000040058a <calc+0x1a>..
0x000000000040058e <calc+0x1e>
[ 0] reg5
offset_pair 7, b
0x000000000040058f <calc+0x1f>..
0x0000000000400592 <calc+0x22>
[ 0] entry_value:
[ 0] reg5
[ 3] deref_size 1
[ 5] const1u 56
[ 7] shl
[ 8] const1u 56
[10] shra
[11] stack_value
end_of_list
Offset: f3, Index: 83
base_address 0x400588
0x0000000000400588 <calc+0x18>
offset_pair 0, 2
0x0000000000400588 <calc+0x18>..
0x0000000000400589 <calc+0x19>
[ 0] reg1
offset_pair 2, b
0x000000000040058a <calc+0x1a>..
0x0000000000400592 <calc+0x22>
[ 0] reg5
end_of_list
EOF
# Same as above, but for DWARF4, note completely different encoding, but
# the information is the same (check with diff -uwb).
testfiles testfile-dwarf-4
testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=loc testfile-dwarf-4<<\EOF
DWARF section [31] '.debug_loc' at offset 0x1c86:
CU [ b] base: 0x0000000000400510 <foo>
[ 0] range 0, a
0x0000000000400510 <foo>..
0x0000000000400519 <foo+0x9>
[ 0] reg5
range a, 34
0x000000000040051a <foo+0xa>..
0x0000000000400543 <foo+0x33>
[ 0] GNU_entry_value:
[ 0] reg5
[ 3] stack_value
[ 39] range 1b, 2d
0x000000000040052b <foo+0x1b>..
0x000000000040053c <foo+0x2c>
[ 0] addr 0x601038 <m>
[ 64] range 1b, 21
0x000000000040052b <foo+0x1b>..
0x0000000000400530 <foo+0x20>
[ 0] reg5
[ 87] range 1b, 27
0x000000000040052b <foo+0x1b>..
0x0000000000400536 <foo+0x26>
[ 0] reg5
range 29, 2d
0x0000000000400539 <foo+0x29>..
0x000000000040053c <foo+0x2c>
[ 0] reg5
[ bd] range 21, 27
0x0000000000400531 <foo+0x21>..
0x0000000000400536 <foo+0x26>
[ 0] reg5
range 29, 2d
0x0000000000400539 <foo+0x29>..
0x000000000040053c <foo+0x2c>
[ 0] reg5
[ f3] range 21, 2d
0x0000000000400531 <foo+0x21>..
0x000000000040053c <foo+0x2c>
[ 0] reg5
[ 116] range 2d, 33
0x000000000040053d <foo+0x2d>..
0x0000000000400542 <foo+0x32>
[ 0] reg5
[ 139] range 40, 4f
0x0000000000400550 <baz>..
0x000000000040055e <baz+0xe>
[ 0] reg5
range 4f, 51
0x000000000040055f <baz+0xf>..
0x0000000000400560 <baz+0x10>
[ 0] GNU_entry_value:
[ 0] reg5
[ 3] stack_value
[ 172] range 40, 50
0x0000000000400550 <baz>..
0x000000000040055f <baz+0xf>
[ 0] reg5
CU [ 21c] base: 000000000000000000
[ 195] range 400410, 400424
0x0000000000400410 <main>..
0x0000000000400423 <main+0x13>
[ 0] reg5
range 400424, 400430
0x0000000000400424 <main+0x14>..
0x000000000040042f <main+0x1f>
[ 0] GNU_entry_value:
[ 0] reg5
[ 3] stack_value
[ 1ce] range 400410, 400428
0x0000000000400410 <main>..
0x0000000000400427 <main+0x17>
[ 0] reg4
range 400428, 400430
0x0000000000400428 <main+0x18>..
0x000000000040042f <main+0x1f>
[ 0] GNU_entry_value:
[ 0] reg4
[ 3] stack_value
[ 207] range 400421, 400428
0x0000000000400421 <main+0x11>..
0x0000000000400427 <main+0x17>
[ 0] reg0
[ 22a] range 400570, 400578
0x0000000000400570 <calc>..
0x0000000000400577 <calc+0x7>
[ 0] reg5
range 400578, 40059b
0x0000000000400578 <calc+0x8>..
0x000000000040059a <calc+0x2a>
[ 0] GNU_entry_value:
[ 0] reg5
[ 3] stack_value
[ 263] range 400588, 400593
0x0000000000400588 <calc+0x18>..
0x0000000000400592 <calc+0x22>
[ 0] reg0
[ 286] range 400588, 40058a
0x0000000000400588 <calc+0x18>..
0x0000000000400589 <calc+0x19>
[ 0] reg1
range 40058a, 40058f
0x000000000040058a <calc+0x1a>..
0x000000000040058e <calc+0x1e>
[ 0] reg5
range 40058f, 400593
0x000000000040058f <calc+0x1f>..
0x0000000000400592 <calc+0x22>
[ 0] GNU_entry_value:
[ 0] reg5
[ 3] deref_size 1
[ 5] const1u 56
[ 7] shl
[ 8] const1u 56
[10] shra
[11] stack_value
[ 2da] range 400588, 40058a
0x0000000000400588 <calc+0x18>..
0x0000000000400589 <calc+0x19>
[ 0] reg1
range 40058a, 400593
0x000000000040058a <calc+0x1a>..
0x0000000000400592 <calc+0x22>
[ 0] reg5
EOF
# Split DWARF5 variant. Note that the .debug_loclists moved to the .dwo file
# and now uses an index and addrx indirections.
testfiles testfile-splitdwarf-5 testfile-hello5.dwo testfile-world5.dwo
testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=loc --dwarf-skeleton=testfile-splitdwarf-5 testfile-hello5.dwo testfile-world5.dwo <<\EOF
testfile-hello5.dwo:
DWARF section [ 3] '.debug_loclists.dwo' at offset 0x236:
Table at Offset 0x0:
Length: 125
DWARF version: 5
Address size: 8
Segment size: 0
Offset entries: 9
CU [ 14] base: 0x0000000000401160 <foo>
Offsets starting at 0xc:
[ 0] 0x24
[ 1] 0x32
[ 2] 0x39
[ 3] 0x3f
[ 4] 0x4a
[ 5] 0x55
[ 6] 0x5b
[ 7] 0x61
[ 8] 0x6f
Offset: 30, Index: 24
startx_length f, a
0x0000000000401160 <foo>..
0x0000000000401169 <foo+0x9>..
[ 0] reg5
startx_length 0, 2a
0x000000000040116a <foo+0xa>..
0x0000000000401193 <foo+0x33>..
[ 0] entry_value:
[ 0] reg5
[ 3] stack_value
end_of_list
Offset: 3e, Index: 32
startx_length 11, 12
0x000000000040117b <foo+0x1b>..
0x000000000040118c <foo+0x2c>..
[ 0] addrx [18] 0x404038 <m>
end_of_list
Offset: 45, Index: 39
startx_length 11, 6
0x000000000040117b <foo+0x1b>..
0x0000000000401180 <foo+0x20>..
[ 0] reg5
end_of_list
Offset: 4b, Index: 3f
startx_length 11, c
0x000000000040117b <foo+0x1b>..
0x0000000000401186 <foo+0x26>..
[ 0] reg5
startx_length 1, 4
0x0000000000401189 <foo+0x29>..
0x000000000040118c <foo+0x2c>..
[ 0] reg5
end_of_list
Offset: 56, Index: 4a
startx_length 4, 6
0x0000000000401181 <foo+0x21>..
0x0000000000401186 <foo+0x26>..
[ 0] reg5
startx_length 1, 4
0x0000000000401189 <foo+0x29>..
0x000000000040118c <foo+0x2c>..
[ 0] reg5
end_of_list
Offset: 61, Index: 55
startx_length 4, c
0x0000000000401181 <foo+0x21>..
0x000000000040118c <foo+0x2c>..
[ 0] reg5
end_of_list
Offset: 67, Index: 5b
startx_length 2, 6
0x000000000040118d <foo+0x2d>..
0x0000000000401192 <foo+0x32>..
[ 0] reg5
end_of_list
Offset: 6d, Index: 61
startx_length 9, f
0x00000000004011a0 <baz>..
0x00000000004011ae <baz+0xe>..
[ 0] reg5
startx_length 5, 2
0x00000000004011af <baz+0xf>..
0x00000000004011b0 <baz+0x10>..
[ 0] entry_value:
[ 0] reg5
[ 3] stack_value
end_of_list
Offset: 7b, Index: 6f
startx_length 9, 10
0x00000000004011a0 <baz>..
0x00000000004011af <baz+0xf>..
[ 0] reg5
end_of_list
testfile-world5.dwo:
DWARF section [ 3] '.debug_loclists.dwo' at offset 0x217:
Table at Offset 0x0:
Length: 128
DWARF version: 5
Address size: 8
Segment size: 0
Offset entries: 7
CU [ 14] base: 000000000000000000
Offsets starting at 0xc:
[ 0] 0x1c
[ 1] 0x2a
[ 2] 0x38
[ 3] 0x3e
[ 4] 0x4c
[ 5] 0x52
[ 6] 0x6d
Offset: 28, Index: 1c
startx_length 2, 14
0x0000000000401060 <main>..
0x0000000000401073 <main+0x13>..
[ 0] reg5
startx_length 4, c
0x0000000000401074 <main+0x14>..
0x000000000040107f <main+0x1f>..
[ 0] entry_value:
[ 0] reg5
[ 3] stack_value
end_of_list
Offset: 36, Index: 2a
startx_length 2, 18
0x0000000000401060 <main>..
0x0000000000401077 <main+0x17>..
[ 0] reg4
startx_length 7, 6
0x0000000000401078 <main+0x18>..
0x000000000040107d <main+0x1d>..
[ 0] entry_value:
[ 0] reg4
[ 3] stack_value
end_of_list
Offset: 44, Index: 38
startx_length 3, 7
0x0000000000401071 <main+0x11>..
0x0000000000401077 <main+0x17>..
[ 0] reg0
end_of_list
Offset: 4a, Index: 3e
startx_length d, 8
0x00000000004011c0 <calc>..
0x00000000004011c7 <calc+0x7>..
[ 0] reg5
startx_length e, 23
0x00000000004011c8 <calc+0x8>..
0x00000000004011ea <calc+0x2a>..
[ 0] entry_value:
[ 0] reg5
[ 3] stack_value
end_of_list
Offset: 58, Index: 4c
startx_length f, b
0x00000000004011d8 <calc+0x18>..
0x00000000004011e2 <calc+0x22>..
[ 0] reg0
end_of_list
Offset: 5e, Index: 52
startx_length f, 2
0x00000000004011d8 <calc+0x18>..
0x00000000004011d9 <calc+0x19>..
[ 0] reg1
startx_length 10, 5
0x00000000004011da <calc+0x1a>..
0x00000000004011de <calc+0x1e>..
[ 0] reg5
startx_length 0, 4
0x00000000004011df <calc+0x1f>..
0x00000000004011e2 <calc+0x22>..
[ 0] entry_value:
[ 0] reg5
[ 3] deref_size 1
[ 5] const1u 56
[ 7] shl
[ 8] const1u 56
[10] shra
[11] stack_value
end_of_list
Offset: 79, Index: 6d
startx_length f, 2
0x00000000004011d8 <calc+0x18>..
0x00000000004011d9 <calc+0x19>..
[ 0] reg1
startx_length 10, 9
0x00000000004011da <calc+0x1a>..
0x00000000004011e2 <calc+0x22>..
[ 0] reg5
end_of_list
EOF
exit 0
|