• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#! /bin/sh
2# Copyright (C) 2012, 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# common.h
21#
22# #include <stdio.h>
23#
24# struct foobar
25# {
26#   int foo;
27#   struct foobar *bar;
28# };
29#
30# extern int call_foo(struct foobar *foobar_struct_ptr);
31
32# main.c
33#
34# #include "common.h"
35#
36# int main(int argc, char ** argv)
37# {
38#   struct foobar b;
39#   b.foo = 42;
40#   b.bar = &b;
41#
42#   return call_foo(b.bar);
43# }
44
45# shared.c
46#
47# #include "common.h"
48#
49# int call_foo(struct foobar *fb)
50# {
51#   return fb->bar->foo - 42;
52# }
53
54# gcc -fPIC -g -c -Wall shared.c
55# gcc -shared -o libtestfile_multi_shared.so shared.o
56# gcc -g -o testfile_multi_main -L. -ltestfile_multi_shared main.c -Wl,-rpath,.
57# dwz -m testfile_multi.dwz testfile_multi_main libtestfile_multi_shared.so
58
59# main.c
60#
61# struct foobarbaz
62# {
63#   int counter;
64#   char *bookstore;
65# };
66#
67# int
68# main (int argc, char **argv)
69# {
70#   struct foobarbaz fbb;
71#   return 0;
72# }
73
74# gcc -g -o testfile-dwzstr main.c
75# cp testfile-dwzstr testfile-dwzstr.alt
76# dwz -m testfile-dwzstr.multi testfile-dwzstr testfile-dwzstr.alt
77
78testfiles libtestfile_multi_shared.so testfile_multi_main testfile_multi.dwz
79testfiles testfile-dwzstr testfile-dwzstr.multi
80
81testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=info testfile_multi_main <<\EOF
82
83DWARF section [28] '.debug_info' at offset 0x1078:
84 [Offset]
85 Compilation unit at offset 0:
86 Version: 4, Abbreviation section offset: 0, Address size: 8, Offset size: 4
87 [     b]  compile_unit
88           producer             (strp) "GNU C 4.7.0 20120507 (Red Hat 4.7.0-5) -mtune=generic -march=x86-64 -g"
89           language             (data1) C89 (1)
90           name                 (strp) "main.c"
91           comp_dir             (GNU_strp_alt) "/home/mark/src/tests/dwz"
92           low_pc               (addr) 0x00000000004006ac <main>
93           high_pc              (udata) 44 (0x00000000004006d8)
94           stmt_list            (sec_offset) 0
95 [    26]    imported_unit
96             import               (GNU_ref_alt) [     b]
97 [    2b]    pointer_type
98             byte_size            (data1) 8
99             type                 (GNU_ref_alt) [    53]
100 [    31]    subprogram
101             external             (flag_present)
102             name                 (strp) "main"
103             decl_file            (data1) 1
104             decl_line            (data1) 3
105             prototyped           (flag_present)
106             type                 (GNU_ref_alt) [    3e]
107             low_pc               (addr) 0x00000000004006ac <main>
108             high_pc              (udata) 44 (0x00000000004006d8)
109             frame_base           (exprloc)
110              [   0] call_frame_cfa
111             GNU_all_tail_call_sites (flag_present)
112             sibling              (ref_udata) [    6e]
113 [    48]      formal_parameter
114               name                 (strp) "argc"
115               decl_file            (data1) 1
116               decl_line            (data1) 3
117               type                 (GNU_ref_alt) [    3e]
118               location             (exprloc)
119                [   0] fbreg -36
120 [    56]      formal_parameter
121               name                 (strp) "argv"
122               decl_file            (data1) 1
123               decl_line            (data1) 3
124               type                 (ref_udata) [    6e]
125               location             (exprloc)
126                [   0] fbreg -48
127 [    61]      variable
128               name                 (string) "b"
129               decl_file            (data1) 1
130               decl_line            (data1) 5
131               type                 (GNU_ref_alt) [    5a]
132               location             (exprloc)
133                [   0] fbreg -32
134 [    6e]    pointer_type
135             byte_size            (data1) 8
136             type                 (ref_udata) [    2b]
137EOF
138
139# Same as above, but find alt debug file in a .dwz subdir.
140mkdir .dwz
141mv testfile_multi.dwz .dwz
142testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=info testfile_multi_main <<\EOF
143
144DWARF section [28] '.debug_info' at offset 0x1078:
145 [Offset]
146 Compilation unit at offset 0:
147 Version: 4, Abbreviation section offset: 0, Address size: 8, Offset size: 4
148 [     b]  compile_unit
149           producer             (strp) "GNU C 4.7.0 20120507 (Red Hat 4.7.0-5) -mtune=generic -march=x86-64 -g"
150           language             (data1) C89 (1)
151           name                 (strp) "main.c"
152           comp_dir             (GNU_strp_alt) "/home/mark/src/tests/dwz"
153           low_pc               (addr) 0x00000000004006ac <main>
154           high_pc              (udata) 44 (0x00000000004006d8)
155           stmt_list            (sec_offset) 0
156 [    26]    imported_unit
157             import               (GNU_ref_alt) [     b]
158 [    2b]    pointer_type
159             byte_size            (data1) 8
160             type                 (GNU_ref_alt) [    53]
161 [    31]    subprogram
162             external             (flag_present)
163             name                 (strp) "main"
164             decl_file            (data1) 1
165             decl_line            (data1) 3
166             prototyped           (flag_present)
167             type                 (GNU_ref_alt) [    3e]
168             low_pc               (addr) 0x00000000004006ac <main>
169             high_pc              (udata) 44 (0x00000000004006d8)
170             frame_base           (exprloc)
171              [   0] call_frame_cfa
172             GNU_all_tail_call_sites (flag_present)
173             sibling              (ref_udata) [    6e]
174 [    48]      formal_parameter
175               name                 (strp) "argc"
176               decl_file            (data1) 1
177               decl_line            (data1) 3
178               type                 (GNU_ref_alt) [    3e]
179               location             (exprloc)
180                [   0] fbreg -36
181 [    56]      formal_parameter
182               name                 (strp) "argv"
183               decl_file            (data1) 1
184               decl_line            (data1) 3
185               type                 (ref_udata) [    6e]
186               location             (exprloc)
187                [   0] fbreg -48
188 [    61]      variable
189               name                 (string) "b"
190               decl_file            (data1) 1
191               decl_line            (data1) 5
192               type                 (GNU_ref_alt) [    5a]
193               location             (exprloc)
194                [   0] fbreg -32
195 [    6e]    pointer_type
196             byte_size            (data1) 8
197             type                 (ref_udata) [    2b]
198EOF
199mv .dwz/testfile_multi.dwz .
200rmdir .dwz
201
202testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=info libtestfile_multi_shared.so <<\EOF
203
204DWARF section [25] '.debug_info' at offset 0x106c:
205 [Offset]
206 Compilation unit at offset 0:
207 Version: 4, Abbreviation section offset: 0, Address size: 8, Offset size: 4
208 [     b]  compile_unit
209           producer             (strp) "GNU C 4.7.0 20120507 (Red Hat 4.7.0-5) -fpreprocessed -mtune=generic -march=x86-64 -g -fPIC"
210           language             (data1) C89 (1)
211           name                 (strp) "shared.c"
212           comp_dir             (GNU_strp_alt) "/home/mark/src/tests/dwz"
213           low_pc               (addr) +0x0000000000000670 <call_foo>
214           high_pc              (udata) 23 (+0x0000000000000687)
215           stmt_list            (sec_offset) 0
216 [    26]    imported_unit
217             import               (GNU_ref_alt) [     b]
218 [    2b]    subprogram
219             external             (flag_present)
220             name                 (strp) "call_foo"
221             decl_file            (data1) 1
222             decl_line            (data1) 3
223             prototyped           (flag_present)
224             type                 (GNU_ref_alt) [    3e]
225             low_pc               (addr) +0x0000000000000670 <call_foo>
226             high_pc              (udata) 23 (+0x0000000000000687)
227             frame_base           (exprloc)
228              [   0] call_frame_cfa
229             GNU_all_call_sites   (flag_present)
230 [    41]      formal_parameter
231               name                 (string) "fb"
232               decl_file            (data1) 1
233               decl_line            (data1) 3
234               type                 (GNU_ref_alt) [    76]
235               location             (exprloc)
236                [   0] fbreg -24
237EOF
238
239# Same as above, but find alt debug file in a .dwz subdir.
240mkdir .dwz
241mv testfile_multi.dwz .dwz
242testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=info libtestfile_multi_shared.so <<\EOF
243
244DWARF section [25] '.debug_info' at offset 0x106c:
245 [Offset]
246 Compilation unit at offset 0:
247 Version: 4, Abbreviation section offset: 0, Address size: 8, Offset size: 4
248 [     b]  compile_unit
249           producer             (strp) "GNU C 4.7.0 20120507 (Red Hat 4.7.0-5) -fpreprocessed -mtune=generic -march=x86-64 -g -fPIC"
250           language             (data1) C89 (1)
251           name                 (strp) "shared.c"
252           comp_dir             (GNU_strp_alt) "/home/mark/src/tests/dwz"
253           low_pc               (addr) +0x0000000000000670 <call_foo>
254           high_pc              (udata) 23 (+0x0000000000000687)
255           stmt_list            (sec_offset) 0
256 [    26]    imported_unit
257             import               (GNU_ref_alt) [     b]
258 [    2b]    subprogram
259             external             (flag_present)
260             name                 (strp) "call_foo"
261             decl_file            (data1) 1
262             decl_line            (data1) 3
263             prototyped           (flag_present)
264             type                 (GNU_ref_alt) [    3e]
265             low_pc               (addr) +0x0000000000000670 <call_foo>
266             high_pc              (udata) 23 (+0x0000000000000687)
267             frame_base           (exprloc)
268              [   0] call_frame_cfa
269             GNU_all_call_sites   (flag_present)
270 [    41]      formal_parameter
271               name                 (string) "fb"
272               decl_file            (data1) 1
273               decl_line            (data1) 3
274               type                 (GNU_ref_alt) [    76]
275               location             (exprloc)
276                [   0] fbreg -24
277EOF
278mv .dwz/testfile_multi.dwz .
279rmdir .dwz
280
281testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=info testfile-dwzstr <<\EOF
282
283DWARF section [28] '.debug_info' at offset 0x1088:
284 [Offset]
285 Compilation unit at offset 0:
286 Version: 4, Abbreviation section offset: 0, Address size: 8, Offset size: 4
287 [     b]  compile_unit
288           producer             (GNU_strp_alt) "GNU C 4.7.2 20121109 (Red Hat 4.7.2-8) -mtune=generic -march=x86-64 -g"
289           language             (data1) C89 (1)
290           name                 (GNU_strp_alt) "main.c"
291           comp_dir             (GNU_strp_alt) "/home/mark/src/tests"
292           low_pc               (addr) 0x00000000004004ec <main>
293           high_pc              (udata) 18 (0x00000000004004fe)
294           stmt_list            (sec_offset) 0
295 [    26]    imported_unit
296             import               (GNU_ref_alt) [     b]
297 [    2b]    subprogram
298             external             (flag_present)
299             name                 (GNU_strp_alt) "main"
300             decl_file            (data1) 1
301             decl_line            (data1) 8
302             prototyped           (flag_present)
303             type                 (GNU_ref_alt) [    30]
304             low_pc               (addr) 0x00000000004004ec <main>
305             high_pc              (udata) 18 (0x00000000004004fe)
306             frame_base           (exprloc)
307              [   0] call_frame_cfa
308             GNU_all_call_sites   (flag_present)
309 [    41]      formal_parameter
310               name                 (GNU_strp_alt) "argc"
311               decl_file            (data1) 1
312               decl_line            (data1) 8
313               type                 (GNU_ref_alt) [    30]
314               location             (exprloc)
315                [   0] fbreg -36
316 [    4f]      formal_parameter
317               name                 (GNU_strp_alt) "argv"
318               decl_file            (data1) 1
319               decl_line            (data1) 8
320               type                 (GNU_ref_alt) [    41]
321               location             (exprloc)
322                [   0] fbreg -48
323 [    5d]      variable
324               name                 (string) "fbb"
325               decl_file            (data1) 1
326               decl_line            (data1) 10
327               type                 (GNU_ref_alt) [    14]
328               location             (exprloc)
329                [   0] fbreg -32
330EOF
331
332exit 0
333