blob: e5152df85d6c3c32fc935cf7cfd5785da9bfd430 [file] [log] [blame]
Brian Silverman86497922018-02-10 19:28:39 -05001#! /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
170exit 0