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
|
#! /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
exit 0
|