082971e0b35051169b29fc5c07ddac68cd1fba94
[platform/upstream/elfutils.git] / tests / run-readelf-zdebug-rel.sh
1 #! /bin/sh
2 # Copyright (C) 2015 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 # - testfile-zdebug-rel.c
21 # #define UINT64_MAX 18446744073709551615UL
22 #
23 # int
24 # main (int argc, char **argv)
25 # {
26 #   unsigned long a = UINT64_MAX - 8;
27 #   unsigned long b = 42 + argc;
28 #
29 #   if ( a + b < b )
30 #     argc = a + argc;
31 #   else
32 #      b--;
33 #
34 #   return a - b;
35 # }
36 #
37 # gcc -Og -g -Xassembler --compress-debug-sections=none \
38 #     -c -o testfile-debug-rel.o testfile-zdebug-rel.c
39 # gcc -Og -g -Xassembler --compress-debug-sections=zlib-gnu \
40 #     -c -o testfile-debug-rel-g.o testfile-zdebug-rel.c
41 # gcc -Og -g -Xassembler --compress-debug-sections=zlib-gabi \
42 #     -c -o testfile-debug-rel-z.o testfile-zdebug-rel.c
43
44 testfiles testfile-debug-rel.o testfile-debug-rel-g.o testfile-debug-rel-z.o
45 tempfiles readelf.out
46 tempfiles info.out loc.out
47
48 cat > info.out << \EOF
49
50 DWARF section [ 4] '.debug_info' at offset 0x58:
51  [Offset]
52  Compilation unit at offset 0:
53  Version: 4, Abbreviation section offset: 0, Address size: 8, Offset size: 4
54  [     b]  compile_unit
55            producer             (strp) "GNU C11 5.3.1 20151207 (Red Hat 5.3.1-2) -mtune=generic -march=x86-64 -g -Og"
56            language             (data1) C99 (12)
57            name                 (strp) "testfile-zdebug-rel.c"
58            comp_dir             (strp) "/tmp"
59            low_pc               (addr) 000000000000000000
60            high_pc              (data8) 24 (0x0000000000000018)
61            stmt_list            (sec_offset) 0
62  [    2d]    subprogram
63              external             (flag_present) yes
64              name                 (strp) "main"
65              decl_file            (data1) 1
66              decl_line            (data1) 4
67              prototyped           (flag_present) yes
68              type                 (ref4) [    80]
69              low_pc               (addr) 000000000000000000
70              high_pc              (data8) 24 (0x0000000000000018)
71              frame_base           (exprloc) 
72               [ 0] call_frame_cfa
73              GNU_all_call_sites   (flag_present) yes
74              sibling              (ref4) [    80]
75  [    4e]      formal_parameter
76                name                 (strp) "argc"
77                decl_file            (data1) 1
78                decl_line            (data1) 4
79                type                 (ref4) [    80]
80                location             (sec_offset) location list [     0]
81  [    5d]      formal_parameter
82                name                 (strp) "argv"
83                decl_file            (data1) 1
84                decl_line            (data1) 4
85                type                 (ref4) [    87]
86                location             (exprloc) 
87                 [ 0] reg4
88  [    6a]      variable
89                name                 (string) "a"
90                decl_file            (data1) 1
91                decl_line            (data1) 6
92                type                 (ref4) [    9a]
93                const_value          (sdata) -9
94  [    74]      variable
95                name                 (string) "b"
96                decl_file            (data1) 1
97                decl_line            (data1) 7
98                type                 (ref4) [    9a]
99                location             (exprloc) 
100                 [ 0] reg5
101  [    80]    base_type
102              byte_size            (data1) 4
103              encoding             (data1) signed (5)
104              name                 (string) "int"
105  [    87]    pointer_type
106              byte_size            (data1) 8
107              type                 (ref4) [    8d]
108  [    8d]    pointer_type
109              byte_size            (data1) 8
110              type                 (ref4) [    93]
111  [    93]    base_type
112              byte_size            (data1) 1
113              encoding             (data1) signed_char (6)
114              name                 (strp) "char"
115  [    9a]    base_type
116              byte_size            (data1) 8
117              encoding             (data1) unsigned (7)
118              name                 (strp) "long unsigned int"
119 EOF
120
121 cat info.out | testrun_compare ${abs_top_builddir}/src/readelf -U --debug-dump=info testfile-debug-rel.o
122
123 cat info.out | sed -e "s/'.debug_info'/'.zdebug_info'/" | testrun_compare ${abs_top_builddir}/src/readelf -U --debug-dump=info testfile-debug-rel-g.o
124
125 cat info.out | testrun_compare ${abs_top_builddir}/src/readelf -U --debug-dump=info testfile-debug-rel-z.o
126
127 cat > loc.out << \EOF
128
129 DWARF section [ 7] '.debug_loc' at offset 0x185:
130  [     0]  000000000000000000..0x0000000000000003 [ 0] reg5
131            0x0000000000000003..0x0000000000000010 [ 0] breg5 -42
132                                                   [ 2] stack_value
133            0x0000000000000010..0x0000000000000018 [ 0] GNU_entry_value:
134       [ 0] reg5
135                                                   [ 3] stack_value
136 EOF
137
138 cat loc.out | testrun_compare ${abs_top_builddir}/src/readelf -U --debug-dump=loc testfile-debug-rel.o
139
140 cat loc.out | sed -e "s/'.debug_loc' at offset 0x185/'.zdebug_loc' at offset 0x138/" | testrun_compare ${abs_top_builddir}/src/readelf -U --debug-dump=loc testfile-debug-rel-g.o
141
142 cat loc.out | sed -e "s/at offset 0x185/at offset 0x150/" | testrun_compare ${abs_top_builddir}/src/readelf -U --debug-dump=loc testfile-debug-rel-z.o
143
144 exit 0