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
85 struct dwarf2_debug_file
87 /* The actual bfd from which debug info was loaded. Might be
88 different to orig_bfd because of gnu_debuglink sections. */
91 /* Pointer to the symbol table. */
94 /* The current info pointer for the .debug_info section being parsed. */
97 /* A pointer to the memory block allocated for .debug_info sections. */
98 bfd_byte
*dwarf_info_buffer
;
100 /* Length of the loaded .debug_info sections. */
101 bfd_size_type dwarf_info_size
;
103 /* Pointer to the .debug_abbrev section loaded into memory. */
104 bfd_byte
*dwarf_abbrev_buffer
;
106 /* Length of the loaded .debug_abbrev section. */
107 bfd_size_type dwarf_abbrev_size
;
109 /* Buffer for decode_line_info. */
110 bfd_byte
*dwarf_line_buffer
;
112 /* Length of the loaded .debug_line section. */
113 bfd_size_type dwarf_line_size
;
115 /* Pointer to the .debug_str section loaded into memory. */
116 bfd_byte
*dwarf_str_buffer
;
118 /* Length of the loaded .debug_str section. */
119 bfd_size_type dwarf_str_size
;
121 /* Pointer to the .debug_line_str section loaded into memory. */
122 bfd_byte
*dwarf_line_str_buffer
;
124 /* Length of the loaded .debug_line_str section. */
125 bfd_size_type dwarf_line_str_size
;
127 /* Pointer to the .debug_ranges section loaded into memory. */
128 bfd_byte
*dwarf_ranges_buffer
;
130 /* Length of the loaded .debug_ranges section. */
131 bfd_size_type dwarf_ranges_size
;
133 /* A list of all previously read comp_units. */
134 struct comp_unit
*all_comp_units
;
136 /* Last comp unit in list above. */
137 struct comp_unit
*last_comp_unit
;
142 /* Names of the debug sections. */
143 const struct dwarf_debug_section
*debug_sections
;
145 /* Per-file stuff. */
146 struct dwarf2_debug_file f
, alt
;
148 /* Pointer to the original bfd for which debug was loaded. This is what
149 we use to compare and so check that the cached debug data is still
150 valid - it saves having to possibly dereference the gnu_debuglink each
154 /* If the most recent call to bfd_find_nearest_line was given an
155 address in an inlined function, preserve a pointer into the
156 calling chain for subsequent calls to bfd_find_inliner_info to
158 struct funcinfo
*inliner_chain
;
160 /* Section VMAs at the time the stash was built. */
162 /* Number of sections in the SEC_VMA table. */
163 unsigned int sec_vma_count
;
165 /* Number of sections whose VMA we must adjust. */
166 int adjusted_section_count
;
168 /* Array of sections with adjusted VMA. */
169 struct adjusted_section
*adjusted_sections
;
171 /* Number of times find_line is called. This is used in
172 the heuristic for enabling the info hash tables. */
175 #define STASH_INFO_HASH_TRIGGER 100
177 /* Hash table mapping symbol names to function infos. */
178 struct info_hash_table
*funcinfo_hash_table
;
180 /* Hash table mapping symbol names to variable infos. */
181 struct info_hash_table
*varinfo_hash_table
;
183 /* Head of comp_unit list in the last hash table update. */
184 struct comp_unit
*hash_units_head
;
186 /* Status of info hash. */
187 int info_hash_status
;
188 #define STASH_INFO_HASH_OFF 0
189 #define STASH_INFO_HASH_ON 1
190 #define STASH_INFO_HASH_DISABLED 2
192 /* True if we opened bfd_ptr. */
193 bfd_boolean close_on_cleanup
;
203 /* A minimal decoding of DWARF2 compilation units. We only decode
204 what's needed to get to the line number information. */
208 /* Chain the previously read compilation units. */
209 struct comp_unit
*next_unit
;
211 /* Likewise, chain the compilation unit read after this one.
212 The comp units are stored in reversed reading order. */
213 struct comp_unit
*prev_unit
;
215 /* Keep the bfd convenient (for memory allocation). */
218 /* The lowest and highest addresses contained in this compilation
219 unit as specified in the compilation unit header. */
220 struct arange arange
;
222 /* The DW_AT_name attribute (for error messages). */
225 /* The abbrev hash table. */
226 struct abbrev_info
**abbrevs
;
228 /* DW_AT_language. */
231 /* Note that an error was found by comp_unit_find_nearest_line. */
234 /* The DW_AT_comp_dir attribute. */
237 /* TRUE if there is a line number table associated with this comp. unit. */
240 /* Pointer to the current comp_unit so that we can find a given entry
242 bfd_byte
*info_ptr_unit
;
244 /* The offset into .debug_line of the line number table. */
245 unsigned long line_offset
;
247 /* Pointer to the first child die for the comp unit. */
248 bfd_byte
*first_child_die_ptr
;
250 /* The end of the comp unit. */
253 /* The decoded line number, NULL if not yet decoded. */
254 struct line_info_table
*line_table
;
256 /* A list of the functions found in this comp. unit. */
257 struct funcinfo
*function_table
;
259 /* A table of function information references searchable by address. */
260 struct lookup_funcinfo
*lookup_funcinfo_table
;
262 /* Number of functions in the function_table and sorted_function_table. */
263 bfd_size_type number_of_functions
;
265 /* A list of the variables found in this comp. unit. */
266 struct varinfo
*variable_table
;
268 /* Pointers to dwarf2_debug structures. */
269 struct dwarf2_debug
*stash
;
270 struct dwarf2_debug_file
*file
;
272 /* DWARF format version for this unit - from unit header. */
275 /* Address size for this unit - from unit header. */
276 unsigned char addr_size
;
278 /* Offset size for this unit - from unit header. */
279 unsigned char offset_size
;
281 /* Base address for this unit - from DW_AT_low_pc attribute of
282 DW_TAG_compile_unit DIE */
283 bfd_vma base_address
;
285 /* TRUE if symbols are cached in hash table for faster lookup by name. */
289 /* This data structure holds the information of an abbrev. */
292 unsigned int number
; /* Number identifying abbrev. */
293 enum dwarf_tag tag
; /* DWARF tag. */
294 int has_children
; /* Boolean. */
295 unsigned int num_attrs
; /* Number of attributes. */
296 struct attr_abbrev
*attrs
; /* An array of attribute descriptions. */
297 struct abbrev_info
*next
; /* Next in chain. */
302 enum dwarf_attribute name
;
303 enum dwarf_form form
;
304 bfd_vma implicit_const
;
307 /* Map of uncompressed DWARF debug section name to compressed one. It
308 is terminated by NULL uncompressed_name. */
310 const struct dwarf_debug_section dwarf_debug_sections
[] =
312 { ".debug_abbrev", ".zdebug_abbrev" },
313 { ".debug_aranges", ".zdebug_aranges" },
314 { ".debug_frame", ".zdebug_frame" },
315 { ".debug_info", ".zdebug_info" },
316 { ".debug_info", ".zdebug_info" },
317 { ".debug_line", ".zdebug_line" },
318 { ".debug_loc", ".zdebug_loc" },
319 { ".debug_macinfo", ".zdebug_macinfo" },
320 { ".debug_macro", ".zdebug_macro" },
321 { ".debug_pubnames", ".zdebug_pubnames" },
322 { ".debug_pubtypes", ".zdebug_pubtypes" },
323 { ".debug_ranges", ".zdebug_ranges" },
324 { ".debug_static_func", ".zdebug_static_func" },
325 { ".debug_static_vars", ".zdebug_static_vars" },
326 { ".debug_str", ".zdebug_str", },
327 { ".debug_str", ".zdebug_str", },
328 { ".debug_line_str", ".zdebug_line_str", },
329 { ".debug_types", ".zdebug_types" },
330 /* GNU DWARF 1 extensions */
331 { ".debug_sfnames", ".zdebug_sfnames" },
332 { ".debug_srcinfo", ".zebug_srcinfo" },
333 /* SGI/MIPS DWARF 2 extensions */
334 { ".debug_funcnames", ".zdebug_funcnames" },
335 { ".debug_typenames", ".zdebug_typenames" },
336 { ".debug_varnames", ".zdebug_varnames" },
337 { ".debug_weaknames", ".zdebug_weaknames" },
341 /* NB/ Numbers in this enum must match up with indices
342 into the dwarf_debug_sections[] array above. */
343 enum dwarf_debug_section_enum
372 /* A static assertion. */
373 extern int dwarf_debug_section_assert
[ARRAY_SIZE (dwarf_debug_sections
)
374 == debug_max
+ 1 ? 1 : -1];
376 #ifndef ABBREV_HASH_SIZE
377 #define ABBREV_HASH_SIZE 121
379 #ifndef ATTR_ALLOC_CHUNK
380 #define ATTR_ALLOC_CHUNK 4
383 /* Variable and function hash tables. This is used to speed up look-up
384 in lookup_symbol_in_var_table() and lookup_symbol_in_function_table().
385 In order to share code between variable and function infos, we use
386 a list of untyped pointer for all variable/function info associated with
387 a symbol. We waste a bit of memory for list with one node but that
388 simplifies the code. */
390 struct info_list_node
392 struct info_list_node
*next
;
396 /* Info hash entry. */
397 struct info_hash_entry
399 struct bfd_hash_entry root
;
400 struct info_list_node
*head
;
403 struct info_hash_table
405 struct bfd_hash_table base
;
408 /* Function to create a new entry in info hash table. */
410 static struct bfd_hash_entry
*
411 info_hash_table_newfunc (struct bfd_hash_entry
*entry
,
412 struct bfd_hash_table
*table
,
415 struct info_hash_entry
*ret
= (struct info_hash_entry
*) entry
;
417 /* Allocate the structure if it has not already been allocated by a
421 ret
= (struct info_hash_entry
*) bfd_hash_allocate (table
,
427 /* Call the allocation method of the base class. */
428 ret
= ((struct info_hash_entry
*)
429 bfd_hash_newfunc ((struct bfd_hash_entry
*) ret
, table
, string
));
431 /* Initialize the local fields here. */
435 return (struct bfd_hash_entry
*) ret
;
438 /* Function to create a new info hash table. It returns a pointer to the
439 newly created table or NULL if there is any error. We need abfd
440 solely for memory allocation. */
442 static struct info_hash_table
*
443 create_info_hash_table (bfd
*abfd
)
445 struct info_hash_table
*hash_table
;
447 hash_table
= ((struct info_hash_table
*)
448 bfd_alloc (abfd
, sizeof (struct info_hash_table
)));
452 if (!bfd_hash_table_init (&hash_table
->base
, info_hash_table_newfunc
,
453 sizeof (struct info_hash_entry
)))
455 bfd_release (abfd
, hash_table
);
462 /* Insert an info entry into an info hash table. We do not check of
463 duplicate entries. Also, the caller need to guarantee that the
464 right type of info in inserted as info is passed as a void* pointer.
465 This function returns true if there is no error. */
468 insert_info_hash_table (struct info_hash_table
*hash_table
,
473 struct info_hash_entry
*entry
;
474 struct info_list_node
*node
;
476 entry
= (struct info_hash_entry
*) bfd_hash_lookup (&hash_table
->base
,
481 node
= (struct info_list_node
*) bfd_hash_allocate (&hash_table
->base
,
487 node
->next
= entry
->head
;
493 /* Look up an info entry list from an info hash table. Return NULL
496 static struct info_list_node
*
497 lookup_info_hash_table (struct info_hash_table
*hash_table
, const char *key
)
499 struct info_hash_entry
*entry
;
501 entry
= (struct info_hash_entry
*) bfd_hash_lookup (&hash_table
->base
, key
,
503 return entry
? entry
->head
: NULL
;
506 /* Read a section into its appropriate place in the dwarf2_debug
507 struct (indicated by SECTION_BUFFER and SECTION_SIZE). If SYMS is
508 not NULL, use bfd_simple_get_relocated_section_contents to read the
509 section contents, otherwise use bfd_get_section_contents. Fail if
510 the located section does not contain at least OFFSET bytes. */
513 read_section (bfd
* abfd
,
514 const struct dwarf_debug_section
*sec
,
517 bfd_byte
** section_buffer
,
518 bfd_size_type
* section_size
)
521 const char *section_name
= sec
->uncompressed_name
;
522 bfd_byte
*contents
= *section_buffer
;
525 /* The section may have already been read. */
526 if (contents
== NULL
)
528 msec
= bfd_get_section_by_name (abfd
, section_name
);
531 section_name
= sec
->compressed_name
;
532 if (section_name
!= NULL
)
533 msec
= bfd_get_section_by_name (abfd
, section_name
);
537 _bfd_error_handler (_("DWARF error: can't find %s section."),
538 sec
->uncompressed_name
);
539 bfd_set_error (bfd_error_bad_value
);
543 *section_size
= msec
->rawsize
? msec
->rawsize
: msec
->size
;
544 /* Paranoia - alloc one extra so that we can make sure a string
545 section is NUL terminated. */
546 amt
= *section_size
+ 1;
549 bfd_set_error (bfd_error_no_memory
);
552 contents
= (bfd_byte
*) bfd_malloc (amt
);
553 if (contents
== NULL
)
556 ? !bfd_simple_get_relocated_section_contents (abfd
, msec
, contents
,
558 : !bfd_get_section_contents (abfd
, msec
, contents
, 0, *section_size
))
563 contents
[*section_size
] = 0;
564 *section_buffer
= contents
;
567 /* It is possible to get a bad value for the offset into the section
568 that the client wants. Validate it here to avoid trouble later. */
569 if (offset
!= 0 && offset
>= *section_size
)
571 /* xgettext: c-format */
572 _bfd_error_handler (_("DWARF error: offset (%" PRIu64
")"
573 " greater than or equal to %s size (%" PRIu64
")"),
574 (uint64_t) offset
, section_name
,
575 (uint64_t) *section_size
);
576 bfd_set_error (bfd_error_bad_value
);
583 /* Read dwarf information from a buffer. */
586 read_1_byte (bfd
*abfd ATTRIBUTE_UNUSED
, bfd_byte
*buf
, bfd_byte
*end
)
590 return bfd_get_8 (abfd
, buf
);
594 read_1_signed_byte (bfd
*abfd ATTRIBUTE_UNUSED
, bfd_byte
*buf
, bfd_byte
*end
)
598 return bfd_get_signed_8 (abfd
, buf
);
602 read_2_bytes (bfd
*abfd
, bfd_byte
*buf
, bfd_byte
*end
)
606 return bfd_get_16 (abfd
, buf
);
610 read_4_bytes (bfd
*abfd
, bfd_byte
*buf
, bfd_byte
*end
)
614 return bfd_get_32 (abfd
, buf
);
618 read_8_bytes (bfd
*abfd
, bfd_byte
*buf
, bfd_byte
*end
)
622 return bfd_get_64 (abfd
, buf
);
626 read_n_bytes (bfd_byte
* buf
,
628 struct dwarf_block
* block
)
630 unsigned int size
= block
->size
;
631 bfd_byte
* block_end
= buf
+ size
;
633 if (block_end
> end
|| block_end
< buf
)
646 /* Scans a NUL terminated string starting at BUF, returning a pointer to it.
647 Returns the number of characters in the string, *including* the NUL byte,
648 in BYTES_READ_PTR. This value is set even if the function fails. Bytes
649 at or beyond BUF_END will not be read. Returns NULL if there was a
650 problem, or if the string is empty. */
653 read_string (bfd
* abfd ATTRIBUTE_UNUSED
,
656 unsigned int * bytes_read_ptr
)
662 * bytes_read_ptr
= 0;
668 * bytes_read_ptr
= 1;
672 while (buf
< buf_end
)
675 * bytes_read_ptr
= buf
- str
;
679 * bytes_read_ptr
= buf
- str
;
683 /* Reads an offset from BUF and then locates the string at this offset
684 inside the debug string section. Returns a pointer to the string.
685 Returns the number of bytes read from BUF, *not* the length of the string,
686 in BYTES_READ_PTR. This value is set even if the function fails. Bytes
687 at or beyond BUF_END will not be read from BUF. Returns NULL if there was
688 a problem, or if the string is empty. Does not check for NUL termination
692 read_indirect_string (struct comp_unit
* unit
,
695 unsigned int * bytes_read_ptr
)
698 struct dwarf2_debug
*stash
= unit
->stash
;
699 struct dwarf2_debug_file
*file
= unit
->file
;
702 if (buf
+ unit
->offset_size
> buf_end
)
704 * bytes_read_ptr
= 0;
708 if (unit
->offset_size
== 4)
709 offset
= read_4_bytes (unit
->abfd
, buf
, buf_end
);
711 offset
= read_8_bytes (unit
->abfd
, buf
, buf_end
);
713 *bytes_read_ptr
= unit
->offset_size
;
715 if (! read_section (unit
->abfd
, &stash
->debug_sections
[debug_str
],
717 &file
->dwarf_str_buffer
, &file
->dwarf_str_size
))
720 str
= (char *) file
->dwarf_str_buffer
+ offset
;
726 /* Like read_indirect_string but from .debug_line_str section. */
729 read_indirect_line_string (struct comp_unit
* unit
,
732 unsigned int * bytes_read_ptr
)
735 struct dwarf2_debug
*stash
= unit
->stash
;
736 struct dwarf2_debug_file
*file
= unit
->file
;
739 if (buf
+ unit
->offset_size
> buf_end
)
741 * bytes_read_ptr
= 0;
745 if (unit
->offset_size
== 4)
746 offset
= read_4_bytes (unit
->abfd
, buf
, buf_end
);
748 offset
= read_8_bytes (unit
->abfd
, buf
, buf_end
);
750 *bytes_read_ptr
= unit
->offset_size
;
752 if (! read_section (unit
->abfd
, &stash
->debug_sections
[debug_line_str
],
754 &file
->dwarf_line_str_buffer
,
755 &file
->dwarf_line_str_size
))
758 str
= (char *) file
->dwarf_line_str_buffer
+ offset
;
764 /* Like read_indirect_string but uses a .debug_str located in
765 an alternate file pointed to by the .gnu_debugaltlink section.
766 Used to impement DW_FORM_GNU_strp_alt. */
769 read_alt_indirect_string (struct comp_unit
* unit
,
772 unsigned int * bytes_read_ptr
)
775 struct dwarf2_debug
*stash
= unit
->stash
;
778 if (buf
+ unit
->offset_size
> buf_end
)
780 * bytes_read_ptr
= 0;
784 if (unit
->offset_size
== 4)
785 offset
= read_4_bytes (unit
->abfd
, buf
, buf_end
);
787 offset
= read_8_bytes (unit
->abfd
, buf
, buf_end
);
789 *bytes_read_ptr
= unit
->offset_size
;
791 if (stash
->alt
.bfd_ptr
== NULL
)
794 char *debug_filename
= bfd_follow_gnu_debugaltlink (unit
->abfd
, DEBUGDIR
);
796 if (debug_filename
== NULL
)
799 debug_bfd
= bfd_openr (debug_filename
, NULL
);
800 free (debug_filename
);
801 if (debug_bfd
== NULL
)
802 /* FIXME: Should we report our failure to follow the debuglink ? */
805 if (!bfd_check_format (debug_bfd
, bfd_object
))
807 bfd_close (debug_bfd
);
810 stash
->alt
.bfd_ptr
= debug_bfd
;
813 if (! read_section (unit
->stash
->alt
.bfd_ptr
,
814 stash
->debug_sections
+ debug_str_alt
,
815 stash
->alt
.syms
, offset
,
816 &stash
->alt
.dwarf_str_buffer
,
817 &stash
->alt
.dwarf_str_size
))
820 str
= (char *) stash
->alt
.dwarf_str_buffer
+ offset
;
827 /* Resolve an alternate reference from UNIT at OFFSET.
828 Returns a pointer into the loaded alternate CU upon success
829 or NULL upon failure. */
832 read_alt_indirect_ref (struct comp_unit
* unit
,
835 struct dwarf2_debug
*stash
= unit
->stash
;
837 if (stash
->alt
.bfd_ptr
== NULL
)
840 char *debug_filename
= bfd_follow_gnu_debugaltlink (unit
->abfd
, DEBUGDIR
);
842 if (debug_filename
== NULL
)
845 debug_bfd
= bfd_openr (debug_filename
, NULL
);
846 free (debug_filename
);
847 if (debug_bfd
== NULL
)
848 /* FIXME: Should we report our failure to follow the debuglink ? */
851 if (!bfd_check_format (debug_bfd
, bfd_object
))
853 bfd_close (debug_bfd
);
856 stash
->alt
.bfd_ptr
= debug_bfd
;
859 if (! read_section (unit
->stash
->alt
.bfd_ptr
,
860 stash
->debug_sections
+ debug_info_alt
,
861 stash
->alt
.syms
, offset
,
862 &stash
->alt
.dwarf_info_buffer
,
863 &stash
->alt
.dwarf_info_size
))
866 return stash
->alt
.dwarf_info_buffer
+ offset
;
870 read_address (struct comp_unit
*unit
, bfd_byte
*buf
, bfd_byte
* buf_end
)
874 if (bfd_get_flavour (unit
->abfd
) == bfd_target_elf_flavour
)
875 signed_vma
= get_elf_backend_data (unit
->abfd
)->sign_extend_vma
;
877 if (buf
+ unit
->addr_size
> buf_end
)
882 switch (unit
->addr_size
)
885 return bfd_get_signed_64 (unit
->abfd
, buf
);
887 return bfd_get_signed_32 (unit
->abfd
, buf
);
889 return bfd_get_signed_16 (unit
->abfd
, buf
);
896 switch (unit
->addr_size
)
899 return bfd_get_64 (unit
->abfd
, buf
);
901 return bfd_get_32 (unit
->abfd
, buf
);
903 return bfd_get_16 (unit
->abfd
, buf
);
910 /* Lookup an abbrev_info structure in the abbrev hash table. */
912 static struct abbrev_info
*
913 lookup_abbrev (unsigned int number
, struct abbrev_info
**abbrevs
)
915 unsigned int hash_number
;
916 struct abbrev_info
*abbrev
;
918 hash_number
= number
% ABBREV_HASH_SIZE
;
919 abbrev
= abbrevs
[hash_number
];
923 if (abbrev
->number
== number
)
926 abbrev
= abbrev
->next
;
932 /* In DWARF version 2, the description of the debugging information is
933 stored in a separate .debug_abbrev section. Before we read any
934 dies from a section we read in all abbreviations and install them
937 static struct abbrev_info
**
938 read_abbrevs (bfd
*abfd
, bfd_uint64_t offset
, struct dwarf2_debug
*stash
,
939 struct dwarf2_debug_file
*file
)
941 struct abbrev_info
**abbrevs
;
942 bfd_byte
*abbrev_ptr
;
943 bfd_byte
*abbrev_end
;
944 struct abbrev_info
*cur_abbrev
;
945 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
946 unsigned int abbrev_form
, hash_number
;
949 if (! read_section (abfd
, &stash
->debug_sections
[debug_abbrev
],
951 &file
->dwarf_abbrev_buffer
,
952 &file
->dwarf_abbrev_size
))
955 amt
= sizeof (struct abbrev_info
*) * ABBREV_HASH_SIZE
;
956 abbrevs
= (struct abbrev_info
**) bfd_zalloc (abfd
, amt
);
960 abbrev_ptr
= file
->dwarf_abbrev_buffer
+ offset
;
961 abbrev_end
= file
->dwarf_abbrev_buffer
+ file
->dwarf_abbrev_size
;
962 abbrev_number
= _bfd_safe_read_leb128 (abfd
, abbrev_ptr
, &bytes_read
,
964 abbrev_ptr
+= bytes_read
;
966 /* Loop until we reach an abbrev number of 0. */
967 while (abbrev_number
)
969 amt
= sizeof (struct abbrev_info
);
970 cur_abbrev
= (struct abbrev_info
*) bfd_zalloc (abfd
, amt
);
971 if (cur_abbrev
== NULL
)
974 /* Read in abbrev header. */
975 cur_abbrev
->number
= abbrev_number
;
976 cur_abbrev
->tag
= (enum dwarf_tag
)
977 _bfd_safe_read_leb128 (abfd
, abbrev_ptr
, &bytes_read
,
979 abbrev_ptr
+= bytes_read
;
980 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
, abbrev_end
);
983 /* Now read in declarations. */
986 /* Initialize it just to avoid a GCC false warning. */
987 bfd_vma implicit_const
= -1;
989 abbrev_name
= _bfd_safe_read_leb128 (abfd
, abbrev_ptr
, &bytes_read
,
991 abbrev_ptr
+= bytes_read
;
992 abbrev_form
= _bfd_safe_read_leb128 (abfd
, abbrev_ptr
, &bytes_read
,
994 abbrev_ptr
+= bytes_read
;
995 if (abbrev_form
== DW_FORM_implicit_const
)
997 implicit_const
= _bfd_safe_read_leb128 (abfd
, abbrev_ptr
,
1000 abbrev_ptr
+= bytes_read
;
1003 if (abbrev_name
== 0)
1006 if ((cur_abbrev
->num_attrs
% ATTR_ALLOC_CHUNK
) == 0)
1008 struct attr_abbrev
*tmp
;
1010 amt
= cur_abbrev
->num_attrs
+ ATTR_ALLOC_CHUNK
;
1011 amt
*= sizeof (struct attr_abbrev
);
1012 tmp
= (struct attr_abbrev
*) bfd_realloc (cur_abbrev
->attrs
, amt
);
1015 cur_abbrev
->attrs
= tmp
;
1018 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
].name
1019 = (enum dwarf_attribute
) abbrev_name
;
1020 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
].form
1021 = (enum dwarf_form
) abbrev_form
;
1022 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
].implicit_const
1024 ++cur_abbrev
->num_attrs
;
1027 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
1028 cur_abbrev
->next
= abbrevs
[hash_number
];
1029 abbrevs
[hash_number
] = cur_abbrev
;
1031 /* Get next abbreviation.
1032 Under Irix6 the abbreviations for a compilation unit are not
1033 always properly terminated with an abbrev number of 0.
1034 Exit loop if we encounter an abbreviation which we have
1035 already read (which means we are about to read the abbreviations
1036 for the next compile unit) or if the end of the abbreviation
1037 table is reached. */
1038 if ((size_t) (abbrev_ptr
- file
->dwarf_abbrev_buffer
)
1039 >= file
->dwarf_abbrev_size
)
1041 abbrev_number
= _bfd_safe_read_leb128 (abfd
, abbrev_ptr
,
1042 &bytes_read
, FALSE
, abbrev_end
);
1043 abbrev_ptr
+= bytes_read
;
1044 if (lookup_abbrev (abbrev_number
, abbrevs
) != NULL
)
1050 if (abbrevs
!= NULL
)
1054 for (i
= 0; i
< ABBREV_HASH_SIZE
; i
++)
1056 struct abbrev_info
*abbrev
= abbrevs
[i
];
1060 free (abbrev
->attrs
);
1061 abbrev
= abbrev
->next
;
1069 /* Returns true if the form is one which has a string value. */
1071 static inline bfd_boolean
1072 is_str_attr (enum dwarf_form form
)
1074 return (form
== DW_FORM_string
|| form
== DW_FORM_strp
1075 || form
== DW_FORM_line_strp
|| form
== DW_FORM_GNU_strp_alt
);
1078 /* Read and fill in the value of attribute ATTR as described by FORM.
1079 Read data starting from INFO_PTR, but never at or beyond INFO_PTR_END.
1080 Returns an updated INFO_PTR taking into account the amount of data read. */
1083 read_attribute_value (struct attribute
* attr
,
1085 bfd_vma implicit_const
,
1086 struct comp_unit
* unit
,
1087 bfd_byte
* info_ptr
,
1088 bfd_byte
* info_ptr_end
)
1090 bfd
*abfd
= unit
->abfd
;
1091 unsigned int bytes_read
;
1092 struct dwarf_block
*blk
;
1095 if (info_ptr
>= info_ptr_end
&& form
!= DW_FORM_flag_present
)
1097 _bfd_error_handler (_("DWARF error: info pointer extends beyond end of attributes"));
1098 bfd_set_error (bfd_error_bad_value
);
1102 attr
->form
= (enum dwarf_form
) form
;
1106 case DW_FORM_ref_addr
:
1107 /* DW_FORM_ref_addr is an address in DWARF2, and an offset in
1109 if (unit
->version
== 3 || unit
->version
== 4)
1111 if (unit
->offset_size
== 4)
1112 attr
->u
.val
= read_4_bytes (unit
->abfd
, info_ptr
, info_ptr_end
);
1114 attr
->u
.val
= read_8_bytes (unit
->abfd
, info_ptr
, info_ptr_end
);
1115 info_ptr
+= unit
->offset_size
;
1120 attr
->u
.val
= read_address (unit
, info_ptr
, info_ptr_end
);
1121 info_ptr
+= unit
->addr_size
;
1123 case DW_FORM_GNU_ref_alt
:
1124 case DW_FORM_sec_offset
:
1125 if (unit
->offset_size
== 4)
1126 attr
->u
.val
= read_4_bytes (unit
->abfd
, info_ptr
, info_ptr_end
);
1128 attr
->u
.val
= read_8_bytes (unit
->abfd
, info_ptr
, info_ptr_end
);
1129 info_ptr
+= unit
->offset_size
;
1131 case DW_FORM_block2
:
1132 amt
= sizeof (struct dwarf_block
);
1133 blk
= (struct dwarf_block
*) bfd_alloc (abfd
, amt
);
1136 blk
->size
= read_2_bytes (abfd
, info_ptr
, info_ptr_end
);
1138 info_ptr
= read_n_bytes (info_ptr
, info_ptr_end
, blk
);
1141 case DW_FORM_block4
:
1142 amt
= sizeof (struct dwarf_block
);
1143 blk
= (struct dwarf_block
*) bfd_alloc (abfd
, amt
);
1146 blk
->size
= read_4_bytes (abfd
, info_ptr
, info_ptr_end
);
1148 info_ptr
= read_n_bytes (info_ptr
, info_ptr_end
, blk
);
1152 attr
->u
.val
= read_2_bytes (abfd
, info_ptr
, info_ptr_end
);
1156 attr
->u
.val
= read_4_bytes (abfd
, info_ptr
, info_ptr_end
);
1160 attr
->u
.val
= read_8_bytes (abfd
, info_ptr
, info_ptr_end
);
1163 case DW_FORM_string
:
1164 attr
->u
.str
= read_string (abfd
, info_ptr
, info_ptr_end
, &bytes_read
);
1165 info_ptr
+= bytes_read
;
1168 attr
->u
.str
= read_indirect_string (unit
, info_ptr
, info_ptr_end
, &bytes_read
);
1169 info_ptr
+= bytes_read
;
1171 case DW_FORM_line_strp
:
1172 attr
->u
.str
= read_indirect_line_string (unit
, info_ptr
, info_ptr_end
, &bytes_read
);
1173 info_ptr
+= bytes_read
;
1175 case DW_FORM_GNU_strp_alt
:
1176 attr
->u
.str
= read_alt_indirect_string (unit
, info_ptr
, info_ptr_end
, &bytes_read
);
1177 info_ptr
+= bytes_read
;
1179 case DW_FORM_exprloc
:
1181 amt
= sizeof (struct dwarf_block
);
1182 blk
= (struct dwarf_block
*) bfd_alloc (abfd
, amt
);
1185 blk
->size
= _bfd_safe_read_leb128 (abfd
, info_ptr
, &bytes_read
,
1186 FALSE
, info_ptr_end
);
1187 info_ptr
+= bytes_read
;
1188 info_ptr
= read_n_bytes (info_ptr
, info_ptr_end
, blk
);
1191 case DW_FORM_block1
:
1192 amt
= sizeof (struct dwarf_block
);
1193 blk
= (struct dwarf_block
*) bfd_alloc (abfd
, amt
);
1196 blk
->size
= read_1_byte (abfd
, info_ptr
, info_ptr_end
);
1198 info_ptr
= read_n_bytes (info_ptr
, info_ptr_end
, blk
);
1202 attr
->u
.val
= read_1_byte (abfd
, info_ptr
, info_ptr_end
);
1206 attr
->u
.val
= read_1_byte (abfd
, info_ptr
, info_ptr_end
);
1209 case DW_FORM_flag_present
:
1213 attr
->u
.sval
= _bfd_safe_read_leb128 (abfd
, info_ptr
, &bytes_read
,
1214 TRUE
, info_ptr_end
);
1215 info_ptr
+= bytes_read
;
1218 attr
->u
.val
= _bfd_safe_read_leb128 (abfd
, info_ptr
, &bytes_read
,
1219 FALSE
, info_ptr_end
);
1220 info_ptr
+= bytes_read
;
1223 attr
->u
.val
= read_1_byte (abfd
, info_ptr
, info_ptr_end
);
1227 attr
->u
.val
= read_2_bytes (abfd
, info_ptr
, info_ptr_end
);
1231 attr
->u
.val
= read_4_bytes (abfd
, info_ptr
, info_ptr_end
);
1235 attr
->u
.val
= read_8_bytes (abfd
, info_ptr
, info_ptr_end
);
1238 case DW_FORM_ref_sig8
:
1239 attr
->u
.val
= read_8_bytes (abfd
, info_ptr
, info_ptr_end
);
1242 case DW_FORM_ref_udata
:
1243 attr
->u
.val
= _bfd_safe_read_leb128 (abfd
, info_ptr
, &bytes_read
,
1244 FALSE
, info_ptr_end
);
1245 info_ptr
+= bytes_read
;
1247 case DW_FORM_indirect
:
1248 form
= _bfd_safe_read_leb128 (abfd
, info_ptr
, &bytes_read
,
1249 FALSE
, info_ptr_end
);
1250 info_ptr
+= bytes_read
;
1251 if (form
== DW_FORM_implicit_const
)
1253 implicit_const
= _bfd_safe_read_leb128 (abfd
, info_ptr
, &bytes_read
,
1254 TRUE
, info_ptr_end
);
1255 info_ptr
+= bytes_read
;
1257 info_ptr
= read_attribute_value (attr
, form
, implicit_const
, unit
,
1258 info_ptr
, info_ptr_end
);
1260 case DW_FORM_implicit_const
:
1261 attr
->form
= DW_FORM_sdata
;
1262 attr
->u
.sval
= implicit_const
;
1265 _bfd_error_handler (_("DWARF error: invalid or unhandled FORM value: %#x"),
1267 bfd_set_error (bfd_error_bad_value
);
1273 /* Read an attribute described by an abbreviated attribute. */
1276 read_attribute (struct attribute
* attr
,
1277 struct attr_abbrev
* abbrev
,
1278 struct comp_unit
* unit
,
1279 bfd_byte
* info_ptr
,
1280 bfd_byte
* info_ptr_end
)
1282 attr
->name
= abbrev
->name
;
1283 info_ptr
= read_attribute_value (attr
, abbrev
->form
, abbrev
->implicit_const
,
1284 unit
, info_ptr
, info_ptr_end
);
1288 /* Return whether DW_AT_name will return the same as DW_AT_linkage_name
1292 non_mangled (int lang
)
1302 case DW_LANG_Cobol74
:
1303 case DW_LANG_Cobol85
:
1304 case DW_LANG_Fortran77
:
1305 case DW_LANG_Pascal83
:
1315 /* Source line information table routines. */
1317 #define FILE_ALLOC_CHUNK 5
1318 #define DIR_ALLOC_CHUNK 5
1322 struct line_info
* prev_line
;
1326 unsigned int column
;
1327 unsigned int discriminator
;
1328 unsigned char op_index
;
1329 unsigned char end_sequence
; /* End of (sequential) code sequence. */
1340 struct line_sequence
1343 struct line_sequence
* prev_sequence
;
1344 struct line_info
* last_line
; /* Largest VMA. */
1345 struct line_info
** line_info_lookup
;
1346 bfd_size_type num_lines
;
1349 struct line_info_table
1352 unsigned int num_files
;
1353 unsigned int num_dirs
;
1354 unsigned int num_sequences
;
1357 struct fileinfo
* files
;
1358 struct line_sequence
* sequences
;
1359 struct line_info
* lcl_head
; /* Local head; used in 'add_line_info'. */
1362 /* Remember some information about each function. If the function is
1363 inlined (DW_TAG_inlined_subroutine) it may have two additional
1364 attributes, DW_AT_call_file and DW_AT_call_line, which specify the
1365 source code location where this function was inlined. */
1369 /* Pointer to previous function in list of all functions. */
1370 struct funcinfo
* prev_func
;
1371 /* Pointer to function one scope higher. */
1372 struct funcinfo
* caller_func
;
1373 /* Source location file name where caller_func inlines this func. */
1375 /* Source location file name. */
1377 /* Source location line number where caller_func inlines this func. */
1379 /* Source location line number. */
1382 bfd_boolean is_linkage
;
1384 struct arange arange
;
1385 /* Where the symbol is defined. */
1389 struct lookup_funcinfo
1391 /* Function information corresponding to this lookup table entry. */
1392 struct funcinfo
* funcinfo
;
1394 /* The lowest address for this specific function. */
1397 /* The highest address of this function before the lookup table is sorted.
1398 The highest address of all prior functions after the lookup table is
1399 sorted, which is used for binary search. */
1401 /* Index of this function, used to ensure qsort is stable. */
1407 /* Pointer to previous variable in list of all variables */
1408 struct varinfo
*prev_var
;
1409 /* Source location file name */
1411 /* Source location line number */
1416 /* Where the symbol is defined */
1418 /* Is this a stack variable? */
1419 unsigned int stack
: 1;
1422 /* Return TRUE if NEW_LINE should sort after LINE. */
1424 static inline bfd_boolean
1425 new_line_sorts_after (struct line_info
*new_line
, struct line_info
*line
)
1427 return (new_line
->address
> line
->address
1428 || (new_line
->address
== line
->address
1429 && new_line
->op_index
> line
->op_index
));
1433 /* Adds a new entry to the line_info list in the line_info_table, ensuring
1434 that the list is sorted. Note that the line_info list is sorted from
1435 highest to lowest VMA (with possible duplicates); that is,
1436 line_info->prev_line always accesses an equal or smaller VMA. */
1439 add_line_info (struct line_info_table
*table
,
1441 unsigned char op_index
,
1444 unsigned int column
,
1445 unsigned int discriminator
,
1448 bfd_size_type amt
= sizeof (struct line_info
);
1449 struct line_sequence
* seq
= table
->sequences
;
1450 struct line_info
* info
= (struct line_info
*) bfd_alloc (table
->abfd
, amt
);
1455 /* Set member data of 'info'. */
1456 info
->prev_line
= NULL
;
1457 info
->address
= address
;
1458 info
->op_index
= op_index
;
1460 info
->column
= column
;
1461 info
->discriminator
= discriminator
;
1462 info
->end_sequence
= end_sequence
;
1464 if (filename
&& filename
[0])
1466 info
->filename
= (char *) bfd_alloc (table
->abfd
, strlen (filename
) + 1);
1467 if (info
->filename
== NULL
)
1469 strcpy (info
->filename
, filename
);
1472 info
->filename
= NULL
;
1474 /* Find the correct location for 'info'. Normally we will receive
1475 new line_info data 1) in order and 2) with increasing VMAs.
1476 However some compilers break the rules (cf. decode_line_info) and
1477 so we include some heuristics for quickly finding the correct
1478 location for 'info'. In particular, these heuristics optimize for
1479 the common case in which the VMA sequence that we receive is a
1480 list of locally sorted VMAs such as
1481 p...z a...j (where a < j < p < z)
1483 Note: table->lcl_head is used to head an *actual* or *possible*
1484 sub-sequence within the list (such as a...j) that is not directly
1485 headed by table->last_line
1487 Note: we may receive duplicate entries from 'decode_line_info'. */
1490 && seq
->last_line
->address
== address
1491 && seq
->last_line
->op_index
== op_index
1492 && seq
->last_line
->end_sequence
== end_sequence
)
1494 /* We only keep the last entry with the same address and end
1495 sequence. See PR ld/4986. */
1496 if (table
->lcl_head
== seq
->last_line
)
1497 table
->lcl_head
= info
;
1498 info
->prev_line
= seq
->last_line
->prev_line
;
1499 seq
->last_line
= info
;
1501 else if (!seq
|| seq
->last_line
->end_sequence
)
1503 /* Start a new line sequence. */
1504 amt
= sizeof (struct line_sequence
);
1505 seq
= (struct line_sequence
*) bfd_malloc (amt
);
1508 seq
->low_pc
= address
;
1509 seq
->prev_sequence
= table
->sequences
;
1510 seq
->last_line
= info
;
1511 table
->lcl_head
= info
;
1512 table
->sequences
= seq
;
1513 table
->num_sequences
++;
1515 else if (info
->end_sequence
1516 || new_line_sorts_after (info
, seq
->last_line
))
1518 /* Normal case: add 'info' to the beginning of the current sequence. */
1519 info
->prev_line
= seq
->last_line
;
1520 seq
->last_line
= info
;
1522 /* lcl_head: initialize to head a *possible* sequence at the end. */
1523 if (!table
->lcl_head
)
1524 table
->lcl_head
= info
;
1526 else if (!new_line_sorts_after (info
, table
->lcl_head
)
1527 && (!table
->lcl_head
->prev_line
1528 || new_line_sorts_after (info
, table
->lcl_head
->prev_line
)))
1530 /* Abnormal but easy: lcl_head is the head of 'info'. */
1531 info
->prev_line
= table
->lcl_head
->prev_line
;
1532 table
->lcl_head
->prev_line
= info
;
1536 /* Abnormal and hard: Neither 'last_line' nor 'lcl_head'
1537 are valid heads for 'info'. Reset 'lcl_head'. */
1538 struct line_info
* li2
= seq
->last_line
; /* Always non-NULL. */
1539 struct line_info
* li1
= li2
->prev_line
;
1543 if (!new_line_sorts_after (info
, li2
)
1544 && new_line_sorts_after (info
, li1
))
1547 li2
= li1
; /* always non-NULL */
1548 li1
= li1
->prev_line
;
1550 table
->lcl_head
= li2
;
1551 info
->prev_line
= table
->lcl_head
->prev_line
;
1552 table
->lcl_head
->prev_line
= info
;
1553 if (address
< seq
->low_pc
)
1554 seq
->low_pc
= address
;
1559 /* Extract a fully qualified filename from a line info table.
1560 The returned string has been malloc'ed and it is the caller's
1561 responsibility to free it. */
1564 concat_filename (struct line_info_table
*table
, unsigned int file
)
1568 if (table
== NULL
|| file
- 1 >= table
->num_files
)
1570 /* FILE == 0 means unknown. */
1573 (_("DWARF error: mangled line number section (bad file number)"));
1574 return strdup ("<unknown>");
1577 filename
= table
->files
[file
- 1].name
;
1578 if (filename
== NULL
)
1579 return strdup ("<unknown>");
1581 if (!IS_ABSOLUTE_PATH (filename
))
1583 char *dir_name
= NULL
;
1584 char *subdir_name
= NULL
;
1588 if (table
->files
[file
- 1].dir
1589 /* PR 17512: file: 0317e960. */
1590 && table
->files
[file
- 1].dir
<= table
->num_dirs
1591 /* PR 17512: file: 7f3d2e4b. */
1592 && table
->dirs
!= NULL
)
1593 subdir_name
= table
->dirs
[table
->files
[file
- 1].dir
- 1];
1595 if (!subdir_name
|| !IS_ABSOLUTE_PATH (subdir_name
))
1596 dir_name
= table
->comp_dir
;
1600 dir_name
= subdir_name
;
1605 return strdup (filename
);
1607 len
= strlen (dir_name
) + strlen (filename
) + 2;
1611 len
+= strlen (subdir_name
) + 1;
1612 name
= (char *) bfd_malloc (len
);
1614 sprintf (name
, "%s/%s/%s", dir_name
, subdir_name
, filename
);
1618 name
= (char *) bfd_malloc (len
);
1620 sprintf (name
, "%s/%s", dir_name
, filename
);
1626 return strdup (filename
);
1630 arange_add (const struct comp_unit
*unit
, struct arange
*first_arange
,
1631 bfd_vma low_pc
, bfd_vma high_pc
)
1633 struct arange
*arange
;
1635 /* Ignore empty ranges. */
1636 if (low_pc
== high_pc
)
1639 /* If the first arange is empty, use it. */
1640 if (first_arange
->high
== 0)
1642 first_arange
->low
= low_pc
;
1643 first_arange
->high
= high_pc
;
1647 /* Next see if we can cheaply extend an existing range. */
1648 arange
= first_arange
;
1651 if (low_pc
== arange
->high
)
1653 arange
->high
= high_pc
;
1656 if (high_pc
== arange
->low
)
1658 arange
->low
= low_pc
;
1661 arange
= arange
->next
;
1665 /* Need to allocate a new arange and insert it into the arange list.
1666 Order isn't significant, so just insert after the first arange. */
1667 arange
= (struct arange
*) bfd_alloc (unit
->abfd
, sizeof (*arange
));
1670 arange
->low
= low_pc
;
1671 arange
->high
= high_pc
;
1672 arange
->next
= first_arange
->next
;
1673 first_arange
->next
= arange
;
1677 /* Compare function for line sequences. */
1680 compare_sequences (const void* a
, const void* b
)
1682 const struct line_sequence
* seq1
= a
;
1683 const struct line_sequence
* seq2
= b
;
1685 /* Sort by low_pc as the primary key. */
1686 if (seq1
->low_pc
< seq2
->low_pc
)
1688 if (seq1
->low_pc
> seq2
->low_pc
)
1691 /* If low_pc values are equal, sort in reverse order of
1692 high_pc, so that the largest region comes first. */
1693 if (seq1
->last_line
->address
< seq2
->last_line
->address
)
1695 if (seq1
->last_line
->address
> seq2
->last_line
->address
)
1698 if (seq1
->last_line
->op_index
< seq2
->last_line
->op_index
)
1700 if (seq1
->last_line
->op_index
> seq2
->last_line
->op_index
)
1703 /* num_lines is initially an index, to make the sort stable. */
1704 if (seq1
->num_lines
< seq2
->num_lines
)
1706 if (seq1
->num_lines
> seq2
->num_lines
)
1711 /* Construct the line information table for quick lookup. */
1714 build_line_info_table (struct line_info_table
* table
,
1715 struct line_sequence
* seq
)
1718 struct line_info
** line_info_lookup
;
1719 struct line_info
* each_line
;
1720 unsigned int num_lines
;
1721 unsigned int line_index
;
1723 if (seq
->line_info_lookup
!= NULL
)
1726 /* Count the number of line information entries. We could do this while
1727 scanning the debug information, but some entries may be added via
1728 lcl_head without having a sequence handy to increment the number of
1731 for (each_line
= seq
->last_line
; each_line
; each_line
= each_line
->prev_line
)
1734 seq
->num_lines
= num_lines
;
1738 /* Allocate space for the line information lookup table. */
1739 amt
= sizeof (struct line_info
*) * num_lines
;
1740 line_info_lookup
= (struct line_info
**) bfd_alloc (table
->abfd
, amt
);
1741 seq
->line_info_lookup
= line_info_lookup
;
1742 if (line_info_lookup
== NULL
)
1745 /* Create the line information lookup table. */
1746 line_index
= num_lines
;
1747 for (each_line
= seq
->last_line
; each_line
; each_line
= each_line
->prev_line
)
1748 line_info_lookup
[--line_index
] = each_line
;
1750 BFD_ASSERT (line_index
== 0);
1754 /* Sort the line sequences for quick lookup. */
1757 sort_line_sequences (struct line_info_table
* table
)
1760 struct line_sequence
* sequences
;
1761 struct line_sequence
* seq
;
1763 unsigned int num_sequences
= table
->num_sequences
;
1764 bfd_vma last_high_pc
;
1766 if (num_sequences
== 0)
1769 /* Allocate space for an array of sequences. */
1770 amt
= sizeof (struct line_sequence
) * num_sequences
;
1771 sequences
= (struct line_sequence
*) bfd_alloc (table
->abfd
, amt
);
1772 if (sequences
== NULL
)
1775 /* Copy the linked list into the array, freeing the original nodes. */
1776 seq
= table
->sequences
;
1777 for (n
= 0; n
< num_sequences
; n
++)
1779 struct line_sequence
* last_seq
= seq
;
1782 sequences
[n
].low_pc
= seq
->low_pc
;
1783 sequences
[n
].prev_sequence
= NULL
;
1784 sequences
[n
].last_line
= seq
->last_line
;
1785 sequences
[n
].line_info_lookup
= NULL
;
1786 sequences
[n
].num_lines
= n
;
1787 seq
= seq
->prev_sequence
;
1790 BFD_ASSERT (seq
== NULL
);
1792 qsort (sequences
, n
, sizeof (struct line_sequence
), compare_sequences
);
1794 /* Make the list binary-searchable by trimming overlapping entries
1795 and removing nested entries. */
1797 last_high_pc
= sequences
[0].last_line
->address
;
1798 for (n
= 1; n
< table
->num_sequences
; n
++)
1800 if (sequences
[n
].low_pc
< last_high_pc
)
1802 if (sequences
[n
].last_line
->address
<= last_high_pc
)
1803 /* Skip nested entries. */
1806 /* Trim overlapping entries. */
1807 sequences
[n
].low_pc
= last_high_pc
;
1809 last_high_pc
= sequences
[n
].last_line
->address
;
1810 if (n
> num_sequences
)
1812 /* Close up the gap. */
1813 sequences
[num_sequences
].low_pc
= sequences
[n
].low_pc
;
1814 sequences
[num_sequences
].last_line
= sequences
[n
].last_line
;
1819 table
->sequences
= sequences
;
1820 table
->num_sequences
= num_sequences
;
1824 /* Add directory to TABLE. CUR_DIR memory ownership is taken by TABLE. */
1827 line_info_add_include_dir (struct line_info_table
*table
, char *cur_dir
)
1829 if ((table
->num_dirs
% DIR_ALLOC_CHUNK
) == 0)
1834 amt
= table
->num_dirs
+ DIR_ALLOC_CHUNK
;
1835 amt
*= sizeof (char *);
1837 tmp
= (char **) bfd_realloc (table
->dirs
, amt
);
1843 table
->dirs
[table
->num_dirs
++] = cur_dir
;
1848 line_info_add_include_dir_stub (struct line_info_table
*table
, char *cur_dir
,
1849 unsigned int dir ATTRIBUTE_UNUSED
,
1850 unsigned int xtime ATTRIBUTE_UNUSED
,
1851 unsigned int size ATTRIBUTE_UNUSED
)
1853 return line_info_add_include_dir (table
, cur_dir
);
1856 /* Add file to TABLE. CUR_FILE memory ownership is taken by TABLE. */
1859 line_info_add_file_name (struct line_info_table
*table
, char *cur_file
,
1860 unsigned int dir
, unsigned int xtime
,
1863 if ((table
->num_files
% FILE_ALLOC_CHUNK
) == 0)
1865 struct fileinfo
*tmp
;
1868 amt
= table
->num_files
+ FILE_ALLOC_CHUNK
;
1869 amt
*= sizeof (struct fileinfo
);
1871 tmp
= (struct fileinfo
*) bfd_realloc (table
->files
, amt
);
1877 table
->files
[table
->num_files
].name
= cur_file
;
1878 table
->files
[table
->num_files
].dir
= dir
;
1879 table
->files
[table
->num_files
].time
= xtime
;
1880 table
->files
[table
->num_files
].size
= size
;
1885 /* Read directory or file name entry format, starting with byte of
1886 format count entries, ULEB128 pairs of entry formats, ULEB128 of
1887 entries count and the entries themselves in the described entry
1891 read_formatted_entries (struct comp_unit
*unit
, bfd_byte
**bufp
,
1892 bfd_byte
*buf_end
, struct line_info_table
*table
,
1893 bfd_boolean (*callback
) (struct line_info_table
*table
,
1899 bfd
*abfd
= unit
->abfd
;
1900 bfd_byte format_count
, formati
;
1901 bfd_vma data_count
, datai
;
1902 bfd_byte
*buf
= *bufp
;
1903 bfd_byte
*format_header_data
;
1904 unsigned int bytes_read
;
1906 format_count
= read_1_byte (abfd
, buf
, buf_end
);
1908 format_header_data
= buf
;
1909 for (formati
= 0; formati
< format_count
; formati
++)
1911 _bfd_safe_read_leb128 (abfd
, buf
, &bytes_read
, FALSE
, buf_end
);
1913 _bfd_safe_read_leb128 (abfd
, buf
, &bytes_read
, FALSE
, buf_end
);
1917 data_count
= _bfd_safe_read_leb128 (abfd
, buf
, &bytes_read
, FALSE
, buf_end
);
1919 if (format_count
== 0 && data_count
!= 0)
1921 _bfd_error_handler (_("DWARF error: zero format count"));
1922 bfd_set_error (bfd_error_bad_value
);
1926 /* PR 22210. Paranoia check. Don't bother running the loop
1927 if we know that we are going to run out of buffer. */
1928 if (data_count
> (bfd_vma
) (buf_end
- buf
))
1931 (_("DWARF error: data count (%" PRIx64
") larger than buffer size"),
1932 (uint64_t) data_count
);
1933 bfd_set_error (bfd_error_bad_value
);
1937 for (datai
= 0; datai
< data_count
; datai
++)
1939 bfd_byte
*format
= format_header_data
;
1942 memset (&fe
, 0, sizeof fe
);
1943 for (formati
= 0; formati
< format_count
; formati
++)
1945 bfd_vma content_type
, form
;
1947 char **stringp
= &string_trash
;
1948 unsigned int uint_trash
, *uintp
= &uint_trash
;
1949 struct attribute attr
;
1951 content_type
= _bfd_safe_read_leb128 (abfd
, format
, &bytes_read
,
1953 format
+= bytes_read
;
1954 switch (content_type
)
1959 case DW_LNCT_directory_index
:
1962 case DW_LNCT_timestamp
:
1972 (_("DWARF error: unknown format content type %" PRIu64
),
1973 (uint64_t) content_type
);
1974 bfd_set_error (bfd_error_bad_value
);
1978 form
= _bfd_safe_read_leb128 (abfd
, format
, &bytes_read
, FALSE
,
1980 format
+= bytes_read
;
1982 buf
= read_attribute_value (&attr
, form
, 0, unit
, buf
, buf_end
);
1987 case DW_FORM_string
:
1988 case DW_FORM_line_strp
:
1989 *stringp
= attr
.u
.str
;
1997 *uintp
= attr
.u
.val
;
2002 if (!callback (table
, fe
.name
, fe
.dir
, fe
.time
, fe
.size
))
2010 /* Decode the line number information for UNIT. */
2012 static struct line_info_table
*
2013 decode_line_info (struct comp_unit
*unit
)
2015 bfd
*abfd
= unit
->abfd
;
2016 struct dwarf2_debug
*stash
= unit
->stash
;
2017 struct dwarf2_debug_file
*file
= unit
->file
;
2018 struct line_info_table
* table
;
2021 struct line_head lh
;
2022 unsigned int i
, bytes_read
, offset_size
;
2023 char *cur_file
, *cur_dir
;
2024 unsigned char op_code
, extended_op
, adj_opcode
;
2025 unsigned int exop_len
;
2028 if (! read_section (abfd
, &stash
->debug_sections
[debug_line
],
2029 file
->syms
, unit
->line_offset
,
2030 &file
->dwarf_line_buffer
, &file
->dwarf_line_size
))
2033 amt
= sizeof (struct line_info_table
);
2034 table
= (struct line_info_table
*) bfd_alloc (abfd
, amt
);
2038 table
->comp_dir
= unit
->comp_dir
;
2040 table
->num_files
= 0;
2041 table
->files
= NULL
;
2043 table
->num_dirs
= 0;
2046 table
->num_sequences
= 0;
2047 table
->sequences
= NULL
;
2049 table
->lcl_head
= NULL
;
2051 if (file
->dwarf_line_size
< 16)
2054 (_("DWARF error: line info section is too small (%" PRId64
")"),
2055 (int64_t) file
->dwarf_line_size
);
2056 bfd_set_error (bfd_error_bad_value
);
2059 line_ptr
= file
->dwarf_line_buffer
+ unit
->line_offset
;
2060 line_end
= file
->dwarf_line_buffer
+ file
->dwarf_line_size
;
2062 /* Read in the prologue. */
2063 lh
.total_length
= read_4_bytes (abfd
, line_ptr
, line_end
);
2066 if (lh
.total_length
== 0xffffffff)
2068 lh
.total_length
= read_8_bytes (abfd
, line_ptr
, line_end
);
2072 else if (lh
.total_length
== 0 && unit
->addr_size
== 8)
2074 /* Handle (non-standard) 64-bit DWARF2 formats. */
2075 lh
.total_length
= read_4_bytes (abfd
, line_ptr
, line_end
);
2080 if (lh
.total_length
> (size_t) (line_end
- line_ptr
))
2083 /* xgettext: c-format */
2084 (_("DWARF error: line info data is bigger (%#" PRIx64
")"
2085 " than the space remaining in the section (%#lx)"),
2086 (uint64_t) lh
.total_length
, (unsigned long) (line_end
- line_ptr
));
2087 bfd_set_error (bfd_error_bad_value
);
2091 line_end
= line_ptr
+ lh
.total_length
;
2093 lh
.version
= read_2_bytes (abfd
, line_ptr
, line_end
);
2094 if (lh
.version
< 2 || lh
.version
> 5)
2097 (_("DWARF error: unhandled .debug_line version %d"), lh
.version
);
2098 bfd_set_error (bfd_error_bad_value
);
2103 if (line_ptr
+ offset_size
+ (lh
.version
>= 5 ? 8 : (lh
.version
>= 4 ? 6 : 5))
2107 (_("DWARF error: ran out of room reading prologue"));
2108 bfd_set_error (bfd_error_bad_value
);
2112 if (lh
.version
>= 5)
2114 unsigned int segment_selector_size
;
2116 /* Skip address size. */
2117 read_1_byte (abfd
, line_ptr
, line_end
);
2120 segment_selector_size
= read_1_byte (abfd
, line_ptr
, line_end
);
2122 if (segment_selector_size
!= 0)
2125 (_("DWARF error: line info unsupported segment selector size %u"),
2126 segment_selector_size
);
2127 bfd_set_error (bfd_error_bad_value
);
2132 if (offset_size
== 4)
2133 lh
.prologue_length
= read_4_bytes (abfd
, line_ptr
, line_end
);
2135 lh
.prologue_length
= read_8_bytes (abfd
, line_ptr
, line_end
);
2136 line_ptr
+= offset_size
;
2138 lh
.minimum_instruction_length
= read_1_byte (abfd
, line_ptr
, line_end
);
2141 if (lh
.version
>= 4)
2143 lh
.maximum_ops_per_insn
= read_1_byte (abfd
, line_ptr
, line_end
);
2147 lh
.maximum_ops_per_insn
= 1;
2149 if (lh
.maximum_ops_per_insn
== 0)
2152 (_("DWARF error: invalid maximum operations per instruction"));
2153 bfd_set_error (bfd_error_bad_value
);
2157 lh
.default_is_stmt
= read_1_byte (abfd
, line_ptr
, line_end
);
2160 lh
.line_base
= read_1_signed_byte (abfd
, line_ptr
, line_end
);
2163 lh
.line_range
= read_1_byte (abfd
, line_ptr
, line_end
);
2166 lh
.opcode_base
= read_1_byte (abfd
, line_ptr
, line_end
);
2169 if (line_ptr
+ (lh
.opcode_base
- 1) >= line_end
)
2171 _bfd_error_handler (_("DWARF error: ran out of room reading opcodes"));
2172 bfd_set_error (bfd_error_bad_value
);
2176 amt
= lh
.opcode_base
* sizeof (unsigned char);
2177 lh
.standard_opcode_lengths
= (unsigned char *) bfd_alloc (abfd
, amt
);
2179 lh
.standard_opcode_lengths
[0] = 1;
2181 for (i
= 1; i
< lh
.opcode_base
; ++i
)
2183 lh
.standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
, line_end
);
2187 if (lh
.version
>= 5)
2189 /* Read directory table. */
2190 if (!read_formatted_entries (unit
, &line_ptr
, line_end
, table
,
2191 line_info_add_include_dir_stub
))
2194 /* Read file name table. */
2195 if (!read_formatted_entries (unit
, &line_ptr
, line_end
, table
,
2196 line_info_add_file_name
))
2201 /* Read directory table. */
2202 while ((cur_dir
= read_string (abfd
, line_ptr
, line_end
, &bytes_read
)) != NULL
)
2204 line_ptr
+= bytes_read
;
2206 if (!line_info_add_include_dir (table
, cur_dir
))
2210 line_ptr
+= bytes_read
;
2212 /* Read file name table. */
2213 while ((cur_file
= read_string (abfd
, line_ptr
, line_end
, &bytes_read
)) != NULL
)
2215 unsigned int dir
, xtime
, size
;
2217 line_ptr
+= bytes_read
;
2219 dir
= _bfd_safe_read_leb128 (abfd
, line_ptr
, &bytes_read
, FALSE
, line_end
);
2220 line_ptr
+= bytes_read
;
2221 xtime
= _bfd_safe_read_leb128 (abfd
, line_ptr
, &bytes_read
, FALSE
, line_end
);
2222 line_ptr
+= bytes_read
;
2223 size
= _bfd_safe_read_leb128 (abfd
, line_ptr
, &bytes_read
, FALSE
, line_end
);
2224 line_ptr
+= bytes_read
;
2226 if (!line_info_add_file_name (table
, cur_file
, dir
, xtime
, size
))
2230 line_ptr
+= bytes_read
;
2233 /* Read the statement sequences until there's nothing left. */
2234 while (line_ptr
< line_end
)
2236 /* State machine registers. */
2237 bfd_vma address
= 0;
2238 unsigned char op_index
= 0;
2239 char * filename
= table
->num_files
? concat_filename (table
, 1) : NULL
;
2240 unsigned int line
= 1;
2241 unsigned int column
= 0;
2242 unsigned int discriminator
= 0;
2243 int is_stmt
= lh
.default_is_stmt
;
2244 int end_sequence
= 0;
2245 unsigned int dir
, xtime
, size
;
2246 /* eraxxon@alumni.rice.edu: Against the DWARF2 specs, some
2247 compilers generate address sequences that are wildly out of
2248 order using DW_LNE_set_address (e.g. Intel C++ 6.0 compiler
2249 for ia64-Linux). Thus, to determine the low and high
2250 address, we must compare on every DW_LNS_copy, etc. */
2251 bfd_vma low_pc
= (bfd_vma
) -1;
2252 bfd_vma high_pc
= 0;
2254 /* Decode the table. */
2255 while (!end_sequence
&& line_ptr
< line_end
)
2257 op_code
= read_1_byte (abfd
, line_ptr
, line_end
);
2260 if (op_code
>= lh
.opcode_base
)
2262 /* Special operand. */
2263 adj_opcode
= op_code
- lh
.opcode_base
;
2264 if (lh
.line_range
== 0)
2266 if (lh
.maximum_ops_per_insn
== 1)
2267 address
+= (adj_opcode
/ lh
.line_range
2268 * lh
.minimum_instruction_length
);
2271 address
+= ((op_index
+ adj_opcode
/ lh
.line_range
)
2272 / lh
.maximum_ops_per_insn
2273 * lh
.minimum_instruction_length
);
2274 op_index
= ((op_index
+ adj_opcode
/ lh
.line_range
)
2275 % lh
.maximum_ops_per_insn
);
2277 line
+= lh
.line_base
+ (adj_opcode
% lh
.line_range
);
2278 /* Append row to matrix using current values. */
2279 if (!add_line_info (table
, address
, op_index
, filename
,
2280 line
, column
, discriminator
, 0))
2283 if (address
< low_pc
)
2285 if (address
> high_pc
)
2288 else switch (op_code
)
2290 case DW_LNS_extended_op
:
2291 exop_len
= _bfd_safe_read_leb128 (abfd
, line_ptr
, &bytes_read
,
2293 line_ptr
+= bytes_read
;
2294 extended_op
= read_1_byte (abfd
, line_ptr
, line_end
);
2297 switch (extended_op
)
2299 case DW_LNE_end_sequence
:
2301 if (!add_line_info (table
, address
, op_index
, filename
, line
,
2302 column
, discriminator
, end_sequence
))
2305 if (address
< low_pc
)
2307 if (address
> high_pc
)
2309 if (!arange_add (unit
, &unit
->arange
, low_pc
, high_pc
))
2312 case DW_LNE_set_address
:
2313 address
= read_address (unit
, line_ptr
, line_end
);
2315 line_ptr
+= unit
->addr_size
;
2317 case DW_LNE_define_file
:
2318 cur_file
= read_string (abfd
, line_ptr
, line_end
, &bytes_read
);
2319 line_ptr
+= bytes_read
;
2320 dir
= _bfd_safe_read_leb128 (abfd
, line_ptr
, &bytes_read
,
2322 line_ptr
+= bytes_read
;
2323 xtime
= _bfd_safe_read_leb128 (abfd
, line_ptr
, &bytes_read
,
2325 line_ptr
+= bytes_read
;
2326 size
= _bfd_safe_read_leb128 (abfd
, line_ptr
, &bytes_read
,
2328 line_ptr
+= bytes_read
;
2329 if (!line_info_add_file_name (table
, cur_file
, dir
,
2333 case DW_LNE_set_discriminator
:
2335 _bfd_safe_read_leb128 (abfd
, line_ptr
, &bytes_read
,
2337 line_ptr
+= bytes_read
;
2339 case DW_LNE_HP_source_file_correlation
:
2340 line_ptr
+= exop_len
- 1;
2344 (_("DWARF error: mangled line number section"));
2345 bfd_set_error (bfd_error_bad_value
);
2347 if (filename
!= NULL
)
2353 if (!add_line_info (table
, address
, op_index
,
2354 filename
, line
, column
, discriminator
, 0))
2357 if (address
< low_pc
)
2359 if (address
> high_pc
)
2362 case DW_LNS_advance_pc
:
2363 if (lh
.maximum_ops_per_insn
== 1)
2364 address
+= (lh
.minimum_instruction_length
2365 * _bfd_safe_read_leb128 (abfd
, line_ptr
,
2370 bfd_vma adjust
= _bfd_safe_read_leb128 (abfd
, line_ptr
,
2373 address
= ((op_index
+ adjust
) / lh
.maximum_ops_per_insn
2374 * lh
.minimum_instruction_length
);
2375 op_index
= (op_index
+ adjust
) % lh
.maximum_ops_per_insn
;
2377 line_ptr
+= bytes_read
;
2379 case DW_LNS_advance_line
:
2380 line
+= _bfd_safe_read_leb128 (abfd
, line_ptr
, &bytes_read
,
2382 line_ptr
+= bytes_read
;
2384 case DW_LNS_set_file
:
2386 unsigned int filenum
;
2388 /* The file and directory tables are 0
2389 based, the references are 1 based. */
2390 filenum
= _bfd_safe_read_leb128 (abfd
, line_ptr
, &bytes_read
,
2392 line_ptr
+= bytes_read
;
2395 filename
= concat_filename (table
, filenum
);
2398 case DW_LNS_set_column
:
2399 column
= _bfd_safe_read_leb128 (abfd
, line_ptr
, &bytes_read
,
2401 line_ptr
+= bytes_read
;
2403 case DW_LNS_negate_stmt
:
2404 is_stmt
= (!is_stmt
);
2406 case DW_LNS_set_basic_block
:
2408 case DW_LNS_const_add_pc
:
2409 if (lh
.line_range
== 0)
2411 if (lh
.maximum_ops_per_insn
== 1)
2412 address
+= (lh
.minimum_instruction_length
2413 * ((255 - lh
.opcode_base
) / lh
.line_range
));
2416 bfd_vma adjust
= ((255 - lh
.opcode_base
) / lh
.line_range
);
2417 address
+= (lh
.minimum_instruction_length
2418 * ((op_index
+ adjust
)
2419 / lh
.maximum_ops_per_insn
));
2420 op_index
= (op_index
+ adjust
) % lh
.maximum_ops_per_insn
;
2423 case DW_LNS_fixed_advance_pc
:
2424 address
+= read_2_bytes (abfd
, line_ptr
, line_end
);
2429 /* Unknown standard opcode, ignore it. */
2430 for (i
= 0; i
< lh
.standard_opcode_lengths
[op_code
]; i
++)
2432 (void) _bfd_safe_read_leb128 (abfd
, line_ptr
, &bytes_read
,
2434 line_ptr
+= bytes_read
;
2444 if (sort_line_sequences (table
))
2448 while (table
->sequences
!= NULL
)
2450 struct line_sequence
* seq
= table
->sequences
;
2451 table
->sequences
= table
->sequences
->prev_sequence
;
2454 if (table
->files
!= NULL
)
2455 free (table
->files
);
2456 if (table
->dirs
!= NULL
)
2461 /* If ADDR is within TABLE set the output parameters and return the
2462 range of addresses covered by the entry used to fill them out.
2463 Otherwise set * FILENAME_PTR to NULL and return 0.
2464 The parameters FILENAME_PTR, LINENUMBER_PTR and DISCRIMINATOR_PTR
2465 are pointers to the objects to be filled in. */
2468 lookup_address_in_line_info_table (struct line_info_table
*table
,
2470 const char **filename_ptr
,
2471 unsigned int *linenumber_ptr
,
2472 unsigned int *discriminator_ptr
)
2474 struct line_sequence
*seq
= NULL
;
2475 struct line_info
*info
;
2478 /* Binary search the array of sequences. */
2480 high
= table
->num_sequences
;
2483 mid
= (low
+ high
) / 2;
2484 seq
= &table
->sequences
[mid
];
2485 if (addr
< seq
->low_pc
)
2487 else if (addr
>= seq
->last_line
->address
)
2493 /* Check for a valid sequence. */
2494 if (!seq
|| addr
< seq
->low_pc
|| addr
>= seq
->last_line
->address
)
2497 if (!build_line_info_table (table
, seq
))
2500 /* Binary search the array of line information. */
2502 high
= seq
->num_lines
;
2506 mid
= (low
+ high
) / 2;
2507 info
= seq
->line_info_lookup
[mid
];
2508 if (addr
< info
->address
)
2510 else if (addr
>= seq
->line_info_lookup
[mid
+ 1]->address
)
2516 /* Check for a valid line information entry. */
2518 && addr
>= info
->address
2519 && addr
< seq
->line_info_lookup
[mid
+ 1]->address
2520 && !(info
->end_sequence
|| info
== seq
->last_line
))
2522 *filename_ptr
= info
->filename
;
2523 *linenumber_ptr
= info
->line
;
2524 if (discriminator_ptr
)
2525 *discriminator_ptr
= info
->discriminator
;
2526 return seq
->last_line
->address
- seq
->low_pc
;
2530 *filename_ptr
= NULL
;
2534 /* Read in the .debug_ranges section for future reference. */
2537 read_debug_ranges (struct comp_unit
* unit
)
2539 struct dwarf2_debug
*stash
= unit
->stash
;
2540 struct dwarf2_debug_file
*file
= unit
->file
;
2542 return read_section (unit
->abfd
, &stash
->debug_sections
[debug_ranges
],
2544 &file
->dwarf_ranges_buffer
, &file
->dwarf_ranges_size
);
2547 /* Function table functions. */
2550 compare_lookup_funcinfos (const void * a
, const void * b
)
2552 const struct lookup_funcinfo
* lookup1
= a
;
2553 const struct lookup_funcinfo
* lookup2
= b
;
2555 if (lookup1
->low_addr
< lookup2
->low_addr
)
2557 if (lookup1
->low_addr
> lookup2
->low_addr
)
2559 if (lookup1
->high_addr
< lookup2
->high_addr
)
2561 if (lookup1
->high_addr
> lookup2
->high_addr
)
2564 if (lookup1
->idx
< lookup2
->idx
)
2566 if (lookup1
->idx
> lookup2
->idx
)
2572 build_lookup_funcinfo_table (struct comp_unit
* unit
)
2574 struct lookup_funcinfo
*lookup_funcinfo_table
= unit
->lookup_funcinfo_table
;
2575 unsigned int number_of_functions
= unit
->number_of_functions
;
2576 struct funcinfo
*each
;
2577 struct lookup_funcinfo
*entry
;
2579 struct arange
*range
;
2580 bfd_vma low_addr
, high_addr
;
2582 if (lookup_funcinfo_table
|| number_of_functions
== 0)
2585 /* Create the function info lookup table. */
2586 lookup_funcinfo_table
= (struct lookup_funcinfo
*)
2587 bfd_malloc (number_of_functions
* sizeof (struct lookup_funcinfo
));
2588 if (lookup_funcinfo_table
== NULL
)
2591 /* Populate the function info lookup table. */
2592 func_index
= number_of_functions
;
2593 for (each
= unit
->function_table
; each
; each
= each
->prev_func
)
2595 entry
= &lookup_funcinfo_table
[--func_index
];
2596 entry
->funcinfo
= each
;
2597 entry
->idx
= func_index
;
2599 /* Calculate the lowest and highest address for this function entry. */
2600 low_addr
= entry
->funcinfo
->arange
.low
;
2601 high_addr
= entry
->funcinfo
->arange
.high
;
2603 for (range
= entry
->funcinfo
->arange
.next
; range
; range
= range
->next
)
2605 if (range
->low
< low_addr
)
2606 low_addr
= range
->low
;
2607 if (range
->high
> high_addr
)
2608 high_addr
= range
->high
;
2611 entry
->low_addr
= low_addr
;
2612 entry
->high_addr
= high_addr
;
2615 BFD_ASSERT (func_index
== 0);
2617 /* Sort the function by address. */
2618 qsort (lookup_funcinfo_table
,
2619 number_of_functions
,
2620 sizeof (struct lookup_funcinfo
),
2621 compare_lookup_funcinfos
);
2623 /* Calculate the high watermark for each function in the lookup table. */
2624 high_addr
= lookup_funcinfo_table
[0].high_addr
;
2625 for (func_index
= 1; func_index
< number_of_functions
; func_index
++)
2627 entry
= &lookup_funcinfo_table
[func_index
];
2628 if (entry
->high_addr
> high_addr
)
2629 high_addr
= entry
->high_addr
;
2631 entry
->high_addr
= high_addr
;
2634 unit
->lookup_funcinfo_table
= lookup_funcinfo_table
;
2638 /* If ADDR is within UNIT's function tables, set FUNCTION_PTR, and return
2639 TRUE. Note that we need to find the function that has the smallest range
2640 that contains ADDR, to handle inlined functions without depending upon
2641 them being ordered in TABLE by increasing range. */
2644 lookup_address_in_function_table (struct comp_unit
*unit
,
2646 struct funcinfo
**function_ptr
)
2648 unsigned int number_of_functions
= unit
->number_of_functions
;
2649 struct lookup_funcinfo
* lookup_funcinfo
= NULL
;
2650 struct funcinfo
* funcinfo
= NULL
;
2651 struct funcinfo
* best_fit
= NULL
;
2652 bfd_vma best_fit_len
= 0;
2653 bfd_size_type low
, high
, mid
, first
;
2654 struct arange
*arange
;
2656 if (number_of_functions
== 0)
2659 if (!build_lookup_funcinfo_table (unit
))
2662 if (unit
->lookup_funcinfo_table
[number_of_functions
- 1].high_addr
< addr
)
2665 /* Find the first function in the lookup table which may contain the
2666 specified address. */
2668 high
= number_of_functions
;
2672 mid
= (low
+ high
) / 2;
2673 lookup_funcinfo
= &unit
->lookup_funcinfo_table
[mid
];
2674 if (addr
< lookup_funcinfo
->low_addr
)
2676 else if (addr
>= lookup_funcinfo
->high_addr
)
2682 /* Find the 'best' match for the address. The prior algorithm defined the
2683 best match as the function with the smallest address range containing
2684 the specified address. This definition should probably be changed to the
2685 innermost inline routine containing the address, but right now we want
2686 to get the same results we did before. */
2687 while (first
< number_of_functions
)
2689 if (addr
< unit
->lookup_funcinfo_table
[first
].low_addr
)
2691 funcinfo
= unit
->lookup_funcinfo_table
[first
].funcinfo
;
2693 for (arange
= &funcinfo
->arange
; arange
; arange
= arange
->next
)
2695 if (addr
< arange
->low
|| addr
>= arange
->high
)
2699 || arange
->high
- arange
->low
< best_fit_len
2700 /* The following comparison is designed to return the same
2701 match as the previous algorithm for routines which have the
2702 same best fit length. */
2703 || (arange
->high
- arange
->low
== best_fit_len
2704 && funcinfo
> best_fit
))
2706 best_fit
= funcinfo
;
2707 best_fit_len
= arange
->high
- arange
->low
;
2717 *function_ptr
= best_fit
;
2721 /* If SYM at ADDR is within function table of UNIT, set FILENAME_PTR
2722 and LINENUMBER_PTR, and return TRUE. */
2725 lookup_symbol_in_function_table (struct comp_unit
*unit
,
2728 const char **filename_ptr
,
2729 unsigned int *linenumber_ptr
)
2731 struct funcinfo
* each_func
;
2732 struct funcinfo
* best_fit
= NULL
;
2733 bfd_vma best_fit_len
= 0;
2734 struct arange
*arange
;
2735 const char *name
= bfd_asymbol_name (sym
);
2736 asection
*sec
= bfd_asymbol_section (sym
);
2738 for (each_func
= unit
->function_table
;
2740 each_func
= each_func
->prev_func
)
2742 for (arange
= &each_func
->arange
;
2744 arange
= arange
->next
)
2746 if ((!each_func
->sec
|| each_func
->sec
== sec
)
2747 && addr
>= arange
->low
2748 && addr
< arange
->high
2750 && strcmp (name
, each_func
->name
) == 0
2752 || arange
->high
- arange
->low
< best_fit_len
))
2754 best_fit
= each_func
;
2755 best_fit_len
= arange
->high
- arange
->low
;
2762 best_fit
->sec
= sec
;
2763 *filename_ptr
= best_fit
->file
;
2764 *linenumber_ptr
= best_fit
->line
;
2771 /* Variable table functions. */
2773 /* If SYM is within variable table of UNIT, set FILENAME_PTR and
2774 LINENUMBER_PTR, and return TRUE. */
2777 lookup_symbol_in_variable_table (struct comp_unit
*unit
,
2780 const char **filename_ptr
,
2781 unsigned int *linenumber_ptr
)
2783 const char *name
= bfd_asymbol_name (sym
);
2784 asection
*sec
= bfd_asymbol_section (sym
);
2785 struct varinfo
* each
;
2787 for (each
= unit
->variable_table
; each
; each
= each
->prev_var
)
2788 if (each
->stack
== 0
2789 && each
->file
!= NULL
2790 && each
->name
!= NULL
2791 && each
->addr
== addr
2792 && (!each
->sec
|| each
->sec
== sec
)
2793 && strcmp (name
, each
->name
) == 0)
2799 *filename_ptr
= each
->file
;
2800 *linenumber_ptr
= each
->line
;
2807 static struct comp_unit
*stash_comp_unit (struct dwarf2_debug
*,
2808 struct dwarf2_debug_file
*);
2809 static bfd_boolean
comp_unit_maybe_decode_line_info (struct comp_unit
*);
2812 find_abstract_instance (struct comp_unit
*unit
,
2813 struct attribute
*attr_ptr
,
2814 unsigned int recur_count
,
2816 bfd_boolean
*is_linkage
,
2817 char **filename_ptr
,
2818 int *linenumber_ptr
)
2820 bfd
*abfd
= unit
->abfd
;
2822 bfd_byte
*info_ptr_end
;
2823 unsigned int abbrev_number
, bytes_read
, i
;
2824 struct abbrev_info
*abbrev
;
2825 bfd_uint64_t die_ref
= attr_ptr
->u
.val
;
2826 struct attribute attr
;
2827 const char *name
= NULL
;
2829 if (recur_count
== 100)
2832 (_("DWARF error: abstract instance recursion detected"));
2833 bfd_set_error (bfd_error_bad_value
);
2837 /* DW_FORM_ref_addr can reference an entry in a different CU. It
2838 is an offset from the .debug_info section, not the current CU. */
2839 if (attr_ptr
->form
== DW_FORM_ref_addr
)
2841 /* We only support DW_FORM_ref_addr within the same file, so
2842 any relocations should be resolved already. Check this by
2843 testing for a zero die_ref; There can't be a valid reference
2844 to the header of a .debug_info section.
2845 DW_FORM_ref_addr is an offset relative to .debug_info.
2846 Normally when using the GNU linker this is accomplished by
2847 emitting a symbolic reference to a label, because .debug_info
2848 sections are linked at zero. When there are multiple section
2849 groups containing .debug_info, as there might be in a
2850 relocatable object file, it would be reasonable to assume that
2851 a symbolic reference to a label in any .debug_info section
2852 might be used. Since we lay out multiple .debug_info
2853 sections at non-zero VMAs (see place_sections), and read
2854 them contiguously into dwarf_info_buffer, that means the
2855 reference is relative to dwarf_info_buffer. */
2858 info_ptr
= unit
->file
->dwarf_info_buffer
;
2859 info_ptr_end
= info_ptr
+ unit
->file
->dwarf_info_size
;
2860 total
= info_ptr_end
- info_ptr
;
2863 else if (die_ref
>= total
)
2866 (_("DWARF error: invalid abstract instance DIE ref"));
2867 bfd_set_error (bfd_error_bad_value
);
2870 info_ptr
+= die_ref
;
2872 /* Now find the CU containing this pointer. */
2873 if (info_ptr
>= unit
->info_ptr_unit
&& info_ptr
< unit
->end_ptr
)
2874 info_ptr_end
= unit
->end_ptr
;
2877 /* Check other CUs to see if they contain the abbrev. */
2878 struct comp_unit
* u
;
2880 for (u
= unit
->prev_unit
; u
!= NULL
; u
= u
->prev_unit
)
2881 if (info_ptr
>= u
->info_ptr_unit
&& info_ptr
< u
->end_ptr
)
2885 for (u
= unit
->next_unit
; u
!= NULL
; u
= u
->next_unit
)
2886 if (info_ptr
>= u
->info_ptr_unit
&& info_ptr
< u
->end_ptr
)
2891 u
= stash_comp_unit (unit
->stash
, unit
->file
);
2894 if (info_ptr
>= u
->info_ptr_unit
&& info_ptr
< u
->end_ptr
)
2902 (_("DWARF error: unable to locate abstract instance DIE ref %"
2903 PRIu64
), (uint64_t) die_ref
);
2904 bfd_set_error (bfd_error_bad_value
);
2908 info_ptr_end
= unit
->end_ptr
;
2911 else if (attr_ptr
->form
== DW_FORM_GNU_ref_alt
)
2913 info_ptr
= read_alt_indirect_ref (unit
, die_ref
);
2914 if (info_ptr
== NULL
)
2917 (_("DWARF error: unable to read alt ref %" PRIu64
),
2918 (uint64_t) die_ref
);
2919 bfd_set_error (bfd_error_bad_value
);
2922 info_ptr_end
= (unit
->stash
->alt
.dwarf_info_buffer
2923 + unit
->stash
->alt
.dwarf_info_size
);
2925 /* FIXME: Do we need to locate the correct CU, in a similar
2926 fashion to the code in the DW_FORM_ref_addr case above ? */
2930 /* DW_FORM_ref1, DW_FORM_ref2, DW_FORM_ref4, DW_FORM_ref8 or
2931 DW_FORM_ref_udata. These are all references relative to the
2932 start of the current CU. */
2935 info_ptr
= unit
->info_ptr_unit
;
2936 info_ptr_end
= unit
->end_ptr
;
2937 total
= info_ptr_end
- info_ptr
;
2938 if (!die_ref
|| die_ref
>= total
)
2941 (_("DWARF error: invalid abstract instance DIE ref"));
2942 bfd_set_error (bfd_error_bad_value
);
2945 info_ptr
+= die_ref
;
2948 abbrev_number
= _bfd_safe_read_leb128 (abfd
, info_ptr
, &bytes_read
,
2949 FALSE
, info_ptr_end
);
2950 info_ptr
+= bytes_read
;
2954 abbrev
= lookup_abbrev (abbrev_number
, unit
->abbrevs
);
2958 (_("DWARF error: could not find abbrev number %u"), abbrev_number
);
2959 bfd_set_error (bfd_error_bad_value
);
2964 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
2966 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], unit
,
2967 info_ptr
, info_ptr_end
);
2968 if (info_ptr
== NULL
)
2973 /* Prefer DW_AT_MIPS_linkage_name or DW_AT_linkage_name
2975 if (name
== NULL
&& is_str_attr (attr
.form
))
2978 if (non_mangled (unit
->lang
))
2982 case DW_AT_specification
:
2983 if (!find_abstract_instance (unit
, &attr
, recur_count
+ 1,
2985 filename_ptr
, linenumber_ptr
))
2988 case DW_AT_linkage_name
:
2989 case DW_AT_MIPS_linkage_name
:
2990 /* PR 16949: Corrupt debug info can place
2991 non-string forms into these attributes. */
2992 if (is_str_attr (attr
.form
))
2998 case DW_AT_decl_file
:
2999 if (!comp_unit_maybe_decode_line_info (unit
))
3001 *filename_ptr
= concat_filename (unit
->line_table
,
3004 case DW_AT_decl_line
:
3005 *linenumber_ptr
= attr
.u
.val
;
3018 read_rangelist (struct comp_unit
*unit
, struct arange
*arange
,
3019 bfd_uint64_t offset
)
3021 bfd_byte
*ranges_ptr
;
3022 bfd_byte
*ranges_end
;
3023 bfd_vma base_address
= unit
->base_address
;
3025 if (! unit
->file
->dwarf_ranges_buffer
)
3027 if (! read_debug_ranges (unit
))
3031 ranges_ptr
= unit
->file
->dwarf_ranges_buffer
+ offset
;
3032 if (ranges_ptr
< unit
->file
->dwarf_ranges_buffer
)
3034 ranges_end
= unit
->file
->dwarf_ranges_buffer
+ unit
->file
->dwarf_ranges_size
;
3041 /* PR 17512: file: 62cada7d. */
3042 if (ranges_ptr
+ 2 * unit
->addr_size
> ranges_end
)
3045 low_pc
= read_address (unit
, ranges_ptr
, ranges_end
);
3046 ranges_ptr
+= unit
->addr_size
;
3047 high_pc
= read_address (unit
, ranges_ptr
, ranges_end
);
3048 ranges_ptr
+= unit
->addr_size
;
3050 if (low_pc
== 0 && high_pc
== 0)
3052 if (low_pc
== -1UL && high_pc
!= -1UL)
3053 base_address
= high_pc
;
3056 if (!arange_add (unit
, arange
,
3057 base_address
+ low_pc
, base_address
+ high_pc
))
3064 /* DWARF2 Compilation unit functions. */
3066 /* Scan over each die in a comp. unit looking for functions to add
3067 to the function table and variables to the variable table. */
3070 scan_unit_for_symbols (struct comp_unit
*unit
)
3072 bfd
*abfd
= unit
->abfd
;
3073 bfd_byte
*info_ptr
= unit
->first_child_die_ptr
;
3074 bfd_byte
*info_ptr_end
= unit
->end_ptr
;
3075 int nesting_level
= 0;
3076 struct nest_funcinfo
{
3077 struct funcinfo
*func
;
3079 int nested_funcs_size
;
3081 /* Maintain a stack of in-scope functions and inlined functions, which we
3082 can use to set the caller_func field. */
3083 nested_funcs_size
= 32;
3084 nested_funcs
= (struct nest_funcinfo
*)
3085 bfd_malloc (nested_funcs_size
* sizeof (*nested_funcs
));
3086 if (nested_funcs
== NULL
)
3088 nested_funcs
[nesting_level
].func
= 0;
3090 while (nesting_level
>= 0)
3092 unsigned int abbrev_number
, bytes_read
, i
;
3093 struct abbrev_info
*abbrev
;
3094 struct attribute attr
;
3095 struct funcinfo
*func
;
3096 struct varinfo
*var
;
3098 bfd_vma high_pc
= 0;
3099 bfd_boolean high_pc_relative
= FALSE
;
3101 /* PR 17512: file: 9f405d9d. */
3102 if (info_ptr
>= info_ptr_end
)
3105 abbrev_number
= _bfd_safe_read_leb128 (abfd
, info_ptr
, &bytes_read
,
3106 FALSE
, info_ptr_end
);
3107 info_ptr
+= bytes_read
;
3109 if (! abbrev_number
)
3115 abbrev
= lookup_abbrev (abbrev_number
, unit
->abbrevs
);
3118 static unsigned int previous_failed_abbrev
= -1U;
3120 /* Avoid multiple reports of the same missing abbrev. */
3121 if (abbrev_number
!= previous_failed_abbrev
)
3124 (_("DWARF error: could not find abbrev number %u"),
3126 previous_failed_abbrev
= abbrev_number
;
3128 bfd_set_error (bfd_error_bad_value
);
3133 if (abbrev
->tag
== DW_TAG_subprogram
3134 || abbrev
->tag
== DW_TAG_entry_point
3135 || abbrev
->tag
== DW_TAG_inlined_subroutine
)
3137 bfd_size_type amt
= sizeof (struct funcinfo
);
3138 func
= (struct funcinfo
*) bfd_zalloc (abfd
, amt
);
3141 func
->tag
= abbrev
->tag
;
3142 func
->prev_func
= unit
->function_table
;
3143 unit
->function_table
= func
;
3144 unit
->number_of_functions
++;
3145 BFD_ASSERT (!unit
->cached
);
3147 if (func
->tag
== DW_TAG_inlined_subroutine
)
3148 for (i
= nesting_level
; i
-- != 0; )
3149 if (nested_funcs
[i
].func
)
3151 func
->caller_func
= nested_funcs
[i
].func
;
3154 nested_funcs
[nesting_level
].func
= func
;
3159 if (abbrev
->tag
== DW_TAG_variable
)
3161 bfd_size_type amt
= sizeof (struct varinfo
);
3162 var
= (struct varinfo
*) bfd_zalloc (abfd
, amt
);
3165 var
->tag
= abbrev
->tag
;
3167 var
->prev_var
= unit
->variable_table
;
3168 unit
->variable_table
= var
;
3169 /* PR 18205: Missing debug information can cause this
3170 var to be attached to an already cached unit. */
3173 /* No inline function in scope at this nesting level. */
3174 nested_funcs
[nesting_level
].func
= 0;
3177 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3179 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
],
3180 unit
, info_ptr
, info_ptr_end
);
3181 if (info_ptr
== NULL
)
3188 case DW_AT_call_file
:
3189 func
->caller_file
= concat_filename (unit
->line_table
,
3193 case DW_AT_call_line
:
3194 func
->caller_line
= attr
.u
.val
;
3197 case DW_AT_abstract_origin
:
3198 case DW_AT_specification
:
3199 if (!find_abstract_instance (unit
, &attr
, 0,
3208 /* Prefer DW_AT_MIPS_linkage_name or DW_AT_linkage_name
3210 if (func
->name
== NULL
&& is_str_attr (attr
.form
))
3212 func
->name
= attr
.u
.str
;
3213 if (non_mangled (unit
->lang
))
3214 func
->is_linkage
= TRUE
;
3218 case DW_AT_linkage_name
:
3219 case DW_AT_MIPS_linkage_name
:
3220 /* PR 16949: Corrupt debug info can place
3221 non-string forms into these attributes. */
3222 if (is_str_attr (attr
.form
))
3224 func
->name
= attr
.u
.str
;
3225 func
->is_linkage
= TRUE
;
3230 low_pc
= attr
.u
.val
;
3234 high_pc
= attr
.u
.val
;
3235 high_pc_relative
= attr
.form
!= DW_FORM_addr
;
3239 if (!read_rangelist (unit
, &func
->arange
, attr
.u
.val
))
3243 case DW_AT_decl_file
:
3244 func
->file
= concat_filename (unit
->line_table
,
3248 case DW_AT_decl_line
:
3249 func
->line
= attr
.u
.val
;
3261 if (is_str_attr (attr
.form
))
3262 var
->name
= attr
.u
.str
;
3265 case DW_AT_decl_file
:
3266 var
->file
= concat_filename (unit
->line_table
,
3270 case DW_AT_decl_line
:
3271 var
->line
= attr
.u
.val
;
3274 case DW_AT_external
:
3275 if (attr
.u
.val
!= 0)
3279 case DW_AT_location
:
3283 case DW_FORM_block1
:
3284 case DW_FORM_block2
:
3285 case DW_FORM_block4
:
3286 case DW_FORM_exprloc
:
3287 if (attr
.u
.blk
->data
!= NULL
3288 && *attr
.u
.blk
->data
== DW_OP_addr
)
3292 /* Verify that DW_OP_addr is the only opcode in the
3293 location, in which case the block size will be 1
3294 plus the address size. */
3295 /* ??? For TLS variables, gcc can emit
3296 DW_OP_addr <addr> DW_OP_GNU_push_tls_address
3297 which we don't handle here yet. */
3298 if (attr
.u
.blk
->size
== unit
->addr_size
+ 1U)
3299 var
->addr
= bfd_get (unit
->addr_size
* 8,
3301 attr
.u
.blk
->data
+ 1);
3316 if (high_pc_relative
)
3319 if (func
&& high_pc
!= 0)
3321 if (!arange_add (unit
, &func
->arange
, low_pc
, high_pc
))
3325 if (abbrev
->has_children
)
3329 if (nesting_level
>= nested_funcs_size
)
3331 struct nest_funcinfo
*tmp
;
3333 nested_funcs_size
*= 2;
3334 tmp
= (struct nest_funcinfo
*)
3335 bfd_realloc (nested_funcs
,
3336 nested_funcs_size
* sizeof (*nested_funcs
));
3341 nested_funcs
[nesting_level
].func
= 0;
3345 free (nested_funcs
);
3349 free (nested_funcs
);
3353 /* Parse a DWARF2 compilation unit starting at INFO_PTR. UNIT_LENGTH
3354 includes the compilation unit header that proceeds the DIE's, but
3355 does not include the length field that precedes each compilation
3356 unit header. END_PTR points one past the end of this comp unit.
3357 OFFSET_SIZE is the size of DWARF2 offsets (either 4 or 8 bytes).
3359 This routine does not read the whole compilation unit; only enough
3360 to get to the line number information for the compilation unit. */
3362 static struct comp_unit
*
3363 parse_comp_unit (struct dwarf2_debug
*stash
,
3364 struct dwarf2_debug_file
*file
,
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
*end_ptr
= info_ptr
+ unit_length
;
3382 bfd_vma high_pc
= 0;
3383 bfd
*abfd
= file
->bfd_ptr
;
3384 bfd_boolean high_pc_relative
= FALSE
;
3385 enum dwarf_unit_type unit_type
;
3387 version
= read_2_bytes (abfd
, info_ptr
, end_ptr
);
3389 if (version
< 2 || version
> 5)
3391 /* PR 19872: A version number of 0 probably means that there is padding
3392 at the end of the .debug_info section. Gold puts it there when
3393 performing an incremental link, for example. So do not generate
3394 an error, just return a NULL. */
3398 (_("DWARF error: found dwarf version '%u', this reader"
3399 " only handles version 2, 3, 4 and 5 information"), version
);
3400 bfd_set_error (bfd_error_bad_value
);
3406 unit_type
= DW_UT_compile
;
3409 unit_type
= read_1_byte (abfd
, info_ptr
, end_ptr
);
3412 addr_size
= read_1_byte (abfd
, info_ptr
, end_ptr
);
3416 BFD_ASSERT (offset_size
== 4 || offset_size
== 8);
3417 if (offset_size
== 4)
3418 abbrev_offset
= read_4_bytes (abfd
, info_ptr
, end_ptr
);
3420 abbrev_offset
= read_8_bytes (abfd
, info_ptr
, end_ptr
);
3421 info_ptr
+= offset_size
;
3425 addr_size
= read_1_byte (abfd
, info_ptr
, end_ptr
);
3429 if (unit_type
== DW_UT_type
)
3431 /* Skip type signature. */
3434 /* Skip type offset. */
3435 info_ptr
+= offset_size
;
3438 if (addr_size
> sizeof (bfd_vma
))
3441 /* xgettext: c-format */
3442 (_("DWARF error: found address size '%u', this reader"
3443 " can not handle sizes greater than '%u'"),
3445 (unsigned int) sizeof (bfd_vma
));
3446 bfd_set_error (bfd_error_bad_value
);
3450 if (addr_size
!= 2 && addr_size
!= 4 && addr_size
!= 8)
3453 ("DWARF error: found address size '%u', this reader"
3454 " can only handle address sizes '2', '4' and '8'", addr_size
);
3455 bfd_set_error (bfd_error_bad_value
);
3459 /* Read the abbrevs for this compilation unit into a table. */
3460 abbrevs
= read_abbrevs (abfd
, abbrev_offset
, stash
, file
);
3464 abbrev_number
= _bfd_safe_read_leb128 (abfd
, info_ptr
, &bytes_read
,
3466 info_ptr
+= bytes_read
;
3467 if (! abbrev_number
)
3469 /* PR 19872: An abbrev number of 0 probably means that there is padding
3470 at the end of the .debug_abbrev section. Gold puts it there when
3471 performing an incremental link, for example. So do not generate
3472 an error, just return a NULL. */
3476 abbrev
= lookup_abbrev (abbrev_number
, abbrevs
);
3479 _bfd_error_handler (_("DWARF error: could not find abbrev number %u"),
3481 bfd_set_error (bfd_error_bad_value
);
3485 amt
= sizeof (struct comp_unit
);
3486 unit
= (struct comp_unit
*) bfd_zalloc (abfd
, amt
);
3490 unit
->version
= version
;
3491 unit
->addr_size
= addr_size
;
3492 unit
->offset_size
= offset_size
;
3493 unit
->abbrevs
= abbrevs
;
3494 unit
->end_ptr
= end_ptr
;
3495 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
)
3627 if (!comp_unit_maybe_decode_line_info (unit
))
3630 *function_ptr
= NULL
;
3631 func_p
= lookup_address_in_function_table (unit
, addr
, function_ptr
);
3632 if (func_p
&& (*function_ptr
)->tag
== DW_TAG_inlined_subroutine
)
3633 unit
->stash
->inliner_chain
= *function_ptr
;
3635 return lookup_address_in_line_info_table (unit
->line_table
, addr
,
3641 /* Check to see if line info is already decoded in a comp_unit.
3642 If not, decode it. Returns TRUE if no errors were encountered;
3646 comp_unit_maybe_decode_line_info (struct comp_unit
*unit
)
3651 if (! unit
->line_table
)
3653 if (! unit
->stmtlist
)
3659 unit
->line_table
= decode_line_info (unit
);
3661 if (! unit
->line_table
)
3667 if (unit
->first_child_die_ptr
< unit
->end_ptr
3668 && ! scan_unit_for_symbols (unit
))
3678 /* If UNIT contains SYM at ADDR, set the output parameters to the
3679 values for the line containing SYM. The output parameters,
3680 FILENAME_PTR, and LINENUMBER_PTR, are pointers to the objects to be
3683 Return TRUE if UNIT contains SYM, and no errors were encountered;
3687 comp_unit_find_line (struct comp_unit
*unit
,
3690 const char **filename_ptr
,
3691 unsigned int *linenumber_ptr
)
3693 if (!comp_unit_maybe_decode_line_info (unit
))
3696 if (sym
->flags
& BSF_FUNCTION
)
3697 return lookup_symbol_in_function_table (unit
, sym
, addr
,
3701 return lookup_symbol_in_variable_table (unit
, sym
, addr
,
3706 static struct funcinfo
*
3707 reverse_funcinfo_list (struct funcinfo
*head
)
3709 struct funcinfo
*rhead
;
3710 struct funcinfo
*temp
;
3712 for (rhead
= NULL
; head
; head
= temp
)
3714 temp
= head
->prev_func
;
3715 head
->prev_func
= rhead
;
3721 static struct varinfo
*
3722 reverse_varinfo_list (struct varinfo
*head
)
3724 struct varinfo
*rhead
;
3725 struct varinfo
*temp
;
3727 for (rhead
= NULL
; head
; head
= temp
)
3729 temp
= head
->prev_var
;
3730 head
->prev_var
= rhead
;
3736 /* Extract all interesting funcinfos and varinfos of a compilation
3737 unit into hash tables for faster lookup. Returns TRUE if no
3738 errors were enountered; FALSE otherwise. */
3741 comp_unit_hash_info (struct dwarf2_debug
*stash
,
3742 struct comp_unit
*unit
,
3743 struct info_hash_table
*funcinfo_hash_table
,
3744 struct info_hash_table
*varinfo_hash_table
)
3746 struct funcinfo
* each_func
;
3747 struct varinfo
* each_var
;
3748 bfd_boolean okay
= TRUE
;
3750 BFD_ASSERT (stash
->info_hash_status
!= STASH_INFO_HASH_DISABLED
);
3752 if (!comp_unit_maybe_decode_line_info (unit
))
3755 BFD_ASSERT (!unit
->cached
);
3757 /* To preserve the original search order, we went to visit the function
3758 infos in the reversed order of the list. However, making the list
3759 bi-directional use quite a bit of extra memory. So we reverse
3760 the list first, traverse the list in the now reversed order and
3761 finally reverse the list again to get back the original order. */
3762 unit
->function_table
= reverse_funcinfo_list (unit
->function_table
);
3763 for (each_func
= unit
->function_table
;
3765 each_func
= each_func
->prev_func
)
3767 /* Skip nameless functions. */
3768 if (each_func
->name
)
3769 /* There is no need to copy name string into hash table as
3770 name string is either in the dwarf string buffer or
3771 info in the stash. */
3772 okay
= insert_info_hash_table (funcinfo_hash_table
, each_func
->name
,
3773 (void*) each_func
, FALSE
);
3775 unit
->function_table
= reverse_funcinfo_list (unit
->function_table
);
3779 /* We do the same for variable infos. */
3780 unit
->variable_table
= reverse_varinfo_list (unit
->variable_table
);
3781 for (each_var
= unit
->variable_table
;
3783 each_var
= each_var
->prev_var
)
3785 /* Skip stack vars and vars with no files or names. */
3786 if (each_var
->stack
== 0
3787 && each_var
->file
!= NULL
3788 && each_var
->name
!= NULL
)
3789 /* There is no need to copy name string into hash table as
3790 name string is either in the dwarf string buffer or
3791 info in the stash. */
3792 okay
= insert_info_hash_table (varinfo_hash_table
, each_var
->name
,
3793 (void*) each_var
, FALSE
);
3796 unit
->variable_table
= reverse_varinfo_list (unit
->variable_table
);
3797 unit
->cached
= TRUE
;
3801 /* Locate a section in a BFD containing debugging info. The search starts
3802 from the section after AFTER_SEC, or from the first section in the BFD if
3803 AFTER_SEC is NULL. The search works by examining the names of the
3804 sections. There are three permissiable names. The first two are given
3805 by DEBUG_SECTIONS[debug_info] (whose standard DWARF2 names are .debug_info
3806 and .zdebug_info). The third is a prefix .gnu.linkonce.wi.
3807 This is a variation on the .debug_info section which has a checksum
3808 describing the contents appended onto the name. This allows the linker to
3809 identify and discard duplicate debugging sections for different
3810 compilation units. */
3811 #define GNU_LINKONCE_INFO ".gnu.linkonce.wi."
3814 find_debug_info (bfd
*abfd
, const struct dwarf_debug_section
*debug_sections
,
3815 asection
*after_sec
)
3820 if (after_sec
== NULL
)
3822 look
= debug_sections
[debug_info
].uncompressed_name
;
3823 msec
= bfd_get_section_by_name (abfd
, look
);
3827 look
= debug_sections
[debug_info
].compressed_name
;
3830 msec
= bfd_get_section_by_name (abfd
, look
);
3835 for (msec
= abfd
->sections
; msec
!= NULL
; msec
= msec
->next
)
3836 if (CONST_STRNEQ (msec
->name
, GNU_LINKONCE_INFO
))
3842 for (msec
= after_sec
->next
; msec
!= NULL
; msec
= msec
->next
)
3844 look
= debug_sections
[debug_info
].uncompressed_name
;
3845 if (strcmp (msec
->name
, look
) == 0)
3848 look
= debug_sections
[debug_info
].compressed_name
;
3849 if (look
!= NULL
&& strcmp (msec
->name
, look
) == 0)
3852 if (CONST_STRNEQ (msec
->name
, GNU_LINKONCE_INFO
))
3859 /* Transfer VMAs from object file to separate debug file. */
3862 set_debug_vma (bfd
*orig_bfd
, bfd
*debug_bfd
)
3866 for (s
= orig_bfd
->sections
, d
= debug_bfd
->sections
;
3867 s
!= NULL
&& d
!= NULL
;
3868 s
= s
->next
, d
= d
->next
)
3870 if ((d
->flags
& SEC_DEBUGGING
) != 0)
3872 /* ??? Assumes 1-1 correspondence between sections in the
3874 if (strcmp (s
->name
, d
->name
) == 0)
3876 d
->output_section
= s
->output_section
;
3877 d
->output_offset
= s
->output_offset
;
3883 /* If the dwarf2 info was found in a separate debug file, return the
3884 debug file section corresponding to the section in the original file
3885 and the debug file symbols. */
3888 _bfd_dwarf2_stash_syms (struct dwarf2_debug
*stash
, bfd
*abfd
,
3889 asection
**sec
, asymbol
***syms
)
3891 if (stash
->f
.bfd_ptr
!= abfd
)
3897 *syms
= stash
->f
.syms
;
3901 for (s
= abfd
->sections
, d
= stash
->f
.bfd_ptr
->sections
;
3902 s
!= NULL
&& d
!= NULL
;
3903 s
= s
->next
, d
= d
->next
)
3905 if ((d
->flags
& SEC_DEBUGGING
) != 0)
3908 && strcmp (s
->name
, d
->name
) == 0)
3911 *syms
= stash
->f
.syms
;
3918 /* Unset vmas for adjusted sections in STASH. */
3921 unset_sections (struct dwarf2_debug
*stash
)
3924 struct adjusted_section
*p
;
3926 i
= stash
->adjusted_section_count
;
3927 p
= stash
->adjusted_sections
;
3928 for (; i
> 0; i
--, p
++)
3929 p
->section
->vma
= 0;
3932 /* Set VMAs for allocated and .debug_info sections in ORIG_BFD, a
3933 relocatable object file. VMAs are normally all zero in relocatable
3934 object files, so if we want to distinguish locations in sections by
3935 address we need to set VMAs so the sections do not overlap. We
3936 also set VMA on .debug_info so that when we have multiple
3937 .debug_info sections (or the linkonce variant) they also do not
3938 overlap. The multiple .debug_info sections make up a single
3939 logical section. ??? We should probably do the same for other
3943 place_sections (bfd
*orig_bfd
, struct dwarf2_debug
*stash
)
3946 struct adjusted_section
*p
;
3948 const char *debug_info_name
;
3950 if (stash
->adjusted_section_count
!= 0)
3952 i
= stash
->adjusted_section_count
;
3953 p
= stash
->adjusted_sections
;
3954 for (; i
> 0; i
--, p
++)
3955 p
->section
->vma
= p
->adj_vma
;
3959 debug_info_name
= stash
->debug_sections
[debug_info
].uncompressed_name
;
3966 for (sect
= abfd
->sections
; sect
!= NULL
; sect
= sect
->next
)
3970 if ((sect
->output_section
!= NULL
3971 && sect
->output_section
!= sect
3972 && (sect
->flags
& SEC_DEBUGGING
) == 0)
3976 is_debug_info
= (strcmp (sect
->name
, debug_info_name
) == 0
3977 || CONST_STRNEQ (sect
->name
, GNU_LINKONCE_INFO
));
3979 if (!((sect
->flags
& SEC_ALLOC
) != 0 && abfd
== orig_bfd
)
3985 if (abfd
== stash
->f
.bfd_ptr
)
3987 abfd
= stash
->f
.bfd_ptr
;
3991 stash
->adjusted_section_count
= -1;
3994 bfd_vma last_vma
= 0, last_dwarf
= 0;
3995 bfd_size_type amt
= i
* sizeof (struct adjusted_section
);
3997 p
= (struct adjusted_section
*) bfd_malloc (amt
);
4001 stash
->adjusted_sections
= p
;
4002 stash
->adjusted_section_count
= i
;
4009 for (sect
= abfd
->sections
; sect
!= NULL
; sect
= sect
->next
)
4014 if ((sect
->output_section
!= NULL
4015 && sect
->output_section
!= sect
4016 && (sect
->flags
& SEC_DEBUGGING
) == 0)
4020 is_debug_info
= (strcmp (sect
->name
, debug_info_name
) == 0
4021 || CONST_STRNEQ (sect
->name
, GNU_LINKONCE_INFO
));
4023 if (!((sect
->flags
& SEC_ALLOC
) != 0 && abfd
== orig_bfd
)
4027 sz
= sect
->rawsize
? sect
->rawsize
: sect
->size
;
4031 BFD_ASSERT (sect
->alignment_power
== 0);
4032 sect
->vma
= last_dwarf
;
4037 /* Align the new address to the current section
4039 last_vma
= ((last_vma
4040 + ~(-((bfd_vma
) 1 << sect
->alignment_power
)))
4041 & (-((bfd_vma
) 1 << sect
->alignment_power
)));
4042 sect
->vma
= last_vma
;
4047 p
->adj_vma
= sect
->vma
;
4050 if (abfd
== stash
->f
.bfd_ptr
)
4052 abfd
= stash
->f
.bfd_ptr
;
4056 if (orig_bfd
!= stash
->f
.bfd_ptr
)
4057 set_debug_vma (orig_bfd
, stash
->f
.bfd_ptr
);
4062 /* Look up a funcinfo by name using the given info hash table. If found,
4063 also update the locations pointed to by filename_ptr and linenumber_ptr.
4065 This function returns TRUE if a funcinfo that matches the given symbol
4066 and address is found with any error; otherwise it returns FALSE. */
4069 info_hash_lookup_funcinfo (struct info_hash_table
*hash_table
,
4072 const char **filename_ptr
,
4073 unsigned int *linenumber_ptr
)
4075 struct funcinfo
* each_func
;
4076 struct funcinfo
* best_fit
= NULL
;
4077 bfd_vma best_fit_len
= 0;
4078 struct info_list_node
*node
;
4079 struct arange
*arange
;
4080 const char *name
= bfd_asymbol_name (sym
);
4081 asection
*sec
= bfd_asymbol_section (sym
);
4083 for (node
= lookup_info_hash_table (hash_table
, name
);
4087 each_func
= (struct funcinfo
*) node
->info
;
4088 for (arange
= &each_func
->arange
;
4090 arange
= arange
->next
)
4092 if ((!each_func
->sec
|| each_func
->sec
== sec
)
4093 && addr
>= arange
->low
4094 && addr
< arange
->high
4096 || arange
->high
- arange
->low
< best_fit_len
))
4098 best_fit
= each_func
;
4099 best_fit_len
= arange
->high
- arange
->low
;
4106 best_fit
->sec
= sec
;
4107 *filename_ptr
= best_fit
->file
;
4108 *linenumber_ptr
= best_fit
->line
;
4115 /* Look up a varinfo by name using the given info hash table. If found,
4116 also update the locations pointed to by filename_ptr and linenumber_ptr.
4118 This function returns TRUE if a varinfo that matches the given symbol
4119 and address is found with any error; otherwise it returns FALSE. */
4122 info_hash_lookup_varinfo (struct info_hash_table
*hash_table
,
4125 const char **filename_ptr
,
4126 unsigned int *linenumber_ptr
)
4128 const char *name
= bfd_asymbol_name (sym
);
4129 asection
*sec
= bfd_asymbol_section (sym
);
4130 struct varinfo
* each
;
4131 struct info_list_node
*node
;
4133 for (node
= lookup_info_hash_table (hash_table
, name
);
4137 each
= (struct varinfo
*) node
->info
;
4138 if (each
->addr
== addr
4139 && (!each
->sec
|| each
->sec
== sec
))
4142 *filename_ptr
= each
->file
;
4143 *linenumber_ptr
= each
->line
;
4151 /* Update the funcinfo and varinfo info hash tables if they are
4152 not up to date. Returns TRUE if there is no error; otherwise
4153 returns FALSE and disable the info hash tables. */
4156 stash_maybe_update_info_hash_tables (struct dwarf2_debug
*stash
)
4158 struct comp_unit
*each
;
4160 /* Exit if hash tables are up-to-date. */
4161 if (stash
->f
.all_comp_units
== stash
->hash_units_head
)
4164 if (stash
->hash_units_head
)
4165 each
= stash
->hash_units_head
->prev_unit
;
4167 each
= stash
->f
.last_comp_unit
;
4171 if (!comp_unit_hash_info (stash
, each
, stash
->funcinfo_hash_table
,
4172 stash
->varinfo_hash_table
))
4174 stash
->info_hash_status
= STASH_INFO_HASH_DISABLED
;
4177 each
= each
->prev_unit
;
4180 stash
->hash_units_head
= stash
->f
.all_comp_units
;
4184 /* Check consistency of info hash tables. This is for debugging only. */
4186 static void ATTRIBUTE_UNUSED
4187 stash_verify_info_hash_table (struct dwarf2_debug
*stash
)
4189 struct comp_unit
*each_unit
;
4190 struct funcinfo
*each_func
;
4191 struct varinfo
*each_var
;
4192 struct info_list_node
*node
;
4195 for (each_unit
= stash
->f
.all_comp_units
;
4197 each_unit
= each_unit
->next_unit
)
4199 for (each_func
= each_unit
->function_table
;
4201 each_func
= each_func
->prev_func
)
4203 if (!each_func
->name
)
4205 node
= lookup_info_hash_table (stash
->funcinfo_hash_table
,
4209 while (node
&& !found
)
4211 found
= node
->info
== each_func
;
4217 for (each_var
= each_unit
->variable_table
;
4219 each_var
= each_var
->prev_var
)
4221 if (!each_var
->name
|| !each_var
->file
|| each_var
->stack
)
4223 node
= lookup_info_hash_table (stash
->varinfo_hash_table
,
4227 while (node
&& !found
)
4229 found
= node
->info
== each_var
;
4237 /* Check to see if we want to enable the info hash tables, which consume
4238 quite a bit of memory. Currently we only check the number times
4239 bfd_dwarf2_find_line is called. In the future, we may also want to
4240 take the number of symbols into account. */
4243 stash_maybe_enable_info_hash_tables (bfd
*abfd
, struct dwarf2_debug
*stash
)
4245 BFD_ASSERT (stash
->info_hash_status
== STASH_INFO_HASH_OFF
);
4247 if (stash
->info_hash_count
++ < STASH_INFO_HASH_TRIGGER
)
4250 /* FIXME: Maybe we should check the reduce_memory_overheads
4251 and optimize fields in the bfd_link_info structure ? */
4253 /* Create hash tables. */
4254 stash
->funcinfo_hash_table
= create_info_hash_table (abfd
);
4255 stash
->varinfo_hash_table
= create_info_hash_table (abfd
);
4256 if (!stash
->funcinfo_hash_table
|| !stash
->varinfo_hash_table
)
4258 /* Turn off info hashes if any allocation above fails. */
4259 stash
->info_hash_status
= STASH_INFO_HASH_DISABLED
;
4262 /* We need a forced update so that the info hash tables will
4263 be created even though there is no compilation unit. That
4264 happens if STASH_INFO_HASH_TRIGGER is 0. */
4265 if (stash_maybe_update_info_hash_tables (stash
))
4266 stash
->info_hash_status
= STASH_INFO_HASH_ON
;
4269 /* Find the file and line associated with a symbol and address using the
4270 info hash tables of a stash. If there is a match, the function returns
4271 TRUE and update the locations pointed to by filename_ptr and linenumber_ptr;
4272 otherwise it returns FALSE. */
4275 stash_find_line_fast (struct dwarf2_debug
*stash
,
4278 const char **filename_ptr
,
4279 unsigned int *linenumber_ptr
)
4281 BFD_ASSERT (stash
->info_hash_status
== STASH_INFO_HASH_ON
);
4283 if (sym
->flags
& BSF_FUNCTION
)
4284 return info_hash_lookup_funcinfo (stash
->funcinfo_hash_table
, sym
, addr
,
4285 filename_ptr
, linenumber_ptr
);
4286 return info_hash_lookup_varinfo (stash
->varinfo_hash_table
, sym
, addr
,
4287 filename_ptr
, linenumber_ptr
);
4290 /* Save current section VMAs. */
4293 save_section_vma (const bfd
*abfd
, struct dwarf2_debug
*stash
)
4298 if (abfd
->section_count
== 0)
4300 stash
->sec_vma
= bfd_malloc (sizeof (*stash
->sec_vma
) * abfd
->section_count
);
4301 if (stash
->sec_vma
== NULL
)
4303 stash
->sec_vma_count
= abfd
->section_count
;
4304 for (i
= 0, s
= abfd
->sections
;
4305 s
!= NULL
&& i
< abfd
->section_count
;
4308 if (s
->output_section
!= NULL
)
4309 stash
->sec_vma
[i
] = s
->output_section
->vma
+ s
->output_offset
;
4311 stash
->sec_vma
[i
] = s
->vma
;
4316 /* Compare current section VMAs against those at the time the stash
4317 was created. If find_nearest_line is used in linker warnings or
4318 errors early in the link process, the debug info stash will be
4319 invalid for later calls. This is because we relocate debug info
4320 sections, so the stashed section contents depend on symbol values,
4321 which in turn depend on section VMAs. */
4324 section_vma_same (const bfd
*abfd
, const struct dwarf2_debug
*stash
)
4329 /* PR 24334: If the number of sections in ABFD has changed between
4330 when the stash was created and now, then we cannot trust the
4331 stashed vma information. */
4332 if (abfd
->section_count
!= stash
->sec_vma_count
)
4335 for (i
= 0, s
= abfd
->sections
;
4336 s
!= NULL
&& i
< abfd
->section_count
;
4341 if (s
->output_section
!= NULL
)
4342 vma
= s
->output_section
->vma
+ s
->output_offset
;
4345 if (vma
!= stash
->sec_vma
[i
])
4351 /* Read debug information from DEBUG_BFD when DEBUG_BFD is specified.
4352 If DEBUG_BFD is not specified, we read debug information from ABFD
4353 or its gnu_debuglink. The results will be stored in PINFO.
4354 The function returns TRUE iff debug information is ready. */
4357 _bfd_dwarf2_slurp_debug_info (bfd
*abfd
, bfd
*debug_bfd
,
4358 const struct dwarf_debug_section
*debug_sections
,
4361 bfd_boolean do_place
)
4363 bfd_size_type amt
= sizeof (struct dwarf2_debug
);
4364 bfd_size_type total_size
;
4366 struct dwarf2_debug
*stash
= (struct dwarf2_debug
*) *pinfo
;
4370 if (stash
->orig_bfd
== abfd
4371 && section_vma_same (abfd
, stash
))
4373 /* Check that we did previously find some debug information
4374 before attempting to make use of it. */
4375 if (stash
->f
.bfd_ptr
!= NULL
)
4377 if (do_place
&& !place_sections (abfd
, stash
))
4384 _bfd_dwarf2_cleanup_debug_info (abfd
, pinfo
);
4385 memset (stash
, 0, amt
);
4389 stash
= (struct dwarf2_debug
*) bfd_zalloc (abfd
, amt
);
4393 stash
->orig_bfd
= abfd
;
4394 stash
->debug_sections
= debug_sections
;
4395 stash
->f
.syms
= symbols
;
4396 if (!save_section_vma (abfd
, stash
))
4401 if (debug_bfd
== NULL
)
4404 msec
= find_debug_info (debug_bfd
, debug_sections
, NULL
);
4405 if (msec
== NULL
&& abfd
== debug_bfd
)
4407 char * debug_filename
;
4409 debug_filename
= bfd_follow_build_id_debuglink (abfd
, DEBUGDIR
);
4410 if (debug_filename
== NULL
)
4411 debug_filename
= bfd_follow_gnu_debuglink (abfd
, DEBUGDIR
);
4413 if (debug_filename
== NULL
)
4414 /* No dwarf2 info, and no gnu_debuglink to follow.
4415 Note that at this point the stash has been allocated, but
4416 contains zeros. This lets future calls to this function
4417 fail more quickly. */
4420 debug_bfd
= bfd_openr (debug_filename
, NULL
);
4421 free (debug_filename
);
4422 if (debug_bfd
== NULL
)
4423 /* FIXME: Should we report our failure to follow the debuglink ? */
4426 /* Set BFD_DECOMPRESS to decompress debug sections. */
4427 debug_bfd
->flags
|= BFD_DECOMPRESS
;
4428 if (!bfd_check_format (debug_bfd
, bfd_object
)
4429 || (msec
= find_debug_info (debug_bfd
,
4430 debug_sections
, NULL
)) == NULL
4431 || !bfd_generic_link_read_symbols (debug_bfd
))
4433 bfd_close (debug_bfd
);
4437 symbols
= bfd_get_outsymbols (debug_bfd
);
4438 stash
->f
.syms
= symbols
;
4439 stash
->close_on_cleanup
= TRUE
;
4441 stash
->f
.bfd_ptr
= debug_bfd
;
4444 && !place_sections (abfd
, stash
))
4447 /* There can be more than one DWARF2 info section in a BFD these
4448 days. First handle the easy case when there's only one. If
4449 there's more than one, try case two: none of the sections is
4450 compressed. In that case, read them all in and produce one
4451 large stash. We do this in two passes - in the first pass we
4452 just accumulate the section sizes, and in the second pass we
4453 read in the section's contents. (The allows us to avoid
4454 reallocing the data as we add sections to the stash.) If
4455 some or all sections are compressed, then do things the slow
4456 way, with a bunch of reallocs. */
4458 if (! find_debug_info (debug_bfd
, debug_sections
, msec
))
4460 /* Case 1: only one info section. */
4461 total_size
= msec
->size
;
4462 if (! read_section (debug_bfd
, &stash
->debug_sections
[debug_info
],
4464 &stash
->f
.dwarf_info_buffer
, &total_size
))
4469 /* Case 2: multiple sections. */
4470 for (total_size
= 0;
4472 msec
= find_debug_info (debug_bfd
, debug_sections
, msec
))
4474 /* Catch PR25070 testcase overflowing size calculation here. */
4475 if (total_size
+ msec
->size
< total_size
4476 || total_size
+ msec
->size
< msec
->size
)
4478 bfd_set_error (bfd_error_no_memory
);
4481 total_size
+= msec
->size
;
4484 stash
->f
.dwarf_info_buffer
= (bfd_byte
*) bfd_malloc (total_size
);
4485 if (stash
->f
.dwarf_info_buffer
== NULL
)
4489 for (msec
= find_debug_info (debug_bfd
, debug_sections
, NULL
);
4491 msec
= find_debug_info (debug_bfd
, debug_sections
, msec
))
4499 if (!(bfd_simple_get_relocated_section_contents
4500 (debug_bfd
, msec
, stash
->f
.dwarf_info_buffer
+ total_size
,
4508 stash
->f
.info_ptr
= stash
->f
.dwarf_info_buffer
;
4509 stash
->f
.dwarf_info_size
= total_size
;
4513 /* Parse the next DWARF2 compilation unit at FILE->INFO_PTR. */
4515 static struct comp_unit
*
4516 stash_comp_unit (struct dwarf2_debug
*stash
, struct dwarf2_debug_file
*file
)
4518 bfd_size_type length
;
4519 unsigned int offset_size
;
4520 bfd_byte
*info_ptr_unit
= file
->info_ptr
;
4521 bfd_byte
*info_ptr_end
= file
->dwarf_info_buffer
+ file
->dwarf_info_size
;
4523 if (file
->info_ptr
>= info_ptr_end
)
4526 length
= read_4_bytes (file
->bfd_ptr
, file
->info_ptr
, info_ptr_end
);
4527 /* A 0xffffff length is the DWARF3 way of indicating
4528 we use 64-bit offsets, instead of 32-bit offsets. */
4529 if (length
== 0xffffffff)
4532 length
= read_8_bytes (file
->bfd_ptr
, file
->info_ptr
+ 4,
4534 file
->info_ptr
+= 12;
4536 /* A zero length is the IRIX way of indicating 64-bit offsets,
4537 mostly because the 64-bit length will generally fit in 32
4538 bits, and the endianness helps. */
4539 else if (length
== 0)
4542 length
= read_4_bytes (file
->bfd_ptr
, file
->info_ptr
+ 4,
4544 file
->info_ptr
+= 8;
4546 /* In the absence of the hints above, we assume 32-bit DWARF2
4547 offsets even for targets with 64-bit addresses, because:
4548 a) most of the time these targets will not have generated
4549 more than 2Gb of debug info and so will not need 64-bit
4552 b) if they do use 64-bit offsets but they are not using
4553 the size hints that are tested for above then they are
4554 not conforming to the DWARF3 standard anyway. */
4558 file
->info_ptr
+= 4;
4562 && file
->info_ptr
+ length
<= info_ptr_end
4563 && file
->info_ptr
+ length
> file
->info_ptr
)
4565 struct comp_unit
*each
= parse_comp_unit (stash
, file
,
4566 file
->info_ptr
, length
,
4567 info_ptr_unit
, offset_size
);
4570 if (file
->all_comp_units
)
4571 file
->all_comp_units
->prev_unit
= each
;
4573 file
->last_comp_unit
= each
;
4575 each
->next_unit
= file
->all_comp_units
;
4576 file
->all_comp_units
= each
;
4578 file
->info_ptr
+= length
;
4583 /* Don't trust any of the DWARF info after a corrupted length or
4585 file
->info_ptr
= info_ptr_end
;
4589 /* Hash function for an asymbol. */
4592 hash_asymbol (const void *sym
)
4594 const asymbol
*asym
= sym
;
4595 return htab_hash_string (asym
->name
);
4598 /* Equality function for asymbols. */
4601 eq_asymbol (const void *a
, const void *b
)
4603 const asymbol
*sa
= a
;
4604 const asymbol
*sb
= b
;
4605 return strcmp (sa
->name
, sb
->name
) == 0;
4608 /* Scan the debug information in PINFO looking for a DW_TAG_subprogram
4609 abbrev with a DW_AT_low_pc attached to it. Then lookup that same
4610 symbol in SYMBOLS and return the difference between the low_pc and
4611 the symbol's address. Returns 0 if no suitable symbol could be found. */
4614 _bfd_dwarf2_find_symbol_bias (asymbol
** symbols
, void ** pinfo
)
4616 struct dwarf2_debug
*stash
;
4617 struct comp_unit
* unit
;
4619 bfd_signed_vma result
= 0;
4622 stash
= (struct dwarf2_debug
*) *pinfo
;
4624 if (stash
== NULL
|| symbols
== NULL
)
4627 sym_hash
= htab_create_alloc (10, hash_asymbol
, eq_asymbol
,
4628 NULL
, xcalloc
, free
);
4629 for (psym
= symbols
; * psym
!= NULL
; psym
++)
4631 asymbol
* sym
= * psym
;
4633 if (sym
->flags
& BSF_FUNCTION
&& sym
->section
!= NULL
)
4635 void **slot
= htab_find_slot (sym_hash
, sym
, INSERT
);
4640 for (unit
= stash
->f
.all_comp_units
; unit
; unit
= unit
->next_unit
)
4642 struct funcinfo
* func
;
4644 comp_unit_maybe_decode_line_info (unit
);
4646 for (func
= unit
->function_table
; func
!= NULL
; func
= func
->prev_func
)
4647 if (func
->name
&& func
->arange
.low
)
4649 asymbol search
, *sym
;
4651 /* FIXME: Do we need to scan the aranges looking for the lowest pc value ? */
4653 search
.name
= func
->name
;
4654 sym
= htab_find (sym_hash
, &search
);
4657 result
= ((bfd_signed_vma
) func
->arange
.low
) -
4658 ((bfd_signed_vma
) (sym
->value
+ sym
->section
->vma
));
4665 htab_delete (sym_hash
);
4669 /* Find the source code location of SYMBOL. If SYMBOL is NULL
4670 then find the nearest source code location corresponding to
4671 the address SECTION + OFFSET.
4672 Returns 1 if the line is found without error and fills in
4673 FILENAME_PTR and LINENUMBER_PTR. In the case where SYMBOL was
4674 NULL the FUNCTIONNAME_PTR is also filled in.
4675 Returns 2 if partial information from _bfd_elf_find_function is
4676 returned (function and maybe file) by looking at symbols. DWARF2
4677 info is present but not regarding the requested code location.
4678 Returns 0 otherwise.
4679 SYMBOLS contains the symbol table for ABFD.
4680 DEBUG_SECTIONS contains the name of the dwarf debug sections. */
4683 _bfd_dwarf2_find_nearest_line (bfd
*abfd
,
4688 const char **filename_ptr
,
4689 const char **functionname_ptr
,
4690 unsigned int *linenumber_ptr
,
4691 unsigned int *discriminator_ptr
,
4692 const struct dwarf_debug_section
*debug_sections
,
4695 /* Read each compilation unit from the section .debug_info, and check
4696 to see if it contains the address we are searching for. If yes,
4697 lookup the address, and return the line number info. If no, go
4698 on to the next compilation unit.
4700 We keep a list of all the previously read compilation units, and
4701 a pointer to the next un-read compilation unit. Check the
4702 previously read units before reading more. */
4703 struct dwarf2_debug
*stash
;
4704 /* What address are we looking for? */
4706 struct comp_unit
* each
;
4707 struct funcinfo
*function
= NULL
;
4709 bfd_boolean do_line
;
4711 *filename_ptr
= NULL
;
4712 if (functionname_ptr
!= NULL
)
4713 *functionname_ptr
= NULL
;
4714 *linenumber_ptr
= 0;
4715 if (discriminator_ptr
)
4716 *discriminator_ptr
= 0;
4718 if (! _bfd_dwarf2_slurp_debug_info (abfd
, NULL
, debug_sections
,
4720 (abfd
->flags
& (EXEC_P
| DYNAMIC
)) == 0))
4723 stash
= (struct dwarf2_debug
*) *pinfo
;
4725 do_line
= symbol
!= NULL
;
4728 BFD_ASSERT (section
== NULL
&& offset
== 0 && functionname_ptr
== NULL
);
4729 section
= bfd_asymbol_section (symbol
);
4730 addr
= symbol
->value
;
4734 BFD_ASSERT (section
!= NULL
&& functionname_ptr
!= NULL
);
4737 /* If we have no SYMBOL but the section we're looking at is not a
4738 code section, then take a look through the list of symbols to see
4739 if we have a symbol at the address we're looking for. If we do
4740 then use this to look up line information. This will allow us to
4741 give file and line results for data symbols. We exclude code
4742 symbols here, if we look up a function symbol and then look up the
4743 line information we'll actually return the line number for the
4744 opening '{' rather than the function definition line. This is
4745 because looking up by symbol uses the line table, in which the
4746 first line for a function is usually the opening '{', while
4747 looking up the function by section + offset uses the
4748 DW_AT_decl_line from the function DW_TAG_subprogram for the line,
4749 which will be the line of the function name. */
4750 if (symbols
!= NULL
&& (section
->flags
& SEC_CODE
) == 0)
4754 for (tmp
= symbols
; (*tmp
) != NULL
; ++tmp
)
4755 if ((*tmp
)->the_bfd
== abfd
4756 && (*tmp
)->section
== section
4757 && (*tmp
)->value
== offset
4758 && ((*tmp
)->flags
& BSF_SECTION_SYM
) == 0)
4762 /* For local symbols, keep going in the hope we find a
4764 if ((symbol
->flags
& BSF_GLOBAL
) != 0)
4770 if (section
->output_section
)
4771 addr
+= section
->output_section
->vma
+ section
->output_offset
;
4773 addr
+= section
->vma
;
4775 /* A null info_ptr indicates that there is no dwarf2 info
4776 (or that an error occured while setting up the stash). */
4777 if (! stash
->f
.info_ptr
)
4780 stash
->inliner_chain
= NULL
;
4782 /* Check the previously read comp. units first. */
4785 /* The info hash tables use quite a bit of memory. We may not want to
4786 always use them. We use some heuristics to decide if and when to
4788 if (stash
->info_hash_status
== STASH_INFO_HASH_OFF
)
4789 stash_maybe_enable_info_hash_tables (abfd
, stash
);
4791 /* Keep info hash table up to date if they are available. Note that we
4792 may disable the hash tables if there is any error duing update. */
4793 if (stash
->info_hash_status
== STASH_INFO_HASH_ON
)
4794 stash_maybe_update_info_hash_tables (stash
);
4796 if (stash
->info_hash_status
== STASH_INFO_HASH_ON
)
4798 found
= stash_find_line_fast (stash
, symbol
, addr
, filename_ptr
,
4805 /* Check the previously read comp. units first. */
4806 for (each
= stash
->f
.all_comp_units
; each
; each
= each
->next_unit
)
4807 if ((symbol
->flags
& BSF_FUNCTION
) == 0
4808 || each
->arange
.high
== 0
4809 || comp_unit_contains_address (each
, addr
))
4811 found
= comp_unit_find_line (each
, symbol
, addr
, filename_ptr
,
4820 bfd_vma min_range
= (bfd_vma
) -1;
4821 const char * local_filename
= NULL
;
4822 struct funcinfo
*local_function
= NULL
;
4823 unsigned int local_linenumber
= 0;
4824 unsigned int local_discriminator
= 0;
4826 for (each
= stash
->f
.all_comp_units
; each
; each
= each
->next_unit
)
4828 bfd_vma range
= (bfd_vma
) -1;
4830 found
= ((each
->arange
.high
== 0
4831 || comp_unit_contains_address (each
, addr
))
4832 && (range
= (comp_unit_find_nearest_line
4833 (each
, addr
, &local_filename
,
4834 &local_function
, &local_linenumber
,
4835 &local_discriminator
))) != 0);
4838 /* PRs 15935 15994: Bogus debug information may have provided us
4839 with an erroneous match. We attempt to counter this by
4840 selecting the match that has the smallest address range
4841 associated with it. (We are assuming that corrupt debug info
4842 will tend to result in extra large address ranges rather than
4843 extra small ranges).
4845 This does mean that we scan through all of the CUs associated
4846 with the bfd each time this function is called. But this does
4847 have the benefit of producing consistent results every time the
4848 function is called. */
4849 if (range
<= min_range
)
4851 if (filename_ptr
&& local_filename
)
4852 * filename_ptr
= local_filename
;
4854 function
= local_function
;
4855 if (discriminator_ptr
&& local_discriminator
)
4856 * discriminator_ptr
= local_discriminator
;
4857 if (local_linenumber
)
4858 * linenumber_ptr
= local_linenumber
;
4864 if (* linenumber_ptr
)
4871 /* Read each remaining comp. units checking each as they are read. */
4872 while ((each
= stash_comp_unit (stash
, &stash
->f
)) != NULL
)
4874 /* DW_AT_low_pc and DW_AT_high_pc are optional for
4875 compilation units. If we don't have them (i.e.,
4876 unit->high == 0), we need to consult the line info table
4877 to see if a compilation unit contains the given
4880 found
= (((symbol
->flags
& BSF_FUNCTION
) == 0
4881 || each
->arange
.high
== 0
4882 || comp_unit_contains_address (each
, addr
))
4883 && comp_unit_find_line (each
, symbol
, addr
,
4884 filename_ptr
, linenumber_ptr
));
4886 found
= ((each
->arange
.high
== 0
4887 || comp_unit_contains_address (each
, addr
))
4888 && comp_unit_find_nearest_line (each
, addr
,
4892 discriminator_ptr
) != 0);
4899 if (functionname_ptr
&& function
&& function
->is_linkage
)
4900 *functionname_ptr
= function
->name
;
4901 else if (functionname_ptr
4902 && (!*functionname_ptr
4903 || (function
&& !function
->is_linkage
)))
4906 asymbol
**syms
= symbols
;
4907 asection
*sec
= section
;
4909 _bfd_dwarf2_stash_syms (stash
, abfd
, &sec
, &syms
);
4910 fun
= _bfd_elf_find_function (abfd
, syms
, sec
, offset
,
4911 *filename_ptr
? NULL
: filename_ptr
,
4914 if (!found
&& fun
!= NULL
)
4917 if (function
&& !function
->is_linkage
)
4921 sec_vma
= section
->vma
;
4922 if (section
->output_section
!= NULL
)
4923 sec_vma
= section
->output_section
->vma
+ section
->output_offset
;
4925 && fun
->value
+ sec_vma
== function
->arange
.low
)
4926 function
->name
= *functionname_ptr
;
4927 /* Even if we didn't find a linkage name, say that we have
4928 to stop a repeated search of symbols. */
4929 function
->is_linkage
= TRUE
;
4933 if ((abfd
->flags
& (EXEC_P
| DYNAMIC
)) == 0)
4934 unset_sections (stash
);
4940 _bfd_dwarf2_find_inliner_info (bfd
*abfd ATTRIBUTE_UNUSED
,
4941 const char **filename_ptr
,
4942 const char **functionname_ptr
,
4943 unsigned int *linenumber_ptr
,
4946 struct dwarf2_debug
*stash
;
4948 stash
= (struct dwarf2_debug
*) *pinfo
;
4951 struct funcinfo
*func
= stash
->inliner_chain
;
4953 if (func
&& func
->caller_func
)
4955 *filename_ptr
= func
->caller_file
;
4956 *functionname_ptr
= func
->caller_func
->name
;
4957 *linenumber_ptr
= func
->caller_line
;
4958 stash
->inliner_chain
= func
->caller_func
;
4967 _bfd_dwarf2_cleanup_debug_info (bfd
*abfd
, void **pinfo
)
4969 struct dwarf2_debug
*stash
= (struct dwarf2_debug
*) *pinfo
;
4970 struct comp_unit
*each
;
4971 struct dwarf2_debug_file
*file
;
4973 if (abfd
== NULL
|| stash
== NULL
)
4976 if (stash
->varinfo_hash_table
)
4977 bfd_hash_table_free (&stash
->varinfo_hash_table
->base
);
4978 if (stash
->funcinfo_hash_table
)
4979 bfd_hash_table_free (&stash
->funcinfo_hash_table
->base
);
4984 for (each
= file
->all_comp_units
; each
; each
= each
->next_unit
)
4986 struct abbrev_info
**abbrevs
= each
->abbrevs
;
4987 struct funcinfo
*function_table
= each
->function_table
;
4988 struct varinfo
*variable_table
= each
->variable_table
;
4991 for (i
= 0; i
< ABBREV_HASH_SIZE
; i
++)
4993 struct abbrev_info
*abbrev
= abbrevs
[i
];
4997 free (abbrev
->attrs
);
4998 abbrev
= abbrev
->next
;
5002 if (each
->line_table
)
5004 free (each
->line_table
->files
);
5005 free (each
->line_table
->dirs
);
5008 if (each
->lookup_funcinfo_table
)
5010 free (each
->lookup_funcinfo_table
);
5011 each
->lookup_funcinfo_table
= NULL
;
5014 while (function_table
)
5016 if (function_table
->file
)
5018 free (function_table
->file
);
5019 function_table
->file
= NULL
;
5021 if (function_table
->caller_file
)
5023 free (function_table
->caller_file
);
5024 function_table
->caller_file
= NULL
;
5026 function_table
= function_table
->prev_func
;
5029 while (variable_table
)
5031 if (variable_table
->file
)
5033 free (variable_table
->file
);
5034 variable_table
->file
= NULL
;
5036 variable_table
= variable_table
->prev_var
;
5040 free (file
->dwarf_line_str_buffer
);
5041 free (file
->dwarf_str_buffer
);
5042 free (file
->dwarf_ranges_buffer
);
5043 free (file
->dwarf_line_buffer
);
5044 free (file
->dwarf_abbrev_buffer
);
5045 free (file
->dwarf_info_buffer
);
5046 if (file
== &stash
->alt
)
5050 free (stash
->sec_vma
);
5051 free (stash
->adjusted_sections
);
5052 if (stash
->close_on_cleanup
)
5053 bfd_close (stash
->f
.bfd_ptr
);
5054 if (stash
->alt
.bfd_ptr
)
5055 bfd_close (stash
->alt
.bfd_ptr
);
5058 /* Find the function to a particular section and offset,
5059 for error reporting. */
5062 _bfd_elf_find_function (bfd
*abfd
,
5066 const char **filename_ptr
,
5067 const char **functionname_ptr
)
5069 struct elf_find_function_cache
5071 asection
*last_section
;
5073 const char *filename
;
5074 bfd_size_type func_size
;
5077 if (symbols
== NULL
)
5080 if (bfd_get_flavour (abfd
) != bfd_target_elf_flavour
)
5083 cache
= elf_tdata (abfd
)->elf_find_function_cache
;
5086 cache
= bfd_zalloc (abfd
, sizeof (*cache
));
5087 elf_tdata (abfd
)->elf_find_function_cache
= cache
;
5091 if (cache
->last_section
!= section
5092 || cache
->func
== NULL
5093 || offset
< cache
->func
->value
5094 || offset
>= cache
->func
->value
+ cache
->func_size
)
5099 /* ??? Given multiple file symbols, it is impossible to reliably
5100 choose the right file name for global symbols. File symbols are
5101 local symbols, and thus all file symbols must sort before any
5102 global symbols. The ELF spec may be interpreted to say that a
5103 file symbol must sort before other local symbols, but currently
5104 ld -r doesn't do this. So, for ld -r output, it is possible to
5105 make a better choice of file name for local symbols by ignoring
5106 file symbols appearing after a given local symbol. */
5107 enum { nothing_seen
, symbol_seen
, file_after_symbol_seen
} state
;
5108 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
5112 state
= nothing_seen
;
5113 cache
->filename
= NULL
;
5115 cache
->func_size
= 0;
5116 cache
->last_section
= section
;
5118 for (p
= symbols
; *p
!= NULL
; p
++)
5124 if ((sym
->flags
& BSF_FILE
) != 0)
5127 if (state
== symbol_seen
)
5128 state
= file_after_symbol_seen
;
5132 size
= bed
->maybe_function_sym (sym
, section
, &code_off
);
5134 && code_off
<= offset
5135 && (code_off
> low_func
5136 || (code_off
== low_func
5137 && size
> cache
->func_size
)))
5140 cache
->func_size
= size
;
5141 cache
->filename
= NULL
;
5142 low_func
= code_off
;
5144 && ((sym
->flags
& BSF_LOCAL
) != 0
5145 || state
!= file_after_symbol_seen
))
5146 cache
->filename
= bfd_asymbol_name (file
);
5148 if (state
== nothing_seen
)
5149 state
= symbol_seen
;
5153 if (cache
->func
== NULL
)
5157 *filename_ptr
= cache
->filename
;
5158 if (functionname_ptr
)
5159 *functionname_ptr
= bfd_asymbol_name (cache
->func
);