annotate libbacktrace/xcoff.c @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 1830386684a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* xcoff.c -- Get debug data from an XCOFF file for backtraces.
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2 Copyright (C) 2012-2020 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
3 Adapted from elf.c.
kono
parents:
diff changeset
4
kono
parents:
diff changeset
5 Redistribution and use in source and binary forms, with or without
kono
parents:
diff changeset
6 modification, are permitted provided that the following conditions are
kono
parents:
diff changeset
7 met:
kono
parents:
diff changeset
8
kono
parents:
diff changeset
9 (1) Redistributions of source code must retain the above copyright
kono
parents:
diff changeset
10 notice, this list of conditions and the following disclaimer.
kono
parents:
diff changeset
11
kono
parents:
diff changeset
12 (2) Redistributions in binary form must reproduce the above copyright
kono
parents:
diff changeset
13 notice, this list of conditions and the following disclaimer in
kono
parents:
diff changeset
14 the documentation and/or other materials provided with the
kono
parents:
diff changeset
15 distribution.
kono
parents:
diff changeset
16
kono
parents:
diff changeset
17 (3) The name of the author may not be used to
kono
parents:
diff changeset
18 endorse or promote products derived from this software without
kono
parents:
diff changeset
19 specific prior written permission.
kono
parents:
diff changeset
20
kono
parents:
diff changeset
21 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
kono
parents:
diff changeset
22 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
kono
parents:
diff changeset
23 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
kono
parents:
diff changeset
24 DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
kono
parents:
diff changeset
25 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
kono
parents:
diff changeset
26 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
kono
parents:
diff changeset
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
kono
parents:
diff changeset
28 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
kono
parents:
diff changeset
29 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
kono
parents:
diff changeset
30 IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
kono
parents:
diff changeset
31 POSSIBILITY OF SUCH DAMAGE. */
kono
parents:
diff changeset
32
kono
parents:
diff changeset
33 #include "config.h"
kono
parents:
diff changeset
34
kono
parents:
diff changeset
35 #include <errno.h>
kono
parents:
diff changeset
36 #include <stdlib.h>
kono
parents:
diff changeset
37 #include <string.h>
kono
parents:
diff changeset
38 #include <sys/types.h>
kono
parents:
diff changeset
39
kono
parents:
diff changeset
40 #ifdef HAVE_LOADQUERY
kono
parents:
diff changeset
41 #include <sys/ldr.h>
kono
parents:
diff changeset
42 #endif
kono
parents:
diff changeset
43
kono
parents:
diff changeset
44 #include "backtrace.h"
kono
parents:
diff changeset
45 #include "internal.h"
kono
parents:
diff changeset
46
kono
parents:
diff changeset
47 /* The configure script must tell us whether we are 32-bit or 64-bit
kono
parents:
diff changeset
48 XCOFF. We could make this code test and support either possibility,
kono
parents:
diff changeset
49 but there is no point. This code only works for the currently
kono
parents:
diff changeset
50 running executable, which means that we know the XCOFF mode at
kono
parents:
diff changeset
51 configure time. */
kono
parents:
diff changeset
52
kono
parents:
diff changeset
53 #if BACKTRACE_XCOFF_SIZE != 32 && BACKTRACE_XCOFF_SIZE != 64
kono
parents:
diff changeset
54 #error "Unknown BACKTRACE_XCOFF_SIZE"
kono
parents:
diff changeset
55 #endif
kono
parents:
diff changeset
56
kono
parents:
diff changeset
57 /* XCOFF file header. */
kono
parents:
diff changeset
58
kono
parents:
diff changeset
59 #if BACKTRACE_XCOFF_SIZE == 32
kono
parents:
diff changeset
60
kono
parents:
diff changeset
61 typedef struct {
kono
parents:
diff changeset
62 uint16_t f_magic;
kono
parents:
diff changeset
63 uint16_t f_nscns;
kono
parents:
diff changeset
64 uint32_t f_timdat;
kono
parents:
diff changeset
65 uint32_t f_symptr;
kono
parents:
diff changeset
66 uint32_t f_nsyms;
kono
parents:
diff changeset
67 uint16_t f_opthdr;
kono
parents:
diff changeset
68 uint16_t f_flags;
kono
parents:
diff changeset
69 } b_xcoff_filhdr;
kono
parents:
diff changeset
70
kono
parents:
diff changeset
71 #define XCOFF_MAGIC 0737
kono
parents:
diff changeset
72
kono
parents:
diff changeset
73 #else /* BACKTRACE_XCOFF_SIZE != 32 */
kono
parents:
diff changeset
74
kono
parents:
diff changeset
75 typedef struct {
kono
parents:
diff changeset
76 uint16_t f_magic;
kono
parents:
diff changeset
77 uint16_t f_nscns;
kono
parents:
diff changeset
78 uint32_t f_timdat;
kono
parents:
diff changeset
79 uint64_t f_symptr;
kono
parents:
diff changeset
80 uint16_t f_opthdr;
kono
parents:
diff changeset
81 uint16_t f_flags;
kono
parents:
diff changeset
82 uint32_t f_nsyms;
kono
parents:
diff changeset
83 } b_xcoff_filhdr;
kono
parents:
diff changeset
84
kono
parents:
diff changeset
85 #define XCOFF_MAGIC 0767
kono
parents:
diff changeset
86
kono
parents:
diff changeset
87 #endif /* BACKTRACE_XCOFF_SIZE != 32 */
kono
parents:
diff changeset
88
kono
parents:
diff changeset
89 #define F_SHROBJ 0x2000 /* File is a shared object. */
kono
parents:
diff changeset
90
kono
parents:
diff changeset
91 /* XCOFF section header. */
kono
parents:
diff changeset
92
kono
parents:
diff changeset
93 #if BACKTRACE_XCOFF_SIZE == 32
kono
parents:
diff changeset
94
kono
parents:
diff changeset
95 typedef struct {
kono
parents:
diff changeset
96 char s_name[8];
kono
parents:
diff changeset
97 uint32_t s_paddr;
kono
parents:
diff changeset
98 uint32_t s_vaddr;
kono
parents:
diff changeset
99 uint32_t s_size;
kono
parents:
diff changeset
100 uint32_t s_scnptr;
kono
parents:
diff changeset
101 uint32_t s_relptr;
kono
parents:
diff changeset
102 uint32_t s_lnnoptr;
kono
parents:
diff changeset
103 uint16_t s_nreloc;
kono
parents:
diff changeset
104 uint16_t s_nlnno;
kono
parents:
diff changeset
105 uint32_t s_flags;
kono
parents:
diff changeset
106 } b_xcoff_scnhdr;
kono
parents:
diff changeset
107
kono
parents:
diff changeset
108 #define _OVERFLOW_MARKER 65535
kono
parents:
diff changeset
109
kono
parents:
diff changeset
110 #else /* BACKTRACE_XCOFF_SIZE != 32 */
kono
parents:
diff changeset
111
kono
parents:
diff changeset
112 typedef struct {
kono
parents:
diff changeset
113 char name[8];
kono
parents:
diff changeset
114 uint64_t s_paddr;
kono
parents:
diff changeset
115 uint64_t s_vaddr;
kono
parents:
diff changeset
116 uint64_t s_size;
kono
parents:
diff changeset
117 uint64_t s_scnptr;
kono
parents:
diff changeset
118 uint64_t s_relptr;
kono
parents:
diff changeset
119 uint64_t s_lnnoptr;
kono
parents:
diff changeset
120 uint32_t s_nreloc;
kono
parents:
diff changeset
121 uint32_t s_nlnno;
kono
parents:
diff changeset
122 uint32_t s_flags;
kono
parents:
diff changeset
123 } b_xcoff_scnhdr;
kono
parents:
diff changeset
124
kono
parents:
diff changeset
125 #endif /* BACKTRACE_XCOFF_SIZE != 32 */
kono
parents:
diff changeset
126
kono
parents:
diff changeset
127 #define STYP_DWARF 0x10 /* DWARF debugging section. */
kono
parents:
diff changeset
128 #define STYP_TEXT 0x20 /* Executable text (code) section. */
kono
parents:
diff changeset
129 #define STYP_OVRFLO 0x8000 /* Line-number field overflow section. */
kono
parents:
diff changeset
130
kono
parents:
diff changeset
131 #define SSUBTYP_DWINFO 0x10000 /* DWARF info section. */
kono
parents:
diff changeset
132 #define SSUBTYP_DWLINE 0x20000 /* DWARF line-number section. */
kono
parents:
diff changeset
133 #define SSUBTYP_DWARNGE 0x50000 /* DWARF aranges section. */
kono
parents:
diff changeset
134 #define SSUBTYP_DWABREV 0x60000 /* DWARF abbreviation section. */
kono
parents:
diff changeset
135 #define SSUBTYP_DWSTR 0x70000 /* DWARF strings section. */
kono
parents:
diff changeset
136
kono
parents:
diff changeset
137 /* XCOFF symbol. */
kono
parents:
diff changeset
138
kono
parents:
diff changeset
139 #define SYMNMLEN 8
kono
parents:
diff changeset
140
kono
parents:
diff changeset
141 #if BACKTRACE_XCOFF_SIZE == 32
kono
parents:
diff changeset
142
kono
parents:
diff changeset
143 typedef struct {
kono
parents:
diff changeset
144 union {
kono
parents:
diff changeset
145 char _name[SYMNMLEN];
kono
parents:
diff changeset
146 struct {
kono
parents:
diff changeset
147 uint32_t _zeroes;
kono
parents:
diff changeset
148 uint32_t _offset;
kono
parents:
diff changeset
149 } _s;
kono
parents:
diff changeset
150 } _u;
kono
parents:
diff changeset
151 #define n_name _u._name
kono
parents:
diff changeset
152 #define n_zeroes _u._s._zeroes
kono
parents:
diff changeset
153 #define n_offset_ _u._s._offset
kono
parents:
diff changeset
154
kono
parents:
diff changeset
155 uint32_t n_value;
kono
parents:
diff changeset
156 int16_t n_scnum;
kono
parents:
diff changeset
157 uint16_t n_type;
kono
parents:
diff changeset
158 uint8_t n_sclass;
kono
parents:
diff changeset
159 uint8_t n_numaux;
kono
parents:
diff changeset
160 } __attribute__ ((packed)) b_xcoff_syment;
kono
parents:
diff changeset
161
kono
parents:
diff changeset
162 #else /* BACKTRACE_XCOFF_SIZE != 32 */
kono
parents:
diff changeset
163
kono
parents:
diff changeset
164 typedef struct {
kono
parents:
diff changeset
165 uint64_t n_value;
kono
parents:
diff changeset
166 uint32_t n_offset_;
kono
parents:
diff changeset
167 int16_t n_scnum;
kono
parents:
diff changeset
168 uint16_t n_type;
kono
parents:
diff changeset
169 uint8_t n_sclass;
kono
parents:
diff changeset
170 uint8_t n_numaux;
kono
parents:
diff changeset
171 } __attribute__ ((packed)) b_xcoff_syment;
kono
parents:
diff changeset
172
kono
parents:
diff changeset
173 #endif /* BACKTRACE_XCOFF_SIZE != 32 */
kono
parents:
diff changeset
174
kono
parents:
diff changeset
175 #define SYMESZ 18
kono
parents:
diff changeset
176
kono
parents:
diff changeset
177 #define C_EXT 2 /* External symbol. */
kono
parents:
diff changeset
178 #define C_FCN 101 /* Beginning or end of function. */
kono
parents:
diff changeset
179 #define C_FILE 103 /* Source file name. */
kono
parents:
diff changeset
180 #define C_HIDEXT 107 /* Unnamed external symbol. */
kono
parents:
diff changeset
181 #define C_BINCL 108 /* Beginning of include file. */
kono
parents:
diff changeset
182 #define C_EINCL 109 /* End of include file. */
kono
parents:
diff changeset
183 #define C_WEAKEXT 111 /* Weak external symbol. */
kono
parents:
diff changeset
184
kono
parents:
diff changeset
185 #define ISFCN(x) ((x) & 0x0020)
kono
parents:
diff changeset
186
kono
parents:
diff changeset
187 /* XCOFF AUX entry. */
kono
parents:
diff changeset
188
kono
parents:
diff changeset
189 #define AUXESZ 18
kono
parents:
diff changeset
190 #define FILNMLEN 14
kono
parents:
diff changeset
191
kono
parents:
diff changeset
192 typedef union {
kono
parents:
diff changeset
193 #if BACKTRACE_XCOFF_SIZE == 32
kono
parents:
diff changeset
194 struct {
kono
parents:
diff changeset
195 uint16_t pad;
kono
parents:
diff changeset
196 uint16_t x_lnnohi;
kono
parents:
diff changeset
197 uint16_t x_lnno;
kono
parents:
diff changeset
198 } x_block;
kono
parents:
diff changeset
199 #else
kono
parents:
diff changeset
200 struct {
kono
parents:
diff changeset
201 uint32_t x_lnno;
kono
parents:
diff changeset
202 } x_block;
kono
parents:
diff changeset
203 #endif
kono
parents:
diff changeset
204 union {
kono
parents:
diff changeset
205 char x_fname[FILNMLEN];
kono
parents:
diff changeset
206 struct {
kono
parents:
diff changeset
207 uint32_t x_zeroes;
kono
parents:
diff changeset
208 uint32_t x_offset;
kono
parents:
diff changeset
209 char pad[FILNMLEN-8];
kono
parents:
diff changeset
210 uint8_t x_ftype;
kono
parents:
diff changeset
211 } _x;
kono
parents:
diff changeset
212 } x_file;
kono
parents:
diff changeset
213 #if BACKTRACE_XCOFF_SIZE == 32
kono
parents:
diff changeset
214 struct {
kono
parents:
diff changeset
215 uint32_t x_exptr;
kono
parents:
diff changeset
216 uint32_t x_fsize;
kono
parents:
diff changeset
217 uint32_t x_lnnoptr;
kono
parents:
diff changeset
218 uint32_t x_endndx;
kono
parents:
diff changeset
219 } x_fcn;
kono
parents:
diff changeset
220 #else
kono
parents:
diff changeset
221 struct {
kono
parents:
diff changeset
222 uint64_t x_lnnoptr;
kono
parents:
diff changeset
223 uint32_t x_fsize;
kono
parents:
diff changeset
224 uint32_t x_endndx;
kono
parents:
diff changeset
225 } x_fcn;
kono
parents:
diff changeset
226 #endif
kono
parents:
diff changeset
227 struct {
kono
parents:
diff changeset
228 uint8_t pad[AUXESZ-1];
kono
parents:
diff changeset
229 uint8_t x_auxtype;
kono
parents:
diff changeset
230 } x_auxtype;
kono
parents:
diff changeset
231 } __attribute__ ((packed)) b_xcoff_auxent;
kono
parents:
diff changeset
232
kono
parents:
diff changeset
233 /* XCOFF line number entry. */
kono
parents:
diff changeset
234
kono
parents:
diff changeset
235 #if BACKTRACE_XCOFF_SIZE == 32
kono
parents:
diff changeset
236
kono
parents:
diff changeset
237 typedef struct {
kono
parents:
diff changeset
238 union {
kono
parents:
diff changeset
239 uint32_t l_symndx;
kono
parents:
diff changeset
240 uint32_t l_paddr;
kono
parents:
diff changeset
241 } l_addr;
kono
parents:
diff changeset
242 uint16_t l_lnno;
kono
parents:
diff changeset
243 } b_xcoff_lineno;
kono
parents:
diff changeset
244
kono
parents:
diff changeset
245 #define LINESZ 6
kono
parents:
diff changeset
246
kono
parents:
diff changeset
247 #else /* BACKTRACE_XCOFF_SIZE != 32 */
kono
parents:
diff changeset
248
kono
parents:
diff changeset
249 typedef struct {
kono
parents:
diff changeset
250 union {
kono
parents:
diff changeset
251 uint32_t l_symndx;
kono
parents:
diff changeset
252 uint64_t l_paddr;
kono
parents:
diff changeset
253 } l_addr;
kono
parents:
diff changeset
254 uint32_t l_lnno;
kono
parents:
diff changeset
255 } b_xcoff_lineno;
kono
parents:
diff changeset
256
kono
parents:
diff changeset
257 #define LINESZ 12
kono
parents:
diff changeset
258
kono
parents:
diff changeset
259 #endif /* BACKTRACE_XCOFF_SIZE != 32 */
kono
parents:
diff changeset
260
kono
parents:
diff changeset
261 #if BACKTRACE_XCOFF_SIZE == 32
kono
parents:
diff changeset
262 #define XCOFF_AIX_TEXTBASE 0x10000000u
kono
parents:
diff changeset
263 #else
kono
parents:
diff changeset
264 #define XCOFF_AIX_TEXTBASE 0x100000000ul
kono
parents:
diff changeset
265 #endif
kono
parents:
diff changeset
266
kono
parents:
diff changeset
267 /* AIX big archive fixed-length header. */
kono
parents:
diff changeset
268
kono
parents:
diff changeset
269 #define AIAMAGBIG "<bigaf>\n"
kono
parents:
diff changeset
270
kono
parents:
diff changeset
271 typedef struct {
kono
parents:
diff changeset
272 char fl_magic[8]; /* Archive magic string. */
kono
parents:
diff changeset
273 char fl_memoff[20]; /* Offset to member table. */
kono
parents:
diff changeset
274 char fl_gstoff[20]; /* Offset to global symbol table. */
kono
parents:
diff changeset
275 char fl_gst64off[20]; /* Offset to global symbol table for 64-bit objects. */
kono
parents:
diff changeset
276 char fl_fstmoff[20]; /* Offset to first archive member. */
kono
parents:
diff changeset
277 char fl_freeoff[20]; /* Offset to first member on free list. */
kono
parents:
diff changeset
278 } b_ar_fl_hdr;
kono
parents:
diff changeset
279
kono
parents:
diff changeset
280 /* AIX big archive file member header. */
kono
parents:
diff changeset
281
kono
parents:
diff changeset
282 typedef struct {
kono
parents:
diff changeset
283 char ar_size[20]; /* File member size - decimal. */
kono
parents:
diff changeset
284 char ar_nxtmem[20]; /* Next member offset - decimal. */
kono
parents:
diff changeset
285 char ar_prvmem[20]; /* Previous member offset - decimal. */
kono
parents:
diff changeset
286 char ar_date[12]; /* File member date - decimal. */
kono
parents:
diff changeset
287 char ar_uid[12]; /* File member userid - decimal. */
kono
parents:
diff changeset
288 char ar_gid[12]; /* File member group id - decimal. */
kono
parents:
diff changeset
289 char ar_mode[12]; /* File member mode - octal. */
kono
parents:
diff changeset
290 char ar_namlen[4]; /* File member name length - decimal. */
kono
parents:
diff changeset
291 char ar_name[2]; /* Start of member name. */
kono
parents:
diff changeset
292 } b_ar_hdr;
kono
parents:
diff changeset
293
kono
parents:
diff changeset
294
kono
parents:
diff changeset
295 /* Information we keep for an XCOFF symbol. */
kono
parents:
diff changeset
296
kono
parents:
diff changeset
297 struct xcoff_symbol
kono
parents:
diff changeset
298 {
kono
parents:
diff changeset
299 /* The name of the symbol. */
kono
parents:
diff changeset
300 const char *name;
kono
parents:
diff changeset
301 /* The address of the symbol. */
kono
parents:
diff changeset
302 uintptr_t address;
kono
parents:
diff changeset
303 /* The size of the symbol. */
kono
parents:
diff changeset
304 size_t size;
kono
parents:
diff changeset
305 };
kono
parents:
diff changeset
306
kono
parents:
diff changeset
307 /* Information to pass to xcoff_syminfo. */
kono
parents:
diff changeset
308
kono
parents:
diff changeset
309 struct xcoff_syminfo_data
kono
parents:
diff changeset
310 {
kono
parents:
diff changeset
311 /* Symbols for the next module. */
kono
parents:
diff changeset
312 struct xcoff_syminfo_data *next;
kono
parents:
diff changeset
313 /* The XCOFF symbols, sorted by address. */
kono
parents:
diff changeset
314 struct xcoff_symbol *symbols;
kono
parents:
diff changeset
315 /* The number of symbols. */
kono
parents:
diff changeset
316 size_t count;
kono
parents:
diff changeset
317 };
kono
parents:
diff changeset
318
kono
parents:
diff changeset
319 /* Information about an include file. */
kono
parents:
diff changeset
320
kono
parents:
diff changeset
321 struct xcoff_incl
kono
parents:
diff changeset
322 {
kono
parents:
diff changeset
323 /* File name. */
kono
parents:
diff changeset
324 const char *filename;
kono
parents:
diff changeset
325 /* Offset to first line number from the include file. */
kono
parents:
diff changeset
326 uintptr_t begin;
kono
parents:
diff changeset
327 /* Offset to last line number from the include file. */
kono
parents:
diff changeset
328 uintptr_t end;
kono
parents:
diff changeset
329 };
kono
parents:
diff changeset
330
kono
parents:
diff changeset
331 /* A growable vector of include files information. */
kono
parents:
diff changeset
332
kono
parents:
diff changeset
333 struct xcoff_incl_vector
kono
parents:
diff changeset
334 {
kono
parents:
diff changeset
335 /* Memory. This is an array of struct xcoff_incl. */
kono
parents:
diff changeset
336 struct backtrace_vector vec;
kono
parents:
diff changeset
337 /* Number of include files. */
kono
parents:
diff changeset
338 size_t count;
kono
parents:
diff changeset
339 };
kono
parents:
diff changeset
340
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
341 /* A growable vector of functions information. */
111
kono
parents:
diff changeset
342
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
343 struct xcoff_func
111
kono
parents:
diff changeset
344 {
kono
parents:
diff changeset
345 /* PC. */
kono
parents:
diff changeset
346 uintptr_t pc;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
347 /* The size of the function. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
348 size_t size;
111
kono
parents:
diff changeset
349 /* Function name. */
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
350 const char *name;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
351 /* File name. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
352 const char *filename;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
353 /* Pointer to first lnno entry. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
354 uintptr_t lnnoptr;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
355 /* Base address of containing section. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
356 uintptr_t sect_base;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
357 /* Starting source line number. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
358 int lnno;
111
kono
parents:
diff changeset
359 };
kono
parents:
diff changeset
360
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
361 /* A growable vector of function information. This is used while
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
362 reading the function symbols. */
111
kono
parents:
diff changeset
363
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
364 struct xcoff_func_vector
111
kono
parents:
diff changeset
365 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
366 /* Memory. This is an array of struct xcoff_func. */
111
kono
parents:
diff changeset
367 struct backtrace_vector vec;
kono
parents:
diff changeset
368 /* Number of valid mappings. */
kono
parents:
diff changeset
369 size_t count;
kono
parents:
diff changeset
370 };
kono
parents:
diff changeset
371
kono
parents:
diff changeset
372 /* The information we need to map a PC to a file and line. */
kono
parents:
diff changeset
373
kono
parents:
diff changeset
374 struct xcoff_fileline_data
kono
parents:
diff changeset
375 {
kono
parents:
diff changeset
376 /* The data for the next file we know about. */
kono
parents:
diff changeset
377 struct xcoff_fileline_data *next;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
378 /* Functions information. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
379 struct xcoff_func_vector func_vec;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
380 /* Include files information. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
381 struct xcoff_incl_vector incl_vec;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
382 /* Line numbers information. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
383 const unsigned char *linenos;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
384 size_t linenos_size;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
385 uint64_t lnnoptr0;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
386 /* Loader address. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
387 uintptr_t base_address;
111
kono
parents:
diff changeset
388 };
kono
parents:
diff changeset
389
kono
parents:
diff changeset
390 /* Information we gather for the DWARF sections we care about. */
kono
parents:
diff changeset
391
kono
parents:
diff changeset
392 struct dwsect_info
kono
parents:
diff changeset
393 {
kono
parents:
diff changeset
394 /* Section file offset. */
kono
parents:
diff changeset
395 off_t offset;
kono
parents:
diff changeset
396 /* Section size. */
kono
parents:
diff changeset
397 size_t size;
kono
parents:
diff changeset
398 /* Section contents, after read from file. */
kono
parents:
diff changeset
399 const unsigned char *data;
kono
parents:
diff changeset
400 };
kono
parents:
diff changeset
401
kono
parents:
diff changeset
402 /* A dummy callback function used when we can't find any debug info. */
kono
parents:
diff changeset
403
kono
parents:
diff changeset
404 static int
kono
parents:
diff changeset
405 xcoff_nodebug (struct backtrace_state *state ATTRIBUTE_UNUSED,
kono
parents:
diff changeset
406 uintptr_t pc ATTRIBUTE_UNUSED,
kono
parents:
diff changeset
407 backtrace_full_callback callback ATTRIBUTE_UNUSED,
kono
parents:
diff changeset
408 backtrace_error_callback error_callback, void *data)
kono
parents:
diff changeset
409 {
kono
parents:
diff changeset
410 error_callback (data, "no debug info in XCOFF executable", -1);
kono
parents:
diff changeset
411 return 0;
kono
parents:
diff changeset
412 }
kono
parents:
diff changeset
413
kono
parents:
diff changeset
414 /* A dummy callback function used when we can't find a symbol
kono
parents:
diff changeset
415 table. */
kono
parents:
diff changeset
416
kono
parents:
diff changeset
417 static void
kono
parents:
diff changeset
418 xcoff_nosyms (struct backtrace_state *state ATTRIBUTE_UNUSED,
kono
parents:
diff changeset
419 uintptr_t addr ATTRIBUTE_UNUSED,
kono
parents:
diff changeset
420 backtrace_syminfo_callback callback ATTRIBUTE_UNUSED,
kono
parents:
diff changeset
421 backtrace_error_callback error_callback, void *data)
kono
parents:
diff changeset
422 {
kono
parents:
diff changeset
423 error_callback (data, "no symbol table in XCOFF executable", -1);
kono
parents:
diff changeset
424 }
kono
parents:
diff changeset
425
kono
parents:
diff changeset
426 /* Compare struct xcoff_symbol for qsort. */
kono
parents:
diff changeset
427
kono
parents:
diff changeset
428 static int
kono
parents:
diff changeset
429 xcoff_symbol_compare (const void *v1, const void *v2)
kono
parents:
diff changeset
430 {
kono
parents:
diff changeset
431 const struct xcoff_symbol *e1 = (const struct xcoff_symbol *) v1;
kono
parents:
diff changeset
432 const struct xcoff_symbol *e2 = (const struct xcoff_symbol *) v2;
kono
parents:
diff changeset
433
kono
parents:
diff changeset
434 if (e1->address < e2->address)
kono
parents:
diff changeset
435 return -1;
kono
parents:
diff changeset
436 else if (e1->address > e2->address)
kono
parents:
diff changeset
437 return 1;
kono
parents:
diff changeset
438 else
kono
parents:
diff changeset
439 return 0;
kono
parents:
diff changeset
440 }
kono
parents:
diff changeset
441
kono
parents:
diff changeset
442 /* Compare an ADDR against an xcoff_symbol for bsearch. */
kono
parents:
diff changeset
443
kono
parents:
diff changeset
444 static int
kono
parents:
diff changeset
445 xcoff_symbol_search (const void *vkey, const void *ventry)
kono
parents:
diff changeset
446 {
kono
parents:
diff changeset
447 const uintptr_t *key = (const uintptr_t *) vkey;
kono
parents:
diff changeset
448 const struct xcoff_symbol *entry = (const struct xcoff_symbol *) ventry;
kono
parents:
diff changeset
449 uintptr_t addr;
kono
parents:
diff changeset
450
kono
parents:
diff changeset
451 addr = *key;
kono
parents:
diff changeset
452 if (addr < entry->address)
kono
parents:
diff changeset
453 return -1;
kono
parents:
diff changeset
454 else if ((entry->size == 0 && addr > entry->address)
kono
parents:
diff changeset
455 || (entry->size > 0 && addr >= entry->address + entry->size))
kono
parents:
diff changeset
456 return 1;
kono
parents:
diff changeset
457 else
kono
parents:
diff changeset
458 return 0;
kono
parents:
diff changeset
459 }
kono
parents:
diff changeset
460
kono
parents:
diff changeset
461 /* Add XDATA to the list in STATE. */
kono
parents:
diff changeset
462
kono
parents:
diff changeset
463 static void
kono
parents:
diff changeset
464 xcoff_add_syminfo_data (struct backtrace_state *state,
kono
parents:
diff changeset
465 struct xcoff_syminfo_data *xdata)
kono
parents:
diff changeset
466 {
kono
parents:
diff changeset
467 if (!state->threaded)
kono
parents:
diff changeset
468 {
kono
parents:
diff changeset
469 struct xcoff_syminfo_data **pp;
kono
parents:
diff changeset
470
kono
parents:
diff changeset
471 for (pp = (struct xcoff_syminfo_data **) (void *) &state->syminfo_data;
kono
parents:
diff changeset
472 *pp != NULL;
kono
parents:
diff changeset
473 pp = &(*pp)->next)
kono
parents:
diff changeset
474 ;
kono
parents:
diff changeset
475 *pp = xdata;
kono
parents:
diff changeset
476 }
kono
parents:
diff changeset
477 else
kono
parents:
diff changeset
478 {
kono
parents:
diff changeset
479 while (1)
kono
parents:
diff changeset
480 {
kono
parents:
diff changeset
481 struct xcoff_syminfo_data **pp;
kono
parents:
diff changeset
482
kono
parents:
diff changeset
483 pp = (struct xcoff_syminfo_data **) (void *) &state->syminfo_data;
kono
parents:
diff changeset
484
kono
parents:
diff changeset
485 while (1)
kono
parents:
diff changeset
486 {
kono
parents:
diff changeset
487 struct xcoff_syminfo_data *p;
kono
parents:
diff changeset
488
kono
parents:
diff changeset
489 p = backtrace_atomic_load_pointer (pp);
kono
parents:
diff changeset
490
kono
parents:
diff changeset
491 if (p == NULL)
kono
parents:
diff changeset
492 break;
kono
parents:
diff changeset
493
kono
parents:
diff changeset
494 pp = &p->next;
kono
parents:
diff changeset
495 }
kono
parents:
diff changeset
496
kono
parents:
diff changeset
497 if (__sync_bool_compare_and_swap (pp, NULL, xdata))
kono
parents:
diff changeset
498 break;
kono
parents:
diff changeset
499 }
kono
parents:
diff changeset
500 }
kono
parents:
diff changeset
501 }
kono
parents:
diff changeset
502
kono
parents:
diff changeset
503 /* Return the symbol name and value for an ADDR. */
kono
parents:
diff changeset
504
kono
parents:
diff changeset
505 static void
kono
parents:
diff changeset
506 xcoff_syminfo (struct backtrace_state *state ATTRIBUTE_UNUSED, uintptr_t addr,
kono
parents:
diff changeset
507 backtrace_syminfo_callback callback,
kono
parents:
diff changeset
508 backtrace_error_callback error_callback ATTRIBUTE_UNUSED,
kono
parents:
diff changeset
509 void *data)
kono
parents:
diff changeset
510 {
kono
parents:
diff changeset
511 struct xcoff_syminfo_data *edata;
kono
parents:
diff changeset
512 struct xcoff_symbol *sym = NULL;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
513 const char *name;
111
kono
parents:
diff changeset
514
kono
parents:
diff changeset
515 if (!state->threaded)
kono
parents:
diff changeset
516 {
kono
parents:
diff changeset
517 for (edata = (struct xcoff_syminfo_data *) state->syminfo_data;
kono
parents:
diff changeset
518 edata != NULL;
kono
parents:
diff changeset
519 edata = edata->next)
kono
parents:
diff changeset
520 {
kono
parents:
diff changeset
521 sym = ((struct xcoff_symbol *)
kono
parents:
diff changeset
522 bsearch (&addr, edata->symbols, edata->count,
kono
parents:
diff changeset
523 sizeof (struct xcoff_symbol), xcoff_symbol_search));
kono
parents:
diff changeset
524 if (sym != NULL)
kono
parents:
diff changeset
525 break;
kono
parents:
diff changeset
526 }
kono
parents:
diff changeset
527 }
kono
parents:
diff changeset
528 else
kono
parents:
diff changeset
529 {
kono
parents:
diff changeset
530 struct xcoff_syminfo_data **pp;
kono
parents:
diff changeset
531
kono
parents:
diff changeset
532 pp = (struct xcoff_syminfo_data **) (void *) &state->syminfo_data;
kono
parents:
diff changeset
533 while (1)
kono
parents:
diff changeset
534 {
kono
parents:
diff changeset
535 edata = backtrace_atomic_load_pointer (pp);
kono
parents:
diff changeset
536 if (edata == NULL)
kono
parents:
diff changeset
537 break;
kono
parents:
diff changeset
538
kono
parents:
diff changeset
539 sym = ((struct xcoff_symbol *)
kono
parents:
diff changeset
540 bsearch (&addr, edata->symbols, edata->count,
kono
parents:
diff changeset
541 sizeof (struct xcoff_symbol), xcoff_symbol_search));
kono
parents:
diff changeset
542 if (sym != NULL)
kono
parents:
diff changeset
543 break;
kono
parents:
diff changeset
544
kono
parents:
diff changeset
545 pp = &edata->next;
kono
parents:
diff changeset
546 }
kono
parents:
diff changeset
547 }
kono
parents:
diff changeset
548
kono
parents:
diff changeset
549 if (sym == NULL)
kono
parents:
diff changeset
550 callback (data, addr, NULL, 0, 0);
kono
parents:
diff changeset
551 else
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
552 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
553 name = sym->name;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
554 /* AIX prepends a '.' to function entry points, remove it. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
555 if (name && *name == '.')
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
556 ++name;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
557 callback (data, addr, name, sym->address, sym->size);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
558 }
111
kono
parents:
diff changeset
559 }
kono
parents:
diff changeset
560
kono
parents:
diff changeset
561 /* Return the name of an XCOFF symbol. */
kono
parents:
diff changeset
562
kono
parents:
diff changeset
563 static const char *
kono
parents:
diff changeset
564 xcoff_symname (const b_xcoff_syment *asym,
kono
parents:
diff changeset
565 const unsigned char *strtab, size_t strtab_size)
kono
parents:
diff changeset
566 {
kono
parents:
diff changeset
567 #if BACKTRACE_XCOFF_SIZE == 32
kono
parents:
diff changeset
568 if (asym->n_zeroes != 0)
kono
parents:
diff changeset
569 {
kono
parents:
diff changeset
570 /* Make a copy as we will release the symtab view. */
kono
parents:
diff changeset
571 char name[SYMNMLEN+1];
kono
parents:
diff changeset
572 strncpy (name, asym->n_name, SYMNMLEN);
kono
parents:
diff changeset
573 name[SYMNMLEN] = '\0';
kono
parents:
diff changeset
574 return strdup (name);
kono
parents:
diff changeset
575 }
kono
parents:
diff changeset
576 #endif
kono
parents:
diff changeset
577 if (asym->n_sclass & 0x80)
kono
parents:
diff changeset
578 return NULL; /* .debug */
kono
parents:
diff changeset
579 if (asym->n_offset_ >= strtab_size)
kono
parents:
diff changeset
580 return NULL;
kono
parents:
diff changeset
581 return (const char *) strtab + asym->n_offset_;
kono
parents:
diff changeset
582 }
kono
parents:
diff changeset
583
kono
parents:
diff changeset
584 /* Initialize the symbol table info for xcoff_syminfo. */
kono
parents:
diff changeset
585
kono
parents:
diff changeset
586 static int
kono
parents:
diff changeset
587 xcoff_initialize_syminfo (struct backtrace_state *state,
kono
parents:
diff changeset
588 uintptr_t base_address,
kono
parents:
diff changeset
589 const b_xcoff_scnhdr *sects,
kono
parents:
diff changeset
590 const b_xcoff_syment *syms, size_t nsyms,
kono
parents:
diff changeset
591 const unsigned char *strtab, size_t strtab_size,
kono
parents:
diff changeset
592 backtrace_error_callback error_callback, void *data,
kono
parents:
diff changeset
593 struct xcoff_syminfo_data *sdata)
kono
parents:
diff changeset
594 {
kono
parents:
diff changeset
595 size_t xcoff_symbol_count;
kono
parents:
diff changeset
596 size_t xcoff_symbol_size;
kono
parents:
diff changeset
597 struct xcoff_symbol *xcoff_symbols;
kono
parents:
diff changeset
598 size_t i;
kono
parents:
diff changeset
599 unsigned int j;
kono
parents:
diff changeset
600
kono
parents:
diff changeset
601 /* We only care about function symbols. Count them. */
kono
parents:
diff changeset
602 xcoff_symbol_count = 0;
kono
parents:
diff changeset
603 for (i = 0; i < nsyms; ++i)
kono
parents:
diff changeset
604 {
kono
parents:
diff changeset
605 const b_xcoff_syment *asym = &syms[i];
kono
parents:
diff changeset
606 if ((asym->n_sclass == C_EXT || asym->n_sclass == C_HIDEXT
kono
parents:
diff changeset
607 || asym->n_sclass == C_WEAKEXT)
kono
parents:
diff changeset
608 && ISFCN (asym->n_type) && asym->n_numaux > 0 && asym->n_scnum > 0)
kono
parents:
diff changeset
609 ++xcoff_symbol_count;
kono
parents:
diff changeset
610
kono
parents:
diff changeset
611 i += asym->n_numaux;
kono
parents:
diff changeset
612 }
kono
parents:
diff changeset
613
kono
parents:
diff changeset
614 xcoff_symbol_size = xcoff_symbol_count * sizeof (struct xcoff_symbol);
kono
parents:
diff changeset
615 xcoff_symbols = ((struct xcoff_symbol *)
kono
parents:
diff changeset
616 backtrace_alloc (state, xcoff_symbol_size, error_callback,
kono
parents:
diff changeset
617 data));
kono
parents:
diff changeset
618 if (xcoff_symbols == NULL)
kono
parents:
diff changeset
619 return 0;
kono
parents:
diff changeset
620
kono
parents:
diff changeset
621 j = 0;
kono
parents:
diff changeset
622 for (i = 0; i < nsyms; ++i)
kono
parents:
diff changeset
623 {
kono
parents:
diff changeset
624 const b_xcoff_syment *asym = &syms[i];
kono
parents:
diff changeset
625 if ((asym->n_sclass == C_EXT || asym->n_sclass == C_HIDEXT
kono
parents:
diff changeset
626 || asym->n_sclass == C_WEAKEXT)
kono
parents:
diff changeset
627 && ISFCN (asym->n_type) && asym->n_numaux > 0 && asym->n_scnum > 0)
kono
parents:
diff changeset
628 {
kono
parents:
diff changeset
629 const b_xcoff_auxent *aux = (const b_xcoff_auxent *) (asym + 1);
kono
parents:
diff changeset
630 xcoff_symbols[j].name = xcoff_symname (asym, strtab, strtab_size);
kono
parents:
diff changeset
631 xcoff_symbols[j].address = base_address + asym->n_value
kono
parents:
diff changeset
632 - sects[asym->n_scnum - 1].s_paddr;
kono
parents:
diff changeset
633 /* x_fsize will be 0 if there is no debug information. */
kono
parents:
diff changeset
634 xcoff_symbols[j].size = aux->x_fcn.x_fsize;
kono
parents:
diff changeset
635 ++j;
kono
parents:
diff changeset
636 }
kono
parents:
diff changeset
637
kono
parents:
diff changeset
638 i += asym->n_numaux;
kono
parents:
diff changeset
639 }
kono
parents:
diff changeset
640
kono
parents:
diff changeset
641 backtrace_qsort (xcoff_symbols, xcoff_symbol_count,
kono
parents:
diff changeset
642 sizeof (struct xcoff_symbol), xcoff_symbol_compare);
kono
parents:
diff changeset
643
kono
parents:
diff changeset
644 sdata->next = NULL;
kono
parents:
diff changeset
645 sdata->symbols = xcoff_symbols;
kono
parents:
diff changeset
646 sdata->count = xcoff_symbol_count;
kono
parents:
diff changeset
647
kono
parents:
diff changeset
648 return 1;
kono
parents:
diff changeset
649 }
kono
parents:
diff changeset
650
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
651 /* Compare struct xcoff_func for qsort. */
111
kono
parents:
diff changeset
652
kono
parents:
diff changeset
653 static int
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
654 xcoff_func_compare (const void *v1, const void *v2)
111
kono
parents:
diff changeset
655 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
656 const struct xcoff_func *fn1 = (const struct xcoff_func *) v1;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
657 const struct xcoff_func *fn2 = (const struct xcoff_func *) v2;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
658
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
659 if (fn1->pc < fn2->pc)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
660 return -1;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
661 else if (fn1->pc > fn2->pc)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
662 return 1;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
663 else
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
664 return 0;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
665 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
666
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
667 /* Compare a PC against an xcoff_func for bsearch. */
111
kono
parents:
diff changeset
668
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
669 static int
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
670 xcoff_func_search (const void *vkey, const void *ventry)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
671 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
672 const uintptr_t *key = (const uintptr_t *) vkey;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
673 const struct xcoff_func *entry = (const struct xcoff_func *) ventry;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
674 uintptr_t pc;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
675
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
676 pc = *key;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
677 if (pc < entry->pc)
111
kono
parents:
diff changeset
678 return -1;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
679 else if ((entry->size == 0 && pc > entry->pc)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
680 || (entry->size > 0 && pc >= entry->pc + entry->size))
111
kono
parents:
diff changeset
681 return 1;
kono
parents:
diff changeset
682 else
kono
parents:
diff changeset
683 return 0;
kono
parents:
diff changeset
684 }
kono
parents:
diff changeset
685
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
686 /* Compare struct xcoff_incl for qsort. */
111
kono
parents:
diff changeset
687
kono
parents:
diff changeset
688 static int
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
689 xcoff_incl_compare (const void *v1, const void *v2)
111
kono
parents:
diff changeset
690 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
691 const struct xcoff_incl *in1 = (const struct xcoff_incl *) v1;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
692 const struct xcoff_incl *in2 = (const struct xcoff_incl *) v2;
111
kono
parents:
diff changeset
693
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
694 if (in1->begin < in2->begin)
111
kono
parents:
diff changeset
695 return -1;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
696 else if (in1->begin > in2->begin)
111
kono
parents:
diff changeset
697 return 1;
kono
parents:
diff changeset
698 else
kono
parents:
diff changeset
699 return 0;
kono
parents:
diff changeset
700 }
kono
parents:
diff changeset
701
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
702 /* Find a lnnoptr in an include file. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
703
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
704 static int
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
705 xcoff_incl_search (const void *vkey, const void *ventry)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
706 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
707 const uintptr_t *key = (const uintptr_t *) vkey;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
708 const struct xcoff_incl *entry = (const struct xcoff_incl *) ventry;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
709 uintptr_t lnno;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
710
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
711 lnno = *key;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
712 if (lnno < entry->begin)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
713 return -1;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
714 else if (lnno > entry->end)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
715 return 1;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
716 else
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
717 return 0;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
718 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
719
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
720 /* Look for a PC in the function vector for one module. On success,
111
kono
parents:
diff changeset
721 call CALLBACK and return whatever it returns. On error, call
kono
parents:
diff changeset
722 ERROR_CALLBACK and return 0. Sets *FOUND to 1 if the PC is found,
kono
parents:
diff changeset
723 0 if not. */
kono
parents:
diff changeset
724
kono
parents:
diff changeset
725 static int
kono
parents:
diff changeset
726 xcoff_lookup_pc (struct backtrace_state *state ATTRIBUTE_UNUSED,
kono
parents:
diff changeset
727 struct xcoff_fileline_data *fdata, uintptr_t pc,
kono
parents:
diff changeset
728 backtrace_full_callback callback,
kono
parents:
diff changeset
729 backtrace_error_callback error_callback ATTRIBUTE_UNUSED,
kono
parents:
diff changeset
730 void *data, int *found)
kono
parents:
diff changeset
731 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
732 const struct xcoff_incl *incl, *bincl;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
733 const struct xcoff_func *fn;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
734 const b_xcoff_lineno *lineno;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
735 const unsigned char *lineptr;
111
kono
parents:
diff changeset
736 const char *function;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
737 const char *filename;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
738 uintptr_t lnnoptr, match;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
739 uint32_t lnno = 0;
111
kono
parents:
diff changeset
740
kono
parents:
diff changeset
741 *found = 1;
kono
parents:
diff changeset
742
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
743 if ((pc & 3) != 0)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
744 ++pc;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
745
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
746 /* Find the function first. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
747 fn = ((struct xcoff_func *)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
748 bsearch (&pc, fdata->func_vec.vec.base, fdata->func_vec.count,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
749 sizeof (struct xcoff_func), xcoff_func_search));
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
750 if (fn == NULL)
111
kono
parents:
diff changeset
751 {
kono
parents:
diff changeset
752 *found = 0;
kono
parents:
diff changeset
753 return 0;
kono
parents:
diff changeset
754 }
kono
parents:
diff changeset
755
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
756 filename = fn->filename;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
757
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
758 /* Find the line number next. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
759
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
760 /* Skip first entry that points to symtab. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
761 lnnoptr = fn->lnnoptr + LINESZ;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
762 match = lnnoptr;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
763
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
764 lineptr = fdata->linenos + (lnnoptr - fdata->lnnoptr0);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
765 while (lineptr + LINESZ <= fdata->linenos + fdata->linenos_size)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
766 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
767 lineno = (const b_xcoff_lineno *) lineptr;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
768 if (lineno->l_lnno == 0)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
769 break;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
770 if (pc <= fdata->base_address + lineno->l_addr.l_paddr - fn->sect_base)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
771 break;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
772 match = lnnoptr;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
773 lnno = lineno->l_lnno;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
774
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
775 lnnoptr += LINESZ;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
776 lineptr += LINESZ;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
777 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
778
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
779 /* If part of a function other than the beginning comes from an
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
780 include file, the line numbers are absolute, rather than
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
781 relative to the beginning of the function. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
782 incl = ((struct xcoff_incl *)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
783 bsearch (&match, fdata->incl_vec.vec.base,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
784 fdata->incl_vec.count, sizeof (struct xcoff_incl),
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
785 xcoff_incl_search));
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
786 if (incl != NULL)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
787 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
788 bincl = ((struct xcoff_incl *)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
789 bsearch (&fn->lnnoptr, fdata->incl_vec.vec.base,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
790 fdata->incl_vec.count, sizeof (struct xcoff_incl),
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
791 xcoff_incl_search));
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
792 if (bincl != NULL && strcmp (incl->filename, bincl->filename) == 0)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
793 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
794 lnno += fn->lnno - 1;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
795 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
796 filename = incl->filename;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
797 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
798 else
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
799 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
800 lnno += fn->lnno - 1;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
801 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
802
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
803 function = fn->name;
111
kono
parents:
diff changeset
804 /* AIX prepends a '.' to function entry points, remove it. */
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
805 if (function != NULL && *function == '.')
111
kono
parents:
diff changeset
806 ++function;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
807 return callback (data, pc, filename, lnno, function);
111
kono
parents:
diff changeset
808 }
kono
parents:
diff changeset
809
kono
parents:
diff changeset
810 /* Return the file/line information for a PC using the XCOFF lineno
kono
parents:
diff changeset
811 mapping we built earlier. */
kono
parents:
diff changeset
812
kono
parents:
diff changeset
813 static int
kono
parents:
diff changeset
814 xcoff_fileline (struct backtrace_state *state, uintptr_t pc,
kono
parents:
diff changeset
815 backtrace_full_callback callback,
kono
parents:
diff changeset
816 backtrace_error_callback error_callback, void *data)
kono
parents:
diff changeset
817
kono
parents:
diff changeset
818 {
kono
parents:
diff changeset
819 struct xcoff_fileline_data *fdata;
kono
parents:
diff changeset
820 int found;
kono
parents:
diff changeset
821 int ret;
kono
parents:
diff changeset
822
kono
parents:
diff changeset
823 if (!state->threaded)
kono
parents:
diff changeset
824 {
kono
parents:
diff changeset
825 for (fdata = (struct xcoff_fileline_data *) state->fileline_data;
kono
parents:
diff changeset
826 fdata != NULL;
kono
parents:
diff changeset
827 fdata = fdata->next)
kono
parents:
diff changeset
828 {
kono
parents:
diff changeset
829 ret = xcoff_lookup_pc (state, fdata, pc, callback, error_callback,
kono
parents:
diff changeset
830 data, &found);
kono
parents:
diff changeset
831 if (ret != 0 || found)
kono
parents:
diff changeset
832 return ret;
kono
parents:
diff changeset
833 }
kono
parents:
diff changeset
834 }
kono
parents:
diff changeset
835 else
kono
parents:
diff changeset
836 {
kono
parents:
diff changeset
837 struct xcoff_fileline_data **pp;
kono
parents:
diff changeset
838
kono
parents:
diff changeset
839 pp = (struct xcoff_fileline_data **) (void *) &state->fileline_data;
kono
parents:
diff changeset
840 while (1)
kono
parents:
diff changeset
841 {
kono
parents:
diff changeset
842 fdata = backtrace_atomic_load_pointer (pp);
kono
parents:
diff changeset
843 if (fdata == NULL)
kono
parents:
diff changeset
844 break;
kono
parents:
diff changeset
845
kono
parents:
diff changeset
846 ret = xcoff_lookup_pc (state, fdata, pc, callback, error_callback,
kono
parents:
diff changeset
847 data, &found);
kono
parents:
diff changeset
848 if (ret != 0 || found)
kono
parents:
diff changeset
849 return ret;
kono
parents:
diff changeset
850
kono
parents:
diff changeset
851 pp = &fdata->next;
kono
parents:
diff changeset
852 }
kono
parents:
diff changeset
853 }
kono
parents:
diff changeset
854
kono
parents:
diff changeset
855 /* FIXME: See if any libraries have been dlopen'ed. */
kono
parents:
diff changeset
856
kono
parents:
diff changeset
857 return callback (data, pc, NULL, 0, NULL);
kono
parents:
diff changeset
858 }
kono
parents:
diff changeset
859
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
860 /* Initialize the function vector info for xcoff_fileline. */
111
kono
parents:
diff changeset
861
kono
parents:
diff changeset
862 static int
kono
parents:
diff changeset
863 xcoff_initialize_fileline (struct backtrace_state *state,
kono
parents:
diff changeset
864 uintptr_t base_address,
kono
parents:
diff changeset
865 const b_xcoff_scnhdr *sects,
kono
parents:
diff changeset
866 const b_xcoff_syment *syms, size_t nsyms,
kono
parents:
diff changeset
867 const unsigned char *strtab, size_t strtab_size,
kono
parents:
diff changeset
868 const unsigned char *linenos, size_t linenos_size,
kono
parents:
diff changeset
869 uint64_t lnnoptr0,
kono
parents:
diff changeset
870 backtrace_error_callback error_callback, void *data)
kono
parents:
diff changeset
871 {
kono
parents:
diff changeset
872 struct xcoff_fileline_data *fdata;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
873 struct xcoff_func *fn;
111
kono
parents:
diff changeset
874 const b_xcoff_syment *fsym;
kono
parents:
diff changeset
875 const b_xcoff_auxent *aux;
kono
parents:
diff changeset
876 const char *filename;
kono
parents:
diff changeset
877 const char *name;
kono
parents:
diff changeset
878 struct xcoff_incl *incl;
kono
parents:
diff changeset
879 uintptr_t begin, end;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
880 uintptr_t lnno, lnnoptr;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
881 uint32_t fsize;
111
kono
parents:
diff changeset
882 size_t i;
kono
parents:
diff changeset
883
kono
parents:
diff changeset
884 fdata = ((struct xcoff_fileline_data *)
kono
parents:
diff changeset
885 backtrace_alloc (state, sizeof (struct xcoff_fileline_data),
kono
parents:
diff changeset
886 error_callback, data));
kono
parents:
diff changeset
887 if (fdata == NULL)
kono
parents:
diff changeset
888 return 0;
kono
parents:
diff changeset
889 memset (fdata, 0, sizeof *fdata);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
890 fdata->base_address = base_address;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
891 fdata->linenos = linenos;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
892 fdata->linenos_size = linenos_size;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
893 fdata->lnnoptr0 = lnnoptr0;
111
kono
parents:
diff changeset
894
kono
parents:
diff changeset
895 begin = 0;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
896 filename = NULL;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
897 fsym = NULL;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
898 lnnoptr = 0;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
899 fsize = 0;
111
kono
parents:
diff changeset
900 for (i = 0; i < nsyms; ++i)
kono
parents:
diff changeset
901 {
kono
parents:
diff changeset
902 const b_xcoff_syment *asym = &syms[i];
kono
parents:
diff changeset
903
kono
parents:
diff changeset
904 switch (asym->n_sclass)
kono
parents:
diff changeset
905 {
kono
parents:
diff changeset
906 case C_BINCL:
kono
parents:
diff changeset
907 begin = asym->n_value;
kono
parents:
diff changeset
908 break;
kono
parents:
diff changeset
909
kono
parents:
diff changeset
910 case C_EINCL:
kono
parents:
diff changeset
911 if (begin == 0)
kono
parents:
diff changeset
912 break;
kono
parents:
diff changeset
913 end = asym->n_value;
kono
parents:
diff changeset
914 incl = ((struct xcoff_incl *)
kono
parents:
diff changeset
915 backtrace_vector_grow (state, sizeof (struct xcoff_incl),
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
916 error_callback, data,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
917 &fdata->incl_vec.vec));
111
kono
parents:
diff changeset
918 if (incl != NULL)
kono
parents:
diff changeset
919 {
kono
parents:
diff changeset
920 incl->filename = xcoff_symname (asym, strtab, strtab_size);
kono
parents:
diff changeset
921 incl->begin = begin;
kono
parents:
diff changeset
922 incl->end = end;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
923 ++fdata->incl_vec.count;
111
kono
parents:
diff changeset
924 }
kono
parents:
diff changeset
925 begin = 0;
kono
parents:
diff changeset
926 break;
kono
parents:
diff changeset
927
kono
parents:
diff changeset
928 case C_FILE:
kono
parents:
diff changeset
929 filename = xcoff_symname (asym, strtab, strtab_size);
kono
parents:
diff changeset
930 if (filename == NULL)
kono
parents:
diff changeset
931 break;
kono
parents:
diff changeset
932
kono
parents:
diff changeset
933 /* If the file auxiliary entry is not used, the symbol name is
kono
parents:
diff changeset
934 the name of the source file. If the file auxiliary entry is
kono
parents:
diff changeset
935 used, then the symbol name should be .file, and the first
kono
parents:
diff changeset
936 file auxiliary entry (by convention) contains the source
kono
parents:
diff changeset
937 file name. */
kono
parents:
diff changeset
938
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
939 if (asym->n_numaux > 0 && strcmp (filename, ".file") == 0)
111
kono
parents:
diff changeset
940 {
kono
parents:
diff changeset
941 aux = (const b_xcoff_auxent *) (asym + 1);
kono
parents:
diff changeset
942 if (aux->x_file._x.x_zeroes != 0)
kono
parents:
diff changeset
943 {
kono
parents:
diff changeset
944 /* Make a copy as we will release the symtab view. */
kono
parents:
diff changeset
945 char name[FILNMLEN+1];
kono
parents:
diff changeset
946 strncpy (name, aux->x_file.x_fname, FILNMLEN);
kono
parents:
diff changeset
947 name[FILNMLEN] = '\0';
kono
parents:
diff changeset
948 filename = strdup (name);
kono
parents:
diff changeset
949 }
kono
parents:
diff changeset
950 else if (aux->x_file._x.x_offset < strtab_size)
kono
parents:
diff changeset
951 filename = (const char *) strtab + aux->x_file._x.x_offset;
kono
parents:
diff changeset
952 else
kono
parents:
diff changeset
953 filename = NULL;
kono
parents:
diff changeset
954 }
kono
parents:
diff changeset
955 break;
kono
parents:
diff changeset
956
kono
parents:
diff changeset
957 case C_EXT:
kono
parents:
diff changeset
958 case C_HIDEXT:
kono
parents:
diff changeset
959 case C_WEAKEXT:
kono
parents:
diff changeset
960 fsym = NULL;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
961 lnnoptr = 0;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
962 fsize = 0;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
963 if (!ISFCN (asym->n_type) || asym->n_numaux == 0
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
964 || asym->n_scnum <= 0)
111
kono
parents:
diff changeset
965 break;
kono
parents:
diff changeset
966 if (filename == NULL)
kono
parents:
diff changeset
967 break;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
968 aux = (const b_xcoff_auxent *) (asym + 1);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
969 lnnoptr = aux->x_fcn.x_lnnoptr;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
970 if (lnnoptr < lnnoptr0
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
971 || lnnoptr + LINESZ > lnnoptr0 + linenos_size)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
972 break;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
973 /* x_fsize will be 0 if there is no debug information. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
974 fsize = aux->x_fcn.x_fsize;
111
kono
parents:
diff changeset
975 fsym = asym;
kono
parents:
diff changeset
976 break;
kono
parents:
diff changeset
977
kono
parents:
diff changeset
978 case C_FCN:
kono
parents:
diff changeset
979 if (asym->n_numaux == 0)
kono
parents:
diff changeset
980 break;
kono
parents:
diff changeset
981 if (fsym == NULL)
kono
parents:
diff changeset
982 break;
kono
parents:
diff changeset
983 name = xcoff_symname (asym, strtab, strtab_size);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
984 if (name == NULL || strcmp (name, ".bf") != 0)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
985 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
986 fsym = NULL;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
987 break;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
988 }
111
kono
parents:
diff changeset
989 aux = (const b_xcoff_auxent *) (asym + 1);
kono
parents:
diff changeset
990 #if BACKTRACE_XCOFF_SIZE == 32
kono
parents:
diff changeset
991 lnno = (uint32_t) aux->x_block.x_lnnohi << 16
kono
parents:
diff changeset
992 | aux->x_block.x_lnno;
kono
parents:
diff changeset
993 #else
kono
parents:
diff changeset
994 lnno = aux->x_block.x_lnno;
kono
parents:
diff changeset
995 #endif
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
996 fn = ((struct xcoff_func *)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
997 backtrace_vector_grow (state, sizeof (struct xcoff_func),
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
998 error_callback, data,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
999 &fdata->func_vec.vec));
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1000 if (fn == NULL)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1001 break;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1002 fn->name = xcoff_symname (fsym, strtab, strtab_size);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1003 fn->filename = filename;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1004 fn->sect_base = sects[fsym->n_scnum - 1].s_paddr;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1005 fn->pc = base_address + fsym->n_value - fn->sect_base;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1006 fn->size = fsize;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1007 fn->lnno = lnno;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1008 fn->lnnoptr = lnnoptr;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1009 ++fdata->func_vec.count;
111
kono
parents:
diff changeset
1010 break;
kono
parents:
diff changeset
1011 }
kono
parents:
diff changeset
1012
kono
parents:
diff changeset
1013 i += asym->n_numaux;
kono
parents:
diff changeset
1014 }
kono
parents:
diff changeset
1015
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1016 if (!backtrace_vector_release (state, &fdata->func_vec.vec, error_callback,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1017 data))
111
kono
parents:
diff changeset
1018 goto fail;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1019 backtrace_qsort (fdata->func_vec.vec.base, fdata->func_vec.count,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1020 sizeof (struct xcoff_func), xcoff_func_compare);
111
kono
parents:
diff changeset
1021
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1022 if (!backtrace_vector_release (state, &fdata->incl_vec.vec, error_callback,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1023 data))
111
kono
parents:
diff changeset
1024 goto fail;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1025 backtrace_qsort (fdata->incl_vec.vec.base, fdata->incl_vec.count,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1026 sizeof (struct xcoff_incl), xcoff_incl_compare);
111
kono
parents:
diff changeset
1027
kono
parents:
diff changeset
1028 if (!state->threaded)
kono
parents:
diff changeset
1029 {
kono
parents:
diff changeset
1030 struct xcoff_fileline_data **pp;
kono
parents:
diff changeset
1031
kono
parents:
diff changeset
1032 for (pp = (struct xcoff_fileline_data **) (void *) &state->fileline_data;
kono
parents:
diff changeset
1033 *pp != NULL;
kono
parents:
diff changeset
1034 pp = &(*pp)->next)
kono
parents:
diff changeset
1035 ;
kono
parents:
diff changeset
1036 *pp = fdata;
kono
parents:
diff changeset
1037 }
kono
parents:
diff changeset
1038 else
kono
parents:
diff changeset
1039 {
kono
parents:
diff changeset
1040 while (1)
kono
parents:
diff changeset
1041 {
kono
parents:
diff changeset
1042 struct xcoff_fileline_data **pp;
kono
parents:
diff changeset
1043
kono
parents:
diff changeset
1044 pp = (struct xcoff_fileline_data **) (void *) &state->fileline_data;
kono
parents:
diff changeset
1045
kono
parents:
diff changeset
1046 while (1)
kono
parents:
diff changeset
1047 {
kono
parents:
diff changeset
1048 struct xcoff_fileline_data *p;
kono
parents:
diff changeset
1049
kono
parents:
diff changeset
1050 p = backtrace_atomic_load_pointer (pp);
kono
parents:
diff changeset
1051
kono
parents:
diff changeset
1052 if (p == NULL)
kono
parents:
diff changeset
1053 break;
kono
parents:
diff changeset
1054
kono
parents:
diff changeset
1055 pp = &p->next;
kono
parents:
diff changeset
1056 }
kono
parents:
diff changeset
1057
kono
parents:
diff changeset
1058 if (__sync_bool_compare_and_swap (pp, NULL, fdata))
kono
parents:
diff changeset
1059 break;
kono
parents:
diff changeset
1060 }
kono
parents:
diff changeset
1061 }
kono
parents:
diff changeset
1062
kono
parents:
diff changeset
1063 return 1;
kono
parents:
diff changeset
1064
kono
parents:
diff changeset
1065 fail:
kono
parents:
diff changeset
1066 return 0;
kono
parents:
diff changeset
1067 }
kono
parents:
diff changeset
1068
kono
parents:
diff changeset
1069 /* Add the backtrace data for one XCOFF file. Returns 1 on success,
kono
parents:
diff changeset
1070 0 on failure (in both cases descriptor is closed). */
kono
parents:
diff changeset
1071
kono
parents:
diff changeset
1072 static int
kono
parents:
diff changeset
1073 xcoff_add (struct backtrace_state *state, int descriptor, off_t offset,
kono
parents:
diff changeset
1074 uintptr_t base_address, backtrace_error_callback error_callback,
kono
parents:
diff changeset
1075 void *data, fileline *fileline_fn, int *found_sym, int exe)
kono
parents:
diff changeset
1076 {
kono
parents:
diff changeset
1077 struct backtrace_view fhdr_view;
kono
parents:
diff changeset
1078 struct backtrace_view sects_view;
kono
parents:
diff changeset
1079 struct backtrace_view linenos_view;
kono
parents:
diff changeset
1080 struct backtrace_view syms_view;
kono
parents:
diff changeset
1081 struct backtrace_view str_view;
kono
parents:
diff changeset
1082 struct backtrace_view dwarf_view;
kono
parents:
diff changeset
1083 b_xcoff_filhdr fhdr;
kono
parents:
diff changeset
1084 const b_xcoff_scnhdr *sects;
kono
parents:
diff changeset
1085 const b_xcoff_scnhdr *stext;
kono
parents:
diff changeset
1086 uint64_t lnnoptr;
kono
parents:
diff changeset
1087 uint32_t nlnno;
kono
parents:
diff changeset
1088 off_t str_off;
kono
parents:
diff changeset
1089 off_t min_offset;
kono
parents:
diff changeset
1090 off_t max_offset;
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1091 struct dwsect_info dwsect[DEBUG_MAX];
111
kono
parents:
diff changeset
1092 size_t sects_size;
kono
parents:
diff changeset
1093 size_t syms_size;
kono
parents:
diff changeset
1094 int32_t str_size;
kono
parents:
diff changeset
1095 int sects_view_valid;
kono
parents:
diff changeset
1096 int linenos_view_valid;
kono
parents:
diff changeset
1097 int syms_view_valid;
kono
parents:
diff changeset
1098 int str_view_valid;
kono
parents:
diff changeset
1099 int dwarf_view_valid;
kono
parents:
diff changeset
1100 int magic_ok;
kono
parents:
diff changeset
1101 int i;
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1102 struct dwarf_sections dwarf_sections;
111
kono
parents:
diff changeset
1103
kono
parents:
diff changeset
1104 *found_sym = 0;
kono
parents:
diff changeset
1105
kono
parents:
diff changeset
1106 sects_view_valid = 0;
kono
parents:
diff changeset
1107 linenos_view_valid = 0;
kono
parents:
diff changeset
1108 syms_view_valid = 0;
kono
parents:
diff changeset
1109 str_view_valid = 0;
kono
parents:
diff changeset
1110 dwarf_view_valid = 0;
kono
parents:
diff changeset
1111
kono
parents:
diff changeset
1112 str_size = 0;
kono
parents:
diff changeset
1113
kono
parents:
diff changeset
1114 /* Map the XCOFF file header. */
kono
parents:
diff changeset
1115 if (!backtrace_get_view (state, descriptor, offset, sizeof (b_xcoff_filhdr),
kono
parents:
diff changeset
1116 error_callback, data, &fhdr_view))
kono
parents:
diff changeset
1117 goto fail;
kono
parents:
diff changeset
1118
kono
parents:
diff changeset
1119 memcpy (&fhdr, fhdr_view.data, sizeof fhdr);
kono
parents:
diff changeset
1120 magic_ok = (fhdr.f_magic == XCOFF_MAGIC);
kono
parents:
diff changeset
1121
kono
parents:
diff changeset
1122 backtrace_release_view (state, &fhdr_view, error_callback, data);
kono
parents:
diff changeset
1123
kono
parents:
diff changeset
1124 if (!magic_ok)
kono
parents:
diff changeset
1125 {
kono
parents:
diff changeset
1126 if (exe)
kono
parents:
diff changeset
1127 error_callback (data, "executable file is not XCOFF", 0);
kono
parents:
diff changeset
1128 goto fail;
kono
parents:
diff changeset
1129 }
kono
parents:
diff changeset
1130
kono
parents:
diff changeset
1131 /* Verify object is of expected type. */
kono
parents:
diff changeset
1132 if ((exe && (fhdr.f_flags & F_SHROBJ))
kono
parents:
diff changeset
1133 || (!exe && !(fhdr.f_flags & F_SHROBJ)))
kono
parents:
diff changeset
1134 goto fail;
kono
parents:
diff changeset
1135
kono
parents:
diff changeset
1136 /* Read the section headers. */
kono
parents:
diff changeset
1137
kono
parents:
diff changeset
1138 sects_size = fhdr.f_nscns * sizeof (b_xcoff_scnhdr);
kono
parents:
diff changeset
1139
kono
parents:
diff changeset
1140 if (!backtrace_get_view (state, descriptor,
kono
parents:
diff changeset
1141 offset + sizeof (fhdr) + fhdr.f_opthdr,
kono
parents:
diff changeset
1142 sects_size, error_callback, data, &sects_view))
kono
parents:
diff changeset
1143 goto fail;
kono
parents:
diff changeset
1144 sects_view_valid = 1;
kono
parents:
diff changeset
1145 sects = (const b_xcoff_scnhdr *) sects_view.data;
kono
parents:
diff changeset
1146
kono
parents:
diff changeset
1147 /* FIXME: assumes only one .text section. */
kono
parents:
diff changeset
1148 for (i = 0; i < fhdr.f_nscns; ++i)
kono
parents:
diff changeset
1149 if ((sects[i].s_flags & 0xffff) == STYP_TEXT)
kono
parents:
diff changeset
1150 break;
kono
parents:
diff changeset
1151 if (i == fhdr.f_nscns)
kono
parents:
diff changeset
1152 goto fail;
kono
parents:
diff changeset
1153
kono
parents:
diff changeset
1154 stext = &sects[i];
kono
parents:
diff changeset
1155
kono
parents:
diff changeset
1156 /* AIX ldinfo_textorg includes the XCOFF headers. */
kono
parents:
diff changeset
1157 base_address = (exe ? XCOFF_AIX_TEXTBASE : base_address) + stext->s_scnptr;
kono
parents:
diff changeset
1158
kono
parents:
diff changeset
1159 lnnoptr = stext->s_lnnoptr;
kono
parents:
diff changeset
1160 nlnno = stext->s_nlnno;
kono
parents:
diff changeset
1161
kono
parents:
diff changeset
1162 #if BACKTRACE_XCOFF_SIZE == 32
kono
parents:
diff changeset
1163 if (nlnno == _OVERFLOW_MARKER)
kono
parents:
diff changeset
1164 {
kono
parents:
diff changeset
1165 int sntext = i + 1;
kono
parents:
diff changeset
1166 /* Find the matching .ovrflo section. */
kono
parents:
diff changeset
1167 for (i = 0; i < fhdr.f_nscns; ++i)
kono
parents:
diff changeset
1168 {
kono
parents:
diff changeset
1169 if (((sects[i].s_flags & 0xffff) == STYP_OVRFLO)
kono
parents:
diff changeset
1170 && sects[i].s_nlnno == sntext)
kono
parents:
diff changeset
1171 {
kono
parents:
diff changeset
1172 nlnno = sects[i].s_vaddr;
kono
parents:
diff changeset
1173 break;
kono
parents:
diff changeset
1174 }
kono
parents:
diff changeset
1175 }
kono
parents:
diff changeset
1176 }
kono
parents:
diff changeset
1177 #endif
kono
parents:
diff changeset
1178
kono
parents:
diff changeset
1179 /* Read the symbol table and the string table. */
kono
parents:
diff changeset
1180
kono
parents:
diff changeset
1181 if (fhdr.f_symptr != 0)
kono
parents:
diff changeset
1182 {
kono
parents:
diff changeset
1183 struct xcoff_syminfo_data *sdata;
kono
parents:
diff changeset
1184
kono
parents:
diff changeset
1185 /* Symbol table is followed by the string table. The string table
kono
parents:
diff changeset
1186 starts with its length (on 4 bytes).
kono
parents:
diff changeset
1187 Map the symbol table and the length of the string table. */
kono
parents:
diff changeset
1188 syms_size = fhdr.f_nsyms * sizeof (b_xcoff_syment);
kono
parents:
diff changeset
1189
kono
parents:
diff changeset
1190 if (!backtrace_get_view (state, descriptor, offset + fhdr.f_symptr,
kono
parents:
diff changeset
1191 syms_size + 4, error_callback, data,
kono
parents:
diff changeset
1192 &syms_view))
kono
parents:
diff changeset
1193 goto fail;
kono
parents:
diff changeset
1194 syms_view_valid = 1;
kono
parents:
diff changeset
1195
kono
parents:
diff changeset
1196 memcpy (&str_size, syms_view.data + syms_size, 4);
kono
parents:
diff changeset
1197
kono
parents:
diff changeset
1198 str_off = fhdr.f_symptr + syms_size;
kono
parents:
diff changeset
1199
kono
parents:
diff changeset
1200 if (str_size > 4)
kono
parents:
diff changeset
1201 {
kono
parents:
diff changeset
1202 /* Map string table (including the length word). */
kono
parents:
diff changeset
1203
kono
parents:
diff changeset
1204 if (!backtrace_get_view (state, descriptor, offset + str_off,
kono
parents:
diff changeset
1205 str_size, error_callback, data, &str_view))
kono
parents:
diff changeset
1206 goto fail;
kono
parents:
diff changeset
1207 str_view_valid = 1;
kono
parents:
diff changeset
1208 }
kono
parents:
diff changeset
1209
kono
parents:
diff changeset
1210 sdata = ((struct xcoff_syminfo_data *)
kono
parents:
diff changeset
1211 backtrace_alloc (state, sizeof *sdata, error_callback, data));
kono
parents:
diff changeset
1212 if (sdata == NULL)
kono
parents:
diff changeset
1213 goto fail;
kono
parents:
diff changeset
1214
kono
parents:
diff changeset
1215 if (!xcoff_initialize_syminfo (state, base_address, sects,
kono
parents:
diff changeset
1216 syms_view.data, fhdr.f_nsyms,
kono
parents:
diff changeset
1217 str_view.data, str_size,
kono
parents:
diff changeset
1218 error_callback, data, sdata))
kono
parents:
diff changeset
1219 {
kono
parents:
diff changeset
1220 backtrace_free (state, sdata, sizeof *sdata, error_callback, data);
kono
parents:
diff changeset
1221 goto fail;
kono
parents:
diff changeset
1222 }
kono
parents:
diff changeset
1223
kono
parents:
diff changeset
1224 *found_sym = 1;
kono
parents:
diff changeset
1225
kono
parents:
diff changeset
1226 xcoff_add_syminfo_data (state, sdata);
kono
parents:
diff changeset
1227 }
kono
parents:
diff changeset
1228
kono
parents:
diff changeset
1229 /* Read all the DWARF sections in a single view, since they are
kono
parents:
diff changeset
1230 probably adjacent in the file. We never release this view. */
kono
parents:
diff changeset
1231
kono
parents:
diff changeset
1232 min_offset = 0;
kono
parents:
diff changeset
1233 max_offset = 0;
kono
parents:
diff changeset
1234 memset (dwsect, 0, sizeof dwsect);
kono
parents:
diff changeset
1235 for (i = 0; i < fhdr.f_nscns; ++i)
kono
parents:
diff changeset
1236 {
kono
parents:
diff changeset
1237 off_t end;
kono
parents:
diff changeset
1238 int idx;
kono
parents:
diff changeset
1239
kono
parents:
diff changeset
1240 if ((sects[i].s_flags & 0xffff) != STYP_DWARF
kono
parents:
diff changeset
1241 || sects[i].s_size == 0)
kono
parents:
diff changeset
1242 continue;
kono
parents:
diff changeset
1243 /* Map DWARF section to array index. */
kono
parents:
diff changeset
1244 switch (sects[i].s_flags & 0xffff0000)
kono
parents:
diff changeset
1245 {
kono
parents:
diff changeset
1246 case SSUBTYP_DWINFO:
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1247 idx = DEBUG_INFO;
111
kono
parents:
diff changeset
1248 break;
kono
parents:
diff changeset
1249 case SSUBTYP_DWLINE:
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1250 idx = DEBUG_LINE;
111
kono
parents:
diff changeset
1251 break;
kono
parents:
diff changeset
1252 case SSUBTYP_DWABREV:
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1253 idx = DEBUG_ABBREV;
111
kono
parents:
diff changeset
1254 break;
kono
parents:
diff changeset
1255 case SSUBTYP_DWARNGE:
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1256 idx = DEBUG_RANGES;
111
kono
parents:
diff changeset
1257 break;
kono
parents:
diff changeset
1258 case SSUBTYP_DWSTR:
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1259 idx = DEBUG_STR;
111
kono
parents:
diff changeset
1260 break;
kono
parents:
diff changeset
1261 default:
kono
parents:
diff changeset
1262 continue;
kono
parents:
diff changeset
1263 }
kono
parents:
diff changeset
1264 if (min_offset == 0 || (off_t) sects[i].s_scnptr < min_offset)
kono
parents:
diff changeset
1265 min_offset = sects[i].s_scnptr;
kono
parents:
diff changeset
1266 end = sects[i].s_scnptr + sects[i].s_size;
kono
parents:
diff changeset
1267 if (end > max_offset)
kono
parents:
diff changeset
1268 max_offset = end;
kono
parents:
diff changeset
1269 dwsect[idx].offset = sects[i].s_scnptr;
kono
parents:
diff changeset
1270 dwsect[idx].size = sects[i].s_size;
kono
parents:
diff changeset
1271 }
kono
parents:
diff changeset
1272 if (min_offset != 0 && max_offset != 0)
kono
parents:
diff changeset
1273 {
kono
parents:
diff changeset
1274 if (!backtrace_get_view (state, descriptor, offset + min_offset,
kono
parents:
diff changeset
1275 max_offset - min_offset,
kono
parents:
diff changeset
1276 error_callback, data, &dwarf_view))
kono
parents:
diff changeset
1277 goto fail;
kono
parents:
diff changeset
1278 dwarf_view_valid = 1;
kono
parents:
diff changeset
1279
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1280 for (i = 0; i < (int) DEBUG_MAX; ++i)
111
kono
parents:
diff changeset
1281 {
kono
parents:
diff changeset
1282 if (dwsect[i].offset == 0)
kono
parents:
diff changeset
1283 dwsect[i].data = NULL;
kono
parents:
diff changeset
1284 else
kono
parents:
diff changeset
1285 dwsect[i].data = ((const unsigned char *) dwarf_view.data
kono
parents:
diff changeset
1286 + (dwsect[i].offset - min_offset));
kono
parents:
diff changeset
1287 }
kono
parents:
diff changeset
1288
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1289 memset (&dwarf_sections, 0, sizeof dwarf_sections);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1290
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1291 dwarf_sections.data[DEBUG_INFO] = dwsect[DEBUG_INFO].data;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1292 dwarf_sections.size[DEBUG_INFO] = dwsect[DEBUG_INFO].size;
111
kono
parents:
diff changeset
1293 #if BACKTRACE_XCOFF_SIZE == 32
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1294 /* XXX workaround for broken lineoff */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1295 dwarf_sections.data[DEBUG_LINE] = dwsect[DEBUG_LINE].data - 4;
111
kono
parents:
diff changeset
1296 #else
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1297 /* XXX workaround for broken lineoff */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1298 dwarf_sections.data[DEBUG_LINE] = dwsect[DEBUG_LINE].data - 12;
111
kono
parents:
diff changeset
1299 #endif
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1300 dwarf_sections.size[DEBUG_LINE] = dwsect[DEBUG_LINE].size;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1301 dwarf_sections.data[DEBUG_ABBREV] = dwsect[DEBUG_ABBREV].data;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1302 dwarf_sections.size[DEBUG_ABBREV] = dwsect[DEBUG_ABBREV].size;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1303 dwarf_sections.data[DEBUG_RANGES] = dwsect[DEBUG_RANGES].data;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1304 dwarf_sections.size[DEBUG_RANGES] = dwsect[DEBUG_RANGES].size;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1305 dwarf_sections.data[DEBUG_STR] = dwsect[DEBUG_STR].data;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1306 dwarf_sections.size[DEBUG_STR] = dwsect[DEBUG_STR].size;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1307
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1308 if (!backtrace_dwarf_add (state, 0, &dwarf_sections,
111
kono
parents:
diff changeset
1309 1, /* big endian */
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1310 NULL, /* altlink */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1311 error_callback, data, fileline_fn,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1312 NULL /* returned fileline_entry */))
111
kono
parents:
diff changeset
1313 goto fail;
kono
parents:
diff changeset
1314 }
kono
parents:
diff changeset
1315
kono
parents:
diff changeset
1316 /* Read the XCOFF line number entries if DWARF sections not found. */
kono
parents:
diff changeset
1317
kono
parents:
diff changeset
1318 if (!dwarf_view_valid && fhdr.f_symptr != 0 && lnnoptr != 0)
kono
parents:
diff changeset
1319 {
kono
parents:
diff changeset
1320 size_t linenos_size = (size_t) nlnno * LINESZ;
kono
parents:
diff changeset
1321
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1322 /* We never release this view. */
111
kono
parents:
diff changeset
1323 if (!backtrace_get_view (state, descriptor, offset + lnnoptr,
kono
parents:
diff changeset
1324 linenos_size,
kono
parents:
diff changeset
1325 error_callback, data, &linenos_view))
kono
parents:
diff changeset
1326 goto fail;
kono
parents:
diff changeset
1327 linenos_view_valid = 1;
kono
parents:
diff changeset
1328
kono
parents:
diff changeset
1329 if (xcoff_initialize_fileline (state, base_address, sects,
kono
parents:
diff changeset
1330 syms_view.data, fhdr.f_nsyms,
kono
parents:
diff changeset
1331 str_view.data, str_size,
kono
parents:
diff changeset
1332 linenos_view.data, linenos_size,
kono
parents:
diff changeset
1333 lnnoptr, error_callback, data))
kono
parents:
diff changeset
1334 *fileline_fn = xcoff_fileline;
kono
parents:
diff changeset
1335 }
kono
parents:
diff changeset
1336
kono
parents:
diff changeset
1337 backtrace_release_view (state, &sects_view, error_callback, data);
kono
parents:
diff changeset
1338 sects_view_valid = 0;
kono
parents:
diff changeset
1339 if (syms_view_valid)
kono
parents:
diff changeset
1340 backtrace_release_view (state, &syms_view, error_callback, data);
kono
parents:
diff changeset
1341 syms_view_valid = 0;
kono
parents:
diff changeset
1342
kono
parents:
diff changeset
1343 /* We've read all we need from the executable. */
kono
parents:
diff changeset
1344 if (!backtrace_close (descriptor, error_callback, data))
kono
parents:
diff changeset
1345 goto fail;
kono
parents:
diff changeset
1346 descriptor = -1;
kono
parents:
diff changeset
1347
kono
parents:
diff changeset
1348 return 1;
kono
parents:
diff changeset
1349
kono
parents:
diff changeset
1350 fail:
kono
parents:
diff changeset
1351 if (sects_view_valid)
kono
parents:
diff changeset
1352 backtrace_release_view (state, &sects_view, error_callback, data);
kono
parents:
diff changeset
1353 if (str_view_valid)
kono
parents:
diff changeset
1354 backtrace_release_view (state, &str_view, error_callback, data);
kono
parents:
diff changeset
1355 if (syms_view_valid)
kono
parents:
diff changeset
1356 backtrace_release_view (state, &syms_view, error_callback, data);
kono
parents:
diff changeset
1357 if (linenos_view_valid)
kono
parents:
diff changeset
1358 backtrace_release_view (state, &linenos_view, error_callback, data);
kono
parents:
diff changeset
1359 if (dwarf_view_valid)
kono
parents:
diff changeset
1360 backtrace_release_view (state, &dwarf_view, error_callback, data);
kono
parents:
diff changeset
1361 if (descriptor != -1 && offset == 0)
kono
parents:
diff changeset
1362 backtrace_close (descriptor, error_callback, data);
kono
parents:
diff changeset
1363 return 0;
kono
parents:
diff changeset
1364 }
kono
parents:
diff changeset
1365
kono
parents:
diff changeset
1366 #ifdef HAVE_LOADQUERY
kono
parents:
diff changeset
1367
kono
parents:
diff changeset
1368 /* Read an integer value in human-readable format from an AIX
kono
parents:
diff changeset
1369 big archive fixed-length or member header. */
kono
parents:
diff changeset
1370
kono
parents:
diff changeset
1371 static int
kono
parents:
diff changeset
1372 xcoff_parse_decimal (const char *buf, size_t size, off_t *off)
kono
parents:
diff changeset
1373 {
kono
parents:
diff changeset
1374 char str[32];
kono
parents:
diff changeset
1375 char *end;
kono
parents:
diff changeset
1376
kono
parents:
diff changeset
1377 if (size >= sizeof str)
kono
parents:
diff changeset
1378 return 0;
kono
parents:
diff changeset
1379 memcpy (str, buf, size);
kono
parents:
diff changeset
1380 str[size] = '\0';
kono
parents:
diff changeset
1381 *off = strtol (str, &end, 10);
kono
parents:
diff changeset
1382 if (*end != '\0' && *end != ' ')
kono
parents:
diff changeset
1383 return 0;
kono
parents:
diff changeset
1384
kono
parents:
diff changeset
1385 return 1;
kono
parents:
diff changeset
1386 }
kono
parents:
diff changeset
1387
kono
parents:
diff changeset
1388 /* Add the backtrace data for a member of an AIX big archive.
kono
parents:
diff changeset
1389 Returns 1 on success, 0 on failure. */
kono
parents:
diff changeset
1390
kono
parents:
diff changeset
1391 static int
kono
parents:
diff changeset
1392 xcoff_armem_add (struct backtrace_state *state, int descriptor,
kono
parents:
diff changeset
1393 uintptr_t base_address, const char *member,
kono
parents:
diff changeset
1394 backtrace_error_callback error_callback, void *data,
kono
parents:
diff changeset
1395 fileline *fileline_fn, int *found_sym)
kono
parents:
diff changeset
1396 {
kono
parents:
diff changeset
1397 struct backtrace_view view;
kono
parents:
diff changeset
1398 b_ar_fl_hdr fl_hdr;
kono
parents:
diff changeset
1399 const b_ar_hdr *ar_hdr;
kono
parents:
diff changeset
1400 off_t off;
kono
parents:
diff changeset
1401 off_t len;
kono
parents:
diff changeset
1402 int memlen;
kono
parents:
diff changeset
1403
kono
parents:
diff changeset
1404 *found_sym = 0;
kono
parents:
diff changeset
1405
kono
parents:
diff changeset
1406 /* Map archive fixed-length header. */
kono
parents:
diff changeset
1407
kono
parents:
diff changeset
1408 if (!backtrace_get_view (state, descriptor, 0, sizeof (b_ar_fl_hdr),
kono
parents:
diff changeset
1409 error_callback, data, &view))
kono
parents:
diff changeset
1410 goto fail;
kono
parents:
diff changeset
1411
kono
parents:
diff changeset
1412 memcpy (&fl_hdr, view.data, sizeof (b_ar_fl_hdr));
kono
parents:
diff changeset
1413
kono
parents:
diff changeset
1414 backtrace_release_view (state, &view, error_callback, data);
kono
parents:
diff changeset
1415
kono
parents:
diff changeset
1416 if (memcmp (fl_hdr.fl_magic, AIAMAGBIG, 8) != 0)
kono
parents:
diff changeset
1417 goto fail;
kono
parents:
diff changeset
1418
kono
parents:
diff changeset
1419 memlen = strlen (member);
kono
parents:
diff changeset
1420
kono
parents:
diff changeset
1421 /* Read offset of first archive member. */
kono
parents:
diff changeset
1422 if (!xcoff_parse_decimal (fl_hdr.fl_fstmoff, sizeof fl_hdr.fl_fstmoff, &off))
kono
parents:
diff changeset
1423 goto fail;
kono
parents:
diff changeset
1424 while (off != 0)
kono
parents:
diff changeset
1425 {
kono
parents:
diff changeset
1426 /* Map archive member header and member name. */
kono
parents:
diff changeset
1427
kono
parents:
diff changeset
1428 if (!backtrace_get_view (state, descriptor, off,
kono
parents:
diff changeset
1429 sizeof (b_ar_hdr) + memlen,
kono
parents:
diff changeset
1430 error_callback, data, &view))
kono
parents:
diff changeset
1431 break;
kono
parents:
diff changeset
1432
kono
parents:
diff changeset
1433 ar_hdr = (const b_ar_hdr *) view.data;
kono
parents:
diff changeset
1434
kono
parents:
diff changeset
1435 /* Read archive member name length. */
kono
parents:
diff changeset
1436 if (!xcoff_parse_decimal (ar_hdr->ar_namlen, sizeof ar_hdr->ar_namlen,
kono
parents:
diff changeset
1437 &len))
kono
parents:
diff changeset
1438 {
kono
parents:
diff changeset
1439 backtrace_release_view (state, &view, error_callback, data);
kono
parents:
diff changeset
1440 break;
kono
parents:
diff changeset
1441 }
kono
parents:
diff changeset
1442 if (len == memlen && !memcmp (ar_hdr->ar_name, member, memlen))
kono
parents:
diff changeset
1443 {
kono
parents:
diff changeset
1444 off = (off + sizeof (b_ar_hdr) + memlen + 1) & ~1;
kono
parents:
diff changeset
1445
kono
parents:
diff changeset
1446 /* The archive can contain several members with the same name
kono
parents:
diff changeset
1447 (e.g. 32-bit and 64-bit), so continue if not ok. */
kono
parents:
diff changeset
1448
kono
parents:
diff changeset
1449 if (xcoff_add (state, descriptor, off, base_address, error_callback,
kono
parents:
diff changeset
1450 data, fileline_fn, found_sym, 0))
kono
parents:
diff changeset
1451 {
kono
parents:
diff changeset
1452 backtrace_release_view (state, &view, error_callback, data);
kono
parents:
diff changeset
1453 return 1;
kono
parents:
diff changeset
1454 }
kono
parents:
diff changeset
1455 }
kono
parents:
diff changeset
1456
kono
parents:
diff changeset
1457 /* Read offset of next archive member. */
kono
parents:
diff changeset
1458 if (!xcoff_parse_decimal (ar_hdr->ar_nxtmem, sizeof ar_hdr->ar_nxtmem,
kono
parents:
diff changeset
1459 &off))
kono
parents:
diff changeset
1460 {
kono
parents:
diff changeset
1461 backtrace_release_view (state, &view, error_callback, data);
kono
parents:
diff changeset
1462 break;
kono
parents:
diff changeset
1463 }
kono
parents:
diff changeset
1464 backtrace_release_view (state, &view, error_callback, data);
kono
parents:
diff changeset
1465 }
kono
parents:
diff changeset
1466
kono
parents:
diff changeset
1467 fail:
kono
parents:
diff changeset
1468 /* No matching member found. */
kono
parents:
diff changeset
1469 backtrace_close (descriptor, error_callback, data);
kono
parents:
diff changeset
1470 return 0;
kono
parents:
diff changeset
1471 }
kono
parents:
diff changeset
1472
kono
parents:
diff changeset
1473 /* Add the backtrace data for dynamically loaded libraries. */
kono
parents:
diff changeset
1474
kono
parents:
diff changeset
1475 static void
kono
parents:
diff changeset
1476 xcoff_add_shared_libs (struct backtrace_state *state,
kono
parents:
diff changeset
1477 backtrace_error_callback error_callback,
kono
parents:
diff changeset
1478 void *data, fileline *fileline_fn, int *found_sym)
kono
parents:
diff changeset
1479 {
kono
parents:
diff changeset
1480 const struct ld_info *ldinfo;
kono
parents:
diff changeset
1481 void *buf;
kono
parents:
diff changeset
1482 unsigned int buflen;
kono
parents:
diff changeset
1483 const char *member;
kono
parents:
diff changeset
1484 int descriptor;
kono
parents:
diff changeset
1485 int does_not_exist;
kono
parents:
diff changeset
1486 int lib_found_sym;
kono
parents:
diff changeset
1487 int ret;
kono
parents:
diff changeset
1488
kono
parents:
diff changeset
1489 /* Retrieve the list of loaded libraries. */
kono
parents:
diff changeset
1490
kono
parents:
diff changeset
1491 buf = NULL;
kono
parents:
diff changeset
1492 buflen = 512;
kono
parents:
diff changeset
1493 do
kono
parents:
diff changeset
1494 {
kono
parents:
diff changeset
1495 buf = realloc (buf, buflen);
kono
parents:
diff changeset
1496 if (buf == NULL)
kono
parents:
diff changeset
1497 {
kono
parents:
diff changeset
1498 ret = -1;
kono
parents:
diff changeset
1499 break;
kono
parents:
diff changeset
1500 }
kono
parents:
diff changeset
1501 ret = loadquery (L_GETINFO, buf, buflen);
kono
parents:
diff changeset
1502 if (ret == 0)
kono
parents:
diff changeset
1503 break;
kono
parents:
diff changeset
1504 buflen *= 2;
kono
parents:
diff changeset
1505 }
kono
parents:
diff changeset
1506 while (ret == -1 && errno == ENOMEM);
kono
parents:
diff changeset
1507 if (ret != 0)
kono
parents:
diff changeset
1508 {
kono
parents:
diff changeset
1509 free (buf);
kono
parents:
diff changeset
1510 return;
kono
parents:
diff changeset
1511 }
kono
parents:
diff changeset
1512
kono
parents:
diff changeset
1513 ldinfo = (const struct ld_info *) buf;
kono
parents:
diff changeset
1514 while ((const char *) ldinfo < (const char *) buf + buflen)
kono
parents:
diff changeset
1515 {
kono
parents:
diff changeset
1516 if (*ldinfo->ldinfo_filename != '/')
kono
parents:
diff changeset
1517 goto next;
kono
parents:
diff changeset
1518
kono
parents:
diff changeset
1519 descriptor = backtrace_open (ldinfo->ldinfo_filename, error_callback,
kono
parents:
diff changeset
1520 data, &does_not_exist);
kono
parents:
diff changeset
1521 if (descriptor < 0)
kono
parents:
diff changeset
1522 goto next;
kono
parents:
diff changeset
1523
kono
parents:
diff changeset
1524 /* Check if it is an archive (member name not empty). */
kono
parents:
diff changeset
1525
kono
parents:
diff changeset
1526 member = ldinfo->ldinfo_filename + strlen (ldinfo->ldinfo_filename) + 1;
kono
parents:
diff changeset
1527 if (*member)
kono
parents:
diff changeset
1528 {
kono
parents:
diff changeset
1529 xcoff_armem_add (state, descriptor,
kono
parents:
diff changeset
1530 (uintptr_t) ldinfo->ldinfo_textorg, member,
kono
parents:
diff changeset
1531 error_callback, data, fileline_fn, &lib_found_sym);
kono
parents:
diff changeset
1532 }
kono
parents:
diff changeset
1533 else
kono
parents:
diff changeset
1534 {
kono
parents:
diff changeset
1535 xcoff_add (state, descriptor, 0, (uintptr_t) ldinfo->ldinfo_textorg,
kono
parents:
diff changeset
1536 error_callback, data, fileline_fn, &lib_found_sym, 0);
kono
parents:
diff changeset
1537 }
kono
parents:
diff changeset
1538 if (lib_found_sym)
kono
parents:
diff changeset
1539 *found_sym = 1;
kono
parents:
diff changeset
1540
kono
parents:
diff changeset
1541 next:
kono
parents:
diff changeset
1542 if (ldinfo->ldinfo_next == 0)
kono
parents:
diff changeset
1543 break;
kono
parents:
diff changeset
1544 ldinfo = (const struct ld_info *) ((const char *) ldinfo
kono
parents:
diff changeset
1545 + ldinfo->ldinfo_next);
kono
parents:
diff changeset
1546 }
kono
parents:
diff changeset
1547
kono
parents:
diff changeset
1548 free (buf);
kono
parents:
diff changeset
1549 }
kono
parents:
diff changeset
1550 #endif /* HAVE_LOADQUERY */
kono
parents:
diff changeset
1551
kono
parents:
diff changeset
1552 /* Initialize the backtrace data we need from an XCOFF executable.
kono
parents:
diff changeset
1553 Returns 1 on success, 0 on failure. */
kono
parents:
diff changeset
1554
kono
parents:
diff changeset
1555 int
kono
parents:
diff changeset
1556 backtrace_initialize (struct backtrace_state *state,
kono
parents:
diff changeset
1557 const char *filename ATTRIBUTE_UNUSED, int descriptor,
kono
parents:
diff changeset
1558 backtrace_error_callback error_callback,
kono
parents:
diff changeset
1559 void *data, fileline *fileline_fn)
kono
parents:
diff changeset
1560 {
kono
parents:
diff changeset
1561 int ret;
kono
parents:
diff changeset
1562 int found_sym;
kono
parents:
diff changeset
1563 fileline xcoff_fileline_fn = xcoff_nodebug;
kono
parents:
diff changeset
1564
kono
parents:
diff changeset
1565 ret = xcoff_add (state, descriptor, 0, 0, error_callback, data,
kono
parents:
diff changeset
1566 &xcoff_fileline_fn, &found_sym, 1);
kono
parents:
diff changeset
1567 if (!ret)
kono
parents:
diff changeset
1568 return 0;
kono
parents:
diff changeset
1569
kono
parents:
diff changeset
1570 #ifdef HAVE_LOADQUERY
kono
parents:
diff changeset
1571 xcoff_add_shared_libs (state, error_callback, data, &xcoff_fileline_fn,
kono
parents:
diff changeset
1572 &found_sym);
kono
parents:
diff changeset
1573 #endif
kono
parents:
diff changeset
1574
kono
parents:
diff changeset
1575 if (!state->threaded)
kono
parents:
diff changeset
1576 {
kono
parents:
diff changeset
1577 if (found_sym)
kono
parents:
diff changeset
1578 state->syminfo_fn = xcoff_syminfo;
kono
parents:
diff changeset
1579 else if (state->syminfo_fn == NULL)
kono
parents:
diff changeset
1580 state->syminfo_fn = xcoff_nosyms;
kono
parents:
diff changeset
1581 }
kono
parents:
diff changeset
1582 else
kono
parents:
diff changeset
1583 {
kono
parents:
diff changeset
1584 if (found_sym)
kono
parents:
diff changeset
1585 backtrace_atomic_store_pointer (&state->syminfo_fn, xcoff_syminfo);
kono
parents:
diff changeset
1586 else
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1587 (void) __sync_bool_compare_and_swap (&state->syminfo_fn, NULL,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1588 xcoff_nosyms);
111
kono
parents:
diff changeset
1589 }
kono
parents:
diff changeset
1590
kono
parents:
diff changeset
1591 if (!state->threaded)
kono
parents:
diff changeset
1592 {
kono
parents:
diff changeset
1593 if (state->fileline_fn == NULL || state->fileline_fn == xcoff_nodebug)
kono
parents:
diff changeset
1594 *fileline_fn = xcoff_fileline_fn;
kono
parents:
diff changeset
1595 }
kono
parents:
diff changeset
1596 else
kono
parents:
diff changeset
1597 {
kono
parents:
diff changeset
1598 fileline current_fn;
kono
parents:
diff changeset
1599
kono
parents:
diff changeset
1600 current_fn = backtrace_atomic_load_pointer (&state->fileline_fn);
kono
parents:
diff changeset
1601 if (current_fn == NULL || current_fn == xcoff_nodebug)
kono
parents:
diff changeset
1602 *fileline_fn = xcoff_fileline_fn;
kono
parents:
diff changeset
1603 }
kono
parents:
diff changeset
1604
kono
parents:
diff changeset
1605 return 1;
kono
parents:
diff changeset
1606 }