2 Copyright (C) 1994-2019 Free Software Foundation, Inc.
4 Adapted from gdb/dwarf2read.c by Gavin Koch of Cygnus Solutions
7 From the dwarf2read.c header:
8 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
9 Inc. with support from Florida State University (under contract
10 with the Ada Joint Program Office), and Silicon Graphics, Inc.
11 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
12 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
13 support in dwarfread.c
15 This file is part of BFD.
17 This program is free software; you can redistribute it and/or modify
18 it under the terms of the GNU General Public License as published by
19 the Free Software Foundation; either version 3 of the License, or (at
20 your option) any later version.
22 This program is distributed in the hope that it will be useful, but
23 WITHOUT ANY WARRANTY; without even the implied warranty of
24 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25 General Public License for more details.
27 You should have received a copy of the GNU General Public License
28 along with this program; if not, write to the Free Software
29 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
30 MA 02110-1301, USA. */
34 #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 /* Names of the debug sections. */
94 const struct dwarf_debug_section
*debug_sections
;
96 /* The next unread compilation unit within the .debug_info section.
97 Zero indicates that the .debug_info section has not been loaded
101 /* Pointer to the end of the .debug_info section memory buffer. */
102 bfd_byte
*info_ptr_end
;
104 /* Pointer to the original bfd for which debug was loaded. This is what
105 we use to compare and so check that the cached debug data is still
106 valid - it saves having to possibly dereference the gnu_debuglink each
110 /* Pointer to the bfd, section and address of the beginning of the
111 section. The bfd might be different than expected because of
112 gnu_debuglink sections. */
115 bfd_byte
*sec_info_ptr
;
117 /* Support for alternate debug info sections created by the DWZ utility:
118 This includes a pointer to an alternate bfd which contains *extra*,
119 possibly duplicate debug sections, and pointers to the loaded
120 .debug_str and .debug_info sections from this bfd. */
122 bfd_byte
* alt_dwarf_str_buffer
;
123 bfd_size_type alt_dwarf_str_size
;
124 bfd_byte
* alt_dwarf_info_buffer
;
125 bfd_size_type alt_dwarf_info_size
;
127 /* A pointer to the memory block allocated for info_ptr. Neither
128 info_ptr nor sec_info_ptr are guaranteed to stay pointing to the
129 beginning of the malloc block. */
130 bfd_byte
*info_ptr_memory
;
132 /* Pointer to the symbol table. */
135 /* Pointer to the .debug_abbrev section loaded into memory. */
136 bfd_byte
*dwarf_abbrev_buffer
;
138 /* Length of the loaded .debug_abbrev section. */
139 bfd_size_type dwarf_abbrev_size
;
141 /* Buffer for decode_line_info. */
142 bfd_byte
*dwarf_line_buffer
;
144 /* Length of the loaded .debug_line section. */
145 bfd_size_type dwarf_line_size
;
147 /* Pointer to the .debug_str section loaded into memory. */
148 bfd_byte
*dwarf_str_buffer
;
150 /* Length of the loaded .debug_str section. */
151 bfd_size_type dwarf_str_size
;
153 /* Pointer to the .debug_line_str section loaded into memory. */
154 bfd_byte
*dwarf_line_str_buffer
;
156 /* Length of the loaded .debug_line_str section. */
157 bfd_size_type dwarf_line_str_size
;
159 /* Pointer to the .debug_ranges section loaded into memory. */
160 bfd_byte
*dwarf_ranges_buffer
;
162 /* Length of the loaded .debug_ranges section. */
163 bfd_size_type dwarf_ranges_size
;
165 /* If the most recent call to bfd_find_nearest_line was given an
166 address in an inlined function, preserve a pointer into the
167 calling chain for subsequent calls to bfd_find_inliner_info to
169 struct funcinfo
*inliner_chain
;
171 /* Section VMAs at the time the stash was built. */
173 /* Number of sections in the SEC_VMA table. */
174 unsigned int sec_vma_count
;
176 /* Number of sections whose VMA we must adjust. */
177 int adjusted_section_count
;
179 /* Array of sections with adjusted VMA. */
180 struct adjusted_section
*adjusted_sections
;
182 /* Number of times find_line is called. This is used in
183 the heuristic for enabling the info hash tables. */
186 #define STASH_INFO_HASH_TRIGGER 100
188 /* Hash table mapping symbol names to function infos. */
189 struct info_hash_table
*funcinfo_hash_table
;
191 /* Hash table mapping symbol names to variable infos. */
192 struct info_hash_table
*varinfo_hash_table
;
194 /* Head of comp_unit list in the last hash table update. */
195 struct comp_unit
*hash_units_head
;
197 /* Status of info hash. */
198 int info_hash_status
;
199 #define STASH_INFO_HASH_OFF 0
200 #define STASH_INFO_HASH_ON 1
201 #define STASH_INFO_HASH_DISABLED 2
203 /* True if we opened bfd_ptr. */
204 bfd_boolean close_on_cleanup
;
214 /* A minimal decoding of DWARF2 compilation units. We only decode
215 what's needed to get to the line number information. */
219 /* Chain the previously read compilation units. */
220 struct comp_unit
*next_unit
;
222 /* Likewise, chain the compilation unit read after this one.
223 The comp units are stored in reversed reading order. */
224 struct comp_unit
*prev_unit
;
226 /* Keep the bfd convenient (for memory allocation). */
229 /* The lowest and highest addresses contained in this compilation
230 unit as specified in the compilation unit header. */
231 struct arange arange
;
233 /* The DW_AT_name attribute (for error messages). */
236 /* The abbrev hash table. */
237 struct abbrev_info
**abbrevs
;
239 /* DW_AT_language. */
242 /* Note that an error was found by comp_unit_find_nearest_line. */
245 /* The DW_AT_comp_dir attribute. */
248 /* TRUE if there is a line number table associated with this comp. unit. */
251 /* Pointer to the current comp_unit so that we can find a given entry
253 bfd_byte
*info_ptr_unit
;
255 /* The offset into .debug_line of the line number table. */
256 unsigned long line_offset
;
258 /* Pointer to the first child die for the comp unit. */
259 bfd_byte
*first_child_die_ptr
;
261 /* The end of the comp unit. */
264 /* The decoded line number, NULL if not yet decoded. */
265 struct line_info_table
*line_table
;
267 /* A list of the functions found in this comp. unit. */
268 struct funcinfo
*function_table
;
270 /* A table of function information references searchable by address. */
271 struct lookup_funcinfo
*lookup_funcinfo_table
;
273 /* Number of functions in the function_table and sorted_function_table. */
274 bfd_size_type number_of_functions
;
276 /* A list of the variables found in this comp. unit. */
277 struct varinfo
*variable_table
;
279 /* Pointer to dwarf2_debug structure. */
280 struct dwarf2_debug
*stash
;
282 /* DWARF format version for this unit - from unit header. */
285 /* Address size for this unit - from unit header. */
286 unsigned char addr_size
;
288 /* Offset size for this unit - from unit header. */
289 unsigned char offset_size
;
291 /* Base address for this unit - from DW_AT_low_pc attribute of
292 DW_TAG_compile_unit DIE */
293 bfd_vma base_address
;
295 /* TRUE if symbols are cached in hash table for faster lookup by name. */
299 /* This data structure holds the information of an abbrev. */
302 unsigned int number
; /* Number identifying abbrev. */
303 enum dwarf_tag tag
; /* DWARF tag. */
304 int has_children
; /* Boolean. */
305 unsigned int num_attrs
; /* Number of attributes. */
306 struct attr_abbrev
*attrs
; /* An array of attribute descriptions. */
307 struct abbrev_info
*next
; /* Next in chain. */
312 enum dwarf_attribute name
;
313 enum dwarf_form form
;
314 bfd_vma implicit_const
;
317 /* Map of uncompressed DWARF debug section name to compressed one. It
318 is terminated by NULL uncompressed_name. */
320 const struct dwarf_debug_section dwarf_debug_sections
[] =
322 { ".debug_abbrev", ".zdebug_abbrev" },
323 { ".debug_aranges", ".zdebug_aranges" },
324 { ".debug_frame", ".zdebug_frame" },
325 { ".debug_info", ".zdebug_info" },
326 { ".debug_info", ".zdebug_info" },
327 { ".debug_line", ".zdebug_line" },
328 { ".debug_loc", ".zdebug_loc" },
329 { ".debug_macinfo", ".zdebug_macinfo" },
330 { ".debug_macro", ".zdebug_macro" },
331 { ".debug_pubnames", ".zdebug_pubnames" },
332 { ".debug_pubtypes", ".zdebug_pubtypes" },
333 { ".debug_ranges", ".zdebug_ranges" },
334 { ".debug_static_func", ".zdebug_static_func" },
335 { ".debug_static_vars", ".zdebug_static_vars" },
336 { ".debug_str", ".zdebug_str", },
337 { ".debug_str", ".zdebug_str", },
338 { ".debug_line_str", ".zdebug_line_str", },
339 { ".debug_types", ".zdebug_types" },
340 /* GNU DWARF 1 extensions */
341 { ".debug_sfnames", ".zdebug_sfnames" },
342 { ".debug_srcinfo", ".zebug_srcinfo" },
343 /* SGI/MIPS DWARF 2 extensions */
344 { ".debug_funcnames", ".zdebug_funcnames" },
345 { ".debug_typenames", ".zdebug_typenames" },
346 { ".debug_varnames", ".zdebug_varnames" },
347 { ".debug_weaknames", ".zdebug_weaknames" },
351 /* NB/ Numbers in this enum must match up with indices
352 into the dwarf_debug_sections[] array above. */
353 enum dwarf_debug_section_enum
382 /* A static assertion. */
383 extern int dwarf_debug_section_assert
[ARRAY_SIZE (dwarf_debug_sections
)
384 == debug_max
+ 1 ? 1 : -1];
386 #ifndef ABBREV_HASH_SIZE
387 #define ABBREV_HASH_SIZE 121
389 #ifndef ATTR_ALLOC_CHUNK
390 #define ATTR_ALLOC_CHUNK 4
393 /* Variable and function hash tables. This is used to speed up look-up
394 in lookup_symbol_in_var_table() and lookup_symbol_in_function_table().
395 In order to share code between variable and function infos, we use
396 a list of untyped pointer for all variable/function info associated with
397 a symbol. We waste a bit of memory for list with one node but that
398 simplifies the code. */
400 struct info_list_node
402 struct info_list_node
*next
;
406 /* Info hash entry. */
407 struct info_hash_entry
409 struct bfd_hash_entry root
;
410 struct info_list_node
*head
;
413 struct info_hash_table
415 struct bfd_hash_table base
;
418 /* Function to create a new entry in info hash table. */
420 static struct bfd_hash_entry
*
421 info_hash_table_newfunc (struct bfd_hash_entry
*entry
,
422 struct bfd_hash_table
*table
,
425 struct info_hash_entry
*ret
= (struct info_hash_entry
*) entry
;
427 /* Allocate the structure if it has not already been allocated by a
431 ret
= (struct info_hash_entry
*) bfd_hash_allocate (table
,
437 /* Call the allocation method of the base class. */
438 ret
= ((struct info_hash_entry
*)
439 bfd_hash_newfunc ((struct bfd_hash_entry
*) ret
, table
, string
));
441 /* Initialize the local fields here. */
445 return (struct bfd_hash_entry
*) ret
;
448 /* Function to create a new info hash table. It returns a pointer to the
449 newly created table or NULL if there is any error. We need abfd
450 solely for memory allocation. */
452 static struct info_hash_table
*
453 create_info_hash_table (bfd
*abfd
)
455 struct info_hash_table
*hash_table
;
457 hash_table
= ((struct info_hash_table
*)
458 bfd_alloc (abfd
, sizeof (struct info_hash_table
)));
462 if (!bfd_hash_table_init (&hash_table
->base
, info_hash_table_newfunc
,
463 sizeof (struct info_hash_entry
)))
465 bfd_release (abfd
, hash_table
);
472 /* Insert an info entry into an info hash table. We do not check of
473 duplicate entries. Also, the caller need to guarantee that the
474 right type of info in inserted as info is passed as a void* pointer.
475 This function returns true if there is no error. */
478 insert_info_hash_table (struct info_hash_table
*hash_table
,
483 struct info_hash_entry
*entry
;
484 struct info_list_node
*node
;
486 entry
= (struct info_hash_entry
*) bfd_hash_lookup (&hash_table
->base
,
491 node
= (struct info_list_node
*) bfd_hash_allocate (&hash_table
->base
,
497 node
->next
= entry
->head
;
503 /* Look up an info entry list from an info hash table. Return NULL
506 static struct info_list_node
*
507 lookup_info_hash_table (struct info_hash_table
*hash_table
, const char *key
)
509 struct info_hash_entry
*entry
;
511 entry
= (struct info_hash_entry
*) bfd_hash_lookup (&hash_table
->base
, key
,
513 return entry
? entry
->head
: NULL
;
516 /* Read a section into its appropriate place in the dwarf2_debug
517 struct (indicated by SECTION_BUFFER and SECTION_SIZE). If SYMS is
518 not NULL, use bfd_simple_get_relocated_section_contents to read the
519 section contents, otherwise use bfd_get_section_contents. Fail if
520 the located section does not contain at least OFFSET bytes. */
523 read_section (bfd
* abfd
,
524 const struct dwarf_debug_section
*sec
,
527 bfd_byte
** section_buffer
,
528 bfd_size_type
* section_size
)
531 const char *section_name
= sec
->uncompressed_name
;
532 bfd_byte
*contents
= *section_buffer
;
535 /* The section may have already been read. */
536 if (contents
== NULL
)
538 msec
= bfd_get_section_by_name (abfd
, section_name
);
541 section_name
= sec
->compressed_name
;
542 if (section_name
!= NULL
)
543 msec
= bfd_get_section_by_name (abfd
, section_name
);
547 _bfd_error_handler (_("DWARF error: can't find %s section."),
548 sec
->uncompressed_name
);
549 bfd_set_error (bfd_error_bad_value
);
553 *section_size
= msec
->rawsize
? msec
->rawsize
: msec
->size
;
554 /* Paranoia - alloc one extra so that we can make sure a string
555 section is NUL terminated. */
556 amt
= *section_size
+ 1;
559 bfd_set_error (bfd_error_no_memory
);
562 contents
= (bfd_byte
*) bfd_malloc (amt
);
563 if (contents
== NULL
)
566 ? !bfd_simple_get_relocated_section_contents (abfd
, msec
, contents
,
568 : !bfd_get_section_contents (abfd
, msec
, contents
, 0, *section_size
))
573 contents
[*section_size
] = 0;
574 *section_buffer
= contents
;
577 /* It is possible to get a bad value for the offset into the section
578 that the client wants. Validate it here to avoid trouble later. */
579 if (offset
!= 0 && offset
>= *section_size
)
581 /* xgettext: c-format */
582 _bfd_error_handler (_("DWARF error: offset (%" PRIu64
")"
583 " greater than or equal to %s size (%" PRIu64
")"),
584 (uint64_t) offset
, section_name
,
585 (uint64_t) *section_size
);
586 bfd_set_error (bfd_error_bad_value
);
593 /* Read dwarf information from a buffer. */
596 read_1_byte (bfd
*abfd ATTRIBUTE_UNUSED
, bfd_byte
*buf
, bfd_byte
*end
)
600 return bfd_get_8 (abfd
, buf
);
604 read_1_signed_byte (bfd
*abfd ATTRIBUTE_UNUSED
, bfd_byte
*buf
, bfd_byte
*end
)
608 return bfd_get_signed_8 (abfd
, buf
);
612 read_2_bytes (bfd
*abfd
, bfd_byte
*buf
, bfd_byte
*end
)
616 return bfd_get_16 (abfd
, buf
);
620 read_4_bytes (bfd
*abfd
, bfd_byte
*buf
, bfd_byte
*end
)
624 return bfd_get_32 (abfd
, buf
);
628 read_8_bytes (bfd
*abfd
, bfd_byte
*buf
, bfd_byte
*end
)
632 return bfd_get_64 (abfd
, buf
);
636 read_n_bytes (bfd_byte
* buf
,
638 struct dwarf_block
* block
)
640 unsigned int size
= block
->size
;
641 bfd_byte
* block_end
= buf
+ size
;
643 if (block_end
> end
|| block_end
< buf
)
656 /* Scans a NUL terminated string starting at BUF, returning a pointer to it.
657 Returns the number of characters in the string, *including* the NUL byte,
658 in BYTES_READ_PTR. This value is set even if the function fails. Bytes
659 at or beyond BUF_END will not be read. Returns NULL if there was a
660 problem, or if the string is empty. */
663 read_string (bfd
* abfd ATTRIBUTE_UNUSED
,
666 unsigned int * bytes_read_ptr
)
672 * bytes_read_ptr
= 0;
678 * bytes_read_ptr
= 1;
682 while (buf
< buf_end
)
685 * bytes_read_ptr
= buf
- str
;
689 * bytes_read_ptr
= buf
- str
;
693 /* Reads an offset from BUF and then locates the string at this offset
694 inside the debug string section. Returns a pointer to the string.
695 Returns the number of bytes read from BUF, *not* the length of the string,
696 in BYTES_READ_PTR. This value is set even if the function fails. Bytes
697 at or beyond BUF_END will not be read from BUF. Returns NULL if there was
698 a problem, or if the string is empty. Does not check for NUL termination
702 read_indirect_string (struct comp_unit
* unit
,
705 unsigned int * bytes_read_ptr
)
708 struct dwarf2_debug
*stash
= unit
->stash
;
711 if (buf
+ unit
->offset_size
> buf_end
)
713 * bytes_read_ptr
= 0;
717 if (unit
->offset_size
== 4)
718 offset
= read_4_bytes (unit
->abfd
, buf
, buf_end
);
720 offset
= read_8_bytes (unit
->abfd
, buf
, buf_end
);
722 *bytes_read_ptr
= unit
->offset_size
;
724 if (! read_section (unit
->abfd
, &stash
->debug_sections
[debug_str
],
726 &stash
->dwarf_str_buffer
, &stash
->dwarf_str_size
))
729 if (offset
>= stash
->dwarf_str_size
)
731 str
= (char *) stash
->dwarf_str_buffer
+ offset
;
737 /* Like read_indirect_string but from .debug_line_str section. */
740 read_indirect_line_string (struct comp_unit
* unit
,
743 unsigned int * bytes_read_ptr
)
746 struct dwarf2_debug
*stash
= unit
->stash
;
749 if (buf
+ unit
->offset_size
> buf_end
)
751 * bytes_read_ptr
= 0;
755 if (unit
->offset_size
== 4)
756 offset
= read_4_bytes (unit
->abfd
, buf
, buf_end
);
758 offset
= read_8_bytes (unit
->abfd
, buf
, buf_end
);
760 *bytes_read_ptr
= unit
->offset_size
;
762 if (! read_section (unit
->abfd
, &stash
->debug_sections
[debug_line_str
],
764 &stash
->dwarf_line_str_buffer
,
765 &stash
->dwarf_line_str_size
))
768 if (offset
>= stash
->dwarf_line_str_size
)
770 str
= (char *) stash
->dwarf_line_str_buffer
+ offset
;
776 /* Like read_indirect_string but uses a .debug_str located in
777 an alternate file pointed to by the .gnu_debugaltlink section.
778 Used to impement DW_FORM_GNU_strp_alt. */
781 read_alt_indirect_string (struct comp_unit
* unit
,
784 unsigned int * bytes_read_ptr
)
787 struct dwarf2_debug
*stash
= unit
->stash
;
790 if (buf
+ unit
->offset_size
> buf_end
)
792 * bytes_read_ptr
= 0;
796 if (unit
->offset_size
== 4)
797 offset
= read_4_bytes (unit
->abfd
, buf
, buf_end
);
799 offset
= read_8_bytes (unit
->abfd
, buf
, buf_end
);
801 *bytes_read_ptr
= unit
->offset_size
;
803 if (stash
->alt_bfd_ptr
== NULL
)
806 char * debug_filename
= bfd_follow_gnu_debugaltlink (unit
->abfd
, DEBUGDIR
);
808 if (debug_filename
== NULL
)
811 if ((debug_bfd
= bfd_openr (debug_filename
, NULL
)) == NULL
812 || ! bfd_check_format (debug_bfd
, bfd_object
))
815 bfd_close (debug_bfd
);
817 /* FIXME: Should we report our failure to follow the debuglink ? */
818 free (debug_filename
);
821 stash
->alt_bfd_ptr
= debug_bfd
;
824 if (! read_section (unit
->stash
->alt_bfd_ptr
,
825 stash
->debug_sections
+ debug_str_alt
,
826 NULL
, /* FIXME: Do we need to load alternate symbols ? */
828 &stash
->alt_dwarf_str_buffer
,
829 &stash
->alt_dwarf_str_size
))
832 if (offset
>= stash
->alt_dwarf_str_size
)
834 str
= (char *) stash
->alt_dwarf_str_buffer
+ offset
;
841 /* Resolve an alternate reference from UNIT at OFFSET.
842 Returns a pointer into the loaded alternate CU upon success
843 or NULL upon failure. */
846 read_alt_indirect_ref (struct comp_unit
* unit
,
849 struct dwarf2_debug
*stash
= unit
->stash
;
851 if (stash
->alt_bfd_ptr
== NULL
)
854 char * debug_filename
= bfd_follow_gnu_debugaltlink (unit
->abfd
, DEBUGDIR
);
856 if (debug_filename
== NULL
)
859 if ((debug_bfd
= bfd_openr (debug_filename
, NULL
)) == NULL
860 || ! bfd_check_format (debug_bfd
, bfd_object
))
863 bfd_close (debug_bfd
);
865 /* FIXME: Should we report our failure to follow the debuglink ? */
866 free (debug_filename
);
869 stash
->alt_bfd_ptr
= debug_bfd
;
872 if (! read_section (unit
->stash
->alt_bfd_ptr
,
873 stash
->debug_sections
+ debug_info_alt
,
874 NULL
, /* FIXME: Do we need to load alternate symbols ? */
876 &stash
->alt_dwarf_info_buffer
,
877 &stash
->alt_dwarf_info_size
))
880 if (offset
>= stash
->alt_dwarf_info_size
)
882 return stash
->alt_dwarf_info_buffer
+ offset
;
886 read_address (struct comp_unit
*unit
, bfd_byte
*buf
, bfd_byte
* buf_end
)
890 if (bfd_get_flavour (unit
->abfd
) == bfd_target_elf_flavour
)
891 signed_vma
= get_elf_backend_data (unit
->abfd
)->sign_extend_vma
;
893 if (buf
+ unit
->addr_size
> buf_end
)
898 switch (unit
->addr_size
)
901 return bfd_get_signed_64 (unit
->abfd
, buf
);
903 return bfd_get_signed_32 (unit
->abfd
, buf
);
905 return bfd_get_signed_16 (unit
->abfd
, buf
);
912 switch (unit
->addr_size
)
915 return bfd_get_64 (unit
->abfd
, buf
);
917 return bfd_get_32 (unit
->abfd
, buf
);
919 return bfd_get_16 (unit
->abfd
, buf
);
926 /* Lookup an abbrev_info structure in the abbrev hash table. */
928 static struct abbrev_info
*
929 lookup_abbrev (unsigned int number
, struct abbrev_info
**abbrevs
)
931 unsigned int hash_number
;
932 struct abbrev_info
*abbrev
;
934 hash_number
= number
% ABBREV_HASH_SIZE
;
935 abbrev
= abbrevs
[hash_number
];
939 if (abbrev
->number
== number
)
942 abbrev
= abbrev
->next
;
948 /* In DWARF version 2, the description of the debugging information is
949 stored in a separate .debug_abbrev section. Before we read any
950 dies from a section we read in all abbreviations and install them
953 static struct abbrev_info
**
954 read_abbrevs (bfd
*abfd
, bfd_uint64_t offset
, struct dwarf2_debug
*stash
)
956 struct abbrev_info
**abbrevs
;
957 bfd_byte
*abbrev_ptr
;
958 bfd_byte
*abbrev_end
;
959 struct abbrev_info
*cur_abbrev
;
960 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
961 unsigned int abbrev_form
, hash_number
;
964 if (! read_section (abfd
, &stash
->debug_sections
[debug_abbrev
],
966 &stash
->dwarf_abbrev_buffer
, &stash
->dwarf_abbrev_size
))
969 if (offset
>= stash
->dwarf_abbrev_size
)
972 amt
= sizeof (struct abbrev_info
*) * ABBREV_HASH_SIZE
;
973 abbrevs
= (struct abbrev_info
**) bfd_zalloc (abfd
, amt
);
977 abbrev_ptr
= stash
->dwarf_abbrev_buffer
+ offset
;
978 abbrev_end
= stash
->dwarf_abbrev_buffer
+ stash
->dwarf_abbrev_size
;
979 abbrev_number
= _bfd_safe_read_leb128 (abfd
, abbrev_ptr
, &bytes_read
,
981 abbrev_ptr
+= bytes_read
;
983 /* Loop until we reach an abbrev number of 0. */
984 while (abbrev_number
)
986 amt
= sizeof (struct abbrev_info
);
987 cur_abbrev
= (struct abbrev_info
*) bfd_zalloc (abfd
, amt
);
988 if (cur_abbrev
== NULL
)
991 /* Read in abbrev header. */
992 cur_abbrev
->number
= abbrev_number
;
993 cur_abbrev
->tag
= (enum dwarf_tag
)
994 _bfd_safe_read_leb128 (abfd
, abbrev_ptr
, &bytes_read
,
996 abbrev_ptr
+= bytes_read
;
997 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
, abbrev_end
);
1000 /* Now read in declarations. */
1003 /* Initialize it just to avoid a GCC false warning. */
1004 bfd_vma implicit_const
= -1;
1006 abbrev_name
= _bfd_safe_read_leb128 (abfd
, abbrev_ptr
, &bytes_read
,
1008 abbrev_ptr
+= bytes_read
;
1009 abbrev_form
= _bfd_safe_read_leb128 (abfd
, abbrev_ptr
, &bytes_read
,
1011 abbrev_ptr
+= bytes_read
;
1012 if (abbrev_form
== DW_FORM_implicit_const
)
1014 implicit_const
= _bfd_safe_read_leb128 (abfd
, abbrev_ptr
,
1017 abbrev_ptr
+= bytes_read
;
1020 if (abbrev_name
== 0)
1023 if ((cur_abbrev
->num_attrs
% ATTR_ALLOC_CHUNK
) == 0)
1025 struct attr_abbrev
*tmp
;
1027 amt
= cur_abbrev
->num_attrs
+ ATTR_ALLOC_CHUNK
;
1028 amt
*= sizeof (struct attr_abbrev
);
1029 tmp
= (struct attr_abbrev
*) bfd_realloc (cur_abbrev
->attrs
, amt
);
1034 for (i
= 0; i
< ABBREV_HASH_SIZE
; i
++)
1036 struct abbrev_info
*abbrev
= abbrevs
[i
];
1040 free (abbrev
->attrs
);
1041 abbrev
= abbrev
->next
;
1046 cur_abbrev
->attrs
= tmp
;
1049 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
].name
1050 = (enum dwarf_attribute
) abbrev_name
;
1051 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
].form
1052 = (enum dwarf_form
) abbrev_form
;
1053 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
].implicit_const
1055 ++cur_abbrev
->num_attrs
;
1058 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
1059 cur_abbrev
->next
= abbrevs
[hash_number
];
1060 abbrevs
[hash_number
] = cur_abbrev
;
1062 /* Get next abbreviation.
1063 Under Irix6 the abbreviations for a compilation unit are not
1064 always properly terminated with an abbrev number of 0.
1065 Exit loop if we encounter an abbreviation which we have
1066 already read (which means we are about to read the abbreviations
1067 for the next compile unit) or if the end of the abbreviation
1068 table is reached. */
1069 if ((unsigned int) (abbrev_ptr
- stash
->dwarf_abbrev_buffer
)
1070 >= stash
->dwarf_abbrev_size
)
1072 abbrev_number
= _bfd_safe_read_leb128 (abfd
, abbrev_ptr
,
1073 &bytes_read
, FALSE
, abbrev_end
);
1074 abbrev_ptr
+= bytes_read
;
1075 if (lookup_abbrev (abbrev_number
, abbrevs
) != NULL
)
1082 /* Returns true if the form is one which has a string value. */
1084 static inline bfd_boolean
1085 is_str_attr (enum dwarf_form form
)
1087 return (form
== DW_FORM_string
|| form
== DW_FORM_strp
1088 || form
== DW_FORM_line_strp
|| form
== DW_FORM_GNU_strp_alt
);
1091 /* Read and fill in the value of attribute ATTR as described by FORM.
1092 Read data starting from INFO_PTR, but never at or beyond INFO_PTR_END.
1093 Returns an updated INFO_PTR taking into account the amount of data read. */
1096 read_attribute_value (struct attribute
* attr
,
1098 bfd_vma implicit_const
,
1099 struct comp_unit
* unit
,
1100 bfd_byte
* info_ptr
,
1101 bfd_byte
* info_ptr_end
)
1103 bfd
*abfd
= unit
->abfd
;
1104 unsigned int bytes_read
;
1105 struct dwarf_block
*blk
;
1108 if (info_ptr
>= info_ptr_end
&& form
!= DW_FORM_flag_present
)
1110 _bfd_error_handler (_("DWARF error: info pointer extends beyond end of attributes"));
1111 bfd_set_error (bfd_error_bad_value
);
1115 attr
->form
= (enum dwarf_form
) form
;
1119 case DW_FORM_ref_addr
:
1120 /* DW_FORM_ref_addr is an address in DWARF2, and an offset in
1122 if (unit
->version
== 3 || unit
->version
== 4)
1124 if (unit
->offset_size
== 4)
1125 attr
->u
.val
= read_4_bytes (unit
->abfd
, info_ptr
, info_ptr_end
);
1127 attr
->u
.val
= read_8_bytes (unit
->abfd
, info_ptr
, info_ptr_end
);
1128 info_ptr
+= unit
->offset_size
;
1133 attr
->u
.val
= read_address (unit
, info_ptr
, info_ptr_end
);
1134 info_ptr
+= unit
->addr_size
;
1136 case DW_FORM_GNU_ref_alt
:
1137 case DW_FORM_sec_offset
:
1138 if (unit
->offset_size
== 4)
1139 attr
->u
.val
= read_4_bytes (unit
->abfd
, info_ptr
, info_ptr_end
);
1141 attr
->u
.val
= read_8_bytes (unit
->abfd
, info_ptr
, info_ptr_end
);
1142 info_ptr
+= unit
->offset_size
;
1144 case DW_FORM_block2
:
1145 amt
= sizeof (struct dwarf_block
);
1146 blk
= (struct dwarf_block
*) bfd_alloc (abfd
, amt
);
1149 blk
->size
= read_2_bytes (abfd
, info_ptr
, info_ptr_end
);
1151 info_ptr
= read_n_bytes (info_ptr
, info_ptr_end
, blk
);
1154 case DW_FORM_block4
:
1155 amt
= sizeof (struct dwarf_block
);
1156 blk
= (struct dwarf_block
*) bfd_alloc (abfd
, amt
);
1159 blk
->size
= read_4_bytes (abfd
, info_ptr
, info_ptr_end
);
1161 info_ptr
= read_n_bytes (info_ptr
, info_ptr_end
, blk
);
1165 attr
->u
.val
= read_2_bytes (abfd
, info_ptr
, info_ptr_end
);
1169 attr
->u
.val
= read_4_bytes (abfd
, info_ptr
, info_ptr_end
);
1173 attr
->u
.val
= read_8_bytes (abfd
, info_ptr
, info_ptr_end
);
1176 case DW_FORM_string
:
1177 attr
->u
.str
= read_string (abfd
, info_ptr
, info_ptr_end
, &bytes_read
);
1178 info_ptr
+= bytes_read
;
1181 attr
->u
.str
= read_indirect_string (unit
, info_ptr
, info_ptr_end
, &bytes_read
);
1182 info_ptr
+= bytes_read
;
1184 case DW_FORM_line_strp
:
1185 attr
->u
.str
= read_indirect_line_string (unit
, info_ptr
, info_ptr_end
, &bytes_read
);
1186 info_ptr
+= bytes_read
;
1188 case DW_FORM_GNU_strp_alt
:
1189 attr
->u
.str
= read_alt_indirect_string (unit
, info_ptr
, info_ptr_end
, &bytes_read
);
1190 info_ptr
+= bytes_read
;
1192 case DW_FORM_exprloc
:
1194 amt
= sizeof (struct dwarf_block
);
1195 blk
= (struct dwarf_block
*) bfd_alloc (abfd
, amt
);
1198 blk
->size
= _bfd_safe_read_leb128 (abfd
, info_ptr
, &bytes_read
,
1199 FALSE
, info_ptr_end
);
1200 info_ptr
+= bytes_read
;
1201 info_ptr
= read_n_bytes (info_ptr
, info_ptr_end
, blk
);
1204 case DW_FORM_block1
:
1205 amt
= sizeof (struct dwarf_block
);
1206 blk
= (struct dwarf_block
*) bfd_alloc (abfd
, amt
);
1209 blk
->size
= read_1_byte (abfd
, info_ptr
, info_ptr_end
);
1211 info_ptr
= read_n_bytes (info_ptr
, info_ptr_end
, blk
);
1215 attr
->u
.val
= read_1_byte (abfd
, info_ptr
, info_ptr_end
);
1219 attr
->u
.val
= read_1_byte (abfd
, info_ptr
, info_ptr_end
);
1222 case DW_FORM_flag_present
:
1226 attr
->u
.sval
= _bfd_safe_read_leb128 (abfd
, info_ptr
, &bytes_read
,
1227 TRUE
, info_ptr_end
);
1228 info_ptr
+= bytes_read
;
1231 attr
->u
.val
= _bfd_safe_read_leb128 (abfd
, info_ptr
, &bytes_read
,
1232 FALSE
, info_ptr_end
);
1233 info_ptr
+= bytes_read
;
1236 attr
->u
.val
= read_1_byte (abfd
, info_ptr
, info_ptr_end
);
1240 attr
->u
.val
= read_2_bytes (abfd
, info_ptr
, info_ptr_end
);
1244 attr
->u
.val
= read_4_bytes (abfd
, info_ptr
, info_ptr_end
);
1248 attr
->u
.val
= read_8_bytes (abfd
, info_ptr
, info_ptr_end
);
1251 case DW_FORM_ref_sig8
:
1252 attr
->u
.val
= read_8_bytes (abfd
, info_ptr
, info_ptr_end
);
1255 case DW_FORM_ref_udata
:
1256 attr
->u
.val
= _bfd_safe_read_leb128 (abfd
, info_ptr
, &bytes_read
,
1257 FALSE
, info_ptr_end
);
1258 info_ptr
+= bytes_read
;
1260 case DW_FORM_indirect
:
1261 form
= _bfd_safe_read_leb128 (abfd
, info_ptr
, &bytes_read
,
1262 FALSE
, info_ptr_end
);
1263 info_ptr
+= bytes_read
;
1264 if (form
== DW_FORM_implicit_const
)
1266 implicit_const
= _bfd_safe_read_leb128 (abfd
, info_ptr
, &bytes_read
,
1267 TRUE
, info_ptr_end
);
1268 info_ptr
+= bytes_read
;
1270 info_ptr
= read_attribute_value (attr
, form
, implicit_const
, unit
,
1271 info_ptr
, info_ptr_end
);
1273 case DW_FORM_implicit_const
:
1274 attr
->form
= DW_FORM_sdata
;
1275 attr
->u
.sval
= implicit_const
;
1278 _bfd_error_handler (_("DWARF error: invalid or unhandled FORM value: %#x"),
1280 bfd_set_error (bfd_error_bad_value
);
1286 /* Read an attribute described by an abbreviated attribute. */
1289 read_attribute (struct attribute
* attr
,
1290 struct attr_abbrev
* abbrev
,
1291 struct comp_unit
* unit
,
1292 bfd_byte
* info_ptr
,
1293 bfd_byte
* info_ptr_end
)
1295 attr
->name
= abbrev
->name
;
1296 info_ptr
= read_attribute_value (attr
, abbrev
->form
, abbrev
->implicit_const
,
1297 unit
, info_ptr
, info_ptr_end
);
1301 /* Return whether DW_AT_name will return the same as DW_AT_linkage_name
1305 non_mangled (int lang
)
1315 case DW_LANG_Cobol74
:
1316 case DW_LANG_Cobol85
:
1317 case DW_LANG_Fortran77
:
1318 case DW_LANG_Pascal83
:
1328 /* Source line information table routines. */
1330 #define FILE_ALLOC_CHUNK 5
1331 #define DIR_ALLOC_CHUNK 5
1335 struct line_info
* prev_line
;
1339 unsigned int column
;
1340 unsigned int discriminator
;
1341 unsigned char op_index
;
1342 unsigned char end_sequence
; /* End of (sequential) code sequence. */
1353 struct line_sequence
1356 struct line_sequence
* prev_sequence
;
1357 struct line_info
* last_line
; /* Largest VMA. */
1358 struct line_info
** line_info_lookup
;
1359 bfd_size_type num_lines
;
1362 struct line_info_table
1365 unsigned int num_files
;
1366 unsigned int num_dirs
;
1367 unsigned int num_sequences
;
1370 struct fileinfo
* files
;
1371 struct line_sequence
* sequences
;
1372 struct line_info
* lcl_head
; /* Local head; used in 'add_line_info'. */
1375 /* Remember some information about each function. If the function is
1376 inlined (DW_TAG_inlined_subroutine) it may have two additional
1377 attributes, DW_AT_call_file and DW_AT_call_line, which specify the
1378 source code location where this function was inlined. */
1382 /* Pointer to previous function in list of all functions. */
1383 struct funcinfo
* prev_func
;
1384 /* Pointer to function one scope higher. */
1385 struct funcinfo
* caller_func
;
1386 /* Source location file name where caller_func inlines this func. */
1388 /* Source location file name. */
1390 /* Source location line number where caller_func inlines this func. */
1392 /* Source location line number. */
1395 bfd_boolean is_linkage
;
1397 struct arange arange
;
1398 /* Where the symbol is defined. */
1402 struct lookup_funcinfo
1404 /* Function information corresponding to this lookup table entry. */
1405 struct funcinfo
* funcinfo
;
1407 /* The lowest address for this specific function. */
1410 /* The highest address of this function before the lookup table is sorted.
1411 The highest address of all prior functions after the lookup table is
1412 sorted, which is used for binary search. */
1418 /* Pointer to previous variable in list of all variables */
1419 struct varinfo
*prev_var
;
1420 /* Source location file name */
1422 /* Source location line number */
1427 /* Where the symbol is defined */
1429 /* Is this a stack variable? */
1430 unsigned int stack
: 1;
1433 /* Return TRUE if NEW_LINE should sort after LINE. */
1435 static inline bfd_boolean
1436 new_line_sorts_after (struct line_info
*new_line
, struct line_info
*line
)
1438 return (new_line
->address
> line
->address
1439 || (new_line
->address
== line
->address
1440 && new_line
->op_index
> line
->op_index
));
1444 /* Adds a new entry to the line_info list in the line_info_table, ensuring
1445 that the list is sorted. Note that the line_info list is sorted from
1446 highest to lowest VMA (with possible duplicates); that is,
1447 line_info->prev_line always accesses an equal or smaller VMA. */
1450 add_line_info (struct line_info_table
*table
,
1452 unsigned char op_index
,
1455 unsigned int column
,
1456 unsigned int discriminator
,
1459 bfd_size_type amt
= sizeof (struct line_info
);
1460 struct line_sequence
* seq
= table
->sequences
;
1461 struct line_info
* info
= (struct line_info
*) bfd_alloc (table
->abfd
, amt
);
1466 /* Set member data of 'info'. */
1467 info
->prev_line
= NULL
;
1468 info
->address
= address
;
1469 info
->op_index
= op_index
;
1471 info
->column
= column
;
1472 info
->discriminator
= discriminator
;
1473 info
->end_sequence
= end_sequence
;
1475 if (filename
&& filename
[0])
1477 info
->filename
= (char *) bfd_alloc (table
->abfd
, strlen (filename
) + 1);
1478 if (info
->filename
== NULL
)
1480 strcpy (info
->filename
, filename
);
1483 info
->filename
= NULL
;
1485 /* Find the correct location for 'info'. Normally we will receive
1486 new line_info data 1) in order and 2) with increasing VMAs.
1487 However some compilers break the rules (cf. decode_line_info) and
1488 so we include some heuristics for quickly finding the correct
1489 location for 'info'. In particular, these heuristics optimize for
1490 the common case in which the VMA sequence that we receive is a
1491 list of locally sorted VMAs such as
1492 p...z a...j (where a < j < p < z)
1494 Note: table->lcl_head is used to head an *actual* or *possible*
1495 sub-sequence within the list (such as a...j) that is not directly
1496 headed by table->last_line
1498 Note: we may receive duplicate entries from 'decode_line_info'. */
1501 && seq
->last_line
->address
== address
1502 && seq
->last_line
->op_index
== op_index
1503 && seq
->last_line
->end_sequence
== end_sequence
)
1505 /* We only keep the last entry with the same address and end
1506 sequence. See PR ld/4986. */
1507 if (table
->lcl_head
== seq
->last_line
)
1508 table
->lcl_head
= info
;
1509 info
->prev_line
= seq
->last_line
->prev_line
;
1510 seq
->last_line
= info
;
1512 else if (!seq
|| seq
->last_line
->end_sequence
)
1514 /* Start a new line sequence. */
1515 amt
= sizeof (struct line_sequence
);
1516 seq
= (struct line_sequence
*) bfd_malloc (amt
);
1519 seq
->low_pc
= address
;
1520 seq
->prev_sequence
= table
->sequences
;
1521 seq
->last_line
= info
;
1522 table
->lcl_head
= info
;
1523 table
->sequences
= seq
;
1524 table
->num_sequences
++;
1526 else if (info
->end_sequence
1527 || new_line_sorts_after (info
, seq
->last_line
))
1529 /* Normal case: add 'info' to the beginning of the current sequence. */
1530 info
->prev_line
= seq
->last_line
;
1531 seq
->last_line
= info
;
1533 /* lcl_head: initialize to head a *possible* sequence at the end. */
1534 if (!table
->lcl_head
)
1535 table
->lcl_head
= info
;
1537 else if (!new_line_sorts_after (info
, table
->lcl_head
)
1538 && (!table
->lcl_head
->prev_line
1539 || new_line_sorts_after (info
, table
->lcl_head
->prev_line
)))
1541 /* Abnormal but easy: lcl_head is the head of 'info'. */
1542 info
->prev_line
= table
->lcl_head
->prev_line
;
1543 table
->lcl_head
->prev_line
= info
;
1547 /* Abnormal and hard: Neither 'last_line' nor 'lcl_head'
1548 are valid heads for 'info'. Reset 'lcl_head'. */
1549 struct line_info
* li2
= seq
->last_line
; /* Always non-NULL. */
1550 struct line_info
* li1
= li2
->prev_line
;
1554 if (!new_line_sorts_after (info
, li2
)
1555 && new_line_sorts_after (info
, li1
))
1558 li2
= li1
; /* always non-NULL */
1559 li1
= li1
->prev_line
;
1561 table
->lcl_head
= li2
;
1562 info
->prev_line
= table
->lcl_head
->prev_line
;
1563 table
->lcl_head
->prev_line
= info
;
1564 if (address
< seq
->low_pc
)
1565 seq
->low_pc
= address
;
1570 /* Extract a fully qualified filename from a line info table.
1571 The returned string has been malloc'ed and it is the caller's
1572 responsibility to free it. */
1575 concat_filename (struct line_info_table
*table
, unsigned int file
)
1579 if (table
== NULL
|| file
- 1 >= table
->num_files
)
1581 /* FILE == 0 means unknown. */
1584 (_("DWARF error: mangled line number section (bad file number)"));
1585 return strdup ("<unknown>");
1588 filename
= table
->files
[file
- 1].name
;
1589 if (filename
== NULL
)
1590 return strdup ("<unknown>");
1592 if (!IS_ABSOLUTE_PATH (filename
))
1594 char *dir_name
= NULL
;
1595 char *subdir_name
= NULL
;
1599 if (table
->files
[file
- 1].dir
1600 /* PR 17512: file: 0317e960. */
1601 && table
->files
[file
- 1].dir
<= table
->num_dirs
1602 /* PR 17512: file: 7f3d2e4b. */
1603 && table
->dirs
!= NULL
)
1604 subdir_name
= table
->dirs
[table
->files
[file
- 1].dir
- 1];
1606 if (!subdir_name
|| !IS_ABSOLUTE_PATH (subdir_name
))
1607 dir_name
= table
->comp_dir
;
1611 dir_name
= subdir_name
;
1616 return strdup (filename
);
1618 len
= strlen (dir_name
) + strlen (filename
) + 2;
1622 len
+= strlen (subdir_name
) + 1;
1623 name
= (char *) bfd_malloc (len
);
1625 sprintf (name
, "%s/%s/%s", dir_name
, subdir_name
, filename
);
1629 name
= (char *) bfd_malloc (len
);
1631 sprintf (name
, "%s/%s", dir_name
, filename
);
1637 return strdup (filename
);
1641 arange_add (const struct comp_unit
*unit
, struct arange
*first_arange
,
1642 bfd_vma low_pc
, bfd_vma high_pc
)
1644 struct arange
*arange
;
1646 /* Ignore empty ranges. */
1647 if (low_pc
== high_pc
)
1650 /* If the first arange is empty, use it. */
1651 if (first_arange
->high
== 0)
1653 first_arange
->low
= low_pc
;
1654 first_arange
->high
= high_pc
;
1658 /* Next see if we can cheaply extend an existing range. */
1659 arange
= first_arange
;
1662 if (low_pc
== arange
->high
)
1664 arange
->high
= high_pc
;
1667 if (high_pc
== arange
->low
)
1669 arange
->low
= low_pc
;
1672 arange
= arange
->next
;
1676 /* Need to allocate a new arange and insert it into the arange list.
1677 Order isn't significant, so just insert after the first arange. */
1678 arange
= (struct arange
*) bfd_alloc (unit
->abfd
, sizeof (*arange
));
1681 arange
->low
= low_pc
;
1682 arange
->high
= high_pc
;
1683 arange
->next
= first_arange
->next
;
1684 first_arange
->next
= arange
;
1688 /* Compare function for line sequences. */
1691 compare_sequences (const void* a
, const void* b
)
1693 const struct line_sequence
* seq1
= a
;
1694 const struct line_sequence
* seq2
= b
;
1696 /* Sort by low_pc as the primary key. */
1697 if (seq1
->low_pc
< seq2
->low_pc
)
1699 if (seq1
->low_pc
> seq2
->low_pc
)
1702 /* If low_pc values are equal, sort in reverse order of
1703 high_pc, so that the largest region comes first. */
1704 if (seq1
->last_line
->address
< seq2
->last_line
->address
)
1706 if (seq1
->last_line
->address
> seq2
->last_line
->address
)
1709 if (seq1
->last_line
->op_index
< seq2
->last_line
->op_index
)
1711 if (seq1
->last_line
->op_index
> seq2
->last_line
->op_index
)
1717 /* Construct the line information table for quick lookup. */
1720 build_line_info_table (struct line_info_table
* table
,
1721 struct line_sequence
* seq
)
1724 struct line_info
** line_info_lookup
;
1725 struct line_info
* each_line
;
1726 unsigned int num_lines
;
1727 unsigned int line_index
;
1729 if (seq
->line_info_lookup
!= NULL
)
1732 /* Count the number of line information entries. We could do this while
1733 scanning the debug information, but some entries may be added via
1734 lcl_head without having a sequence handy to increment the number of
1737 for (each_line
= seq
->last_line
; each_line
; each_line
= each_line
->prev_line
)
1743 /* Allocate space for the line information lookup table. */
1744 amt
= sizeof (struct line_info
*) * num_lines
;
1745 line_info_lookup
= (struct line_info
**) bfd_alloc (table
->abfd
, amt
);
1746 if (line_info_lookup
== NULL
)
1749 /* Create the line information lookup table. */
1750 line_index
= num_lines
;
1751 for (each_line
= seq
->last_line
; each_line
; each_line
= each_line
->prev_line
)
1752 line_info_lookup
[--line_index
] = each_line
;
1754 BFD_ASSERT (line_index
== 0);
1756 seq
->num_lines
= num_lines
;
1757 seq
->line_info_lookup
= line_info_lookup
;
1762 /* Sort the line sequences for quick lookup. */
1765 sort_line_sequences (struct line_info_table
* table
)
1768 struct line_sequence
* sequences
;
1769 struct line_sequence
* seq
;
1771 unsigned int num_sequences
= table
->num_sequences
;
1772 bfd_vma last_high_pc
;
1774 if (num_sequences
== 0)
1777 /* Allocate space for an array of sequences. */
1778 amt
= sizeof (struct line_sequence
) * num_sequences
;
1779 sequences
= (struct line_sequence
*) bfd_alloc (table
->abfd
, amt
);
1780 if (sequences
== NULL
)
1783 /* Copy the linked list into the array, freeing the original nodes. */
1784 seq
= table
->sequences
;
1785 for (n
= 0; n
< num_sequences
; n
++)
1787 struct line_sequence
* last_seq
= seq
;
1790 sequences
[n
].low_pc
= seq
->low_pc
;
1791 sequences
[n
].prev_sequence
= NULL
;
1792 sequences
[n
].last_line
= seq
->last_line
;
1793 sequences
[n
].line_info_lookup
= NULL
;
1794 sequences
[n
].num_lines
= 0;
1795 seq
= seq
->prev_sequence
;
1798 BFD_ASSERT (seq
== NULL
);
1800 qsort (sequences
, n
, sizeof (struct line_sequence
), compare_sequences
);
1802 /* Make the list binary-searchable by trimming overlapping entries
1803 and removing nested entries. */
1805 last_high_pc
= sequences
[0].last_line
->address
;
1806 for (n
= 1; n
< table
->num_sequences
; n
++)
1808 if (sequences
[n
].low_pc
< last_high_pc
)
1810 if (sequences
[n
].last_line
->address
<= last_high_pc
)
1811 /* Skip nested entries. */
1814 /* Trim overlapping entries. */
1815 sequences
[n
].low_pc
= last_high_pc
;
1817 last_high_pc
= sequences
[n
].last_line
->address
;
1818 if (n
> num_sequences
)
1820 /* Close up the gap. */
1821 sequences
[num_sequences
].low_pc
= sequences
[n
].low_pc
;
1822 sequences
[num_sequences
].last_line
= sequences
[n
].last_line
;
1827 table
->sequences
= sequences
;
1828 table
->num_sequences
= num_sequences
;
1832 /* Add directory to TABLE. CUR_DIR memory ownership is taken by TABLE. */
1835 line_info_add_include_dir (struct line_info_table
*table
, char *cur_dir
)
1837 if ((table
->num_dirs
% DIR_ALLOC_CHUNK
) == 0)
1842 amt
= table
->num_dirs
+ DIR_ALLOC_CHUNK
;
1843 amt
*= sizeof (char *);
1845 tmp
= (char **) bfd_realloc (table
->dirs
, amt
);
1851 table
->dirs
[table
->num_dirs
++] = cur_dir
;
1856 line_info_add_include_dir_stub (struct line_info_table
*table
, char *cur_dir
,
1857 unsigned int dir ATTRIBUTE_UNUSED
,
1858 unsigned int xtime ATTRIBUTE_UNUSED
,
1859 unsigned int size ATTRIBUTE_UNUSED
)
1861 return line_info_add_include_dir (table
, cur_dir
);
1864 /* Add file to TABLE. CUR_FILE memory ownership is taken by TABLE. */
1867 line_info_add_file_name (struct line_info_table
*table
, char *cur_file
,
1868 unsigned int dir
, unsigned int xtime
,
1871 if ((table
->num_files
% FILE_ALLOC_CHUNK
) == 0)
1873 struct fileinfo
*tmp
;
1876 amt
= table
->num_files
+ FILE_ALLOC_CHUNK
;
1877 amt
*= sizeof (struct fileinfo
);
1879 tmp
= (struct fileinfo
*) bfd_realloc (table
->files
, amt
);
1885 table
->files
[table
->num_files
].name
= cur_file
;
1886 table
->files
[table
->num_files
].dir
= dir
;
1887 table
->files
[table
->num_files
].time
= xtime
;
1888 table
->files
[table
->num_files
].size
= size
;
1893 /* Read directory or file name entry format, starting with byte of
1894 format count entries, ULEB128 pairs of entry formats, ULEB128 of
1895 entries count and the entries themselves in the described entry
1899 read_formatted_entries (struct comp_unit
*unit
, bfd_byte
**bufp
,
1900 bfd_byte
*buf_end
, struct line_info_table
*table
,
1901 bfd_boolean (*callback
) (struct line_info_table
*table
,
1907 bfd
*abfd
= unit
->abfd
;
1908 bfd_byte format_count
, formati
;
1909 bfd_vma data_count
, datai
;
1910 bfd_byte
*buf
= *bufp
;
1911 bfd_byte
*format_header_data
;
1912 unsigned int bytes_read
;
1914 format_count
= read_1_byte (abfd
, buf
, buf_end
);
1916 format_header_data
= buf
;
1917 for (formati
= 0; formati
< format_count
; formati
++)
1919 _bfd_safe_read_leb128 (abfd
, buf
, &bytes_read
, FALSE
, buf_end
);
1921 _bfd_safe_read_leb128 (abfd
, buf
, &bytes_read
, FALSE
, buf_end
);
1925 data_count
= _bfd_safe_read_leb128 (abfd
, buf
, &bytes_read
, FALSE
, buf_end
);
1927 if (format_count
== 0 && data_count
!= 0)
1929 _bfd_error_handler (_("DWARF error: zero format count"));
1930 bfd_set_error (bfd_error_bad_value
);
1934 /* PR 22210. Paranoia check. Don't bother running the loop
1935 if we know that we are going to run out of buffer. */
1936 if (data_count
> (bfd_vma
) (buf_end
- buf
))
1939 (_("DWARF error: data count (%" PRIx64
") larger than buffer size"),
1940 (uint64_t) data_count
);
1941 bfd_set_error (bfd_error_bad_value
);
1945 for (datai
= 0; datai
< data_count
; datai
++)
1947 bfd_byte
*format
= format_header_data
;
1950 memset (&fe
, 0, sizeof fe
);
1951 for (formati
= 0; formati
< format_count
; formati
++)
1953 bfd_vma content_type
, form
;
1955 char **stringp
= &string_trash
;
1956 unsigned int uint_trash
, *uintp
= &uint_trash
;
1957 struct attribute attr
;
1959 content_type
= _bfd_safe_read_leb128 (abfd
, format
, &bytes_read
,
1961 format
+= bytes_read
;
1962 switch (content_type
)
1967 case DW_LNCT_directory_index
:
1970 case DW_LNCT_timestamp
:
1980 (_("DWARF error: unknown format content type %" PRIu64
),
1981 (uint64_t) content_type
);
1982 bfd_set_error (bfd_error_bad_value
);
1986 form
= _bfd_safe_read_leb128 (abfd
, format
, &bytes_read
, FALSE
,
1988 format
+= bytes_read
;
1990 buf
= read_attribute_value (&attr
, form
, 0, unit
, buf
, buf_end
);
1995 case DW_FORM_string
:
1996 case DW_FORM_line_strp
:
1997 *stringp
= attr
.u
.str
;
2005 *uintp
= attr
.u
.val
;
2010 if (!callback (table
, fe
.name
, fe
.dir
, fe
.time
, fe
.size
))
2018 /* Decode the line number information for UNIT. */
2020 static struct line_info_table
*
2021 decode_line_info (struct comp_unit
*unit
, struct dwarf2_debug
*stash
)
2023 bfd
*abfd
= unit
->abfd
;
2024 struct line_info_table
* table
;
2027 struct line_head lh
;
2028 unsigned int i
, bytes_read
, offset_size
;
2029 char *cur_file
, *cur_dir
;
2030 unsigned char op_code
, extended_op
, adj_opcode
;
2031 unsigned int exop_len
;
2034 if (! read_section (abfd
, &stash
->debug_sections
[debug_line
],
2035 stash
->syms
, unit
->line_offset
,
2036 &stash
->dwarf_line_buffer
, &stash
->dwarf_line_size
))
2039 amt
= sizeof (struct line_info_table
);
2040 table
= (struct line_info_table
*) bfd_alloc (abfd
, amt
);
2044 table
->comp_dir
= unit
->comp_dir
;
2046 table
->num_files
= 0;
2047 table
->files
= NULL
;
2049 table
->num_dirs
= 0;
2052 table
->num_sequences
= 0;
2053 table
->sequences
= NULL
;
2055 table
->lcl_head
= NULL
;
2057 if (stash
->dwarf_line_size
< 16)
2060 (_("DWARF error: line info section is too small (%" PRId64
")"),
2061 (int64_t) stash
->dwarf_line_size
);
2062 bfd_set_error (bfd_error_bad_value
);
2065 line_ptr
= stash
->dwarf_line_buffer
+ unit
->line_offset
;
2066 line_end
= stash
->dwarf_line_buffer
+ stash
->dwarf_line_size
;
2068 /* Read in the prologue. */
2069 lh
.total_length
= read_4_bytes (abfd
, line_ptr
, line_end
);
2072 if (lh
.total_length
== 0xffffffff)
2074 lh
.total_length
= read_8_bytes (abfd
, line_ptr
, line_end
);
2078 else if (lh
.total_length
== 0 && unit
->addr_size
== 8)
2080 /* Handle (non-standard) 64-bit DWARF2 formats. */
2081 lh
.total_length
= read_4_bytes (abfd
, line_ptr
, line_end
);
2086 if (lh
.total_length
> (size_t) (line_end
- line_ptr
))
2089 /* xgettext: c-format */
2090 (_("DWARF error: line info data is bigger (%#" PRIx64
")"
2091 " than the space remaining in the section (%#lx)"),
2092 (uint64_t) lh
.total_length
, (unsigned long) (line_end
- line_ptr
));
2093 bfd_set_error (bfd_error_bad_value
);
2097 line_end
= line_ptr
+ lh
.total_length
;
2099 lh
.version
= read_2_bytes (abfd
, line_ptr
, line_end
);
2100 if (lh
.version
< 2 || lh
.version
> 5)
2103 (_("DWARF error: unhandled .debug_line version %d"), lh
.version
);
2104 bfd_set_error (bfd_error_bad_value
);
2109 if (line_ptr
+ offset_size
+ (lh
.version
>= 5 ? 8 : (lh
.version
>= 4 ? 6 : 5))
2113 (_("DWARF error: ran out of room reading prologue"));
2114 bfd_set_error (bfd_error_bad_value
);
2118 if (lh
.version
>= 5)
2120 unsigned int segment_selector_size
;
2122 /* Skip address size. */
2123 read_1_byte (abfd
, line_ptr
, line_end
);
2126 segment_selector_size
= read_1_byte (abfd
, line_ptr
, line_end
);
2128 if (segment_selector_size
!= 0)
2131 (_("DWARF error: line info unsupported segment selector size %u"),
2132 segment_selector_size
);
2133 bfd_set_error (bfd_error_bad_value
);
2138 if (offset_size
== 4)
2139 lh
.prologue_length
= read_4_bytes (abfd
, line_ptr
, line_end
);
2141 lh
.prologue_length
= read_8_bytes (abfd
, line_ptr
, line_end
);
2142 line_ptr
+= offset_size
;
2144 lh
.minimum_instruction_length
= read_1_byte (abfd
, line_ptr
, line_end
);
2147 if (lh
.version
>= 4)
2149 lh
.maximum_ops_per_insn
= read_1_byte (abfd
, line_ptr
, line_end
);
2153 lh
.maximum_ops_per_insn
= 1;
2155 if (lh
.maximum_ops_per_insn
== 0)
2158 (_("DWARF error: invalid maximum operations per instruction"));
2159 bfd_set_error (bfd_error_bad_value
);
2163 lh
.default_is_stmt
= read_1_byte (abfd
, line_ptr
, line_end
);
2166 lh
.line_base
= read_1_signed_byte (abfd
, line_ptr
, line_end
);
2169 lh
.line_range
= read_1_byte (abfd
, line_ptr
, line_end
);
2172 lh
.opcode_base
= read_1_byte (abfd
, line_ptr
, line_end
);
2175 if (line_ptr
+ (lh
.opcode_base
- 1) >= line_end
)
2177 _bfd_error_handler (_("DWARF error: ran out of room reading opcodes"));
2178 bfd_set_error (bfd_error_bad_value
);
2182 amt
= lh
.opcode_base
* sizeof (unsigned char);
2183 lh
.standard_opcode_lengths
= (unsigned char *) bfd_alloc (abfd
, amt
);
2185 lh
.standard_opcode_lengths
[0] = 1;
2187 for (i
= 1; i
< lh
.opcode_base
; ++i
)
2189 lh
.standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
, line_end
);
2193 if (lh
.version
>= 5)
2195 /* Read directory table. */
2196 if (!read_formatted_entries (unit
, &line_ptr
, line_end
, table
,
2197 line_info_add_include_dir_stub
))
2200 /* Read file name table. */
2201 if (!read_formatted_entries (unit
, &line_ptr
, line_end
, table
,
2202 line_info_add_file_name
))
2207 /* Read directory table. */
2208 while ((cur_dir
= read_string (abfd
, line_ptr
, line_end
, &bytes_read
)) != NULL
)
2210 line_ptr
+= bytes_read
;
2212 if (!line_info_add_include_dir (table
, cur_dir
))
2216 line_ptr
+= bytes_read
;
2218 /* Read file name table. */
2219 while ((cur_file
= read_string (abfd
, line_ptr
, line_end
, &bytes_read
)) != NULL
)
2221 unsigned int dir
, xtime
, size
;
2223 line_ptr
+= bytes_read
;
2225 dir
= _bfd_safe_read_leb128 (abfd
, line_ptr
, &bytes_read
, FALSE
, line_end
);
2226 line_ptr
+= bytes_read
;
2227 xtime
= _bfd_safe_read_leb128 (abfd
, line_ptr
, &bytes_read
, FALSE
, line_end
);
2228 line_ptr
+= bytes_read
;
2229 size
= _bfd_safe_read_leb128 (abfd
, line_ptr
, &bytes_read
, FALSE
, line_end
);
2230 line_ptr
+= bytes_read
;
2232 if (!line_info_add_file_name (table
, cur_file
, dir
, xtime
, size
))
2236 line_ptr
+= bytes_read
;
2239 /* Read the statement sequences until there's nothing left. */
2240 while (line_ptr
< line_end
)
2242 /* State machine registers. */
2243 bfd_vma address
= 0;
2244 unsigned char op_index
= 0;
2245 char * filename
= table
->num_files
? concat_filename (table
, 1) : NULL
;
2246 unsigned int line
= 1;
2247 unsigned int column
= 0;
2248 unsigned int discriminator
= 0;
2249 int is_stmt
= lh
.default_is_stmt
;
2250 int end_sequence
= 0;
2251 unsigned int dir
, xtime
, size
;
2252 /* eraxxon@alumni.rice.edu: Against the DWARF2 specs, some
2253 compilers generate address sequences that are wildly out of
2254 order using DW_LNE_set_address (e.g. Intel C++ 6.0 compiler
2255 for ia64-Linux). Thus, to determine the low and high
2256 address, we must compare on every DW_LNS_copy, etc. */
2257 bfd_vma low_pc
= (bfd_vma
) -1;
2258 bfd_vma high_pc
= 0;
2260 /* Decode the table. */
2261 while (!end_sequence
&& line_ptr
< line_end
)
2263 op_code
= read_1_byte (abfd
, line_ptr
, line_end
);
2266 if (op_code
>= lh
.opcode_base
)
2268 /* Special operand. */
2269 adj_opcode
= op_code
- lh
.opcode_base
;
2270 if (lh
.line_range
== 0)
2272 if (lh
.maximum_ops_per_insn
== 1)
2273 address
+= (adj_opcode
/ lh
.line_range
2274 * lh
.minimum_instruction_length
);
2277 address
+= ((op_index
+ adj_opcode
/ lh
.line_range
)
2278 / lh
.maximum_ops_per_insn
2279 * lh
.minimum_instruction_length
);
2280 op_index
= ((op_index
+ adj_opcode
/ lh
.line_range
)
2281 % lh
.maximum_ops_per_insn
);
2283 line
+= lh
.line_base
+ (adj_opcode
% lh
.line_range
);
2284 /* Append row to matrix using current values. */
2285 if (!add_line_info (table
, address
, op_index
, filename
,
2286 line
, column
, discriminator
, 0))
2289 if (address
< low_pc
)
2291 if (address
> high_pc
)
2294 else switch (op_code
)
2296 case DW_LNS_extended_op
:
2297 exop_len
= _bfd_safe_read_leb128 (abfd
, line_ptr
, &bytes_read
,
2299 line_ptr
+= bytes_read
;
2300 extended_op
= read_1_byte (abfd
, line_ptr
, line_end
);
2303 switch (extended_op
)
2305 case DW_LNE_end_sequence
:
2307 if (!add_line_info (table
, address
, op_index
, filename
, line
,
2308 column
, discriminator
, end_sequence
))
2311 if (address
< low_pc
)
2313 if (address
> high_pc
)
2315 if (!arange_add (unit
, &unit
->arange
, low_pc
, high_pc
))
2318 case DW_LNE_set_address
:
2319 address
= read_address (unit
, line_ptr
, line_end
);
2321 line_ptr
+= unit
->addr_size
;
2323 case DW_LNE_define_file
:
2324 cur_file
= read_string (abfd
, line_ptr
, line_end
, &bytes_read
);
2325 line_ptr
+= bytes_read
;
2326 dir
= _bfd_safe_read_leb128 (abfd
, line_ptr
, &bytes_read
,
2328 line_ptr
+= bytes_read
;
2329 xtime
= _bfd_safe_read_leb128 (abfd
, line_ptr
, &bytes_read
,
2331 line_ptr
+= bytes_read
;
2332 size
= _bfd_safe_read_leb128 (abfd
, line_ptr
, &bytes_read
,
2334 line_ptr
+= bytes_read
;
2335 if (!line_info_add_file_name (table
, cur_file
, dir
,
2339 case DW_LNE_set_discriminator
:
2341 _bfd_safe_read_leb128 (abfd
, line_ptr
, &bytes_read
,
2343 line_ptr
+= bytes_read
;
2345 case DW_LNE_HP_source_file_correlation
:
2346 line_ptr
+= exop_len
- 1;
2350 (_("DWARF error: mangled line number section"));
2351 bfd_set_error (bfd_error_bad_value
);
2353 if (filename
!= NULL
)
2359 if (!add_line_info (table
, address
, op_index
,
2360 filename
, line
, column
, discriminator
, 0))
2363 if (address
< low_pc
)
2365 if (address
> high_pc
)
2368 case DW_LNS_advance_pc
:
2369 if (lh
.maximum_ops_per_insn
== 1)
2370 address
+= (lh
.minimum_instruction_length
2371 * _bfd_safe_read_leb128 (abfd
, line_ptr
,
2376 bfd_vma adjust
= _bfd_safe_read_leb128 (abfd
, line_ptr
,
2379 address
= ((op_index
+ adjust
) / lh
.maximum_ops_per_insn
2380 * lh
.minimum_instruction_length
);
2381 op_index
= (op_index
+ adjust
) % lh
.maximum_ops_per_insn
;
2383 line_ptr
+= bytes_read
;
2385 case DW_LNS_advance_line
:
2386 line
+= _bfd_safe_read_leb128 (abfd
, line_ptr
, &bytes_read
,
2388 line_ptr
+= bytes_read
;
2390 case DW_LNS_set_file
:
2394 /* The file and directory tables are 0
2395 based, the references are 1 based. */
2396 file
= _bfd_safe_read_leb128 (abfd
, line_ptr
, &bytes_read
,
2398 line_ptr
+= bytes_read
;
2401 filename
= concat_filename (table
, file
);
2404 case DW_LNS_set_column
:
2405 column
= _bfd_safe_read_leb128 (abfd
, line_ptr
, &bytes_read
,
2407 line_ptr
+= bytes_read
;
2409 case DW_LNS_negate_stmt
:
2410 is_stmt
= (!is_stmt
);
2412 case DW_LNS_set_basic_block
:
2414 case DW_LNS_const_add_pc
:
2415 if (lh
.line_range
== 0)
2417 if (lh
.maximum_ops_per_insn
== 1)
2418 address
+= (lh
.minimum_instruction_length
2419 * ((255 - lh
.opcode_base
) / lh
.line_range
));
2422 bfd_vma adjust
= ((255 - lh
.opcode_base
) / lh
.line_range
);
2423 address
+= (lh
.minimum_instruction_length
2424 * ((op_index
+ adjust
)
2425 / lh
.maximum_ops_per_insn
));
2426 op_index
= (op_index
+ adjust
) % lh
.maximum_ops_per_insn
;
2429 case DW_LNS_fixed_advance_pc
:
2430 address
+= read_2_bytes (abfd
, line_ptr
, line_end
);
2435 /* Unknown standard opcode, ignore it. */
2436 for (i
= 0; i
< lh
.standard_opcode_lengths
[op_code
]; i
++)
2438 (void) _bfd_safe_read_leb128 (abfd
, line_ptr
, &bytes_read
,
2440 line_ptr
+= bytes_read
;
2450 if (sort_line_sequences (table
))
2454 while (table
->sequences
!= NULL
)
2456 struct line_sequence
* seq
= table
->sequences
;
2457 table
->sequences
= table
->sequences
->prev_sequence
;
2460 if (table
->files
!= NULL
)
2461 free (table
->files
);
2462 if (table
->dirs
!= NULL
)
2467 /* If ADDR is within TABLE set the output parameters and return the
2468 range of addresses covered by the entry used to fill them out.
2469 Otherwise set * FILENAME_PTR to NULL and return 0.
2470 The parameters FILENAME_PTR, LINENUMBER_PTR and DISCRIMINATOR_PTR
2471 are pointers to the objects to be filled in. */
2474 lookup_address_in_line_info_table (struct line_info_table
*table
,
2476 const char **filename_ptr
,
2477 unsigned int *linenumber_ptr
,
2478 unsigned int *discriminator_ptr
)
2480 struct line_sequence
*seq
= NULL
;
2481 struct line_info
*info
;
2484 /* Binary search the array of sequences. */
2486 high
= table
->num_sequences
;
2489 mid
= (low
+ high
) / 2;
2490 seq
= &table
->sequences
[mid
];
2491 if (addr
< seq
->low_pc
)
2493 else if (addr
>= seq
->last_line
->address
)
2499 /* Check for a valid sequence. */
2500 if (!seq
|| addr
< seq
->low_pc
|| addr
>= seq
->last_line
->address
)
2503 if (!build_line_info_table (table
, seq
))
2506 /* Binary search the array of line information. */
2508 high
= seq
->num_lines
;
2512 mid
= (low
+ high
) / 2;
2513 info
= seq
->line_info_lookup
[mid
];
2514 if (addr
< info
->address
)
2516 else if (addr
>= seq
->line_info_lookup
[mid
+ 1]->address
)
2522 /* Check for a valid line information entry. */
2524 && addr
>= info
->address
2525 && addr
< seq
->line_info_lookup
[mid
+ 1]->address
2526 && !(info
->end_sequence
|| info
== seq
->last_line
))
2528 *filename_ptr
= info
->filename
;
2529 *linenumber_ptr
= info
->line
;
2530 if (discriminator_ptr
)
2531 *discriminator_ptr
= info
->discriminator
;
2532 return seq
->last_line
->address
- seq
->low_pc
;
2536 *filename_ptr
= NULL
;
2540 /* Read in the .debug_ranges section for future reference. */
2543 read_debug_ranges (struct comp_unit
* unit
)
2545 struct dwarf2_debug
* stash
= unit
->stash
;
2547 return read_section (unit
->abfd
, &stash
->debug_sections
[debug_ranges
],
2549 &stash
->dwarf_ranges_buffer
,
2550 &stash
->dwarf_ranges_size
);
2553 /* Function table functions. */
2556 compare_lookup_funcinfos (const void * a
, const void * b
)
2558 const struct lookup_funcinfo
* lookup1
= a
;
2559 const struct lookup_funcinfo
* lookup2
= b
;
2561 if (lookup1
->low_addr
< lookup2
->low_addr
)
2563 if (lookup1
->low_addr
> lookup2
->low_addr
)
2565 if (lookup1
->high_addr
< lookup2
->high_addr
)
2567 if (lookup1
->high_addr
> lookup2
->high_addr
)
2574 build_lookup_funcinfo_table (struct comp_unit
* unit
)
2576 struct lookup_funcinfo
*lookup_funcinfo_table
= unit
->lookup_funcinfo_table
;
2577 unsigned int number_of_functions
= unit
->number_of_functions
;
2578 struct funcinfo
*each
;
2579 struct lookup_funcinfo
*entry
;
2581 struct arange
*range
;
2582 bfd_vma low_addr
, high_addr
;
2584 if (lookup_funcinfo_table
|| number_of_functions
== 0)
2587 /* Create the function info lookup table. */
2588 lookup_funcinfo_table
= (struct lookup_funcinfo
*)
2589 bfd_malloc (number_of_functions
* sizeof (struct lookup_funcinfo
));
2590 if (lookup_funcinfo_table
== NULL
)
2593 /* Populate the function info lookup table. */
2594 func_index
= number_of_functions
;
2595 for (each
= unit
->function_table
; each
; each
= each
->prev_func
)
2597 entry
= &lookup_funcinfo_table
[--func_index
];
2598 entry
->funcinfo
= each
;
2600 /* Calculate the lowest and highest address for this function entry. */
2601 low_addr
= entry
->funcinfo
->arange
.low
;
2602 high_addr
= entry
->funcinfo
->arange
.high
;
2604 for (range
= entry
->funcinfo
->arange
.next
; range
; range
= range
->next
)
2606 if (range
->low
< low_addr
)
2607 low_addr
= range
->low
;
2608 if (range
->high
> high_addr
)
2609 high_addr
= range
->high
;
2612 entry
->low_addr
= low_addr
;
2613 entry
->high_addr
= high_addr
;
2616 BFD_ASSERT (func_index
== 0);
2618 /* Sort the function by address. */
2619 qsort (lookup_funcinfo_table
,
2620 number_of_functions
,
2621 sizeof (struct lookup_funcinfo
),
2622 compare_lookup_funcinfos
);
2624 /* Calculate the high watermark for each function in the lookup table. */
2625 high_addr
= lookup_funcinfo_table
[0].high_addr
;
2626 for (func_index
= 1; func_index
< number_of_functions
; func_index
++)
2628 entry
= &lookup_funcinfo_table
[func_index
];
2629 if (entry
->high_addr
> high_addr
)
2630 high_addr
= entry
->high_addr
;
2632 entry
->high_addr
= high_addr
;
2635 unit
->lookup_funcinfo_table
= lookup_funcinfo_table
;
2639 /* If ADDR is within UNIT's function tables, set FUNCTION_PTR, and return
2640 TRUE. Note that we need to find the function that has the smallest range
2641 that contains ADDR, to handle inlined functions without depending upon
2642 them being ordered in TABLE by increasing range. */
2645 lookup_address_in_function_table (struct comp_unit
*unit
,
2647 struct funcinfo
**function_ptr
)
2649 unsigned int number_of_functions
= unit
->number_of_functions
;
2650 struct lookup_funcinfo
* lookup_funcinfo
= NULL
;
2651 struct funcinfo
* funcinfo
= NULL
;
2652 struct funcinfo
* best_fit
= NULL
;
2653 bfd_vma best_fit_len
= 0;
2654 bfd_size_type low
, high
, mid
, first
;
2655 struct arange
*arange
;
2657 if (number_of_functions
== 0)
2660 if (!build_lookup_funcinfo_table (unit
))
2663 if (unit
->lookup_funcinfo_table
[number_of_functions
- 1].high_addr
< addr
)
2666 /* Find the first function in the lookup table which may contain the
2667 specified address. */
2669 high
= number_of_functions
;
2673 mid
= (low
+ high
) / 2;
2674 lookup_funcinfo
= &unit
->lookup_funcinfo_table
[mid
];
2675 if (addr
< lookup_funcinfo
->low_addr
)
2677 else if (addr
>= lookup_funcinfo
->high_addr
)
2683 /* Find the 'best' match for the address. The prior algorithm defined the
2684 best match as the function with the smallest address range containing
2685 the specified address. This definition should probably be changed to the
2686 innermost inline routine containing the address, but right now we want
2687 to get the same results we did before. */
2688 while (first
< number_of_functions
)
2690 if (addr
< unit
->lookup_funcinfo_table
[first
].low_addr
)
2692 funcinfo
= unit
->lookup_funcinfo_table
[first
].funcinfo
;
2694 for (arange
= &funcinfo
->arange
; arange
; arange
= arange
->next
)
2696 if (addr
< arange
->low
|| addr
>= arange
->high
)
2700 || arange
->high
- arange
->low
< best_fit_len
2701 /* The following comparison is designed to return the same
2702 match as the previous algorithm for routines which have the
2703 same best fit length. */
2704 || (arange
->high
- arange
->low
== best_fit_len
2705 && funcinfo
> best_fit
))
2707 best_fit
= funcinfo
;
2708 best_fit_len
= arange
->high
- arange
->low
;
2718 *function_ptr
= best_fit
;
2722 /* If SYM at ADDR is within function table of UNIT, set FILENAME_PTR
2723 and LINENUMBER_PTR, and return TRUE. */
2726 lookup_symbol_in_function_table (struct comp_unit
*unit
,
2729 const char **filename_ptr
,
2730 unsigned int *linenumber_ptr
)
2732 struct funcinfo
* each_func
;
2733 struct funcinfo
* best_fit
= NULL
;
2734 bfd_vma best_fit_len
= 0;
2735 struct arange
*arange
;
2736 const char *name
= bfd_asymbol_name (sym
);
2737 asection
*sec
= bfd_get_section (sym
);
2739 for (each_func
= unit
->function_table
;
2741 each_func
= each_func
->prev_func
)
2743 for (arange
= &each_func
->arange
;
2745 arange
= arange
->next
)
2747 if ((!each_func
->sec
|| each_func
->sec
== sec
)
2748 && addr
>= arange
->low
2749 && addr
< arange
->high
2751 && strcmp (name
, each_func
->name
) == 0
2753 || arange
->high
- arange
->low
< best_fit_len
))
2755 best_fit
= each_func
;
2756 best_fit_len
= arange
->high
- arange
->low
;
2763 best_fit
->sec
= sec
;
2764 *filename_ptr
= best_fit
->file
;
2765 *linenumber_ptr
= best_fit
->line
;
2772 /* Variable table functions. */
2774 /* If SYM is within variable table of UNIT, set FILENAME_PTR and
2775 LINENUMBER_PTR, and return TRUE. */
2778 lookup_symbol_in_variable_table (struct comp_unit
*unit
,
2781 const char **filename_ptr
,
2782 unsigned int *linenumber_ptr
)
2784 const char *name
= bfd_asymbol_name (sym
);
2785 asection
*sec
= bfd_get_section (sym
);
2786 struct varinfo
* each
;
2788 for (each
= unit
->variable_table
; each
; each
= each
->prev_var
)
2789 if (each
->stack
== 0
2790 && each
->file
!= NULL
2791 && each
->name
!= NULL
2792 && each
->addr
== addr
2793 && (!each
->sec
|| each
->sec
== sec
)
2794 && strcmp (name
, each
->name
) == 0)
2800 *filename_ptr
= each
->file
;
2801 *linenumber_ptr
= each
->line
;
2808 static struct comp_unit
*stash_comp_unit (struct dwarf2_debug
*);
2809 static bfd_boolean
comp_unit_maybe_decode_line_info (struct comp_unit
*,
2810 struct dwarf2_debug
*);
2813 find_abstract_instance (struct comp_unit
* unit
,
2814 bfd_byte
* orig_info_ptr
,
2815 struct attribute
* attr_ptr
,
2816 const char ** pname
,
2817 bfd_boolean
* is_linkage
,
2818 char ** filename_ptr
,
2819 int * linenumber_ptr
)
2821 bfd
*abfd
= unit
->abfd
;
2823 bfd_byte
*info_ptr_end
;
2824 unsigned int abbrev_number
, bytes_read
, i
;
2825 struct abbrev_info
*abbrev
;
2826 bfd_uint64_t die_ref
= attr_ptr
->u
.val
;
2827 struct attribute attr
;
2828 const char *name
= NULL
;
2830 /* DW_FORM_ref_addr can reference an entry in a different CU. It
2831 is an offset from the .debug_info section, not the current CU. */
2832 if (attr_ptr
->form
== DW_FORM_ref_addr
)
2834 /* We only support DW_FORM_ref_addr within the same file, so
2835 any relocations should be resolved already. Check this by
2836 testing for a zero die_ref; There can't be a valid reference
2837 to the header of a .debug_info section.
2838 DW_FORM_ref_addr is an offset relative to .debug_info.
2839 Normally when using the GNU linker this is accomplished by
2840 emitting a symbolic reference to a label, because .debug_info
2841 sections are linked at zero. When there are multiple section
2842 groups containing .debug_info, as there might be in a
2843 relocatable object file, it would be reasonable to assume that
2844 a symbolic reference to a label in any .debug_info section
2845 might be used. Since we lay out multiple .debug_info
2846 sections at non-zero VMAs (see place_sections), and read
2847 them contiguously into stash->info_ptr_memory, that means
2848 the reference is relative to stash->info_ptr_memory. */
2851 info_ptr
= unit
->stash
->info_ptr_memory
;
2852 info_ptr_end
= unit
->stash
->info_ptr_end
;
2853 total
= info_ptr_end
- info_ptr
;
2856 else if (die_ref
>= total
)
2859 (_("DWARF error: invalid abstract instance DIE ref"));
2860 bfd_set_error (bfd_error_bad_value
);
2863 info_ptr
+= die_ref
;
2865 /* Now find the CU containing this pointer. */
2866 if (info_ptr
>= unit
->info_ptr_unit
&& info_ptr
< unit
->end_ptr
)
2867 info_ptr_end
= unit
->end_ptr
;
2870 /* Check other CUs to see if they contain the abbrev. */
2871 struct comp_unit
* u
;
2873 for (u
= unit
->prev_unit
; u
!= NULL
; u
= u
->prev_unit
)
2874 if (info_ptr
>= u
->info_ptr_unit
&& info_ptr
< u
->end_ptr
)
2878 for (u
= unit
->next_unit
; u
!= NULL
; u
= u
->next_unit
)
2879 if (info_ptr
>= u
->info_ptr_unit
&& info_ptr
< u
->end_ptr
)
2884 u
= stash_comp_unit (unit
->stash
);
2887 if (info_ptr
>= u
->info_ptr_unit
&& info_ptr
< u
->end_ptr
)
2895 (_("DWARF error: unable to locate abstract instance DIE ref %"
2896 PRIu64
), (uint64_t) die_ref
);
2897 bfd_set_error (bfd_error_bad_value
);
2901 info_ptr_end
= unit
->end_ptr
;
2904 else if (attr_ptr
->form
== DW_FORM_GNU_ref_alt
)
2906 info_ptr
= read_alt_indirect_ref (unit
, die_ref
);
2907 if (info_ptr
== NULL
)
2910 (_("DWARF error: unable to read alt ref %" PRIu64
),
2911 (uint64_t) die_ref
);
2912 bfd_set_error (bfd_error_bad_value
);
2915 info_ptr_end
= (unit
->stash
->alt_dwarf_info_buffer
2916 + unit
->stash
->alt_dwarf_info_size
);
2918 /* FIXME: Do we need to locate the correct CU, in a similar
2919 fashion to the code in the DW_FORM_ref_addr case above ? */
2923 /* DW_FORM_ref1, DW_FORM_ref2, DW_FORM_ref4, DW_FORM_ref8 or
2924 DW_FORM_ref_udata. These are all references relative to the
2925 start of the current CU. */
2928 info_ptr
= unit
->info_ptr_unit
;
2929 info_ptr_end
= unit
->end_ptr
;
2930 total
= info_ptr_end
- info_ptr
;
2931 if (!die_ref
|| die_ref
>= total
)
2934 (_("DWARF error: invalid abstract instance DIE ref"));
2935 bfd_set_error (bfd_error_bad_value
);
2938 info_ptr
+= die_ref
;
2941 abbrev_number
= _bfd_safe_read_leb128 (abfd
, info_ptr
, &bytes_read
,
2942 FALSE
, info_ptr_end
);
2943 info_ptr
+= bytes_read
;
2947 abbrev
= lookup_abbrev (abbrev_number
, unit
->abbrevs
);
2951 (_("DWARF error: could not find abbrev number %u"), abbrev_number
);
2952 bfd_set_error (bfd_error_bad_value
);
2957 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
2959 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], unit
,
2960 info_ptr
, info_ptr_end
);
2961 if (info_ptr
== NULL
)
2963 /* It doesn't ever make sense for DW_AT_specification to
2964 refer to the same DIE. Stop simple recursion. */
2965 if (info_ptr
== orig_info_ptr
)
2968 (_("DWARF error: abstract instance recursion detected"));
2969 bfd_set_error (bfd_error_bad_value
);
2975 /* Prefer DW_AT_MIPS_linkage_name or DW_AT_linkage_name
2977 if (name
== NULL
&& is_str_attr (attr
.form
))
2980 if (non_mangled (unit
->lang
))
2984 case DW_AT_specification
:
2985 if (!find_abstract_instance (unit
, info_ptr
, &attr
,
2987 filename_ptr
, linenumber_ptr
))
2990 case DW_AT_linkage_name
:
2991 case DW_AT_MIPS_linkage_name
:
2992 /* PR 16949: Corrupt debug info can place
2993 non-string forms into these attributes. */
2994 if (is_str_attr (attr
.form
))
3000 case DW_AT_decl_file
:
3001 if (!comp_unit_maybe_decode_line_info (unit
, unit
->stash
))
3003 *filename_ptr
= concat_filename (unit
->line_table
,
3006 case DW_AT_decl_line
:
3007 *linenumber_ptr
= attr
.u
.val
;
3020 read_rangelist (struct comp_unit
*unit
, struct arange
*arange
,
3021 bfd_uint64_t offset
)
3023 bfd_byte
*ranges_ptr
;
3024 bfd_byte
*ranges_end
;
3025 bfd_vma base_address
= unit
->base_address
;
3027 if (! unit
->stash
->dwarf_ranges_buffer
)
3029 if (! read_debug_ranges (unit
))
3033 ranges_ptr
= unit
->stash
->dwarf_ranges_buffer
+ offset
;
3034 if (ranges_ptr
< unit
->stash
->dwarf_ranges_buffer
)
3036 ranges_end
= unit
->stash
->dwarf_ranges_buffer
+ unit
->stash
->dwarf_ranges_size
;
3043 /* PR 17512: file: 62cada7d. */
3044 if (ranges_ptr
+ 2 * unit
->addr_size
> ranges_end
)
3047 low_pc
= read_address (unit
, ranges_ptr
, ranges_end
);
3048 ranges_ptr
+= unit
->addr_size
;
3049 high_pc
= read_address (unit
, ranges_ptr
, ranges_end
);
3050 ranges_ptr
+= unit
->addr_size
;
3052 if (low_pc
== 0 && high_pc
== 0)
3054 if (low_pc
== -1UL && high_pc
!= -1UL)
3055 base_address
= high_pc
;
3058 if (!arange_add (unit
, arange
,
3059 base_address
+ low_pc
, base_address
+ high_pc
))
3066 /* DWARF2 Compilation unit functions. */
3068 /* Scan over each die in a comp. unit looking for functions to add
3069 to the function table and variables to the variable table. */
3072 scan_unit_for_symbols (struct comp_unit
*unit
)
3074 bfd
*abfd
= unit
->abfd
;
3075 bfd_byte
*info_ptr
= unit
->first_child_die_ptr
;
3076 bfd_byte
*info_ptr_end
= unit
->end_ptr
;
3077 int nesting_level
= 0;
3078 struct nest_funcinfo
{
3079 struct funcinfo
*func
;
3081 int nested_funcs_size
;
3083 /* Maintain a stack of in-scope functions and inlined functions, which we
3084 can use to set the caller_func field. */
3085 nested_funcs_size
= 32;
3086 nested_funcs
= (struct nest_funcinfo
*)
3087 bfd_malloc (nested_funcs_size
* sizeof (*nested_funcs
));
3088 if (nested_funcs
== NULL
)
3090 nested_funcs
[nesting_level
].func
= 0;
3092 while (nesting_level
>= 0)
3094 unsigned int abbrev_number
, bytes_read
, i
;
3095 struct abbrev_info
*abbrev
;
3096 struct attribute attr
;
3097 struct funcinfo
*func
;
3098 struct varinfo
*var
;
3100 bfd_vma high_pc
= 0;
3101 bfd_boolean high_pc_relative
= FALSE
;
3103 /* PR 17512: file: 9f405d9d. */
3104 if (info_ptr
>= info_ptr_end
)
3107 abbrev_number
= _bfd_safe_read_leb128 (abfd
, info_ptr
, &bytes_read
,
3108 FALSE
, info_ptr_end
);
3109 info_ptr
+= bytes_read
;
3111 if (! abbrev_number
)
3117 abbrev
= lookup_abbrev (abbrev_number
, unit
->abbrevs
);
3120 static unsigned int previous_failed_abbrev
= -1U;
3122 /* Avoid multiple reports of the same missing abbrev. */
3123 if (abbrev_number
!= previous_failed_abbrev
)
3126 (_("DWARF error: could not find abbrev number %u"),
3128 previous_failed_abbrev
= abbrev_number
;
3130 bfd_set_error (bfd_error_bad_value
);
3135 if (abbrev
->tag
== DW_TAG_subprogram
3136 || abbrev
->tag
== DW_TAG_entry_point
3137 || abbrev
->tag
== DW_TAG_inlined_subroutine
)
3139 bfd_size_type amt
= sizeof (struct funcinfo
);
3140 func
= (struct funcinfo
*) bfd_zalloc (abfd
, amt
);
3143 func
->tag
= abbrev
->tag
;
3144 func
->prev_func
= unit
->function_table
;
3145 unit
->function_table
= func
;
3146 unit
->number_of_functions
++;
3147 BFD_ASSERT (!unit
->cached
);
3149 if (func
->tag
== DW_TAG_inlined_subroutine
)
3150 for (i
= nesting_level
; i
-- != 0; )
3151 if (nested_funcs
[i
].func
)
3153 func
->caller_func
= nested_funcs
[i
].func
;
3156 nested_funcs
[nesting_level
].func
= func
;
3161 if (abbrev
->tag
== DW_TAG_variable
)
3163 bfd_size_type amt
= sizeof (struct varinfo
);
3164 var
= (struct varinfo
*) bfd_zalloc (abfd
, amt
);
3167 var
->tag
= abbrev
->tag
;
3169 var
->prev_var
= unit
->variable_table
;
3170 unit
->variable_table
= var
;
3171 /* PR 18205: Missing debug information can cause this
3172 var to be attached to an already cached unit. */
3175 /* No inline function in scope at this nesting level. */
3176 nested_funcs
[nesting_level
].func
= 0;
3179 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3181 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
],
3182 unit
, info_ptr
, info_ptr_end
);
3183 if (info_ptr
== NULL
)
3190 case DW_AT_call_file
:
3191 func
->caller_file
= concat_filename (unit
->line_table
,
3195 case DW_AT_call_line
:
3196 func
->caller_line
= attr
.u
.val
;
3199 case DW_AT_abstract_origin
:
3200 case DW_AT_specification
:
3201 if (!find_abstract_instance (unit
, info_ptr
, &attr
,
3210 /* Prefer DW_AT_MIPS_linkage_name or DW_AT_linkage_name
3212 if (func
->name
== NULL
&& is_str_attr (attr
.form
))
3214 func
->name
= attr
.u
.str
;
3215 if (non_mangled (unit
->lang
))
3216 func
->is_linkage
= TRUE
;
3220 case DW_AT_linkage_name
:
3221 case DW_AT_MIPS_linkage_name
:
3222 /* PR 16949: Corrupt debug info can place
3223 non-string forms into these attributes. */
3224 if (is_str_attr (attr
.form
))
3226 func
->name
= attr
.u
.str
;
3227 func
->is_linkage
= TRUE
;
3232 low_pc
= attr
.u
.val
;
3236 high_pc
= attr
.u
.val
;
3237 high_pc_relative
= attr
.form
!= DW_FORM_addr
;
3241 if (!read_rangelist (unit
, &func
->arange
, attr
.u
.val
))
3245 case DW_AT_decl_file
:
3246 func
->file
= concat_filename (unit
->line_table
,
3250 case DW_AT_decl_line
:
3251 func
->line
= attr
.u
.val
;
3263 if (is_str_attr (attr
.form
))
3264 var
->name
= attr
.u
.str
;
3267 case DW_AT_decl_file
:
3268 var
->file
= concat_filename (unit
->line_table
,
3272 case DW_AT_decl_line
:
3273 var
->line
= attr
.u
.val
;
3276 case DW_AT_external
:
3277 if (attr
.u
.val
!= 0)
3281 case DW_AT_location
:
3285 case DW_FORM_block1
:
3286 case DW_FORM_block2
:
3287 case DW_FORM_block4
:
3288 case DW_FORM_exprloc
:
3289 if (attr
.u
.blk
->data
!= NULL
3290 && *attr
.u
.blk
->data
== DW_OP_addr
)
3294 /* Verify that DW_OP_addr is the only opcode in the
3295 location, in which case the block size will be 1
3296 plus the address size. */
3297 /* ??? For TLS variables, gcc can emit
3298 DW_OP_addr <addr> DW_OP_GNU_push_tls_address
3299 which we don't handle here yet. */
3300 if (attr
.u
.blk
->size
== unit
->addr_size
+ 1U)
3301 var
->addr
= bfd_get (unit
->addr_size
* 8,
3303 attr
.u
.blk
->data
+ 1);
3318 if (high_pc_relative
)
3321 if (func
&& high_pc
!= 0)
3323 if (!arange_add (unit
, &func
->arange
, low_pc
, high_pc
))
3327 if (abbrev
->has_children
)
3331 if (nesting_level
>= nested_funcs_size
)
3333 struct nest_funcinfo
*tmp
;
3335 nested_funcs_size
*= 2;
3336 tmp
= (struct nest_funcinfo
*)
3337 bfd_realloc (nested_funcs
,
3338 nested_funcs_size
* sizeof (*nested_funcs
));
3343 nested_funcs
[nesting_level
].func
= 0;
3347 free (nested_funcs
);
3351 free (nested_funcs
);
3355 /* Parse a DWARF2 compilation unit starting at INFO_PTR. UNIT_LENGTH
3356 includes the compilation unit header that proceeds the DIE's, but
3357 does not include the length field that precedes each compilation
3358 unit header. END_PTR points one past the end of this comp unit.
3359 OFFSET_SIZE is the size of DWARF2 offsets (either 4 or 8 bytes).
3361 This routine does not read the whole compilation unit; only enough
3362 to get to the line number information for the compilation unit. */
3364 static struct comp_unit
*
3365 parse_comp_unit (struct dwarf2_debug
*stash
,
3366 bfd_vma unit_length
,
3367 bfd_byte
*info_ptr_unit
,
3368 unsigned int offset_size
)
3370 struct comp_unit
* unit
;
3371 unsigned int version
;
3372 bfd_uint64_t abbrev_offset
= 0;
3373 /* Initialize it just to avoid a GCC false warning. */
3374 unsigned int addr_size
= -1;
3375 struct abbrev_info
** abbrevs
;
3376 unsigned int abbrev_number
, bytes_read
, i
;
3377 struct abbrev_info
*abbrev
;
3378 struct attribute attr
;
3379 bfd_byte
*info_ptr
= stash
->info_ptr
;
3380 bfd_byte
*end_ptr
= info_ptr
+ unit_length
;
3383 bfd_vma high_pc
= 0;
3384 bfd
*abfd
= stash
->bfd_ptr
;
3385 bfd_boolean high_pc_relative
= FALSE
;
3386 enum dwarf_unit_type unit_type
;
3388 version
= read_2_bytes (abfd
, info_ptr
, end_ptr
);
3390 if (version
< 2 || version
> 5)
3392 /* PR 19872: A version number of 0 probably means that there is padding
3393 at the end of the .debug_info section. Gold puts it there when
3394 performing an incremental link, for example. So do not generate
3395 an error, just return a NULL. */
3399 (_("DWARF error: found dwarf version '%u', this reader"
3400 " only handles version 2, 3, 4 and 5 information"), version
);
3401 bfd_set_error (bfd_error_bad_value
);
3407 unit_type
= DW_UT_compile
;
3410 unit_type
= read_1_byte (abfd
, info_ptr
, end_ptr
);
3413 addr_size
= read_1_byte (abfd
, info_ptr
, end_ptr
);
3417 BFD_ASSERT (offset_size
== 4 || offset_size
== 8);
3418 if (offset_size
== 4)
3419 abbrev_offset
= read_4_bytes (abfd
, info_ptr
, end_ptr
);
3421 abbrev_offset
= read_8_bytes (abfd
, info_ptr
, end_ptr
);
3422 info_ptr
+= offset_size
;
3426 addr_size
= read_1_byte (abfd
, info_ptr
, end_ptr
);
3430 if (unit_type
== DW_UT_type
)
3432 /* Skip type signature. */
3435 /* Skip type offset. */
3436 info_ptr
+= offset_size
;
3439 if (addr_size
> sizeof (bfd_vma
))
3442 /* xgettext: c-format */
3443 (_("DWARF error: found address size '%u', this reader"
3444 " can not handle sizes greater than '%u'"),
3446 (unsigned int) sizeof (bfd_vma
));
3447 bfd_set_error (bfd_error_bad_value
);
3451 if (addr_size
!= 2 && addr_size
!= 4 && addr_size
!= 8)
3454 ("DWARF error: found address size '%u', this reader"
3455 " can only handle address sizes '2', '4' and '8'", addr_size
);
3456 bfd_set_error (bfd_error_bad_value
);
3460 /* Read the abbrevs for this compilation unit into a table. */
3461 abbrevs
= read_abbrevs (abfd
, abbrev_offset
, stash
);
3465 abbrev_number
= _bfd_safe_read_leb128 (abfd
, info_ptr
, &bytes_read
,
3467 info_ptr
+= bytes_read
;
3468 if (! abbrev_number
)
3470 /* PR 19872: An abbrev number of 0 probably means that there is padding
3471 at the end of the .debug_abbrev section. Gold puts it there when
3472 performing an incremental link, for example. So do not generate
3473 an error, just return a NULL. */
3477 abbrev
= lookup_abbrev (abbrev_number
, abbrevs
);
3480 _bfd_error_handler (_("DWARF error: could not find abbrev number %u"),
3482 bfd_set_error (bfd_error_bad_value
);
3486 amt
= sizeof (struct comp_unit
);
3487 unit
= (struct comp_unit
*) bfd_zalloc (abfd
, amt
);
3491 unit
->version
= version
;
3492 unit
->addr_size
= addr_size
;
3493 unit
->offset_size
= offset_size
;
3494 unit
->abbrevs
= abbrevs
;
3495 unit
->end_ptr
= end_ptr
;
3496 unit
->stash
= stash
;
3497 unit
->info_ptr_unit
= info_ptr_unit
;
3499 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3501 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], unit
, info_ptr
, end_ptr
);
3502 if (info_ptr
== NULL
)
3505 /* Store the data if it is of an attribute we want to keep in a
3506 partial symbol table. */
3509 case DW_AT_stmt_list
:
3511 unit
->line_offset
= attr
.u
.val
;
3515 if (is_str_attr (attr
.form
))
3516 unit
->name
= attr
.u
.str
;
3520 low_pc
= attr
.u
.val
;
3521 /* If the compilation unit DIE has a DW_AT_low_pc attribute,
3522 this is the base address to use when reading location
3523 lists or range lists. */
3524 if (abbrev
->tag
== DW_TAG_compile_unit
)
3525 unit
->base_address
= low_pc
;
3529 high_pc
= attr
.u
.val
;
3530 high_pc_relative
= attr
.form
!= DW_FORM_addr
;
3534 if (!read_rangelist (unit
, &unit
->arange
, attr
.u
.val
))
3538 case DW_AT_comp_dir
:
3540 char *comp_dir
= attr
.u
.str
;
3542 /* PR 17512: file: 1fe726be. */
3543 if (! is_str_attr (attr
.form
))
3546 (_("DWARF error: DW_AT_comp_dir attribute encountered with a non-string form"));
3552 /* Irix 6.2 native cc prepends <machine>.: to the compilation
3553 directory, get rid of it. */
3554 char *cp
= strchr (comp_dir
, ':');
3556 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
3559 unit
->comp_dir
= comp_dir
;
3563 case DW_AT_language
:
3564 unit
->lang
= attr
.u
.val
;
3571 if (high_pc_relative
)
3575 if (!arange_add (unit
, &unit
->arange
, low_pc
, high_pc
))
3579 unit
->first_child_die_ptr
= info_ptr
;
3583 /* Return TRUE if UNIT may contain the address given by ADDR. When
3584 there are functions written entirely with inline asm statements, the
3585 range info in the compilation unit header may not be correct. We
3586 need to consult the line info table to see if a compilation unit
3587 really contains the given address. */
3590 comp_unit_contains_address (struct comp_unit
*unit
, bfd_vma addr
)
3592 struct arange
*arange
;
3597 arange
= &unit
->arange
;
3600 if (addr
>= arange
->low
&& addr
< arange
->high
)
3602 arange
= arange
->next
;
3609 /* If UNIT contains ADDR, set the output parameters to the values for
3610 the line containing ADDR. The output parameters, FILENAME_PTR,
3611 FUNCTION_PTR, and LINENUMBER_PTR, are pointers to the objects
3614 Returns the range of addresses covered by the entry that was used
3615 to fill in *LINENUMBER_PTR or 0 if it was not filled in. */
3618 comp_unit_find_nearest_line (struct comp_unit
*unit
,
3620 const char **filename_ptr
,
3621 struct funcinfo
**function_ptr
,
3622 unsigned int *linenumber_ptr
,
3623 unsigned int *discriminator_ptr
,
3624 struct dwarf2_debug
*stash
)
3628 if (!comp_unit_maybe_decode_line_info (unit
, stash
))
3631 *function_ptr
= NULL
;
3632 func_p
= lookup_address_in_function_table (unit
, addr
, function_ptr
);
3633 if (func_p
&& (*function_ptr
)->tag
== DW_TAG_inlined_subroutine
)
3634 stash
->inliner_chain
= *function_ptr
;
3636 return lookup_address_in_line_info_table (unit
->line_table
, addr
,
3642 /* Check to see if line info is already decoded in a comp_unit.
3643 If not, decode it. Returns TRUE if no errors were encountered;
3647 comp_unit_maybe_decode_line_info (struct comp_unit
*unit
,
3648 struct dwarf2_debug
*stash
)
3653 if (! unit
->line_table
)
3655 if (! unit
->stmtlist
)
3661 unit
->line_table
= decode_line_info (unit
, stash
);
3663 if (! unit
->line_table
)
3669 if (unit
->first_child_die_ptr
< unit
->end_ptr
3670 && ! scan_unit_for_symbols (unit
))
3680 /* If UNIT contains SYM at ADDR, set the output parameters to the
3681 values for the line containing SYM. The output parameters,
3682 FILENAME_PTR, and LINENUMBER_PTR, are pointers to the objects to be
3685 Return TRUE if UNIT contains SYM, and no errors were encountered;
3689 comp_unit_find_line (struct comp_unit
*unit
,
3692 const char **filename_ptr
,
3693 unsigned int *linenumber_ptr
,
3694 struct dwarf2_debug
*stash
)
3696 if (!comp_unit_maybe_decode_line_info (unit
, stash
))
3699 if (sym
->flags
& BSF_FUNCTION
)
3700 return lookup_symbol_in_function_table (unit
, sym
, addr
,
3704 return lookup_symbol_in_variable_table (unit
, sym
, addr
,
3709 static struct funcinfo
*
3710 reverse_funcinfo_list (struct funcinfo
*head
)
3712 struct funcinfo
*rhead
;
3713 struct funcinfo
*temp
;
3715 for (rhead
= NULL
; head
; head
= temp
)
3717 temp
= head
->prev_func
;
3718 head
->prev_func
= rhead
;
3724 static struct varinfo
*
3725 reverse_varinfo_list (struct varinfo
*head
)
3727 struct varinfo
*rhead
;
3728 struct varinfo
*temp
;
3730 for (rhead
= NULL
; head
; head
= temp
)
3732 temp
= head
->prev_var
;
3733 head
->prev_var
= rhead
;
3739 /* Extract all interesting funcinfos and varinfos of a compilation
3740 unit into hash tables for faster lookup. Returns TRUE if no
3741 errors were enountered; FALSE otherwise. */
3744 comp_unit_hash_info (struct dwarf2_debug
*stash
,
3745 struct comp_unit
*unit
,
3746 struct info_hash_table
*funcinfo_hash_table
,
3747 struct info_hash_table
*varinfo_hash_table
)
3749 struct funcinfo
* each_func
;
3750 struct varinfo
* each_var
;
3751 bfd_boolean okay
= TRUE
;
3753 BFD_ASSERT (stash
->info_hash_status
!= STASH_INFO_HASH_DISABLED
);
3755 if (!comp_unit_maybe_decode_line_info (unit
, stash
))
3758 BFD_ASSERT (!unit
->cached
);
3760 /* To preserve the original search order, we went to visit the function
3761 infos in the reversed order of the list. However, making the list
3762 bi-directional use quite a bit of extra memory. So we reverse
3763 the list first, traverse the list in the now reversed order and
3764 finally reverse the list again to get back the original order. */
3765 unit
->function_table
= reverse_funcinfo_list (unit
->function_table
);
3766 for (each_func
= unit
->function_table
;
3768 each_func
= each_func
->prev_func
)
3770 /* Skip nameless functions. */
3771 if (each_func
->name
)
3772 /* There is no need to copy name string into hash table as
3773 name string is either in the dwarf string buffer or
3774 info in the stash. */
3775 okay
= insert_info_hash_table (funcinfo_hash_table
, each_func
->name
,
3776 (void*) each_func
, FALSE
);
3778 unit
->function_table
= reverse_funcinfo_list (unit
->function_table
);
3782 /* We do the same for variable infos. */
3783 unit
->variable_table
= reverse_varinfo_list (unit
->variable_table
);
3784 for (each_var
= unit
->variable_table
;
3786 each_var
= each_var
->prev_var
)
3788 /* Skip stack vars and vars with no files or names. */
3789 if (each_var
->stack
== 0
3790 && each_var
->file
!= NULL
3791 && each_var
->name
!= NULL
)
3792 /* There is no need to copy name string into hash table as
3793 name string is either in the dwarf string buffer or
3794 info in the stash. */
3795 okay
= insert_info_hash_table (varinfo_hash_table
, each_var
->name
,
3796 (void*) each_var
, FALSE
);
3799 unit
->variable_table
= reverse_varinfo_list (unit
->variable_table
);
3800 unit
->cached
= TRUE
;
3804 /* Locate a section in a BFD containing debugging info. The search starts
3805 from the section after AFTER_SEC, or from the first section in the BFD if
3806 AFTER_SEC is NULL. The search works by examining the names of the
3807 sections. There are three permissiable names. The first two are given
3808 by DEBUG_SECTIONS[debug_info] (whose standard DWARF2 names are .debug_info
3809 and .zdebug_info). The third is a prefix .gnu.linkonce.wi.
3810 This is a variation on the .debug_info section which has a checksum
3811 describing the contents appended onto the name. This allows the linker to
3812 identify and discard duplicate debugging sections for different
3813 compilation units. */
3814 #define GNU_LINKONCE_INFO ".gnu.linkonce.wi."
3817 find_debug_info (bfd
*abfd
, const struct dwarf_debug_section
*debug_sections
,
3818 asection
*after_sec
)
3823 if (after_sec
== NULL
)
3825 look
= debug_sections
[debug_info
].uncompressed_name
;
3826 msec
= bfd_get_section_by_name (abfd
, look
);
3830 look
= debug_sections
[debug_info
].compressed_name
;
3833 msec
= bfd_get_section_by_name (abfd
, look
);
3838 for (msec
= abfd
->sections
; msec
!= NULL
; msec
= msec
->next
)
3839 if (CONST_STRNEQ (msec
->name
, GNU_LINKONCE_INFO
))
3845 for (msec
= after_sec
->next
; msec
!= NULL
; msec
= msec
->next
)
3847 look
= debug_sections
[debug_info
].uncompressed_name
;
3848 if (strcmp (msec
->name
, look
) == 0)
3851 look
= debug_sections
[debug_info
].compressed_name
;
3852 if (look
!= NULL
&& strcmp (msec
->name
, look
) == 0)
3855 if (CONST_STRNEQ (msec
->name
, GNU_LINKONCE_INFO
))
3862 /* Transfer VMAs from object file to separate debug file. */
3865 set_debug_vma (bfd
*orig_bfd
, bfd
*debug_bfd
)
3869 for (s
= orig_bfd
->sections
, d
= debug_bfd
->sections
;
3870 s
!= NULL
&& d
!= NULL
;
3871 s
= s
->next
, d
= d
->next
)
3873 if ((d
->flags
& SEC_DEBUGGING
) != 0)
3875 /* ??? Assumes 1-1 correspondence between sections in the
3877 if (strcmp (s
->name
, d
->name
) == 0)
3879 d
->output_section
= s
->output_section
;
3880 d
->output_offset
= s
->output_offset
;
3886 /* Unset vmas for adjusted sections in STASH. */
3889 unset_sections (struct dwarf2_debug
*stash
)
3892 struct adjusted_section
*p
;
3894 i
= stash
->adjusted_section_count
;
3895 p
= stash
->adjusted_sections
;
3896 for (; i
> 0; i
--, p
++)
3897 p
->section
->vma
= 0;
3900 /* Set VMAs for allocated and .debug_info sections in ORIG_BFD, a
3901 relocatable object file. VMAs are normally all zero in relocatable
3902 object files, so if we want to distinguish locations in sections by
3903 address we need to set VMAs so the sections do not overlap. We
3904 also set VMA on .debug_info so that when we have multiple
3905 .debug_info sections (or the linkonce variant) they also do not
3906 overlap. The multiple .debug_info sections make up a single
3907 logical section. ??? We should probably do the same for other
3911 place_sections (bfd
*orig_bfd
, struct dwarf2_debug
*stash
)
3914 struct adjusted_section
*p
;
3916 const char *debug_info_name
;
3918 if (stash
->adjusted_section_count
!= 0)
3920 i
= stash
->adjusted_section_count
;
3921 p
= stash
->adjusted_sections
;
3922 for (; i
> 0; i
--, p
++)
3923 p
->section
->vma
= p
->adj_vma
;
3927 debug_info_name
= stash
->debug_sections
[debug_info
].uncompressed_name
;
3934 for (sect
= abfd
->sections
; sect
!= NULL
; sect
= sect
->next
)
3938 if ((sect
->output_section
!= NULL
3939 && sect
->output_section
!= sect
3940 && (sect
->flags
& SEC_DEBUGGING
) == 0)
3944 is_debug_info
= (strcmp (sect
->name
, debug_info_name
) == 0
3945 || CONST_STRNEQ (sect
->name
, GNU_LINKONCE_INFO
));
3947 if (!((sect
->flags
& SEC_ALLOC
) != 0 && abfd
== orig_bfd
)
3953 if (abfd
== stash
->bfd_ptr
)
3955 abfd
= stash
->bfd_ptr
;
3959 stash
->adjusted_section_count
= -1;
3962 bfd_vma last_vma
= 0, last_dwarf
= 0;
3963 bfd_size_type amt
= i
* sizeof (struct adjusted_section
);
3965 p
= (struct adjusted_section
*) bfd_malloc (amt
);
3969 stash
->adjusted_sections
= p
;
3970 stash
->adjusted_section_count
= i
;
3977 for (sect
= abfd
->sections
; sect
!= NULL
; sect
= sect
->next
)
3982 if ((sect
->output_section
!= NULL
3983 && sect
->output_section
!= sect
3984 && (sect
->flags
& SEC_DEBUGGING
) == 0)
3988 is_debug_info
= (strcmp (sect
->name
, debug_info_name
) == 0
3989 || CONST_STRNEQ (sect
->name
, GNU_LINKONCE_INFO
));
3991 if (!((sect
->flags
& SEC_ALLOC
) != 0 && abfd
== orig_bfd
)
3995 sz
= sect
->rawsize
? sect
->rawsize
: sect
->size
;
3999 BFD_ASSERT (sect
->alignment_power
== 0);
4000 sect
->vma
= last_dwarf
;
4005 /* Align the new address to the current section
4007 last_vma
= ((last_vma
4008 + ~(-((bfd_vma
) 1 << sect
->alignment_power
)))
4009 & (-((bfd_vma
) 1 << sect
->alignment_power
)));
4010 sect
->vma
= last_vma
;
4015 p
->adj_vma
= sect
->vma
;
4018 if (abfd
== stash
->bfd_ptr
)
4020 abfd
= stash
->bfd_ptr
;
4024 if (orig_bfd
!= stash
->bfd_ptr
)
4025 set_debug_vma (orig_bfd
, stash
->bfd_ptr
);
4030 /* Look up a funcinfo by name using the given info hash table. If found,
4031 also update the locations pointed to by filename_ptr and linenumber_ptr.
4033 This function returns TRUE if a funcinfo that matches the given symbol
4034 and address is found with any error; otherwise it returns FALSE. */
4037 info_hash_lookup_funcinfo (struct info_hash_table
*hash_table
,
4040 const char **filename_ptr
,
4041 unsigned int *linenumber_ptr
)
4043 struct funcinfo
* each_func
;
4044 struct funcinfo
* best_fit
= NULL
;
4045 bfd_vma best_fit_len
= 0;
4046 struct info_list_node
*node
;
4047 struct arange
*arange
;
4048 const char *name
= bfd_asymbol_name (sym
);
4049 asection
*sec
= bfd_get_section (sym
);
4051 for (node
= lookup_info_hash_table (hash_table
, name
);
4055 each_func
= (struct funcinfo
*) node
->info
;
4056 for (arange
= &each_func
->arange
;
4058 arange
= arange
->next
)
4060 if ((!each_func
->sec
|| each_func
->sec
== sec
)
4061 && addr
>= arange
->low
4062 && addr
< arange
->high
4064 || arange
->high
- arange
->low
< best_fit_len
))
4066 best_fit
= each_func
;
4067 best_fit_len
= arange
->high
- arange
->low
;
4074 best_fit
->sec
= sec
;
4075 *filename_ptr
= best_fit
->file
;
4076 *linenumber_ptr
= best_fit
->line
;
4083 /* Look up a varinfo by name using the given info hash table. If found,
4084 also update the locations pointed to by filename_ptr and linenumber_ptr.
4086 This function returns TRUE if a varinfo that matches the given symbol
4087 and address is found with any error; otherwise it returns FALSE. */
4090 info_hash_lookup_varinfo (struct info_hash_table
*hash_table
,
4093 const char **filename_ptr
,
4094 unsigned int *linenumber_ptr
)
4096 const char *name
= bfd_asymbol_name (sym
);
4097 asection
*sec
= bfd_get_section (sym
);
4098 struct varinfo
* each
;
4099 struct info_list_node
*node
;
4101 for (node
= lookup_info_hash_table (hash_table
, name
);
4105 each
= (struct varinfo
*) node
->info
;
4106 if (each
->addr
== addr
4107 && (!each
->sec
|| each
->sec
== sec
))
4110 *filename_ptr
= each
->file
;
4111 *linenumber_ptr
= each
->line
;
4119 /* Update the funcinfo and varinfo info hash tables if they are
4120 not up to date. Returns TRUE if there is no error; otherwise
4121 returns FALSE and disable the info hash tables. */
4124 stash_maybe_update_info_hash_tables (struct dwarf2_debug
*stash
)
4126 struct comp_unit
*each
;
4128 /* Exit if hash tables are up-to-date. */
4129 if (stash
->all_comp_units
== stash
->hash_units_head
)
4132 if (stash
->hash_units_head
)
4133 each
= stash
->hash_units_head
->prev_unit
;
4135 each
= stash
->last_comp_unit
;
4139 if (!comp_unit_hash_info (stash
, each
, stash
->funcinfo_hash_table
,
4140 stash
->varinfo_hash_table
))
4142 stash
->info_hash_status
= STASH_INFO_HASH_DISABLED
;
4145 each
= each
->prev_unit
;
4148 stash
->hash_units_head
= stash
->all_comp_units
;
4152 /* Check consistency of info hash tables. This is for debugging only. */
4154 static void ATTRIBUTE_UNUSED
4155 stash_verify_info_hash_table (struct dwarf2_debug
*stash
)
4157 struct comp_unit
*each_unit
;
4158 struct funcinfo
*each_func
;
4159 struct varinfo
*each_var
;
4160 struct info_list_node
*node
;
4163 for (each_unit
= stash
->all_comp_units
;
4165 each_unit
= each_unit
->next_unit
)
4167 for (each_func
= each_unit
->function_table
;
4169 each_func
= each_func
->prev_func
)
4171 if (!each_func
->name
)
4173 node
= lookup_info_hash_table (stash
->funcinfo_hash_table
,
4177 while (node
&& !found
)
4179 found
= node
->info
== each_func
;
4185 for (each_var
= each_unit
->variable_table
;
4187 each_var
= each_var
->prev_var
)
4189 if (!each_var
->name
|| !each_var
->file
|| each_var
->stack
)
4191 node
= lookup_info_hash_table (stash
->varinfo_hash_table
,
4195 while (node
&& !found
)
4197 found
= node
->info
== each_var
;
4205 /* Check to see if we want to enable the info hash tables, which consume
4206 quite a bit of memory. Currently we only check the number times
4207 bfd_dwarf2_find_line is called. In the future, we may also want to
4208 take the number of symbols into account. */
4211 stash_maybe_enable_info_hash_tables (bfd
*abfd
, struct dwarf2_debug
*stash
)
4213 BFD_ASSERT (stash
->info_hash_status
== STASH_INFO_HASH_OFF
);
4215 if (stash
->info_hash_count
++ < STASH_INFO_HASH_TRIGGER
)
4218 /* FIXME: Maybe we should check the reduce_memory_overheads
4219 and optimize fields in the bfd_link_info structure ? */
4221 /* Create hash tables. */
4222 stash
->funcinfo_hash_table
= create_info_hash_table (abfd
);
4223 stash
->varinfo_hash_table
= create_info_hash_table (abfd
);
4224 if (!stash
->funcinfo_hash_table
|| !stash
->varinfo_hash_table
)
4226 /* Turn off info hashes if any allocation above fails. */
4227 stash
->info_hash_status
= STASH_INFO_HASH_DISABLED
;
4230 /* We need a forced update so that the info hash tables will
4231 be created even though there is no compilation unit. That
4232 happens if STASH_INFO_HASH_TRIGGER is 0. */
4233 stash_maybe_update_info_hash_tables (stash
);
4234 stash
->info_hash_status
= STASH_INFO_HASH_ON
;
4237 /* Find the file and line associated with a symbol and address using the
4238 info hash tables of a stash. If there is a match, the function returns
4239 TRUE and update the locations pointed to by filename_ptr and linenumber_ptr;
4240 otherwise it returns FALSE. */
4243 stash_find_line_fast (struct dwarf2_debug
*stash
,
4246 const char **filename_ptr
,
4247 unsigned int *linenumber_ptr
)
4249 BFD_ASSERT (stash
->info_hash_status
== STASH_INFO_HASH_ON
);
4251 if (sym
->flags
& BSF_FUNCTION
)
4252 return info_hash_lookup_funcinfo (stash
->funcinfo_hash_table
, sym
, addr
,
4253 filename_ptr
, linenumber_ptr
);
4254 return info_hash_lookup_varinfo (stash
->varinfo_hash_table
, sym
, addr
,
4255 filename_ptr
, linenumber_ptr
);
4258 /* Save current section VMAs. */
4261 save_section_vma (const bfd
*abfd
, struct dwarf2_debug
*stash
)
4266 if (abfd
->section_count
== 0)
4268 stash
->sec_vma
= bfd_malloc (sizeof (*stash
->sec_vma
) * abfd
->section_count
);
4269 if (stash
->sec_vma
== NULL
)
4271 stash
->sec_vma_count
= abfd
->section_count
;
4272 for (i
= 0, s
= abfd
->sections
;
4273 s
!= NULL
&& i
< abfd
->section_count
;
4276 if (s
->output_section
!= NULL
)
4277 stash
->sec_vma
[i
] = s
->output_section
->vma
+ s
->output_offset
;
4279 stash
->sec_vma
[i
] = s
->vma
;
4284 /* Compare current section VMAs against those at the time the stash
4285 was created. If find_nearest_line is used in linker warnings or
4286 errors early in the link process, the debug info stash will be
4287 invalid for later calls. This is because we relocate debug info
4288 sections, so the stashed section contents depend on symbol values,
4289 which in turn depend on section VMAs. */
4292 section_vma_same (const bfd
*abfd
, const struct dwarf2_debug
*stash
)
4297 /* PR 24334: If the number of sections in ABFD has changed between
4298 when the stash was created and now, then we cannot trust the
4299 stashed vma information. */
4300 if (abfd
->section_count
!= stash
->sec_vma_count
)
4303 for (i
= 0, s
= abfd
->sections
;
4304 s
!= NULL
&& i
< abfd
->section_count
;
4309 if (s
->output_section
!= NULL
)
4310 vma
= s
->output_section
->vma
+ s
->output_offset
;
4313 if (vma
!= stash
->sec_vma
[i
])
4319 /* Read debug information from DEBUG_BFD when DEBUG_BFD is specified.
4320 If DEBUG_BFD is not specified, we read debug information from ABFD
4321 or its gnu_debuglink. The results will be stored in PINFO.
4322 The function returns TRUE iff debug information is ready. */
4325 _bfd_dwarf2_slurp_debug_info (bfd
*abfd
, bfd
*debug_bfd
,
4326 const struct dwarf_debug_section
*debug_sections
,
4329 bfd_boolean do_place
)
4331 bfd_size_type amt
= sizeof (struct dwarf2_debug
);
4332 bfd_size_type total_size
;
4334 struct dwarf2_debug
*stash
= (struct dwarf2_debug
*) *pinfo
;
4338 if (stash
->orig_bfd
== abfd
4339 && section_vma_same (abfd
, stash
))
4341 /* Check that we did previously find some debug information
4342 before attempting to make use of it. */
4343 if (stash
->bfd_ptr
!= NULL
)
4345 if (do_place
&& !place_sections (abfd
, stash
))
4352 _bfd_dwarf2_cleanup_debug_info (abfd
, pinfo
);
4353 memset (stash
, 0, amt
);
4357 stash
= (struct dwarf2_debug
*) bfd_zalloc (abfd
, amt
);
4361 stash
->orig_bfd
= abfd
;
4362 stash
->debug_sections
= debug_sections
;
4363 stash
->syms
= symbols
;
4364 if (!save_section_vma (abfd
, stash
))
4369 if (debug_bfd
== NULL
)
4372 msec
= find_debug_info (debug_bfd
, debug_sections
, NULL
);
4373 if (msec
== NULL
&& abfd
== debug_bfd
)
4375 char * debug_filename
;
4377 debug_filename
= bfd_follow_build_id_debuglink (abfd
, DEBUGDIR
);
4378 if (debug_filename
== NULL
)
4379 debug_filename
= bfd_follow_gnu_debuglink (abfd
, DEBUGDIR
);
4381 if (debug_filename
== NULL
)
4382 /* No dwarf2 info, and no gnu_debuglink to follow.
4383 Note that at this point the stash has been allocated, but
4384 contains zeros. This lets future calls to this function
4385 fail more quickly. */
4388 /* Set BFD_DECOMPRESS to decompress debug sections. */
4389 if ((debug_bfd
= bfd_openr (debug_filename
, NULL
)) == NULL
4390 || !(debug_bfd
->flags
|= BFD_DECOMPRESS
,
4391 bfd_check_format (debug_bfd
, bfd_object
))
4392 || (msec
= find_debug_info (debug_bfd
,
4393 debug_sections
, NULL
)) == NULL
4394 || !bfd_generic_link_read_symbols (debug_bfd
))
4397 bfd_close (debug_bfd
);
4398 /* FIXME: Should we report our failure to follow the debuglink ? */
4399 free (debug_filename
);
4403 symbols
= bfd_get_outsymbols (debug_bfd
);
4404 stash
->syms
= symbols
;
4405 stash
->close_on_cleanup
= TRUE
;
4407 stash
->bfd_ptr
= debug_bfd
;
4410 && !place_sections (abfd
, stash
))
4413 /* There can be more than one DWARF2 info section in a BFD these
4414 days. First handle the easy case when there's only one. If
4415 there's more than one, try case two: none of the sections is
4416 compressed. In that case, read them all in and produce one
4417 large stash. We do this in two passes - in the first pass we
4418 just accumulate the section sizes, and in the second pass we
4419 read in the section's contents. (The allows us to avoid
4420 reallocing the data as we add sections to the stash.) If
4421 some or all sections are compressed, then do things the slow
4422 way, with a bunch of reallocs. */
4424 if (! find_debug_info (debug_bfd
, debug_sections
, msec
))
4426 /* Case 1: only one info section. */
4427 total_size
= msec
->size
;
4428 if (! read_section (debug_bfd
, &stash
->debug_sections
[debug_info
],
4430 &stash
->info_ptr_memory
, &total_size
))
4435 /* Case 2: multiple sections. */
4436 for (total_size
= 0;
4438 msec
= find_debug_info (debug_bfd
, debug_sections
, msec
))
4439 total_size
+= msec
->size
;
4441 stash
->info_ptr_memory
= (bfd_byte
*) bfd_malloc (total_size
);
4442 if (stash
->info_ptr_memory
== NULL
)
4446 for (msec
= find_debug_info (debug_bfd
, debug_sections
, NULL
);
4448 msec
= find_debug_info (debug_bfd
, debug_sections
, msec
))
4456 if (!(bfd_simple_get_relocated_section_contents
4457 (debug_bfd
, msec
, stash
->info_ptr_memory
+ total_size
,
4465 stash
->info_ptr
= stash
->info_ptr_memory
;
4466 stash
->info_ptr_end
= stash
->info_ptr
+ total_size
;
4467 stash
->sec
= find_debug_info (debug_bfd
, debug_sections
, NULL
);
4468 stash
->sec_info_ptr
= stash
->info_ptr
;
4472 /* Parse the next DWARF2 compilation unit at STASH->INFO_PTR. */
4474 static struct comp_unit
*
4475 stash_comp_unit (struct dwarf2_debug
*stash
)
4477 bfd_size_type length
;
4478 unsigned int offset_size
;
4479 bfd_byte
*info_ptr_unit
= stash
->info_ptr
;
4481 if (stash
->info_ptr
>= stash
->info_ptr_end
)
4484 length
= read_4_bytes (stash
->bfd_ptr
, stash
->info_ptr
,
4485 stash
->info_ptr_end
);
4486 /* A 0xffffff length is the DWARF3 way of indicating
4487 we use 64-bit offsets, instead of 32-bit offsets. */
4488 if (length
== 0xffffffff)
4491 length
= read_8_bytes (stash
->bfd_ptr
, stash
->info_ptr
+ 4,
4492 stash
->info_ptr_end
);
4493 stash
->info_ptr
+= 12;
4495 /* A zero length is the IRIX way of indicating 64-bit offsets,
4496 mostly because the 64-bit length will generally fit in 32
4497 bits, and the endianness helps. */
4498 else if (length
== 0)
4501 length
= read_4_bytes (stash
->bfd_ptr
, stash
->info_ptr
+ 4,
4502 stash
->info_ptr_end
);
4503 stash
->info_ptr
+= 8;
4505 /* In the absence of the hints above, we assume 32-bit DWARF2
4506 offsets even for targets with 64-bit addresses, because:
4507 a) most of the time these targets will not have generated
4508 more than 2Gb of debug info and so will not need 64-bit
4511 b) if they do use 64-bit offsets but they are not using
4512 the size hints that are tested for above then they are
4513 not conforming to the DWARF3 standard anyway. */
4517 stash
->info_ptr
+= 4;
4521 && stash
->info_ptr
+ length
<= stash
->info_ptr_end
4522 && stash
->info_ptr
+ length
> stash
->info_ptr
)
4524 struct comp_unit
*each
= parse_comp_unit (stash
, length
, info_ptr_unit
,
4528 if (stash
->all_comp_units
)
4529 stash
->all_comp_units
->prev_unit
= each
;
4531 stash
->last_comp_unit
= each
;
4533 each
->next_unit
= stash
->all_comp_units
;
4534 stash
->all_comp_units
= each
;
4536 stash
->info_ptr
+= length
;
4538 if ((bfd_size_type
) (stash
->info_ptr
- stash
->sec_info_ptr
)
4539 == stash
->sec
->size
)
4541 stash
->sec
= find_debug_info (stash
->bfd_ptr
,
4542 stash
->debug_sections
,
4544 stash
->sec_info_ptr
= stash
->info_ptr
;
4550 /* Don't trust any of the DWARF info after a corrupted length or
4552 stash
->info_ptr
= stash
->info_ptr_end
;
4556 /* Hash function for an asymbol. */
4559 hash_asymbol (const void *sym
)
4561 const asymbol
*asym
= sym
;
4562 return htab_hash_string (asym
->name
);
4565 /* Equality function for asymbols. */
4568 eq_asymbol (const void *a
, const void *b
)
4570 const asymbol
*sa
= a
;
4571 const asymbol
*sb
= b
;
4572 return strcmp (sa
->name
, sb
->name
) == 0;
4575 /* Scan the debug information in PINFO looking for a DW_TAG_subprogram
4576 abbrev with a DW_AT_low_pc attached to it. Then lookup that same
4577 symbol in SYMBOLS and return the difference between the low_pc and
4578 the symbol's address. Returns 0 if no suitable symbol could be found. */
4581 _bfd_dwarf2_find_symbol_bias (asymbol
** symbols
, void ** pinfo
)
4583 struct dwarf2_debug
*stash
;
4584 struct comp_unit
* unit
;
4586 bfd_signed_vma result
= 0;
4589 stash
= (struct dwarf2_debug
*) *pinfo
;
4591 if (stash
== NULL
|| symbols
== NULL
)
4594 sym_hash
= htab_create_alloc (10, hash_asymbol
, eq_asymbol
,
4595 NULL
, xcalloc
, free
);
4596 for (psym
= symbols
; * psym
!= NULL
; psym
++)
4598 asymbol
* sym
= * psym
;
4600 if (sym
->flags
& BSF_FUNCTION
&& sym
->section
!= NULL
)
4602 void **slot
= htab_find_slot (sym_hash
, sym
, INSERT
);
4607 for (unit
= stash
->all_comp_units
; unit
; unit
= unit
->next_unit
)
4609 struct funcinfo
* func
;
4611 comp_unit_maybe_decode_line_info (unit
, stash
);
4613 for (func
= unit
->function_table
; func
!= NULL
; func
= func
->prev_func
)
4614 if (func
->name
&& func
->arange
.low
)
4616 asymbol search
, *sym
;
4618 /* FIXME: Do we need to scan the aranges looking for the lowest pc value ? */
4620 search
.name
= func
->name
;
4621 sym
= htab_find (sym_hash
, &search
);
4624 result
= ((bfd_signed_vma
) func
->arange
.low
) -
4625 ((bfd_signed_vma
) (sym
->value
+ sym
->section
->vma
));
4632 htab_delete (sym_hash
);
4636 /* Find the source code location of SYMBOL. If SYMBOL is NULL
4637 then find the nearest source code location corresponding to
4638 the address SECTION + OFFSET.
4639 Returns TRUE if the line is found without error and fills in
4640 FILENAME_PTR and LINENUMBER_PTR. In the case where SYMBOL was
4641 NULL the FUNCTIONNAME_PTR is also filled in.
4642 SYMBOLS contains the symbol table for ABFD.
4643 DEBUG_SECTIONS contains the name of the dwarf debug sections.
4644 field and in the abbreviation offset, or zero to indicate that the
4645 default value should be used. */
4648 _bfd_dwarf2_find_nearest_line (bfd
*abfd
,
4653 const char **filename_ptr
,
4654 const char **functionname_ptr
,
4655 unsigned int *linenumber_ptr
,
4656 unsigned int *discriminator_ptr
,
4657 const struct dwarf_debug_section
*debug_sections
,
4660 /* Read each compilation unit from the section .debug_info, and check
4661 to see if it contains the address we are searching for. If yes,
4662 lookup the address, and return the line number info. If no, go
4663 on to the next compilation unit.
4665 We keep a list of all the previously read compilation units, and
4666 a pointer to the next un-read compilation unit. Check the
4667 previously read units before reading more. */
4668 struct dwarf2_debug
*stash
;
4669 /* What address are we looking for? */
4671 struct comp_unit
* each
;
4672 struct funcinfo
*function
= NULL
;
4673 bfd_boolean found
= FALSE
;
4674 bfd_boolean do_line
;
4676 *filename_ptr
= NULL
;
4677 if (functionname_ptr
!= NULL
)
4678 *functionname_ptr
= NULL
;
4679 *linenumber_ptr
= 0;
4680 if (discriminator_ptr
)
4681 *discriminator_ptr
= 0;
4683 if (! _bfd_dwarf2_slurp_debug_info (abfd
, NULL
, debug_sections
,
4685 (abfd
->flags
& (EXEC_P
| DYNAMIC
)) == 0))
4688 stash
= (struct dwarf2_debug
*) *pinfo
;
4690 do_line
= symbol
!= NULL
;
4693 BFD_ASSERT (section
== NULL
&& offset
== 0 && functionname_ptr
== NULL
);
4694 section
= bfd_get_section (symbol
);
4695 addr
= symbol
->value
;
4699 BFD_ASSERT (section
!= NULL
&& functionname_ptr
!= NULL
);
4702 /* If we have no SYMBOL but the section we're looking at is not a
4703 code section, then take a look through the list of symbols to see
4704 if we have a symbol at the address we're looking for. If we do
4705 then use this to look up line information. This will allow us to
4706 give file and line results for data symbols. We exclude code
4707 symbols here, if we look up a function symbol and then look up the
4708 line information we'll actually return the line number for the
4709 opening '{' rather than the function definition line. This is
4710 because looking up by symbol uses the line table, in which the
4711 first line for a function is usually the opening '{', while
4712 looking up the function by section + offset uses the
4713 DW_AT_decl_line from the function DW_TAG_subprogram for the line,
4714 which will be the line of the function name. */
4715 if (symbols
!= NULL
&& (section
->flags
& SEC_CODE
) == 0)
4719 for (tmp
= symbols
; (*tmp
) != NULL
; ++tmp
)
4720 if ((*tmp
)->the_bfd
== abfd
4721 && (*tmp
)->section
== section
4722 && (*tmp
)->value
== offset
4723 && ((*tmp
)->flags
& BSF_SECTION_SYM
) == 0)
4727 /* For local symbols, keep going in the hope we find a
4729 if ((symbol
->flags
& BSF_GLOBAL
) != 0)
4735 if (section
->output_section
)
4736 addr
+= section
->output_section
->vma
+ section
->output_offset
;
4738 addr
+= section
->vma
;
4740 /* A null info_ptr indicates that there is no dwarf2 info
4741 (or that an error occured while setting up the stash). */
4742 if (! stash
->info_ptr
)
4745 stash
->inliner_chain
= NULL
;
4747 /* Check the previously read comp. units first. */
4750 /* The info hash tables use quite a bit of memory. We may not want to
4751 always use them. We use some heuristics to decide if and when to
4753 if (stash
->info_hash_status
== STASH_INFO_HASH_OFF
)
4754 stash_maybe_enable_info_hash_tables (abfd
, stash
);
4756 /* Keep info hash table up to date if they are available. Note that we
4757 may disable the hash tables if there is any error duing update. */
4758 if (stash
->info_hash_status
== STASH_INFO_HASH_ON
)
4759 stash_maybe_update_info_hash_tables (stash
);
4761 if (stash
->info_hash_status
== STASH_INFO_HASH_ON
)
4763 found
= stash_find_line_fast (stash
, symbol
, addr
, filename_ptr
,
4770 /* Check the previously read comp. units first. */
4771 for (each
= stash
->all_comp_units
; each
; each
= each
->next_unit
)
4772 if ((symbol
->flags
& BSF_FUNCTION
) == 0
4773 || each
->arange
.high
== 0
4774 || comp_unit_contains_address (each
, addr
))
4776 found
= comp_unit_find_line (each
, symbol
, addr
, filename_ptr
,
4777 linenumber_ptr
, stash
);
4785 bfd_vma min_range
= (bfd_vma
) -1;
4786 const char * local_filename
= NULL
;
4787 struct funcinfo
*local_function
= NULL
;
4788 unsigned int local_linenumber
= 0;
4789 unsigned int local_discriminator
= 0;
4791 for (each
= stash
->all_comp_units
; each
; each
= each
->next_unit
)
4793 bfd_vma range
= (bfd_vma
) -1;
4795 found
= ((each
->arange
.high
== 0
4796 || comp_unit_contains_address (each
, addr
))
4797 && (range
= comp_unit_find_nearest_line (each
, addr
,
4801 & local_discriminator
,
4805 /* PRs 15935 15994: Bogus debug information may have provided us
4806 with an erroneous match. We attempt to counter this by
4807 selecting the match that has the smallest address range
4808 associated with it. (We are assuming that corrupt debug info
4809 will tend to result in extra large address ranges rather than
4810 extra small ranges).
4812 This does mean that we scan through all of the CUs associated
4813 with the bfd each time this function is called. But this does
4814 have the benefit of producing consistent results every time the
4815 function is called. */
4816 if (range
<= min_range
)
4818 if (filename_ptr
&& local_filename
)
4819 * filename_ptr
= local_filename
;
4821 function
= local_function
;
4822 if (discriminator_ptr
&& local_discriminator
)
4823 * discriminator_ptr
= local_discriminator
;
4824 if (local_linenumber
)
4825 * linenumber_ptr
= local_linenumber
;
4831 if (* linenumber_ptr
)
4838 /* Read each remaining comp. units checking each as they are read. */
4839 while ((each
= stash_comp_unit (stash
)) != NULL
)
4841 /* DW_AT_low_pc and DW_AT_high_pc are optional for
4842 compilation units. If we don't have them (i.e.,
4843 unit->high == 0), we need to consult the line info table
4844 to see if a compilation unit contains the given
4847 found
= (((symbol
->flags
& BSF_FUNCTION
) == 0
4848 || each
->arange
.high
== 0
4849 || comp_unit_contains_address (each
, addr
))
4850 && comp_unit_find_line (each
, symbol
, addr
,
4855 found
= ((each
->arange
.high
== 0
4856 || comp_unit_contains_address (each
, addr
))
4857 && comp_unit_find_nearest_line (each
, addr
,
4871 if (!function
->is_linkage
)
4876 fun
= _bfd_elf_find_function (abfd
, symbols
, section
, offset
,
4877 *filename_ptr
? NULL
: filename_ptr
,
4879 sec_vma
= section
->vma
;
4880 if (section
->output_section
!= NULL
)
4881 sec_vma
= section
->output_section
->vma
+ section
->output_offset
;
4883 && fun
->value
+ sec_vma
== function
->arange
.low
)
4884 function
->name
= *functionname_ptr
;
4885 /* Even if we didn't find a linkage name, say that we have
4886 to stop a repeated search of symbols. */
4887 function
->is_linkage
= TRUE
;
4889 *functionname_ptr
= function
->name
;
4891 if ((abfd
->flags
& (EXEC_P
| DYNAMIC
)) == 0)
4892 unset_sections (stash
);
4898 _bfd_dwarf2_find_inliner_info (bfd
*abfd ATTRIBUTE_UNUSED
,
4899 const char **filename_ptr
,
4900 const char **functionname_ptr
,
4901 unsigned int *linenumber_ptr
,
4904 struct dwarf2_debug
*stash
;
4906 stash
= (struct dwarf2_debug
*) *pinfo
;
4909 struct funcinfo
*func
= stash
->inliner_chain
;
4911 if (func
&& func
->caller_func
)
4913 *filename_ptr
= func
->caller_file
;
4914 *functionname_ptr
= func
->caller_func
->name
;
4915 *linenumber_ptr
= func
->caller_line
;
4916 stash
->inliner_chain
= func
->caller_func
;
4925 _bfd_dwarf2_cleanup_debug_info (bfd
*abfd
, void **pinfo
)
4927 struct dwarf2_debug
*stash
= (struct dwarf2_debug
*) *pinfo
;
4928 struct comp_unit
*each
;
4930 if (abfd
== NULL
|| stash
== NULL
)
4933 for (each
= stash
->all_comp_units
; each
; each
= each
->next_unit
)
4935 struct abbrev_info
**abbrevs
= each
->abbrevs
;
4936 struct funcinfo
*function_table
= each
->function_table
;
4937 struct varinfo
*variable_table
= each
->variable_table
;
4940 for (i
= 0; i
< ABBREV_HASH_SIZE
; i
++)
4942 struct abbrev_info
*abbrev
= abbrevs
[i
];
4946 free (abbrev
->attrs
);
4947 abbrev
= abbrev
->next
;
4951 if (each
->line_table
)
4953 free (each
->line_table
->dirs
);
4954 free (each
->line_table
->files
);
4957 while (function_table
)
4959 if (function_table
->file
)
4961 free (function_table
->file
);
4962 function_table
->file
= NULL
;
4965 if (function_table
->caller_file
)
4967 free (function_table
->caller_file
);
4968 function_table
->caller_file
= NULL
;
4970 function_table
= function_table
->prev_func
;
4973 if (each
->lookup_funcinfo_table
)
4975 free (each
->lookup_funcinfo_table
);
4976 each
->lookup_funcinfo_table
= NULL
;
4979 while (variable_table
)
4981 if (variable_table
->file
)
4983 free (variable_table
->file
);
4984 variable_table
->file
= NULL
;
4987 variable_table
= variable_table
->prev_var
;
4991 if (stash
->funcinfo_hash_table
)
4992 bfd_hash_table_free (&stash
->funcinfo_hash_table
->base
);
4993 if (stash
->varinfo_hash_table
)
4994 bfd_hash_table_free (&stash
->varinfo_hash_table
->base
);
4995 if (stash
->dwarf_abbrev_buffer
)
4996 free (stash
->dwarf_abbrev_buffer
);
4997 if (stash
->dwarf_line_buffer
)
4998 free (stash
->dwarf_line_buffer
);
4999 if (stash
->dwarf_str_buffer
)
5000 free (stash
->dwarf_str_buffer
);
5001 if (stash
->dwarf_line_str_buffer
)
5002 free (stash
->dwarf_line_str_buffer
);
5003 if (stash
->dwarf_ranges_buffer
)
5004 free (stash
->dwarf_ranges_buffer
);
5005 if (stash
->info_ptr_memory
)
5006 free (stash
->info_ptr_memory
);
5007 if (stash
->close_on_cleanup
)
5008 bfd_close (stash
->bfd_ptr
);
5009 if (stash
->alt_dwarf_str_buffer
)
5010 free (stash
->alt_dwarf_str_buffer
);
5011 if (stash
->alt_dwarf_info_buffer
)
5012 free (stash
->alt_dwarf_info_buffer
);
5014 free (stash
->sec_vma
);
5015 if (stash
->adjusted_sections
)
5016 free (stash
->adjusted_sections
);
5017 if (stash
->alt_bfd_ptr
)
5018 bfd_close (stash
->alt_bfd_ptr
);
5021 /* Find the function to a particular section and offset,
5022 for error reporting. */
5025 _bfd_elf_find_function (bfd
*abfd
,
5029 const char **filename_ptr
,
5030 const char **functionname_ptr
)
5032 struct elf_find_function_cache
5034 asection
*last_section
;
5036 const char *filename
;
5037 bfd_size_type func_size
;
5040 if (symbols
== NULL
)
5043 if (bfd_get_flavour (abfd
) != bfd_target_elf_flavour
)
5046 cache
= elf_tdata (abfd
)->elf_find_function_cache
;
5049 cache
= bfd_zalloc (abfd
, sizeof (*cache
));
5050 elf_tdata (abfd
)->elf_find_function_cache
= cache
;
5054 if (cache
->last_section
!= section
5055 || cache
->func
== NULL
5056 || offset
< cache
->func
->value
5057 || offset
>= cache
->func
->value
+ cache
->func_size
)
5062 /* ??? Given multiple file symbols, it is impossible to reliably
5063 choose the right file name for global symbols. File symbols are
5064 local symbols, and thus all file symbols must sort before any
5065 global symbols. The ELF spec may be interpreted to say that a
5066 file symbol must sort before other local symbols, but currently
5067 ld -r doesn't do this. So, for ld -r output, it is possible to
5068 make a better choice of file name for local symbols by ignoring
5069 file symbols appearing after a given local symbol. */
5070 enum { nothing_seen
, symbol_seen
, file_after_symbol_seen
} state
;
5071 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
5075 state
= nothing_seen
;
5076 cache
->filename
= NULL
;
5078 cache
->func_size
= 0;
5079 cache
->last_section
= section
;
5081 for (p
= symbols
; *p
!= NULL
; p
++)
5087 if ((sym
->flags
& BSF_FILE
) != 0)
5090 if (state
== symbol_seen
)
5091 state
= file_after_symbol_seen
;
5095 size
= bed
->maybe_function_sym (sym
, section
, &code_off
);
5097 && code_off
<= offset
5098 && (code_off
> low_func
5099 || (code_off
== low_func
5100 && size
> cache
->func_size
)))
5103 cache
->func_size
= size
;
5104 cache
->filename
= NULL
;
5105 low_func
= code_off
;
5107 && ((sym
->flags
& BSF_LOCAL
) != 0
5108 || state
!= file_after_symbol_seen
))
5109 cache
->filename
= bfd_asymbol_name (file
);
5111 if (state
== nothing_seen
)
5112 state
= symbol_seen
;
5116 if (cache
->func
== NULL
)
5120 *filename_ptr
= cache
->filename
;
5121 if (functionname_ptr
)
5122 *functionname_ptr
= bfd_asymbol_name (cache
->func
);