* copying.c: Rebuild.
[deliverable/binutils-gdb.git] / bfd / dwarf2.c
CommitLineData
252b5132 1/* DWARF 2 support.
818a27ac 2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
94df17f2 3 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
252b5132
RH
4
5 Adapted from gdb/dwarf2read.c by Gavin Koch of Cygnus Solutions
6 (gavin@cygnus.com).
7
8 From the dwarf2read.c header:
9 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
10 Inc. with support from Florida State University (under contract
11 with the Ada Joint Program Office), and Silicon Graphics, Inc.
12 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
13 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
14 support in dwarfread.c
15
e2f6d277 16 This file is part of BFD.
252b5132 17
e2f6d277
NC
18 This program is free software; you can redistribute it and/or modify
19 it under the terms of the GNU General Public License as published by
cd123cb7 20 the Free Software Foundation; either version 3 of the License, or (at
e2f6d277 21 your option) any later version.
252b5132 22
e2f6d277
NC
23 This program is distributed in the hope that it will be useful, but
24 WITHOUT ANY WARRANTY; without even the implied warranty of
25 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26 General Public License for more details.
252b5132 27
e2f6d277
NC
28 You should have received a copy of the GNU General Public License
29 along with this program; if not, write to the Free Software
cd123cb7
NC
30 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
31 MA 02110-1301, USA. */
252b5132 32
252b5132 33#include "sysdep.h"
3db64b00 34#include "bfd.h"
252b5132
RH
35#include "libiberty.h"
36#include "libbfd.h"
37#include "elf-bfd.h"
fa8f86ff 38#include "dwarf2.h"
252b5132
RH
39
40/* The data in the .debug_line statement prologue looks like this. */
a092b084 41
252b5132 42struct line_head
a092b084 43{
d03ba2a1 44 bfd_vma total_length;
a092b084 45 unsigned short version;
f46c2da6 46 bfd_vma prologue_length;
a092b084 47 unsigned char minimum_instruction_length;
a233b20c 48 unsigned char maximum_ops_per_insn;
a092b084
NC
49 unsigned char default_is_stmt;
50 int line_base;
51 unsigned char line_range;
52 unsigned char opcode_base;
53 unsigned char *standard_opcode_lengths;
54};
55
56/* Attributes have a name and a value. */
57
252b5132 58struct attribute
a092b084
NC
59{
60 enum dwarf_attribute name;
61 enum dwarf_form form;
62 union
252b5132 63 {
a092b084
NC
64 char *str;
65 struct dwarf_block *blk;
8ce8c090
AM
66 bfd_uint64_t val;
67 bfd_int64_t sval;
a092b084
NC
68 }
69 u;
70};
71
98591c73 72/* Blocks are a bunch of untyped bytes. */
252b5132 73struct dwarf_block
a092b084
NC
74{
75 unsigned int size;
f075ee0c 76 bfd_byte *data;
a092b084 77};
252b5132 78
5609a71e 79struct adjusted_section
d4c32a81
L
80{
81 asection *section;
82 bfd_vma adj_vma;
83};
84
a092b084
NC
85struct dwarf2_debug
86{
87 /* A list of all previously read comp_units. */
f075ee0c 88 struct comp_unit *all_comp_units;
252b5132 89
bd210d54
NC
90 /* Last comp unit in list above. */
91 struct comp_unit *last_comp_unit;
92
fc28f9aa
TG
93 /* Names of the debug sections. */
94 const struct dwarf_debug_section *debug_sections;
95
252b5132
RH
96 /* The next unread compilation unit within the .debug_info section.
97 Zero indicates that the .debug_info section has not been loaded
a092b084 98 into a buffer yet. */
f075ee0c 99 bfd_byte *info_ptr;
252b5132 100
a092b084 101 /* Pointer to the end of the .debug_info section memory buffer. */
f075ee0c 102 bfd_byte *info_ptr_end;
252b5132 103
0d161102
NC
104 /* Pointer to the bfd, section and address of the beginning of the
105 section. The bfd might be different than expected because of
106 gnu_debuglink sections. */
a50b1753 107 bfd *bfd_ptr;
f075ee0c
AM
108 asection *sec;
109 bfd_byte *sec_info_ptr;
f2363ce5 110
aaf30c25
CS
111 /* A pointer to the memory block allocated for info_ptr. Neither
112 info_ptr nor sec_info_ptr are guaranteed to stay pointing to the
113 beginning of the malloc block. This is used only to free the
114 memory later. */
115 bfd_byte *info_ptr_memory;
116
f2363ce5 117 /* Pointer to the symbol table. */
f075ee0c 118 asymbol **syms;
f2363ce5 119
a092b084 120 /* Pointer to the .debug_abbrev section loaded into memory. */
f075ee0c 121 bfd_byte *dwarf_abbrev_buffer;
252b5132 122
a092b084 123 /* Length of the loaded .debug_abbrev section. */
3076cd1f 124 bfd_size_type dwarf_abbrev_size;
69dd2e2d
RH
125
126 /* Buffer for decode_line_info. */
f075ee0c 127 bfd_byte *dwarf_line_buffer;
ccdb16fc
JW
128
129 /* Length of the loaded .debug_line section. */
3076cd1f 130 bfd_size_type dwarf_line_size;
d03ba2a1
JJ
131
132 /* Pointer to the .debug_str section loaded into memory. */
f075ee0c 133 bfd_byte *dwarf_str_buffer;
d03ba2a1
JJ
134
135 /* Length of the loaded .debug_str section. */
3076cd1f 136 bfd_size_type dwarf_str_size;
a13afe8e
FF
137
138 /* Pointer to the .debug_ranges section loaded into memory. */
139 bfd_byte *dwarf_ranges_buffer;
140
141 /* Length of the loaded .debug_ranges section. */
3076cd1f 142 bfd_size_type dwarf_ranges_size;
4ab527b0
FF
143
144 /* If the most recent call to bfd_find_nearest_line was given an
145 address in an inlined function, preserve a pointer into the
146 calling chain for subsequent calls to bfd_find_inliner_info to
147 use. */
148 struct funcinfo *inliner_chain;
d4c32a81 149
5609a71e
DJ
150 /* Number of sections whose VMA we must adjust. */
151 unsigned int adjusted_section_count;
d4c32a81 152
5609a71e
DJ
153 /* Array of sections with adjusted VMA. */
154 struct adjusted_section *adjusted_sections;
bd210d54
NC
155
156 /* Number of times find_line is called. This is used in
157 the heuristic for enabling the info hash tables. */
158 int info_hash_count;
159
160#define STASH_INFO_HASH_TRIGGER 100
161
162 /* Hash table mapping symbol names to function infos. */
163 struct info_hash_table *funcinfo_hash_table;
164
165 /* Hash table mapping symbol names to variable infos. */
166 struct info_hash_table *varinfo_hash_table;
167
168 /* Head of comp_unit list in the last hash table update. */
169 struct comp_unit *hash_units_head;
170
171 /* Status of info hash. */
172 int info_hash_status;
173#define STASH_INFO_HASH_OFF 0
174#define STASH_INFO_HASH_ON 1
175#define STASH_INFO_HASH_DISABLED 2
252b5132
RH
176};
177
a092b084
NC
178struct arange
179{
f623be2b
RH
180 struct arange *next;
181 bfd_vma low;
182 bfd_vma high;
183};
252b5132 184
252b5132 185/* A minimal decoding of DWARF2 compilation units. We only decode
a092b084 186 what's needed to get to the line number information. */
252b5132 187
a092b084
NC
188struct comp_unit
189{
190 /* Chain the previously read compilation units. */
f075ee0c 191 struct comp_unit *next_unit;
252b5132 192
bd210d54
NC
193 /* Likewise, chain the compilation unit read after this one.
194 The comp units are stored in reversed reading order. */
195 struct comp_unit *prev_unit;
196
2ae727ad 197 /* Keep the bfd convenient (for memory allocation). */
f075ee0c 198 bfd *abfd;
252b5132 199
709d67f1
AM
200 /* The lowest and highest addresses contained in this compilation
201 unit as specified in the compilation unit header. */
202 struct arange arange;
252b5132 203
a092b084 204 /* The DW_AT_name attribute (for error messages). */
f075ee0c 205 char *name;
252b5132 206
a092b084 207 /* The abbrev hash table. */
f075ee0c 208 struct abbrev_info **abbrevs;
252b5132 209
a092b084 210 /* Note that an error was found by comp_unit_find_nearest_line. */
252b5132
RH
211 int error;
212
a092b084 213 /* The DW_AT_comp_dir attribute. */
f075ee0c 214 char *comp_dir;
252b5132 215
b34976b6 216 /* TRUE if there is a line number table associated with this comp. unit. */
252b5132 217 int stmtlist;
98591c73 218
c0c28ab8
L
219 /* Pointer to the current comp_unit so that we can find a given entry
220 by its reference. */
f075ee0c 221 bfd_byte *info_ptr_unit;
c0c28ab8 222
a358ecb8
AM
223 /* Pointer to the start of the debug section, for DW_FORM_ref_addr. */
224 bfd_byte *sec_info_ptr;
225
a092b084 226 /* The offset into .debug_line of the line number table. */
252b5132
RH
227 unsigned long line_offset;
228
a092b084 229 /* Pointer to the first child die for the comp unit. */
f075ee0c 230 bfd_byte *first_child_die_ptr;
252b5132 231
a092b084 232 /* The end of the comp unit. */
f075ee0c 233 bfd_byte *end_ptr;
252b5132 234
a092b084 235 /* The decoded line number, NULL if not yet decoded. */
f075ee0c 236 struct line_info_table *line_table;
252b5132 237
a092b084 238 /* A list of the functions found in this comp. unit. */
f075ee0c 239 struct funcinfo *function_table;
252b5132 240
5420f73d
L
241 /* A list of the variables found in this comp. unit. */
242 struct varinfo *variable_table;
243
d03ba2a1
JJ
244 /* Pointer to dwarf2_debug structure. */
245 struct dwarf2_debug *stash;
246
5609a71e
DJ
247 /* DWARF format version for this unit - from unit header. */
248 int version;
249
a092b084 250 /* Address size for this unit - from unit header. */
252b5132 251 unsigned char addr_size;
d03ba2a1
JJ
252
253 /* Offset size for this unit - from unit header. */
254 unsigned char offset_size;
a13afe8e
FF
255
256 /* Base address for this unit - from DW_AT_low_pc attribute of
257 DW_TAG_compile_unit DIE */
258 bfd_vma base_address;
bd210d54
NC
259
260 /* TRUE if symbols are cached in hash table for faster lookup by name. */
261 bfd_boolean cached;
252b5132
RH
262};
263
a7b97311
AM
264/* This data structure holds the information of an abbrev. */
265struct abbrev_info
266{
267 unsigned int number; /* Number identifying abbrev. */
268 enum dwarf_tag tag; /* DWARF tag. */
269 int has_children; /* Boolean. */
270 unsigned int num_attrs; /* Number of attributes. */
271 struct attr_abbrev *attrs; /* An array of attribute descriptions. */
272 struct abbrev_info *next; /* Next in chain. */
273};
274
275struct attr_abbrev
276{
277 enum dwarf_attribute name;
278 enum dwarf_form form;
279};
280
4a114e3e
L
281/* Map of uncompressed DWARF debug section name to compressed one. It
282 is terminated by NULL uncompressed_name. */
283
e4c93b56 284const struct dwarf_debug_section dwarf_debug_sections[] =
4a114e3e
L
285{
286 { ".debug_abbrev", ".zdebug_abbrev" },
287 { ".debug_aranges", ".zdebug_aranges" },
288 { ".debug_frame", ".zdebug_frame" },
289 { ".debug_info", ".zdebug_info" },
290 { ".debug_line", ".zdebug_line" },
291 { ".debug_loc", ".zdebug_loc" },
292 { ".debug_macinfo", ".zdebug_macinfo" },
4ccf1e31 293 { ".debug_macro", ".zdebug_macro" },
4a114e3e
L
294 { ".debug_pubnames", ".zdebug_pubnames" },
295 { ".debug_pubtypes", ".zdebug_pubtypes" },
296 { ".debug_ranges", ".zdebug_ranges" },
297 { ".debug_static_func", ".zdebug_static_func" },
298 { ".debug_static_vars", ".zdebug_static_vars" },
299 { ".debug_str", ".zdebug_str", },
300 { ".debug_types", ".zdebug_types" },
301 /* GNU DWARF 1 extensions */
302 { ".debug_sfnames", ".zdebug_sfnames" },
303 { ".debug_srcinfo", ".zebug_srcinfo" },
304 /* SGI/MIPS DWARF 2 extensions */
305 { ".debug_funcnames", ".zdebug_funcnames" },
306 { ".debug_typenames", ".zdebug_typenames" },
307 { ".debug_varnames", ".zdebug_varnames" },
308 { ".debug_weaknames", ".zdebug_weaknames" },
309 { NULL, NULL },
310};
311
312enum dwarf_debug_section_enum
313{
314 debug_abbrev = 0,
315 debug_aranges,
316 debug_frame,
317 debug_info,
318 debug_line,
319 debug_loc,
320 debug_macinfo,
4ccf1e31 321 debug_macro,
4a114e3e
L
322 debug_pubnames,
323 debug_pubtypes,
324 debug_ranges,
325 debug_static_func,
326 debug_static_vars,
327 debug_str,
328 debug_types,
329 debug_sfnames,
330 debug_srcinfo,
331 debug_funcnames,
332 debug_typenames,
333 debug_varnames,
334 debug_weaknames
335};
336
a7b97311
AM
337#ifndef ABBREV_HASH_SIZE
338#define ABBREV_HASH_SIZE 121
339#endif
340#ifndef ATTR_ALLOC_CHUNK
341#define ATTR_ALLOC_CHUNK 4
342#endif
343
bd210d54
NC
344/* Variable and function hash tables. This is used to speed up look-up
345 in lookup_symbol_in_var_table() and lookup_symbol_in_function_table().
346 In order to share code between variable and function infos, we use
347 a list of untyped pointer for all variable/function info associated with
348 a symbol. We waste a bit of memory for list with one node but that
349 simplifies the code. */
350
351struct info_list_node
352{
353 struct info_list_node *next;
354 void *info;
355};
356
357/* Info hash entry. */
358struct info_hash_entry
359{
360 struct bfd_hash_entry root;
361 struct info_list_node *head;
362};
363
364struct info_hash_table
365{
366 struct bfd_hash_table base;
367};
368
369/* Function to create a new entry in info hash table. */
370
371static struct bfd_hash_entry *
372info_hash_table_newfunc (struct bfd_hash_entry *entry,
373 struct bfd_hash_table *table,
374 const char *string)
375{
376 struct info_hash_entry *ret = (struct info_hash_entry *) entry;
377
378 /* Allocate the structure if it has not already been allocated by a
379 derived class. */
380 if (ret == NULL)
381 {
a50b1753
NC
382 ret = (struct info_hash_entry *) bfd_hash_allocate (table,
383 sizeof (* ret));
bd210d54
NC
384 if (ret == NULL)
385 return NULL;
386 }
387
388 /* Call the allocation method of the base class. */
389 ret = ((struct info_hash_entry *)
2d47a72c 390 bfd_hash_newfunc ((struct bfd_hash_entry *) ret, table, string));
bd210d54
NC
391
392 /* Initialize the local fields here. */
393 if (ret)
394 ret->head = NULL;
395
396 return (struct bfd_hash_entry *) ret;
397}
398
399/* Function to create a new info hash table. It returns a pointer to the
400 newly created table or NULL if there is any error. We need abfd
401 solely for memory allocation. */
402
403static struct info_hash_table *
404create_info_hash_table (bfd *abfd)
405{
406 struct info_hash_table *hash_table;
407
a2a50954
AM
408 hash_table = ((struct info_hash_table *)
409 bfd_alloc (abfd, sizeof (struct info_hash_table)));
bd210d54
NC
410 if (!hash_table)
411 return hash_table;
412
413 if (!bfd_hash_table_init (&hash_table->base, info_hash_table_newfunc,
414 sizeof (struct info_hash_entry)))
415 {
416 bfd_release (abfd, hash_table);
417 return NULL;
418 }
419
420 return hash_table;
421}
422
423/* Insert an info entry into an info hash table. We do not check of
424 duplicate entries. Also, the caller need to guarantee that the
425 right type of info in inserted as info is passed as a void* pointer.
426 This function returns true if there is no error. */
427
428static bfd_boolean
429insert_info_hash_table (struct info_hash_table *hash_table,
430 const char *key,
431 void *info,
432 bfd_boolean copy_p)
433{
434 struct info_hash_entry *entry;
435 struct info_list_node *node;
436
437 entry = (struct info_hash_entry*) bfd_hash_lookup (&hash_table->base,
438 key, TRUE, copy_p);
439 if (!entry)
440 return FALSE;
441
a50b1753
NC
442 node = (struct info_list_node *) bfd_hash_allocate (&hash_table->base,
443 sizeof (*node));
bd210d54
NC
444 if (!node)
445 return FALSE;
446
447 node->info = info;
448 node->next = entry->head;
449 entry->head = node;
450
451 return TRUE;
452}
453
454/* Look up an info entry list from an info hash table. Return NULL
455 if there is none. */
456
457static struct info_list_node *
458lookup_info_hash_table (struct info_hash_table *hash_table, const char *key)
459{
460 struct info_hash_entry *entry;
461
462 entry = (struct info_hash_entry*) bfd_hash_lookup (&hash_table->base, key,
463 FALSE, FALSE);
464 return entry ? entry->head : NULL;
465}
466
1b315056 467/* Read a section into its appropriate place in the dwarf2_debug
dc80fd5c 468 struct (indicated by SECTION_BUFFER and SECTION_SIZE). If SYMS is
1b315056 469 not NULL, use bfd_simple_get_relocated_section_contents to read the
dc80fd5c
NC
470 section contents, otherwise use bfd_get_section_contents. Fail if
471 the located section does not contain at least OFFSET bytes. */
1b315056
CS
472
473static bfd_boolean
dc80fd5c 474read_section (bfd * abfd,
fc28f9aa 475 const struct dwarf_debug_section *sec,
dc80fd5c
NC
476 asymbol ** syms,
477 bfd_uint64_t offset,
478 bfd_byte ** section_buffer,
479 bfd_size_type * section_size)
1b315056
CS
480{
481 asection *msec;
fc28f9aa 482 const char *section_name = sec->uncompressed_name;
1b315056
CS
483
484 /* read_section is a noop if the section has already been read. */
53638231 485 if (!*section_buffer)
1b315056 486 {
53638231 487 msec = bfd_get_section_by_name (abfd, section_name);
4a114e3e 488 if (! msec)
53638231 489 {
fc28f9aa
TG
490 section_name = sec->compressed_name;
491 if (section_name != NULL)
492 msec = bfd_get_section_by_name (abfd, section_name);
53638231
AS
493 }
494 if (! msec)
2d47a72c 495 {
fc28f9aa
TG
496 (*_bfd_error_handler) (_("Dwarf Error: Can't find %s section."),
497 sec->uncompressed_name);
2d47a72c
DJ
498 bfd_set_error (bfd_error_bad_value);
499 return FALSE;
500 }
53638231 501
bc664799 502 *section_size = msec->rawsize ? msec->rawsize : msec->size;
8c2ccebd
CC
503 if (syms)
504 {
505 *section_buffer
a2a50954 506 = bfd_simple_get_relocated_section_contents (abfd, msec, NULL, syms);
8c2ccebd
CC
507 if (! *section_buffer)
508 return FALSE;
509 }
510 else
511 {
512 *section_buffer = (bfd_byte *) bfd_malloc (*section_size);
513 if (! *section_buffer)
514 return FALSE;
515 if (! bfd_get_section_contents (abfd, msec, *section_buffer,
516 0, *section_size))
517 return FALSE;
518 }
1b315056
CS
519 }
520
521 /* It is possible to get a bad value for the offset into the section
dc80fd5c 522 that the client wants. Validate it here to avoid trouble later. */
1b315056
CS
523 if (offset != 0 && offset >= *section_size)
524 {
a2a50954
AM
525 (*_bfd_error_handler) (_("Dwarf Error: Offset (%lu)"
526 " greater than or equal to %s size (%lu)."),
dc80fd5c 527 (long) offset, section_name, *section_size);
1b315056
CS
528 bfd_set_error (bfd_error_bad_value);
529 return FALSE;
530 }
531
532 return TRUE;
533}
534
98591c73
KH
535/* VERBATIM
536 The following function up to the END VERBATIM mark are
a092b084 537 copied directly from dwarf2read.c. */
252b5132 538
a092b084 539/* Read dwarf information from a buffer. */
252b5132
RH
540
541static unsigned int
f075ee0c 542read_1_byte (bfd *abfd ATTRIBUTE_UNUSED, bfd_byte *buf)
252b5132 543{
818a27ac 544 return bfd_get_8 (abfd, buf);
252b5132
RH
545}
546
547static int
f075ee0c 548read_1_signed_byte (bfd *abfd ATTRIBUTE_UNUSED, bfd_byte *buf)
252b5132 549{
818a27ac 550 return bfd_get_signed_8 (abfd, buf);
252b5132
RH
551}
552
553static unsigned int
f075ee0c 554read_2_bytes (bfd *abfd, bfd_byte *buf)
252b5132 555{
818a27ac 556 return bfd_get_16 (abfd, buf);
252b5132
RH
557}
558
252b5132 559static unsigned int
f075ee0c 560read_4_bytes (bfd *abfd, bfd_byte *buf)
252b5132 561{
818a27ac 562 return bfd_get_32 (abfd, buf);
252b5132
RH
563}
564
8ce8c090 565static bfd_uint64_t
f075ee0c 566read_8_bytes (bfd *abfd, bfd_byte *buf)
252b5132 567{
818a27ac 568 return bfd_get_64 (abfd, buf);
252b5132
RH
569}
570
f075ee0c 571static bfd_byte *
818a27ac 572read_n_bytes (bfd *abfd ATTRIBUTE_UNUSED,
f075ee0c 573 bfd_byte *buf,
818a27ac 574 unsigned int size ATTRIBUTE_UNUSED)
252b5132 575{
252b5132
RH
576 return buf;
577}
578
579static char *
818a27ac 580read_string (bfd *abfd ATTRIBUTE_UNUSED,
f075ee0c 581 bfd_byte *buf,
818a27ac 582 unsigned int *bytes_read_ptr)
252b5132 583{
d03ba2a1 584 /* Return a pointer to the embedded string. */
f075ee0c 585 char *str = (char *) buf;
dc80fd5c 586
f075ee0c 587 if (*str == '\0')
252b5132
RH
588 {
589 *bytes_read_ptr = 1;
590 return NULL;
591 }
98591c73 592
f075ee0c
AM
593 *bytes_read_ptr = strlen (str) + 1;
594 return str;
252b5132
RH
595}
596
dc80fd5c
NC
597/* END VERBATIM */
598
d03ba2a1 599static char *
dc80fd5c
NC
600read_indirect_string (struct comp_unit * unit,
601 bfd_byte * buf,
602 unsigned int * bytes_read_ptr)
d03ba2a1 603{
8ce8c090 604 bfd_uint64_t offset;
d03ba2a1 605 struct dwarf2_debug *stash = unit->stash;
f075ee0c 606 char *str;
d03ba2a1
JJ
607
608 if (unit->offset_size == 4)
609 offset = read_4_bytes (unit->abfd, buf);
610 else
611 offset = read_8_bytes (unit->abfd, buf);
dc80fd5c 612
d03ba2a1
JJ
613 *bytes_read_ptr = unit->offset_size;
614
fc28f9aa
TG
615 if (! read_section (unit->abfd, &stash->debug_sections[debug_str],
616 stash->syms, offset,
9e32b19f 617 &stash->dwarf_str_buffer, &stash->dwarf_str_size))
dc80fd5c 618 return NULL;
d03ba2a1 619
f075ee0c
AM
620 str = (char *) stash->dwarf_str_buffer + offset;
621 if (*str == '\0')
d03ba2a1 622 return NULL;
f075ee0c 623 return str;
d03ba2a1
JJ
624}
625
8ce8c090 626static bfd_uint64_t
f075ee0c 627read_address (struct comp_unit *unit, bfd_byte *buf)
252b5132 628{
0af4cd7c
PK
629 int signed_vma = get_elf_backend_data (unit->abfd)->sign_extend_vma;
630
631 if (signed_vma)
632 {
633 switch (unit->addr_size)
634 {
635 case 8:
636 return bfd_get_signed_64 (unit->abfd, buf);
637 case 4:
638 return bfd_get_signed_32 (unit->abfd, buf);
639 case 2:
640 return bfd_get_signed_16 (unit->abfd, buf);
641 default:
642 abort ();
643 }
644 }
645 else
252b5132 646 {
0af4cd7c
PK
647 switch (unit->addr_size)
648 {
649 case 8:
650 return bfd_get_64 (unit->abfd, buf);
651 case 4:
652 return bfd_get_32 (unit->abfd, buf);
653 case 2:
654 return bfd_get_16 (unit->abfd, buf);
655 default:
656 abort ();
657 }
252b5132 658 }
252b5132
RH
659}
660
252b5132
RH
661/* Lookup an abbrev_info structure in the abbrev hash table. */
662
663static struct abbrev_info *
818a27ac 664lookup_abbrev (unsigned int number, struct abbrev_info **abbrevs)
252b5132
RH
665{
666 unsigned int hash_number;
667 struct abbrev_info *abbrev;
668
669 hash_number = number % ABBREV_HASH_SIZE;
670 abbrev = abbrevs[hash_number];
671
672 while (abbrev)
673 {
674 if (abbrev->number == number)
675 return abbrev;
676 else
677 abbrev = abbrev->next;
678 }
98591c73 679
252b5132
RH
680 return NULL;
681}
682
683/* In DWARF version 2, the description of the debugging information is
684 stored in a separate .debug_abbrev section. Before we read any
685 dies from a section we read in all abbreviations and install them
686 in a hash table. */
687
688static struct abbrev_info**
8ce8c090 689read_abbrevs (bfd *abfd, bfd_uint64_t offset, struct dwarf2_debug *stash)
252b5132
RH
690{
691 struct abbrev_info **abbrevs;
f075ee0c 692 bfd_byte *abbrev_ptr;
252b5132
RH
693 struct abbrev_info *cur_abbrev;
694 unsigned int abbrev_number, bytes_read, abbrev_name;
695 unsigned int abbrev_form, hash_number;
dc810e39 696 bfd_size_type amt;
252b5132 697
fc28f9aa
TG
698 if (! read_section (abfd, &stash->debug_sections[debug_abbrev],
699 stash->syms, offset,
9e32b19f 700 &stash->dwarf_abbrev_buffer, &stash->dwarf_abbrev_size))
8af6b354 701 return NULL;
252b5132 702
dc810e39 703 amt = sizeof (struct abbrev_info*) * ABBREV_HASH_SIZE;
a50b1753 704 abbrevs = (struct abbrev_info **) bfd_zalloc (abfd, amt);
8af6b354
AM
705 if (abbrevs == NULL)
706 return NULL;
252b5132
RH
707
708 abbrev_ptr = stash->dwarf_abbrev_buffer + offset;
709 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
710 abbrev_ptr += bytes_read;
711
a092b084 712 /* Loop until we reach an abbrev number of 0. */
252b5132
RH
713 while (abbrev_number)
714 {
dc810e39 715 amt = sizeof (struct abbrev_info);
a50b1753 716 cur_abbrev = (struct abbrev_info *) bfd_zalloc (abfd, amt);
8af6b354
AM
717 if (cur_abbrev == NULL)
718 return NULL;
252b5132 719
a092b084 720 /* Read in abbrev header. */
252b5132 721 cur_abbrev->number = abbrev_number;
d45913a0
DA
722 cur_abbrev->tag = (enum dwarf_tag)
723 read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
252b5132
RH
724 abbrev_ptr += bytes_read;
725 cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr);
726 abbrev_ptr += 1;
727
a092b084 728 /* Now read in declarations. */
252b5132
RH
729 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
730 abbrev_ptr += bytes_read;
731 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
732 abbrev_ptr += bytes_read;
98591c73 733
252b5132
RH
734 while (abbrev_name)
735 {
736 if ((cur_abbrev->num_attrs % ATTR_ALLOC_CHUNK) == 0)
737 {
35330cce
NC
738 struct attr_abbrev *tmp;
739
dc810e39
AM
740 amt = cur_abbrev->num_attrs + ATTR_ALLOC_CHUNK;
741 amt *= sizeof (struct attr_abbrev);
a50b1753 742 tmp = (struct attr_abbrev *) bfd_realloc (cur_abbrev->attrs, amt);
35330cce 743 if (tmp == NULL)
d8d1c398
AM
744 {
745 size_t i;
746
747 for (i = 0; i < ABBREV_HASH_SIZE; i++)
748 {
749 struct abbrev_info *abbrev = abbrevs[i];
750
751 while (abbrev)
752 {
34b5e0b2
NC
753 free (abbrev->attrs);
754 abbrev = abbrev->next;
d8d1c398
AM
755 }
756 }
757 return NULL;
758 }
35330cce 759 cur_abbrev->attrs = tmp;
252b5132 760 }
98591c73 761
d45913a0
DA
762 cur_abbrev->attrs[cur_abbrev->num_attrs].name
763 = (enum dwarf_attribute) abbrev_name;
764 cur_abbrev->attrs[cur_abbrev->num_attrs++].form
765 = (enum dwarf_form) abbrev_form;
252b5132
RH
766 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
767 abbrev_ptr += bytes_read;
768 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
769 abbrev_ptr += bytes_read;
770 }
771
772 hash_number = abbrev_number % ABBREV_HASH_SIZE;
773 cur_abbrev->next = abbrevs[hash_number];
774 abbrevs[hash_number] = cur_abbrev;
775
776 /* Get next abbreviation.
e82ce529 777 Under Irix6 the abbreviations for a compilation unit are not
252b5132
RH
778 always properly terminated with an abbrev number of 0.
779 Exit loop if we encounter an abbreviation which we have
780 already read (which means we are about to read the abbreviations
781 for the next compile unit) or if the end of the abbreviation
782 table is reached. */
783 if ((unsigned int) (abbrev_ptr - stash->dwarf_abbrev_buffer)
d8d1c398 784 >= stash->dwarf_abbrev_size)
252b5132
RH
785 break;
786 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
787 abbrev_ptr += bytes_read;
788 if (lookup_abbrev (abbrev_number,abbrevs) != NULL)
789 break;
790 }
791
792 return abbrevs;
793}
794
cf716c56 795/* Read an attribute value described by an attribute form. */
252b5132 796
f075ee0c 797static bfd_byte *
818a27ac
AM
798read_attribute_value (struct attribute *attr,
799 unsigned form,
800 struct comp_unit *unit,
f075ee0c 801 bfd_byte *info_ptr)
252b5132
RH
802{
803 bfd *abfd = unit->abfd;
804 unsigned int bytes_read;
805 struct dwarf_block *blk;
dc810e39 806 bfd_size_type amt;
252b5132 807
d45913a0 808 attr->form = (enum dwarf_form) form;
98591c73 809
cf716c56 810 switch (form)
252b5132 811 {
252b5132 812 case DW_FORM_ref_addr:
5609a71e
DJ
813 /* DW_FORM_ref_addr is an address in DWARF2, and an offset in
814 DWARF3. */
c07cbdd7 815 if (unit->version == 3 || unit->version == 4)
5609a71e
DJ
816 {
817 if (unit->offset_size == 4)
818 attr->u.val = read_4_bytes (unit->abfd, info_ptr);
819 else
820 attr->u.val = read_8_bytes (unit->abfd, info_ptr);
821 info_ptr += unit->offset_size;
822 break;
823 }
824 /* FALLTHROUGH */
825 case DW_FORM_addr:
482e2e37 826 attr->u.val = read_address (unit, info_ptr);
252b5132
RH
827 info_ptr += unit->addr_size;
828 break;
c07cbdd7
JJ
829 case DW_FORM_sec_offset:
830 if (unit->offset_size == 4)
831 attr->u.val = read_4_bytes (unit->abfd, info_ptr);
832 else
833 attr->u.val = read_8_bytes (unit->abfd, info_ptr);
834 info_ptr += unit->offset_size;
835 break;
252b5132 836 case DW_FORM_block2:
dc810e39 837 amt = sizeof (struct dwarf_block);
a50b1753 838 blk = (struct dwarf_block *) bfd_alloc (abfd, amt);
8af6b354
AM
839 if (blk == NULL)
840 return NULL;
252b5132
RH
841 blk->size = read_2_bytes (abfd, info_ptr);
842 info_ptr += 2;
843 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
844 info_ptr += blk->size;
482e2e37 845 attr->u.blk = blk;
252b5132
RH
846 break;
847 case DW_FORM_block4:
dc810e39 848 amt = sizeof (struct dwarf_block);
a50b1753 849 blk = (struct dwarf_block *) bfd_alloc (abfd, amt);
8af6b354
AM
850 if (blk == NULL)
851 return NULL;
252b5132
RH
852 blk->size = read_4_bytes (abfd, info_ptr);
853 info_ptr += 4;
854 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
855 info_ptr += blk->size;
482e2e37 856 attr->u.blk = blk;
252b5132
RH
857 break;
858 case DW_FORM_data2:
482e2e37 859 attr->u.val = read_2_bytes (abfd, info_ptr);
252b5132
RH
860 info_ptr += 2;
861 break;
862 case DW_FORM_data4:
482e2e37 863 attr->u.val = read_4_bytes (abfd, info_ptr);
252b5132
RH
864 info_ptr += 4;
865 break;
866 case DW_FORM_data8:
482e2e37 867 attr->u.val = read_8_bytes (abfd, info_ptr);
252b5132
RH
868 info_ptr += 8;
869 break;
870 case DW_FORM_string:
482e2e37 871 attr->u.str = read_string (abfd, info_ptr, &bytes_read);
252b5132
RH
872 info_ptr += bytes_read;
873 break;
d03ba2a1 874 case DW_FORM_strp:
482e2e37 875 attr->u.str = read_indirect_string (unit, info_ptr, &bytes_read);
d03ba2a1
JJ
876 info_ptr += bytes_read;
877 break;
c07cbdd7 878 case DW_FORM_exprloc:
252b5132 879 case DW_FORM_block:
dc810e39 880 amt = sizeof (struct dwarf_block);
a50b1753 881 blk = (struct dwarf_block *) bfd_alloc (abfd, amt);
8af6b354
AM
882 if (blk == NULL)
883 return NULL;
252b5132
RH
884 blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
885 info_ptr += bytes_read;
886 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
887 info_ptr += blk->size;
482e2e37 888 attr->u.blk = blk;
252b5132
RH
889 break;
890 case DW_FORM_block1:
dc810e39 891 amt = sizeof (struct dwarf_block);
a50b1753 892 blk = (struct dwarf_block *) bfd_alloc (abfd, amt);
8af6b354
AM
893 if (blk == NULL)
894 return NULL;
252b5132
RH
895 blk->size = read_1_byte (abfd, info_ptr);
896 info_ptr += 1;
897 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
898 info_ptr += blk->size;
482e2e37 899 attr->u.blk = blk;
252b5132
RH
900 break;
901 case DW_FORM_data1:
482e2e37 902 attr->u.val = read_1_byte (abfd, info_ptr);
252b5132
RH
903 info_ptr += 1;
904 break;
905 case DW_FORM_flag:
482e2e37 906 attr->u.val = read_1_byte (abfd, info_ptr);
252b5132
RH
907 info_ptr += 1;
908 break;
c07cbdd7
JJ
909 case DW_FORM_flag_present:
910 attr->u.val = 1;
911 break;
252b5132 912 case DW_FORM_sdata:
482e2e37 913 attr->u.sval = read_signed_leb128 (abfd, info_ptr, &bytes_read);
252b5132
RH
914 info_ptr += bytes_read;
915 break;
916 case DW_FORM_udata:
482e2e37 917 attr->u.val = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
252b5132
RH
918 info_ptr += bytes_read;
919 break;
920 case DW_FORM_ref1:
482e2e37 921 attr->u.val = read_1_byte (abfd, info_ptr);
252b5132
RH
922 info_ptr += 1;
923 break;
924 case DW_FORM_ref2:
482e2e37 925 attr->u.val = read_2_bytes (abfd, info_ptr);
252b5132
RH
926 info_ptr += 2;
927 break;
928 case DW_FORM_ref4:
482e2e37 929 attr->u.val = read_4_bytes (abfd, info_ptr);
252b5132
RH
930 info_ptr += 4;
931 break;
81edd86d 932 case DW_FORM_ref8:
482e2e37 933 attr->u.val = read_8_bytes (abfd, info_ptr);
81edd86d
MM
934 info_ptr += 8;
935 break;
a37a68dd
CC
936 case DW_FORM_ref_sig8:
937 attr->u.val = read_8_bytes (abfd, info_ptr);
938 info_ptr += 8;
939 break;
252b5132 940 case DW_FORM_ref_udata:
482e2e37 941 attr->u.val = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
252b5132
RH
942 info_ptr += bytes_read;
943 break;
252b5132 944 case DW_FORM_indirect:
cf716c56
RH
945 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
946 info_ptr += bytes_read;
947 info_ptr = read_attribute_value (attr, form, unit, info_ptr);
948 break;
252b5132 949 default:
f46c2da6 950 (*_bfd_error_handler) (_("Dwarf Error: Invalid or unhandled FORM value: %u."),
cf716c56 951 form);
252b5132 952 bfd_set_error (bfd_error_bad_value);
c07cbdd7 953 return NULL;
252b5132
RH
954 }
955 return info_ptr;
956}
957
cf716c56
RH
958/* Read an attribute described by an abbreviated attribute. */
959
f075ee0c 960static bfd_byte *
818a27ac
AM
961read_attribute (struct attribute *attr,
962 struct attr_abbrev *abbrev,
963 struct comp_unit *unit,
f075ee0c 964 bfd_byte *info_ptr)
cf716c56
RH
965{
966 attr->name = abbrev->name;
967 info_ptr = read_attribute_value (attr, abbrev->form, unit, info_ptr);
968 return info_ptr;
969}
970
a092b084 971/* Source line information table routines. */
252b5132
RH
972
973#define FILE_ALLOC_CHUNK 5
974#define DIR_ALLOC_CHUNK 5
975
a092b084
NC
976struct line_info
977{
252b5132 978 struct line_info* prev_line;
252b5132 979 bfd_vma address;
f075ee0c 980 char *filename;
252b5132
RH
981 unsigned int line;
982 unsigned int column;
9b8d1a36 983 unsigned int discriminator;
a233b20c
JJ
984 unsigned char op_index;
985 unsigned char end_sequence; /* End of (sequential) code sequence. */
252b5132
RH
986};
987
a092b084
NC
988struct fileinfo
989{
252b5132
RH
990 char *name;
991 unsigned int dir;
992 unsigned int time;
993 unsigned int size;
994};
995
0ee19663
NC
996struct line_sequence
997{
998 bfd_vma low_pc;
999 struct line_sequence* prev_sequence;
1000 struct line_info* last_line; /* Largest VMA. */
1001};
1002
a092b084
NC
1003struct line_info_table
1004{
0ee19663
NC
1005 bfd* abfd;
1006 unsigned int num_files;
1007 unsigned int num_dirs;
1008 unsigned int num_sequences;
1009 char * comp_dir;
1010 char ** dirs;
1011 struct fileinfo* files;
1012 struct line_sequence* sequences;
1013 struct line_info* lcl_head; /* Local head; used in 'add_line_info'. */
252b5132
RH
1014};
1015
4ab527b0
FF
1016/* Remember some information about each function. If the function is
1017 inlined (DW_TAG_inlined_subroutine) it may have two additional
1018 attributes, DW_AT_call_file and DW_AT_call_line, which specify the
a2a50954 1019 source code location where this function was inlined. */
4ab527b0 1020
1ee24f27
DJ
1021struct funcinfo
1022{
a2a50954
AM
1023 /* Pointer to previous function in list of all functions. */
1024 struct funcinfo *prev_func;
1025 /* Pointer to function one scope higher. */
1026 struct funcinfo *caller_func;
1027 /* Source location file name where caller_func inlines this func. */
1028 char *caller_file;
1029 /* Source location line number where caller_func inlines this func. */
1030 int caller_line;
1031 /* Source location file name. */
1032 char *file;
1033 /* Source location line number. */
1034 int line;
4ab527b0 1035 int tag;
f075ee0c 1036 char *name;
a13afe8e 1037 struct arange arange;
a2a50954
AM
1038 /* Where the symbol is defined. */
1039 asection *sec;
5420f73d
L
1040};
1041
1042struct varinfo
1043{
709d67f1 1044 /* Pointer to previous variable in list of all variables */
5420f73d 1045 struct varinfo *prev_var;
709d67f1 1046 /* Source location file name */
5420f73d 1047 char *file;
709d67f1 1048 /* Source location line number */
5420f73d
L
1049 int line;
1050 int tag;
1051 char *name;
5cf2e3f0 1052 bfd_vma addr;
709d67f1 1053 /* Where the symbol is defined */
5420f73d 1054 asection *sec;
709d67f1 1055 /* Is this a stack variable? */
5420f73d 1056 unsigned int stack: 1;
1ee24f27
DJ
1057};
1058
d4c32a81
L
1059/* Return TRUE if NEW_LINE should sort after LINE. */
1060
1061static inline bfd_boolean
1062new_line_sorts_after (struct line_info *new_line, struct line_info *line)
1063{
1064 return (new_line->address > line->address
1065 || (new_line->address == line->address
a233b20c
JJ
1066 && (new_line->op_index > line->op_index
1067 || (new_line->op_index == line->op_index
1068 && new_line->end_sequence < line->end_sequence))));
d4c32a81
L
1069}
1070
1071
af3ef9fe
NC
1072/* Adds a new entry to the line_info list in the line_info_table, ensuring
1073 that the list is sorted. Note that the line_info list is sorted from
1074 highest to lowest VMA (with possible duplicates); that is,
1075 line_info->prev_line always accesses an equal or smaller VMA. */
1076
8af6b354 1077static bfd_boolean
818a27ac
AM
1078add_line_info (struct line_info_table *table,
1079 bfd_vma address,
a233b20c 1080 unsigned char op_index,
818a27ac
AM
1081 char *filename,
1082 unsigned int line,
1083 unsigned int column,
9b8d1a36 1084 unsigned int discriminator,
818a27ac 1085 int end_sequence)
252b5132 1086{
dc810e39 1087 bfd_size_type amt = sizeof (struct line_info);
0ee19663 1088 struct line_sequence* seq = table->sequences;
a50b1753 1089 struct line_info* info = (struct line_info *) bfd_alloc (table->abfd, amt);
252b5132 1090
8af6b354
AM
1091 if (info == NULL)
1092 return FALSE;
1093
d4c32a81 1094 /* Set member data of 'info'. */
f5296ddc 1095 info->prev_line = NULL;
d4c32a81 1096 info->address = address;
a233b20c 1097 info->op_index = op_index;
d4c32a81
L
1098 info->line = line;
1099 info->column = column;
9b8d1a36 1100 info->discriminator = discriminator;
d4c32a81
L
1101 info->end_sequence = end_sequence;
1102
1103 if (filename && filename[0])
1104 {
a50b1753 1105 info->filename = (char *) bfd_alloc (table->abfd, strlen (filename) + 1);
8af6b354
AM
1106 if (info->filename == NULL)
1107 return FALSE;
1108 strcpy (info->filename, filename);
d4c32a81
L
1109 }
1110 else
1111 info->filename = NULL;
1112
e82ce529
AM
1113 /* Find the correct location for 'info'. Normally we will receive
1114 new line_info data 1) in order and 2) with increasing VMAs.
1115 However some compilers break the rules (cf. decode_line_info) and
1116 so we include some heuristics for quickly finding the correct
1117 location for 'info'. In particular, these heuristics optimize for
1118 the common case in which the VMA sequence that we receive is a
1119 list of locally sorted VMAs such as
1120 p...z a...j (where a < j < p < z)
252b5132 1121
e82ce529 1122 Note: table->lcl_head is used to head an *actual* or *possible*
0ee19663 1123 sub-sequence within the list (such as a...j) that is not directly
e82ce529
AM
1124 headed by table->last_line
1125
1126 Note: we may receive duplicate entries from 'decode_line_info'. */
1127
0ee19663
NC
1128 if (seq
1129 && seq->last_line->address == address
a233b20c 1130 && seq->last_line->op_index == op_index
0ee19663 1131 && seq->last_line->end_sequence == end_sequence)
aff90a5f
L
1132 {
1133 /* We only keep the last entry with the same address and end
1134 sequence. See PR ld/4986. */
0ee19663 1135 if (table->lcl_head == seq->last_line)
aff90a5f 1136 table->lcl_head = info;
0ee19663
NC
1137 info->prev_line = seq->last_line->prev_line;
1138 seq->last_line = info;
aff90a5f 1139 }
0ee19663 1140 else if (!seq || seq->last_line->end_sequence)
d8d1c398 1141 {
0ee19663
NC
1142 /* Start a new line sequence. */
1143 amt = sizeof (struct line_sequence);
1144 seq = (struct line_sequence *) bfd_malloc (amt);
8af6b354
AM
1145 if (seq == NULL)
1146 return FALSE;
0ee19663
NC
1147 seq->low_pc = address;
1148 seq->prev_sequence = table->sequences;
1149 seq->last_line = info;
1150 table->lcl_head = info;
1151 table->sequences = seq;
1152 table->num_sequences++;
1153 }
1154 else if (new_line_sorts_after (info, seq->last_line))
1155 {
1156 /* Normal case: add 'info' to the beginning of the current sequence. */
1157 info->prev_line = seq->last_line;
1158 seq->last_line = info;
e82ce529 1159
d8d1c398
AM
1160 /* lcl_head: initialize to head a *possible* sequence at the end. */
1161 if (!table->lcl_head)
1162 table->lcl_head = info;
1163 }
1164 else if (!new_line_sorts_after (info, table->lcl_head)
1165 && (!table->lcl_head->prev_line
1166 || new_line_sorts_after (info, table->lcl_head->prev_line)))
1167 {
1168 /* Abnormal but easy: lcl_head is the head of 'info'. */
1169 info->prev_line = table->lcl_head->prev_line;
1170 table->lcl_head->prev_line = info;
1171 }
1172 else
1173 {
0ee19663
NC
1174 /* Abnormal and hard: Neither 'last_line' nor 'lcl_head'
1175 are valid heads for 'info'. Reset 'lcl_head'. */
1176 struct line_info* li2 = seq->last_line; /* Always non-NULL. */
d8d1c398 1177 struct line_info* li1 = li2->prev_line;
e82ce529 1178
d8d1c398
AM
1179 while (li1)
1180 {
1181 if (!new_line_sorts_after (info, li2)
1182 && new_line_sorts_after (info, li1))
1183 break;
e82ce529 1184
709d67f1 1185 li2 = li1; /* always non-NULL */
d8d1c398
AM
1186 li1 = li1->prev_line;
1187 }
1188 table->lcl_head = li2;
1189 info->prev_line = table->lcl_head->prev_line;
1190 table->lcl_head->prev_line = info;
0ee19663
NC
1191 if (address < seq->low_pc)
1192 seq->low_pc = address;
d8d1c398 1193 }
8af6b354 1194 return TRUE;
252b5132
RH
1195}
1196
5ed6aba4 1197/* Extract a fully qualified filename from a line info table.
af3ef9fe
NC
1198 The returned string has been malloc'ed and it is the caller's
1199 responsibility to free it. */
5ed6aba4 1200
a092b084 1201static char *
818a27ac 1202concat_filename (struct line_info_table *table, unsigned int file)
252b5132 1203{
f075ee0c 1204 char *filename;
159002ff
RH
1205
1206 if (file - 1 >= table->num_files)
1207 {
75a657ba
L
1208 /* FILE == 0 means unknown. */
1209 if (file)
1210 (*_bfd_error_handler)
1211 (_("Dwarf Error: mangled line number section (bad file number)."));
af3ef9fe 1212 return strdup ("<unknown>");
159002ff
RH
1213 }
1214
1215 filename = table->files[file - 1].name;
5ed6aba4 1216
7421a730 1217 if (!IS_ABSOLUTE_PATH (filename))
252b5132 1218 {
608fa8d3
JB
1219 char *dir_name = NULL;
1220 char *subdir_name = NULL;
7421a730
AM
1221 char *name;
1222 size_t len;
0dafd5f6 1223
7421a730 1224 if (table->files[file - 1].dir)
608fa8d3 1225 subdir_name = table->dirs[table->files[file - 1].dir - 1];
7421a730 1226
608fa8d3
JB
1227 if (!subdir_name || !IS_ABSOLUTE_PATH (subdir_name))
1228 dir_name = table->comp_dir;
7421a730 1229
608fa8d3 1230 if (!dir_name)
af3ef9fe 1231 {
608fa8d3
JB
1232 dir_name = subdir_name;
1233 subdir_name = NULL;
7421a730 1234 }
af3ef9fe 1235
608fa8d3 1236 if (!dir_name)
7421a730
AM
1237 return strdup (filename);
1238
608fa8d3 1239 len = strlen (dir_name) + strlen (filename) + 2;
7421a730 1240
608fa8d3 1241 if (subdir_name)
7421a730 1242 {
608fa8d3 1243 len += strlen (subdir_name) + 1;
a50b1753 1244 name = (char *) bfd_malloc (len);
7421a730 1245 if (name)
608fa8d3 1246 sprintf (name, "%s/%s/%s", dir_name, subdir_name, filename);
7421a730
AM
1247 }
1248 else
1249 {
a50b1753 1250 name = (char *) bfd_malloc (len);
af3ef9fe 1251 if (name)
608fa8d3 1252 sprintf (name, "%s/%s", dir_name, filename);
af3ef9fe 1253 }
7421a730
AM
1254
1255 return name;
252b5132 1256 }
af3ef9fe
NC
1257
1258 return strdup (filename);
252b5132
RH
1259}
1260
8af6b354 1261static bfd_boolean
a2a50954 1262arange_add (const struct comp_unit *unit, struct arange *first_arange,
8af6b354 1263 bfd_vma low_pc, bfd_vma high_pc)
f623be2b
RH
1264{
1265 struct arange *arange;
1266
a2a50954
AM
1267 /* Ignore empty ranges. */
1268 if (low_pc == high_pc)
1269 return TRUE;
1270
1271 /* If the first arange is empty, use it. */
a13afe8e
FF
1272 if (first_arange->high == 0)
1273 {
1274 first_arange->low = low_pc;
1275 first_arange->high = high_pc;
8af6b354 1276 return TRUE;
a13afe8e 1277 }
98591c73 1278
a13afe8e
FF
1279 /* Next see if we can cheaply extend an existing range. */
1280 arange = first_arange;
f623be2b
RH
1281 do
1282 {
1283 if (low_pc == arange->high)
1284 {
1285 arange->high = high_pc;
8af6b354 1286 return TRUE;
f623be2b
RH
1287 }
1288 if (high_pc == arange->low)
1289 {
1290 arange->low = low_pc;
8af6b354 1291 return TRUE;
f623be2b
RH
1292 }
1293 arange = arange->next;
1294 }
1295 while (arange);
1296
a13afe8e 1297 /* Need to allocate a new arange and insert it into the arange list.
709d67f1 1298 Order isn't significant, so just insert after the first arange. */
a2a50954 1299 arange = (struct arange *) bfd_alloc (unit->abfd, sizeof (*arange));
8af6b354
AM
1300 if (arange == NULL)
1301 return FALSE;
f623be2b
RH
1302 arange->low = low_pc;
1303 arange->high = high_pc;
a13afe8e
FF
1304 arange->next = first_arange->next;
1305 first_arange->next = arange;
8af6b354 1306 return TRUE;
f623be2b
RH
1307}
1308
0ee19663
NC
1309/* Compare function for line sequences. */
1310
1311static int
1312compare_sequences (const void* a, const void* b)
1313{
1314 const struct line_sequence* seq1 = a;
1315 const struct line_sequence* seq2 = b;
1316
1317 /* Sort by low_pc as the primary key. */
1318 if (seq1->low_pc < seq2->low_pc)
1319 return -1;
1320 if (seq1->low_pc > seq2->low_pc)
1321 return 1;
1322
1323 /* If low_pc values are equal, sort in reverse order of
1324 high_pc, so that the largest region comes first. */
1325 if (seq1->last_line->address < seq2->last_line->address)
1326 return 1;
1327 if (seq1->last_line->address > seq2->last_line->address)
1328 return -1;
1329
a233b20c
JJ
1330 if (seq1->last_line->op_index < seq2->last_line->op_index)
1331 return 1;
1332 if (seq1->last_line->op_index > seq2->last_line->op_index)
1333 return -1;
1334
0ee19663
NC
1335 return 0;
1336}
1337
1338/* Sort the line sequences for quick lookup. */
1339
8af6b354 1340static bfd_boolean
0ee19663
NC
1341sort_line_sequences (struct line_info_table* table)
1342{
1343 bfd_size_type amt;
1344 struct line_sequence* sequences;
1345 struct line_sequence* seq;
1346 unsigned int n = 0;
1347 unsigned int num_sequences = table->num_sequences;
1348 bfd_vma last_high_pc;
1349
1350 if (num_sequences == 0)
8af6b354 1351 return TRUE;
0ee19663
NC
1352
1353 /* Allocate space for an array of sequences. */
1354 amt = sizeof (struct line_sequence) * num_sequences;
1355 sequences = (struct line_sequence *) bfd_alloc (table->abfd, amt);
8af6b354
AM
1356 if (sequences == NULL)
1357 return FALSE;
0ee19663
NC
1358
1359 /* Copy the linked list into the array, freeing the original nodes. */
1360 seq = table->sequences;
1361 for (n = 0; n < num_sequences; n++)
1362 {
1363 struct line_sequence* last_seq = seq;
1364
1365 BFD_ASSERT (seq);
1366 sequences[n].low_pc = seq->low_pc;
1367 sequences[n].prev_sequence = NULL;
1368 sequences[n].last_line = seq->last_line;
1369 seq = seq->prev_sequence;
1370 free (last_seq);
1371 }
1372 BFD_ASSERT (seq == NULL);
1373
1374 qsort (sequences, n, sizeof (struct line_sequence), compare_sequences);
1375
1376 /* Make the list binary-searchable by trimming overlapping entries
1377 and removing nested entries. */
1378 num_sequences = 1;
1379 last_high_pc = sequences[0].last_line->address;
1380 for (n = 1; n < table->num_sequences; n++)
1381 {
1382 if (sequences[n].low_pc < last_high_pc)
1383 {
1384 if (sequences[n].last_line->address <= last_high_pc)
1385 /* Skip nested entries. */
1386 continue;
1387
1388 /* Trim overlapping entries. */
1389 sequences[n].low_pc = last_high_pc;
1390 }
1391 last_high_pc = sequences[n].last_line->address;
1392 if (n > num_sequences)
1393 {
1394 /* Close up the gap. */
1395 sequences[num_sequences].low_pc = sequences[n].low_pc;
1396 sequences[num_sequences].last_line = sequences[n].last_line;
1397 }
1398 num_sequences++;
1399 }
1400
1401 table->sequences = sequences;
1402 table->num_sequences = num_sequences;
8af6b354 1403 return TRUE;
0ee19663
NC
1404}
1405
34b5e0b2 1406/* Decode the line number information for UNIT. */
252b5132 1407
34b5e0b2 1408static struct line_info_table*
818a27ac 1409decode_line_info (struct comp_unit *unit, struct dwarf2_debug *stash)
252b5132
RH
1410{
1411 bfd *abfd = unit->abfd;
252b5132 1412 struct line_info_table* table;
f075ee0c
AM
1413 bfd_byte *line_ptr;
1414 bfd_byte *line_end;
252b5132 1415 struct line_head lh;
d03ba2a1 1416 unsigned int i, bytes_read, offset_size;
252b5132
RH
1417 char *cur_file, *cur_dir;
1418 unsigned char op_code, extended_op, adj_opcode;
fec16237 1419 unsigned int exop_len;
dc810e39 1420 bfd_size_type amt;
252b5132 1421
fc28f9aa
TG
1422 if (! read_section (abfd, &stash->debug_sections[debug_line],
1423 stash->syms, unit->line_offset,
9e32b19f 1424 &stash->dwarf_line_buffer, &stash->dwarf_line_size))
8af6b354 1425 return NULL;
ccdb16fc 1426
dc810e39 1427 amt = sizeof (struct line_info_table);
a50b1753 1428 table = (struct line_info_table *) bfd_alloc (abfd, amt);
8af6b354
AM
1429 if (table == NULL)
1430 return NULL;
252b5132
RH
1431 table->abfd = abfd;
1432 table->comp_dir = unit->comp_dir;
1433
1434 table->num_files = 0;
1435 table->files = NULL;
1436
1437 table->num_dirs = 0;
1438 table->dirs = NULL;
1439
0ee19663
NC
1440 table->num_sequences = 0;
1441 table->sequences = NULL;
1442
e82ce529 1443 table->lcl_head = NULL;
159002ff 1444
69dd2e2d 1445 line_ptr = stash->dwarf_line_buffer + unit->line_offset;
252b5132 1446
a092b084 1447 /* Read in the prologue. */
91a4d569
AM
1448 lh.total_length = read_4_bytes (abfd, line_ptr);
1449 line_ptr += 4;
1450 offset_size = 4;
1451 if (lh.total_length == 0xffffffff)
dae2dd0d 1452 {
dae2dd0d
NC
1453 lh.total_length = read_8_bytes (abfd, line_ptr);
1454 line_ptr += 8;
1455 offset_size = 8;
1456 }
91a4d569 1457 else if (lh.total_length == 0 && unit->addr_size == 8)
d03ba2a1 1458 {
91a4d569
AM
1459 /* Handle (non-standard) 64-bit DWARF2 formats. */
1460 lh.total_length = read_4_bytes (abfd, line_ptr);
1461 line_ptr += 4;
d03ba2a1
JJ
1462 offset_size = 8;
1463 }
252b5132
RH
1464 line_end = line_ptr + lh.total_length;
1465 lh.version = read_2_bytes (abfd, line_ptr);
a233b20c
JJ
1466 if (lh.version < 2 || lh.version > 4)
1467 {
1468 (*_bfd_error_handler)
1469 (_("Dwarf Error: Unhandled .debug_line version %d."), lh.version);
1470 bfd_set_error (bfd_error_bad_value);
1471 return NULL;
1472 }
252b5132 1473 line_ptr += 2;
d03ba2a1
JJ
1474 if (offset_size == 4)
1475 lh.prologue_length = read_4_bytes (abfd, line_ptr);
1476 else
1477 lh.prologue_length = read_8_bytes (abfd, line_ptr);
1478 line_ptr += offset_size;
252b5132
RH
1479 lh.minimum_instruction_length = read_1_byte (abfd, line_ptr);
1480 line_ptr += 1;
a233b20c
JJ
1481 if (lh.version >= 4)
1482 {
1483 lh.maximum_ops_per_insn = read_1_byte (abfd, line_ptr);
1484 line_ptr += 1;
1485 }
1486 else
1487 lh.maximum_ops_per_insn = 1;
1488 if (lh.maximum_ops_per_insn == 0)
1489 {
1490 (*_bfd_error_handler)
1491 (_("Dwarf Error: Invalid maximum operations per instruction."));
1492 bfd_set_error (bfd_error_bad_value);
1493 return NULL;
1494 }
252b5132
RH
1495 lh.default_is_stmt = read_1_byte (abfd, line_ptr);
1496 line_ptr += 1;
1497 lh.line_base = read_1_signed_byte (abfd, line_ptr);
1498 line_ptr += 1;
1499 lh.line_range = read_1_byte (abfd, line_ptr);
1500 line_ptr += 1;
1501 lh.opcode_base = read_1_byte (abfd, line_ptr);
1502 line_ptr += 1;
dc810e39 1503 amt = lh.opcode_base * sizeof (unsigned char);
a50b1753 1504 lh.standard_opcode_lengths = (unsigned char *) bfd_alloc (abfd, amt);
252b5132
RH
1505
1506 lh.standard_opcode_lengths[0] = 1;
98591c73 1507
252b5132
RH
1508 for (i = 1; i < lh.opcode_base; ++i)
1509 {
1510 lh.standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr);
1511 line_ptr += 1;
1512 }
1513
a092b084 1514 /* Read directory table. */
252b5132
RH
1515 while ((cur_dir = read_string (abfd, line_ptr, &bytes_read)) != NULL)
1516 {
1517 line_ptr += bytes_read;
98591c73 1518
252b5132
RH
1519 if ((table->num_dirs % DIR_ALLOC_CHUNK) == 0)
1520 {
35330cce
NC
1521 char **tmp;
1522
dc810e39
AM
1523 amt = table->num_dirs + DIR_ALLOC_CHUNK;
1524 amt *= sizeof (char *);
35330cce 1525
a50b1753 1526 tmp = (char **) bfd_realloc (table->dirs, amt);
35330cce 1527 if (tmp == NULL)
8af6b354 1528 goto fail;
35330cce 1529 table->dirs = tmp;
252b5132 1530 }
98591c73 1531
252b5132
RH
1532 table->dirs[table->num_dirs++] = cur_dir;
1533 }
98591c73 1534
252b5132
RH
1535 line_ptr += bytes_read;
1536
a092b084 1537 /* Read file name table. */
252b5132
RH
1538 while ((cur_file = read_string (abfd, line_ptr, &bytes_read)) != NULL)
1539 {
1540 line_ptr += bytes_read;
98591c73 1541
252b5132
RH
1542 if ((table->num_files % FILE_ALLOC_CHUNK) == 0)
1543 {
35330cce
NC
1544 struct fileinfo *tmp;
1545
dc810e39
AM
1546 amt = table->num_files + FILE_ALLOC_CHUNK;
1547 amt *= sizeof (struct fileinfo);
35330cce 1548
a50b1753 1549 tmp = (struct fileinfo *) bfd_realloc (table->files, amt);
35330cce 1550 if (tmp == NULL)
8af6b354 1551 goto fail;
35330cce 1552 table->files = tmp;
252b5132 1553 }
98591c73 1554
252b5132
RH
1555 table->files[table->num_files].name = cur_file;
1556 table->files[table->num_files].dir =
1557 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
1558 line_ptr += bytes_read;
1559 table->files[table->num_files].time =
1560 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
1561 line_ptr += bytes_read;
1562 table->files[table->num_files].size =
1563 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
1564 line_ptr += bytes_read;
1565 table->num_files++;
1566 }
98591c73 1567
252b5132
RH
1568 line_ptr += bytes_read;
1569
1570 /* Read the statement sequences until there's nothing left. */
1571 while (line_ptr < line_end)
1572 {
a092b084 1573 /* State machine registers. */
252b5132 1574 bfd_vma address = 0;
a233b20c 1575 unsigned char op_index = 0;
8bfd78b3 1576 char * filename = table->num_files ? concat_filename (table, 1) : NULL;
252b5132
RH
1577 unsigned int line = 1;
1578 unsigned int column = 0;
9b8d1a36 1579 unsigned int discriminator = 0;
252b5132 1580 int is_stmt = lh.default_is_stmt;
e2f6d277
NC
1581 int end_sequence = 0;
1582 /* eraxxon@alumni.rice.edu: Against the DWARF2 specs, some
e82ce529
AM
1583 compilers generate address sequences that are wildly out of
1584 order using DW_LNE_set_address (e.g. Intel C++ 6.0 compiler
1585 for ia64-Linux). Thus, to determine the low and high
1586 address, we must compare on every DW_LNS_copy, etc. */
75758e9d 1587 bfd_vma low_pc = (bfd_vma) -1;
e2f6d277 1588 bfd_vma high_pc = 0;
252b5132 1589
a092b084 1590 /* Decode the table. */
252b5132
RH
1591 while (! end_sequence)
1592 {
1593 op_code = read_1_byte (abfd, line_ptr);
1594 line_ptr += 1;
98591c73 1595
1a509dcc 1596 if (op_code >= lh.opcode_base)
e2f6d277
NC
1597 {
1598 /* Special operand. */
1a509dcc 1599 adj_opcode = op_code - lh.opcode_base;
a233b20c 1600 if (lh.maximum_ops_per_insn == 1)
a2a50954
AM
1601 address += (adj_opcode / lh.line_range
1602 * lh.minimum_instruction_length);
a233b20c
JJ
1603 else
1604 {
a2a50954
AM
1605 address += ((op_index + adj_opcode / lh.line_range)
1606 / lh.maximum_ops_per_insn
1607 * lh.minimum_instruction_length);
1608 op_index = ((op_index + adj_opcode / lh.line_range)
1609 % lh.maximum_ops_per_insn);
a233b20c 1610 }
1a509dcc
GK
1611 line += lh.line_base + (adj_opcode % lh.line_range);
1612 /* Append row to matrix using current values. */
a233b20c 1613 if (!add_line_info (table, address, op_index, filename,
9b8d1a36 1614 line, column, discriminator, 0))
8af6b354 1615 goto line_fail;
9b8d1a36 1616 discriminator = 0;
75758e9d
AM
1617 if (address < low_pc)
1618 low_pc = address;
e2f6d277
NC
1619 if (address > high_pc)
1620 high_pc = address;
1a509dcc
GK
1621 }
1622 else switch (op_code)
252b5132
RH
1623 {
1624 case DW_LNS_extended_op:
a2a50954 1625 exop_len = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
fec16237 1626 line_ptr += bytes_read;
252b5132
RH
1627 extended_op = read_1_byte (abfd, line_ptr);
1628 line_ptr += 1;
e2f6d277 1629
252b5132
RH
1630 switch (extended_op)
1631 {
1632 case DW_LNE_end_sequence:
1633 end_sequence = 1;
9b8d1a36
CC
1634 if (!add_line_info (table, address, op_index, filename, line,
1635 column, discriminator, end_sequence))
8af6b354 1636 goto line_fail;
9b8d1a36 1637 discriminator = 0;
75758e9d
AM
1638 if (address < low_pc)
1639 low_pc = address;
e2f6d277
NC
1640 if (address > high_pc)
1641 high_pc = address;
a2a50954 1642 if (!arange_add (unit, &unit->arange, low_pc, high_pc))
8af6b354 1643 goto line_fail;
252b5132
RH
1644 break;
1645 case DW_LNE_set_address:
1646 address = read_address (unit, line_ptr);
a233b20c 1647 op_index = 0;
252b5132
RH
1648 line_ptr += unit->addr_size;
1649 break;
1650 case DW_LNE_define_file:
1651 cur_file = read_string (abfd, line_ptr, &bytes_read);
1652 line_ptr += bytes_read;
1653 if ((table->num_files % FILE_ALLOC_CHUNK) == 0)
1654 {
35330cce
NC
1655 struct fileinfo *tmp;
1656
dc810e39
AM
1657 amt = table->num_files + FILE_ALLOC_CHUNK;
1658 amt *= sizeof (struct fileinfo);
a50b1753 1659 tmp = (struct fileinfo *) bfd_realloc (table->files, amt);
35330cce 1660 if (tmp == NULL)
8af6b354 1661 goto line_fail;
35330cce 1662 table->files = tmp;
252b5132
RH
1663 }
1664 table->files[table->num_files].name = cur_file;
1665 table->files[table->num_files].dir =
1666 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
1667 line_ptr += bytes_read;
1668 table->files[table->num_files].time =
1669 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
1670 line_ptr += bytes_read;
1671 table->files[table->num_files].size =
1672 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
1673 line_ptr += bytes_read;
1674 table->num_files++;
1675 break;
9e1f7c0e 1676 case DW_LNE_set_discriminator:
9b8d1a36
CC
1677 discriminator =
1678 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
9e1f7c0e
DK
1679 line_ptr += bytes_read;
1680 break;
a2a50954
AM
1681 case DW_LNE_HP_source_file_correlation:
1682 line_ptr += exop_len - 1;
1683 break;
252b5132 1684 default:
a2a50954
AM
1685 (*_bfd_error_handler)
1686 (_("Dwarf Error: mangled line number section."));
252b5132 1687 bfd_set_error (bfd_error_bad_value);
8af6b354
AM
1688 line_fail:
1689 if (filename != NULL)
1690 free (filename);
1691 goto fail;
252b5132
RH
1692 }
1693 break;
1694 case DW_LNS_copy:
a233b20c 1695 if (!add_line_info (table, address, op_index,
9b8d1a36 1696 filename, line, column, discriminator, 0))
8af6b354 1697 goto line_fail;
9b8d1a36 1698 discriminator = 0;
75758e9d
AM
1699 if (address < low_pc)
1700 low_pc = address;
e2f6d277
NC
1701 if (address > high_pc)
1702 high_pc = address;
252b5132
RH
1703 break;
1704 case DW_LNS_advance_pc:
a233b20c 1705 if (lh.maximum_ops_per_insn == 1)
a2a50954
AM
1706 address += (lh.minimum_instruction_length
1707 * read_unsigned_leb128 (abfd, line_ptr,
1708 &bytes_read));
a233b20c
JJ
1709 else
1710 {
1711 bfd_vma adjust = read_unsigned_leb128 (abfd, line_ptr,
1712 &bytes_read);
a2a50954
AM
1713 address = ((op_index + adjust) / lh.maximum_ops_per_insn
1714 * lh.minimum_instruction_length);
a233b20c
JJ
1715 op_index = (op_index + adjust) % lh.maximum_ops_per_insn;
1716 }
252b5132
RH
1717 line_ptr += bytes_read;
1718 break;
1719 case DW_LNS_advance_line:
1720 line += read_signed_leb128 (abfd, line_ptr, &bytes_read);
1721 line_ptr += bytes_read;
1722 break;
1723 case DW_LNS_set_file:
1724 {
1725 unsigned int file;
1726
e2f6d277
NC
1727 /* The file and directory tables are 0
1728 based, the references are 1 based. */
252b5132
RH
1729 file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
1730 line_ptr += bytes_read;
af3ef9fe
NC
1731 if (filename)
1732 free (filename);
252b5132
RH
1733 filename = concat_filename (table, file);
1734 break;
1735 }
1736 case DW_LNS_set_column:
1737 column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
1738 line_ptr += bytes_read;
1739 break;
1740 case DW_LNS_negate_stmt:
1741 is_stmt = (!is_stmt);
1742 break;
1743 case DW_LNS_set_basic_block:
252b5132
RH
1744 break;
1745 case DW_LNS_const_add_pc:
a233b20c 1746 if (lh.maximum_ops_per_insn == 1)
a2a50954
AM
1747 address += (lh.minimum_instruction_length
1748 * ((255 - lh.opcode_base) / lh.line_range));
a233b20c
JJ
1749 else
1750 {
1751 bfd_vma adjust = ((255 - lh.opcode_base) / lh.line_range);
a2a50954
AM
1752 address += (lh.minimum_instruction_length
1753 * ((op_index + adjust)
1754 / lh.maximum_ops_per_insn));
a233b20c
JJ
1755 op_index = (op_index + adjust) % lh.maximum_ops_per_insn;
1756 }
252b5132
RH
1757 break;
1758 case DW_LNS_fixed_advance_pc:
1759 address += read_2_bytes (abfd, line_ptr);
a233b20c 1760 op_index = 0;
252b5132
RH
1761 line_ptr += 2;
1762 break;
1a509dcc 1763 default:
91d6fa6a
NC
1764 /* Unknown standard opcode, ignore it. */
1765 for (i = 0; i < lh.standard_opcode_lengths[op_code]; i++)
1766 {
1767 (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
1768 line_ptr += bytes_read;
1769 }
1770 break;
252b5132
RH
1771 }
1772 }
5ed6aba4 1773
af3ef9fe
NC
1774 if (filename)
1775 free (filename);
252b5132
RH
1776 }
1777
8af6b354
AM
1778 if (sort_line_sequences (table))
1779 return table;
0ee19663 1780
8af6b354
AM
1781 fail:
1782 if (table->sequences != NULL)
1783 free (table->sequences);
1784 if (table->files != NULL)
1785 free (table->files);
1786 if (table->dirs != NULL)
1787 free (table->dirs);
1788 return NULL;
252b5132
RH
1789}
1790
b34976b6
AM
1791/* If ADDR is within TABLE set the output parameters and return TRUE,
1792 otherwise return FALSE. The output parameters, FILENAME_PTR and
a092b084 1793 LINENUMBER_PTR, are pointers to the objects to be filled in. */
252b5132 1794
b34976b6 1795static bfd_boolean
818a27ac
AM
1796lookup_address_in_line_info_table (struct line_info_table *table,
1797 bfd_vma addr,
818a27ac 1798 const char **filename_ptr,
9b8d1a36
CC
1799 unsigned int *linenumber_ptr,
1800 unsigned int *discriminator_ptr)
252b5132 1801{
0ee19663 1802 struct line_sequence *seq = NULL;
107601c8 1803 struct line_info *each_line;
0ee19663 1804 int low, high, mid;
e82ce529 1805
0ee19663
NC
1806 /* Binary search the array of sequences. */
1807 low = 0;
1808 high = table->num_sequences;
1809 while (low < high)
1810 {
1811 mid = (low + high) / 2;
1812 seq = &table->sequences[mid];
1813 if (addr < seq->low_pc)
1814 high = mid;
1815 else if (addr >= seq->last_line->address)
1816 low = mid + 1;
1817 else
1818 break;
1819 }
98591c73 1820
0ee19663 1821 if (seq && addr >= seq->low_pc && addr < seq->last_line->address)
1ee24f27 1822 {
0ee19663
NC
1823 /* Note: seq->last_line should be a descendingly sorted list. */
1824 for (each_line = seq->last_line;
1825 each_line;
1826 each_line = each_line->prev_line)
1827 if (addr >= each_line->address)
1828 break;
1829
1830 if (each_line
1831 && !(each_line->end_sequence || each_line == seq->last_line))
1832 {
1833 *filename_ptr = each_line->filename;
1834 *linenumber_ptr = each_line->line;
9b8d1a36
CC
1835 if (discriminator_ptr)
1836 *discriminator_ptr = each_line->discriminator;
0ee19663
NC
1837 return TRUE;
1838 }
1ee24f27
DJ
1839 }
1840
107601c8 1841 *filename_ptr = NULL;
b34976b6 1842 return FALSE;
252b5132 1843}
98591c73 1844
0ee19663 1845/* Read in the .debug_ranges section for future reference. */
a13afe8e
FF
1846
1847static bfd_boolean
1848read_debug_ranges (struct comp_unit *unit)
1849{
1850 struct dwarf2_debug *stash = unit->stash;
fc28f9aa
TG
1851 return read_section (unit->abfd, &stash->debug_sections[debug_ranges],
1852 stash->syms, 0,
9e32b19f 1853 &stash->dwarf_ranges_buffer, &stash->dwarf_ranges_size);
a13afe8e
FF
1854}
1855
a092b084 1856/* Function table functions. */
252b5132 1857
a13afe8e
FF
1858/* If ADDR is within TABLE, set FUNCTIONNAME_PTR, and return TRUE.
1859 Note that we need to find the function that has the smallest
1860 range that contains ADDR, to handle inlined functions without
1861 depending upon them being ordered in TABLE by increasing range. */
252b5132 1862
b34976b6 1863static bfd_boolean
4ab527b0 1864lookup_address_in_function_table (struct comp_unit *unit,
818a27ac
AM
1865 bfd_vma addr,
1866 struct funcinfo **function_ptr,
1867 const char **functionname_ptr)
252b5132
RH
1868{
1869 struct funcinfo* each_func;
a13afe8e
FF
1870 struct funcinfo* best_fit = NULL;
1871 struct arange *arange;
252b5132 1872
4ab527b0 1873 for (each_func = unit->function_table;
252b5132
RH
1874 each_func;
1875 each_func = each_func->prev_func)
1876 {
a13afe8e
FF
1877 for (arange = &each_func->arange;
1878 arange;
1879 arange = arange->next)
252b5132 1880 {
a13afe8e
FF
1881 if (addr >= arange->low && addr < arange->high)
1882 {
a2a50954
AM
1883 if (!best_fit
1884 || (arange->high - arange->low
1885 < best_fit->arange.high - best_fit->arange.low))
a13afe8e
FF
1886 best_fit = each_func;
1887 }
252b5132
RH
1888 }
1889 }
98591c73 1890
a13afe8e
FF
1891 if (best_fit)
1892 {
1893 *functionname_ptr = best_fit->name;
1894 *function_ptr = best_fit;
1895 return TRUE;
1896 }
1897 else
1898 {
1899 return FALSE;
1900 }
252b5132
RH
1901}
1902
5420f73d
L
1903/* If SYM at ADDR is within function table of UNIT, set FILENAME_PTR
1904 and LINENUMBER_PTR, and return TRUE. */
1905
1906static bfd_boolean
1907lookup_symbol_in_function_table (struct comp_unit *unit,
1908 asymbol *sym,
1909 bfd_vma addr,
1910 const char **filename_ptr,
1911 unsigned int *linenumber_ptr)
1912{
1913 struct funcinfo* each_func;
1914 struct funcinfo* best_fit = NULL;
1915 struct arange *arange;
1916 const char *name = bfd_asymbol_name (sym);
1917 asection *sec = bfd_get_section (sym);
1918
1919 for (each_func = unit->function_table;
1920 each_func;
1921 each_func = each_func->prev_func)
1922 {
1923 for (arange = &each_func->arange;
1924 arange;
1925 arange = arange->next)
1926 {
1927 if ((!each_func->sec || each_func->sec == sec)
1928 && addr >= arange->low
1929 && addr < arange->high
650f284e 1930 && each_func->name
5420f73d
L
1931 && strcmp (name, each_func->name) == 0
1932 && (!best_fit
a2a50954
AM
1933 || (arange->high - arange->low
1934 < best_fit->arange.high - best_fit->arange.low)))
5420f73d
L
1935 best_fit = each_func;
1936 }
1937 }
1938
1939 if (best_fit)
1940 {
1941 best_fit->sec = sec;
1942 *filename_ptr = best_fit->file;
1943 *linenumber_ptr = best_fit->line;
1944 return TRUE;
1945 }
1946 else
1947 return FALSE;
1948}
1949
1950/* Variable table functions. */
1951
1952/* If SYM is within variable table of UNIT, set FILENAME_PTR and
1953 LINENUMBER_PTR, and return TRUE. */
1954
1955static bfd_boolean
1956lookup_symbol_in_variable_table (struct comp_unit *unit,
1957 asymbol *sym,
5cf2e3f0 1958 bfd_vma addr,
5420f73d
L
1959 const char **filename_ptr,
1960 unsigned int *linenumber_ptr)
1961{
1962 const char *name = bfd_asymbol_name (sym);
1963 asection *sec = bfd_get_section (sym);
1964 struct varinfo* each;
1965
1966 for (each = unit->variable_table; each; each = each->prev_var)
1967 if (each->stack == 0
5cf2e3f0
L
1968 && each->file != NULL
1969 && each->name != NULL
1970 && each->addr == addr
5420f73d
L
1971 && (!each->sec || each->sec == sec)
1972 && strcmp (name, each->name) == 0)
1973 break;
1974
1975 if (each)
1976 {
1977 each->sec = sec;
1978 *filename_ptr = each->file;
1979 *linenumber_ptr = each->line;
1980 return TRUE;
1981 }
1982 else
1983 return FALSE;
1984}
1985
06f22d7e 1986static char *
5609a71e
DJ
1987find_abstract_instance_name (struct comp_unit *unit,
1988 struct attribute *attr_ptr)
06f22d7e
FF
1989{
1990 bfd *abfd = unit->abfd;
f075ee0c 1991 bfd_byte *info_ptr;
06f22d7e
FF
1992 unsigned int abbrev_number, bytes_read, i;
1993 struct abbrev_info *abbrev;
5609a71e 1994 bfd_uint64_t die_ref = attr_ptr->u.val;
06f22d7e
FF
1995 struct attribute attr;
1996 char *name = 0;
1997
5609a71e
DJ
1998 /* DW_FORM_ref_addr can reference an entry in a different CU. It
1999 is an offset from the .debug_info section, not the current CU. */
2000 if (attr_ptr->form == DW_FORM_ref_addr)
2001 {
2002 /* We only support DW_FORM_ref_addr within the same file, so
2003 any relocations should be resolved already. */
2004 if (!die_ref)
2005 abort ();
2006
a358ecb8 2007 info_ptr = unit->sec_info_ptr + die_ref;
5609a71e
DJ
2008 }
2009 else
2010 info_ptr = unit->info_ptr_unit + die_ref;
06f22d7e
FF
2011 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
2012 info_ptr += bytes_read;
2013
2014 if (abbrev_number)
2015 {
2016 abbrev = lookup_abbrev (abbrev_number, unit->abbrevs);
2017 if (! abbrev)
2018 {
a2a50954
AM
2019 (*_bfd_error_handler)
2020 (_("Dwarf Error: Could not find abbrev number %u."), abbrev_number);
06f22d7e
FF
2021 bfd_set_error (bfd_error_bad_value);
2022 }
2023 else
2024 {
d5cbaa15 2025 for (i = 0; i < abbrev->num_attrs; ++i)
06f22d7e 2026 {
8af6b354
AM
2027 info_ptr = read_attribute (&attr, &abbrev->attrs[i], unit,
2028 info_ptr);
2029 if (info_ptr == NULL)
2030 break;
26bf4e33
FF
2031 switch (attr.name)
2032 {
2033 case DW_AT_name:
643be349
JJ
2034 /* Prefer DW_AT_MIPS_linkage_name or DW_AT_linkage_name
2035 over DW_AT_name. */
d5cbaa15
JW
2036 if (name == NULL)
2037 name = attr.u.str;
26bf4e33
FF
2038 break;
2039 case DW_AT_specification:
5609a71e 2040 name = find_abstract_instance_name (unit, &attr);
26bf4e33 2041 break;
643be349 2042 case DW_AT_linkage_name:
d5cbaa15
JW
2043 case DW_AT_MIPS_linkage_name:
2044 name = attr.u.str;
2045 break;
26bf4e33
FF
2046 default:
2047 break;
2048 }
06f22d7e
FF
2049 }
2050 }
2051 }
8af6b354 2052 return name;
06f22d7e
FF
2053}
2054
8af6b354
AM
2055static bfd_boolean
2056read_rangelist (struct comp_unit *unit, struct arange *arange,
2057 bfd_uint64_t offset)
a13afe8e
FF
2058{
2059 bfd_byte *ranges_ptr;
2060 bfd_vma base_address = unit->base_address;
2061
2062 if (! unit->stash->dwarf_ranges_buffer)
2063 {
2064 if (! read_debug_ranges (unit))
8af6b354 2065 return FALSE;
a13afe8e
FF
2066 }
2067 ranges_ptr = unit->stash->dwarf_ranges_buffer + offset;
d8d1c398 2068
a13afe8e
FF
2069 for (;;)
2070 {
2071 bfd_vma low_pc;
2072 bfd_vma high_pc;
2073
13d72a14
AN
2074 low_pc = read_address (unit, ranges_ptr);
2075 ranges_ptr += unit->addr_size;
2076 high_pc = read_address (unit, ranges_ptr);
2077 ranges_ptr += unit->addr_size;
2078
a13afe8e
FF
2079 if (low_pc == 0 && high_pc == 0)
2080 break;
2081 if (low_pc == -1UL && high_pc != -1UL)
2082 base_address = high_pc;
2083 else
8af6b354 2084 {
a2a50954 2085 if (!arange_add (unit, arange,
8af6b354
AM
2086 base_address + low_pc, base_address + high_pc))
2087 return FALSE;
2088 }
a13afe8e 2089 }
8af6b354 2090 return TRUE;
a13afe8e
FF
2091}
2092
a092b084 2093/* DWARF2 Compilation unit functions. */
252b5132
RH
2094
2095/* Scan over each die in a comp. unit looking for functions to add
34b5e0b2 2096 to the function table and variables to the variable table. */
252b5132 2097
b34976b6 2098static bfd_boolean
5420f73d 2099scan_unit_for_symbols (struct comp_unit *unit)
252b5132
RH
2100{
2101 bfd *abfd = unit->abfd;
f075ee0c 2102 bfd_byte *info_ptr = unit->first_child_die_ptr;
252b5132 2103 int nesting_level = 1;
c955f9cd
JW
2104 struct funcinfo **nested_funcs;
2105 int nested_funcs_size;
2106
2107 /* Maintain a stack of in-scope functions and inlined functions, which we
2108 can use to set the caller_func field. */
2109 nested_funcs_size = 32;
a50b1753 2110 nested_funcs = (struct funcinfo **)
a2a50954 2111 bfd_malloc (nested_funcs_size * sizeof (struct funcinfo *));
c955f9cd
JW
2112 if (nested_funcs == NULL)
2113 return FALSE;
34b5e0b2 2114 nested_funcs[nesting_level] = 0;
252b5132
RH
2115
2116 while (nesting_level)
2117 {
2118 unsigned int abbrev_number, bytes_read, i;
2119 struct abbrev_info *abbrev;
2120 struct attribute attr;
2121 struct funcinfo *func;
5420f73d 2122 struct varinfo *var;
a13afe8e
FF
2123 bfd_vma low_pc = 0;
2124 bfd_vma high_pc = 0;
c49ead2f 2125 bfd_boolean high_pc_relative = FALSE;
252b5132
RH
2126
2127 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
2128 info_ptr += bytes_read;
2129
2130 if (! abbrev_number)
2131 {
2132 nesting_level--;
2133 continue;
2134 }
98591c73 2135
252b5132
RH
2136 abbrev = lookup_abbrev (abbrev_number,unit->abbrevs);
2137 if (! abbrev)
2138 {
8af6b354
AM
2139 (*_bfd_error_handler)
2140 (_("Dwarf Error: Could not find abbrev number %u."),
2141 abbrev_number);
252b5132 2142 bfd_set_error (bfd_error_bad_value);
8af6b354 2143 goto fail;
252b5132 2144 }
98591c73 2145
5420f73d 2146 var = NULL;
06f22d7e 2147 if (abbrev->tag == DW_TAG_subprogram
5420f73d 2148 || abbrev->tag == DW_TAG_entry_point
06f22d7e 2149 || abbrev->tag == DW_TAG_inlined_subroutine)
252b5132 2150 {
dc810e39 2151 bfd_size_type amt = sizeof (struct funcinfo);
a50b1753 2152 func = (struct funcinfo *) bfd_zalloc (abfd, amt);
8af6b354
AM
2153 if (func == NULL)
2154 goto fail;
4ab527b0 2155 func->tag = abbrev->tag;
252b5132
RH
2156 func->prev_func = unit->function_table;
2157 unit->function_table = func;
bd210d54 2158 BFD_ASSERT (!unit->cached);
c955f9cd
JW
2159
2160 if (func->tag == DW_TAG_inlined_subroutine)
2161 for (i = nesting_level - 1; i >= 1; i--)
2162 if (nested_funcs[i])
2163 {
2164 func->caller_func = nested_funcs[i];
2165 break;
2166 }
2167 nested_funcs[nesting_level] = func;
252b5132
RH
2168 }
2169 else
5420f73d
L
2170 {
2171 func = NULL;
2172 if (abbrev->tag == DW_TAG_variable)
2173 {
2174 bfd_size_type amt = sizeof (struct varinfo);
a50b1753 2175 var = (struct varinfo *) bfd_zalloc (abfd, amt);
8af6b354
AM
2176 if (var == NULL)
2177 goto fail;
5420f73d
L
2178 var->tag = abbrev->tag;
2179 var->stack = 1;
2180 var->prev_var = unit->variable_table;
2181 unit->variable_table = var;
bd210d54 2182 BFD_ASSERT (!unit->cached);
5420f73d 2183 }
c955f9cd
JW
2184
2185 /* No inline function in scope at this nesting level. */
2186 nested_funcs[nesting_level] = 0;
5420f73d 2187 }
98591c73 2188
252b5132
RH
2189 for (i = 0; i < abbrev->num_attrs; ++i)
2190 {
2191 info_ptr = read_attribute (&attr, &abbrev->attrs[i], unit, info_ptr);
8af6b354 2192 if (info_ptr == NULL)
8ecc1f20 2193 goto fail;
98591c73 2194
252b5132
RH
2195 if (func)
2196 {
2197 switch (attr.name)
2198 {
4ab527b0 2199 case DW_AT_call_file:
8af6b354
AM
2200 func->caller_file = concat_filename (unit->line_table,
2201 attr.u.val);
4ab527b0
FF
2202 break;
2203
2204 case DW_AT_call_line:
2205 func->caller_line = attr.u.val;
2206 break;
2207
06f22d7e 2208 case DW_AT_abstract_origin:
5d8e6b4d 2209 case DW_AT_specification:
5609a71e 2210 func->name = find_abstract_instance_name (unit, &attr);
06f22d7e
FF
2211 break;
2212
252b5132 2213 case DW_AT_name:
643be349
JJ
2214 /* Prefer DW_AT_MIPS_linkage_name or DW_AT_linkage_name
2215 over DW_AT_name. */
252b5132 2216 if (func->name == NULL)
482e2e37 2217 func->name = attr.u.str;
252b5132 2218 break;
98591c73 2219
643be349 2220 case DW_AT_linkage_name:
252b5132 2221 case DW_AT_MIPS_linkage_name:
482e2e37 2222 func->name = attr.u.str;
252b5132
RH
2223 break;
2224
2225 case DW_AT_low_pc:
a13afe8e 2226 low_pc = attr.u.val;
252b5132
RH
2227 break;
2228
2229 case DW_AT_high_pc:
a13afe8e 2230 high_pc = attr.u.val;
c49ead2f 2231 high_pc_relative = attr.form != DW_FORM_addr;
a13afe8e
FF
2232 break;
2233
2234 case DW_AT_ranges:
8af6b354
AM
2235 if (!read_rangelist (unit, &func->arange, attr.u.val))
2236 goto fail;
252b5132
RH
2237 break;
2238
5420f73d
L
2239 case DW_AT_decl_file:
2240 func->file = concat_filename (unit->line_table,
2241 attr.u.val);
2242 break;
2243
2244 case DW_AT_decl_line:
2245 func->line = attr.u.val;
2246 break;
2247
2248 default:
2249 break;
2250 }
2251 }
2252 else if (var)
2253 {
2254 switch (attr.name)
2255 {
2256 case DW_AT_name:
2257 var->name = attr.u.str;
2258 break;
2259
2260 case DW_AT_decl_file:
2261 var->file = concat_filename (unit->line_table,
2262 attr.u.val);
2263 break;
2264
2265 case DW_AT_decl_line:
2266 var->line = attr.u.val;
2267 break;
2268
2269 case DW_AT_external:
2270 if (attr.u.val != 0)
2271 var->stack = 0;
2272 break;
2273
2274 case DW_AT_location:
5cf2e3f0 2275 switch (attr.form)
5420f73d 2276 {
5cf2e3f0
L
2277 case DW_FORM_block:
2278 case DW_FORM_block1:
2279 case DW_FORM_block2:
2280 case DW_FORM_block4:
c07cbdd7 2281 case DW_FORM_exprloc:
5cf2e3f0 2282 if (*attr.u.blk->data == DW_OP_addr)
5420f73d 2283 {
5cf2e3f0 2284 var->stack = 0;
98b880f4
JW
2285
2286 /* Verify that DW_OP_addr is the only opcode in the
2287 location, in which case the block size will be 1
2288 plus the address size. */
2289 /* ??? For TLS variables, gcc can emit
2290 DW_OP_addr <addr> DW_OP_GNU_push_tls_address
2291 which we don't handle here yet. */
2292 if (attr.u.blk->size == unit->addr_size + 1U)
2293 var->addr = bfd_get (unit->addr_size * 8,
2294 unit->abfd,
2295 attr.u.blk->data + 1);
5420f73d 2296 }
5cf2e3f0 2297 break;
d8d1c398 2298
5cf2e3f0
L
2299 default:
2300 break;
5420f73d
L
2301 }
2302 break;
2303
252b5132
RH
2304 default:
2305 break;
2306 }
2307 }
2308 }
2309
c49ead2f
MW
2310 if (high_pc_relative)
2311 high_pc += low_pc;
2312
a13afe8e
FF
2313 if (func && high_pc != 0)
2314 {
a2a50954 2315 if (!arange_add (unit, &func->arange, low_pc, high_pc))
8af6b354 2316 goto fail;
a13afe8e
FF
2317 }
2318
252b5132 2319 if (abbrev->has_children)
c955f9cd
JW
2320 {
2321 nesting_level++;
2322
2323 if (nesting_level >= nested_funcs_size)
2324 {
2325 struct funcinfo **tmp;
2326
2327 nested_funcs_size *= 2;
a50b1753 2328 tmp = (struct funcinfo **)
a2a50954
AM
2329 bfd_realloc (nested_funcs,
2330 nested_funcs_size * sizeof (struct funcinfo *));
c955f9cd 2331 if (tmp == NULL)
8af6b354 2332 goto fail;
c955f9cd
JW
2333 nested_funcs = tmp;
2334 }
2335 nested_funcs[nesting_level] = 0;
2336 }
252b5132
RH
2337 }
2338
c955f9cd 2339 free (nested_funcs);
b34976b6 2340 return TRUE;
8af6b354
AM
2341
2342 fail:
2343 free (nested_funcs);
2344 return FALSE;
252b5132
RH
2345}
2346
5e38c3b8
MM
2347/* Parse a DWARF2 compilation unit starting at INFO_PTR. This
2348 includes the compilation unit header that proceeds the DIE's, but
5c4491d3 2349 does not include the length field that precedes each compilation
5e38c3b8 2350 unit header. END_PTR points one past the end of this comp unit.
d03ba2a1 2351 OFFSET_SIZE is the size of DWARF2 offsets (either 4 or 8 bytes).
252b5132
RH
2352
2353 This routine does not read the whole compilation unit; only enough
2354 to get to the line number information for the compilation unit. */
2355
2356static struct comp_unit *
0d161102 2357parse_comp_unit (struct dwarf2_debug *stash,
818a27ac 2358 bfd_vma unit_length,
f075ee0c 2359 bfd_byte *info_ptr_unit,
818a27ac 2360 unsigned int offset_size)
252b5132
RH
2361{
2362 struct comp_unit* unit;
f46c2da6 2363 unsigned int version;
8ce8c090 2364 bfd_uint64_t abbrev_offset = 0;
f46c2da6 2365 unsigned int addr_size;
252b5132 2366 struct abbrev_info** abbrevs;
252b5132
RH
2367 unsigned int abbrev_number, bytes_read, i;
2368 struct abbrev_info *abbrev;
2369 struct attribute attr;
f075ee0c
AM
2370 bfd_byte *info_ptr = stash->info_ptr;
2371 bfd_byte *end_ptr = info_ptr + unit_length;
dc810e39 2372 bfd_size_type amt;
a13afe8e
FF
2373 bfd_vma low_pc = 0;
2374 bfd_vma high_pc = 0;
a50b1753 2375 bfd *abfd = stash->bfd_ptr;
c49ead2f 2376 bfd_boolean high_pc_relative = FALSE;
3fde5a36 2377
252b5132
RH
2378 version = read_2_bytes (abfd, info_ptr);
2379 info_ptr += 2;
d03ba2a1
JJ
2380 BFD_ASSERT (offset_size == 4 || offset_size == 8);
2381 if (offset_size == 4)
5e38c3b8 2382 abbrev_offset = read_4_bytes (abfd, info_ptr);
d03ba2a1 2383 else
5e38c3b8 2384 abbrev_offset = read_8_bytes (abfd, info_ptr);
d03ba2a1 2385 info_ptr += offset_size;
252b5132
RH
2386 addr_size = read_1_byte (abfd, info_ptr);
2387 info_ptr += 1;
2388
c07cbdd7 2389 if (version != 2 && version != 3 && version != 4)
252b5132 2390 {
a2a50954
AM
2391 (*_bfd_error_handler)
2392 (_("Dwarf Error: found dwarf version '%u', this reader"
2393 " only handles version 2, 3 and 4 information."), version);
252b5132
RH
2394 bfd_set_error (bfd_error_bad_value);
2395 return 0;
2396 }
2397
2398 if (addr_size > sizeof (bfd_vma))
2399 {
a2a50954
AM
2400 (*_bfd_error_handler)
2401 (_("Dwarf Error: found address size '%u', this reader"
2402 " can not handle sizes greater than '%u'."),
2403 addr_size,
2404 (unsigned int) sizeof (bfd_vma));
252b5132
RH
2405 bfd_set_error (bfd_error_bad_value);
2406 return 0;
2407 }
2408
ecb651f0 2409 if (addr_size != 2 && addr_size != 4 && addr_size != 8)
252b5132 2410 {
a2a50954
AM
2411 (*_bfd_error_handler)
2412 ("Dwarf Error: found address size '%u', this reader"
2413 " can only handle address sizes '2', '4' and '8'.", addr_size);
252b5132
RH
2414 bfd_set_error (bfd_error_bad_value);
2415 return 0;
2416 }
2417
a092b084 2418 /* Read the abbrevs for this compilation unit into a table. */
51db3708 2419 abbrevs = read_abbrevs (abfd, abbrev_offset, stash);
252b5132 2420 if (! abbrevs)
a2a50954 2421 return 0;
252b5132
RH
2422
2423 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
2424 info_ptr += bytes_read;
2425 if (! abbrev_number)
2426 {
f46c2da6 2427 (*_bfd_error_handler) (_("Dwarf Error: Bad abbrev number: %u."),
a2a50954 2428 abbrev_number);
252b5132
RH
2429 bfd_set_error (bfd_error_bad_value);
2430 return 0;
2431 }
2432
2433 abbrev = lookup_abbrev (abbrev_number, abbrevs);
2434 if (! abbrev)
2435 {
f46c2da6 2436 (*_bfd_error_handler) (_("Dwarf Error: Could not find abbrev number %u."),
a2a50954 2437 abbrev_number);
252b5132
RH
2438 bfd_set_error (bfd_error_bad_value);
2439 return 0;
2440 }
98591c73 2441
dc810e39 2442 amt = sizeof (struct comp_unit);
a50b1753 2443 unit = (struct comp_unit *) bfd_zalloc (abfd, amt);
8af6b354
AM
2444 if (unit == NULL)
2445 return NULL;
252b5132 2446 unit->abfd = abfd;
5609a71e 2447 unit->version = version;
98591c73 2448 unit->addr_size = addr_size;
d03ba2a1 2449 unit->offset_size = offset_size;
252b5132
RH
2450 unit->abbrevs = abbrevs;
2451 unit->end_ptr = end_ptr;
d03ba2a1 2452 unit->stash = stash;
c0c28ab8 2453 unit->info_ptr_unit = info_ptr_unit;
a358ecb8 2454 unit->sec_info_ptr = stash->sec_info_ptr;
252b5132
RH
2455
2456 for (i = 0; i < abbrev->num_attrs; ++i)
2457 {
2458 info_ptr = read_attribute (&attr, &abbrev->attrs[i], unit, info_ptr);
8af6b354
AM
2459 if (info_ptr == NULL)
2460 return NULL;
252b5132
RH
2461
2462 /* Store the data if it is of an attribute we want to keep in a
2463 partial symbol table. */
2464 switch (attr.name)
2465 {
2466 case DW_AT_stmt_list:
2467 unit->stmtlist = 1;
482e2e37 2468 unit->line_offset = attr.u.val;
252b5132
RH
2469 break;
2470
2471 case DW_AT_name:
482e2e37 2472 unit->name = attr.u.str;
252b5132
RH
2473 break;
2474
2475 case DW_AT_low_pc:
a13afe8e
FF
2476 low_pc = attr.u.val;
2477 /* If the compilation unit DIE has a DW_AT_low_pc attribute,
2478 this is the base address to use when reading location
2479 lists or range lists. */
a2a50954
AM
2480 if (abbrev->tag == DW_TAG_compile_unit)
2481 unit->base_address = low_pc;
252b5132
RH
2482 break;
2483
2484 case DW_AT_high_pc:
a13afe8e 2485 high_pc = attr.u.val;
c49ead2f 2486 high_pc_relative = attr.form != DW_FORM_addr;
a13afe8e
FF
2487 break;
2488
2489 case DW_AT_ranges:
8af6b354
AM
2490 if (!read_rangelist (unit, &unit->arange, attr.u.val))
2491 return NULL;
252b5132
RH
2492 break;
2493
2494 case DW_AT_comp_dir:
2495 {
f075ee0c 2496 char *comp_dir = attr.u.str;
252b5132
RH
2497 if (comp_dir)
2498 {
2499 /* Irix 6.2 native cc prepends <machine>.: to the compilation
2500 directory, get rid of it. */
818a27ac 2501 char *cp = strchr (comp_dir, ':');
252b5132
RH
2502
2503 if (cp && cp != comp_dir && cp[-1] == '.' && cp[1] == '/')
2504 comp_dir = cp + 1;
2505 }
2506 unit->comp_dir = comp_dir;
2507 break;
2508 }
2509
2510 default:
2511 break;
2512 }
2513 }
c49ead2f
MW
2514 if (high_pc_relative)
2515 high_pc += low_pc;
a13afe8e 2516 if (high_pc != 0)
709d67f1 2517 {
a2a50954 2518 if (!arange_add (unit, &unit->arange, low_pc, high_pc))
8af6b354 2519 return NULL;
709d67f1 2520 }
252b5132
RH
2521
2522 unit->first_child_die_ptr = info_ptr;
2523 return unit;
2524}
2525
6dd55cb7
L
2526/* Return TRUE if UNIT may contain the address given by ADDR. When
2527 there are functions written entirely with inline asm statements, the
2528 range info in the compilation unit header may not be correct. We
2529 need to consult the line info table to see if a compilation unit
2530 really contains the given address. */
252b5132 2531
b34976b6 2532static bfd_boolean
818a27ac 2533comp_unit_contains_address (struct comp_unit *unit, bfd_vma addr)
252b5132 2534{
709d67f1
AM
2535 struct arange *arange;
2536
2537 if (unit->error)
2538 return FALSE;
2539
2540 arange = &unit->arange;
2541 do
2542 {
2543 if (addr >= arange->low && addr < arange->high)
2544 return TRUE;
2545 arange = arange->next;
2546 }
2547 while (arange);
2548
2549 return FALSE;
252b5132
RH
2550}
2551
252b5132
RH
2552/* If UNIT contains ADDR, set the output parameters to the values for
2553 the line containing ADDR. The output parameters, FILENAME_PTR,
2554 FUNCTIONNAME_PTR, and LINENUMBER_PTR, are pointers to the objects
98591c73 2555 to be filled in.
252b5132 2556
ab3acfbe 2557 Return TRUE if UNIT contains ADDR, and no errors were encountered;
b34976b6 2558 FALSE otherwise. */
252b5132 2559
b34976b6 2560static bfd_boolean
818a27ac
AM
2561comp_unit_find_nearest_line (struct comp_unit *unit,
2562 bfd_vma addr,
2563 const char **filename_ptr,
2564 const char **functionname_ptr,
2565 unsigned int *linenumber_ptr,
9b8d1a36 2566 unsigned int *discriminator_ptr,
818a27ac 2567 struct dwarf2_debug *stash)
252b5132 2568{
b34976b6
AM
2569 bfd_boolean line_p;
2570 bfd_boolean func_p;
1ee24f27 2571 struct funcinfo *function;
98591c73 2572
252b5132 2573 if (unit->error)
b34976b6 2574 return FALSE;
252b5132
RH
2575
2576 if (! unit->line_table)
2577 {
2578 if (! unit->stmtlist)
2579 {
2580 unit->error = 1;
b34976b6 2581 return FALSE;
252b5132 2582 }
98591c73 2583
51db3708 2584 unit->line_table = decode_line_info (unit, stash);
252b5132
RH
2585
2586 if (! unit->line_table)
2587 {
2588 unit->error = 1;
b34976b6 2589 return FALSE;
252b5132 2590 }
98591c73 2591
3f5864e1 2592 if (unit->first_child_die_ptr < unit->end_ptr
5420f73d 2593 && ! scan_unit_for_symbols (unit))
252b5132
RH
2594 {
2595 unit->error = 1;
b34976b6 2596 return FALSE;
252b5132
RH
2597 }
2598 }
2599
1ee24f27 2600 function = NULL;
4ab527b0 2601 func_p = lookup_address_in_function_table (unit, addr,
e2f6d277 2602 &function, functionname_ptr);
4ab527b0
FF
2603 if (func_p && (function->tag == DW_TAG_inlined_subroutine))
2604 stash->inliner_chain = function;
e2f6d277 2605 line_p = lookup_address_in_line_info_table (unit->line_table, addr,
107601c8 2606 filename_ptr,
9b8d1a36
CC
2607 linenumber_ptr,
2608 discriminator_ptr);
b34976b6 2609 return line_p || func_p;
252b5132
RH
2610}
2611
bd210d54
NC
2612/* Check to see if line info is already decoded in a comp_unit.
2613 If not, decode it. Returns TRUE if no errors were encountered;
5420f73d
L
2614 FALSE otherwise. */
2615
2616static bfd_boolean
bd210d54
NC
2617comp_unit_maybe_decode_line_info (struct comp_unit *unit,
2618 struct dwarf2_debug *stash)
5420f73d
L
2619{
2620 if (unit->error)
2621 return FALSE;
2622
2623 if (! unit->line_table)
2624 {
2625 if (! unit->stmtlist)
2626 {
2627 unit->error = 1;
2628 return FALSE;
2629 }
2630
2631 unit->line_table = decode_line_info (unit, stash);
2632
2633 if (! unit->line_table)
2634 {
2635 unit->error = 1;
2636 return FALSE;
2637 }
2638
2639 if (unit->first_child_die_ptr < unit->end_ptr
2640 && ! scan_unit_for_symbols (unit))
2641 {
2642 unit->error = 1;
2643 return FALSE;
2644 }
2645 }
2646
bd210d54
NC
2647 return TRUE;
2648}
2649
2650/* If UNIT contains SYM at ADDR, set the output parameters to the
2651 values for the line containing SYM. The output parameters,
2652 FILENAME_PTR, and LINENUMBER_PTR, are pointers to the objects to be
2653 filled in.
2654
2655 Return TRUE if UNIT contains SYM, and no errors were encountered;
2656 FALSE otherwise. */
2657
2658static bfd_boolean
2659comp_unit_find_line (struct comp_unit *unit,
2660 asymbol *sym,
2661 bfd_vma addr,
2662 const char **filename_ptr,
2663 unsigned int *linenumber_ptr,
2664 struct dwarf2_debug *stash)
2665{
2666 if (!comp_unit_maybe_decode_line_info (unit, stash))
2667 return FALSE;
2668
5420f73d
L
2669 if (sym->flags & BSF_FUNCTION)
2670 return lookup_symbol_in_function_table (unit, sym, addr,
2671 filename_ptr,
2672 linenumber_ptr);
bd210d54
NC
2673
2674 return lookup_symbol_in_variable_table (unit, sym, addr,
2675 filename_ptr,
2676 linenumber_ptr);
2677}
2678
2679static struct funcinfo *
2680reverse_funcinfo_list (struct funcinfo *head)
2681{
2682 struct funcinfo *rhead;
2683 struct funcinfo *temp;
2684
2685 for (rhead = NULL; head; head = temp)
2686 {
2687 temp = head->prev_func;
2688 head->prev_func = rhead;
2689 rhead = head;
2690 }
2691 return rhead;
2692}
2693
2694static struct varinfo *
2695reverse_varinfo_list (struct varinfo *head)
2696{
2697 struct varinfo *rhead;
2698 struct varinfo *temp;
2699
2700 for (rhead = NULL; head; head = temp)
2701 {
2702 temp = head->prev_var;
2703 head->prev_var = rhead;
2704 rhead = head;
2705 }
2706 return rhead;
2707}
2708
2709/* Extract all interesting funcinfos and varinfos of a compilation
2710 unit into hash tables for faster lookup. Returns TRUE if no
2711 errors were enountered; FALSE otherwise. */
2712
2713static bfd_boolean
2714comp_unit_hash_info (struct dwarf2_debug *stash,
2715 struct comp_unit *unit,
2716 struct info_hash_table *funcinfo_hash_table,
2717 struct info_hash_table *varinfo_hash_table)
2718{
2719 struct funcinfo* each_func;
2720 struct varinfo* each_var;
2721 bfd_boolean okay = TRUE;
2722
2723 BFD_ASSERT (stash->info_hash_status != STASH_INFO_HASH_DISABLED);
2724
2725 if (!comp_unit_maybe_decode_line_info (unit, stash))
2726 return FALSE;
2727
2728 BFD_ASSERT (!unit->cached);
2729
2730 /* To preserve the original search order, we went to visit the function
2731 infos in the reversed order of the list. However, making the list
2732 bi-directional use quite a bit of extra memory. So we reverse
2733 the list first, traverse the list in the now reversed order and
2734 finally reverse the list again to get back the original order. */
2735 unit->function_table = reverse_funcinfo_list (unit->function_table);
2736 for (each_func = unit->function_table;
2737 each_func && okay;
2738 each_func = each_func->prev_func)
2739 {
2740 /* Skip nameless functions. */
2741 if (each_func->name)
2742 /* There is no need to copy name string into hash table as
2743 name string is either in the dwarf string buffer or
2744 info in the stash. */
2745 okay = insert_info_hash_table (funcinfo_hash_table, each_func->name,
2746 (void*) each_func, FALSE);
2747 }
2748 unit->function_table = reverse_funcinfo_list (unit->function_table);
2749 if (!okay)
2750 return FALSE;
2751
2752 /* We do the same for variable infos. */
2753 unit->variable_table = reverse_varinfo_list (unit->variable_table);
2754 for (each_var = unit->variable_table;
2755 each_var && okay;
2756 each_var = each_var->prev_var)
2757 {
2758 /* Skip stack vars and vars with no files or names. */
2759 if (each_var->stack == 0
2760 && each_var->file != NULL
2761 && each_var->name != NULL)
2762 /* There is no need to copy name string into hash table as
2763 name string is either in the dwarf string buffer or
2764 info in the stash. */
2765 okay = insert_info_hash_table (varinfo_hash_table, each_var->name,
2766 (void*) each_var, FALSE);
2767 }
2768
2769 unit->variable_table = reverse_varinfo_list (unit->variable_table);
2770 unit->cached = TRUE;
2771 return okay;
5420f73d
L
2772}
2773
e2f6d277
NC
2774/* Locate a section in a BFD containing debugging info. The search starts
2775 from the section after AFTER_SEC, or from the first section in the BFD if
2776 AFTER_SEC is NULL. The search works by examining the names of the
fc28f9aa
TG
2777 sections. There are three permissiable names. The first two are given
2778 by DEBUG_SECTIONS[debug_info] (whose standard DWARF2 names are .debug_info
2779 and .zdebug_info). The third is a prefix .gnu.linkonce.wi.
e2f6d277
NC
2780 This is a variation on the .debug_info section which has a checksum
2781 describing the contents appended onto the name. This allows the linker to
2782 identify and discard duplicate debugging sections for different
2783 compilation units. */
a092b084
NC
2784#define GNU_LINKONCE_INFO ".gnu.linkonce.wi."
2785
2786static asection *
fc28f9aa
TG
2787find_debug_info (bfd *abfd, const struct dwarf_debug_section *debug_sections,
2788 asection *after_sec)
a092b084 2789{
a2a50954
AM
2790 asection *msec;
2791 const char *look;
2792
2793 if (after_sec == NULL)
2794 {
2795 look = debug_sections[debug_info].uncompressed_name;
2796 msec = bfd_get_section_by_name (abfd, look);
2797 if (msec != NULL)
2798 return msec;
a092b084 2799
a2a50954
AM
2800 look = debug_sections[debug_info].compressed_name;
2801 if (look != NULL)
2802 {
2803 msec = bfd_get_section_by_name (abfd, look);
2804 if (msec != NULL)
2805 return msec;
2806 }
a092b084 2807
a2a50954
AM
2808 for (msec = abfd->sections; msec != NULL; msec = msec->next)
2809 if (CONST_STRNEQ (msec->name, GNU_LINKONCE_INFO))
2810 return msec;
2811
2812 return NULL;
2813 }
2814
2815 for (msec = after_sec->next; msec != NULL; msec = msec->next)
a092b084 2816 {
a2a50954
AM
2817 look = debug_sections[debug_info].uncompressed_name;
2818 if (strcmp (msec->name, look) == 0)
a092b084
NC
2819 return msec;
2820
a2a50954
AM
2821 look = debug_sections[debug_info].compressed_name;
2822 if (look != NULL && strcmp (msec->name, look) == 0)
1b315056
CS
2823 return msec;
2824
0112cd26 2825 if (CONST_STRNEQ (msec->name, GNU_LINKONCE_INFO))
a092b084 2826 return msec;
a092b084
NC
2827 }
2828
2829 return NULL;
2830}
2831
5609a71e 2832/* Unset vmas for adjusted sections in STASH. */
d4c32a81
L
2833
2834static void
2835unset_sections (struct dwarf2_debug *stash)
2836{
2837 unsigned int i;
5609a71e 2838 struct adjusted_section *p;
d4c32a81 2839
5609a71e
DJ
2840 i = stash->adjusted_section_count;
2841 p = stash->adjusted_sections;
d4c32a81
L
2842 for (; i > 0; i--, p++)
2843 p->section->vma = 0;
2844}
2845
5609a71e
DJ
2846/* Set unique VMAs for loadable and DWARF sections in ABFD and save
2847 VMAs in STASH for unset_sections. */
35ccda9e
L
2848
2849static bfd_boolean
d4c32a81 2850place_sections (bfd *abfd, struct dwarf2_debug *stash)
35ccda9e 2851{
5609a71e 2852 struct adjusted_section *p;
d4c32a81
L
2853 unsigned int i;
2854
5609a71e 2855 if (stash->adjusted_section_count != 0)
35ccda9e 2856 {
5609a71e
DJ
2857 i = stash->adjusted_section_count;
2858 p = stash->adjusted_sections;
d4c32a81
L
2859 for (; i > 0; i--, p++)
2860 p->section->vma = p->adj_vma;
2861 }
2862 else
2863 {
2864 asection *sect;
5609a71e 2865 bfd_vma last_vma = 0, last_dwarf = 0;
d4c32a81 2866 bfd_size_type amt;
fc28f9aa 2867 const char *debug_info_name;
35ccda9e 2868
fc28f9aa 2869 debug_info_name = stash->debug_sections[debug_info].uncompressed_name;
d4c32a81
L
2870 i = 0;
2871 for (sect = abfd->sections; sect != NULL; sect = sect->next)
35ccda9e 2872 {
d4c32a81 2873 bfd_size_type sz;
5609a71e
DJ
2874 int is_debug_info;
2875
2876 if (sect->vma != 0)
2877 continue;
2878
2879 /* We need to adjust the VMAs of any .debug_info sections.
2880 Skip compressed ones, since no relocations could target
2881 them - they should not appear in object files anyway. */
fc28f9aa 2882 if (strcmp (sect->name, debug_info_name) == 0)
5609a71e
DJ
2883 is_debug_info = 1;
2884 else if (CONST_STRNEQ (sect->name, GNU_LINKONCE_INFO))
2885 is_debug_info = 1;
2886 else
2887 is_debug_info = 0;
d4c32a81 2888
5609a71e 2889 if (!is_debug_info && (sect->flags & SEC_LOAD) == 0)
d4c32a81
L
2890 continue;
2891
2892 sz = sect->rawsize ? sect->rawsize : sect->size;
2893 if (sz == 0)
2894 continue;
2895
2896 i++;
2897 }
2898
5609a71e 2899 amt = i * sizeof (struct adjusted_section);
a2a50954 2900 p = (struct adjusted_section *) bfd_alloc (abfd, amt);
d4c32a81
L
2901 if (! p)
2902 return FALSE;
2903
5609a71e
DJ
2904 stash->adjusted_sections = p;
2905 stash->adjusted_section_count = i;
d4c32a81
L
2906
2907 for (sect = abfd->sections; sect != NULL; sect = sect->next)
2908 {
2909 bfd_size_type sz;
5609a71e 2910 int is_debug_info;
d4c32a81 2911
5609a71e
DJ
2912 if (sect->vma != 0)
2913 continue;
2914
2915 /* We need to adjust the VMAs of any .debug_info sections.
2916 Skip compressed ones, since no relocations could target
2917 them - they should not appear in object files anyway. */
fc28f9aa 2918 if (strcmp (sect->name, debug_info_name) == 0)
5609a71e
DJ
2919 is_debug_info = 1;
2920 else if (CONST_STRNEQ (sect->name, GNU_LINKONCE_INFO))
2921 is_debug_info = 1;
2922 else
2923 is_debug_info = 0;
2924
2925 if (!is_debug_info && (sect->flags & SEC_LOAD) == 0)
d4c32a81
L
2926 continue;
2927
2928 sz = sect->rawsize ? sect->rawsize : sect->size;
2929 if (sz == 0)
2930 continue;
2931
2932 p->section = sect;
5609a71e
DJ
2933 if (is_debug_info)
2934 {
2935 BFD_ASSERT (sect->alignment_power == 0);
2936 sect->vma = last_dwarf;
2937 last_dwarf += sz;
2938 }
2939 else if (last_vma != 0)
d4c32a81
L
2940 {
2941 /* Align the new address to the current section
2942 alignment. */
2943 last_vma = ((last_vma
2944 + ~((bfd_vma) -1 << sect->alignment_power))
2945 & ((bfd_vma) -1 << sect->alignment_power));
2946 sect->vma = last_vma;
5609a71e 2947 last_vma += sect->vma + sz;
d4c32a81 2948 }
5609a71e
DJ
2949 else
2950 last_vma += sect->vma + sz;
2951
d4c32a81 2952 p->adj_vma = sect->vma;
d4c32a81
L
2953
2954 p++;
35ccda9e
L
2955 }
2956 }
2957
2958 return TRUE;
2959}
2960
bd210d54
NC
2961/* Look up a funcinfo by name using the given info hash table. If found,
2962 also update the locations pointed to by filename_ptr and linenumber_ptr.
2963
2964 This function returns TRUE if a funcinfo that matches the given symbol
2965 and address is found with any error; otherwise it returns FALSE. */
2966
2967static bfd_boolean
2968info_hash_lookup_funcinfo (struct info_hash_table *hash_table,
2969 asymbol *sym,
2970 bfd_vma addr,
2971 const char **filename_ptr,
2972 unsigned int *linenumber_ptr)
2973{
2974 struct funcinfo* each_func;
2975 struct funcinfo* best_fit = NULL;
2976 struct info_list_node *node;
2977 struct arange *arange;
2978 const char *name = bfd_asymbol_name (sym);
2979 asection *sec = bfd_get_section (sym);
2980
2981 for (node = lookup_info_hash_table (hash_table, name);
2982 node;
2983 node = node->next)
2984 {
a50b1753 2985 each_func = (struct funcinfo *) node->info;
bd210d54
NC
2986 for (arange = &each_func->arange;
2987 arange;
2988 arange = arange->next)
2989 {
2990 if ((!each_func->sec || each_func->sec == sec)
2991 && addr >= arange->low
2992 && addr < arange->high
2993 && (!best_fit
a2a50954
AM
2994 || (arange->high - arange->low
2995 < best_fit->arange.high - best_fit->arange.low)))
bd210d54
NC
2996 best_fit = each_func;
2997 }
2998 }
2999
3000 if (best_fit)
3001 {
3002 best_fit->sec = sec;
3003 *filename_ptr = best_fit->file;
3004 *linenumber_ptr = best_fit->line;
3005 return TRUE;
3006 }
3007
3008 return FALSE;
3009}
3010
3011/* Look up a varinfo by name using the given info hash table. If found,
3012 also update the locations pointed to by filename_ptr and linenumber_ptr.
3013
3014 This function returns TRUE if a varinfo that matches the given symbol
3015 and address is found with any error; otherwise it returns FALSE. */
3016
3017static bfd_boolean
3018info_hash_lookup_varinfo (struct info_hash_table *hash_table,
3019 asymbol *sym,
3020 bfd_vma addr,
3021 const char **filename_ptr,
3022 unsigned int *linenumber_ptr)
3023{
3024 const char *name = bfd_asymbol_name (sym);
3025 asection *sec = bfd_get_section (sym);
3026 struct varinfo* each;
3027 struct info_list_node *node;
3028
3029 for (node = lookup_info_hash_table (hash_table, name);
3030 node;
3031 node = node->next)
3032 {
a50b1753 3033 each = (struct varinfo *) node->info;
bd210d54
NC
3034 if (each->addr == addr
3035 && (!each->sec || each->sec == sec))
3036 {
3037 each->sec = sec;
3038 *filename_ptr = each->file;
3039 *linenumber_ptr = each->line;
3040 return TRUE;
3041 }
3042 }
3043
3044 return FALSE;
3045}
3046
3047/* Update the funcinfo and varinfo info hash tables if they are
3048 not up to date. Returns TRUE if there is no error; otherwise
3049 returns FALSE and disable the info hash tables. */
3050
3051static bfd_boolean
3052stash_maybe_update_info_hash_tables (struct dwarf2_debug *stash)
3053{
3054 struct comp_unit *each;
3055
3056 /* Exit if hash tables are up-to-date. */
3057 if (stash->all_comp_units == stash->hash_units_head)
3058 return TRUE;
3059
3060 if (stash->hash_units_head)
3061 each = stash->hash_units_head->prev_unit;
3062 else
3063 each = stash->last_comp_unit;
3064
3065 while (each)
3066 {
3067 if (!comp_unit_hash_info (stash, each, stash->funcinfo_hash_table,
3068 stash->varinfo_hash_table))
3069 {
3070 stash->info_hash_status = STASH_INFO_HASH_DISABLED;
3071 return FALSE;
3072 }
3073 each = each->prev_unit;
3074 }
3075
3076 stash->hash_units_head = stash->all_comp_units;
3077 return TRUE;
3078}
3079
3080/* Check consistency of info hash tables. This is for debugging only. */
3081
3082static void ATTRIBUTE_UNUSED
3083stash_verify_info_hash_table (struct dwarf2_debug *stash)
3084{
3085 struct comp_unit *each_unit;
3086 struct funcinfo *each_func;
3087 struct varinfo *each_var;
3088 struct info_list_node *node;
3089 bfd_boolean found;
3090
3091 for (each_unit = stash->all_comp_units;
3092 each_unit;
3093 each_unit = each_unit->next_unit)
3094 {
3095 for (each_func = each_unit->function_table;
3096 each_func;
3097 each_func = each_func->prev_func)
3098 {
3099 if (!each_func->name)
3100 continue;
3101 node = lookup_info_hash_table (stash->funcinfo_hash_table,
3102 each_func->name);
3103 BFD_ASSERT (node);
3104 found = FALSE;
3105 while (node && !found)
3106 {
3107 found = node->info == each_func;
3108 node = node->next;
3109 }
3110 BFD_ASSERT (found);
3111 }
3112
3113 for (each_var = each_unit->variable_table;
3114 each_var;
3115 each_var = each_var->prev_var)
3116 {
3117 if (!each_var->name || !each_var->file || each_var->stack)
3118 continue;
3119 node = lookup_info_hash_table (stash->varinfo_hash_table,
3120 each_var->name);
3121 BFD_ASSERT (node);
3122 found = FALSE;
3123 while (node && !found)
3124 {
3125 found = node->info == each_var;
3126 node = node->next;
3127 }
3128 BFD_ASSERT (found);
3129 }
3130 }
3131}
3132
3133/* Check to see if we want to enable the info hash tables, which consume
3134 quite a bit of memory. Currently we only check the number times
3135 bfd_dwarf2_find_line is called. In the future, we may also want to
3136 take the number of symbols into account. */
3137
3138static void
3139stash_maybe_enable_info_hash_tables (bfd *abfd, struct dwarf2_debug *stash)
3140{
3141 BFD_ASSERT (stash->info_hash_status == STASH_INFO_HASH_OFF);
3142
3143 if (stash->info_hash_count++ < STASH_INFO_HASH_TRIGGER)
3144 return;
3145
3146 /* FIXME: Maybe we should check the reduce_memory_overheads
3147 and optimize fields in the bfd_link_info structure ? */
3148
3149 /* Create hash tables. */
3150 stash->funcinfo_hash_table = create_info_hash_table (abfd);
3151 stash->varinfo_hash_table = create_info_hash_table (abfd);
3152 if (!stash->funcinfo_hash_table || !stash->varinfo_hash_table)
3153 {
3154 /* Turn off info hashes if any allocation above fails. */
3155 stash->info_hash_status = STASH_INFO_HASH_DISABLED;
3156 return;
3157 }
3158 /* We need a forced update so that the info hash tables will
3159 be created even though there is no compilation unit. That
3160 happens if STASH_INFO_HASH_TRIGGER is 0. */
3161 stash_maybe_update_info_hash_tables (stash);
3162 stash->info_hash_status = STASH_INFO_HASH_ON;
3163}
3164
3165/* Find the file and line associated with a symbol and address using the
3166 info hash tables of a stash. If there is a match, the function returns
3167 TRUE and update the locations pointed to by filename_ptr and linenumber_ptr;
3168 otherwise it returns FALSE. */
3169
3170static bfd_boolean
3171stash_find_line_fast (struct dwarf2_debug *stash,
3172 asymbol *sym,
3173 bfd_vma addr,
3174 const char **filename_ptr,
3175 unsigned int *linenumber_ptr)
3176{
3177 BFD_ASSERT (stash->info_hash_status == STASH_INFO_HASH_ON);
3178
3179 if (sym->flags & BSF_FUNCTION)
3180 return info_hash_lookup_funcinfo (stash->funcinfo_hash_table, sym, addr,
3181 filename_ptr, linenumber_ptr);
3182 return info_hash_lookup_varinfo (stash->varinfo_hash_table, sym, addr,
3183 filename_ptr, linenumber_ptr);
3184}
3185
2ca7691a
TG
3186/* Read debug information from DEBUG_BFD when DEBUG_BFD is specified.
3187 If DEBUG_BFD is not specified, we read debug information from ABFD
3188 or its gnu_debuglink. The results will be stored in PINFO.
3189 The function returns TRUE iff debug information is ready. */
3190
3191bfd_boolean
3192_bfd_dwarf2_slurp_debug_info (bfd *abfd, bfd *debug_bfd,
3193 const struct dwarf_debug_section *debug_sections,
3194 asymbol **symbols,
3195 void **pinfo)
3196{
3197 bfd_size_type amt = sizeof (struct dwarf2_debug);
3198 bfd_size_type total_size;
3199 asection *msec;
3200 struct dwarf2_debug *stash = (struct dwarf2_debug *) *pinfo;
3201
3202 if (stash != NULL)
3203 return TRUE;
3204
3205 stash = (struct dwarf2_debug *) bfd_zalloc (abfd, amt);
3206 if (! stash)
3207 return FALSE;
3208 stash->debug_sections = debug_sections;
3209
3210 *pinfo = stash;
3211
3212 if (debug_bfd == NULL)
3213 debug_bfd = abfd;
3214
3215 msec = find_debug_info (debug_bfd, debug_sections, NULL);
3216 if (msec == NULL && abfd == debug_bfd)
3217 {
3218 char * debug_filename = bfd_follow_gnu_debuglink (abfd, DEBUGDIR);
3219
3220 if (debug_filename == NULL)
3221 /* No dwarf2 info, and no gnu_debuglink to follow.
3222 Note that at this point the stash has been allocated, but
3223 contains zeros. This lets future calls to this function
3224 fail more quickly. */
3225 return FALSE;
3226
3227 if ((debug_bfd = bfd_openr (debug_filename, NULL)) == NULL
3228 || ! bfd_check_format (debug_bfd, bfd_object)
3229 || (msec = find_debug_info (debug_bfd,
3230 debug_sections, NULL)) == NULL)
3231 {
3232 if (debug_bfd)
3233 bfd_close (debug_bfd);
3234 /* FIXME: Should we report our failure to follow the debuglink ? */
3235 free (debug_filename);
3236 return FALSE;
3237 }
3238 }
3239
3240 /* There can be more than one DWARF2 info section in a BFD these
3241 days. First handle the easy case when there's only one. If
3242 there's more than one, try case two: none of the sections is
3243 compressed. In that case, read them all in and produce one
3244 large stash. We do this in two passes - in the first pass we
3245 just accumulate the section sizes, and in the second pass we
3246 read in the section's contents. (The allows us to avoid
3247 reallocing the data as we add sections to the stash.) If
3248 some or all sections are compressed, then do things the slow
3249 way, with a bunch of reallocs. */
3250
3251 if (! find_debug_info (debug_bfd, debug_sections, msec))
3252 {
3253 /* Case 1: only one info section. */
3254 total_size = msec->size;
3255 if (! read_section (debug_bfd, &stash->debug_sections[debug_info],
3256 symbols, 0,
3257 &stash->info_ptr_memory, &total_size))
3258 return FALSE;
3259 }
3260 else
3261 {
3262 /* Case 2: multiple sections. */
3263 for (total_size = 0;
3264 msec;
3265 msec = find_debug_info (debug_bfd, debug_sections, msec))
3266 total_size += msec->size;
3267
3268 stash->info_ptr_memory = (bfd_byte *) bfd_malloc (total_size);
3269 if (stash->info_ptr_memory == NULL)
3270 return FALSE;
3271
3272 total_size = 0;
3273 for (msec = find_debug_info (debug_bfd, debug_sections, NULL);
3274 msec;
3275 msec = find_debug_info (debug_bfd, debug_sections, msec))
3276 {
3277 bfd_size_type size;
3278
3279 size = msec->size;
3280 if (size == 0)
3281 continue;
3282
3283 if (!(bfd_simple_get_relocated_section_contents
3284 (debug_bfd, msec, stash->info_ptr_memory + total_size,
3285 symbols)))
3286 return FALSE;
3287
3288 total_size += size;
3289 }
3290 }
3291
3292 stash->info_ptr = stash->info_ptr_memory;
3293 stash->info_ptr_end = stash->info_ptr + total_size;
3294 stash->sec = find_debug_info (debug_bfd, debug_sections, NULL);
3295 stash->sec_info_ptr = stash->info_ptr;
3296 stash->syms = symbols;
3297 stash->bfd_ptr = debug_bfd;
3298
3299 return TRUE;
3300}
3301
bec42b15
NC
3302/* Find the source code location of SYMBOL. If SYMBOL is NULL
3303 then find the nearest source code location corresponding to
3304 the address SECTION + OFFSET.
3305 Returns TRUE if the line is found without error and fills in
3306 FILENAME_PTR and LINENUMBER_PTR. In the case where SYMBOL was
3307 NULL the FUNCTIONNAME_PTR is also filled in.
3308 SYMBOLS contains the symbol table for ABFD.
fc28f9aa 3309 DEBUG_SECTIONS contains the name of the dwarf debug sections.
bec42b15
NC
3310 ADDR_SIZE is the number of bytes in the initial .debug_info length
3311 field and in the abbreviation offset, or zero to indicate that the
3312 default value should be used. */
252b5132 3313
bec42b15
NC
3314static bfd_boolean
3315find_line (bfd *abfd,
fc28f9aa 3316 const struct dwarf_debug_section *debug_sections,
bec42b15
NC
3317 asection *section,
3318 bfd_vma offset,
3319 asymbol *symbol,
3320 asymbol **symbols,
3321 const char **filename_ptr,
3322 const char **functionname_ptr,
3323 unsigned int *linenumber_ptr,
9b8d1a36 3324 unsigned int *discriminator_ptr,
bec42b15
NC
3325 unsigned int addr_size,
3326 void **pinfo)
252b5132
RH
3327{
3328 /* Read each compilation unit from the section .debug_info, and check
3329 to see if it contains the address we are searching for. If yes,
3330 lookup the address, and return the line number info. If no, go
98591c73 3331 on to the next compilation unit.
252b5132
RH
3332
3333 We keep a list of all the previously read compilation units, and
98591c73 3334 a pointer to the next un-read compilation unit. Check the
a092b084 3335 previously read units before reading more. */
1ba54ee0 3336 struct dwarf2_debug *stash;
a092b084 3337 /* What address are we looking for? */
1ba54ee0 3338 bfd_vma addr;
252b5132 3339 struct comp_unit* each;
d4c32a81 3340 bfd_vma found = FALSE;
bec42b15 3341 bfd_boolean do_line;
d4c32a81 3342
2ca7691a
TG
3343 *filename_ptr = NULL;
3344 if (functionname_ptr != NULL)
3345 *functionname_ptr = NULL;
3346 *linenumber_ptr = 0;
d4c32a81 3347
2ca7691a
TG
3348 if (! _bfd_dwarf2_slurp_debug_info (abfd, NULL,
3349 debug_sections, symbols, pinfo))
3350 return FALSE;
d4c32a81 3351
2ca7691a 3352 stash = (struct dwarf2_debug *) *pinfo;
d4c32a81
L
3353
3354 /* In a relocatable file, 2 functions may have the same address.
3355 We change the section vma so that they won't overlap. */
3356 if ((abfd->flags & (EXEC_P | DYNAMIC)) == 0)
3357 {
3358 if (! place_sections (abfd, stash))
3359 return FALSE;
3360 }
3361
bec42b15
NC
3362 do_line = (section == NULL
3363 && offset == 0
3364 && functionname_ptr == NULL
3365 && symbol != NULL);
3366 if (do_line)
3367 {
3368 addr = symbol->value;
3369 section = bfd_get_section (symbol);
3370 }
3371 else if (section != NULL
3372 && functionname_ptr != NULL
3373 && symbol == NULL)
3374 addr = offset;
3375 else
3376 abort ();
3377
1ba54ee0 3378 if (section->output_section)
6dd55cb7 3379 addr += section->output_section->vma + section->output_offset;
1ba54ee0 3380 else
6dd55cb7 3381 addr += section->vma;
a092b084 3382
98591c73 3383 /* A null info_ptr indicates that there is no dwarf2 info
a092b084 3384 (or that an error occured while setting up the stash). */
252b5132 3385 if (! stash->info_ptr)
2ca7691a 3386 return FALSE;
252b5132 3387
4ab527b0
FF
3388 stash->inliner_chain = NULL;
3389
a092b084 3390 /* Check the previously read comp. units first. */
bd210d54
NC
3391 if (do_line)
3392 {
3393 /* The info hash tables use quite a bit of memory. We may not want to
3394 always use them. We use some heuristics to decide if and when to
3395 turn it on. */
3396 if (stash->info_hash_status == STASH_INFO_HASH_OFF)
3397 stash_maybe_enable_info_hash_tables (abfd, stash);
3398
3399 /* Keep info hash table up to date if they are available. Note that we
3400 may disable the hash tables if there is any error duing update. */
3401 if (stash->info_hash_status == STASH_INFO_HASH_ON)
3402 stash_maybe_update_info_hash_tables (stash);
3403
3404 if (stash->info_hash_status == STASH_INFO_HASH_ON)
3405 {
3406 found = stash_find_line_fast (stash, symbol, addr, filename_ptr,
3407 linenumber_ptr);
3408 if (found)
3409 goto done;
3410 }
0d161102 3411 else
bd210d54
NC
3412 {
3413 /* Check the previously read comp. units first. */
3414 for (each = stash->all_comp_units; each; each = each->next_unit)
3415 if ((symbol->flags & BSF_FUNCTION) == 0
a2a50954 3416 || each->arange.high == 0
bd210d54
NC
3417 || comp_unit_contains_address (each, addr))
3418 {
3419 found = comp_unit_find_line (each, symbol, addr, filename_ptr,
3420 linenumber_ptr, stash);
3421 if (found)
3422 goto done;
3423 }
3424 }
3425 }
3426 else
3427 {
709d67f1
AM
3428 for (each = stash->all_comp_units; each; each = each->next_unit)
3429 {
a2a50954
AM
3430 found = ((each->arange.high == 0
3431 || comp_unit_contains_address (each, addr))
709d67f1
AM
3432 && comp_unit_find_nearest_line (each, addr,
3433 filename_ptr,
3434 functionname_ptr,
3435 linenumber_ptr,
9b8d1a36 3436 discriminator_ptr,
709d67f1
AM
3437 stash));
3438 if (found)
3439 goto done;
3440 }
5420f73d
L
3441 }
3442
5420f73d
L
3443 /* The DWARF2 spec says that the initial length field, and the
3444 offset of the abbreviation table, should both be 4-byte values.
3445 However, some compilers do things differently. */
3446 if (addr_size == 0)
3447 addr_size = 4;
3448 BFD_ASSERT (addr_size == 4 || addr_size == 8);
3449
3450 /* Read each remaining comp. units checking each as they are read. */
3451 while (stash->info_ptr < stash->info_ptr_end)
3452 {
3453 bfd_vma length;
3454 unsigned int offset_size = addr_size;
3455 bfd_byte *info_ptr_unit = stash->info_ptr;
3456
a50b1753 3457 length = read_4_bytes (stash->bfd_ptr, stash->info_ptr);
bec42b15
NC
3458 /* A 0xffffff length is the DWARF3 way of indicating
3459 we use 64-bit offsets, instead of 32-bit offsets. */
5420f73d
L
3460 if (length == 0xffffffff)
3461 {
3462 offset_size = 8;
a50b1753 3463 length = read_8_bytes (stash->bfd_ptr, stash->info_ptr + 4);
5420f73d
L
3464 stash->info_ptr += 12;
3465 }
3466 /* A zero length is the IRIX way of indicating 64-bit offsets,
3467 mostly because the 64-bit length will generally fit in 32
3468 bits, and the endianness helps. */
3469 else if (length == 0)
3470 {
3471 offset_size = 8;
a50b1753 3472 length = read_4_bytes (stash->bfd_ptr, stash->info_ptr + 4);
5420f73d
L
3473 stash->info_ptr += 8;
3474 }
024b2372
CD
3475 /* In the absence of the hints above, we assume 32-bit DWARF2
3476 offsets even for targets with 64-bit addresses, because:
3477 a) most of the time these targets will not have generated
3478 more than 2Gb of debug info and so will not need 64-bit
3479 offsets,
3480 and
3481 b) if they do use 64-bit offsets but they are not using
3482 the size hints that are tested for above then they are
3483 not conforming to the DWARF3 standard anyway. */
5420f73d
L
3484 else if (addr_size == 8)
3485 {
024b2372 3486 offset_size = 4;
2d47a72c 3487 stash->info_ptr += 4;
5420f73d
L
3488 }
3489 else
3490 stash->info_ptr += 4;
3491
3492 if (length > 0)
3493 {
0d161102 3494 each = parse_comp_unit (stash, length, info_ptr_unit,
5420f73d 3495 offset_size);
d74e4b29
NS
3496 if (!each)
3497 /* The dwarf information is damaged, don't trust it any
3498 more. */
3499 break;
5420f73d
L
3500 stash->info_ptr += length;
3501
d74e4b29
NS
3502 if (stash->all_comp_units)
3503 stash->all_comp_units->prev_unit = each;
3504 else
3505 stash->last_comp_unit = each;
3506
3507 each->next_unit = stash->all_comp_units;
3508 stash->all_comp_units = each;
3509
3510 /* DW_AT_low_pc and DW_AT_high_pc are optional for
3511 compilation units. If we don't have them (i.e.,
3512 unit->high == 0), we need to consult the line info table
3513 to see if a compilation unit contains the given
3514 address. */
3515 if (do_line)
3516 found = (((symbol->flags & BSF_FUNCTION) == 0
3517 || each->arange.high == 0
3518 || comp_unit_contains_address (each, addr))
3519 && comp_unit_find_line (each, symbol, addr,
3520 filename_ptr,
3521 linenumber_ptr,
3522 stash));
3523 else
3524 found = ((each->arange.high == 0
3525 || comp_unit_contains_address (each, addr))
3526 && comp_unit_find_nearest_line (each, addr,
3527 filename_ptr,
3528 functionname_ptr,
3529 linenumber_ptr,
9b8d1a36 3530 discriminator_ptr,
d74e4b29 3531 stash));
be04437d
AM
3532
3533 if ((bfd_vma) (stash->info_ptr - stash->sec_info_ptr)
3534 == stash->sec->size)
3535 {
fc28f9aa
TG
3536 stash->sec = find_debug_info (stash->bfd_ptr, debug_sections,
3537 stash->sec);
be04437d
AM
3538 stash->sec_info_ptr = stash->info_ptr;
3539 }
3540
d74e4b29
NS
3541 if (found)
3542 goto done;
5420f73d
L
3543 }
3544 }
3545
a2a50954 3546 done:
d4c32a81
L
3547 if ((abfd->flags & (EXEC_P | DYNAMIC)) == 0)
3548 unset_sections (stash);
3549
3550 return found;
5420f73d
L
3551}
3552
bec42b15
NC
3553/* The DWARF2 version of find_nearest_line.
3554 Return TRUE if the line is found without error. */
3555
3556bfd_boolean
3557_bfd_dwarf2_find_nearest_line (bfd *abfd,
fc28f9aa 3558 const struct dwarf_debug_section *debug_sections,
bec42b15
NC
3559 asection *section,
3560 asymbol **symbols,
3561 bfd_vma offset,
3562 const char **filename_ptr,
3563 const char **functionname_ptr,
3564 unsigned int *linenumber_ptr,
9b8d1a36 3565 unsigned int *discriminator_ptr,
bec42b15
NC
3566 unsigned int addr_size,
3567 void **pinfo)
3568{
fc28f9aa 3569 return find_line (abfd, debug_sections, section, offset, NULL, symbols,
9b8d1a36
CC
3570 filename_ptr, functionname_ptr, linenumber_ptr,
3571 discriminator_ptr, addr_size, pinfo);
bec42b15
NC
3572}
3573
3574/* The DWARF2 version of find_line.
3575 Return TRUE if the line is found without error. */
3576
3577bfd_boolean
3578_bfd_dwarf2_find_line (bfd *abfd,
3579 asymbol **symbols,
3580 asymbol *symbol,
3581 const char **filename_ptr,
3582 unsigned int *linenumber_ptr,
9b8d1a36 3583 unsigned int *discriminator_ptr,
bec42b15
NC
3584 unsigned int addr_size,
3585 void **pinfo)
3586{
fc28f9aa 3587 return find_line (abfd, dwarf_debug_sections, NULL, 0, symbol, symbols,
9b8d1a36
CC
3588 filename_ptr, NULL, linenumber_ptr, discriminator_ptr,
3589 addr_size, pinfo);
bec42b15
NC
3590}
3591
4ab527b0
FF
3592bfd_boolean
3593_bfd_dwarf2_find_inliner_info (bfd *abfd ATTRIBUTE_UNUSED,
3594 const char **filename_ptr,
3595 const char **functionname_ptr,
3596 unsigned int *linenumber_ptr,
3597 void **pinfo)
3598{
3599 struct dwarf2_debug *stash;
3600
a50b1753 3601 stash = (struct dwarf2_debug *) *pinfo;
4ab527b0
FF
3602 if (stash)
3603 {
3604 struct funcinfo *func = stash->inliner_chain;
bec42b15 3605
4ab527b0
FF
3606 if (func && func->caller_func)
3607 {
3608 *filename_ptr = func->caller_file;
3609 *functionname_ptr = func->caller_func->name;
3610 *linenumber_ptr = func->caller_line;
3611 stash->inliner_chain = func->caller_func;
bec42b15 3612 return TRUE;
4ab527b0
FF
3613 }
3614 }
3615
bec42b15 3616 return FALSE;
4ab527b0
FF
3617}
3618
35330cce 3619void
d9071b0c 3620_bfd_dwarf2_cleanup_debug_info (bfd *abfd, void **pinfo)
35330cce 3621{
d9071b0c 3622 struct dwarf2_debug *stash = (struct dwarf2_debug *) *pinfo;;
35330cce 3623 struct comp_unit *each;
35330cce 3624
d9071b0c 3625 if (abfd == NULL || stash == NULL)
35330cce
NC
3626 return;
3627
3628 for (each = stash->all_comp_units; each; each = each->next_unit)
3629 {
34b5e0b2 3630 struct abbrev_info **abbrevs = each->abbrevs;
90b5b1a5
NC
3631 struct funcinfo *function_table = each->function_table;
3632 struct varinfo *variable_table = each->variable_table;
34b5e0b2 3633 size_t i;
35330cce 3634
34b5e0b2 3635 for (i = 0; i < ABBREV_HASH_SIZE; i++)
d8d1c398 3636 {
34b5e0b2 3637 struct abbrev_info *abbrev = abbrevs[i];
35330cce 3638
34b5e0b2 3639 while (abbrev)
d8d1c398 3640 {
34b5e0b2
NC
3641 free (abbrev->attrs);
3642 abbrev = abbrev->next;
d8d1c398
AM
3643 }
3644 }
35330cce
NC
3645
3646 if (each->line_table)
d8d1c398 3647 {
34b5e0b2
NC
3648 free (each->line_table->dirs);
3649 free (each->line_table->files);
d8d1c398 3650 }
90b5b1a5
NC
3651
3652 while (function_table)
3653 {
3654 if (function_table->file)
3655 {
3656 free (function_table->file);
3657 function_table->file = NULL;
3658 }
3659
3660 if (function_table->caller_file)
3661 {
3662 free (function_table->caller_file);
3663 function_table->caller_file = NULL;
3664 }
3665 function_table = function_table->prev_func;
3666 }
3667
3668 while (variable_table)
3669 {
3670 if (variable_table->file)
3671 {
3672 free (variable_table->file);
3673 variable_table->file = NULL;
3674 }
3675
3676 variable_table = variable_table->prev_var;
3677 }
35330cce
NC
3678 }
3679
5d0900eb
AM
3680 if (stash->dwarf_abbrev_buffer)
3681 free (stash->dwarf_abbrev_buffer);
3682 if (stash->dwarf_line_buffer)
3683 free (stash->dwarf_line_buffer);
3684 if (stash->dwarf_str_buffer)
3685 free (stash->dwarf_str_buffer);
3686 if (stash->dwarf_ranges_buffer)
3687 free (stash->dwarf_ranges_buffer);
3688 if (stash->info_ptr_memory)
3689 free (stash->info_ptr_memory);
35330cce 3690}
This page took 1.133075 seconds and 4 git commands to generate.