2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
3 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
5 Adapted from gdb/dwarf2read.c by Gavin Koch of Cygnus Solutions
8 From the dwarf2read.c header:
9 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
10 Inc. with support from Florida State University (under contract
11 with the Ada Joint Program Office), and Silicon Graphics, Inc.
12 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
13 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
14 support in dwarfread.c
16 This file is part of BFD.
18 This program is free software; you can redistribute it and/or modify
19 it under the terms of the GNU General Public License as published by
20 the Free Software Foundation; either version 3 of the License, or (at
21 your option) any later version.
23 This program is distributed in the hope that it will be useful, but
24 WITHOUT ANY WARRANTY; without even the implied warranty of
25 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26 General Public License for more details.
28 You should have received a copy of the GNU General Public License
29 along with this program; if not, write to the Free Software
30 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
31 MA 02110-1301, USA. */
35 #include "libiberty.h"
40 /* The data in the .debug_line statement prologue looks like this. */
45 unsigned short version
;
46 bfd_vma prologue_length
;
47 unsigned char minimum_instruction_length
;
48 unsigned char maximum_ops_per_insn
;
49 unsigned char default_is_stmt
;
51 unsigned char line_range
;
52 unsigned char opcode_base
;
53 unsigned char *standard_opcode_lengths
;
56 /* Attributes have a name and a value. */
60 enum dwarf_attribute name
;
65 struct dwarf_block
*blk
;
72 /* Blocks are a bunch of untyped bytes. */
79 struct adjusted_section
87 /* A list of all previously read comp_units. */
88 struct comp_unit
*all_comp_units
;
90 /* Last comp unit in list above. */
91 struct comp_unit
*last_comp_unit
;
93 /* The next unread compilation unit within the .debug_info section.
94 Zero indicates that the .debug_info section has not been loaded
98 /* Pointer to the end of the .debug_info section memory buffer. */
99 bfd_byte
*info_ptr_end
;
101 /* Pointer to the bfd, section and address of the beginning of the
102 section. The bfd might be different than expected because of
103 gnu_debuglink sections. */
106 bfd_byte
*sec_info_ptr
;
108 /* A pointer to the memory block allocated for info_ptr. Neither
109 info_ptr nor sec_info_ptr are guaranteed to stay pointing to the
110 beginning of the malloc block. This is used only to free the
112 bfd_byte
*info_ptr_memory
;
114 /* Pointer to the symbol table. */
117 /* Pointer to the .debug_abbrev section loaded into memory. */
118 bfd_byte
*dwarf_abbrev_buffer
;
120 /* Length of the loaded .debug_abbrev section. */
121 bfd_size_type dwarf_abbrev_size
;
123 /* Buffer for decode_line_info. */
124 bfd_byte
*dwarf_line_buffer
;
126 /* Length of the loaded .debug_line section. */
127 bfd_size_type dwarf_line_size
;
129 /* Pointer to the .debug_str section loaded into memory. */
130 bfd_byte
*dwarf_str_buffer
;
132 /* Length of the loaded .debug_str section. */
133 bfd_size_type dwarf_str_size
;
135 /* Pointer to the .debug_ranges section loaded into memory. */
136 bfd_byte
*dwarf_ranges_buffer
;
138 /* Length of the loaded .debug_ranges section. */
139 bfd_size_type dwarf_ranges_size
;
141 /* If the most recent call to bfd_find_nearest_line was given an
142 address in an inlined function, preserve a pointer into the
143 calling chain for subsequent calls to bfd_find_inliner_info to
145 struct funcinfo
*inliner_chain
;
147 /* Number of sections whose VMA we must adjust. */
148 unsigned int adjusted_section_count
;
150 /* Array of sections with adjusted VMA. */
151 struct adjusted_section
*adjusted_sections
;
153 /* Number of times find_line is called. This is used in
154 the heuristic for enabling the info hash tables. */
157 #define STASH_INFO_HASH_TRIGGER 100
159 /* Hash table mapping symbol names to function infos. */
160 struct info_hash_table
*funcinfo_hash_table
;
162 /* Hash table mapping symbol names to variable infos. */
163 struct info_hash_table
*varinfo_hash_table
;
165 /* Head of comp_unit list in the last hash table update. */
166 struct comp_unit
*hash_units_head
;
168 /* Status of info hash. */
169 int info_hash_status
;
170 #define STASH_INFO_HASH_OFF 0
171 #define STASH_INFO_HASH_ON 1
172 #define STASH_INFO_HASH_DISABLED 2
182 /* A minimal decoding of DWARF2 compilation units. We only decode
183 what's needed to get to the line number information. */
187 /* Chain the previously read compilation units. */
188 struct comp_unit
*next_unit
;
190 /* Likewise, chain the compilation unit read after this one.
191 The comp units are stored in reversed reading order. */
192 struct comp_unit
*prev_unit
;
194 /* Keep the bfd convenient (for memory allocation). */
197 /* The lowest and highest addresses contained in this compilation
198 unit as specified in the compilation unit header. */
199 struct arange arange
;
201 /* The DW_AT_name attribute (for error messages). */
204 /* The abbrev hash table. */
205 struct abbrev_info
**abbrevs
;
207 /* Note that an error was found by comp_unit_find_nearest_line. */
210 /* The DW_AT_comp_dir attribute. */
213 /* TRUE if there is a line number table associated with this comp. unit. */
216 /* Pointer to the current comp_unit so that we can find a given entry
218 bfd_byte
*info_ptr_unit
;
220 /* Pointer to the start of the debug section, for DW_FORM_ref_addr. */
221 bfd_byte
*sec_info_ptr
;
223 /* The offset into .debug_line of the line number table. */
224 unsigned long line_offset
;
226 /* Pointer to the first child die for the comp unit. */
227 bfd_byte
*first_child_die_ptr
;
229 /* The end of the comp unit. */
232 /* The decoded line number, NULL if not yet decoded. */
233 struct line_info_table
*line_table
;
235 /* A list of the functions found in this comp. unit. */
236 struct funcinfo
*function_table
;
238 /* A list of the variables found in this comp. unit. */
239 struct varinfo
*variable_table
;
241 /* Pointer to dwarf2_debug structure. */
242 struct dwarf2_debug
*stash
;
244 /* DWARF format version for this unit - from unit header. */
247 /* Address size for this unit - from unit header. */
248 unsigned char addr_size
;
250 /* Offset size for this unit - from unit header. */
251 unsigned char offset_size
;
253 /* Base address for this unit - from DW_AT_low_pc attribute of
254 DW_TAG_compile_unit DIE */
255 bfd_vma base_address
;
257 /* TRUE if symbols are cached in hash table for faster lookup by name. */
261 /* This data structure holds the information of an abbrev. */
264 unsigned int number
; /* Number identifying abbrev. */
265 enum dwarf_tag tag
; /* DWARF tag. */
266 int has_children
; /* Boolean. */
267 unsigned int num_attrs
; /* Number of attributes. */
268 struct attr_abbrev
*attrs
; /* An array of attribute descriptions. */
269 struct abbrev_info
*next
; /* Next in chain. */
274 enum dwarf_attribute name
;
275 enum dwarf_form form
;
278 #ifndef ABBREV_HASH_SIZE
279 #define ABBREV_HASH_SIZE 121
281 #ifndef ATTR_ALLOC_CHUNK
282 #define ATTR_ALLOC_CHUNK 4
285 /* Variable and function hash tables. This is used to speed up look-up
286 in lookup_symbol_in_var_table() and lookup_symbol_in_function_table().
287 In order to share code between variable and function infos, we use
288 a list of untyped pointer for all variable/function info associated with
289 a symbol. We waste a bit of memory for list with one node but that
290 simplifies the code. */
292 struct info_list_node
294 struct info_list_node
*next
;
298 /* Info hash entry. */
299 struct info_hash_entry
301 struct bfd_hash_entry root
;
302 struct info_list_node
*head
;
305 struct info_hash_table
307 struct bfd_hash_table base
;
310 /* Function to create a new entry in info hash table. */
312 static struct bfd_hash_entry
*
313 info_hash_table_newfunc (struct bfd_hash_entry
*entry
,
314 struct bfd_hash_table
*table
,
317 struct info_hash_entry
*ret
= (struct info_hash_entry
*) entry
;
319 /* Allocate the structure if it has not already been allocated by a
323 ret
= (struct info_hash_entry
*) bfd_hash_allocate (table
,
329 /* Call the allocation method of the base class. */
330 ret
= ((struct info_hash_entry
*)
331 bfd_hash_newfunc ((struct bfd_hash_entry
*) ret
, table
, string
));
333 /* Initialize the local fields here. */
337 return (struct bfd_hash_entry
*) ret
;
340 /* Function to create a new info hash table. It returns a pointer to the
341 newly created table or NULL if there is any error. We need abfd
342 solely for memory allocation. */
344 static struct info_hash_table
*
345 create_info_hash_table (bfd
*abfd
)
347 struct info_hash_table
*hash_table
;
349 hash_table
= (struct info_hash_table
*)
350 bfd_alloc (abfd
, sizeof (struct info_hash_table
));
354 if (!bfd_hash_table_init (&hash_table
->base
, info_hash_table_newfunc
,
355 sizeof (struct info_hash_entry
)))
357 bfd_release (abfd
, hash_table
);
364 /* Insert an info entry into an info hash table. We do not check of
365 duplicate entries. Also, the caller need to guarantee that the
366 right type of info in inserted as info is passed as a void* pointer.
367 This function returns true if there is no error. */
370 insert_info_hash_table (struct info_hash_table
*hash_table
,
375 struct info_hash_entry
*entry
;
376 struct info_list_node
*node
;
378 entry
= (struct info_hash_entry
*) bfd_hash_lookup (&hash_table
->base
,
383 node
= (struct info_list_node
*) bfd_hash_allocate (&hash_table
->base
,
389 node
->next
= entry
->head
;
395 /* Look up an info entry list from an info hash table. Return NULL
398 static struct info_list_node
*
399 lookup_info_hash_table (struct info_hash_table
*hash_table
, const char *key
)
401 struct info_hash_entry
*entry
;
403 entry
= (struct info_hash_entry
*) bfd_hash_lookup (&hash_table
->base
, key
,
405 return entry
? entry
->head
: NULL
;
408 /* Read a section into its appropriate place in the dwarf2_debug
409 struct (indicated by SECTION_BUFFER and SECTION_SIZE). If SYMS is
410 not NULL, use bfd_simple_get_relocated_section_contents to read the
411 section contents, otherwise use bfd_get_section_contents. Fail if
412 the located section does not contain at least OFFSET bytes. */
415 read_section (bfd
* abfd
,
416 const char * section_name
,
417 const char * compressed_section_name
,
420 bfd_byte
** section_buffer
,
421 bfd_size_type
* section_size
)
424 bfd_boolean section_is_compressed
= FALSE
;
426 /* read_section is a noop if the section has already been read. */
427 if (!*section_buffer
)
429 msec
= bfd_get_section_by_name (abfd
, section_name
);
430 if (! msec
&& compressed_section_name
)
432 msec
= bfd_get_section_by_name (abfd
, compressed_section_name
);
433 section_is_compressed
= TRUE
;
437 (*_bfd_error_handler
) (_("Dwarf Error: Can't find %s section."), section_name
);
438 bfd_set_error (bfd_error_bad_value
);
442 *section_size
= msec
->rawsize
? msec
->rawsize
: msec
->size
;
446 = bfd_simple_get_relocated_section_contents (abfd
, msec
, NULL
, syms
);
447 if (! *section_buffer
)
452 *section_buffer
= (bfd_byte
*) bfd_malloc (*section_size
);
453 if (! *section_buffer
)
455 if (! bfd_get_section_contents (abfd
, msec
, *section_buffer
,
460 if (section_is_compressed
)
462 if (! bfd_uncompress_section_contents (section_buffer
, section_size
))
464 (*_bfd_error_handler
) (_("Dwarf Error: unable to decompress %s section."), compressed_section_name
);
465 bfd_set_error (bfd_error_bad_value
);
471 /* It is possible to get a bad value for the offset into the section
472 that the client wants. Validate it here to avoid trouble later. */
473 if (offset
!= 0 && offset
>= *section_size
)
475 (*_bfd_error_handler
) (_("Dwarf Error: Offset (%lu) greater than or equal to %s size (%lu)."),
476 (long) offset
, section_name
, *section_size
);
477 bfd_set_error (bfd_error_bad_value
);
485 The following function up to the END VERBATIM mark are
486 copied directly from dwarf2read.c. */
488 /* Read dwarf information from a buffer. */
491 read_1_byte (bfd
*abfd ATTRIBUTE_UNUSED
, bfd_byte
*buf
)
493 return bfd_get_8 (abfd
, buf
);
497 read_1_signed_byte (bfd
*abfd ATTRIBUTE_UNUSED
, bfd_byte
*buf
)
499 return bfd_get_signed_8 (abfd
, buf
);
503 read_2_bytes (bfd
*abfd
, bfd_byte
*buf
)
505 return bfd_get_16 (abfd
, buf
);
509 read_4_bytes (bfd
*abfd
, bfd_byte
*buf
)
511 return bfd_get_32 (abfd
, buf
);
515 read_8_bytes (bfd
*abfd
, bfd_byte
*buf
)
517 return bfd_get_64 (abfd
, buf
);
521 read_n_bytes (bfd
*abfd ATTRIBUTE_UNUSED
,
523 unsigned int size ATTRIBUTE_UNUSED
)
529 read_string (bfd
*abfd ATTRIBUTE_UNUSED
,
531 unsigned int *bytes_read_ptr
)
533 /* Return a pointer to the embedded string. */
534 char *str
= (char *) buf
;
542 *bytes_read_ptr
= strlen (str
) + 1;
549 read_indirect_string (struct comp_unit
* unit
,
551 unsigned int * bytes_read_ptr
)
554 struct dwarf2_debug
*stash
= unit
->stash
;
557 if (unit
->offset_size
== 4)
558 offset
= read_4_bytes (unit
->abfd
, buf
);
560 offset
= read_8_bytes (unit
->abfd
, buf
);
562 *bytes_read_ptr
= unit
->offset_size
;
564 if (! read_section (unit
->abfd
, ".debug_str", ".zdebug_str",
566 &stash
->dwarf_str_buffer
, &stash
->dwarf_str_size
))
569 str
= (char *) stash
->dwarf_str_buffer
+ offset
;
576 read_address (struct comp_unit
*unit
, bfd_byte
*buf
)
578 int signed_vma
= get_elf_backend_data (unit
->abfd
)->sign_extend_vma
;
582 switch (unit
->addr_size
)
585 return bfd_get_signed_64 (unit
->abfd
, buf
);
587 return bfd_get_signed_32 (unit
->abfd
, buf
);
589 return bfd_get_signed_16 (unit
->abfd
, buf
);
596 switch (unit
->addr_size
)
599 return bfd_get_64 (unit
->abfd
, buf
);
601 return bfd_get_32 (unit
->abfd
, buf
);
603 return bfd_get_16 (unit
->abfd
, buf
);
610 /* Lookup an abbrev_info structure in the abbrev hash table. */
612 static struct abbrev_info
*
613 lookup_abbrev (unsigned int number
, struct abbrev_info
**abbrevs
)
615 unsigned int hash_number
;
616 struct abbrev_info
*abbrev
;
618 hash_number
= number
% ABBREV_HASH_SIZE
;
619 abbrev
= abbrevs
[hash_number
];
623 if (abbrev
->number
== number
)
626 abbrev
= abbrev
->next
;
632 /* In DWARF version 2, the description of the debugging information is
633 stored in a separate .debug_abbrev section. Before we read any
634 dies from a section we read in all abbreviations and install them
637 static struct abbrev_info
**
638 read_abbrevs (bfd
*abfd
, bfd_uint64_t offset
, struct dwarf2_debug
*stash
)
640 struct abbrev_info
**abbrevs
;
641 bfd_byte
*abbrev_ptr
;
642 struct abbrev_info
*cur_abbrev
;
643 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
644 unsigned int abbrev_form
, hash_number
;
647 if (! read_section (abfd
, ".debug_abbrev", ".zdebug_abbrev",
649 &stash
->dwarf_abbrev_buffer
, &stash
->dwarf_abbrev_size
))
652 amt
= sizeof (struct abbrev_info
*) * ABBREV_HASH_SIZE
;
653 abbrevs
= (struct abbrev_info
**) bfd_zalloc (abfd
, amt
);
657 abbrev_ptr
= stash
->dwarf_abbrev_buffer
+ offset
;
658 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
659 abbrev_ptr
+= bytes_read
;
661 /* Loop until we reach an abbrev number of 0. */
662 while (abbrev_number
)
664 amt
= sizeof (struct abbrev_info
);
665 cur_abbrev
= (struct abbrev_info
*) bfd_zalloc (abfd
, amt
);
666 if (cur_abbrev
== NULL
)
669 /* Read in abbrev header. */
670 cur_abbrev
->number
= abbrev_number
;
671 cur_abbrev
->tag
= (enum dwarf_tag
)
672 read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
673 abbrev_ptr
+= bytes_read
;
674 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
677 /* Now read in declarations. */
678 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
679 abbrev_ptr
+= bytes_read
;
680 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
681 abbrev_ptr
+= bytes_read
;
685 if ((cur_abbrev
->num_attrs
% ATTR_ALLOC_CHUNK
) == 0)
687 struct attr_abbrev
*tmp
;
689 amt
= cur_abbrev
->num_attrs
+ ATTR_ALLOC_CHUNK
;
690 amt
*= sizeof (struct attr_abbrev
);
691 tmp
= (struct attr_abbrev
*) bfd_realloc (cur_abbrev
->attrs
, amt
);
696 for (i
= 0; i
< ABBREV_HASH_SIZE
; i
++)
698 struct abbrev_info
*abbrev
= abbrevs
[i
];
702 free (abbrev
->attrs
);
703 abbrev
= abbrev
->next
;
708 cur_abbrev
->attrs
= tmp
;
711 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
].name
712 = (enum dwarf_attribute
) abbrev_name
;
713 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
++].form
714 = (enum dwarf_form
) abbrev_form
;
715 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
716 abbrev_ptr
+= bytes_read
;
717 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
718 abbrev_ptr
+= bytes_read
;
721 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
722 cur_abbrev
->next
= abbrevs
[hash_number
];
723 abbrevs
[hash_number
] = cur_abbrev
;
725 /* Get next abbreviation.
726 Under Irix6 the abbreviations for a compilation unit are not
727 always properly terminated with an abbrev number of 0.
728 Exit loop if we encounter an abbreviation which we have
729 already read (which means we are about to read the abbreviations
730 for the next compile unit) or if the end of the abbreviation
732 if ((unsigned int) (abbrev_ptr
- stash
->dwarf_abbrev_buffer
)
733 >= stash
->dwarf_abbrev_size
)
735 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
736 abbrev_ptr
+= bytes_read
;
737 if (lookup_abbrev (abbrev_number
,abbrevs
) != NULL
)
744 /* Read an attribute value described by an attribute form. */
747 read_attribute_value (struct attribute
*attr
,
749 struct comp_unit
*unit
,
752 bfd
*abfd
= unit
->abfd
;
753 unsigned int bytes_read
;
754 struct dwarf_block
*blk
;
757 attr
->form
= (enum dwarf_form
) form
;
761 case DW_FORM_ref_addr
:
762 /* DW_FORM_ref_addr is an address in DWARF2, and an offset in
764 if (unit
->version
== 3 || unit
->version
== 4)
766 if (unit
->offset_size
== 4)
767 attr
->u
.val
= read_4_bytes (unit
->abfd
, info_ptr
);
769 attr
->u
.val
= read_8_bytes (unit
->abfd
, info_ptr
);
770 info_ptr
+= unit
->offset_size
;
775 attr
->u
.val
= read_address (unit
, info_ptr
);
776 info_ptr
+= unit
->addr_size
;
778 case DW_FORM_sec_offset
:
779 if (unit
->offset_size
== 4)
780 attr
->u
.val
= read_4_bytes (unit
->abfd
, info_ptr
);
782 attr
->u
.val
= read_8_bytes (unit
->abfd
, info_ptr
);
783 info_ptr
+= unit
->offset_size
;
786 amt
= sizeof (struct dwarf_block
);
787 blk
= (struct dwarf_block
*) bfd_alloc (abfd
, amt
);
790 blk
->size
= read_2_bytes (abfd
, info_ptr
);
792 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
793 info_ptr
+= blk
->size
;
797 amt
= sizeof (struct dwarf_block
);
798 blk
= (struct dwarf_block
*) bfd_alloc (abfd
, amt
);
801 blk
->size
= read_4_bytes (abfd
, info_ptr
);
803 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
804 info_ptr
+= blk
->size
;
808 attr
->u
.val
= read_2_bytes (abfd
, info_ptr
);
812 attr
->u
.val
= read_4_bytes (abfd
, info_ptr
);
816 attr
->u
.val
= read_8_bytes (abfd
, info_ptr
);
820 attr
->u
.str
= read_string (abfd
, info_ptr
, &bytes_read
);
821 info_ptr
+= bytes_read
;
824 attr
->u
.str
= read_indirect_string (unit
, info_ptr
, &bytes_read
);
825 info_ptr
+= bytes_read
;
827 case DW_FORM_exprloc
:
829 amt
= sizeof (struct dwarf_block
);
830 blk
= (struct dwarf_block
*) bfd_alloc (abfd
, amt
);
833 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
834 info_ptr
+= bytes_read
;
835 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
836 info_ptr
+= blk
->size
;
840 amt
= sizeof (struct dwarf_block
);
841 blk
= (struct dwarf_block
*) bfd_alloc (abfd
, amt
);
844 blk
->size
= read_1_byte (abfd
, info_ptr
);
846 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
847 info_ptr
+= blk
->size
;
851 attr
->u
.val
= read_1_byte (abfd
, info_ptr
);
855 attr
->u
.val
= read_1_byte (abfd
, info_ptr
);
858 case DW_FORM_flag_present
:
862 attr
->u
.sval
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
863 info_ptr
+= bytes_read
;
866 attr
->u
.val
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
867 info_ptr
+= bytes_read
;
870 attr
->u
.val
= read_1_byte (abfd
, info_ptr
);
874 attr
->u
.val
= read_2_bytes (abfd
, info_ptr
);
878 attr
->u
.val
= read_4_bytes (abfd
, info_ptr
);
882 attr
->u
.val
= read_8_bytes (abfd
, info_ptr
);
885 case DW_FORM_ref_sig8
:
886 attr
->u
.val
= read_8_bytes (abfd
, info_ptr
);
889 case DW_FORM_ref_udata
:
890 attr
->u
.val
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
891 info_ptr
+= bytes_read
;
893 case DW_FORM_indirect
:
894 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
895 info_ptr
+= bytes_read
;
896 info_ptr
= read_attribute_value (attr
, form
, unit
, info_ptr
);
899 (*_bfd_error_handler
) (_("Dwarf Error: Invalid or unhandled FORM value: %u."),
901 bfd_set_error (bfd_error_bad_value
);
907 /* Read an attribute described by an abbreviated attribute. */
910 read_attribute (struct attribute
*attr
,
911 struct attr_abbrev
*abbrev
,
912 struct comp_unit
*unit
,
915 attr
->name
= abbrev
->name
;
916 info_ptr
= read_attribute_value (attr
, abbrev
->form
, unit
, info_ptr
);
920 /* Source line information table routines. */
922 #define FILE_ALLOC_CHUNK 5
923 #define DIR_ALLOC_CHUNK 5
927 struct line_info
* prev_line
;
932 unsigned char op_index
;
933 unsigned char end_sequence
; /* End of (sequential) code sequence. */
947 struct line_sequence
* prev_sequence
;
948 struct line_info
* last_line
; /* Largest VMA. */
951 struct line_info_table
954 unsigned int num_files
;
955 unsigned int num_dirs
;
956 unsigned int num_sequences
;
959 struct fileinfo
* files
;
960 struct line_sequence
* sequences
;
961 struct line_info
* lcl_head
; /* Local head; used in 'add_line_info'. */
964 /* Remember some information about each function. If the function is
965 inlined (DW_TAG_inlined_subroutine) it may have two additional
966 attributes, DW_AT_call_file and DW_AT_call_line, which specify the
967 source code location where this function was inlined. */
971 struct funcinfo
*prev_func
; /* Pointer to previous function in list of all functions */
972 struct funcinfo
*caller_func
; /* Pointer to function one scope higher */
973 char *caller_file
; /* Source location file name where caller_func inlines this func */
974 int caller_line
; /* Source location line number where caller_func inlines this func */
975 char *file
; /* Source location file name */
976 int line
; /* Source location line number */
979 struct arange arange
;
980 asection
*sec
; /* Where the symbol is defined */
985 /* Pointer to previous variable in list of all variables */
986 struct varinfo
*prev_var
;
987 /* Source location file name */
989 /* Source location line number */
994 /* Where the symbol is defined */
996 /* Is this a stack variable? */
997 unsigned int stack
: 1;
1000 /* Return TRUE if NEW_LINE should sort after LINE. */
1002 static inline bfd_boolean
1003 new_line_sorts_after (struct line_info
*new_line
, struct line_info
*line
)
1005 return (new_line
->address
> line
->address
1006 || (new_line
->address
== line
->address
1007 && (new_line
->op_index
> line
->op_index
1008 || (new_line
->op_index
== line
->op_index
1009 && new_line
->end_sequence
< line
->end_sequence
))));
1013 /* Adds a new entry to the line_info list in the line_info_table, ensuring
1014 that the list is sorted. Note that the line_info list is sorted from
1015 highest to lowest VMA (with possible duplicates); that is,
1016 line_info->prev_line always accesses an equal or smaller VMA. */
1019 add_line_info (struct line_info_table
*table
,
1021 unsigned char op_index
,
1024 unsigned int column
,
1027 bfd_size_type amt
= sizeof (struct line_info
);
1028 struct line_sequence
* seq
= table
->sequences
;
1029 struct line_info
* info
= (struct line_info
*) bfd_alloc (table
->abfd
, amt
);
1034 /* Set member data of 'info'. */
1035 info
->address
= address
;
1036 info
->op_index
= op_index
;
1038 info
->column
= column
;
1039 info
->end_sequence
= end_sequence
;
1041 if (filename
&& filename
[0])
1043 info
->filename
= (char *) bfd_alloc (table
->abfd
, strlen (filename
) + 1);
1044 if (info
->filename
== NULL
)
1046 strcpy (info
->filename
, filename
);
1049 info
->filename
= NULL
;
1051 /* Find the correct location for 'info'. Normally we will receive
1052 new line_info data 1) in order and 2) with increasing VMAs.
1053 However some compilers break the rules (cf. decode_line_info) and
1054 so we include some heuristics for quickly finding the correct
1055 location for 'info'. In particular, these heuristics optimize for
1056 the common case in which the VMA sequence that we receive is a
1057 list of locally sorted VMAs such as
1058 p...z a...j (where a < j < p < z)
1060 Note: table->lcl_head is used to head an *actual* or *possible*
1061 sub-sequence within the list (such as a...j) that is not directly
1062 headed by table->last_line
1064 Note: we may receive duplicate entries from 'decode_line_info'. */
1067 && seq
->last_line
->address
== address
1068 && seq
->last_line
->op_index
== op_index
1069 && seq
->last_line
->end_sequence
== end_sequence
)
1071 /* We only keep the last entry with the same address and end
1072 sequence. See PR ld/4986. */
1073 if (table
->lcl_head
== seq
->last_line
)
1074 table
->lcl_head
= info
;
1075 info
->prev_line
= seq
->last_line
->prev_line
;
1076 seq
->last_line
= info
;
1078 else if (!seq
|| seq
->last_line
->end_sequence
)
1080 /* Start a new line sequence. */
1081 amt
= sizeof (struct line_sequence
);
1082 seq
= (struct line_sequence
*) bfd_malloc (amt
);
1085 seq
->low_pc
= address
;
1086 seq
->prev_sequence
= table
->sequences
;
1087 seq
->last_line
= info
;
1088 table
->lcl_head
= info
;
1089 table
->sequences
= seq
;
1090 table
->num_sequences
++;
1092 else if (new_line_sorts_after (info
, seq
->last_line
))
1094 /* Normal case: add 'info' to the beginning of the current sequence. */
1095 info
->prev_line
= seq
->last_line
;
1096 seq
->last_line
= info
;
1098 /* lcl_head: initialize to head a *possible* sequence at the end. */
1099 if (!table
->lcl_head
)
1100 table
->lcl_head
= info
;
1102 else if (!new_line_sorts_after (info
, table
->lcl_head
)
1103 && (!table
->lcl_head
->prev_line
1104 || new_line_sorts_after (info
, table
->lcl_head
->prev_line
)))
1106 /* Abnormal but easy: lcl_head is the head of 'info'. */
1107 info
->prev_line
= table
->lcl_head
->prev_line
;
1108 table
->lcl_head
->prev_line
= info
;
1112 /* Abnormal and hard: Neither 'last_line' nor 'lcl_head'
1113 are valid heads for 'info'. Reset 'lcl_head'. */
1114 struct line_info
* li2
= seq
->last_line
; /* Always non-NULL. */
1115 struct line_info
* li1
= li2
->prev_line
;
1119 if (!new_line_sorts_after (info
, li2
)
1120 && new_line_sorts_after (info
, li1
))
1123 li2
= li1
; /* always non-NULL */
1124 li1
= li1
->prev_line
;
1126 table
->lcl_head
= li2
;
1127 info
->prev_line
= table
->lcl_head
->prev_line
;
1128 table
->lcl_head
->prev_line
= info
;
1129 if (address
< seq
->low_pc
)
1130 seq
->low_pc
= address
;
1135 /* Extract a fully qualified filename from a line info table.
1136 The returned string has been malloc'ed and it is the caller's
1137 responsibility to free it. */
1140 concat_filename (struct line_info_table
*table
, unsigned int file
)
1144 if (file
- 1 >= table
->num_files
)
1146 /* FILE == 0 means unknown. */
1148 (*_bfd_error_handler
)
1149 (_("Dwarf Error: mangled line number section (bad file number)."));
1150 return strdup ("<unknown>");
1153 filename
= table
->files
[file
- 1].name
;
1155 if (!IS_ABSOLUTE_PATH (filename
))
1157 char *dir_name
= NULL
;
1158 char *subdir_name
= NULL
;
1162 if (table
->files
[file
- 1].dir
)
1163 subdir_name
= table
->dirs
[table
->files
[file
- 1].dir
- 1];
1165 if (!subdir_name
|| !IS_ABSOLUTE_PATH (subdir_name
))
1166 dir_name
= table
->comp_dir
;
1170 dir_name
= subdir_name
;
1175 return strdup (filename
);
1177 len
= strlen (dir_name
) + strlen (filename
) + 2;
1181 len
+= strlen (subdir_name
) + 1;
1182 name
= (char *) bfd_malloc (len
);
1184 sprintf (name
, "%s/%s/%s", dir_name
, subdir_name
, filename
);
1188 name
= (char *) bfd_malloc (len
);
1190 sprintf (name
, "%s/%s", dir_name
, filename
);
1196 return strdup (filename
);
1200 arange_add (bfd
*abfd
, struct arange
*first_arange
,
1201 bfd_vma low_pc
, bfd_vma high_pc
)
1203 struct arange
*arange
;
1205 /* If the first arange is empty, use it. */
1206 if (first_arange
->high
== 0)
1208 first_arange
->low
= low_pc
;
1209 first_arange
->high
= high_pc
;
1213 /* Next see if we can cheaply extend an existing range. */
1214 arange
= first_arange
;
1217 if (low_pc
== arange
->high
)
1219 arange
->high
= high_pc
;
1222 if (high_pc
== arange
->low
)
1224 arange
->low
= low_pc
;
1227 arange
= arange
->next
;
1231 /* Need to allocate a new arange and insert it into the arange list.
1232 Order isn't significant, so just insert after the first arange. */
1233 arange
= (struct arange
*) bfd_zalloc (abfd
, sizeof (*arange
));
1236 arange
->low
= low_pc
;
1237 arange
->high
= high_pc
;
1238 arange
->next
= first_arange
->next
;
1239 first_arange
->next
= arange
;
1243 /* Compare function for line sequences. */
1246 compare_sequences (const void* a
, const void* b
)
1248 const struct line_sequence
* seq1
= a
;
1249 const struct line_sequence
* seq2
= b
;
1251 /* Sort by low_pc as the primary key. */
1252 if (seq1
->low_pc
< seq2
->low_pc
)
1254 if (seq1
->low_pc
> seq2
->low_pc
)
1257 /* If low_pc values are equal, sort in reverse order of
1258 high_pc, so that the largest region comes first. */
1259 if (seq1
->last_line
->address
< seq2
->last_line
->address
)
1261 if (seq1
->last_line
->address
> seq2
->last_line
->address
)
1264 if (seq1
->last_line
->op_index
< seq2
->last_line
->op_index
)
1266 if (seq1
->last_line
->op_index
> seq2
->last_line
->op_index
)
1272 /* Sort the line sequences for quick lookup. */
1275 sort_line_sequences (struct line_info_table
* table
)
1278 struct line_sequence
* sequences
;
1279 struct line_sequence
* seq
;
1281 unsigned int num_sequences
= table
->num_sequences
;
1282 bfd_vma last_high_pc
;
1284 if (num_sequences
== 0)
1287 /* Allocate space for an array of sequences. */
1288 amt
= sizeof (struct line_sequence
) * num_sequences
;
1289 sequences
= (struct line_sequence
*) bfd_alloc (table
->abfd
, amt
);
1290 if (sequences
== NULL
)
1293 /* Copy the linked list into the array, freeing the original nodes. */
1294 seq
= table
->sequences
;
1295 for (n
= 0; n
< num_sequences
; n
++)
1297 struct line_sequence
* last_seq
= seq
;
1300 sequences
[n
].low_pc
= seq
->low_pc
;
1301 sequences
[n
].prev_sequence
= NULL
;
1302 sequences
[n
].last_line
= seq
->last_line
;
1303 seq
= seq
->prev_sequence
;
1306 BFD_ASSERT (seq
== NULL
);
1308 qsort (sequences
, n
, sizeof (struct line_sequence
), compare_sequences
);
1310 /* Make the list binary-searchable by trimming overlapping entries
1311 and removing nested entries. */
1313 last_high_pc
= sequences
[0].last_line
->address
;
1314 for (n
= 1; n
< table
->num_sequences
; n
++)
1316 if (sequences
[n
].low_pc
< last_high_pc
)
1318 if (sequences
[n
].last_line
->address
<= last_high_pc
)
1319 /* Skip nested entries. */
1322 /* Trim overlapping entries. */
1323 sequences
[n
].low_pc
= last_high_pc
;
1325 last_high_pc
= sequences
[n
].last_line
->address
;
1326 if (n
> num_sequences
)
1328 /* Close up the gap. */
1329 sequences
[num_sequences
].low_pc
= sequences
[n
].low_pc
;
1330 sequences
[num_sequences
].last_line
= sequences
[n
].last_line
;
1335 table
->sequences
= sequences
;
1336 table
->num_sequences
= num_sequences
;
1340 /* Decode the line number information for UNIT. */
1342 static struct line_info_table
*
1343 decode_line_info (struct comp_unit
*unit
, struct dwarf2_debug
*stash
)
1345 bfd
*abfd
= unit
->abfd
;
1346 struct line_info_table
* table
;
1349 struct line_head lh
;
1350 unsigned int i
, bytes_read
, offset_size
;
1351 char *cur_file
, *cur_dir
;
1352 unsigned char op_code
, extended_op
, adj_opcode
;
1355 if (! read_section (abfd
, ".debug_line", ".zdebug_line",
1356 stash
->syms
, unit
->line_offset
,
1357 &stash
->dwarf_line_buffer
, &stash
->dwarf_line_size
))
1360 amt
= sizeof (struct line_info_table
);
1361 table
= (struct line_info_table
*) bfd_alloc (abfd
, amt
);
1365 table
->comp_dir
= unit
->comp_dir
;
1367 table
->num_files
= 0;
1368 table
->files
= NULL
;
1370 table
->num_dirs
= 0;
1373 table
->num_sequences
= 0;
1374 table
->sequences
= NULL
;
1376 table
->lcl_head
= NULL
;
1378 line_ptr
= stash
->dwarf_line_buffer
+ unit
->line_offset
;
1380 /* Read in the prologue. */
1381 lh
.total_length
= read_4_bytes (abfd
, line_ptr
);
1384 if (lh
.total_length
== 0xffffffff)
1386 lh
.total_length
= read_8_bytes (abfd
, line_ptr
);
1390 else if (lh
.total_length
== 0 && unit
->addr_size
== 8)
1392 /* Handle (non-standard) 64-bit DWARF2 formats. */
1393 lh
.total_length
= read_4_bytes (abfd
, line_ptr
);
1397 line_end
= line_ptr
+ lh
.total_length
;
1398 lh
.version
= read_2_bytes (abfd
, line_ptr
);
1399 if (lh
.version
< 2 || lh
.version
> 4)
1401 (*_bfd_error_handler
)
1402 (_("Dwarf Error: Unhandled .debug_line version %d."), lh
.version
);
1403 bfd_set_error (bfd_error_bad_value
);
1407 if (offset_size
== 4)
1408 lh
.prologue_length
= read_4_bytes (abfd
, line_ptr
);
1410 lh
.prologue_length
= read_8_bytes (abfd
, line_ptr
);
1411 line_ptr
+= offset_size
;
1412 lh
.minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
1414 if (lh
.version
>= 4)
1416 lh
.maximum_ops_per_insn
= read_1_byte (abfd
, line_ptr
);
1420 lh
.maximum_ops_per_insn
= 1;
1421 if (lh
.maximum_ops_per_insn
== 0)
1423 (*_bfd_error_handler
)
1424 (_("Dwarf Error: Invalid maximum operations per instruction."));
1425 bfd_set_error (bfd_error_bad_value
);
1428 lh
.default_is_stmt
= read_1_byte (abfd
, line_ptr
);
1430 lh
.line_base
= read_1_signed_byte (abfd
, line_ptr
);
1432 lh
.line_range
= read_1_byte (abfd
, line_ptr
);
1434 lh
.opcode_base
= read_1_byte (abfd
, line_ptr
);
1436 amt
= lh
.opcode_base
* sizeof (unsigned char);
1437 lh
.standard_opcode_lengths
= (unsigned char *) bfd_alloc (abfd
, amt
);
1439 lh
.standard_opcode_lengths
[0] = 1;
1441 for (i
= 1; i
< lh
.opcode_base
; ++i
)
1443 lh
.standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
1447 /* Read directory table. */
1448 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
1450 line_ptr
+= bytes_read
;
1452 if ((table
->num_dirs
% DIR_ALLOC_CHUNK
) == 0)
1456 amt
= table
->num_dirs
+ DIR_ALLOC_CHUNK
;
1457 amt
*= sizeof (char *);
1459 tmp
= (char **) bfd_realloc (table
->dirs
, amt
);
1465 table
->dirs
[table
->num_dirs
++] = cur_dir
;
1468 line_ptr
+= bytes_read
;
1470 /* Read file name table. */
1471 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
1473 line_ptr
+= bytes_read
;
1475 if ((table
->num_files
% FILE_ALLOC_CHUNK
) == 0)
1477 struct fileinfo
*tmp
;
1479 amt
= table
->num_files
+ FILE_ALLOC_CHUNK
;
1480 amt
*= sizeof (struct fileinfo
);
1482 tmp
= (struct fileinfo
*) bfd_realloc (table
->files
, amt
);
1488 table
->files
[table
->num_files
].name
= cur_file
;
1489 table
->files
[table
->num_files
].dir
=
1490 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
1491 line_ptr
+= bytes_read
;
1492 table
->files
[table
->num_files
].time
=
1493 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
1494 line_ptr
+= bytes_read
;
1495 table
->files
[table
->num_files
].size
=
1496 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
1497 line_ptr
+= bytes_read
;
1501 line_ptr
+= bytes_read
;
1503 /* Read the statement sequences until there's nothing left. */
1504 while (line_ptr
< line_end
)
1506 /* State machine registers. */
1507 bfd_vma address
= 0;
1508 unsigned char op_index
= 0;
1509 char * filename
= table
->num_files
? concat_filename (table
, 1) : NULL
;
1510 unsigned int line
= 1;
1511 unsigned int column
= 0;
1512 int is_stmt
= lh
.default_is_stmt
;
1513 int end_sequence
= 0;
1514 /* eraxxon@alumni.rice.edu: Against the DWARF2 specs, some
1515 compilers generate address sequences that are wildly out of
1516 order using DW_LNE_set_address (e.g. Intel C++ 6.0 compiler
1517 for ia64-Linux). Thus, to determine the low and high
1518 address, we must compare on every DW_LNS_copy, etc. */
1519 bfd_vma low_pc
= (bfd_vma
) -1;
1520 bfd_vma high_pc
= 0;
1522 /* Decode the table. */
1523 while (! end_sequence
)
1525 op_code
= read_1_byte (abfd
, line_ptr
);
1528 if (op_code
>= lh
.opcode_base
)
1530 /* Special operand. */
1531 adj_opcode
= op_code
- lh
.opcode_base
;
1532 if (lh
.maximum_ops_per_insn
== 1)
1533 address
+= (adj_opcode
/ lh
.line_range
)
1534 * lh
.minimum_instruction_length
;
1537 address
+= ((op_index
+ (adj_opcode
/ lh
.line_range
))
1538 / lh
.maximum_ops_per_insn
)
1539 * lh
.minimum_instruction_length
;
1540 op_index
= (op_index
+ (adj_opcode
/ lh
.line_range
))
1541 % lh
.maximum_ops_per_insn
;
1543 line
+= lh
.line_base
+ (adj_opcode
% lh
.line_range
);
1544 /* Append row to matrix using current values. */
1545 if (!add_line_info (table
, address
, op_index
, filename
,
1548 if (address
< low_pc
)
1550 if (address
> high_pc
)
1553 else switch (op_code
)
1555 case DW_LNS_extended_op
:
1556 /* Ignore length. */
1558 extended_op
= read_1_byte (abfd
, line_ptr
);
1561 switch (extended_op
)
1563 case DW_LNE_end_sequence
:
1565 if (!add_line_info (table
, address
, op_index
, filename
,
1566 line
, column
, end_sequence
))
1568 if (address
< low_pc
)
1570 if (address
> high_pc
)
1572 if (!arange_add (unit
->abfd
, &unit
->arange
, low_pc
, high_pc
))
1575 case DW_LNE_set_address
:
1576 address
= read_address (unit
, line_ptr
);
1578 line_ptr
+= unit
->addr_size
;
1580 case DW_LNE_define_file
:
1581 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
1582 line_ptr
+= bytes_read
;
1583 if ((table
->num_files
% FILE_ALLOC_CHUNK
) == 0)
1585 struct fileinfo
*tmp
;
1587 amt
= table
->num_files
+ FILE_ALLOC_CHUNK
;
1588 amt
*= sizeof (struct fileinfo
);
1589 tmp
= (struct fileinfo
*) bfd_realloc (table
->files
, amt
);
1594 table
->files
[table
->num_files
].name
= cur_file
;
1595 table
->files
[table
->num_files
].dir
=
1596 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
1597 line_ptr
+= bytes_read
;
1598 table
->files
[table
->num_files
].time
=
1599 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
1600 line_ptr
+= bytes_read
;
1601 table
->files
[table
->num_files
].size
=
1602 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
1603 line_ptr
+= bytes_read
;
1606 case DW_LNE_set_discriminator
:
1607 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
1608 line_ptr
+= bytes_read
;
1611 (*_bfd_error_handler
) (_("Dwarf Error: mangled line number section."));
1612 bfd_set_error (bfd_error_bad_value
);
1614 if (filename
!= NULL
)
1620 if (!add_line_info (table
, address
, op_index
,
1621 filename
, line
, column
, 0))
1623 if (address
< low_pc
)
1625 if (address
> high_pc
)
1628 case DW_LNS_advance_pc
:
1629 if (lh
.maximum_ops_per_insn
== 1)
1630 address
+= lh
.minimum_instruction_length
1631 * read_unsigned_leb128 (abfd
, line_ptr
,
1635 bfd_vma adjust
= read_unsigned_leb128 (abfd
, line_ptr
,
1637 address
= ((op_index
+ adjust
) / lh
.maximum_ops_per_insn
)
1638 * lh
.minimum_instruction_length
;
1639 op_index
= (op_index
+ adjust
) % lh
.maximum_ops_per_insn
;
1641 line_ptr
+= bytes_read
;
1643 case DW_LNS_advance_line
:
1644 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
1645 line_ptr
+= bytes_read
;
1647 case DW_LNS_set_file
:
1651 /* The file and directory tables are 0
1652 based, the references are 1 based. */
1653 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
1654 line_ptr
+= bytes_read
;
1657 filename
= concat_filename (table
, file
);
1660 case DW_LNS_set_column
:
1661 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
1662 line_ptr
+= bytes_read
;
1664 case DW_LNS_negate_stmt
:
1665 is_stmt
= (!is_stmt
);
1667 case DW_LNS_set_basic_block
:
1669 case DW_LNS_const_add_pc
:
1670 if (lh
.maximum_ops_per_insn
== 1)
1671 address
+= lh
.minimum_instruction_length
1672 * ((255 - lh
.opcode_base
) / lh
.line_range
);
1675 bfd_vma adjust
= ((255 - lh
.opcode_base
) / lh
.line_range
);
1676 address
+= lh
.minimum_instruction_length
1677 * ((op_index
+ adjust
) / lh
.maximum_ops_per_insn
);
1678 op_index
= (op_index
+ adjust
) % lh
.maximum_ops_per_insn
;
1681 case DW_LNS_fixed_advance_pc
:
1682 address
+= read_2_bytes (abfd
, line_ptr
);
1687 /* Unknown standard opcode, ignore it. */
1688 for (i
= 0; i
< lh
.standard_opcode_lengths
[op_code
]; i
++)
1690 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
1691 line_ptr
+= bytes_read
;
1701 if (sort_line_sequences (table
))
1705 if (table
->sequences
!= NULL
)
1706 free (table
->sequences
);
1707 if (table
->files
!= NULL
)
1708 free (table
->files
);
1709 if (table
->dirs
!= NULL
)
1714 /* If ADDR is within TABLE set the output parameters and return TRUE,
1715 otherwise return FALSE. The output parameters, FILENAME_PTR and
1716 LINENUMBER_PTR, are pointers to the objects to be filled in. */
1719 lookup_address_in_line_info_table (struct line_info_table
*table
,
1721 const char **filename_ptr
,
1722 unsigned int *linenumber_ptr
)
1724 struct line_sequence
*seq
= NULL
;
1725 struct line_info
*each_line
;
1728 /* Binary search the array of sequences. */
1730 high
= table
->num_sequences
;
1733 mid
= (low
+ high
) / 2;
1734 seq
= &table
->sequences
[mid
];
1735 if (addr
< seq
->low_pc
)
1737 else if (addr
>= seq
->last_line
->address
)
1743 if (seq
&& addr
>= seq
->low_pc
&& addr
< seq
->last_line
->address
)
1745 /* Note: seq->last_line should be a descendingly sorted list. */
1746 for (each_line
= seq
->last_line
;
1748 each_line
= each_line
->prev_line
)
1749 if (addr
>= each_line
->address
)
1753 && !(each_line
->end_sequence
|| each_line
== seq
->last_line
))
1755 *filename_ptr
= each_line
->filename
;
1756 *linenumber_ptr
= each_line
->line
;
1761 *filename_ptr
= NULL
;
1765 /* Read in the .debug_ranges section for future reference. */
1768 read_debug_ranges (struct comp_unit
*unit
)
1770 struct dwarf2_debug
*stash
= unit
->stash
;
1771 return read_section (unit
->abfd
, ".debug_ranges", ".zdebug_ranges",
1773 &stash
->dwarf_ranges_buffer
, &stash
->dwarf_ranges_size
);
1776 /* Function table functions. */
1778 /* If ADDR is within TABLE, set FUNCTIONNAME_PTR, and return TRUE.
1779 Note that we need to find the function that has the smallest
1780 range that contains ADDR, to handle inlined functions without
1781 depending upon them being ordered in TABLE by increasing range. */
1784 lookup_address_in_function_table (struct comp_unit
*unit
,
1786 struct funcinfo
**function_ptr
,
1787 const char **functionname_ptr
)
1789 struct funcinfo
* each_func
;
1790 struct funcinfo
* best_fit
= NULL
;
1791 struct arange
*arange
;
1793 for (each_func
= unit
->function_table
;
1795 each_func
= each_func
->prev_func
)
1797 for (arange
= &each_func
->arange
;
1799 arange
= arange
->next
)
1801 if (addr
>= arange
->low
&& addr
< arange
->high
)
1804 ((arange
->high
- arange
->low
) < (best_fit
->arange
.high
- best_fit
->arange
.low
)))
1805 best_fit
= each_func
;
1812 *functionname_ptr
= best_fit
->name
;
1813 *function_ptr
= best_fit
;
1822 /* If SYM at ADDR is within function table of UNIT, set FILENAME_PTR
1823 and LINENUMBER_PTR, and return TRUE. */
1826 lookup_symbol_in_function_table (struct comp_unit
*unit
,
1829 const char **filename_ptr
,
1830 unsigned int *linenumber_ptr
)
1832 struct funcinfo
* each_func
;
1833 struct funcinfo
* best_fit
= NULL
;
1834 struct arange
*arange
;
1835 const char *name
= bfd_asymbol_name (sym
);
1836 asection
*sec
= bfd_get_section (sym
);
1838 for (each_func
= unit
->function_table
;
1840 each_func
= each_func
->prev_func
)
1842 for (arange
= &each_func
->arange
;
1844 arange
= arange
->next
)
1846 if ((!each_func
->sec
|| each_func
->sec
== sec
)
1847 && addr
>= arange
->low
1848 && addr
< arange
->high
1850 && strcmp (name
, each_func
->name
) == 0
1852 || ((arange
->high
- arange
->low
)
1853 < (best_fit
->arange
.high
- best_fit
->arange
.low
))))
1854 best_fit
= each_func
;
1860 best_fit
->sec
= sec
;
1861 *filename_ptr
= best_fit
->file
;
1862 *linenumber_ptr
= best_fit
->line
;
1869 /* Variable table functions. */
1871 /* If SYM is within variable table of UNIT, set FILENAME_PTR and
1872 LINENUMBER_PTR, and return TRUE. */
1875 lookup_symbol_in_variable_table (struct comp_unit
*unit
,
1878 const char **filename_ptr
,
1879 unsigned int *linenumber_ptr
)
1881 const char *name
= bfd_asymbol_name (sym
);
1882 asection
*sec
= bfd_get_section (sym
);
1883 struct varinfo
* each
;
1885 for (each
= unit
->variable_table
; each
; each
= each
->prev_var
)
1886 if (each
->stack
== 0
1887 && each
->file
!= NULL
1888 && each
->name
!= NULL
1889 && each
->addr
== addr
1890 && (!each
->sec
|| each
->sec
== sec
)
1891 && strcmp (name
, each
->name
) == 0)
1897 *filename_ptr
= each
->file
;
1898 *linenumber_ptr
= each
->line
;
1906 find_abstract_instance_name (struct comp_unit
*unit
,
1907 struct attribute
*attr_ptr
)
1909 bfd
*abfd
= unit
->abfd
;
1911 unsigned int abbrev_number
, bytes_read
, i
;
1912 struct abbrev_info
*abbrev
;
1913 bfd_uint64_t die_ref
= attr_ptr
->u
.val
;
1914 struct attribute attr
;
1917 /* DW_FORM_ref_addr can reference an entry in a different CU. It
1918 is an offset from the .debug_info section, not the current CU. */
1919 if (attr_ptr
->form
== DW_FORM_ref_addr
)
1921 /* We only support DW_FORM_ref_addr within the same file, so
1922 any relocations should be resolved already. */
1926 info_ptr
= unit
->sec_info_ptr
+ die_ref
;
1929 info_ptr
= unit
->info_ptr_unit
+ die_ref
;
1930 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
1931 info_ptr
+= bytes_read
;
1935 abbrev
= lookup_abbrev (abbrev_number
, unit
->abbrevs
);
1938 (*_bfd_error_handler
) (_("Dwarf Error: Could not find abbrev number %u."),
1940 bfd_set_error (bfd_error_bad_value
);
1944 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
1946 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], unit
,
1948 if (info_ptr
== NULL
)
1953 /* Prefer DW_AT_MIPS_linkage_name or DW_AT_linkage_name
1958 case DW_AT_specification
:
1959 name
= find_abstract_instance_name (unit
, &attr
);
1961 case DW_AT_linkage_name
:
1962 case DW_AT_MIPS_linkage_name
:
1975 read_rangelist (struct comp_unit
*unit
, struct arange
*arange
,
1976 bfd_uint64_t offset
)
1978 bfd_byte
*ranges_ptr
;
1979 bfd_vma base_address
= unit
->base_address
;
1981 if (! unit
->stash
->dwarf_ranges_buffer
)
1983 if (! read_debug_ranges (unit
))
1986 ranges_ptr
= unit
->stash
->dwarf_ranges_buffer
+ offset
;
1993 low_pc
= read_address (unit
, ranges_ptr
);
1994 ranges_ptr
+= unit
->addr_size
;
1995 high_pc
= read_address (unit
, ranges_ptr
);
1996 ranges_ptr
+= unit
->addr_size
;
1998 if (low_pc
== 0 && high_pc
== 0)
2000 if (low_pc
== -1UL && high_pc
!= -1UL)
2001 base_address
= high_pc
;
2004 if (!arange_add (unit
->abfd
, arange
,
2005 base_address
+ low_pc
, base_address
+ high_pc
))
2012 /* DWARF2 Compilation unit functions. */
2014 /* Scan over each die in a comp. unit looking for functions to add
2015 to the function table and variables to the variable table. */
2018 scan_unit_for_symbols (struct comp_unit
*unit
)
2020 bfd
*abfd
= unit
->abfd
;
2021 bfd_byte
*info_ptr
= unit
->first_child_die_ptr
;
2022 int nesting_level
= 1;
2023 struct funcinfo
**nested_funcs
;
2024 int nested_funcs_size
;
2026 /* Maintain a stack of in-scope functions and inlined functions, which we
2027 can use to set the caller_func field. */
2028 nested_funcs_size
= 32;
2029 nested_funcs
= (struct funcinfo
**)
2030 bfd_malloc (nested_funcs_size
* sizeof (struct funcinfo
*));
2031 if (nested_funcs
== NULL
)
2033 nested_funcs
[nesting_level
] = 0;
2035 while (nesting_level
)
2037 unsigned int abbrev_number
, bytes_read
, i
;
2038 struct abbrev_info
*abbrev
;
2039 struct attribute attr
;
2040 struct funcinfo
*func
;
2041 struct varinfo
*var
;
2043 bfd_vma high_pc
= 0;
2045 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2046 info_ptr
+= bytes_read
;
2048 if (! abbrev_number
)
2054 abbrev
= lookup_abbrev (abbrev_number
,unit
->abbrevs
);
2057 (*_bfd_error_handler
)
2058 (_("Dwarf Error: Could not find abbrev number %u."),
2060 bfd_set_error (bfd_error_bad_value
);
2065 if (abbrev
->tag
== DW_TAG_subprogram
2066 || abbrev
->tag
== DW_TAG_entry_point
2067 || abbrev
->tag
== DW_TAG_inlined_subroutine
)
2069 bfd_size_type amt
= sizeof (struct funcinfo
);
2070 func
= (struct funcinfo
*) bfd_zalloc (abfd
, amt
);
2073 func
->tag
= abbrev
->tag
;
2074 func
->prev_func
= unit
->function_table
;
2075 unit
->function_table
= func
;
2076 BFD_ASSERT (!unit
->cached
);
2078 if (func
->tag
== DW_TAG_inlined_subroutine
)
2079 for (i
= nesting_level
- 1; i
>= 1; i
--)
2080 if (nested_funcs
[i
])
2082 func
->caller_func
= nested_funcs
[i
];
2085 nested_funcs
[nesting_level
] = func
;
2090 if (abbrev
->tag
== DW_TAG_variable
)
2092 bfd_size_type amt
= sizeof (struct varinfo
);
2093 var
= (struct varinfo
*) bfd_zalloc (abfd
, amt
);
2096 var
->tag
= abbrev
->tag
;
2098 var
->prev_var
= unit
->variable_table
;
2099 unit
->variable_table
= var
;
2100 BFD_ASSERT (!unit
->cached
);
2103 /* No inline function in scope at this nesting level. */
2104 nested_funcs
[nesting_level
] = 0;
2107 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
2109 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], unit
, info_ptr
);
2110 if (info_ptr
== NULL
)
2117 case DW_AT_call_file
:
2118 func
->caller_file
= concat_filename (unit
->line_table
,
2122 case DW_AT_call_line
:
2123 func
->caller_line
= attr
.u
.val
;
2126 case DW_AT_abstract_origin
:
2127 func
->name
= find_abstract_instance_name (unit
, &attr
);
2131 /* Prefer DW_AT_MIPS_linkage_name or DW_AT_linkage_name
2133 if (func
->name
== NULL
)
2134 func
->name
= attr
.u
.str
;
2137 case DW_AT_linkage_name
:
2138 case DW_AT_MIPS_linkage_name
:
2139 func
->name
= attr
.u
.str
;
2143 low_pc
= attr
.u
.val
;
2147 high_pc
= attr
.u
.val
;
2151 if (!read_rangelist (unit
, &func
->arange
, attr
.u
.val
))
2155 case DW_AT_decl_file
:
2156 func
->file
= concat_filename (unit
->line_table
,
2160 case DW_AT_decl_line
:
2161 func
->line
= attr
.u
.val
;
2173 var
->name
= attr
.u
.str
;
2176 case DW_AT_decl_file
:
2177 var
->file
= concat_filename (unit
->line_table
,
2181 case DW_AT_decl_line
:
2182 var
->line
= attr
.u
.val
;
2185 case DW_AT_external
:
2186 if (attr
.u
.val
!= 0)
2190 case DW_AT_location
:
2194 case DW_FORM_block1
:
2195 case DW_FORM_block2
:
2196 case DW_FORM_block4
:
2197 case DW_FORM_exprloc
:
2198 if (*attr
.u
.blk
->data
== DW_OP_addr
)
2202 /* Verify that DW_OP_addr is the only opcode in the
2203 location, in which case the block size will be 1
2204 plus the address size. */
2205 /* ??? For TLS variables, gcc can emit
2206 DW_OP_addr <addr> DW_OP_GNU_push_tls_address
2207 which we don't handle here yet. */
2208 if (attr
.u
.blk
->size
== unit
->addr_size
+ 1U)
2209 var
->addr
= bfd_get (unit
->addr_size
* 8,
2211 attr
.u
.blk
->data
+ 1);
2226 if (func
&& high_pc
!= 0)
2228 if (!arange_add (unit
->abfd
, &func
->arange
, low_pc
, high_pc
))
2232 if (abbrev
->has_children
)
2236 if (nesting_level
>= nested_funcs_size
)
2238 struct funcinfo
**tmp
;
2240 nested_funcs_size
*= 2;
2241 tmp
= (struct funcinfo
**)
2242 bfd_realloc (nested_funcs
,
2243 (nested_funcs_size
* sizeof (struct funcinfo
*)));
2248 nested_funcs
[nesting_level
] = 0;
2252 free (nested_funcs
);
2256 free (nested_funcs
);
2260 /* Parse a DWARF2 compilation unit starting at INFO_PTR. This
2261 includes the compilation unit header that proceeds the DIE's, but
2262 does not include the length field that precedes each compilation
2263 unit header. END_PTR points one past the end of this comp unit.
2264 OFFSET_SIZE is the size of DWARF2 offsets (either 4 or 8 bytes).
2266 This routine does not read the whole compilation unit; only enough
2267 to get to the line number information for the compilation unit. */
2269 static struct comp_unit
*
2270 parse_comp_unit (struct dwarf2_debug
*stash
,
2271 bfd_vma unit_length
,
2272 bfd_byte
*info_ptr_unit
,
2273 unsigned int offset_size
)
2275 struct comp_unit
* unit
;
2276 unsigned int version
;
2277 bfd_uint64_t abbrev_offset
= 0;
2278 unsigned int addr_size
;
2279 struct abbrev_info
** abbrevs
;
2280 unsigned int abbrev_number
, bytes_read
, i
;
2281 struct abbrev_info
*abbrev
;
2282 struct attribute attr
;
2283 bfd_byte
*info_ptr
= stash
->info_ptr
;
2284 bfd_byte
*end_ptr
= info_ptr
+ unit_length
;
2287 bfd_vma high_pc
= 0;
2288 bfd
*abfd
= stash
->bfd_ptr
;
2290 version
= read_2_bytes (abfd
, info_ptr
);
2292 BFD_ASSERT (offset_size
== 4 || offset_size
== 8);
2293 if (offset_size
== 4)
2294 abbrev_offset
= read_4_bytes (abfd
, info_ptr
);
2296 abbrev_offset
= read_8_bytes (abfd
, info_ptr
);
2297 info_ptr
+= offset_size
;
2298 addr_size
= read_1_byte (abfd
, info_ptr
);
2301 if (version
!= 2 && version
!= 3 && version
!= 4)
2303 (*_bfd_error_handler
) (_("Dwarf Error: found dwarf version '%u', this reader only handles version 2, 3 and 4 information."), version
);
2304 bfd_set_error (bfd_error_bad_value
);
2308 if (addr_size
> sizeof (bfd_vma
))
2310 (*_bfd_error_handler
) (_("Dwarf Error: found address size '%u', this reader can not handle sizes greater than '%u'."),
2312 (unsigned int) sizeof (bfd_vma
));
2313 bfd_set_error (bfd_error_bad_value
);
2317 if (addr_size
!= 2 && addr_size
!= 4 && addr_size
!= 8)
2319 (*_bfd_error_handler
) ("Dwarf Error: found address size '%u', this reader can only handle address sizes '2', '4' and '8'.", addr_size
);
2320 bfd_set_error (bfd_error_bad_value
);
2324 /* Read the abbrevs for this compilation unit into a table. */
2325 abbrevs
= read_abbrevs (abfd
, abbrev_offset
, stash
);
2329 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2330 info_ptr
+= bytes_read
;
2331 if (! abbrev_number
)
2333 (*_bfd_error_handler
) (_("Dwarf Error: Bad abbrev number: %u."),
2335 bfd_set_error (bfd_error_bad_value
);
2339 abbrev
= lookup_abbrev (abbrev_number
, abbrevs
);
2342 (*_bfd_error_handler
) (_("Dwarf Error: Could not find abbrev number %u."),
2344 bfd_set_error (bfd_error_bad_value
);
2348 amt
= sizeof (struct comp_unit
);
2349 unit
= (struct comp_unit
*) bfd_zalloc (abfd
, amt
);
2353 unit
->version
= version
;
2354 unit
->addr_size
= addr_size
;
2355 unit
->offset_size
= offset_size
;
2356 unit
->abbrevs
= abbrevs
;
2357 unit
->end_ptr
= end_ptr
;
2358 unit
->stash
= stash
;
2359 unit
->info_ptr_unit
= info_ptr_unit
;
2360 unit
->sec_info_ptr
= stash
->sec_info_ptr
;
2362 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
2364 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], unit
, info_ptr
);
2365 if (info_ptr
== NULL
)
2368 /* Store the data if it is of an attribute we want to keep in a
2369 partial symbol table. */
2372 case DW_AT_stmt_list
:
2374 unit
->line_offset
= attr
.u
.val
;
2378 unit
->name
= attr
.u
.str
;
2382 low_pc
= attr
.u
.val
;
2383 /* If the compilation unit DIE has a DW_AT_low_pc attribute,
2384 this is the base address to use when reading location
2385 lists or range lists. */
2386 unit
->base_address
= low_pc
;
2390 high_pc
= attr
.u
.val
;
2394 if (!read_rangelist (unit
, &unit
->arange
, attr
.u
.val
))
2398 case DW_AT_comp_dir
:
2400 char *comp_dir
= attr
.u
.str
;
2403 /* Irix 6.2 native cc prepends <machine>.: to the compilation
2404 directory, get rid of it. */
2405 char *cp
= strchr (comp_dir
, ':');
2407 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
2410 unit
->comp_dir
= comp_dir
;
2420 if (!arange_add (unit
->abfd
, &unit
->arange
, low_pc
, high_pc
))
2424 unit
->first_child_die_ptr
= info_ptr
;
2428 /* Return TRUE if UNIT may contain the address given by ADDR. When
2429 there are functions written entirely with inline asm statements, the
2430 range info in the compilation unit header may not be correct. We
2431 need to consult the line info table to see if a compilation unit
2432 really contains the given address. */
2435 comp_unit_contains_address (struct comp_unit
*unit
, bfd_vma addr
)
2437 struct arange
*arange
;
2442 arange
= &unit
->arange
;
2445 if (addr
>= arange
->low
&& addr
< arange
->high
)
2447 arange
= arange
->next
;
2454 /* If UNIT contains ADDR, set the output parameters to the values for
2455 the line containing ADDR. The output parameters, FILENAME_PTR,
2456 FUNCTIONNAME_PTR, and LINENUMBER_PTR, are pointers to the objects
2459 Return TRUE if UNIT contains ADDR, and no errors were encountered;
2463 comp_unit_find_nearest_line (struct comp_unit
*unit
,
2465 const char **filename_ptr
,
2466 const char **functionname_ptr
,
2467 unsigned int *linenumber_ptr
,
2468 struct dwarf2_debug
*stash
)
2472 struct funcinfo
*function
;
2477 if (! unit
->line_table
)
2479 if (! unit
->stmtlist
)
2485 unit
->line_table
= decode_line_info (unit
, stash
);
2487 if (! unit
->line_table
)
2493 if (unit
->first_child_die_ptr
< unit
->end_ptr
2494 && ! scan_unit_for_symbols (unit
))
2502 func_p
= lookup_address_in_function_table (unit
, addr
,
2503 &function
, functionname_ptr
);
2504 if (func_p
&& (function
->tag
== DW_TAG_inlined_subroutine
))
2505 stash
->inliner_chain
= function
;
2506 line_p
= lookup_address_in_line_info_table (unit
->line_table
, addr
,
2509 return line_p
|| func_p
;
2512 /* Check to see if line info is already decoded in a comp_unit.
2513 If not, decode it. Returns TRUE if no errors were encountered;
2517 comp_unit_maybe_decode_line_info (struct comp_unit
*unit
,
2518 struct dwarf2_debug
*stash
)
2523 if (! unit
->line_table
)
2525 if (! unit
->stmtlist
)
2531 unit
->line_table
= decode_line_info (unit
, stash
);
2533 if (! unit
->line_table
)
2539 if (unit
->first_child_die_ptr
< unit
->end_ptr
2540 && ! scan_unit_for_symbols (unit
))
2550 /* If UNIT contains SYM at ADDR, set the output parameters to the
2551 values for the line containing SYM. The output parameters,
2552 FILENAME_PTR, and LINENUMBER_PTR, are pointers to the objects to be
2555 Return TRUE if UNIT contains SYM, and no errors were encountered;
2559 comp_unit_find_line (struct comp_unit
*unit
,
2562 const char **filename_ptr
,
2563 unsigned int *linenumber_ptr
,
2564 struct dwarf2_debug
*stash
)
2566 if (!comp_unit_maybe_decode_line_info (unit
, stash
))
2569 if (sym
->flags
& BSF_FUNCTION
)
2570 return lookup_symbol_in_function_table (unit
, sym
, addr
,
2574 return lookup_symbol_in_variable_table (unit
, sym
, addr
,
2579 static struct funcinfo
*
2580 reverse_funcinfo_list (struct funcinfo
*head
)
2582 struct funcinfo
*rhead
;
2583 struct funcinfo
*temp
;
2585 for (rhead
= NULL
; head
; head
= temp
)
2587 temp
= head
->prev_func
;
2588 head
->prev_func
= rhead
;
2594 static struct varinfo
*
2595 reverse_varinfo_list (struct varinfo
*head
)
2597 struct varinfo
*rhead
;
2598 struct varinfo
*temp
;
2600 for (rhead
= NULL
; head
; head
= temp
)
2602 temp
= head
->prev_var
;
2603 head
->prev_var
= rhead
;
2609 /* Extract all interesting funcinfos and varinfos of a compilation
2610 unit into hash tables for faster lookup. Returns TRUE if no
2611 errors were enountered; FALSE otherwise. */
2614 comp_unit_hash_info (struct dwarf2_debug
*stash
,
2615 struct comp_unit
*unit
,
2616 struct info_hash_table
*funcinfo_hash_table
,
2617 struct info_hash_table
*varinfo_hash_table
)
2619 struct funcinfo
* each_func
;
2620 struct varinfo
* each_var
;
2621 bfd_boolean okay
= TRUE
;
2623 BFD_ASSERT (stash
->info_hash_status
!= STASH_INFO_HASH_DISABLED
);
2625 if (!comp_unit_maybe_decode_line_info (unit
, stash
))
2628 BFD_ASSERT (!unit
->cached
);
2630 /* To preserve the original search order, we went to visit the function
2631 infos in the reversed order of the list. However, making the list
2632 bi-directional use quite a bit of extra memory. So we reverse
2633 the list first, traverse the list in the now reversed order and
2634 finally reverse the list again to get back the original order. */
2635 unit
->function_table
= reverse_funcinfo_list (unit
->function_table
);
2636 for (each_func
= unit
->function_table
;
2638 each_func
= each_func
->prev_func
)
2640 /* Skip nameless functions. */
2641 if (each_func
->name
)
2642 /* There is no need to copy name string into hash table as
2643 name string is either in the dwarf string buffer or
2644 info in the stash. */
2645 okay
= insert_info_hash_table (funcinfo_hash_table
, each_func
->name
,
2646 (void*) each_func
, FALSE
);
2648 unit
->function_table
= reverse_funcinfo_list (unit
->function_table
);
2652 /* We do the same for variable infos. */
2653 unit
->variable_table
= reverse_varinfo_list (unit
->variable_table
);
2654 for (each_var
= unit
->variable_table
;
2656 each_var
= each_var
->prev_var
)
2658 /* Skip stack vars and vars with no files or names. */
2659 if (each_var
->stack
== 0
2660 && each_var
->file
!= NULL
2661 && each_var
->name
!= NULL
)
2662 /* There is no need to copy name string into hash table as
2663 name string is either in the dwarf string buffer or
2664 info in the stash. */
2665 okay
= insert_info_hash_table (varinfo_hash_table
, each_var
->name
,
2666 (void*) each_var
, FALSE
);
2669 unit
->variable_table
= reverse_varinfo_list (unit
->variable_table
);
2670 unit
->cached
= TRUE
;
2674 /* Locate a section in a BFD containing debugging info. The search starts
2675 from the section after AFTER_SEC, or from the first section in the BFD if
2676 AFTER_SEC is NULL. The search works by examining the names of the
2677 sections. There are two permissiable names. The first is .debug_info.
2678 This is the standard DWARF2 name. The second is a prefix .gnu.linkonce.wi.
2679 This is a variation on the .debug_info section which has a checksum
2680 describing the contents appended onto the name. This allows the linker to
2681 identify and discard duplicate debugging sections for different
2682 compilation units. */
2683 #define DWARF2_DEBUG_INFO ".debug_info"
2684 #define DWARF2_COMPRESSED_DEBUG_INFO ".zdebug_info"
2685 #define GNU_LINKONCE_INFO ".gnu.linkonce.wi."
2688 find_debug_info (bfd
*abfd
, asection
*after_sec
)
2692 msec
= after_sec
!= NULL
? after_sec
->next
: abfd
->sections
;
2696 if (strcmp (msec
->name
, DWARF2_DEBUG_INFO
) == 0)
2699 if (strcmp (msec
->name
, DWARF2_COMPRESSED_DEBUG_INFO
) == 0)
2702 if (CONST_STRNEQ (msec
->name
, GNU_LINKONCE_INFO
))
2711 /* Unset vmas for adjusted sections in STASH. */
2714 unset_sections (struct dwarf2_debug
*stash
)
2717 struct adjusted_section
*p
;
2719 i
= stash
->adjusted_section_count
;
2720 p
= stash
->adjusted_sections
;
2721 for (; i
> 0; i
--, p
++)
2722 p
->section
->vma
= 0;
2725 /* Set unique VMAs for loadable and DWARF sections in ABFD and save
2726 VMAs in STASH for unset_sections. */
2729 place_sections (bfd
*abfd
, struct dwarf2_debug
*stash
)
2731 struct adjusted_section
*p
;
2734 if (stash
->adjusted_section_count
!= 0)
2736 i
= stash
->adjusted_section_count
;
2737 p
= stash
->adjusted_sections
;
2738 for (; i
> 0; i
--, p
++)
2739 p
->section
->vma
= p
->adj_vma
;
2744 bfd_vma last_vma
= 0, last_dwarf
= 0;
2748 for (sect
= abfd
->sections
; sect
!= NULL
; sect
= sect
->next
)
2756 /* We need to adjust the VMAs of any .debug_info sections.
2757 Skip compressed ones, since no relocations could target
2758 them - they should not appear in object files anyway. */
2759 if (strcmp (sect
->name
, DWARF2_DEBUG_INFO
) == 0)
2761 else if (CONST_STRNEQ (sect
->name
, GNU_LINKONCE_INFO
))
2766 if (!is_debug_info
&& (sect
->flags
& SEC_LOAD
) == 0)
2769 sz
= sect
->rawsize
? sect
->rawsize
: sect
->size
;
2776 amt
= i
* sizeof (struct adjusted_section
);
2777 p
= (struct adjusted_section
*) bfd_zalloc (abfd
, amt
);
2781 stash
->adjusted_sections
= p
;
2782 stash
->adjusted_section_count
= i
;
2784 for (sect
= abfd
->sections
; sect
!= NULL
; sect
= sect
->next
)
2792 /* We need to adjust the VMAs of any .debug_info sections.
2793 Skip compressed ones, since no relocations could target
2794 them - they should not appear in object files anyway. */
2795 if (strcmp (sect
->name
, DWARF2_DEBUG_INFO
) == 0)
2797 else if (CONST_STRNEQ (sect
->name
, GNU_LINKONCE_INFO
))
2802 if (!is_debug_info
&& (sect
->flags
& SEC_LOAD
) == 0)
2805 sz
= sect
->rawsize
? sect
->rawsize
: sect
->size
;
2812 BFD_ASSERT (sect
->alignment_power
== 0);
2813 sect
->vma
= last_dwarf
;
2816 else if (last_vma
!= 0)
2818 /* Align the new address to the current section
2820 last_vma
= ((last_vma
2821 + ~((bfd_vma
) -1 << sect
->alignment_power
))
2822 & ((bfd_vma
) -1 << sect
->alignment_power
));
2823 sect
->vma
= last_vma
;
2824 last_vma
+= sect
->vma
+ sz
;
2827 last_vma
+= sect
->vma
+ sz
;
2829 p
->adj_vma
= sect
->vma
;
2838 /* Look up a funcinfo by name using the given info hash table. If found,
2839 also update the locations pointed to by filename_ptr and linenumber_ptr.
2841 This function returns TRUE if a funcinfo that matches the given symbol
2842 and address is found with any error; otherwise it returns FALSE. */
2845 info_hash_lookup_funcinfo (struct info_hash_table
*hash_table
,
2848 const char **filename_ptr
,
2849 unsigned int *linenumber_ptr
)
2851 struct funcinfo
* each_func
;
2852 struct funcinfo
* best_fit
= NULL
;
2853 struct info_list_node
*node
;
2854 struct arange
*arange
;
2855 const char *name
= bfd_asymbol_name (sym
);
2856 asection
*sec
= bfd_get_section (sym
);
2858 for (node
= lookup_info_hash_table (hash_table
, name
);
2862 each_func
= (struct funcinfo
*) node
->info
;
2863 for (arange
= &each_func
->arange
;
2865 arange
= arange
->next
)
2867 if ((!each_func
->sec
|| each_func
->sec
== sec
)
2868 && addr
>= arange
->low
2869 && addr
< arange
->high
2871 || ((arange
->high
- arange
->low
)
2872 < (best_fit
->arange
.high
- best_fit
->arange
.low
))))
2873 best_fit
= each_func
;
2879 best_fit
->sec
= sec
;
2880 *filename_ptr
= best_fit
->file
;
2881 *linenumber_ptr
= best_fit
->line
;
2888 /* Look up a varinfo by name using the given info hash table. If found,
2889 also update the locations pointed to by filename_ptr and linenumber_ptr.
2891 This function returns TRUE if a varinfo that matches the given symbol
2892 and address is found with any error; otherwise it returns FALSE. */
2895 info_hash_lookup_varinfo (struct info_hash_table
*hash_table
,
2898 const char **filename_ptr
,
2899 unsigned int *linenumber_ptr
)
2901 const char *name
= bfd_asymbol_name (sym
);
2902 asection
*sec
= bfd_get_section (sym
);
2903 struct varinfo
* each
;
2904 struct info_list_node
*node
;
2906 for (node
= lookup_info_hash_table (hash_table
, name
);
2910 each
= (struct varinfo
*) node
->info
;
2911 if (each
->addr
== addr
2912 && (!each
->sec
|| each
->sec
== sec
))
2915 *filename_ptr
= each
->file
;
2916 *linenumber_ptr
= each
->line
;
2924 /* Update the funcinfo and varinfo info hash tables if they are
2925 not up to date. Returns TRUE if there is no error; otherwise
2926 returns FALSE and disable the info hash tables. */
2929 stash_maybe_update_info_hash_tables (struct dwarf2_debug
*stash
)
2931 struct comp_unit
*each
;
2933 /* Exit if hash tables are up-to-date. */
2934 if (stash
->all_comp_units
== stash
->hash_units_head
)
2937 if (stash
->hash_units_head
)
2938 each
= stash
->hash_units_head
->prev_unit
;
2940 each
= stash
->last_comp_unit
;
2944 if (!comp_unit_hash_info (stash
, each
, stash
->funcinfo_hash_table
,
2945 stash
->varinfo_hash_table
))
2947 stash
->info_hash_status
= STASH_INFO_HASH_DISABLED
;
2950 each
= each
->prev_unit
;
2953 stash
->hash_units_head
= stash
->all_comp_units
;
2957 /* Check consistency of info hash tables. This is for debugging only. */
2959 static void ATTRIBUTE_UNUSED
2960 stash_verify_info_hash_table (struct dwarf2_debug
*stash
)
2962 struct comp_unit
*each_unit
;
2963 struct funcinfo
*each_func
;
2964 struct varinfo
*each_var
;
2965 struct info_list_node
*node
;
2968 for (each_unit
= stash
->all_comp_units
;
2970 each_unit
= each_unit
->next_unit
)
2972 for (each_func
= each_unit
->function_table
;
2974 each_func
= each_func
->prev_func
)
2976 if (!each_func
->name
)
2978 node
= lookup_info_hash_table (stash
->funcinfo_hash_table
,
2982 while (node
&& !found
)
2984 found
= node
->info
== each_func
;
2990 for (each_var
= each_unit
->variable_table
;
2992 each_var
= each_var
->prev_var
)
2994 if (!each_var
->name
|| !each_var
->file
|| each_var
->stack
)
2996 node
= lookup_info_hash_table (stash
->varinfo_hash_table
,
3000 while (node
&& !found
)
3002 found
= node
->info
== each_var
;
3010 /* Check to see if we want to enable the info hash tables, which consume
3011 quite a bit of memory. Currently we only check the number times
3012 bfd_dwarf2_find_line is called. In the future, we may also want to
3013 take the number of symbols into account. */
3016 stash_maybe_enable_info_hash_tables (bfd
*abfd
, struct dwarf2_debug
*stash
)
3018 BFD_ASSERT (stash
->info_hash_status
== STASH_INFO_HASH_OFF
);
3020 if (stash
->info_hash_count
++ < STASH_INFO_HASH_TRIGGER
)
3023 /* FIXME: Maybe we should check the reduce_memory_overheads
3024 and optimize fields in the bfd_link_info structure ? */
3026 /* Create hash tables. */
3027 stash
->funcinfo_hash_table
= create_info_hash_table (abfd
);
3028 stash
->varinfo_hash_table
= create_info_hash_table (abfd
);
3029 if (!stash
->funcinfo_hash_table
|| !stash
->varinfo_hash_table
)
3031 /* Turn off info hashes if any allocation above fails. */
3032 stash
->info_hash_status
= STASH_INFO_HASH_DISABLED
;
3035 /* We need a forced update so that the info hash tables will
3036 be created even though there is no compilation unit. That
3037 happens if STASH_INFO_HASH_TRIGGER is 0. */
3038 stash_maybe_update_info_hash_tables (stash
);
3039 stash
->info_hash_status
= STASH_INFO_HASH_ON
;
3042 /* Find the file and line associated with a symbol and address using the
3043 info hash tables of a stash. If there is a match, the function returns
3044 TRUE and update the locations pointed to by filename_ptr and linenumber_ptr;
3045 otherwise it returns FALSE. */
3048 stash_find_line_fast (struct dwarf2_debug
*stash
,
3051 const char **filename_ptr
,
3052 unsigned int *linenumber_ptr
)
3054 BFD_ASSERT (stash
->info_hash_status
== STASH_INFO_HASH_ON
);
3056 if (sym
->flags
& BSF_FUNCTION
)
3057 return info_hash_lookup_funcinfo (stash
->funcinfo_hash_table
, sym
, addr
,
3058 filename_ptr
, linenumber_ptr
);
3059 return info_hash_lookup_varinfo (stash
->varinfo_hash_table
, sym
, addr
,
3060 filename_ptr
, linenumber_ptr
);
3063 /* Find the source code location of SYMBOL. If SYMBOL is NULL
3064 then find the nearest source code location corresponding to
3065 the address SECTION + OFFSET.
3066 Returns TRUE if the line is found without error and fills in
3067 FILENAME_PTR and LINENUMBER_PTR. In the case where SYMBOL was
3068 NULL the FUNCTIONNAME_PTR is also filled in.
3069 SYMBOLS contains the symbol table for ABFD.
3070 ADDR_SIZE is the number of bytes in the initial .debug_info length
3071 field and in the abbreviation offset, or zero to indicate that the
3072 default value should be used. */
3075 find_line (bfd
*abfd
,
3080 const char **filename_ptr
,
3081 const char **functionname_ptr
,
3082 unsigned int *linenumber_ptr
,
3083 unsigned int addr_size
,
3086 /* Read each compilation unit from the section .debug_info, and check
3087 to see if it contains the address we are searching for. If yes,
3088 lookup the address, and return the line number info. If no, go
3089 on to the next compilation unit.
3091 We keep a list of all the previously read compilation units, and
3092 a pointer to the next un-read compilation unit. Check the
3093 previously read units before reading more. */
3094 struct dwarf2_debug
*stash
;
3095 /* What address are we looking for? */
3097 struct comp_unit
* each
;
3098 bfd_vma found
= FALSE
;
3099 bfd_boolean do_line
;
3101 stash
= (struct dwarf2_debug
*) *pinfo
;
3105 bfd_size_type amt
= sizeof (struct dwarf2_debug
);
3107 stash
= (struct dwarf2_debug
*) bfd_zalloc (abfd
, amt
);
3112 /* In a relocatable file, 2 functions may have the same address.
3113 We change the section vma so that they won't overlap. */
3114 if ((abfd
->flags
& (EXEC_P
| DYNAMIC
)) == 0)
3116 if (! place_sections (abfd
, stash
))
3120 do_line
= (section
== NULL
3122 && functionname_ptr
== NULL
3126 addr
= symbol
->value
;
3127 section
= bfd_get_section (symbol
);
3129 else if (section
!= NULL
3130 && functionname_ptr
!= NULL
3136 if (section
->output_section
)
3137 addr
+= section
->output_section
->vma
+ section
->output_offset
;
3139 addr
+= section
->vma
;
3140 *filename_ptr
= NULL
;
3142 *functionname_ptr
= NULL
;
3143 *linenumber_ptr
= 0;
3148 bfd_size_type total_size
;
3153 msec
= find_debug_info (abfd
, NULL
);
3156 char * debug_filename
= bfd_follow_gnu_debuglink (abfd
, DEBUGDIR
);
3158 if (debug_filename
== NULL
)
3159 /* No dwarf2 info, and no gnu_debuglink to follow.
3160 Note that at this point the stash has been allocated, but
3161 contains zeros. This lets future calls to this function
3162 fail more quickly. */
3165 if ((debug_bfd
= bfd_openr (debug_filename
, NULL
)) == NULL
3166 || ! bfd_check_format (debug_bfd
, bfd_object
)
3167 || (msec
= find_debug_info (debug_bfd
, NULL
)) == NULL
)
3170 bfd_close (debug_bfd
);
3171 /* FIXME: Should we report our failure to follow the debuglink ? */
3172 free (debug_filename
);
3179 /* There can be more than one DWARF2 info section in a BFD these
3180 days. First handle the easy case when there's only one. If
3181 there's more than one, try case two: none of the sections is
3182 compressed. In that case, read them all in and produce one
3183 large stash. We do this in two passes - in the first pass we
3184 just accumulate the section sizes, and in the second pass we
3185 read in the section's contents. (The allows us to avoid
3186 reallocing the data as we add sections to the stash.) If
3187 some or all sections are compressed, then do things the slow
3188 way, with a bunch of reallocs. */
3190 if (! find_debug_info (debug_bfd
, msec
))
3192 /* Case 1: only one info section. */
3193 total_size
= msec
->size
;
3194 if (! read_section (debug_bfd
, ".debug_info", ".zdebug_info",
3196 &stash
->info_ptr_memory
, &total_size
))
3201 int all_uncompressed
= 1;
3202 for (total_size
= 0; msec
; msec
= find_debug_info (debug_bfd
, msec
))
3204 total_size
+= msec
->size
;
3205 if (strcmp (msec
->name
, DWARF2_COMPRESSED_DEBUG_INFO
) == 0)
3206 all_uncompressed
= 0;
3208 if (all_uncompressed
)
3210 /* Case 2: multiple sections, but none is compressed. */
3211 stash
->info_ptr_memory
= (bfd_byte
*) bfd_malloc (total_size
);
3212 if (stash
->info_ptr_memory
== NULL
)
3216 for (msec
= find_debug_info (debug_bfd
, NULL
);
3218 msec
= find_debug_info (debug_bfd
, msec
))
3226 if (!(bfd_simple_get_relocated_section_contents
3227 (debug_bfd
, msec
, stash
->info_ptr_memory
+ total_size
,
3236 /* Case 3: multiple sections, some or all compressed. */
3237 stash
->info_ptr_memory
= NULL
;
3239 for (msec
= find_debug_info (debug_bfd
, NULL
);
3241 msec
= find_debug_info (debug_bfd
, msec
))
3243 bfd_size_type size
= msec
->size
;
3244 bfd_byte
*buffer
, *tmp
;
3249 buffer
= (bfd_simple_get_relocated_section_contents
3250 (debug_bfd
, msec
, NULL
, symbols
));
3254 if (strcmp (msec
->name
, DWARF2_COMPRESSED_DEBUG_INFO
) == 0)
3256 if (! bfd_uncompress_section_contents (&buffer
, &size
))
3262 tmp
= (bfd_byte
*) bfd_realloc (stash
->info_ptr_memory
,
3269 stash
->info_ptr_memory
= tmp
;
3270 memcpy (stash
->info_ptr_memory
+ total_size
, buffer
, size
);
3277 stash
->info_ptr
= stash
->info_ptr_memory
;
3278 stash
->info_ptr_end
= stash
->info_ptr
+ total_size
;
3279 stash
->sec
= find_debug_info (debug_bfd
, NULL
);
3280 stash
->sec_info_ptr
= stash
->info_ptr
;
3281 stash
->syms
= symbols
;
3282 stash
->bfd_ptr
= debug_bfd
;
3285 /* A null info_ptr indicates that there is no dwarf2 info
3286 (or that an error occured while setting up the stash). */
3287 if (! stash
->info_ptr
)
3290 stash
->inliner_chain
= NULL
;
3292 /* Check the previously read comp. units first. */
3295 /* The info hash tables use quite a bit of memory. We may not want to
3296 always use them. We use some heuristics to decide if and when to
3298 if (stash
->info_hash_status
== STASH_INFO_HASH_OFF
)
3299 stash_maybe_enable_info_hash_tables (abfd
, stash
);
3301 /* Keep info hash table up to date if they are available. Note that we
3302 may disable the hash tables if there is any error duing update. */
3303 if (stash
->info_hash_status
== STASH_INFO_HASH_ON
)
3304 stash_maybe_update_info_hash_tables (stash
);
3306 if (stash
->info_hash_status
== STASH_INFO_HASH_ON
)
3308 found
= stash_find_line_fast (stash
, symbol
, addr
, filename_ptr
,
3315 /* Check the previously read comp. units first. */
3316 for (each
= stash
->all_comp_units
; each
; each
= each
->next_unit
)
3317 if ((symbol
->flags
& BSF_FUNCTION
) == 0
3318 || comp_unit_contains_address (each
, addr
))
3320 found
= comp_unit_find_line (each
, symbol
, addr
, filename_ptr
,
3321 linenumber_ptr
, stash
);
3329 for (each
= stash
->all_comp_units
; each
; each
= each
->next_unit
)
3331 found
= (comp_unit_contains_address (each
, addr
)
3332 && comp_unit_find_nearest_line (each
, addr
,
3342 /* The DWARF2 spec says that the initial length field, and the
3343 offset of the abbreviation table, should both be 4-byte values.
3344 However, some compilers do things differently. */
3347 BFD_ASSERT (addr_size
== 4 || addr_size
== 8);
3349 /* Read each remaining comp. units checking each as they are read. */
3350 while (stash
->info_ptr
< stash
->info_ptr_end
)
3353 unsigned int offset_size
= addr_size
;
3354 bfd_byte
*info_ptr_unit
= stash
->info_ptr
;
3356 length
= read_4_bytes (stash
->bfd_ptr
, stash
->info_ptr
);
3357 /* A 0xffffff length is the DWARF3 way of indicating
3358 we use 64-bit offsets, instead of 32-bit offsets. */
3359 if (length
== 0xffffffff)
3362 length
= read_8_bytes (stash
->bfd_ptr
, stash
->info_ptr
+ 4);
3363 stash
->info_ptr
+= 12;
3365 /* A zero length is the IRIX way of indicating 64-bit offsets,
3366 mostly because the 64-bit length will generally fit in 32
3367 bits, and the endianness helps. */
3368 else if (length
== 0)
3371 length
= read_4_bytes (stash
->bfd_ptr
, stash
->info_ptr
+ 4);
3372 stash
->info_ptr
+= 8;
3374 /* In the absence of the hints above, we assume 32-bit DWARF2
3375 offsets even for targets with 64-bit addresses, because:
3376 a) most of the time these targets will not have generated
3377 more than 2Gb of debug info and so will not need 64-bit
3380 b) if they do use 64-bit offsets but they are not using
3381 the size hints that are tested for above then they are
3382 not conforming to the DWARF3 standard anyway. */
3383 else if (addr_size
== 8)
3386 stash
->info_ptr
+= 4;
3389 stash
->info_ptr
+= 4;
3393 each
= parse_comp_unit (stash
, length
, info_ptr_unit
,
3396 /* The dwarf information is damaged, don't trust it any
3399 stash
->info_ptr
+= length
;
3401 if (stash
->all_comp_units
)
3402 stash
->all_comp_units
->prev_unit
= each
;
3404 stash
->last_comp_unit
= each
;
3406 each
->next_unit
= stash
->all_comp_units
;
3407 stash
->all_comp_units
= each
;
3409 /* DW_AT_low_pc and DW_AT_high_pc are optional for
3410 compilation units. If we don't have them (i.e.,
3411 unit->high == 0), we need to consult the line info table
3412 to see if a compilation unit contains the given
3415 found
= (((symbol
->flags
& BSF_FUNCTION
) == 0
3416 || each
->arange
.high
== 0
3417 || comp_unit_contains_address (each
, addr
))
3418 && comp_unit_find_line (each
, symbol
, addr
,
3423 found
= ((each
->arange
.high
== 0
3424 || comp_unit_contains_address (each
, addr
))
3425 && comp_unit_find_nearest_line (each
, addr
,
3431 if ((bfd_vma
) (stash
->info_ptr
- stash
->sec_info_ptr
)
3432 == stash
->sec
->size
)
3434 stash
->sec
= find_debug_info (stash
->bfd_ptr
, stash
->sec
);
3435 stash
->sec_info_ptr
= stash
->info_ptr
;
3444 if ((abfd
->flags
& (EXEC_P
| DYNAMIC
)) == 0)
3445 unset_sections (stash
);
3450 /* The DWARF2 version of find_nearest_line.
3451 Return TRUE if the line is found without error. */
3454 _bfd_dwarf2_find_nearest_line (bfd
*abfd
,
3458 const char **filename_ptr
,
3459 const char **functionname_ptr
,
3460 unsigned int *linenumber_ptr
,
3461 unsigned int addr_size
,
3464 return find_line (abfd
, section
, offset
, NULL
, symbols
, filename_ptr
,
3465 functionname_ptr
, linenumber_ptr
, addr_size
,
3469 /* The DWARF2 version of find_line.
3470 Return TRUE if the line is found without error. */
3473 _bfd_dwarf2_find_line (bfd
*abfd
,
3476 const char **filename_ptr
,
3477 unsigned int *linenumber_ptr
,
3478 unsigned int addr_size
,
3481 return find_line (abfd
, NULL
, 0, symbol
, symbols
, filename_ptr
,
3482 NULL
, linenumber_ptr
, addr_size
,
3487 _bfd_dwarf2_find_inliner_info (bfd
*abfd ATTRIBUTE_UNUSED
,
3488 const char **filename_ptr
,
3489 const char **functionname_ptr
,
3490 unsigned int *linenumber_ptr
,
3493 struct dwarf2_debug
*stash
;
3495 stash
= (struct dwarf2_debug
*) *pinfo
;
3498 struct funcinfo
*func
= stash
->inliner_chain
;
3500 if (func
&& func
->caller_func
)
3502 *filename_ptr
= func
->caller_file
;
3503 *functionname_ptr
= func
->caller_func
->name
;
3504 *linenumber_ptr
= func
->caller_line
;
3505 stash
->inliner_chain
= func
->caller_func
;
3514 _bfd_dwarf2_cleanup_debug_info (bfd
*abfd
)
3516 struct comp_unit
*each
;
3517 struct dwarf2_debug
*stash
;
3519 if (abfd
== NULL
|| elf_tdata (abfd
) == NULL
)
3522 stash
= (struct dwarf2_debug
*) elf_tdata (abfd
)->dwarf2_find_line_info
;
3527 for (each
= stash
->all_comp_units
; each
; each
= each
->next_unit
)
3529 struct abbrev_info
**abbrevs
= each
->abbrevs
;
3530 struct funcinfo
*function_table
= each
->function_table
;
3531 struct varinfo
*variable_table
= each
->variable_table
;
3534 for (i
= 0; i
< ABBREV_HASH_SIZE
; i
++)
3536 struct abbrev_info
*abbrev
= abbrevs
[i
];
3540 free (abbrev
->attrs
);
3541 abbrev
= abbrev
->next
;
3545 if (each
->line_table
)
3547 free (each
->line_table
->dirs
);
3548 free (each
->line_table
->files
);
3551 while (function_table
)
3553 if (function_table
->file
)
3555 free (function_table
->file
);
3556 function_table
->file
= NULL
;
3559 if (function_table
->caller_file
)
3561 free (function_table
->caller_file
);
3562 function_table
->caller_file
= NULL
;
3564 function_table
= function_table
->prev_func
;
3567 while (variable_table
)
3569 if (variable_table
->file
)
3571 free (variable_table
->file
);
3572 variable_table
->file
= NULL
;
3575 variable_table
= variable_table
->prev_var
;
3579 if (stash
->dwarf_abbrev_buffer
)
3580 free (stash
->dwarf_abbrev_buffer
);
3581 if (stash
->dwarf_line_buffer
)
3582 free (stash
->dwarf_line_buffer
);
3583 if (stash
->dwarf_str_buffer
)
3584 free (stash
->dwarf_str_buffer
);
3585 if (stash
->dwarf_ranges_buffer
)
3586 free (stash
->dwarf_ranges_buffer
);
3587 if (stash
->info_ptr_memory
)
3588 free (stash
->info_ptr_memory
);