summaryrefslogtreecommitdiff
path: root/tests/run-readelf-dwz-multi.sh
blob: 27e0f38c02d52587e22e3ef5ce5daa32bc49f412 (plain)
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
#! /bin/sh
# Copyright (C) 2012, 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

# common.h
#
# #include <stdio.h>
#
# struct foobar
# {
#   int foo;
#   struct foobar *bar;
# };
#
# extern int call_foo(struct foobar *foobar_struct_ptr);

# main.c
#
# #include "common.h"
#
# int main(int argc, char ** argv)
# {
#   struct foobar b;
#   b.foo = 42;
#   b.bar = &b;
#
#   return call_foo(b.bar);
# }

# shared.c
#
# #include "common.h"
#
# int call_foo(struct foobar *fb)
# {
#   return fb->bar->foo - 42;
# }

# gcc -fPIC -g -c -Wall shared.c
# gcc -shared -o libtestfile_multi_shared.so shared.o
# gcc -g -o testfile_multi_main -L. -ltestfile_multi_shared main.c -Wl,-rpath,.
# dwz -m testfile_multi.dwz testfile_multi_main libtestfile_multi_shared.so

# main.c
#
# struct foobarbaz
# {
#   int counter;
#   char *bookstore;
# };
#
# int
# main (int argc, char **argv)
# {
#   struct foobarbaz fbb;
#   return 0;
# }

# gcc -g -o testfile-dwzstr main.c
# cp testfile-dwzstr testfile-dwzstr.alt
# dwz -m testfile-dwzstr.multi testfile-dwzstr testfile-dwzstr.alt

testfiles libtestfile_multi_shared.so testfile_multi_main testfile_multi.dwz
testfiles testfile-dwzstr testfile-dwzstr.multi

testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=info testfile_multi_main <<\EOF

DWARF section [28] '.debug_info' at offset 0x1078:
 [Offset]
 Compilation unit at offset 0:
 Version: 4, Abbreviation section offset: 0, Address size: 8, Offset size: 4
 [     b]  compile_unit
           producer             (strp) "GNU C 4.7.0 20120507 (Red Hat 4.7.0-5) -mtune=generic -march=x86-64 -g"
           language             (data1) C89 (1)
           name                 (strp) "main.c"
           comp_dir             (GNU_strp_alt) "/home/mark/src/tests/dwz"
           low_pc               (addr) 0x00000000004006ac <main>
           high_pc              (udata) 44 (0x00000000004006d8)
           stmt_list            (sec_offset) 0
 [    26]    imported_unit
             import               (GNU_ref_alt) [     b]
 [    2b]    pointer_type
             byte_size            (data1) 8
             type                 (GNU_ref_alt) [    53]
 [    31]    subprogram
             external             (flag_present) 
             name                 (strp) "main"
             decl_file            (data1) 1
             decl_line            (data1) 3
             prototyped           (flag_present) 
             type                 (GNU_ref_alt) [    3e]
             low_pc               (addr) 0x00000000004006ac <main>
             high_pc              (udata) 44 (0x00000000004006d8)
             frame_base           (exprloc) 
              [   0] call_frame_cfa
             GNU_all_tail_call_sites (flag_present) 
             sibling              (ref_udata) [    6e]
 [    48]      formal_parameter
               name                 (strp) "argc"
               decl_file            (data1) 1
               decl_line            (data1) 3
               type                 (GNU_ref_alt) [    3e]
               location             (exprloc) 
                [   0] fbreg -36
 [    56]      formal_parameter
               name                 (strp) "argv"
               decl_file            (data1) 1
               decl_line            (data1) 3
               type                 (ref_udata) [    6e]
               location             (exprloc) 
                [   0] fbreg -48
 [    61]      variable
               name                 (string) "b"
               decl_file            (data1) 1
               decl_line            (data1) 5
               type                 (GNU_ref_alt) [    5a]
               location             (exprloc) 
                [   0] fbreg -32
 [    6e]    pointer_type
             byte_size            (data1) 8
             type                 (ref_udata) [    2b]
EOF

# Same as above, but find alt debug file in a .dwz subdir.
mkdir .dwz
mv testfile_multi.dwz .dwz
testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=info testfile_multi_main <<\EOF

DWARF section [28] '.debug_info' at offset 0x1078:
 [Offset]
 Compilation unit at offset 0:
 Version: 4, Abbreviation section offset: 0, Address size: 8, Offset size: 4
 [     b]  compile_unit
           producer             (strp) "GNU C 4.7.0 20120507 (Red Hat 4.7.0-5) -mtune=generic -march=x86-64 -g"
           language             (data1) C89 (1)
           name                 (strp) "main.c"
           comp_dir             (GNU_strp_alt) "/home/mark/src/tests/dwz"
           low_pc               (addr) 0x00000000004006ac <main>
           high_pc              (udata) 44 (0x00000000004006d8)
           stmt_list            (sec_offset) 0
 [    26]    imported_unit
             import               (GNU_ref_alt) [     b]
 [    2b]    pointer_type
             byte_size            (data1) 8
             type                 (GNU_ref_alt) [    53]
 [    31]    subprogram
             external             (flag_present) 
             name                 (strp) "main"
             decl_file            (data1) 1
             decl_line            (data1) 3
             prototyped           (flag_present) 
             type                 (GNU_ref_alt) [    3e]
             low_pc               (addr) 0x00000000004006ac <main>
             high_pc              (udata) 44 (0x00000000004006d8)
             frame_base           (exprloc) 
              [   0] call_frame_cfa
             GNU_all_tail_call_sites (flag_present) 
             sibling              (ref_udata) [    6e]
 [    48]      formal_parameter
               name                 (strp) "argc"
               decl_file            (data1) 1
               decl_line            (data1) 3
               type                 (GNU_ref_alt) [    3e]
               location             (exprloc) 
                [   0] fbreg -36
 [    56]      formal_parameter
               name                 (strp) "argv"
               decl_file            (data1) 1
               decl_line            (data1) 3
               type                 (ref_udata) [    6e]
               location             (exprloc) 
                [   0] fbreg -48
 [    61]      variable
               name                 (string) "b"
               decl_file            (data1) 1
               decl_line            (data1) 5
               type                 (GNU_ref_alt) [    5a]
               location             (exprloc) 
                [   0] fbreg -32
 [    6e]    pointer_type
             byte_size            (data1) 8
             type                 (ref_udata) [    2b]
EOF
mv .dwz/testfile_multi.dwz .
rmdir .dwz

testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=info libtestfile_multi_shared.so <<\EOF

DWARF section [25] '.debug_info' at offset 0x106c:
 [Offset]
 Compilation unit at offset 0:
 Version: 4, Abbreviation section offset: 0, Address size: 8, Offset size: 4
 [     b]  compile_unit
           producer             (strp) "GNU C 4.7.0 20120507 (Red Hat 4.7.0-5) -fpreprocessed -mtune=generic -march=x86-64 -g -fPIC"
           language             (data1) C89 (1)
           name                 (strp) "shared.c"
           comp_dir             (GNU_strp_alt) "/home/mark/src/tests/dwz"
           low_pc               (addr) +0x0000000000000670 <call_foo>
           high_pc              (udata) 23 (+0x0000000000000687)
           stmt_list            (sec_offset) 0
 [    26]    imported_unit
             import               (GNU_ref_alt) [     b]
 [    2b]    subprogram
             external             (flag_present) 
             name                 (strp) "call_foo"
             decl_file            (data1) 1
             decl_line            (data1) 3
             prototyped           (flag_present) 
             type                 (GNU_ref_alt) [    3e]
             low_pc               (addr) +0x0000000000000670 <call_foo>
             high_pc              (udata) 23 (+0x0000000000000687)
             frame_base           (exprloc) 
              [   0] call_frame_cfa
             GNU_all_call_sites   (flag_present) 
 [    41]      formal_parameter
               name                 (string) "fb"
               decl_file            (data1) 1
               decl_line            (data1) 3
               type                 (GNU_ref_alt) [    76]
               location             (exprloc) 
                [   0] fbreg -24
EOF

# Same as above, but find alt debug file in a .dwz subdir.
mkdir .dwz
mv testfile_multi.dwz .dwz
testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=info libtestfile_multi_shared.so <<\EOF

DWARF section [25] '.debug_info' at offset 0x106c:
 [Offset]
 Compilation unit at offset 0:
 Version: 4, Abbreviation section offset: 0, Address size: 8, Offset size: 4
 [     b]  compile_unit
           producer             (strp) "GNU C 4.7.0 20120507 (Red Hat 4.7.0-5) -fpreprocessed -mtune=generic -march=x86-64 -g -fPIC"
           language             (data1) C89 (1)
           name                 (strp) "shared.c"
           comp_dir             (GNU_strp_alt) "/home/mark/src/tests/dwz"
           low_pc               (addr) +0x0000000000000670 <call_foo>
           high_pc              (udata) 23 (+0x0000000000000687)
           stmt_list            (sec_offset) 0
 [    26]    imported_unit
             import               (GNU_ref_alt) [     b]
 [    2b]    subprogram
             external             (flag_present) 
             name                 (strp) "call_foo"
             decl_file            (data1) 1
             decl_line            (data1) 3
             prototyped           (flag_present) 
             type                 (GNU_ref_alt) [    3e]
             low_pc               (addr) +0x0000000000000670 <call_foo>
             high_pc              (udata) 23 (+0x0000000000000687)
             frame_base           (exprloc) 
              [   0] call_frame_cfa
             GNU_all_call_sites   (flag_present) 
 [    41]      formal_parameter
               name                 (string) "fb"
               decl_file            (data1) 1
               decl_line            (data1) 3
               type                 (GNU_ref_alt) [    76]
               location             (exprloc) 
                [   0] fbreg -24
EOF
mv .dwz/testfile_multi.dwz .
rmdir .dwz

testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=info testfile-dwzstr <<\EOF

DWARF section [28] '.debug_info' at offset 0x1088:
 [Offset]
 Compilation unit at offset 0:
 Version: 4, Abbreviation section offset: 0, Address size: 8, Offset size: 4
 [     b]  compile_unit
           producer             (GNU_strp_alt) "GNU C 4.7.2 20121109 (Red Hat 4.7.2-8) -mtune=generic -march=x86-64 -g"
           language             (data1) C89 (1)
           name                 (GNU_strp_alt) "main.c"
           comp_dir             (GNU_strp_alt) "/home/mark/src/tests"
           low_pc               (addr) 0x00000000004004ec <main>
           high_pc              (udata) 18 (0x00000000004004fe)
           stmt_list            (sec_offset) 0
 [    26]    imported_unit
             import               (GNU_ref_alt) [     b]
 [    2b]    subprogram
             external             (flag_present) 
             name                 (GNU_strp_alt) "main"
             decl_file            (data1) 1
             decl_line            (data1) 8
             prototyped           (flag_present) 
             type                 (GNU_ref_alt) [    30]
             low_pc               (addr) 0x00000000004004ec <main>
             high_pc              (udata) 18 (0x00000000004004fe)
             frame_base           (exprloc) 
              [   0] call_frame_cfa
             GNU_all_call_sites   (flag_present) 
 [    41]      formal_parameter
               name                 (GNU_strp_alt) "argc"
               decl_file            (data1) 1
               decl_line            (data1) 8
               type                 (GNU_ref_alt) [    30]
               location             (exprloc) 
                [   0] fbreg -36
 [    4f]      formal_parameter
               name                 (GNU_strp_alt) "argv"
               decl_file            (data1) 1
               decl_line            (data1) 8
               type                 (GNU_ref_alt) [    41]
               location             (exprloc) 
                [   0] fbreg -48
 [    5d]      variable
               name                 (string) "fbb"
               decl_file            (data1) 1
               decl_line            (data1) 10
               type                 (GNU_ref_alt) [    14]
               location             (exprloc) 
                [   0] fbreg -32
EOF

exit 0