2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
3 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
5 Adapted from gdb/dwarf2read.c by Gavin Koch of Cygnus Solutions
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
16 This file is part of BFD.
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
20 the Free Software Foundation; either version 3 of the License, or (at
21 your option) any later version.
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.
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
30 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
31 MA 02110-1301, USA. */
35 #include "libiberty.h"
40 /* The data in the .debug_line statement prologue looks like this. */
45 unsigned short version
;
46 bfd_vma prologue_length
;
47 unsigned char minimum_instruction_length
;
48 unsigned char maximum_ops_per_insn
;
49 unsigned char default_is_stmt
;
51 unsigned char line_range
;
52 unsigned char opcode_base
;
53 unsigned char *standard_opcode_lengths
;
56 /* Attributes have a name and a value. */
60 enum dwarf_attribute name
;
65 struct dwarf_block
*blk
;
72 /* Blocks are a bunch of untyped bytes. */
79 struct adjusted_section
87 /* A list of all previously read comp_units. */
88 struct comp_unit
*all_comp_units
;
90 /* Last comp unit in list above. */
91 struct comp_unit
*last_comp_unit
;
93 /* The next unread compilation unit within the .debug_info section.
94 Zero indicates that the .debug_info section has not been loaded
98 /* Pointer to the end of the .debug_info section memory buffer. */
99 bfd_byte
*info_ptr_end
;
101 /* Pointer to the bfd, section and address of the beginning of the
102 section. The bfd might be different than expected because of
103 gnu_debuglink sections. */
106 bfd_byte
*sec_info_ptr
;
108 /* A pointer to the memory block allocated for info_ptr. Neither
109 info_ptr nor sec_info_ptr are guaranteed to stay pointing to the
110 beginning of the malloc block. This is used only to free the
112 bfd_byte
*info_ptr_memory
;
114 /* Pointer to the symbol table. */
117 /* Pointer to the .debug_abbrev section loaded into memory. */
118 bfd_byte
*dwarf_abbrev_buffer
;
120 /* Length of the loaded .debug_abbrev section. */
121 bfd_size_type dwarf_abbrev_size
;
123 /* Buffer for decode_line_info. */
124 bfd_byte
*dwarf_line_buffer
;
126 /* Length of the loaded .debug_line section. */
127 bfd_size_type dwarf_line_size
;
129 /* Pointer to the .debug_str section loaded into memory. */
130 bfd_byte
*dwarf_str_buffer
;
132 /* Length of the loaded .debug_str section. */
133 bfd_size_type dwarf_str_size
;
135 /* Pointer to the .debug_ranges section loaded into memory. */
136 bfd_byte
*dwarf_ranges_buffer
;
138 /* Length of the loaded .debug_ranges section. */
139 bfd_size_type dwarf_ranges_size
;
141 /* If the most recent call to bfd_find_nearest_line was given an
142 address in an inlined function, preserve a pointer into the
143 calling chain for subsequent calls to bfd_find_inliner_info to
145 struct funcinfo
*inliner_chain
;
147 /* Number of sections whose VMA we must adjust. */
148 unsigned int adjusted_section_count
;
150 /* Array of sections with adjusted VMA. */
151 struct adjusted_section
*adjusted_sections
;
153 /* Number of times find_line is called. This is used in
154 the heuristic for enabling the info hash tables. */
157 #define STASH_INFO_HASH_TRIGGER 100
159 /* Hash table mapping symbol names to function infos. */
160 struct info_hash_table
*funcinfo_hash_table
;
162 /* Hash table mapping symbol names to variable infos. */
163 struct info_hash_table
*varinfo_hash_table
;
165 /* Head of comp_unit list in the last hash table update. */
166 struct comp_unit
*hash_units_head
;
168 /* Status of info hash. */
169 int info_hash_status
;
170 #define STASH_INFO_HASH_OFF 0
171 #define STASH_INFO_HASH_ON 1
172 #define STASH_INFO_HASH_DISABLED 2
182 /* A minimal decoding of DWARF2 compilation units. We only decode
183 what's needed to get to the line number information. */
187 /* Chain the previously read compilation units. */
188 struct comp_unit
*next_unit
;
190 /* Likewise, chain the compilation unit read after this one.
191 The comp units are stored in reversed reading order. */
192 struct comp_unit
*prev_unit
;
194 /* Keep the bfd convenient (for memory allocation). */
197 /* The lowest and highest addresses contained in this compilation
198 unit as specified in the compilation unit header. */
199 struct arange arange
;
201 /* The DW_AT_name attribute (for error messages). */
204 /* The abbrev hash table. */
205 struct abbrev_info
**abbrevs
;
207 /* Note that an error was found by comp_unit_find_nearest_line. */
210 /* The DW_AT_comp_dir attribute. */
213 /* TRUE if there is a line number table associated with this comp. unit. */
216 /* Pointer to the current comp_unit so that we can find a given entry
218 bfd_byte
*info_ptr_unit
;
220 /* Pointer to the start of the debug section, for DW_FORM_ref_addr. */
221 bfd_byte
*sec_info_ptr
;
223 /* The offset into .debug_line of the line number table. */
224 unsigned long line_offset
;
226 /* Pointer to the first child die for the comp unit. */
227 bfd_byte
*first_child_die_ptr
;
229 /* The end of the comp unit. */
232 /* The decoded line number, NULL if not yet decoded. */
233 struct line_info_table
*line_table
;
235 /* A list of the functions found in this comp. unit. */
236 struct funcinfo
*function_table
;
238 /* A list of the variables found in this comp. unit. */
239 struct varinfo
*variable_table
;
241 /* Pointer to dwarf2_debug structure. */
242 struct dwarf2_debug
*stash
;
244 /* DWARF format version for this unit - from unit header. */
247 /* Address size for this unit - from unit header. */
248 unsigned char addr_size
;
250 /* Offset size for this unit - from unit header. */
251 unsigned char offset_size
;
253 /* Base address for this unit - from DW_AT_low_pc attribute of
254 DW_TAG_compile_unit DIE */
255 bfd_vma base_address
;
257 /* TRUE if symbols are cached in hash table for faster lookup by name. */
261 /* This data structure holds the information of an abbrev. */
264 unsigned int number
; /* Number identifying abbrev. */
265 enum dwarf_tag tag
; /* DWARF tag. */
266 int has_children
; /* Boolean. */
267 unsigned int num_attrs
; /* Number of attributes. */
268 struct attr_abbrev
*attrs
; /* An array of attribute descriptions. */
269 struct abbrev_info
*next
; /* Next in chain. */
274 enum dwarf_attribute name
;
275 enum dwarf_form form
;
278 /* Map of uncompressed DWARF debug section name to compressed one. It
279 is terminated by NULL uncompressed_name. */
281 const struct dwarf_debug_section dwarf_debug_sections
[] =
283 { ".debug_abbrev", ".zdebug_abbrev" },
284 { ".debug_aranges", ".zdebug_aranges" },
285 { ".debug_frame", ".zdebug_frame" },
286 { ".debug_info", ".zdebug_info" },
287 { ".debug_line", ".zdebug_line" },
288 { ".debug_loc", ".zdebug_loc" },
289 { ".debug_macinfo", ".zdebug_macinfo" },
290 { ".debug_macro", ".zdebug_macro" },
291 { ".debug_pubnames", ".zdebug_pubnames" },
292 { ".debug_pubtypes", ".zdebug_pubtypes" },
293 { ".debug_ranges", ".zdebug_ranges" },
294 { ".debug_static_func", ".zdebug_static_func" },
295 { ".debug_static_vars", ".zdebug_static_vars" },
296 { ".debug_str", ".zdebug_str", },
297 { ".debug_types", ".zdebug_types" },
298 /* GNU DWARF 1 extensions */
299 { ".debug_sfnames", ".zdebug_sfnames" },
300 { ".debug_srcinfo", ".zebug_srcinfo" },
301 /* SGI/MIPS DWARF 2 extensions */
302 { ".debug_funcnames", ".zdebug_funcnames" },
303 { ".debug_typenames", ".zdebug_typenames" },
304 { ".debug_varnames", ".zdebug_varnames" },
305 { ".debug_weaknames", ".zdebug_weaknames" },
309 enum dwarf_debug_section_enum
334 #ifndef ABBREV_HASH_SIZE
335 #define ABBREV_HASH_SIZE 121
337 #ifndef ATTR_ALLOC_CHUNK
338 #define ATTR_ALLOC_CHUNK 4
341 /* Variable and function hash tables. This is used to speed up look-up
342 in lookup_symbol_in_var_table() and lookup_symbol_in_function_table().
343 In order to share code between variable and function infos, we use
344 a list of untyped pointer for all variable/function info associated with
345 a symbol. We waste a bit of memory for list with one node but that
346 simplifies the code. */
348 struct info_list_node
350 struct info_list_node
*next
;
354 /* Info hash entry. */
355 struct info_hash_entry
357 struct bfd_hash_entry root
;
358 struct info_list_node
*head
;
361 struct info_hash_table
363 struct bfd_hash_table base
;
366 /* Function to create a new entry in info hash table. */
368 static struct bfd_hash_entry
*
369 info_hash_table_newfunc (struct bfd_hash_entry
*entry
,
370 struct bfd_hash_table
*table
,
373 struct info_hash_entry
*ret
= (struct info_hash_entry
*) entry
;
375 /* Allocate the structure if it has not already been allocated by a
379 ret
= (struct info_hash_entry
*) bfd_hash_allocate (table
,
385 /* Call the allocation method of the base class. */
386 ret
= ((struct info_hash_entry
*)
387 bfd_hash_newfunc ((struct bfd_hash_entry
*) ret
, table
, string
));
389 /* Initialize the local fields here. */
393 return (struct bfd_hash_entry
*) ret
;
396 /* Function to create a new info hash table. It returns a pointer to the
397 newly created table or NULL if there is any error. We need abfd
398 solely for memory allocation. */
400 static struct info_hash_table
*
401 create_info_hash_table (bfd
*abfd
)
403 struct info_hash_table
*hash_table
;
405 hash_table
= (struct info_hash_table
*)
406 bfd_alloc (abfd
, sizeof (struct info_hash_table
));
410 if (!bfd_hash_table_init (&hash_table
->base
, info_hash_table_newfunc
,
411 sizeof (struct info_hash_entry
)))
413 bfd_release (abfd
, hash_table
);
420 /* Insert an info entry into an info hash table. We do not check of
421 duplicate entries. Also, the caller need to guarantee that the
422 right type of info in inserted as info is passed as a void* pointer.
423 This function returns true if there is no error. */
426 insert_info_hash_table (struct info_hash_table
*hash_table
,
431 struct info_hash_entry
*entry
;
432 struct info_list_node
*node
;
434 entry
= (struct info_hash_entry
*) bfd_hash_lookup (&hash_table
->base
,
439 node
= (struct info_list_node
*) bfd_hash_allocate (&hash_table
->base
,
445 node
->next
= entry
->head
;
451 /* Look up an info entry list from an info hash table. Return NULL
454 static struct info_list_node
*
455 lookup_info_hash_table (struct info_hash_table
*hash_table
, const char *key
)
457 struct info_hash_entry
*entry
;
459 entry
= (struct info_hash_entry
*) bfd_hash_lookup (&hash_table
->base
, key
,
461 return entry
? entry
->head
: NULL
;
464 /* Read a section into its appropriate place in the dwarf2_debug
465 struct (indicated by SECTION_BUFFER and SECTION_SIZE). If SYMS is
466 not NULL, use bfd_simple_get_relocated_section_contents to read the
467 section contents, otherwise use bfd_get_section_contents. Fail if
468 the located section does not contain at least OFFSET bytes. */
471 read_section (bfd
* abfd
,
472 enum dwarf_debug_section_enum sec
,
475 bfd_byte
** section_buffer
,
476 bfd_size_type
* section_size
)
479 const char *section_name
= dwarf_debug_sections
[sec
].uncompressed_name
;
481 /* read_section is a noop if the section has already been read. */
482 if (!*section_buffer
)
484 msec
= bfd_get_section_by_name (abfd
, section_name
);
487 section_name
= dwarf_debug_sections
[sec
].compressed_name
;
488 msec
= bfd_get_section_by_name (abfd
, section_name
);
492 (*_bfd_error_handler
) (_("Dwarf Error: Can't find %s section."), section_name
);
493 bfd_set_error (bfd_error_bad_value
);
497 *section_size
= msec
->rawsize
? msec
->rawsize
: msec
->size
;
501 = bfd_simple_get_relocated_section_contents (abfd
, msec
, NULL
, syms
);
502 if (! *section_buffer
)
507 *section_buffer
= (bfd_byte
*) bfd_malloc (*section_size
);
508 if (! *section_buffer
)
510 if (! bfd_get_section_contents (abfd
, msec
, *section_buffer
,
516 /* It is possible to get a bad value for the offset into the section
517 that the client wants. Validate it here to avoid trouble later. */
518 if (offset
!= 0 && offset
>= *section_size
)
520 (*_bfd_error_handler
) (_("Dwarf Error: Offset (%lu) greater than or equal to %s size (%lu)."),
521 (long) offset
, section_name
, *section_size
);
522 bfd_set_error (bfd_error_bad_value
);
530 The following function up to the END VERBATIM mark are
531 copied directly from dwarf2read.c. */
533 /* Read dwarf information from a buffer. */
536 read_1_byte (bfd
*abfd ATTRIBUTE_UNUSED
, bfd_byte
*buf
)
538 return bfd_get_8 (abfd
, buf
);
542 read_1_signed_byte (bfd
*abfd ATTRIBUTE_UNUSED
, bfd_byte
*buf
)
544 return bfd_get_signed_8 (abfd
, buf
);
548 read_2_bytes (bfd
*abfd
, bfd_byte
*buf
)
550 return bfd_get_16 (abfd
, buf
);
554 read_4_bytes (bfd
*abfd
, bfd_byte
*buf
)
556 return bfd_get_32 (abfd
, buf
);
560 read_8_bytes (bfd
*abfd
, bfd_byte
*buf
)
562 return bfd_get_64 (abfd
, buf
);
566 read_n_bytes (bfd
*abfd ATTRIBUTE_UNUSED
,
568 unsigned int size ATTRIBUTE_UNUSED
)
574 read_string (bfd
*abfd ATTRIBUTE_UNUSED
,
576 unsigned int *bytes_read_ptr
)
578 /* Return a pointer to the embedded string. */
579 char *str
= (char *) buf
;
587 *bytes_read_ptr
= strlen (str
) + 1;
594 read_indirect_string (struct comp_unit
* unit
,
596 unsigned int * bytes_read_ptr
)
599 struct dwarf2_debug
*stash
= unit
->stash
;
602 if (unit
->offset_size
== 4)
603 offset
= read_4_bytes (unit
->abfd
, buf
);
605 offset
= read_8_bytes (unit
->abfd
, buf
);
607 *bytes_read_ptr
= unit
->offset_size
;
609 if (! read_section (unit
->abfd
, debug_str
, stash
->syms
, offset
,
610 &stash
->dwarf_str_buffer
, &stash
->dwarf_str_size
))
613 str
= (char *) stash
->dwarf_str_buffer
+ offset
;
620 read_address (struct comp_unit
*unit
, bfd_byte
*buf
)
622 int signed_vma
= get_elf_backend_data (unit
->abfd
)->sign_extend_vma
;
626 switch (unit
->addr_size
)
629 return bfd_get_signed_64 (unit
->abfd
, buf
);
631 return bfd_get_signed_32 (unit
->abfd
, buf
);
633 return bfd_get_signed_16 (unit
->abfd
, buf
);
640 switch (unit
->addr_size
)
643 return bfd_get_64 (unit
->abfd
, buf
);
645 return bfd_get_32 (unit
->abfd
, buf
);
647 return bfd_get_16 (unit
->abfd
, buf
);
654 /* Lookup an abbrev_info structure in the abbrev hash table. */
656 static struct abbrev_info
*
657 lookup_abbrev (unsigned int number
, struct abbrev_info
**abbrevs
)
659 unsigned int hash_number
;
660 struct abbrev_info
*abbrev
;
662 hash_number
= number
% ABBREV_HASH_SIZE
;
663 abbrev
= abbrevs
[hash_number
];
667 if (abbrev
->number
== number
)
670 abbrev
= abbrev
->next
;
676 /* In DWARF version 2, the description of the debugging information is
677 stored in a separate .debug_abbrev section. Before we read any
678 dies from a section we read in all abbreviations and install them
681 static struct abbrev_info
**
682 read_abbrevs (bfd
*abfd
, bfd_uint64_t offset
, struct dwarf2_debug
*stash
)
684 struct abbrev_info
**abbrevs
;
685 bfd_byte
*abbrev_ptr
;
686 struct abbrev_info
*cur_abbrev
;
687 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
688 unsigned int abbrev_form
, hash_number
;
691 if (! read_section (abfd
, debug_abbrev
, stash
->syms
, offset
,
692 &stash
->dwarf_abbrev_buffer
, &stash
->dwarf_abbrev_size
))
695 amt
= sizeof (struct abbrev_info
*) * ABBREV_HASH_SIZE
;
696 abbrevs
= (struct abbrev_info
**) bfd_zalloc (abfd
, amt
);
700 abbrev_ptr
= stash
->dwarf_abbrev_buffer
+ offset
;
701 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
702 abbrev_ptr
+= bytes_read
;
704 /* Loop until we reach an abbrev number of 0. */
705 while (abbrev_number
)
707 amt
= sizeof (struct abbrev_info
);
708 cur_abbrev
= (struct abbrev_info
*) bfd_zalloc (abfd
, amt
);
709 if (cur_abbrev
== NULL
)
712 /* Read in abbrev header. */
713 cur_abbrev
->number
= abbrev_number
;
714 cur_abbrev
->tag
= (enum dwarf_tag
)
715 read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
716 abbrev_ptr
+= bytes_read
;
717 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
720 /* Now read in declarations. */
721 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
722 abbrev_ptr
+= bytes_read
;
723 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
724 abbrev_ptr
+= bytes_read
;
728 if ((cur_abbrev
->num_attrs
% ATTR_ALLOC_CHUNK
) == 0)
730 struct attr_abbrev
*tmp
;
732 amt
= cur_abbrev
->num_attrs
+ ATTR_ALLOC_CHUNK
;
733 amt
*= sizeof (struct attr_abbrev
);
734 tmp
= (struct attr_abbrev
*) bfd_realloc (cur_abbrev
->attrs
, amt
);
739 for (i
= 0; i
< ABBREV_HASH_SIZE
; i
++)
741 struct abbrev_info
*abbrev
= abbrevs
[i
];
745 free (abbrev
->attrs
);
746 abbrev
= abbrev
->next
;
751 cur_abbrev
->attrs
= tmp
;
754 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
].name
755 = (enum dwarf_attribute
) abbrev_name
;
756 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
++].form
757 = (enum dwarf_form
) abbrev_form
;
758 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
759 abbrev_ptr
+= bytes_read
;
760 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
761 abbrev_ptr
+= bytes_read
;
764 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
765 cur_abbrev
->next
= abbrevs
[hash_number
];
766 abbrevs
[hash_number
] = cur_abbrev
;
768 /* Get next abbreviation.
769 Under Irix6 the abbreviations for a compilation unit are not
770 always properly terminated with an abbrev number of 0.
771 Exit loop if we encounter an abbreviation which we have
772 already read (which means we are about to read the abbreviations
773 for the next compile unit) or if the end of the abbreviation
775 if ((unsigned int) (abbrev_ptr
- stash
->dwarf_abbrev_buffer
)
776 >= stash
->dwarf_abbrev_size
)
778 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
779 abbrev_ptr
+= bytes_read
;
780 if (lookup_abbrev (abbrev_number
,abbrevs
) != NULL
)
787 /* Read an attribute value described by an attribute form. */
790 read_attribute_value (struct attribute
*attr
,
792 struct comp_unit
*unit
,
795 bfd
*abfd
= unit
->abfd
;
796 unsigned int bytes_read
;
797 struct dwarf_block
*blk
;
800 attr
->form
= (enum dwarf_form
) form
;
804 case DW_FORM_ref_addr
:
805 /* DW_FORM_ref_addr is an address in DWARF2, and an offset in
807 if (unit
->version
== 3 || unit
->version
== 4)
809 if (unit
->offset_size
== 4)
810 attr
->u
.val
= read_4_bytes (unit
->abfd
, info_ptr
);
812 attr
->u
.val
= read_8_bytes (unit
->abfd
, info_ptr
);
813 info_ptr
+= unit
->offset_size
;
818 attr
->u
.val
= read_address (unit
, info_ptr
);
819 info_ptr
+= unit
->addr_size
;
821 case DW_FORM_sec_offset
:
822 if (unit
->offset_size
== 4)
823 attr
->u
.val
= read_4_bytes (unit
->abfd
, info_ptr
);
825 attr
->u
.val
= read_8_bytes (unit
->abfd
, info_ptr
);
826 info_ptr
+= unit
->offset_size
;
829 amt
= sizeof (struct dwarf_block
);
830 blk
= (struct dwarf_block
*) bfd_alloc (abfd
, amt
);
833 blk
->size
= read_2_bytes (abfd
, info_ptr
);
835 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
836 info_ptr
+= blk
->size
;
840 amt
= sizeof (struct dwarf_block
);
841 blk
= (struct dwarf_block
*) bfd_alloc (abfd
, amt
);
844 blk
->size
= read_4_bytes (abfd
, info_ptr
);
846 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
847 info_ptr
+= blk
->size
;
851 attr
->u
.val
= read_2_bytes (abfd
, info_ptr
);
855 attr
->u
.val
= read_4_bytes (abfd
, info_ptr
);
859 attr
->u
.val
= read_8_bytes (abfd
, info_ptr
);
863 attr
->u
.str
= read_string (abfd
, info_ptr
, &bytes_read
);
864 info_ptr
+= bytes_read
;
867 attr
->u
.str
= read_indirect_string (unit
, info_ptr
, &bytes_read
);
868 info_ptr
+= bytes_read
;
870 case DW_FORM_exprloc
:
872 amt
= sizeof (struct dwarf_block
);
873 blk
= (struct dwarf_block
*) bfd_alloc (abfd
, amt
);
876 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
877 info_ptr
+= bytes_read
;
878 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
879 info_ptr
+= blk
->size
;
883 amt
= sizeof (struct dwarf_block
);
884 blk
= (struct dwarf_block
*) bfd_alloc (abfd
, amt
);
887 blk
->size
= read_1_byte (abfd
, info_ptr
);
889 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
890 info_ptr
+= blk
->size
;
894 attr
->u
.val
= read_1_byte (abfd
, info_ptr
);
898 attr
->u
.val
= read_1_byte (abfd
, info_ptr
);
901 case DW_FORM_flag_present
:
905 attr
->u
.sval
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
906 info_ptr
+= bytes_read
;
909 attr
->u
.val
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
910 info_ptr
+= bytes_read
;
913 attr
->u
.val
= read_1_byte (abfd
, info_ptr
);
917 attr
->u
.val
= read_2_bytes (abfd
, info_ptr
);
921 attr
->u
.val
= read_4_bytes (abfd
, info_ptr
);
925 attr
->u
.val
= read_8_bytes (abfd
, info_ptr
);
928 case DW_FORM_ref_sig8
:
929 attr
->u
.val
= read_8_bytes (abfd
, info_ptr
);
932 case DW_FORM_ref_udata
:
933 attr
->u
.val
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
934 info_ptr
+= bytes_read
;
936 case DW_FORM_indirect
:
937 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
938 info_ptr
+= bytes_read
;
939 info_ptr
= read_attribute_value (attr
, form
, unit
, info_ptr
);
942 (*_bfd_error_handler
) (_("Dwarf Error: Invalid or unhandled FORM value: %u."),
944 bfd_set_error (bfd_error_bad_value
);
950 /* Read an attribute described by an abbreviated attribute. */
953 read_attribute (struct attribute
*attr
,
954 struct attr_abbrev
*abbrev
,
955 struct comp_unit
*unit
,
958 attr
->name
= abbrev
->name
;
959 info_ptr
= read_attribute_value (attr
, abbrev
->form
, unit
, info_ptr
);
963 /* Source line information table routines. */
965 #define FILE_ALLOC_CHUNK 5
966 #define DIR_ALLOC_CHUNK 5
970 struct line_info
* prev_line
;
975 unsigned char op_index
;
976 unsigned char end_sequence
; /* End of (sequential) code sequence. */
990 struct line_sequence
* prev_sequence
;
991 struct line_info
* last_line
; /* Largest VMA. */
994 struct line_info_table
997 unsigned int num_files
;
998 unsigned int num_dirs
;
999 unsigned int num_sequences
;
1002 struct fileinfo
* files
;
1003 struct line_sequence
* sequences
;
1004 struct line_info
* lcl_head
; /* Local head; used in 'add_line_info'. */
1007 /* Remember some information about each function. If the function is
1008 inlined (DW_TAG_inlined_subroutine) it may have two additional
1009 attributes, DW_AT_call_file and DW_AT_call_line, which specify the
1010 source code location where this function was inlined. */
1014 struct funcinfo
*prev_func
; /* Pointer to previous function in list of all functions */
1015 struct funcinfo
*caller_func
; /* Pointer to function one scope higher */
1016 char *caller_file
; /* Source location file name where caller_func inlines this func */
1017 int caller_line
; /* Source location line number where caller_func inlines this func */
1018 char *file
; /* Source location file name */
1019 int line
; /* Source location line number */
1022 struct arange arange
;
1023 asection
*sec
; /* Where the symbol is defined */
1028 /* Pointer to previous variable in list of all variables */
1029 struct varinfo
*prev_var
;
1030 /* Source location file name */
1032 /* Source location line number */
1037 /* Where the symbol is defined */
1039 /* Is this a stack variable? */
1040 unsigned int stack
: 1;
1043 /* Return TRUE if NEW_LINE should sort after LINE. */
1045 static inline bfd_boolean
1046 new_line_sorts_after (struct line_info
*new_line
, struct line_info
*line
)
1048 return (new_line
->address
> line
->address
1049 || (new_line
->address
== line
->address
1050 && (new_line
->op_index
> line
->op_index
1051 || (new_line
->op_index
== line
->op_index
1052 && new_line
->end_sequence
< line
->end_sequence
))));
1056 /* Adds a new entry to the line_info list in the line_info_table, ensuring
1057 that the list is sorted. Note that the line_info list is sorted from
1058 highest to lowest VMA (with possible duplicates); that is,
1059 line_info->prev_line always accesses an equal or smaller VMA. */
1062 add_line_info (struct line_info_table
*table
,
1064 unsigned char op_index
,
1067 unsigned int column
,
1070 bfd_size_type amt
= sizeof (struct line_info
);
1071 struct line_sequence
* seq
= table
->sequences
;
1072 struct line_info
* info
= (struct line_info
*) bfd_alloc (table
->abfd
, amt
);
1077 /* Set member data of 'info'. */
1078 info
->prev_line
= NULL
;
1079 info
->address
= address
;
1080 info
->op_index
= op_index
;
1082 info
->column
= column
;
1083 info
->end_sequence
= end_sequence
;
1085 if (filename
&& filename
[0])
1087 info
->filename
= (char *) bfd_alloc (table
->abfd
, strlen (filename
) + 1);
1088 if (info
->filename
== NULL
)
1090 strcpy (info
->filename
, filename
);
1093 info
->filename
= NULL
;
1095 /* Find the correct location for 'info'. Normally we will receive
1096 new line_info data 1) in order and 2) with increasing VMAs.
1097 However some compilers break the rules (cf. decode_line_info) and
1098 so we include some heuristics for quickly finding the correct
1099 location for 'info'. In particular, these heuristics optimize for
1100 the common case in which the VMA sequence that we receive is a
1101 list of locally sorted VMAs such as
1102 p...z a...j (where a < j < p < z)
1104 Note: table->lcl_head is used to head an *actual* or *possible*
1105 sub-sequence within the list (such as a...j) that is not directly
1106 headed by table->last_line
1108 Note: we may receive duplicate entries from 'decode_line_info'. */
1111 && seq
->last_line
->address
== address
1112 && seq
->last_line
->op_index
== op_index
1113 && seq
->last_line
->end_sequence
== end_sequence
)
1115 /* We only keep the last entry with the same address and end
1116 sequence. See PR ld/4986. */
1117 if (table
->lcl_head
== seq
->last_line
)
1118 table
->lcl_head
= info
;
1119 info
->prev_line
= seq
->last_line
->prev_line
;
1120 seq
->last_line
= info
;
1122 else if (!seq
|| seq
->last_line
->end_sequence
)
1124 /* Start a new line sequence. */
1125 amt
= sizeof (struct line_sequence
);
1126 seq
= (struct line_sequence
*) bfd_malloc (amt
);
1129 seq
->low_pc
= address
;
1130 seq
->prev_sequence
= table
->sequences
;
1131 seq
->last_line
= info
;
1132 table
->lcl_head
= info
;
1133 table
->sequences
= seq
;
1134 table
->num_sequences
++;
1136 else if (new_line_sorts_after (info
, seq
->last_line
))
1138 /* Normal case: add 'info' to the beginning of the current sequence. */
1139 info
->prev_line
= seq
->last_line
;
1140 seq
->last_line
= info
;
1142 /* lcl_head: initialize to head a *possible* sequence at the end. */
1143 if (!table
->lcl_head
)
1144 table
->lcl_head
= info
;
1146 else if (!new_line_sorts_after (info
, table
->lcl_head
)
1147 && (!table
->lcl_head
->prev_line
1148 || new_line_sorts_after (info
, table
->lcl_head
->prev_line
)))
1150 /* Abnormal but easy: lcl_head is the head of 'info'. */
1151 info
->prev_line
= table
->lcl_head
->prev_line
;
1152 table
->lcl_head
->prev_line
= info
;
1156 /* Abnormal and hard: Neither 'last_line' nor 'lcl_head'
1157 are valid heads for 'info'. Reset 'lcl_head'. */
1158 struct line_info
* li2
= seq
->last_line
; /* Always non-NULL. */
1159 struct line_info
* li1
= li2
->prev_line
;
1163 if (!new_line_sorts_after (info
, li2
)
1164 && new_line_sorts_after (info
, li1
))
1167 li2
= li1
; /* always non-NULL */
1168 li1
= li1
->prev_line
;
1170 table
->lcl_head
= li2
;
1171 info
->prev_line
= table
->lcl_head
->prev_line
;
1172 table
->lcl_head
->prev_line
= info
;
1173 if (address
< seq
->low_pc
)
1174 seq
->low_pc
= address
;
1179 /* Extract a fully qualified filename from a line info table.
1180 The returned string has been malloc'ed and it is the caller's
1181 responsibility to free it. */
1184 concat_filename (struct line_info_table
*table
, unsigned int file
)
1188 if (file
- 1 >= table
->num_files
)
1190 /* FILE == 0 means unknown. */
1192 (*_bfd_error_handler
)
1193 (_("Dwarf Error: mangled line number section (bad file number)."));
1194 return strdup ("<unknown>");
1197 filename
= table
->files
[file
- 1].name
;
1199 if (!IS_ABSOLUTE_PATH (filename
))
1201 char *dir_name
= NULL
;
1202 char *subdir_name
= NULL
;
1206 if (table
->files
[file
- 1].dir
)
1207 subdir_name
= table
->dirs
[table
->files
[file
- 1].dir
- 1];
1209 if (!subdir_name
|| !IS_ABSOLUTE_PATH (subdir_name
))
1210 dir_name
= table
->comp_dir
;
1214 dir_name
= subdir_name
;
1219 return strdup (filename
);
1221 len
= strlen (dir_name
) + strlen (filename
) + 2;
1225 len
+= strlen (subdir_name
) + 1;
1226 name
= (char *) bfd_malloc (len
);
1228 sprintf (name
, "%s/%s/%s", dir_name
, subdir_name
, filename
);
1232 name
= (char *) bfd_malloc (len
);
1234 sprintf (name
, "%s/%s", dir_name
, filename
);
1240 return strdup (filename
);
1244 arange_add (bfd
*abfd
, struct arange
*first_arange
,
1245 bfd_vma low_pc
, bfd_vma high_pc
)
1247 struct arange
*arange
;
1249 /* If the first arange is empty, use it. */
1250 if (first_arange
->high
== 0)
1252 first_arange
->low
= low_pc
;
1253 first_arange
->high
= high_pc
;
1257 /* Next see if we can cheaply extend an existing range. */
1258 arange
= first_arange
;
1261 if (low_pc
== arange
->high
)
1263 arange
->high
= high_pc
;
1266 if (high_pc
== arange
->low
)
1268 arange
->low
= low_pc
;
1271 arange
= arange
->next
;
1275 /* Need to allocate a new arange and insert it into the arange list.
1276 Order isn't significant, so just insert after the first arange. */
1277 arange
= (struct arange
*) bfd_zalloc (abfd
, sizeof (*arange
));
1280 arange
->low
= low_pc
;
1281 arange
->high
= high_pc
;
1282 arange
->next
= first_arange
->next
;
1283 first_arange
->next
= arange
;
1287 /* Compare function for line sequences. */
1290 compare_sequences (const void* a
, const void* b
)
1292 const struct line_sequence
* seq1
= a
;
1293 const struct line_sequence
* seq2
= b
;
1295 /* Sort by low_pc as the primary key. */
1296 if (seq1
->low_pc
< seq2
->low_pc
)
1298 if (seq1
->low_pc
> seq2
->low_pc
)
1301 /* If low_pc values are equal, sort in reverse order of
1302 high_pc, so that the largest region comes first. */
1303 if (seq1
->last_line
->address
< seq2
->last_line
->address
)
1305 if (seq1
->last_line
->address
> seq2
->last_line
->address
)
1308 if (seq1
->last_line
->op_index
< seq2
->last_line
->op_index
)
1310 if (seq1
->last_line
->op_index
> seq2
->last_line
->op_index
)
1316 /* Sort the line sequences for quick lookup. */
1319 sort_line_sequences (struct line_info_table
* table
)
1322 struct line_sequence
* sequences
;
1323 struct line_sequence
* seq
;
1325 unsigned int num_sequences
= table
->num_sequences
;
1326 bfd_vma last_high_pc
;
1328 if (num_sequences
== 0)
1331 /* Allocate space for an array of sequences. */
1332 amt
= sizeof (struct line_sequence
) * num_sequences
;
1333 sequences
= (struct line_sequence
*) bfd_alloc (table
->abfd
, amt
);
1334 if (sequences
== NULL
)
1337 /* Copy the linked list into the array, freeing the original nodes. */
1338 seq
= table
->sequences
;
1339 for (n
= 0; n
< num_sequences
; n
++)
1341 struct line_sequence
* last_seq
= seq
;
1344 sequences
[n
].low_pc
= seq
->low_pc
;
1345 sequences
[n
].prev_sequence
= NULL
;
1346 sequences
[n
].last_line
= seq
->last_line
;
1347 seq
= seq
->prev_sequence
;
1350 BFD_ASSERT (seq
== NULL
);
1352 qsort (sequences
, n
, sizeof (struct line_sequence
), compare_sequences
);
1354 /* Make the list binary-searchable by trimming overlapping entries
1355 and removing nested entries. */
1357 last_high_pc
= sequences
[0].last_line
->address
;
1358 for (n
= 1; n
< table
->num_sequences
; n
++)
1360 if (sequences
[n
].low_pc
< last_high_pc
)
1362 if (sequences
[n
].last_line
->address
<= last_high_pc
)
1363 /* Skip nested entries. */
1366 /* Trim overlapping entries. */
1367 sequences
[n
].low_pc
= last_high_pc
;
1369 last_high_pc
= sequences
[n
].last_line
->address
;
1370 if (n
> num_sequences
)
1372 /* Close up the gap. */
1373 sequences
[num_sequences
].low_pc
= sequences
[n
].low_pc
;
1374 sequences
[num_sequences
].last_line
= sequences
[n
].last_line
;
1379 table
->sequences
= sequences
;
1380 table
->num_sequences
= num_sequences
;
1384 /* Decode the line number information for UNIT. */
1386 static struct line_info_table
*
1387 decode_line_info (struct comp_unit
*unit
, struct dwarf2_debug
*stash
)
1389 bfd
*abfd
= unit
->abfd
;
1390 struct line_info_table
* table
;
1393 struct line_head lh
;
1394 unsigned int i
, bytes_read
, offset_size
;
1395 char *cur_file
, *cur_dir
;
1396 unsigned char op_code
, extended_op
, adj_opcode
;
1399 if (! read_section (abfd
, debug_line
, stash
->syms
, unit
->line_offset
,
1400 &stash
->dwarf_line_buffer
, &stash
->dwarf_line_size
))
1403 amt
= sizeof (struct line_info_table
);
1404 table
= (struct line_info_table
*) bfd_alloc (abfd
, amt
);
1408 table
->comp_dir
= unit
->comp_dir
;
1410 table
->num_files
= 0;
1411 table
->files
= NULL
;
1413 table
->num_dirs
= 0;
1416 table
->num_sequences
= 0;
1417 table
->sequences
= NULL
;
1419 table
->lcl_head
= NULL
;
1421 line_ptr
= stash
->dwarf_line_buffer
+ unit
->line_offset
;
1423 /* Read in the prologue. */
1424 lh
.total_length
= read_4_bytes (abfd
, line_ptr
);
1427 if (lh
.total_length
== 0xffffffff)
1429 lh
.total_length
= read_8_bytes (abfd
, line_ptr
);
1433 else if (lh
.total_length
== 0 && unit
->addr_size
== 8)
1435 /* Handle (non-standard) 64-bit DWARF2 formats. */
1436 lh
.total_length
= read_4_bytes (abfd
, line_ptr
);
1440 line_end
= line_ptr
+ lh
.total_length
;
1441 lh
.version
= read_2_bytes (abfd
, line_ptr
);
1442 if (lh
.version
< 2 || lh
.version
> 4)
1444 (*_bfd_error_handler
)
1445 (_("Dwarf Error: Unhandled .debug_line version %d."), lh
.version
);
1446 bfd_set_error (bfd_error_bad_value
);
1450 if (offset_size
== 4)
1451 lh
.prologue_length
= read_4_bytes (abfd
, line_ptr
);
1453 lh
.prologue_length
= read_8_bytes (abfd
, line_ptr
);
1454 line_ptr
+= offset_size
;
1455 lh
.minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
1457 if (lh
.version
>= 4)
1459 lh
.maximum_ops_per_insn
= read_1_byte (abfd
, line_ptr
);
1463 lh
.maximum_ops_per_insn
= 1;
1464 if (lh
.maximum_ops_per_insn
== 0)
1466 (*_bfd_error_handler
)
1467 (_("Dwarf Error: Invalid maximum operations per instruction."));
1468 bfd_set_error (bfd_error_bad_value
);
1471 lh
.default_is_stmt
= read_1_byte (abfd
, line_ptr
);
1473 lh
.line_base
= read_1_signed_byte (abfd
, line_ptr
);
1475 lh
.line_range
= read_1_byte (abfd
, line_ptr
);
1477 lh
.opcode_base
= read_1_byte (abfd
, line_ptr
);
1479 amt
= lh
.opcode_base
* sizeof (unsigned char);
1480 lh
.standard_opcode_lengths
= (unsigned char *) bfd_alloc (abfd
, amt
);
1482 lh
.standard_opcode_lengths
[0] = 1;
1484 for (i
= 1; i
< lh
.opcode_base
; ++i
)
1486 lh
.standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
1490 /* Read directory table. */
1491 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
1493 line_ptr
+= bytes_read
;
1495 if ((table
->num_dirs
% DIR_ALLOC_CHUNK
) == 0)
1499 amt
= table
->num_dirs
+ DIR_ALLOC_CHUNK
;
1500 amt
*= sizeof (char *);
1502 tmp
= (char **) bfd_realloc (table
->dirs
, amt
);
1508 table
->dirs
[table
->num_dirs
++] = cur_dir
;
1511 line_ptr
+= bytes_read
;
1513 /* Read file name table. */
1514 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
1516 line_ptr
+= bytes_read
;
1518 if ((table
->num_files
% FILE_ALLOC_CHUNK
) == 0)
1520 struct fileinfo
*tmp
;
1522 amt
= table
->num_files
+ FILE_ALLOC_CHUNK
;
1523 amt
*= sizeof (struct fileinfo
);
1525 tmp
= (struct fileinfo
*) bfd_realloc (table
->files
, amt
);
1531 table
->files
[table
->num_files
].name
= cur_file
;
1532 table
->files
[table
->num_files
].dir
=
1533 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
1534 line_ptr
+= bytes_read
;
1535 table
->files
[table
->num_files
].time
=
1536 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
1537 line_ptr
+= bytes_read
;
1538 table
->files
[table
->num_files
].size
=
1539 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
1540 line_ptr
+= bytes_read
;
1544 line_ptr
+= bytes_read
;
1546 /* Read the statement sequences until there's nothing left. */
1547 while (line_ptr
< line_end
)
1549 /* State machine registers. */
1550 bfd_vma address
= 0;
1551 unsigned char op_index
= 0;
1552 char * filename
= table
->num_files
? concat_filename (table
, 1) : NULL
;
1553 unsigned int line
= 1;
1554 unsigned int column
= 0;
1555 int is_stmt
= lh
.default_is_stmt
;
1556 int end_sequence
= 0;
1557 /* eraxxon@alumni.rice.edu: Against the DWARF2 specs, some
1558 compilers generate address sequences that are wildly out of
1559 order using DW_LNE_set_address (e.g. Intel C++ 6.0 compiler
1560 for ia64-Linux). Thus, to determine the low and high
1561 address, we must compare on every DW_LNS_copy, etc. */
1562 bfd_vma low_pc
= (bfd_vma
) -1;
1563 bfd_vma high_pc
= 0;
1565 /* Decode the table. */
1566 while (! end_sequence
)
1568 op_code
= read_1_byte (abfd
, line_ptr
);
1571 if (op_code
>= lh
.opcode_base
)
1573 /* Special operand. */
1574 adj_opcode
= op_code
- lh
.opcode_base
;
1575 if (lh
.maximum_ops_per_insn
== 1)
1576 address
+= (adj_opcode
/ lh
.line_range
)
1577 * lh
.minimum_instruction_length
;
1580 address
+= ((op_index
+ (adj_opcode
/ lh
.line_range
))
1581 / lh
.maximum_ops_per_insn
)
1582 * lh
.minimum_instruction_length
;
1583 op_index
= (op_index
+ (adj_opcode
/ lh
.line_range
))
1584 % lh
.maximum_ops_per_insn
;
1586 line
+= lh
.line_base
+ (adj_opcode
% lh
.line_range
);
1587 /* Append row to matrix using current values. */
1588 if (!add_line_info (table
, address
, op_index
, filename
,
1591 if (address
< low_pc
)
1593 if (address
> high_pc
)
1596 else switch (op_code
)
1598 case DW_LNS_extended_op
:
1599 /* Ignore length. */
1601 extended_op
= read_1_byte (abfd
, line_ptr
);
1604 switch (extended_op
)
1606 case DW_LNE_end_sequence
:
1608 if (!add_line_info (table
, address
, op_index
, filename
,
1609 line
, column
, end_sequence
))
1611 if (address
< low_pc
)
1613 if (address
> high_pc
)
1615 if (!arange_add (unit
->abfd
, &unit
->arange
, low_pc
, high_pc
))
1618 case DW_LNE_set_address
:
1619 address
= read_address (unit
, line_ptr
);
1621 line_ptr
+= unit
->addr_size
;
1623 case DW_LNE_define_file
:
1624 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
1625 line_ptr
+= bytes_read
;
1626 if ((table
->num_files
% FILE_ALLOC_CHUNK
) == 0)
1628 struct fileinfo
*tmp
;
1630 amt
= table
->num_files
+ FILE_ALLOC_CHUNK
;
1631 amt
*= sizeof (struct fileinfo
);
1632 tmp
= (struct fileinfo
*) bfd_realloc (table
->files
, amt
);
1637 table
->files
[table
->num_files
].name
= cur_file
;
1638 table
->files
[table
->num_files
].dir
=
1639 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
1640 line_ptr
+= bytes_read
;
1641 table
->files
[table
->num_files
].time
=
1642 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
1643 line_ptr
+= bytes_read
;
1644 table
->files
[table
->num_files
].size
=
1645 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
1646 line_ptr
+= bytes_read
;
1649 case DW_LNE_set_discriminator
:
1650 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
1651 line_ptr
+= bytes_read
;
1654 (*_bfd_error_handler
) (_("Dwarf Error: mangled line number section."));
1655 bfd_set_error (bfd_error_bad_value
);
1657 if (filename
!= NULL
)
1663 if (!add_line_info (table
, address
, op_index
,
1664 filename
, line
, column
, 0))
1666 if (address
< low_pc
)
1668 if (address
> high_pc
)
1671 case DW_LNS_advance_pc
:
1672 if (lh
.maximum_ops_per_insn
== 1)
1673 address
+= lh
.minimum_instruction_length
1674 * read_unsigned_leb128 (abfd
, line_ptr
,
1678 bfd_vma adjust
= read_unsigned_leb128 (abfd
, line_ptr
,
1680 address
= ((op_index
+ adjust
) / lh
.maximum_ops_per_insn
)
1681 * lh
.minimum_instruction_length
;
1682 op_index
= (op_index
+ adjust
) % lh
.maximum_ops_per_insn
;
1684 line_ptr
+= bytes_read
;
1686 case DW_LNS_advance_line
:
1687 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
1688 line_ptr
+= bytes_read
;
1690 case DW_LNS_set_file
:
1694 /* The file and directory tables are 0
1695 based, the references are 1 based. */
1696 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
1697 line_ptr
+= bytes_read
;
1700 filename
= concat_filename (table
, file
);
1703 case DW_LNS_set_column
:
1704 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
1705 line_ptr
+= bytes_read
;
1707 case DW_LNS_negate_stmt
:
1708 is_stmt
= (!is_stmt
);
1710 case DW_LNS_set_basic_block
:
1712 case DW_LNS_const_add_pc
:
1713 if (lh
.maximum_ops_per_insn
== 1)
1714 address
+= lh
.minimum_instruction_length
1715 * ((255 - lh
.opcode_base
) / lh
.line_range
);
1718 bfd_vma adjust
= ((255 - lh
.opcode_base
) / lh
.line_range
);
1719 address
+= lh
.minimum_instruction_length
1720 * ((op_index
+ adjust
) / lh
.maximum_ops_per_insn
);
1721 op_index
= (op_index
+ adjust
) % lh
.maximum_ops_per_insn
;
1724 case DW_LNS_fixed_advance_pc
:
1725 address
+= read_2_bytes (abfd
, line_ptr
);
1730 /* Unknown standard opcode, ignore it. */
1731 for (i
= 0; i
< lh
.standard_opcode_lengths
[op_code
]; i
++)
1733 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
1734 line_ptr
+= bytes_read
;
1744 if (sort_line_sequences (table
))
1748 if (table
->sequences
!= NULL
)
1749 free (table
->sequences
);
1750 if (table
->files
!= NULL
)
1751 free (table
->files
);
1752 if (table
->dirs
!= NULL
)
1757 /* If ADDR is within TABLE set the output parameters and return TRUE,
1758 otherwise return FALSE. The output parameters, FILENAME_PTR and
1759 LINENUMBER_PTR, are pointers to the objects to be filled in. */
1762 lookup_address_in_line_info_table (struct line_info_table
*table
,
1764 const char **filename_ptr
,
1765 unsigned int *linenumber_ptr
)
1767 struct line_sequence
*seq
= NULL
;
1768 struct line_info
*each_line
;
1771 /* Binary search the array of sequences. */
1773 high
= table
->num_sequences
;
1776 mid
= (low
+ high
) / 2;
1777 seq
= &table
->sequences
[mid
];
1778 if (addr
< seq
->low_pc
)
1780 else if (addr
>= seq
->last_line
->address
)
1786 if (seq
&& addr
>= seq
->low_pc
&& addr
< seq
->last_line
->address
)
1788 /* Note: seq->last_line should be a descendingly sorted list. */
1789 for (each_line
= seq
->last_line
;
1791 each_line
= each_line
->prev_line
)
1792 if (addr
>= each_line
->address
)
1796 && !(each_line
->end_sequence
|| each_line
== seq
->last_line
))
1798 *filename_ptr
= each_line
->filename
;
1799 *linenumber_ptr
= each_line
->line
;
1804 *filename_ptr
= NULL
;
1808 /* Read in the .debug_ranges section for future reference. */
1811 read_debug_ranges (struct comp_unit
*unit
)
1813 struct dwarf2_debug
*stash
= unit
->stash
;
1814 return read_section (unit
->abfd
, debug_ranges
, stash
->syms
, 0,
1815 &stash
->dwarf_ranges_buffer
, &stash
->dwarf_ranges_size
);
1818 /* Function table functions. */
1820 /* If ADDR is within TABLE, set FUNCTIONNAME_PTR, and return TRUE.
1821 Note that we need to find the function that has the smallest
1822 range that contains ADDR, to handle inlined functions without
1823 depending upon them being ordered in TABLE by increasing range. */
1826 lookup_address_in_function_table (struct comp_unit
*unit
,
1828 struct funcinfo
**function_ptr
,
1829 const char **functionname_ptr
)
1831 struct funcinfo
* each_func
;
1832 struct funcinfo
* best_fit
= NULL
;
1833 struct arange
*arange
;
1835 for (each_func
= unit
->function_table
;
1837 each_func
= each_func
->prev_func
)
1839 for (arange
= &each_func
->arange
;
1841 arange
= arange
->next
)
1843 if (addr
>= arange
->low
&& addr
< arange
->high
)
1846 ((arange
->high
- arange
->low
) < (best_fit
->arange
.high
- best_fit
->arange
.low
)))
1847 best_fit
= each_func
;
1854 *functionname_ptr
= best_fit
->name
;
1855 *function_ptr
= best_fit
;
1864 /* If SYM at ADDR is within function table of UNIT, set FILENAME_PTR
1865 and LINENUMBER_PTR, and return TRUE. */
1868 lookup_symbol_in_function_table (struct comp_unit
*unit
,
1871 const char **filename_ptr
,
1872 unsigned int *linenumber_ptr
)
1874 struct funcinfo
* each_func
;
1875 struct funcinfo
* best_fit
= NULL
;
1876 struct arange
*arange
;
1877 const char *name
= bfd_asymbol_name (sym
);
1878 asection
*sec
= bfd_get_section (sym
);
1880 for (each_func
= unit
->function_table
;
1882 each_func
= each_func
->prev_func
)
1884 for (arange
= &each_func
->arange
;
1886 arange
= arange
->next
)
1888 if ((!each_func
->sec
|| each_func
->sec
== sec
)
1889 && addr
>= arange
->low
1890 && addr
< arange
->high
1892 && strcmp (name
, each_func
->name
) == 0
1894 || ((arange
->high
- arange
->low
)
1895 < (best_fit
->arange
.high
- best_fit
->arange
.low
))))
1896 best_fit
= each_func
;
1902 best_fit
->sec
= sec
;
1903 *filename_ptr
= best_fit
->file
;
1904 *linenumber_ptr
= best_fit
->line
;
1911 /* Variable table functions. */
1913 /* If SYM is within variable table of UNIT, set FILENAME_PTR and
1914 LINENUMBER_PTR, and return TRUE. */
1917 lookup_symbol_in_variable_table (struct comp_unit
*unit
,
1920 const char **filename_ptr
,
1921 unsigned int *linenumber_ptr
)
1923 const char *name
= bfd_asymbol_name (sym
);
1924 asection
*sec
= bfd_get_section (sym
);
1925 struct varinfo
* each
;
1927 for (each
= unit
->variable_table
; each
; each
= each
->prev_var
)
1928 if (each
->stack
== 0
1929 && each
->file
!= NULL
1930 && each
->name
!= NULL
1931 && each
->addr
== addr
1932 && (!each
->sec
|| each
->sec
== sec
)
1933 && strcmp (name
, each
->name
) == 0)
1939 *filename_ptr
= each
->file
;
1940 *linenumber_ptr
= each
->line
;
1948 find_abstract_instance_name (struct comp_unit
*unit
,
1949 struct attribute
*attr_ptr
)
1951 bfd
*abfd
= unit
->abfd
;
1953 unsigned int abbrev_number
, bytes_read
, i
;
1954 struct abbrev_info
*abbrev
;
1955 bfd_uint64_t die_ref
= attr_ptr
->u
.val
;
1956 struct attribute attr
;
1959 /* DW_FORM_ref_addr can reference an entry in a different CU. It
1960 is an offset from the .debug_info section, not the current CU. */
1961 if (attr_ptr
->form
== DW_FORM_ref_addr
)
1963 /* We only support DW_FORM_ref_addr within the same file, so
1964 any relocations should be resolved already. */
1968 info_ptr
= unit
->sec_info_ptr
+ die_ref
;
1971 info_ptr
= unit
->info_ptr_unit
+ die_ref
;
1972 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
1973 info_ptr
+= bytes_read
;
1977 abbrev
= lookup_abbrev (abbrev_number
, unit
->abbrevs
);
1980 (*_bfd_error_handler
) (_("Dwarf Error: Could not find abbrev number %u."),
1982 bfd_set_error (bfd_error_bad_value
);
1986 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
1988 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], unit
,
1990 if (info_ptr
== NULL
)
1995 /* Prefer DW_AT_MIPS_linkage_name or DW_AT_linkage_name
2000 case DW_AT_specification
:
2001 name
= find_abstract_instance_name (unit
, &attr
);
2003 case DW_AT_linkage_name
:
2004 case DW_AT_MIPS_linkage_name
:
2017 read_rangelist (struct comp_unit
*unit
, struct arange
*arange
,
2018 bfd_uint64_t offset
)
2020 bfd_byte
*ranges_ptr
;
2021 bfd_vma base_address
= unit
->base_address
;
2023 if (! unit
->stash
->dwarf_ranges_buffer
)
2025 if (! read_debug_ranges (unit
))
2028 ranges_ptr
= unit
->stash
->dwarf_ranges_buffer
+ offset
;
2035 low_pc
= read_address (unit
, ranges_ptr
);
2036 ranges_ptr
+= unit
->addr_size
;
2037 high_pc
= read_address (unit
, ranges_ptr
);
2038 ranges_ptr
+= unit
->addr_size
;
2040 if (low_pc
== 0 && high_pc
== 0)
2042 if (low_pc
== -1UL && high_pc
!= -1UL)
2043 base_address
= high_pc
;
2046 if (!arange_add (unit
->abfd
, arange
,
2047 base_address
+ low_pc
, base_address
+ high_pc
))
2054 /* DWARF2 Compilation unit functions. */
2056 /* Scan over each die in a comp. unit looking for functions to add
2057 to the function table and variables to the variable table. */
2060 scan_unit_for_symbols (struct comp_unit
*unit
)
2062 bfd
*abfd
= unit
->abfd
;
2063 bfd_byte
*info_ptr
= unit
->first_child_die_ptr
;
2064 int nesting_level
= 1;
2065 struct funcinfo
**nested_funcs
;
2066 int nested_funcs_size
;
2068 /* Maintain a stack of in-scope functions and inlined functions, which we
2069 can use to set the caller_func field. */
2070 nested_funcs_size
= 32;
2071 nested_funcs
= (struct funcinfo
**)
2072 bfd_malloc (nested_funcs_size
* sizeof (struct funcinfo
*));
2073 if (nested_funcs
== NULL
)
2075 nested_funcs
[nesting_level
] = 0;
2077 while (nesting_level
)
2079 unsigned int abbrev_number
, bytes_read
, i
;
2080 struct abbrev_info
*abbrev
;
2081 struct attribute attr
;
2082 struct funcinfo
*func
;
2083 struct varinfo
*var
;
2085 bfd_vma high_pc
= 0;
2087 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2088 info_ptr
+= bytes_read
;
2090 if (! abbrev_number
)
2096 abbrev
= lookup_abbrev (abbrev_number
,unit
->abbrevs
);
2099 (*_bfd_error_handler
)
2100 (_("Dwarf Error: Could not find abbrev number %u."),
2102 bfd_set_error (bfd_error_bad_value
);
2107 if (abbrev
->tag
== DW_TAG_subprogram
2108 || abbrev
->tag
== DW_TAG_entry_point
2109 || abbrev
->tag
== DW_TAG_inlined_subroutine
)
2111 bfd_size_type amt
= sizeof (struct funcinfo
);
2112 func
= (struct funcinfo
*) bfd_zalloc (abfd
, amt
);
2115 func
->tag
= abbrev
->tag
;
2116 func
->prev_func
= unit
->function_table
;
2117 unit
->function_table
= func
;
2118 BFD_ASSERT (!unit
->cached
);
2120 if (func
->tag
== DW_TAG_inlined_subroutine
)
2121 for (i
= nesting_level
- 1; i
>= 1; i
--)
2122 if (nested_funcs
[i
])
2124 func
->caller_func
= nested_funcs
[i
];
2127 nested_funcs
[nesting_level
] = func
;
2132 if (abbrev
->tag
== DW_TAG_variable
)
2134 bfd_size_type amt
= sizeof (struct varinfo
);
2135 var
= (struct varinfo
*) bfd_zalloc (abfd
, amt
);
2138 var
->tag
= abbrev
->tag
;
2140 var
->prev_var
= unit
->variable_table
;
2141 unit
->variable_table
= var
;
2142 BFD_ASSERT (!unit
->cached
);
2145 /* No inline function in scope at this nesting level. */
2146 nested_funcs
[nesting_level
] = 0;
2149 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
2151 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], unit
, info_ptr
);
2152 if (info_ptr
== NULL
)
2159 case DW_AT_call_file
:
2160 func
->caller_file
= concat_filename (unit
->line_table
,
2164 case DW_AT_call_line
:
2165 func
->caller_line
= attr
.u
.val
;
2168 case DW_AT_abstract_origin
:
2169 case DW_AT_specification
:
2170 func
->name
= find_abstract_instance_name (unit
, &attr
);
2174 /* Prefer DW_AT_MIPS_linkage_name or DW_AT_linkage_name
2176 if (func
->name
== NULL
)
2177 func
->name
= attr
.u
.str
;
2180 case DW_AT_linkage_name
:
2181 case DW_AT_MIPS_linkage_name
:
2182 func
->name
= attr
.u
.str
;
2186 low_pc
= attr
.u
.val
;
2190 high_pc
= attr
.u
.val
;
2194 if (!read_rangelist (unit
, &func
->arange
, attr
.u
.val
))
2198 case DW_AT_decl_file
:
2199 func
->file
= concat_filename (unit
->line_table
,
2203 case DW_AT_decl_line
:
2204 func
->line
= attr
.u
.val
;
2216 var
->name
= attr
.u
.str
;
2219 case DW_AT_decl_file
:
2220 var
->file
= concat_filename (unit
->line_table
,
2224 case DW_AT_decl_line
:
2225 var
->line
= attr
.u
.val
;
2228 case DW_AT_external
:
2229 if (attr
.u
.val
!= 0)
2233 case DW_AT_location
:
2237 case DW_FORM_block1
:
2238 case DW_FORM_block2
:
2239 case DW_FORM_block4
:
2240 case DW_FORM_exprloc
:
2241 if (*attr
.u
.blk
->data
== DW_OP_addr
)
2245 /* Verify that DW_OP_addr is the only opcode in the
2246 location, in which case the block size will be 1
2247 plus the address size. */
2248 /* ??? For TLS variables, gcc can emit
2249 DW_OP_addr <addr> DW_OP_GNU_push_tls_address
2250 which we don't handle here yet. */
2251 if (attr
.u
.blk
->size
== unit
->addr_size
+ 1U)
2252 var
->addr
= bfd_get (unit
->addr_size
* 8,
2254 attr
.u
.blk
->data
+ 1);
2269 if (func
&& high_pc
!= 0)
2271 if (!arange_add (unit
->abfd
, &func
->arange
, low_pc
, high_pc
))
2275 if (abbrev
->has_children
)
2279 if (nesting_level
>= nested_funcs_size
)
2281 struct funcinfo
**tmp
;
2283 nested_funcs_size
*= 2;
2284 tmp
= (struct funcinfo
**)
2285 bfd_realloc (nested_funcs
,
2286 (nested_funcs_size
* sizeof (struct funcinfo
*)));
2291 nested_funcs
[nesting_level
] = 0;
2295 free (nested_funcs
);
2299 free (nested_funcs
);
2303 /* Parse a DWARF2 compilation unit starting at INFO_PTR. This
2304 includes the compilation unit header that proceeds the DIE's, but
2305 does not include the length field that precedes each compilation
2306 unit header. END_PTR points one past the end of this comp unit.
2307 OFFSET_SIZE is the size of DWARF2 offsets (either 4 or 8 bytes).
2309 This routine does not read the whole compilation unit; only enough
2310 to get to the line number information for the compilation unit. */
2312 static struct comp_unit
*
2313 parse_comp_unit (struct dwarf2_debug
*stash
,
2314 bfd_vma unit_length
,
2315 bfd_byte
*info_ptr_unit
,
2316 unsigned int offset_size
)
2318 struct comp_unit
* unit
;
2319 unsigned int version
;
2320 bfd_uint64_t abbrev_offset
= 0;
2321 unsigned int addr_size
;
2322 struct abbrev_info
** abbrevs
;
2323 unsigned int abbrev_number
, bytes_read
, i
;
2324 struct abbrev_info
*abbrev
;
2325 struct attribute attr
;
2326 bfd_byte
*info_ptr
= stash
->info_ptr
;
2327 bfd_byte
*end_ptr
= info_ptr
+ unit_length
;
2330 bfd_vma high_pc
= 0;
2331 bfd
*abfd
= stash
->bfd_ptr
;
2333 version
= read_2_bytes (abfd
, info_ptr
);
2335 BFD_ASSERT (offset_size
== 4 || offset_size
== 8);
2336 if (offset_size
== 4)
2337 abbrev_offset
= read_4_bytes (abfd
, info_ptr
);
2339 abbrev_offset
= read_8_bytes (abfd
, info_ptr
);
2340 info_ptr
+= offset_size
;
2341 addr_size
= read_1_byte (abfd
, info_ptr
);
2344 if (version
!= 2 && version
!= 3 && version
!= 4)
2346 (*_bfd_error_handler
) (_("Dwarf Error: found dwarf version '%u', this reader only handles version 2, 3 and 4 information."), version
);
2347 bfd_set_error (bfd_error_bad_value
);
2351 if (addr_size
> sizeof (bfd_vma
))
2353 (*_bfd_error_handler
) (_("Dwarf Error: found address size '%u', this reader can not handle sizes greater than '%u'."),
2355 (unsigned int) sizeof (bfd_vma
));
2356 bfd_set_error (bfd_error_bad_value
);
2360 if (addr_size
!= 2 && addr_size
!= 4 && addr_size
!= 8)
2362 (*_bfd_error_handler
) ("Dwarf Error: found address size '%u', this reader can only handle address sizes '2', '4' and '8'.", addr_size
);
2363 bfd_set_error (bfd_error_bad_value
);
2367 /* Read the abbrevs for this compilation unit into a table. */
2368 abbrevs
= read_abbrevs (abfd
, abbrev_offset
, stash
);
2372 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2373 info_ptr
+= bytes_read
;
2374 if (! abbrev_number
)
2376 (*_bfd_error_handler
) (_("Dwarf Error: Bad abbrev number: %u."),
2378 bfd_set_error (bfd_error_bad_value
);
2382 abbrev
= lookup_abbrev (abbrev_number
, abbrevs
);
2385 (*_bfd_error_handler
) (_("Dwarf Error: Could not find abbrev number %u."),
2387 bfd_set_error (bfd_error_bad_value
);
2391 amt
= sizeof (struct comp_unit
);
2392 unit
= (struct comp_unit
*) bfd_zalloc (abfd
, amt
);
2396 unit
->version
= version
;
2397 unit
->addr_size
= addr_size
;
2398 unit
->offset_size
= offset_size
;
2399 unit
->abbrevs
= abbrevs
;
2400 unit
->end_ptr
= end_ptr
;
2401 unit
->stash
= stash
;
2402 unit
->info_ptr_unit
= info_ptr_unit
;
2403 unit
->sec_info_ptr
= stash
->sec_info_ptr
;
2405 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
2407 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], unit
, info_ptr
);
2408 if (info_ptr
== NULL
)
2411 /* Store the data if it is of an attribute we want to keep in a
2412 partial symbol table. */
2415 case DW_AT_stmt_list
:
2417 unit
->line_offset
= attr
.u
.val
;
2421 unit
->name
= attr
.u
.str
;
2425 low_pc
= attr
.u
.val
;
2426 /* If the compilation unit DIE has a DW_AT_low_pc attribute,
2427 this is the base address to use when reading location
2428 lists or range lists. */
2429 unit
->base_address
= low_pc
;
2433 high_pc
= attr
.u
.val
;
2437 if (!read_rangelist (unit
, &unit
->arange
, attr
.u
.val
))
2441 case DW_AT_comp_dir
:
2443 char *comp_dir
= attr
.u
.str
;
2446 /* Irix 6.2 native cc prepends <machine>.: to the compilation
2447 directory, get rid of it. */
2448 char *cp
= strchr (comp_dir
, ':');
2450 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
2453 unit
->comp_dir
= comp_dir
;
2463 if (!arange_add (unit
->abfd
, &unit
->arange
, low_pc
, high_pc
))
2467 unit
->first_child_die_ptr
= info_ptr
;
2471 /* Return TRUE if UNIT may contain the address given by ADDR. When
2472 there are functions written entirely with inline asm statements, the
2473 range info in the compilation unit header may not be correct. We
2474 need to consult the line info table to see if a compilation unit
2475 really contains the given address. */
2478 comp_unit_contains_address (struct comp_unit
*unit
, bfd_vma addr
)
2480 struct arange
*arange
;
2485 arange
= &unit
->arange
;
2488 if (addr
>= arange
->low
&& addr
< arange
->high
)
2490 arange
= arange
->next
;
2497 /* If UNIT contains ADDR, set the output parameters to the values for
2498 the line containing ADDR. The output parameters, FILENAME_PTR,
2499 FUNCTIONNAME_PTR, and LINENUMBER_PTR, are pointers to the objects
2502 Return TRUE if UNIT contains ADDR, and no errors were encountered;
2506 comp_unit_find_nearest_line (struct comp_unit
*unit
,
2508 const char **filename_ptr
,
2509 const char **functionname_ptr
,
2510 unsigned int *linenumber_ptr
,
2511 struct dwarf2_debug
*stash
)
2515 struct funcinfo
*function
;
2520 if (! unit
->line_table
)
2522 if (! unit
->stmtlist
)
2528 unit
->line_table
= decode_line_info (unit
, stash
);
2530 if (! unit
->line_table
)
2536 if (unit
->first_child_die_ptr
< unit
->end_ptr
2537 && ! scan_unit_for_symbols (unit
))
2545 func_p
= lookup_address_in_function_table (unit
, addr
,
2546 &function
, functionname_ptr
);
2547 if (func_p
&& (function
->tag
== DW_TAG_inlined_subroutine
))
2548 stash
->inliner_chain
= function
;
2549 line_p
= lookup_address_in_line_info_table (unit
->line_table
, addr
,
2552 return line_p
|| func_p
;
2555 /* Check to see if line info is already decoded in a comp_unit.
2556 If not, decode it. Returns TRUE if no errors were encountered;
2560 comp_unit_maybe_decode_line_info (struct comp_unit
*unit
,
2561 struct dwarf2_debug
*stash
)
2566 if (! unit
->line_table
)
2568 if (! unit
->stmtlist
)
2574 unit
->line_table
= decode_line_info (unit
, stash
);
2576 if (! unit
->line_table
)
2582 if (unit
->first_child_die_ptr
< unit
->end_ptr
2583 && ! scan_unit_for_symbols (unit
))
2593 /* If UNIT contains SYM at ADDR, set the output parameters to the
2594 values for the line containing SYM. The output parameters,
2595 FILENAME_PTR, and LINENUMBER_PTR, are pointers to the objects to be
2598 Return TRUE if UNIT contains SYM, and no errors were encountered;
2602 comp_unit_find_line (struct comp_unit
*unit
,
2605 const char **filename_ptr
,
2606 unsigned int *linenumber_ptr
,
2607 struct dwarf2_debug
*stash
)
2609 if (!comp_unit_maybe_decode_line_info (unit
, stash
))
2612 if (sym
->flags
& BSF_FUNCTION
)
2613 return lookup_symbol_in_function_table (unit
, sym
, addr
,
2617 return lookup_symbol_in_variable_table (unit
, sym
, addr
,
2622 static struct funcinfo
*
2623 reverse_funcinfo_list (struct funcinfo
*head
)
2625 struct funcinfo
*rhead
;
2626 struct funcinfo
*temp
;
2628 for (rhead
= NULL
; head
; head
= temp
)
2630 temp
= head
->prev_func
;
2631 head
->prev_func
= rhead
;
2637 static struct varinfo
*
2638 reverse_varinfo_list (struct varinfo
*head
)
2640 struct varinfo
*rhead
;
2641 struct varinfo
*temp
;
2643 for (rhead
= NULL
; head
; head
= temp
)
2645 temp
= head
->prev_var
;
2646 head
->prev_var
= rhead
;
2652 /* Extract all interesting funcinfos and varinfos of a compilation
2653 unit into hash tables for faster lookup. Returns TRUE if no
2654 errors were enountered; FALSE otherwise. */
2657 comp_unit_hash_info (struct dwarf2_debug
*stash
,
2658 struct comp_unit
*unit
,
2659 struct info_hash_table
*funcinfo_hash_table
,
2660 struct info_hash_table
*varinfo_hash_table
)
2662 struct funcinfo
* each_func
;
2663 struct varinfo
* each_var
;
2664 bfd_boolean okay
= TRUE
;
2666 BFD_ASSERT (stash
->info_hash_status
!= STASH_INFO_HASH_DISABLED
);
2668 if (!comp_unit_maybe_decode_line_info (unit
, stash
))
2671 BFD_ASSERT (!unit
->cached
);
2673 /* To preserve the original search order, we went to visit the function
2674 infos in the reversed order of the list. However, making the list
2675 bi-directional use quite a bit of extra memory. So we reverse
2676 the list first, traverse the list in the now reversed order and
2677 finally reverse the list again to get back the original order. */
2678 unit
->function_table
= reverse_funcinfo_list (unit
->function_table
);
2679 for (each_func
= unit
->function_table
;
2681 each_func
= each_func
->prev_func
)
2683 /* Skip nameless functions. */
2684 if (each_func
->name
)
2685 /* There is no need to copy name string into hash table as
2686 name string is either in the dwarf string buffer or
2687 info in the stash. */
2688 okay
= insert_info_hash_table (funcinfo_hash_table
, each_func
->name
,
2689 (void*) each_func
, FALSE
);
2691 unit
->function_table
= reverse_funcinfo_list (unit
->function_table
);
2695 /* We do the same for variable infos. */
2696 unit
->variable_table
= reverse_varinfo_list (unit
->variable_table
);
2697 for (each_var
= unit
->variable_table
;
2699 each_var
= each_var
->prev_var
)
2701 /* Skip stack vars and vars with no files or names. */
2702 if (each_var
->stack
== 0
2703 && each_var
->file
!= NULL
2704 && each_var
->name
!= NULL
)
2705 /* There is no need to copy name string into hash table as
2706 name string is either in the dwarf string buffer or
2707 info in the stash. */
2708 okay
= insert_info_hash_table (varinfo_hash_table
, each_var
->name
,
2709 (void*) each_var
, FALSE
);
2712 unit
->variable_table
= reverse_varinfo_list (unit
->variable_table
);
2713 unit
->cached
= TRUE
;
2717 /* Locate a section in a BFD containing debugging info. The search starts
2718 from the section after AFTER_SEC, or from the first section in the BFD if
2719 AFTER_SEC is NULL. The search works by examining the names of the
2720 sections. There are two permissiable names. The first is .debug_info.
2721 This is the standard DWARF2 name. The second is a prefix .gnu.linkonce.wi.
2722 This is a variation on the .debug_info section which has a checksum
2723 describing the contents appended onto the name. This allows the linker to
2724 identify and discard duplicate debugging sections for different
2725 compilation units. */
2726 #define DWARF2_DEBUG_INFO ".debug_info"
2727 #define DWARF2_COMPRESSED_DEBUG_INFO ".zdebug_info"
2728 #define GNU_LINKONCE_INFO ".gnu.linkonce.wi."
2731 find_debug_info (bfd
*abfd
, asection
*after_sec
)
2735 msec
= after_sec
!= NULL
? after_sec
->next
: abfd
->sections
;
2739 if (strcmp (msec
->name
, DWARF2_DEBUG_INFO
) == 0)
2742 if (strcmp (msec
->name
, DWARF2_COMPRESSED_DEBUG_INFO
) == 0)
2745 if (CONST_STRNEQ (msec
->name
, GNU_LINKONCE_INFO
))
2754 /* Unset vmas for adjusted sections in STASH. */
2757 unset_sections (struct dwarf2_debug
*stash
)
2760 struct adjusted_section
*p
;
2762 i
= stash
->adjusted_section_count
;
2763 p
= stash
->adjusted_sections
;
2764 for (; i
> 0; i
--, p
++)
2765 p
->section
->vma
= 0;
2768 /* Set unique VMAs for loadable and DWARF sections in ABFD and save
2769 VMAs in STASH for unset_sections. */
2772 place_sections (bfd
*abfd
, struct dwarf2_debug
*stash
)
2774 struct adjusted_section
*p
;
2777 if (stash
->adjusted_section_count
!= 0)
2779 i
= stash
->adjusted_section_count
;
2780 p
= stash
->adjusted_sections
;
2781 for (; i
> 0; i
--, p
++)
2782 p
->section
->vma
= p
->adj_vma
;
2787 bfd_vma last_vma
= 0, last_dwarf
= 0;
2791 for (sect
= abfd
->sections
; sect
!= NULL
; sect
= sect
->next
)
2799 /* We need to adjust the VMAs of any .debug_info sections.
2800 Skip compressed ones, since no relocations could target
2801 them - they should not appear in object files anyway. */
2802 if (strcmp (sect
->name
, DWARF2_DEBUG_INFO
) == 0)
2804 else if (CONST_STRNEQ (sect
->name
, GNU_LINKONCE_INFO
))
2809 if (!is_debug_info
&& (sect
->flags
& SEC_LOAD
) == 0)
2812 sz
= sect
->rawsize
? sect
->rawsize
: sect
->size
;
2819 amt
= i
* sizeof (struct adjusted_section
);
2820 p
= (struct adjusted_section
*) bfd_zalloc (abfd
, amt
);
2824 stash
->adjusted_sections
= p
;
2825 stash
->adjusted_section_count
= i
;
2827 for (sect
= abfd
->sections
; sect
!= NULL
; sect
= sect
->next
)
2835 /* We need to adjust the VMAs of any .debug_info sections.
2836 Skip compressed ones, since no relocations could target
2837 them - they should not appear in object files anyway. */
2838 if (strcmp (sect
->name
, DWARF2_DEBUG_INFO
) == 0)
2840 else if (CONST_STRNEQ (sect
->name
, GNU_LINKONCE_INFO
))
2845 if (!is_debug_info
&& (sect
->flags
& SEC_LOAD
) == 0)
2848 sz
= sect
->rawsize
? sect
->rawsize
: sect
->size
;
2855 BFD_ASSERT (sect
->alignment_power
== 0);
2856 sect
->vma
= last_dwarf
;
2859 else if (last_vma
!= 0)
2861 /* Align the new address to the current section
2863 last_vma
= ((last_vma
2864 + ~((bfd_vma
) -1 << sect
->alignment_power
))
2865 & ((bfd_vma
) -1 << sect
->alignment_power
));
2866 sect
->vma
= last_vma
;
2867 last_vma
+= sect
->vma
+ sz
;
2870 last_vma
+= sect
->vma
+ sz
;
2872 p
->adj_vma
= sect
->vma
;
2881 /* Look up a funcinfo by name using the given info hash table. If found,
2882 also update the locations pointed to by filename_ptr and linenumber_ptr.
2884 This function returns TRUE if a funcinfo that matches the given symbol
2885 and address is found with any error; otherwise it returns FALSE. */
2888 info_hash_lookup_funcinfo (struct info_hash_table
*hash_table
,
2891 const char **filename_ptr
,
2892 unsigned int *linenumber_ptr
)
2894 struct funcinfo
* each_func
;
2895 struct funcinfo
* best_fit
= NULL
;
2896 struct info_list_node
*node
;
2897 struct arange
*arange
;
2898 const char *name
= bfd_asymbol_name (sym
);
2899 asection
*sec
= bfd_get_section (sym
);
2901 for (node
= lookup_info_hash_table (hash_table
, name
);
2905 each_func
= (struct funcinfo
*) node
->info
;
2906 for (arange
= &each_func
->arange
;
2908 arange
= arange
->next
)
2910 if ((!each_func
->sec
|| each_func
->sec
== sec
)
2911 && addr
>= arange
->low
2912 && addr
< arange
->high
2914 || ((arange
->high
- arange
->low
)
2915 < (best_fit
->arange
.high
- best_fit
->arange
.low
))))
2916 best_fit
= each_func
;
2922 best_fit
->sec
= sec
;
2923 *filename_ptr
= best_fit
->file
;
2924 *linenumber_ptr
= best_fit
->line
;
2931 /* Look up a varinfo by name using the given info hash table. If found,
2932 also update the locations pointed to by filename_ptr and linenumber_ptr.
2934 This function returns TRUE if a varinfo that matches the given symbol
2935 and address is found with any error; otherwise it returns FALSE. */
2938 info_hash_lookup_varinfo (struct info_hash_table
*hash_table
,
2941 const char **filename_ptr
,
2942 unsigned int *linenumber_ptr
)
2944 const char *name
= bfd_asymbol_name (sym
);
2945 asection
*sec
= bfd_get_section (sym
);
2946 struct varinfo
* each
;
2947 struct info_list_node
*node
;
2949 for (node
= lookup_info_hash_table (hash_table
, name
);
2953 each
= (struct varinfo
*) node
->info
;
2954 if (each
->addr
== addr
2955 && (!each
->sec
|| each
->sec
== sec
))
2958 *filename_ptr
= each
->file
;
2959 *linenumber_ptr
= each
->line
;
2967 /* Update the funcinfo and varinfo info hash tables if they are
2968 not up to date. Returns TRUE if there is no error; otherwise
2969 returns FALSE and disable the info hash tables. */
2972 stash_maybe_update_info_hash_tables (struct dwarf2_debug
*stash
)
2974 struct comp_unit
*each
;
2976 /* Exit if hash tables are up-to-date. */
2977 if (stash
->all_comp_units
== stash
->hash_units_head
)
2980 if (stash
->hash_units_head
)
2981 each
= stash
->hash_units_head
->prev_unit
;
2983 each
= stash
->last_comp_unit
;
2987 if (!comp_unit_hash_info (stash
, each
, stash
->funcinfo_hash_table
,
2988 stash
->varinfo_hash_table
))
2990 stash
->info_hash_status
= STASH_INFO_HASH_DISABLED
;
2993 each
= each
->prev_unit
;
2996 stash
->hash_units_head
= stash
->all_comp_units
;
3000 /* Check consistency of info hash tables. This is for debugging only. */
3002 static void ATTRIBUTE_UNUSED
3003 stash_verify_info_hash_table (struct dwarf2_debug
*stash
)
3005 struct comp_unit
*each_unit
;
3006 struct funcinfo
*each_func
;
3007 struct varinfo
*each_var
;
3008 struct info_list_node
*node
;
3011 for (each_unit
= stash
->all_comp_units
;
3013 each_unit
= each_unit
->next_unit
)
3015 for (each_func
= each_unit
->function_table
;
3017 each_func
= each_func
->prev_func
)
3019 if (!each_func
->name
)
3021 node
= lookup_info_hash_table (stash
->funcinfo_hash_table
,
3025 while (node
&& !found
)
3027 found
= node
->info
== each_func
;
3033 for (each_var
= each_unit
->variable_table
;
3035 each_var
= each_var
->prev_var
)
3037 if (!each_var
->name
|| !each_var
->file
|| each_var
->stack
)
3039 node
= lookup_info_hash_table (stash
->varinfo_hash_table
,
3043 while (node
&& !found
)
3045 found
= node
->info
== each_var
;
3053 /* Check to see if we want to enable the info hash tables, which consume
3054 quite a bit of memory. Currently we only check the number times
3055 bfd_dwarf2_find_line is called. In the future, we may also want to
3056 take the number of symbols into account. */
3059 stash_maybe_enable_info_hash_tables (bfd
*abfd
, struct dwarf2_debug
*stash
)
3061 BFD_ASSERT (stash
->info_hash_status
== STASH_INFO_HASH_OFF
);
3063 if (stash
->info_hash_count
++ < STASH_INFO_HASH_TRIGGER
)
3066 /* FIXME: Maybe we should check the reduce_memory_overheads
3067 and optimize fields in the bfd_link_info structure ? */
3069 /* Create hash tables. */
3070 stash
->funcinfo_hash_table
= create_info_hash_table (abfd
);
3071 stash
->varinfo_hash_table
= create_info_hash_table (abfd
);
3072 if (!stash
->funcinfo_hash_table
|| !stash
->varinfo_hash_table
)
3074 /* Turn off info hashes if any allocation above fails. */
3075 stash
->info_hash_status
= STASH_INFO_HASH_DISABLED
;
3078 /* We need a forced update so that the info hash tables will
3079 be created even though there is no compilation unit. That
3080 happens if STASH_INFO_HASH_TRIGGER is 0. */
3081 stash_maybe_update_info_hash_tables (stash
);
3082 stash
->info_hash_status
= STASH_INFO_HASH_ON
;
3085 /* Find the file and line associated with a symbol and address using the
3086 info hash tables of a stash. If there is a match, the function returns
3087 TRUE and update the locations pointed to by filename_ptr and linenumber_ptr;
3088 otherwise it returns FALSE. */
3091 stash_find_line_fast (struct dwarf2_debug
*stash
,
3094 const char **filename_ptr
,
3095 unsigned int *linenumber_ptr
)
3097 BFD_ASSERT (stash
->info_hash_status
== STASH_INFO_HASH_ON
);
3099 if (sym
->flags
& BSF_FUNCTION
)
3100 return info_hash_lookup_funcinfo (stash
->funcinfo_hash_table
, sym
, addr
,
3101 filename_ptr
, linenumber_ptr
);
3102 return info_hash_lookup_varinfo (stash
->varinfo_hash_table
, sym
, addr
,
3103 filename_ptr
, linenumber_ptr
);
3106 /* Find the source code location of SYMBOL. If SYMBOL is NULL
3107 then find the nearest source code location corresponding to
3108 the address SECTION + OFFSET.
3109 Returns TRUE if the line is found without error and fills in
3110 FILENAME_PTR and LINENUMBER_PTR. In the case where SYMBOL was
3111 NULL the FUNCTIONNAME_PTR is also filled in.
3112 SYMBOLS contains the symbol table for ABFD.
3113 ADDR_SIZE is the number of bytes in the initial .debug_info length
3114 field and in the abbreviation offset, or zero to indicate that the
3115 default value should be used. */
3118 find_line (bfd
*abfd
,
3123 const char **filename_ptr
,
3124 const char **functionname_ptr
,
3125 unsigned int *linenumber_ptr
,
3126 unsigned int addr_size
,
3129 /* Read each compilation unit from the section .debug_info, and check
3130 to see if it contains the address we are searching for. If yes,
3131 lookup the address, and return the line number info. If no, go
3132 on to the next compilation unit.
3134 We keep a list of all the previously read compilation units, and
3135 a pointer to the next un-read compilation unit. Check the
3136 previously read units before reading more. */
3137 struct dwarf2_debug
*stash
;
3138 /* What address are we looking for? */
3140 struct comp_unit
* each
;
3141 bfd_vma found
= FALSE
;
3142 bfd_boolean do_line
;
3144 stash
= (struct dwarf2_debug
*) *pinfo
;
3148 bfd_size_type amt
= sizeof (struct dwarf2_debug
);
3150 stash
= (struct dwarf2_debug
*) bfd_zalloc (abfd
, amt
);
3155 /* In a relocatable file, 2 functions may have the same address.
3156 We change the section vma so that they won't overlap. */
3157 if ((abfd
->flags
& (EXEC_P
| DYNAMIC
)) == 0)
3159 if (! place_sections (abfd
, stash
))
3163 do_line
= (section
== NULL
3165 && functionname_ptr
== NULL
3169 addr
= symbol
->value
;
3170 section
= bfd_get_section (symbol
);
3172 else if (section
!= NULL
3173 && functionname_ptr
!= NULL
3179 if (section
->output_section
)
3180 addr
+= section
->output_section
->vma
+ section
->output_offset
;
3182 addr
+= section
->vma
;
3183 *filename_ptr
= NULL
;
3185 *functionname_ptr
= NULL
;
3186 *linenumber_ptr
= 0;
3191 bfd_size_type total_size
;
3196 msec
= find_debug_info (abfd
, NULL
);
3199 char * debug_filename
= bfd_follow_gnu_debuglink (abfd
, DEBUGDIR
);
3201 if (debug_filename
== NULL
)
3202 /* No dwarf2 info, and no gnu_debuglink to follow.
3203 Note that at this point the stash has been allocated, but
3204 contains zeros. This lets future calls to this function
3205 fail more quickly. */
3208 if ((debug_bfd
= bfd_openr (debug_filename
, NULL
)) == NULL
3209 || ! bfd_check_format (debug_bfd
, bfd_object
)
3210 || (msec
= find_debug_info (debug_bfd
, NULL
)) == NULL
)
3213 bfd_close (debug_bfd
);
3214 /* FIXME: Should we report our failure to follow the debuglink ? */
3215 free (debug_filename
);
3222 /* There can be more than one DWARF2 info section in a BFD these
3223 days. First handle the easy case when there's only one. If
3224 there's more than one, try case two: none of the sections is
3225 compressed. In that case, read them all in and produce one
3226 large stash. We do this in two passes - in the first pass we
3227 just accumulate the section sizes, and in the second pass we
3228 read in the section's contents. (The allows us to avoid
3229 reallocing the data as we add sections to the stash.) If
3230 some or all sections are compressed, then do things the slow
3231 way, with a bunch of reallocs. */
3233 if (! find_debug_info (debug_bfd
, msec
))
3235 /* Case 1: only one info section. */
3236 total_size
= msec
->size
;
3237 if (! read_section (debug_bfd
, debug_info
, symbols
, 0,
3238 &stash
->info_ptr_memory
, &total_size
))
3243 /* Case 2: multiple sections. */
3244 for (total_size
= 0; msec
; msec
= find_debug_info (debug_bfd
, msec
))
3245 total_size
+= msec
->size
;
3247 stash
->info_ptr_memory
= (bfd_byte
*) bfd_malloc (total_size
);
3248 if (stash
->info_ptr_memory
== NULL
)
3252 for (msec
= find_debug_info (debug_bfd
, NULL
);
3254 msec
= find_debug_info (debug_bfd
, msec
))
3262 if (!(bfd_simple_get_relocated_section_contents
3263 (debug_bfd
, msec
, stash
->info_ptr_memory
+ total_size
,
3271 stash
->info_ptr
= stash
->info_ptr_memory
;
3272 stash
->info_ptr_end
= stash
->info_ptr
+ total_size
;
3273 stash
->sec
= find_debug_info (debug_bfd
, NULL
);
3274 stash
->sec_info_ptr
= stash
->info_ptr
;
3275 stash
->syms
= symbols
;
3276 stash
->bfd_ptr
= debug_bfd
;
3279 /* A null info_ptr indicates that there is no dwarf2 info
3280 (or that an error occured while setting up the stash). */
3281 if (! stash
->info_ptr
)
3284 stash
->inliner_chain
= NULL
;
3286 /* Check the previously read comp. units first. */
3289 /* The info hash tables use quite a bit of memory. We may not want to
3290 always use them. We use some heuristics to decide if and when to
3292 if (stash
->info_hash_status
== STASH_INFO_HASH_OFF
)
3293 stash_maybe_enable_info_hash_tables (abfd
, stash
);
3295 /* Keep info hash table up to date if they are available. Note that we
3296 may disable the hash tables if there is any error duing update. */
3297 if (stash
->info_hash_status
== STASH_INFO_HASH_ON
)
3298 stash_maybe_update_info_hash_tables (stash
);
3300 if (stash
->info_hash_status
== STASH_INFO_HASH_ON
)
3302 found
= stash_find_line_fast (stash
, symbol
, addr
, filename_ptr
,
3309 /* Check the previously read comp. units first. */
3310 for (each
= stash
->all_comp_units
; each
; each
= each
->next_unit
)
3311 if ((symbol
->flags
& BSF_FUNCTION
) == 0
3312 || comp_unit_contains_address (each
, addr
))
3314 found
= comp_unit_find_line (each
, symbol
, addr
, filename_ptr
,
3315 linenumber_ptr
, stash
);
3323 for (each
= stash
->all_comp_units
; each
; each
= each
->next_unit
)
3325 found
= (comp_unit_contains_address (each
, addr
)
3326 && comp_unit_find_nearest_line (each
, addr
,
3336 /* The DWARF2 spec says that the initial length field, and the
3337 offset of the abbreviation table, should both be 4-byte values.
3338 However, some compilers do things differently. */
3341 BFD_ASSERT (addr_size
== 4 || addr_size
== 8);
3343 /* Read each remaining comp. units checking each as they are read. */
3344 while (stash
->info_ptr
< stash
->info_ptr_end
)
3347 unsigned int offset_size
= addr_size
;
3348 bfd_byte
*info_ptr_unit
= stash
->info_ptr
;
3350 length
= read_4_bytes (stash
->bfd_ptr
, stash
->info_ptr
);
3351 /* A 0xffffff length is the DWARF3 way of indicating
3352 we use 64-bit offsets, instead of 32-bit offsets. */
3353 if (length
== 0xffffffff)
3356 length
= read_8_bytes (stash
->bfd_ptr
, stash
->info_ptr
+ 4);
3357 stash
->info_ptr
+= 12;
3359 /* A zero length is the IRIX way of indicating 64-bit offsets,
3360 mostly because the 64-bit length will generally fit in 32
3361 bits, and the endianness helps. */
3362 else if (length
== 0)
3365 length
= read_4_bytes (stash
->bfd_ptr
, stash
->info_ptr
+ 4);
3366 stash
->info_ptr
+= 8;
3368 /* In the absence of the hints above, we assume 32-bit DWARF2
3369 offsets even for targets with 64-bit addresses, because:
3370 a) most of the time these targets will not have generated
3371 more than 2Gb of debug info and so will not need 64-bit
3374 b) if they do use 64-bit offsets but they are not using
3375 the size hints that are tested for above then they are
3376 not conforming to the DWARF3 standard anyway. */
3377 else if (addr_size
== 8)
3380 stash
->info_ptr
+= 4;
3383 stash
->info_ptr
+= 4;
3387 each
= parse_comp_unit (stash
, length
, info_ptr_unit
,
3390 /* The dwarf information is damaged, don't trust it any
3393 stash
->info_ptr
+= length
;
3395 if (stash
->all_comp_units
)
3396 stash
->all_comp_units
->prev_unit
= each
;
3398 stash
->last_comp_unit
= each
;
3400 each
->next_unit
= stash
->all_comp_units
;
3401 stash
->all_comp_units
= each
;
3403 /* DW_AT_low_pc and DW_AT_high_pc are optional for
3404 compilation units. If we don't have them (i.e.,
3405 unit->high == 0), we need to consult the line info table
3406 to see if a compilation unit contains the given
3409 found
= (((symbol
->flags
& BSF_FUNCTION
) == 0
3410 || each
->arange
.high
== 0
3411 || comp_unit_contains_address (each
, addr
))
3412 && comp_unit_find_line (each
, symbol
, addr
,
3417 found
= ((each
->arange
.high
== 0
3418 || comp_unit_contains_address (each
, addr
))
3419 && comp_unit_find_nearest_line (each
, addr
,
3425 if ((bfd_vma
) (stash
->info_ptr
- stash
->sec_info_ptr
)
3426 == stash
->sec
->size
)
3428 stash
->sec
= find_debug_info (stash
->bfd_ptr
, stash
->sec
);
3429 stash
->sec_info_ptr
= stash
->info_ptr
;
3438 if ((abfd
->flags
& (EXEC_P
| DYNAMIC
)) == 0)
3439 unset_sections (stash
);
3444 /* The DWARF2 version of find_nearest_line.
3445 Return TRUE if the line is found without error. */
3448 _bfd_dwarf2_find_nearest_line (bfd
*abfd
,
3452 const char **filename_ptr
,
3453 const char **functionname_ptr
,
3454 unsigned int *linenumber_ptr
,
3455 unsigned int addr_size
,
3458 return find_line (abfd
, section
, offset
, NULL
, symbols
, filename_ptr
,
3459 functionname_ptr
, linenumber_ptr
, addr_size
,
3463 /* The DWARF2 version of find_line.
3464 Return TRUE if the line is found without error. */
3467 _bfd_dwarf2_find_line (bfd
*abfd
,
3470 const char **filename_ptr
,
3471 unsigned int *linenumber_ptr
,
3472 unsigned int addr_size
,
3475 return find_line (abfd
, NULL
, 0, symbol
, symbols
, filename_ptr
,
3476 NULL
, linenumber_ptr
, addr_size
,
3481 _bfd_dwarf2_find_inliner_info (bfd
*abfd ATTRIBUTE_UNUSED
,
3482 const char **filename_ptr
,
3483 const char **functionname_ptr
,
3484 unsigned int *linenumber_ptr
,
3487 struct dwarf2_debug
*stash
;
3489 stash
= (struct dwarf2_debug
*) *pinfo
;
3492 struct funcinfo
*func
= stash
->inliner_chain
;
3494 if (func
&& func
->caller_func
)
3496 *filename_ptr
= func
->caller_file
;
3497 *functionname_ptr
= func
->caller_func
->name
;
3498 *linenumber_ptr
= func
->caller_line
;
3499 stash
->inliner_chain
= func
->caller_func
;
3508 _bfd_dwarf2_cleanup_debug_info (bfd
*abfd
)
3510 struct comp_unit
*each
;
3511 struct dwarf2_debug
*stash
;
3513 if (abfd
== NULL
|| elf_tdata (abfd
) == NULL
)
3516 stash
= (struct dwarf2_debug
*) elf_tdata (abfd
)->dwarf2_find_line_info
;
3521 for (each
= stash
->all_comp_units
; each
; each
= each
->next_unit
)
3523 struct abbrev_info
**abbrevs
= each
->abbrevs
;
3524 struct funcinfo
*function_table
= each
->function_table
;
3525 struct varinfo
*variable_table
= each
->variable_table
;
3528 for (i
= 0; i
< ABBREV_HASH_SIZE
; i
++)
3530 struct abbrev_info
*abbrev
= abbrevs
[i
];
3534 free (abbrev
->attrs
);
3535 abbrev
= abbrev
->next
;
3539 if (each
->line_table
)
3541 free (each
->line_table
->dirs
);
3542 free (each
->line_table
->files
);
3545 while (function_table
)
3547 if (function_table
->file
)
3549 free (function_table
->file
);
3550 function_table
->file
= NULL
;
3553 if (function_table
->caller_file
)
3555 free (function_table
->caller_file
);
3556 function_table
->caller_file
= NULL
;
3558 function_table
= function_table
->prev_func
;
3561 while (variable_table
)
3563 if (variable_table
->file
)
3565 free (variable_table
->file
);
3566 variable_table
->file
= NULL
;
3569 variable_table
= variable_table
->prev_var
;
3573 if (stash
->dwarf_abbrev_buffer
)
3574 free (stash
->dwarf_abbrev_buffer
);
3575 if (stash
->dwarf_line_buffer
)
3576 free (stash
->dwarf_line_buffer
);
3577 if (stash
->dwarf_str_buffer
)
3578 free (stash
->dwarf_str_buffer
);
3579 if (stash
->dwarf_ranges_buffer
)
3580 free (stash
->dwarf_ranges_buffer
);
3581 if (stash
->info_ptr_memory
)
3582 free (stash
->info_ptr_memory
);