2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
3 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
5 Adapted from gdb/dwarf2read.c by Gavin Koch of Cygnus Solutions
8 From the dwarf2read.c header:
9 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
10 Inc. with support from Florida State University (under contract
11 with the Ada Joint Program Office), and Silicon Graphics, Inc.
12 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
13 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
14 support in dwarfread.c
16 This file is part of BFD.
18 This program is free software; you can redistribute it and/or modify
19 it under the terms of the GNU General Public License as published by
20 the Free Software Foundation; either version 3 of the License, or (at
21 your option) any later version.
23 This program is distributed in the hope that it will be useful, but
24 WITHOUT ANY WARRANTY; without even the implied warranty of
25 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26 General Public License for more details.
28 You should have received a copy of the GNU General Public License
29 along with this program; if not, write to the Free Software
30 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
31 MA 02110-1301, USA. */
35 #include "libiberty.h"
40 /* The data in the .debug_line statement prologue looks like this. */
45 unsigned short version
;
46 bfd_vma prologue_length
;
47 unsigned char minimum_instruction_length
;
48 unsigned char maximum_ops_per_insn
;
49 unsigned char default_is_stmt
;
51 unsigned char line_range
;
52 unsigned char opcode_base
;
53 unsigned char *standard_opcode_lengths
;
56 /* Attributes have a name and a value. */
60 enum dwarf_attribute name
;
65 struct dwarf_block
*blk
;
72 /* Blocks are a bunch of untyped bytes. */
79 struct adjusted_section
87 /* A list of all previously read comp_units. */
88 struct comp_unit
*all_comp_units
;
90 /* Last comp unit in list above. */
91 struct comp_unit
*last_comp_unit
;
93 /* The next unread compilation unit within the .debug_info section.
94 Zero indicates that the .debug_info section has not been loaded
98 /* Pointer to the end of the .debug_info section memory buffer. */
99 bfd_byte
*info_ptr_end
;
101 /* Pointer to the bfd, section and address of the beginning of the
102 section. The bfd might be different than expected because of
103 gnu_debuglink sections. */
106 bfd_byte
*sec_info_ptr
;
108 /* A pointer to the memory block allocated for info_ptr. Neither
109 info_ptr nor sec_info_ptr are guaranteed to stay pointing to the
110 beginning of the malloc block. This is used only to free the
112 bfd_byte
*info_ptr_memory
;
114 /* Pointer to the symbol table. */
117 /* Pointer to the .debug_abbrev section loaded into memory. */
118 bfd_byte
*dwarf_abbrev_buffer
;
120 /* Length of the loaded .debug_abbrev section. */
121 bfd_size_type dwarf_abbrev_size
;
123 /* Buffer for decode_line_info. */
124 bfd_byte
*dwarf_line_buffer
;
126 /* Length of the loaded .debug_line section. */
127 bfd_size_type dwarf_line_size
;
129 /* Pointer to the .debug_str section loaded into memory. */
130 bfd_byte
*dwarf_str_buffer
;
132 /* Length of the loaded .debug_str section. */
133 bfd_size_type dwarf_str_size
;
135 /* Pointer to the .debug_ranges section loaded into memory. */
136 bfd_byte
*dwarf_ranges_buffer
;
138 /* Length of the loaded .debug_ranges section. */
139 bfd_size_type dwarf_ranges_size
;
141 /* If the most recent call to bfd_find_nearest_line was given an
142 address in an inlined function, preserve a pointer into the
143 calling chain for subsequent calls to bfd_find_inliner_info to
145 struct funcinfo
*inliner_chain
;
147 /* Number of sections whose VMA we must adjust. */
148 unsigned int adjusted_section_count
;
150 /* Array of sections with adjusted VMA. */
151 struct adjusted_section
*adjusted_sections
;
153 /* Number of times find_line is called. This is used in
154 the heuristic for enabling the info hash tables. */
157 #define STASH_INFO_HASH_TRIGGER 100
159 /* Hash table mapping symbol names to function infos. */
160 struct info_hash_table
*funcinfo_hash_table
;
162 /* Hash table mapping symbol names to variable infos. */
163 struct info_hash_table
*varinfo_hash_table
;
165 /* Head of comp_unit list in the last hash table update. */
166 struct comp_unit
*hash_units_head
;
168 /* Status of info hash. */
169 int info_hash_status
;
170 #define STASH_INFO_HASH_OFF 0
171 #define STASH_INFO_HASH_ON 1
172 #define STASH_INFO_HASH_DISABLED 2
182 /* A minimal decoding of DWARF2 compilation units. We only decode
183 what's needed to get to the line number information. */
187 /* Chain the previously read compilation units. */
188 struct comp_unit
*next_unit
;
190 /* Likewise, chain the compilation unit read after this one.
191 The comp units are stored in reversed reading order. */
192 struct comp_unit
*prev_unit
;
194 /* Keep the bfd convenient (for memory allocation). */
197 /* The lowest and highest addresses contained in this compilation
198 unit as specified in the compilation unit header. */
199 struct arange arange
;
201 /* The DW_AT_name attribute (for error messages). */
204 /* The abbrev hash table. */
205 struct abbrev_info
**abbrevs
;
207 /* Note that an error was found by comp_unit_find_nearest_line. */
210 /* The DW_AT_comp_dir attribute. */
213 /* TRUE if there is a line number table associated with this comp. unit. */
216 /* Pointer to the current comp_unit so that we can find a given entry
218 bfd_byte
*info_ptr_unit
;
220 /* Pointer to the start of the debug section, for DW_FORM_ref_addr. */
221 bfd_byte
*sec_info_ptr
;
223 /* The offset into .debug_line of the line number table. */
224 unsigned long line_offset
;
226 /* Pointer to the first child die for the comp unit. */
227 bfd_byte
*first_child_die_ptr
;
229 /* The end of the comp unit. */
232 /* The decoded line number, NULL if not yet decoded. */
233 struct line_info_table
*line_table
;
235 /* A list of the functions found in this comp. unit. */
236 struct funcinfo
*function_table
;
238 /* A list of the variables found in this comp. unit. */
239 struct varinfo
*variable_table
;
241 /* Pointer to dwarf2_debug structure. */
242 struct dwarf2_debug
*stash
;
244 /* DWARF format version for this unit - from unit header. */
247 /* Address size for this unit - from unit header. */
248 unsigned char addr_size
;
250 /* Offset size for this unit - from unit header. */
251 unsigned char offset_size
;
253 /* Base address for this unit - from DW_AT_low_pc attribute of
254 DW_TAG_compile_unit DIE */
255 bfd_vma base_address
;
257 /* TRUE if symbols are cached in hash table for faster lookup by name. */
261 /* This data structure holds the information of an abbrev. */
264 unsigned int number
; /* Number identifying abbrev. */
265 enum dwarf_tag tag
; /* DWARF tag. */
266 int has_children
; /* Boolean. */
267 unsigned int num_attrs
; /* Number of attributes. */
268 struct attr_abbrev
*attrs
; /* An array of attribute descriptions. */
269 struct abbrev_info
*next
; /* Next in chain. */
274 enum dwarf_attribute name
;
275 enum dwarf_form form
;
278 /* Map of uncompressed DWARF debug section name to compressed one. It
279 is terminated by NULL uncompressed_name. */
281 struct dwarf_debug_section dwarf_debug_sections
[] =
283 { ".debug_abbrev", ".zdebug_abbrev" },
284 { ".debug_aranges", ".zdebug_aranges" },
285 { ".debug_frame", ".zdebug_frame" },
286 { ".debug_info", ".zdebug_info" },
287 { ".debug_line", ".zdebug_line" },
288 { ".debug_loc", ".zdebug_loc" },
289 { ".debug_macinfo", ".zdebug_macinfo" },
290 { ".debug_pubnames", ".zdebug_pubnames" },
291 { ".debug_pubtypes", ".zdebug_pubtypes" },
292 { ".debug_ranges", ".zdebug_ranges" },
293 { ".debug_static_func", ".zdebug_static_func" },
294 { ".debug_static_vars", ".zdebug_static_vars" },
295 { ".debug_str", ".zdebug_str", },
296 { ".debug_types", ".zdebug_types" },
297 /* GNU DWARF 1 extensions */
298 { ".debug_sfnames", ".zdebug_sfnames" },
299 { ".debug_srcinfo", ".zebug_srcinfo" },
300 /* SGI/MIPS DWARF 2 extensions */
301 { ".debug_funcnames", ".zdebug_funcnames" },
302 { ".debug_typenames", ".zdebug_typenames" },
303 { ".debug_varnames", ".zdebug_varnames" },
304 { ".debug_weaknames", ".zdebug_weaknames" },
308 enum dwarf_debug_section_enum
332 #ifndef ABBREV_HASH_SIZE
333 #define ABBREV_HASH_SIZE 121
335 #ifndef ATTR_ALLOC_CHUNK
336 #define ATTR_ALLOC_CHUNK 4
339 /* Variable and function hash tables. This is used to speed up look-up
340 in lookup_symbol_in_var_table() and lookup_symbol_in_function_table().
341 In order to share code between variable and function infos, we use
342 a list of untyped pointer for all variable/function info associated with
343 a symbol. We waste a bit of memory for list with one node but that
344 simplifies the code. */
346 struct info_list_node
348 struct info_list_node
*next
;
352 /* Info hash entry. */
353 struct info_hash_entry
355 struct bfd_hash_entry root
;
356 struct info_list_node
*head
;
359 struct info_hash_table
361 struct bfd_hash_table base
;
364 /* Function to create a new entry in info hash table. */
366 static struct bfd_hash_entry
*
367 info_hash_table_newfunc (struct bfd_hash_entry
*entry
,
368 struct bfd_hash_table
*table
,
371 struct info_hash_entry
*ret
= (struct info_hash_entry
*) entry
;
373 /* Allocate the structure if it has not already been allocated by a
377 ret
= (struct info_hash_entry
*) bfd_hash_allocate (table
,
383 /* Call the allocation method of the base class. */
384 ret
= ((struct info_hash_entry
*)
385 bfd_hash_newfunc ((struct bfd_hash_entry
*) ret
, table
, string
));
387 /* Initialize the local fields here. */
391 return (struct bfd_hash_entry
*) ret
;
394 /* Function to create a new info hash table. It returns a pointer to the
395 newly created table or NULL if there is any error. We need abfd
396 solely for memory allocation. */
398 static struct info_hash_table
*
399 create_info_hash_table (bfd
*abfd
)
401 struct info_hash_table
*hash_table
;
403 hash_table
= (struct info_hash_table
*)
404 bfd_alloc (abfd
, sizeof (struct info_hash_table
));
408 if (!bfd_hash_table_init (&hash_table
->base
, info_hash_table_newfunc
,
409 sizeof (struct info_hash_entry
)))
411 bfd_release (abfd
, hash_table
);
418 /* Insert an info entry into an info hash table. We do not check of
419 duplicate entries. Also, the caller need to guarantee that the
420 right type of info in inserted as info is passed as a void* pointer.
421 This function returns true if there is no error. */
424 insert_info_hash_table (struct info_hash_table
*hash_table
,
429 struct info_hash_entry
*entry
;
430 struct info_list_node
*node
;
432 entry
= (struct info_hash_entry
*) bfd_hash_lookup (&hash_table
->base
,
437 node
= (struct info_list_node
*) bfd_hash_allocate (&hash_table
->base
,
443 node
->next
= entry
->head
;
449 /* Look up an info entry list from an info hash table. Return NULL
452 static struct info_list_node
*
453 lookup_info_hash_table (struct info_hash_table
*hash_table
, const char *key
)
455 struct info_hash_entry
*entry
;
457 entry
= (struct info_hash_entry
*) bfd_hash_lookup (&hash_table
->base
, key
,
459 return entry
? entry
->head
: NULL
;
462 /* Read a section into its appropriate place in the dwarf2_debug
463 struct (indicated by SECTION_BUFFER and SECTION_SIZE). If SYMS is
464 not NULL, use bfd_simple_get_relocated_section_contents to read the
465 section contents, otherwise use bfd_get_section_contents. Fail if
466 the located section does not contain at least OFFSET bytes. */
469 read_section (bfd
* abfd
,
470 enum dwarf_debug_section_enum sec
,
473 bfd_byte
** section_buffer
,
474 bfd_size_type
* section_size
)
477 const char *section_name
= dwarf_debug_sections
[sec
].uncompressed_name
;
479 /* read_section is a noop if the section has already been read. */
480 if (!*section_buffer
)
482 msec
= bfd_get_section_by_name (abfd
, section_name
);
485 section_name
= dwarf_debug_sections
[sec
].compressed_name
;
486 msec
= bfd_get_section_by_name (abfd
, section_name
);
490 (*_bfd_error_handler
) (_("Dwarf Error: Can't find %s section."), section_name
);
491 bfd_set_error (bfd_error_bad_value
);
495 *section_size
= msec
->rawsize
? msec
->rawsize
: msec
->size
;
499 = bfd_simple_get_relocated_section_contents (abfd
, msec
, NULL
, syms
);
500 if (! *section_buffer
)
505 *section_buffer
= (bfd_byte
*) bfd_malloc (*section_size
);
506 if (! *section_buffer
)
508 if (! bfd_get_section_contents (abfd
, msec
, *section_buffer
,
514 /* It is possible to get a bad value for the offset into the section
515 that the client wants. Validate it here to avoid trouble later. */
516 if (offset
!= 0 && offset
>= *section_size
)
518 (*_bfd_error_handler
) (_("Dwarf Error: Offset (%lu) greater than or equal to %s size (%lu)."),
519 (long) offset
, section_name
, *section_size
);
520 bfd_set_error (bfd_error_bad_value
);
528 The following function up to the END VERBATIM mark are
529 copied directly from dwarf2read.c. */
531 /* Read dwarf information from a buffer. */
534 read_1_byte (bfd
*abfd ATTRIBUTE_UNUSED
, bfd_byte
*buf
)
536 return bfd_get_8 (abfd
, buf
);
540 read_1_signed_byte (bfd
*abfd ATTRIBUTE_UNUSED
, bfd_byte
*buf
)
542 return bfd_get_signed_8 (abfd
, buf
);
546 read_2_bytes (bfd
*abfd
, bfd_byte
*buf
)
548 return bfd_get_16 (abfd
, buf
);
552 read_4_bytes (bfd
*abfd
, bfd_byte
*buf
)
554 return bfd_get_32 (abfd
, buf
);
558 read_8_bytes (bfd
*abfd
, bfd_byte
*buf
)
560 return bfd_get_64 (abfd
, buf
);
564 read_n_bytes (bfd
*abfd ATTRIBUTE_UNUSED
,
566 unsigned int size ATTRIBUTE_UNUSED
)
572 read_string (bfd
*abfd ATTRIBUTE_UNUSED
,
574 unsigned int *bytes_read_ptr
)
576 /* Return a pointer to the embedded string. */
577 char *str
= (char *) buf
;
585 *bytes_read_ptr
= strlen (str
) + 1;
592 read_indirect_string (struct comp_unit
* unit
,
594 unsigned int * bytes_read_ptr
)
597 struct dwarf2_debug
*stash
= unit
->stash
;
600 if (unit
->offset_size
== 4)
601 offset
= read_4_bytes (unit
->abfd
, buf
);
603 offset
= read_8_bytes (unit
->abfd
, buf
);
605 *bytes_read_ptr
= unit
->offset_size
;
607 if (! read_section (unit
->abfd
, debug_str
, stash
->syms
, offset
,
608 &stash
->dwarf_str_buffer
, &stash
->dwarf_str_size
))
611 str
= (char *) stash
->dwarf_str_buffer
+ offset
;
618 read_address (struct comp_unit
*unit
, bfd_byte
*buf
)
620 int signed_vma
= get_elf_backend_data (unit
->abfd
)->sign_extend_vma
;
624 switch (unit
->addr_size
)
627 return bfd_get_signed_64 (unit
->abfd
, buf
);
629 return bfd_get_signed_32 (unit
->abfd
, buf
);
631 return bfd_get_signed_16 (unit
->abfd
, buf
);
638 switch (unit
->addr_size
)
641 return bfd_get_64 (unit
->abfd
, buf
);
643 return bfd_get_32 (unit
->abfd
, buf
);
645 return bfd_get_16 (unit
->abfd
, buf
);
652 /* Lookup an abbrev_info structure in the abbrev hash table. */
654 static struct abbrev_info
*
655 lookup_abbrev (unsigned int number
, struct abbrev_info
**abbrevs
)
657 unsigned int hash_number
;
658 struct abbrev_info
*abbrev
;
660 hash_number
= number
% ABBREV_HASH_SIZE
;
661 abbrev
= abbrevs
[hash_number
];
665 if (abbrev
->number
== number
)
668 abbrev
= abbrev
->next
;
674 /* In DWARF version 2, the description of the debugging information is
675 stored in a separate .debug_abbrev section. Before we read any
676 dies from a section we read in all abbreviations and install them
679 static struct abbrev_info
**
680 read_abbrevs (bfd
*abfd
, bfd_uint64_t offset
, struct dwarf2_debug
*stash
)
682 struct abbrev_info
**abbrevs
;
683 bfd_byte
*abbrev_ptr
;
684 struct abbrev_info
*cur_abbrev
;
685 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
686 unsigned int abbrev_form
, hash_number
;
689 if (! read_section (abfd
, debug_abbrev
, stash
->syms
, offset
,
690 &stash
->dwarf_abbrev_buffer
, &stash
->dwarf_abbrev_size
))
693 amt
= sizeof (struct abbrev_info
*) * ABBREV_HASH_SIZE
;
694 abbrevs
= (struct abbrev_info
**) bfd_zalloc (abfd
, amt
);
698 abbrev_ptr
= stash
->dwarf_abbrev_buffer
+ offset
;
699 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
700 abbrev_ptr
+= bytes_read
;
702 /* Loop until we reach an abbrev number of 0. */
703 while (abbrev_number
)
705 amt
= sizeof (struct abbrev_info
);
706 cur_abbrev
= (struct abbrev_info
*) bfd_zalloc (abfd
, amt
);
707 if (cur_abbrev
== NULL
)
710 /* Read in abbrev header. */
711 cur_abbrev
->number
= abbrev_number
;
712 cur_abbrev
->tag
= (enum dwarf_tag
)
713 read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
714 abbrev_ptr
+= bytes_read
;
715 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
718 /* Now read in declarations. */
719 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
720 abbrev_ptr
+= bytes_read
;
721 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
722 abbrev_ptr
+= bytes_read
;
726 if ((cur_abbrev
->num_attrs
% ATTR_ALLOC_CHUNK
) == 0)
728 struct attr_abbrev
*tmp
;
730 amt
= cur_abbrev
->num_attrs
+ ATTR_ALLOC_CHUNK
;
731 amt
*= sizeof (struct attr_abbrev
);
732 tmp
= (struct attr_abbrev
*) bfd_realloc (cur_abbrev
->attrs
, amt
);
737 for (i
= 0; i
< ABBREV_HASH_SIZE
; i
++)
739 struct abbrev_info
*abbrev
= abbrevs
[i
];
743 free (abbrev
->attrs
);
744 abbrev
= abbrev
->next
;
749 cur_abbrev
->attrs
= tmp
;
752 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
].name
753 = (enum dwarf_attribute
) abbrev_name
;
754 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
++].form
755 = (enum dwarf_form
) abbrev_form
;
756 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
757 abbrev_ptr
+= bytes_read
;
758 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
759 abbrev_ptr
+= bytes_read
;
762 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
763 cur_abbrev
->next
= abbrevs
[hash_number
];
764 abbrevs
[hash_number
] = cur_abbrev
;
766 /* Get next abbreviation.
767 Under Irix6 the abbreviations for a compilation unit are not
768 always properly terminated with an abbrev number of 0.
769 Exit loop if we encounter an abbreviation which we have
770 already read (which means we are about to read the abbreviations
771 for the next compile unit) or if the end of the abbreviation
773 if ((unsigned int) (abbrev_ptr
- stash
->dwarf_abbrev_buffer
)
774 >= stash
->dwarf_abbrev_size
)
776 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
777 abbrev_ptr
+= bytes_read
;
778 if (lookup_abbrev (abbrev_number
,abbrevs
) != NULL
)
785 /* Read an attribute value described by an attribute form. */
788 read_attribute_value (struct attribute
*attr
,
790 struct comp_unit
*unit
,
793 bfd
*abfd
= unit
->abfd
;
794 unsigned int bytes_read
;
795 struct dwarf_block
*blk
;
798 attr
->form
= (enum dwarf_form
) form
;
802 case DW_FORM_ref_addr
:
803 /* DW_FORM_ref_addr is an address in DWARF2, and an offset in
805 if (unit
->version
== 3 || unit
->version
== 4)
807 if (unit
->offset_size
== 4)
808 attr
->u
.val
= read_4_bytes (unit
->abfd
, info_ptr
);
810 attr
->u
.val
= read_8_bytes (unit
->abfd
, info_ptr
);
811 info_ptr
+= unit
->offset_size
;
816 attr
->u
.val
= read_address (unit
, info_ptr
);
817 info_ptr
+= unit
->addr_size
;
819 case DW_FORM_sec_offset
:
820 if (unit
->offset_size
== 4)
821 attr
->u
.val
= read_4_bytes (unit
->abfd
, info_ptr
);
823 attr
->u
.val
= read_8_bytes (unit
->abfd
, info_ptr
);
824 info_ptr
+= unit
->offset_size
;
827 amt
= sizeof (struct dwarf_block
);
828 blk
= (struct dwarf_block
*) bfd_alloc (abfd
, amt
);
831 blk
->size
= read_2_bytes (abfd
, info_ptr
);
833 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
834 info_ptr
+= blk
->size
;
838 amt
= sizeof (struct dwarf_block
);
839 blk
= (struct dwarf_block
*) bfd_alloc (abfd
, amt
);
842 blk
->size
= read_4_bytes (abfd
, info_ptr
);
844 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
845 info_ptr
+= blk
->size
;
849 attr
->u
.val
= read_2_bytes (abfd
, info_ptr
);
853 attr
->u
.val
= read_4_bytes (abfd
, info_ptr
);
857 attr
->u
.val
= read_8_bytes (abfd
, info_ptr
);
861 attr
->u
.str
= read_string (abfd
, info_ptr
, &bytes_read
);
862 info_ptr
+= bytes_read
;
865 attr
->u
.str
= read_indirect_string (unit
, info_ptr
, &bytes_read
);
866 info_ptr
+= bytes_read
;
868 case DW_FORM_exprloc
:
870 amt
= sizeof (struct dwarf_block
);
871 blk
= (struct dwarf_block
*) bfd_alloc (abfd
, amt
);
874 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
875 info_ptr
+= bytes_read
;
876 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
877 info_ptr
+= blk
->size
;
881 amt
= sizeof (struct dwarf_block
);
882 blk
= (struct dwarf_block
*) bfd_alloc (abfd
, amt
);
885 blk
->size
= read_1_byte (abfd
, info_ptr
);
887 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
888 info_ptr
+= blk
->size
;
892 attr
->u
.val
= read_1_byte (abfd
, info_ptr
);
896 attr
->u
.val
= read_1_byte (abfd
, info_ptr
);
899 case DW_FORM_flag_present
:
903 attr
->u
.sval
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
904 info_ptr
+= bytes_read
;
907 attr
->u
.val
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
908 info_ptr
+= bytes_read
;
911 attr
->u
.val
= read_1_byte (abfd
, info_ptr
);
915 attr
->u
.val
= read_2_bytes (abfd
, info_ptr
);
919 attr
->u
.val
= read_4_bytes (abfd
, info_ptr
);
923 attr
->u
.val
= read_8_bytes (abfd
, info_ptr
);
926 case DW_FORM_ref_sig8
:
927 attr
->u
.val
= read_8_bytes (abfd
, info_ptr
);
930 case DW_FORM_ref_udata
:
931 attr
->u
.val
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
932 info_ptr
+= bytes_read
;
934 case DW_FORM_indirect
:
935 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
936 info_ptr
+= bytes_read
;
937 info_ptr
= read_attribute_value (attr
, form
, unit
, info_ptr
);
940 (*_bfd_error_handler
) (_("Dwarf Error: Invalid or unhandled FORM value: %u."),
942 bfd_set_error (bfd_error_bad_value
);
948 /* Read an attribute described by an abbreviated attribute. */
951 read_attribute (struct attribute
*attr
,
952 struct attr_abbrev
*abbrev
,
953 struct comp_unit
*unit
,
956 attr
->name
= abbrev
->name
;
957 info_ptr
= read_attribute_value (attr
, abbrev
->form
, unit
, info_ptr
);
961 /* Source line information table routines. */
963 #define FILE_ALLOC_CHUNK 5
964 #define DIR_ALLOC_CHUNK 5
968 struct line_info
* prev_line
;
973 unsigned char op_index
;
974 unsigned char end_sequence
; /* End of (sequential) code sequence. */
988 struct line_sequence
* prev_sequence
;
989 struct line_info
* last_line
; /* Largest VMA. */
992 struct line_info_table
995 unsigned int num_files
;
996 unsigned int num_dirs
;
997 unsigned int num_sequences
;
1000 struct fileinfo
* files
;
1001 struct line_sequence
* sequences
;
1002 struct line_info
* lcl_head
; /* Local head; used in 'add_line_info'. */
1005 /* Remember some information about each function. If the function is
1006 inlined (DW_TAG_inlined_subroutine) it may have two additional
1007 attributes, DW_AT_call_file and DW_AT_call_line, which specify the
1008 source code location where this function was inlined. */
1012 struct funcinfo
*prev_func
; /* Pointer to previous function in list of all functions */
1013 struct funcinfo
*caller_func
; /* Pointer to function one scope higher */
1014 char *caller_file
; /* Source location file name where caller_func inlines this func */
1015 int caller_line
; /* Source location line number where caller_func inlines this func */
1016 char *file
; /* Source location file name */
1017 int line
; /* Source location line number */
1020 struct arange arange
;
1021 asection
*sec
; /* Where the symbol is defined */
1026 /* Pointer to previous variable in list of all variables */
1027 struct varinfo
*prev_var
;
1028 /* Source location file name */
1030 /* Source location line number */
1035 /* Where the symbol is defined */
1037 /* Is this a stack variable? */
1038 unsigned int stack
: 1;
1041 /* Return TRUE if NEW_LINE should sort after LINE. */
1043 static inline bfd_boolean
1044 new_line_sorts_after (struct line_info
*new_line
, struct line_info
*line
)
1046 return (new_line
->address
> line
->address
1047 || (new_line
->address
== line
->address
1048 && (new_line
->op_index
> line
->op_index
1049 || (new_line
->op_index
== line
->op_index
1050 && new_line
->end_sequence
< line
->end_sequence
))));
1054 /* Adds a new entry to the line_info list in the line_info_table, ensuring
1055 that the list is sorted. Note that the line_info list is sorted from
1056 highest to lowest VMA (with possible duplicates); that is,
1057 line_info->prev_line always accesses an equal or smaller VMA. */
1060 add_line_info (struct line_info_table
*table
,
1062 unsigned char op_index
,
1065 unsigned int column
,
1068 bfd_size_type amt
= sizeof (struct line_info
);
1069 struct line_sequence
* seq
= table
->sequences
;
1070 struct line_info
* info
= (struct line_info
*) bfd_alloc (table
->abfd
, amt
);
1075 /* Set member data of 'info'. */
1076 info
->prev_line
= NULL
;
1077 info
->address
= address
;
1078 info
->op_index
= op_index
;
1080 info
->column
= column
;
1081 info
->end_sequence
= end_sequence
;
1083 if (filename
&& filename
[0])
1085 info
->filename
= (char *) bfd_alloc (table
->abfd
, strlen (filename
) + 1);
1086 if (info
->filename
== NULL
)
1088 strcpy (info
->filename
, filename
);
1091 info
->filename
= NULL
;
1093 /* Find the correct location for 'info'. Normally we will receive
1094 new line_info data 1) in order and 2) with increasing VMAs.
1095 However some compilers break the rules (cf. decode_line_info) and
1096 so we include some heuristics for quickly finding the correct
1097 location for 'info'. In particular, these heuristics optimize for
1098 the common case in which the VMA sequence that we receive is a
1099 list of locally sorted VMAs such as
1100 p...z a...j (where a < j < p < z)
1102 Note: table->lcl_head is used to head an *actual* or *possible*
1103 sub-sequence within the list (such as a...j) that is not directly
1104 headed by table->last_line
1106 Note: we may receive duplicate entries from 'decode_line_info'. */
1109 && seq
->last_line
->address
== address
1110 && seq
->last_line
->op_index
== op_index
1111 && seq
->last_line
->end_sequence
== end_sequence
)
1113 /* We only keep the last entry with the same address and end
1114 sequence. See PR ld/4986. */
1115 if (table
->lcl_head
== seq
->last_line
)
1116 table
->lcl_head
= info
;
1117 info
->prev_line
= seq
->last_line
->prev_line
;
1118 seq
->last_line
= info
;
1120 else if (!seq
|| seq
->last_line
->end_sequence
)
1122 /* Start a new line sequence. */
1123 amt
= sizeof (struct line_sequence
);
1124 seq
= (struct line_sequence
*) bfd_malloc (amt
);
1127 seq
->low_pc
= address
;
1128 seq
->prev_sequence
= table
->sequences
;
1129 seq
->last_line
= info
;
1130 table
->lcl_head
= info
;
1131 table
->sequences
= seq
;
1132 table
->num_sequences
++;
1134 else if (new_line_sorts_after (info
, seq
->last_line
))
1136 /* Normal case: add 'info' to the beginning of the current sequence. */
1137 info
->prev_line
= seq
->last_line
;
1138 seq
->last_line
= info
;
1140 /* lcl_head: initialize to head a *possible* sequence at the end. */
1141 if (!table
->lcl_head
)
1142 table
->lcl_head
= info
;
1144 else if (!new_line_sorts_after (info
, table
->lcl_head
)
1145 && (!table
->lcl_head
->prev_line
1146 || new_line_sorts_after (info
, table
->lcl_head
->prev_line
)))
1148 /* Abnormal but easy: lcl_head is the head of 'info'. */
1149 info
->prev_line
= table
->lcl_head
->prev_line
;
1150 table
->lcl_head
->prev_line
= info
;
1154 /* Abnormal and hard: Neither 'last_line' nor 'lcl_head'
1155 are valid heads for 'info'. Reset 'lcl_head'. */
1156 struct line_info
* li2
= seq
->last_line
; /* Always non-NULL. */
1157 struct line_info
* li1
= li2
->prev_line
;
1161 if (!new_line_sorts_after (info
, li2
)
1162 && new_line_sorts_after (info
, li1
))
1165 li2
= li1
; /* always non-NULL */
1166 li1
= li1
->prev_line
;
1168 table
->lcl_head
= li2
;
1169 info
->prev_line
= table
->lcl_head
->prev_line
;
1170 table
->lcl_head
->prev_line
= info
;
1171 if (address
< seq
->low_pc
)
1172 seq
->low_pc
= address
;
1177 /* Extract a fully qualified filename from a line info table.
1178 The returned string has been malloc'ed and it is the caller's
1179 responsibility to free it. */
1182 concat_filename (struct line_info_table
*table
, unsigned int file
)
1186 if (file
- 1 >= table
->num_files
)
1188 /* FILE == 0 means unknown. */
1190 (*_bfd_error_handler
)
1191 (_("Dwarf Error: mangled line number section (bad file number)."));
1192 return strdup ("<unknown>");
1195 filename
= table
->files
[file
- 1].name
;
1197 if (!IS_ABSOLUTE_PATH (filename
))
1199 char *dir_name
= NULL
;
1200 char *subdir_name
= NULL
;
1204 if (table
->files
[file
- 1].dir
)
1205 subdir_name
= table
->dirs
[table
->files
[file
- 1].dir
- 1];
1207 if (!subdir_name
|| !IS_ABSOLUTE_PATH (subdir_name
))
1208 dir_name
= table
->comp_dir
;
1212 dir_name
= subdir_name
;
1217 return strdup (filename
);
1219 len
= strlen (dir_name
) + strlen (filename
) + 2;
1223 len
+= strlen (subdir_name
) + 1;
1224 name
= (char *) bfd_malloc (len
);
1226 sprintf (name
, "%s/%s/%s", dir_name
, subdir_name
, filename
);
1230 name
= (char *) bfd_malloc (len
);
1232 sprintf (name
, "%s/%s", dir_name
, filename
);
1238 return strdup (filename
);
1242 arange_add (bfd
*abfd
, struct arange
*first_arange
,
1243 bfd_vma low_pc
, bfd_vma high_pc
)
1245 struct arange
*arange
;
1247 /* If the first arange is empty, use it. */
1248 if (first_arange
->high
== 0)
1250 first_arange
->low
= low_pc
;
1251 first_arange
->high
= high_pc
;
1255 /* Next see if we can cheaply extend an existing range. */
1256 arange
= first_arange
;
1259 if (low_pc
== arange
->high
)
1261 arange
->high
= high_pc
;
1264 if (high_pc
== arange
->low
)
1266 arange
->low
= low_pc
;
1269 arange
= arange
->next
;
1273 /* Need to allocate a new arange and insert it into the arange list.
1274 Order isn't significant, so just insert after the first arange. */
1275 arange
= (struct arange
*) bfd_zalloc (abfd
, sizeof (*arange
));
1278 arange
->low
= low_pc
;
1279 arange
->high
= high_pc
;
1280 arange
->next
= first_arange
->next
;
1281 first_arange
->next
= arange
;
1285 /* Compare function for line sequences. */
1288 compare_sequences (const void* a
, const void* b
)
1290 const struct line_sequence
* seq1
= a
;
1291 const struct line_sequence
* seq2
= b
;
1293 /* Sort by low_pc as the primary key. */
1294 if (seq1
->low_pc
< seq2
->low_pc
)
1296 if (seq1
->low_pc
> seq2
->low_pc
)
1299 /* If low_pc values are equal, sort in reverse order of
1300 high_pc, so that the largest region comes first. */
1301 if (seq1
->last_line
->address
< seq2
->last_line
->address
)
1303 if (seq1
->last_line
->address
> seq2
->last_line
->address
)
1306 if (seq1
->last_line
->op_index
< seq2
->last_line
->op_index
)
1308 if (seq1
->last_line
->op_index
> seq2
->last_line
->op_index
)
1314 /* Sort the line sequences for quick lookup. */
1317 sort_line_sequences (struct line_info_table
* table
)
1320 struct line_sequence
* sequences
;
1321 struct line_sequence
* seq
;
1323 unsigned int num_sequences
= table
->num_sequences
;
1324 bfd_vma last_high_pc
;
1326 if (num_sequences
== 0)
1329 /* Allocate space for an array of sequences. */
1330 amt
= sizeof (struct line_sequence
) * num_sequences
;
1331 sequences
= (struct line_sequence
*) bfd_alloc (table
->abfd
, amt
);
1332 if (sequences
== NULL
)
1335 /* Copy the linked list into the array, freeing the original nodes. */
1336 seq
= table
->sequences
;
1337 for (n
= 0; n
< num_sequences
; n
++)
1339 struct line_sequence
* last_seq
= seq
;
1342 sequences
[n
].low_pc
= seq
->low_pc
;
1343 sequences
[n
].prev_sequence
= NULL
;
1344 sequences
[n
].last_line
= seq
->last_line
;
1345 seq
= seq
->prev_sequence
;
1348 BFD_ASSERT (seq
== NULL
);
1350 qsort (sequences
, n
, sizeof (struct line_sequence
), compare_sequences
);
1352 /* Make the list binary-searchable by trimming overlapping entries
1353 and removing nested entries. */
1355 last_high_pc
= sequences
[0].last_line
->address
;
1356 for (n
= 1; n
< table
->num_sequences
; n
++)
1358 if (sequences
[n
].low_pc
< last_high_pc
)
1360 if (sequences
[n
].last_line
->address
<= last_high_pc
)
1361 /* Skip nested entries. */
1364 /* Trim overlapping entries. */
1365 sequences
[n
].low_pc
= last_high_pc
;
1367 last_high_pc
= sequences
[n
].last_line
->address
;
1368 if (n
> num_sequences
)
1370 /* Close up the gap. */
1371 sequences
[num_sequences
].low_pc
= sequences
[n
].low_pc
;
1372 sequences
[num_sequences
].last_line
= sequences
[n
].last_line
;
1377 table
->sequences
= sequences
;
1378 table
->num_sequences
= num_sequences
;
1382 /* Decode the line number information for UNIT. */
1384 static struct line_info_table
*
1385 decode_line_info (struct comp_unit
*unit
, struct dwarf2_debug
*stash
)
1387 bfd
*abfd
= unit
->abfd
;
1388 struct line_info_table
* table
;
1391 struct line_head lh
;
1392 unsigned int i
, bytes_read
, offset_size
;
1393 char *cur_file
, *cur_dir
;
1394 unsigned char op_code
, extended_op
, adj_opcode
;
1397 if (! read_section (abfd
, debug_line
, stash
->syms
, unit
->line_offset
,
1398 &stash
->dwarf_line_buffer
, &stash
->dwarf_line_size
))
1401 amt
= sizeof (struct line_info_table
);
1402 table
= (struct line_info_table
*) bfd_alloc (abfd
, amt
);
1406 table
->comp_dir
= unit
->comp_dir
;
1408 table
->num_files
= 0;
1409 table
->files
= NULL
;
1411 table
->num_dirs
= 0;
1414 table
->num_sequences
= 0;
1415 table
->sequences
= NULL
;
1417 table
->lcl_head
= NULL
;
1419 line_ptr
= stash
->dwarf_line_buffer
+ unit
->line_offset
;
1421 /* Read in the prologue. */
1422 lh
.total_length
= read_4_bytes (abfd
, line_ptr
);
1425 if (lh
.total_length
== 0xffffffff)
1427 lh
.total_length
= read_8_bytes (abfd
, line_ptr
);
1431 else if (lh
.total_length
== 0 && unit
->addr_size
== 8)
1433 /* Handle (non-standard) 64-bit DWARF2 formats. */
1434 lh
.total_length
= read_4_bytes (abfd
, line_ptr
);
1438 line_end
= line_ptr
+ lh
.total_length
;
1439 lh
.version
= read_2_bytes (abfd
, line_ptr
);
1440 if (lh
.version
< 2 || lh
.version
> 4)
1442 (*_bfd_error_handler
)
1443 (_("Dwarf Error: Unhandled .debug_line version %d."), lh
.version
);
1444 bfd_set_error (bfd_error_bad_value
);
1448 if (offset_size
== 4)
1449 lh
.prologue_length
= read_4_bytes (abfd
, line_ptr
);
1451 lh
.prologue_length
= read_8_bytes (abfd
, line_ptr
);
1452 line_ptr
+= offset_size
;
1453 lh
.minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
1455 if (lh
.version
>= 4)
1457 lh
.maximum_ops_per_insn
= read_1_byte (abfd
, line_ptr
);
1461 lh
.maximum_ops_per_insn
= 1;
1462 if (lh
.maximum_ops_per_insn
== 0)
1464 (*_bfd_error_handler
)
1465 (_("Dwarf Error: Invalid maximum operations per instruction."));
1466 bfd_set_error (bfd_error_bad_value
);
1469 lh
.default_is_stmt
= read_1_byte (abfd
, line_ptr
);
1471 lh
.line_base
= read_1_signed_byte (abfd
, line_ptr
);
1473 lh
.line_range
= read_1_byte (abfd
, line_ptr
);
1475 lh
.opcode_base
= read_1_byte (abfd
, line_ptr
);
1477 amt
= lh
.opcode_base
* sizeof (unsigned char);
1478 lh
.standard_opcode_lengths
= (unsigned char *) bfd_alloc (abfd
, amt
);
1480 lh
.standard_opcode_lengths
[0] = 1;
1482 for (i
= 1; i
< lh
.opcode_base
; ++i
)
1484 lh
.standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
1488 /* Read directory table. */
1489 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
1491 line_ptr
+= bytes_read
;
1493 if ((table
->num_dirs
% DIR_ALLOC_CHUNK
) == 0)
1497 amt
= table
->num_dirs
+ DIR_ALLOC_CHUNK
;
1498 amt
*= sizeof (char *);
1500 tmp
= (char **) bfd_realloc (table
->dirs
, amt
);
1506 table
->dirs
[table
->num_dirs
++] = cur_dir
;
1509 line_ptr
+= bytes_read
;
1511 /* Read file name table. */
1512 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
1514 line_ptr
+= bytes_read
;
1516 if ((table
->num_files
% FILE_ALLOC_CHUNK
) == 0)
1518 struct fileinfo
*tmp
;
1520 amt
= table
->num_files
+ FILE_ALLOC_CHUNK
;
1521 amt
*= sizeof (struct fileinfo
);
1523 tmp
= (struct fileinfo
*) bfd_realloc (table
->files
, amt
);
1529 table
->files
[table
->num_files
].name
= cur_file
;
1530 table
->files
[table
->num_files
].dir
=
1531 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
1532 line_ptr
+= bytes_read
;
1533 table
->files
[table
->num_files
].time
=
1534 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
1535 line_ptr
+= bytes_read
;
1536 table
->files
[table
->num_files
].size
=
1537 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
1538 line_ptr
+= bytes_read
;
1542 line_ptr
+= bytes_read
;
1544 /* Read the statement sequences until there's nothing left. */
1545 while (line_ptr
< line_end
)
1547 /* State machine registers. */
1548 bfd_vma address
= 0;
1549 unsigned char op_index
= 0;
1550 char * filename
= table
->num_files
? concat_filename (table
, 1) : NULL
;
1551 unsigned int line
= 1;
1552 unsigned int column
= 0;
1553 int is_stmt
= lh
.default_is_stmt
;
1554 int end_sequence
= 0;
1555 /* eraxxon@alumni.rice.edu: Against the DWARF2 specs, some
1556 compilers generate address sequences that are wildly out of
1557 order using DW_LNE_set_address (e.g. Intel C++ 6.0 compiler
1558 for ia64-Linux). Thus, to determine the low and high
1559 address, we must compare on every DW_LNS_copy, etc. */
1560 bfd_vma low_pc
= (bfd_vma
) -1;
1561 bfd_vma high_pc
= 0;
1563 /* Decode the table. */
1564 while (! end_sequence
)
1566 op_code
= read_1_byte (abfd
, line_ptr
);
1569 if (op_code
>= lh
.opcode_base
)
1571 /* Special operand. */
1572 adj_opcode
= op_code
- lh
.opcode_base
;
1573 if (lh
.maximum_ops_per_insn
== 1)
1574 address
+= (adj_opcode
/ lh
.line_range
)
1575 * lh
.minimum_instruction_length
;
1578 address
+= ((op_index
+ (adj_opcode
/ lh
.line_range
))
1579 / lh
.maximum_ops_per_insn
)
1580 * lh
.minimum_instruction_length
;
1581 op_index
= (op_index
+ (adj_opcode
/ lh
.line_range
))
1582 % lh
.maximum_ops_per_insn
;
1584 line
+= lh
.line_base
+ (adj_opcode
% lh
.line_range
);
1585 /* Append row to matrix using current values. */
1586 if (!add_line_info (table
, address
, op_index
, filename
,
1589 if (address
< low_pc
)
1591 if (address
> high_pc
)
1594 else switch (op_code
)
1596 case DW_LNS_extended_op
:
1597 /* Ignore length. */
1599 extended_op
= read_1_byte (abfd
, line_ptr
);
1602 switch (extended_op
)
1604 case DW_LNE_end_sequence
:
1606 if (!add_line_info (table
, address
, op_index
, filename
,
1607 line
, column
, end_sequence
))
1609 if (address
< low_pc
)
1611 if (address
> high_pc
)
1613 if (!arange_add (unit
->abfd
, &unit
->arange
, low_pc
, high_pc
))
1616 case DW_LNE_set_address
:
1617 address
= read_address (unit
, line_ptr
);
1619 line_ptr
+= unit
->addr_size
;
1621 case DW_LNE_define_file
:
1622 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
1623 line_ptr
+= bytes_read
;
1624 if ((table
->num_files
% FILE_ALLOC_CHUNK
) == 0)
1626 struct fileinfo
*tmp
;
1628 amt
= table
->num_files
+ FILE_ALLOC_CHUNK
;
1629 amt
*= sizeof (struct fileinfo
);
1630 tmp
= (struct fileinfo
*) bfd_realloc (table
->files
, amt
);
1635 table
->files
[table
->num_files
].name
= cur_file
;
1636 table
->files
[table
->num_files
].dir
=
1637 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
1638 line_ptr
+= bytes_read
;
1639 table
->files
[table
->num_files
].time
=
1640 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
1641 line_ptr
+= bytes_read
;
1642 table
->files
[table
->num_files
].size
=
1643 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
1644 line_ptr
+= bytes_read
;
1647 case DW_LNE_set_discriminator
:
1648 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
1649 line_ptr
+= bytes_read
;
1652 (*_bfd_error_handler
) (_("Dwarf Error: mangled line number section."));
1653 bfd_set_error (bfd_error_bad_value
);
1655 if (filename
!= NULL
)
1661 if (!add_line_info (table
, address
, op_index
,
1662 filename
, line
, column
, 0))
1664 if (address
< low_pc
)
1666 if (address
> high_pc
)
1669 case DW_LNS_advance_pc
:
1670 if (lh
.maximum_ops_per_insn
== 1)
1671 address
+= lh
.minimum_instruction_length
1672 * read_unsigned_leb128 (abfd
, line_ptr
,
1676 bfd_vma adjust
= read_unsigned_leb128 (abfd
, line_ptr
,
1678 address
= ((op_index
+ adjust
) / lh
.maximum_ops_per_insn
)
1679 * lh
.minimum_instruction_length
;
1680 op_index
= (op_index
+ adjust
) % lh
.maximum_ops_per_insn
;
1682 line_ptr
+= bytes_read
;
1684 case DW_LNS_advance_line
:
1685 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
1686 line_ptr
+= bytes_read
;
1688 case DW_LNS_set_file
:
1692 /* The file and directory tables are 0
1693 based, the references are 1 based. */
1694 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
1695 line_ptr
+= bytes_read
;
1698 filename
= concat_filename (table
, file
);
1701 case DW_LNS_set_column
:
1702 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
1703 line_ptr
+= bytes_read
;
1705 case DW_LNS_negate_stmt
:
1706 is_stmt
= (!is_stmt
);
1708 case DW_LNS_set_basic_block
:
1710 case DW_LNS_const_add_pc
:
1711 if (lh
.maximum_ops_per_insn
== 1)
1712 address
+= lh
.minimum_instruction_length
1713 * ((255 - lh
.opcode_base
) / lh
.line_range
);
1716 bfd_vma adjust
= ((255 - lh
.opcode_base
) / lh
.line_range
);
1717 address
+= lh
.minimum_instruction_length
1718 * ((op_index
+ adjust
) / lh
.maximum_ops_per_insn
);
1719 op_index
= (op_index
+ adjust
) % lh
.maximum_ops_per_insn
;
1722 case DW_LNS_fixed_advance_pc
:
1723 address
+= read_2_bytes (abfd
, line_ptr
);
1728 /* Unknown standard opcode, ignore it. */
1729 for (i
= 0; i
< lh
.standard_opcode_lengths
[op_code
]; i
++)
1731 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
1732 line_ptr
+= bytes_read
;
1742 if (sort_line_sequences (table
))
1746 if (table
->sequences
!= NULL
)
1747 free (table
->sequences
);
1748 if (table
->files
!= NULL
)
1749 free (table
->files
);
1750 if (table
->dirs
!= NULL
)
1755 /* If ADDR is within TABLE set the output parameters and return TRUE,
1756 otherwise return FALSE. The output parameters, FILENAME_PTR and
1757 LINENUMBER_PTR, are pointers to the objects to be filled in. */
1760 lookup_address_in_line_info_table (struct line_info_table
*table
,
1762 const char **filename_ptr
,
1763 unsigned int *linenumber_ptr
)
1765 struct line_sequence
*seq
= NULL
;
1766 struct line_info
*each_line
;
1769 /* Binary search the array of sequences. */
1771 high
= table
->num_sequences
;
1774 mid
= (low
+ high
) / 2;
1775 seq
= &table
->sequences
[mid
];
1776 if (addr
< seq
->low_pc
)
1778 else if (addr
>= seq
->last_line
->address
)
1784 if (seq
&& addr
>= seq
->low_pc
&& addr
< seq
->last_line
->address
)
1786 /* Note: seq->last_line should be a descendingly sorted list. */
1787 for (each_line
= seq
->last_line
;
1789 each_line
= each_line
->prev_line
)
1790 if (addr
>= each_line
->address
)
1794 && !(each_line
->end_sequence
|| each_line
== seq
->last_line
))
1796 *filename_ptr
= each_line
->filename
;
1797 *linenumber_ptr
= each_line
->line
;
1802 *filename_ptr
= NULL
;
1806 /* Read in the .debug_ranges section for future reference. */
1809 read_debug_ranges (struct comp_unit
*unit
)
1811 struct dwarf2_debug
*stash
= unit
->stash
;
1812 return read_section (unit
->abfd
, debug_ranges
, stash
->syms
, 0,
1813 &stash
->dwarf_ranges_buffer
, &stash
->dwarf_ranges_size
);
1816 /* Function table functions. */
1818 /* If ADDR is within TABLE, set FUNCTIONNAME_PTR, and return TRUE.
1819 Note that we need to find the function that has the smallest
1820 range that contains ADDR, to handle inlined functions without
1821 depending upon them being ordered in TABLE by increasing range. */
1824 lookup_address_in_function_table (struct comp_unit
*unit
,
1826 struct funcinfo
**function_ptr
,
1827 const char **functionname_ptr
)
1829 struct funcinfo
* each_func
;
1830 struct funcinfo
* best_fit
= NULL
;
1831 struct arange
*arange
;
1833 for (each_func
= unit
->function_table
;
1835 each_func
= each_func
->prev_func
)
1837 for (arange
= &each_func
->arange
;
1839 arange
= arange
->next
)
1841 if (addr
>= arange
->low
&& addr
< arange
->high
)
1844 ((arange
->high
- arange
->low
) < (best_fit
->arange
.high
- best_fit
->arange
.low
)))
1845 best_fit
= each_func
;
1852 *functionname_ptr
= best_fit
->name
;
1853 *function_ptr
= best_fit
;
1862 /* If SYM at ADDR is within function table of UNIT, set FILENAME_PTR
1863 and LINENUMBER_PTR, and return TRUE. */
1866 lookup_symbol_in_function_table (struct comp_unit
*unit
,
1869 const char **filename_ptr
,
1870 unsigned int *linenumber_ptr
)
1872 struct funcinfo
* each_func
;
1873 struct funcinfo
* best_fit
= NULL
;
1874 struct arange
*arange
;
1875 const char *name
= bfd_asymbol_name (sym
);
1876 asection
*sec
= bfd_get_section (sym
);
1878 for (each_func
= unit
->function_table
;
1880 each_func
= each_func
->prev_func
)
1882 for (arange
= &each_func
->arange
;
1884 arange
= arange
->next
)
1886 if ((!each_func
->sec
|| each_func
->sec
== sec
)
1887 && addr
>= arange
->low
1888 && addr
< arange
->high
1890 && strcmp (name
, each_func
->name
) == 0
1892 || ((arange
->high
- arange
->low
)
1893 < (best_fit
->arange
.high
- best_fit
->arange
.low
))))
1894 best_fit
= each_func
;
1900 best_fit
->sec
= sec
;
1901 *filename_ptr
= best_fit
->file
;
1902 *linenumber_ptr
= best_fit
->line
;
1909 /* Variable table functions. */
1911 /* If SYM is within variable table of UNIT, set FILENAME_PTR and
1912 LINENUMBER_PTR, and return TRUE. */
1915 lookup_symbol_in_variable_table (struct comp_unit
*unit
,
1918 const char **filename_ptr
,
1919 unsigned int *linenumber_ptr
)
1921 const char *name
= bfd_asymbol_name (sym
);
1922 asection
*sec
= bfd_get_section (sym
);
1923 struct varinfo
* each
;
1925 for (each
= unit
->variable_table
; each
; each
= each
->prev_var
)
1926 if (each
->stack
== 0
1927 && each
->file
!= NULL
1928 && each
->name
!= NULL
1929 && each
->addr
== addr
1930 && (!each
->sec
|| each
->sec
== sec
)
1931 && strcmp (name
, each
->name
) == 0)
1937 *filename_ptr
= each
->file
;
1938 *linenumber_ptr
= each
->line
;
1946 find_abstract_instance_name (struct comp_unit
*unit
,
1947 struct attribute
*attr_ptr
)
1949 bfd
*abfd
= unit
->abfd
;
1951 unsigned int abbrev_number
, bytes_read
, i
;
1952 struct abbrev_info
*abbrev
;
1953 bfd_uint64_t die_ref
= attr_ptr
->u
.val
;
1954 struct attribute attr
;
1957 /* DW_FORM_ref_addr can reference an entry in a different CU. It
1958 is an offset from the .debug_info section, not the current CU. */
1959 if (attr_ptr
->form
== DW_FORM_ref_addr
)
1961 /* We only support DW_FORM_ref_addr within the same file, so
1962 any relocations should be resolved already. */
1966 info_ptr
= unit
->sec_info_ptr
+ die_ref
;
1969 info_ptr
= unit
->info_ptr_unit
+ die_ref
;
1970 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
1971 info_ptr
+= bytes_read
;
1975 abbrev
= lookup_abbrev (abbrev_number
, unit
->abbrevs
);
1978 (*_bfd_error_handler
) (_("Dwarf Error: Could not find abbrev number %u."),
1980 bfd_set_error (bfd_error_bad_value
);
1984 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
1986 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], unit
,
1988 if (info_ptr
== NULL
)
1993 /* Prefer DW_AT_MIPS_linkage_name or DW_AT_linkage_name
1998 case DW_AT_specification
:
1999 name
= find_abstract_instance_name (unit
, &attr
);
2001 case DW_AT_linkage_name
:
2002 case DW_AT_MIPS_linkage_name
:
2015 read_rangelist (struct comp_unit
*unit
, struct arange
*arange
,
2016 bfd_uint64_t offset
)
2018 bfd_byte
*ranges_ptr
;
2019 bfd_vma base_address
= unit
->base_address
;
2021 if (! unit
->stash
->dwarf_ranges_buffer
)
2023 if (! read_debug_ranges (unit
))
2026 ranges_ptr
= unit
->stash
->dwarf_ranges_buffer
+ offset
;
2033 low_pc
= read_address (unit
, ranges_ptr
);
2034 ranges_ptr
+= unit
->addr_size
;
2035 high_pc
= read_address (unit
, ranges_ptr
);
2036 ranges_ptr
+= unit
->addr_size
;
2038 if (low_pc
== 0 && high_pc
== 0)
2040 if (low_pc
== -1UL && high_pc
!= -1UL)
2041 base_address
= high_pc
;
2044 if (!arange_add (unit
->abfd
, arange
,
2045 base_address
+ low_pc
, base_address
+ high_pc
))
2052 /* DWARF2 Compilation unit functions. */
2054 /* Scan over each die in a comp. unit looking for functions to add
2055 to the function table and variables to the variable table. */
2058 scan_unit_for_symbols (struct comp_unit
*unit
)
2060 bfd
*abfd
= unit
->abfd
;
2061 bfd_byte
*info_ptr
= unit
->first_child_die_ptr
;
2062 int nesting_level
= 1;
2063 struct funcinfo
**nested_funcs
;
2064 int nested_funcs_size
;
2066 /* Maintain a stack of in-scope functions and inlined functions, which we
2067 can use to set the caller_func field. */
2068 nested_funcs_size
= 32;
2069 nested_funcs
= (struct funcinfo
**)
2070 bfd_malloc (nested_funcs_size
* sizeof (struct funcinfo
*));
2071 if (nested_funcs
== NULL
)
2073 nested_funcs
[nesting_level
] = 0;
2075 while (nesting_level
)
2077 unsigned int abbrev_number
, bytes_read
, i
;
2078 struct abbrev_info
*abbrev
;
2079 struct attribute attr
;
2080 struct funcinfo
*func
;
2081 struct varinfo
*var
;
2083 bfd_vma high_pc
= 0;
2085 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2086 info_ptr
+= bytes_read
;
2088 if (! abbrev_number
)
2094 abbrev
= lookup_abbrev (abbrev_number
,unit
->abbrevs
);
2097 (*_bfd_error_handler
)
2098 (_("Dwarf Error: Could not find abbrev number %u."),
2100 bfd_set_error (bfd_error_bad_value
);
2105 if (abbrev
->tag
== DW_TAG_subprogram
2106 || abbrev
->tag
== DW_TAG_entry_point
2107 || abbrev
->tag
== DW_TAG_inlined_subroutine
)
2109 bfd_size_type amt
= sizeof (struct funcinfo
);
2110 func
= (struct funcinfo
*) bfd_zalloc (abfd
, amt
);
2113 func
->tag
= abbrev
->tag
;
2114 func
->prev_func
= unit
->function_table
;
2115 unit
->function_table
= func
;
2116 BFD_ASSERT (!unit
->cached
);
2118 if (func
->tag
== DW_TAG_inlined_subroutine
)
2119 for (i
= nesting_level
- 1; i
>= 1; i
--)
2120 if (nested_funcs
[i
])
2122 func
->caller_func
= nested_funcs
[i
];
2125 nested_funcs
[nesting_level
] = func
;
2130 if (abbrev
->tag
== DW_TAG_variable
)
2132 bfd_size_type amt
= sizeof (struct varinfo
);
2133 var
= (struct varinfo
*) bfd_zalloc (abfd
, amt
);
2136 var
->tag
= abbrev
->tag
;
2138 var
->prev_var
= unit
->variable_table
;
2139 unit
->variable_table
= var
;
2140 BFD_ASSERT (!unit
->cached
);
2143 /* No inline function in scope at this nesting level. */
2144 nested_funcs
[nesting_level
] = 0;
2147 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
2149 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], unit
, info_ptr
);
2150 if (info_ptr
== NULL
)
2157 case DW_AT_call_file
:
2158 func
->caller_file
= concat_filename (unit
->line_table
,
2162 case DW_AT_call_line
:
2163 func
->caller_line
= attr
.u
.val
;
2166 case DW_AT_abstract_origin
:
2167 func
->name
= find_abstract_instance_name (unit
, &attr
);
2171 /* Prefer DW_AT_MIPS_linkage_name or DW_AT_linkage_name
2173 if (func
->name
== NULL
)
2174 func
->name
= attr
.u
.str
;
2177 case DW_AT_linkage_name
:
2178 case DW_AT_MIPS_linkage_name
:
2179 func
->name
= attr
.u
.str
;
2183 low_pc
= attr
.u
.val
;
2187 high_pc
= attr
.u
.val
;
2191 if (!read_rangelist (unit
, &func
->arange
, attr
.u
.val
))
2195 case DW_AT_decl_file
:
2196 func
->file
= concat_filename (unit
->line_table
,
2200 case DW_AT_decl_line
:
2201 func
->line
= attr
.u
.val
;
2213 var
->name
= attr
.u
.str
;
2216 case DW_AT_decl_file
:
2217 var
->file
= concat_filename (unit
->line_table
,
2221 case DW_AT_decl_line
:
2222 var
->line
= attr
.u
.val
;
2225 case DW_AT_external
:
2226 if (attr
.u
.val
!= 0)
2230 case DW_AT_location
:
2234 case DW_FORM_block1
:
2235 case DW_FORM_block2
:
2236 case DW_FORM_block4
:
2237 case DW_FORM_exprloc
:
2238 if (*attr
.u
.blk
->data
== DW_OP_addr
)
2242 /* Verify that DW_OP_addr is the only opcode in the
2243 location, in which case the block size will be 1
2244 plus the address size. */
2245 /* ??? For TLS variables, gcc can emit
2246 DW_OP_addr <addr> DW_OP_GNU_push_tls_address
2247 which we don't handle here yet. */
2248 if (attr
.u
.blk
->size
== unit
->addr_size
+ 1U)
2249 var
->addr
= bfd_get (unit
->addr_size
* 8,
2251 attr
.u
.blk
->data
+ 1);
2266 if (func
&& high_pc
!= 0)
2268 if (!arange_add (unit
->abfd
, &func
->arange
, low_pc
, high_pc
))
2272 if (abbrev
->has_children
)
2276 if (nesting_level
>= nested_funcs_size
)
2278 struct funcinfo
**tmp
;
2280 nested_funcs_size
*= 2;
2281 tmp
= (struct funcinfo
**)
2282 bfd_realloc (nested_funcs
,
2283 (nested_funcs_size
* sizeof (struct funcinfo
*)));
2288 nested_funcs
[nesting_level
] = 0;
2292 free (nested_funcs
);
2296 free (nested_funcs
);
2300 /* Parse a DWARF2 compilation unit starting at INFO_PTR. This
2301 includes the compilation unit header that proceeds the DIE's, but
2302 does not include the length field that precedes each compilation
2303 unit header. END_PTR points one past the end of this comp unit.
2304 OFFSET_SIZE is the size of DWARF2 offsets (either 4 or 8 bytes).
2306 This routine does not read the whole compilation unit; only enough
2307 to get to the line number information for the compilation unit. */
2309 static struct comp_unit
*
2310 parse_comp_unit (struct dwarf2_debug
*stash
,
2311 bfd_vma unit_length
,
2312 bfd_byte
*info_ptr_unit
,
2313 unsigned int offset_size
)
2315 struct comp_unit
* unit
;
2316 unsigned int version
;
2317 bfd_uint64_t abbrev_offset
= 0;
2318 unsigned int addr_size
;
2319 struct abbrev_info
** abbrevs
;
2320 unsigned int abbrev_number
, bytes_read
, i
;
2321 struct abbrev_info
*abbrev
;
2322 struct attribute attr
;
2323 bfd_byte
*info_ptr
= stash
->info_ptr
;
2324 bfd_byte
*end_ptr
= info_ptr
+ unit_length
;
2327 bfd_vma high_pc
= 0;
2328 bfd
*abfd
= stash
->bfd_ptr
;
2330 version
= read_2_bytes (abfd
, info_ptr
);
2332 BFD_ASSERT (offset_size
== 4 || offset_size
== 8);
2333 if (offset_size
== 4)
2334 abbrev_offset
= read_4_bytes (abfd
, info_ptr
);
2336 abbrev_offset
= read_8_bytes (abfd
, info_ptr
);
2337 info_ptr
+= offset_size
;
2338 addr_size
= read_1_byte (abfd
, info_ptr
);
2341 if (version
!= 2 && version
!= 3 && version
!= 4)
2343 (*_bfd_error_handler
) (_("Dwarf Error: found dwarf version '%u', this reader only handles version 2, 3 and 4 information."), version
);
2344 bfd_set_error (bfd_error_bad_value
);
2348 if (addr_size
> sizeof (bfd_vma
))
2350 (*_bfd_error_handler
) (_("Dwarf Error: found address size '%u', this reader can not handle sizes greater than '%u'."),
2352 (unsigned int) sizeof (bfd_vma
));
2353 bfd_set_error (bfd_error_bad_value
);
2357 if (addr_size
!= 2 && addr_size
!= 4 && addr_size
!= 8)
2359 (*_bfd_error_handler
) ("Dwarf Error: found address size '%u', this reader can only handle address sizes '2', '4' and '8'.", addr_size
);
2360 bfd_set_error (bfd_error_bad_value
);
2364 /* Read the abbrevs for this compilation unit into a table. */
2365 abbrevs
= read_abbrevs (abfd
, abbrev_offset
, stash
);
2369 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2370 info_ptr
+= bytes_read
;
2371 if (! abbrev_number
)
2373 (*_bfd_error_handler
) (_("Dwarf Error: Bad abbrev number: %u."),
2375 bfd_set_error (bfd_error_bad_value
);
2379 abbrev
= lookup_abbrev (abbrev_number
, abbrevs
);
2382 (*_bfd_error_handler
) (_("Dwarf Error: Could not find abbrev number %u."),
2384 bfd_set_error (bfd_error_bad_value
);
2388 amt
= sizeof (struct comp_unit
);
2389 unit
= (struct comp_unit
*) bfd_zalloc (abfd
, amt
);
2393 unit
->version
= version
;
2394 unit
->addr_size
= addr_size
;
2395 unit
->offset_size
= offset_size
;
2396 unit
->abbrevs
= abbrevs
;
2397 unit
->end_ptr
= end_ptr
;
2398 unit
->stash
= stash
;
2399 unit
->info_ptr_unit
= info_ptr_unit
;
2400 unit
->sec_info_ptr
= stash
->sec_info_ptr
;
2402 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
2404 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], unit
, info_ptr
);
2405 if (info_ptr
== NULL
)
2408 /* Store the data if it is of an attribute we want to keep in a
2409 partial symbol table. */
2412 case DW_AT_stmt_list
:
2414 unit
->line_offset
= attr
.u
.val
;
2418 unit
->name
= attr
.u
.str
;
2422 low_pc
= attr
.u
.val
;
2423 /* If the compilation unit DIE has a DW_AT_low_pc attribute,
2424 this is the base address to use when reading location
2425 lists or range lists. */
2426 unit
->base_address
= low_pc
;
2430 high_pc
= attr
.u
.val
;
2434 if (!read_rangelist (unit
, &unit
->arange
, attr
.u
.val
))
2438 case DW_AT_comp_dir
:
2440 char *comp_dir
= attr
.u
.str
;
2443 /* Irix 6.2 native cc prepends <machine>.: to the compilation
2444 directory, get rid of it. */
2445 char *cp
= strchr (comp_dir
, ':');
2447 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
2450 unit
->comp_dir
= comp_dir
;
2460 if (!arange_add (unit
->abfd
, &unit
->arange
, low_pc
, high_pc
))
2464 unit
->first_child_die_ptr
= info_ptr
;
2468 /* Return TRUE if UNIT may contain the address given by ADDR. When
2469 there are functions written entirely with inline asm statements, the
2470 range info in the compilation unit header may not be correct. We
2471 need to consult the line info table to see if a compilation unit
2472 really contains the given address. */
2475 comp_unit_contains_address (struct comp_unit
*unit
, bfd_vma addr
)
2477 struct arange
*arange
;
2482 arange
= &unit
->arange
;
2485 if (addr
>= arange
->low
&& addr
< arange
->high
)
2487 arange
= arange
->next
;
2494 /* If UNIT contains ADDR, set the output parameters to the values for
2495 the line containing ADDR. The output parameters, FILENAME_PTR,
2496 FUNCTIONNAME_PTR, and LINENUMBER_PTR, are pointers to the objects
2499 Return TRUE if UNIT contains ADDR, and no errors were encountered;
2503 comp_unit_find_nearest_line (struct comp_unit
*unit
,
2505 const char **filename_ptr
,
2506 const char **functionname_ptr
,
2507 unsigned int *linenumber_ptr
,
2508 struct dwarf2_debug
*stash
)
2512 struct funcinfo
*function
;
2517 if (! unit
->line_table
)
2519 if (! unit
->stmtlist
)
2525 unit
->line_table
= decode_line_info (unit
, stash
);
2527 if (! unit
->line_table
)
2533 if (unit
->first_child_die_ptr
< unit
->end_ptr
2534 && ! scan_unit_for_symbols (unit
))
2542 func_p
= lookup_address_in_function_table (unit
, addr
,
2543 &function
, functionname_ptr
);
2544 if (func_p
&& (function
->tag
== DW_TAG_inlined_subroutine
))
2545 stash
->inliner_chain
= function
;
2546 line_p
= lookup_address_in_line_info_table (unit
->line_table
, addr
,
2549 return line_p
|| func_p
;
2552 /* Check to see if line info is already decoded in a comp_unit.
2553 If not, decode it. Returns TRUE if no errors were encountered;
2557 comp_unit_maybe_decode_line_info (struct comp_unit
*unit
,
2558 struct dwarf2_debug
*stash
)
2563 if (! unit
->line_table
)
2565 if (! unit
->stmtlist
)
2571 unit
->line_table
= decode_line_info (unit
, stash
);
2573 if (! unit
->line_table
)
2579 if (unit
->first_child_die_ptr
< unit
->end_ptr
2580 && ! scan_unit_for_symbols (unit
))
2590 /* If UNIT contains SYM at ADDR, set the output parameters to the
2591 values for the line containing SYM. The output parameters,
2592 FILENAME_PTR, and LINENUMBER_PTR, are pointers to the objects to be
2595 Return TRUE if UNIT contains SYM, and no errors were encountered;
2599 comp_unit_find_line (struct comp_unit
*unit
,
2602 const char **filename_ptr
,
2603 unsigned int *linenumber_ptr
,
2604 struct dwarf2_debug
*stash
)
2606 if (!comp_unit_maybe_decode_line_info (unit
, stash
))
2609 if (sym
->flags
& BSF_FUNCTION
)
2610 return lookup_symbol_in_function_table (unit
, sym
, addr
,
2614 return lookup_symbol_in_variable_table (unit
, sym
, addr
,
2619 static struct funcinfo
*
2620 reverse_funcinfo_list (struct funcinfo
*head
)
2622 struct funcinfo
*rhead
;
2623 struct funcinfo
*temp
;
2625 for (rhead
= NULL
; head
; head
= temp
)
2627 temp
= head
->prev_func
;
2628 head
->prev_func
= rhead
;
2634 static struct varinfo
*
2635 reverse_varinfo_list (struct varinfo
*head
)
2637 struct varinfo
*rhead
;
2638 struct varinfo
*temp
;
2640 for (rhead
= NULL
; head
; head
= temp
)
2642 temp
= head
->prev_var
;
2643 head
->prev_var
= rhead
;
2649 /* Extract all interesting funcinfos and varinfos of a compilation
2650 unit into hash tables for faster lookup. Returns TRUE if no
2651 errors were enountered; FALSE otherwise. */
2654 comp_unit_hash_info (struct dwarf2_debug
*stash
,
2655 struct comp_unit
*unit
,
2656 struct info_hash_table
*funcinfo_hash_table
,
2657 struct info_hash_table
*varinfo_hash_table
)
2659 struct funcinfo
* each_func
;
2660 struct varinfo
* each_var
;
2661 bfd_boolean okay
= TRUE
;
2663 BFD_ASSERT (stash
->info_hash_status
!= STASH_INFO_HASH_DISABLED
);
2665 if (!comp_unit_maybe_decode_line_info (unit
, stash
))
2668 BFD_ASSERT (!unit
->cached
);
2670 /* To preserve the original search order, we went to visit the function
2671 infos in the reversed order of the list. However, making the list
2672 bi-directional use quite a bit of extra memory. So we reverse
2673 the list first, traverse the list in the now reversed order and
2674 finally reverse the list again to get back the original order. */
2675 unit
->function_table
= reverse_funcinfo_list (unit
->function_table
);
2676 for (each_func
= unit
->function_table
;
2678 each_func
= each_func
->prev_func
)
2680 /* Skip nameless functions. */
2681 if (each_func
->name
)
2682 /* There is no need to copy name string into hash table as
2683 name string is either in the dwarf string buffer or
2684 info in the stash. */
2685 okay
= insert_info_hash_table (funcinfo_hash_table
, each_func
->name
,
2686 (void*) each_func
, FALSE
);
2688 unit
->function_table
= reverse_funcinfo_list (unit
->function_table
);
2692 /* We do the same for variable infos. */
2693 unit
->variable_table
= reverse_varinfo_list (unit
->variable_table
);
2694 for (each_var
= unit
->variable_table
;
2696 each_var
= each_var
->prev_var
)
2698 /* Skip stack vars and vars with no files or names. */
2699 if (each_var
->stack
== 0
2700 && each_var
->file
!= NULL
2701 && each_var
->name
!= NULL
)
2702 /* There is no need to copy name string into hash table as
2703 name string is either in the dwarf string buffer or
2704 info in the stash. */
2705 okay
= insert_info_hash_table (varinfo_hash_table
, each_var
->name
,
2706 (void*) each_var
, FALSE
);
2709 unit
->variable_table
= reverse_varinfo_list (unit
->variable_table
);
2710 unit
->cached
= TRUE
;
2714 /* Locate a section in a BFD containing debugging info. The search starts
2715 from the section after AFTER_SEC, or from the first section in the BFD if
2716 AFTER_SEC is NULL. The search works by examining the names of the
2717 sections. There are two permissiable names. The first is .debug_info.
2718 This is the standard DWARF2 name. The second is a prefix .gnu.linkonce.wi.
2719 This is a variation on the .debug_info section which has a checksum
2720 describing the contents appended onto the name. This allows the linker to
2721 identify and discard duplicate debugging sections for different
2722 compilation units. */
2723 #define DWARF2_DEBUG_INFO ".debug_info"
2724 #define DWARF2_COMPRESSED_DEBUG_INFO ".zdebug_info"
2725 #define GNU_LINKONCE_INFO ".gnu.linkonce.wi."
2728 find_debug_info (bfd
*abfd
, asection
*after_sec
)
2732 msec
= after_sec
!= NULL
? after_sec
->next
: abfd
->sections
;
2736 if (strcmp (msec
->name
, DWARF2_DEBUG_INFO
) == 0)
2739 if (strcmp (msec
->name
, DWARF2_COMPRESSED_DEBUG_INFO
) == 0)
2742 if (CONST_STRNEQ (msec
->name
, GNU_LINKONCE_INFO
))
2751 /* Unset vmas for adjusted sections in STASH. */
2754 unset_sections (struct dwarf2_debug
*stash
)
2757 struct adjusted_section
*p
;
2759 i
= stash
->adjusted_section_count
;
2760 p
= stash
->adjusted_sections
;
2761 for (; i
> 0; i
--, p
++)
2762 p
->section
->vma
= 0;
2765 /* Set unique VMAs for loadable and DWARF sections in ABFD and save
2766 VMAs in STASH for unset_sections. */
2769 place_sections (bfd
*abfd
, struct dwarf2_debug
*stash
)
2771 struct adjusted_section
*p
;
2774 if (stash
->adjusted_section_count
!= 0)
2776 i
= stash
->adjusted_section_count
;
2777 p
= stash
->adjusted_sections
;
2778 for (; i
> 0; i
--, p
++)
2779 p
->section
->vma
= p
->adj_vma
;
2784 bfd_vma last_vma
= 0, last_dwarf
= 0;
2788 for (sect
= abfd
->sections
; sect
!= NULL
; sect
= sect
->next
)
2796 /* We need to adjust the VMAs of any .debug_info sections.
2797 Skip compressed ones, since no relocations could target
2798 them - they should not appear in object files anyway. */
2799 if (strcmp (sect
->name
, DWARF2_DEBUG_INFO
) == 0)
2801 else if (CONST_STRNEQ (sect
->name
, GNU_LINKONCE_INFO
))
2806 if (!is_debug_info
&& (sect
->flags
& SEC_LOAD
) == 0)
2809 sz
= sect
->rawsize
? sect
->rawsize
: sect
->size
;
2816 amt
= i
* sizeof (struct adjusted_section
);
2817 p
= (struct adjusted_section
*) bfd_zalloc (abfd
, amt
);
2821 stash
->adjusted_sections
= p
;
2822 stash
->adjusted_section_count
= i
;
2824 for (sect
= abfd
->sections
; sect
!= NULL
; sect
= sect
->next
)
2832 /* We need to adjust the VMAs of any .debug_info sections.
2833 Skip compressed ones, since no relocations could target
2834 them - they should not appear in object files anyway. */
2835 if (strcmp (sect
->name
, DWARF2_DEBUG_INFO
) == 0)
2837 else if (CONST_STRNEQ (sect
->name
, GNU_LINKONCE_INFO
))
2842 if (!is_debug_info
&& (sect
->flags
& SEC_LOAD
) == 0)
2845 sz
= sect
->rawsize
? sect
->rawsize
: sect
->size
;
2852 BFD_ASSERT (sect
->alignment_power
== 0);
2853 sect
->vma
= last_dwarf
;
2856 else if (last_vma
!= 0)
2858 /* Align the new address to the current section
2860 last_vma
= ((last_vma
2861 + ~((bfd_vma
) -1 << sect
->alignment_power
))
2862 & ((bfd_vma
) -1 << sect
->alignment_power
));
2863 sect
->vma
= last_vma
;
2864 last_vma
+= sect
->vma
+ sz
;
2867 last_vma
+= sect
->vma
+ sz
;
2869 p
->adj_vma
= sect
->vma
;
2878 /* Look up a funcinfo by name using the given info hash table. If found,
2879 also update the locations pointed to by filename_ptr and linenumber_ptr.
2881 This function returns TRUE if a funcinfo that matches the given symbol
2882 and address is found with any error; otherwise it returns FALSE. */
2885 info_hash_lookup_funcinfo (struct info_hash_table
*hash_table
,
2888 const char **filename_ptr
,
2889 unsigned int *linenumber_ptr
)
2891 struct funcinfo
* each_func
;
2892 struct funcinfo
* best_fit
= NULL
;
2893 struct info_list_node
*node
;
2894 struct arange
*arange
;
2895 const char *name
= bfd_asymbol_name (sym
);
2896 asection
*sec
= bfd_get_section (sym
);
2898 for (node
= lookup_info_hash_table (hash_table
, name
);
2902 each_func
= (struct funcinfo
*) node
->info
;
2903 for (arange
= &each_func
->arange
;
2905 arange
= arange
->next
)
2907 if ((!each_func
->sec
|| each_func
->sec
== sec
)
2908 && addr
>= arange
->low
2909 && addr
< arange
->high
2911 || ((arange
->high
- arange
->low
)
2912 < (best_fit
->arange
.high
- best_fit
->arange
.low
))))
2913 best_fit
= each_func
;
2919 best_fit
->sec
= sec
;
2920 *filename_ptr
= best_fit
->file
;
2921 *linenumber_ptr
= best_fit
->line
;
2928 /* Look up a varinfo by name using the given info hash table. If found,
2929 also update the locations pointed to by filename_ptr and linenumber_ptr.
2931 This function returns TRUE if a varinfo that matches the given symbol
2932 and address is found with any error; otherwise it returns FALSE. */
2935 info_hash_lookup_varinfo (struct info_hash_table
*hash_table
,
2938 const char **filename_ptr
,
2939 unsigned int *linenumber_ptr
)
2941 const char *name
= bfd_asymbol_name (sym
);
2942 asection
*sec
= bfd_get_section (sym
);
2943 struct varinfo
* each
;
2944 struct info_list_node
*node
;
2946 for (node
= lookup_info_hash_table (hash_table
, name
);
2950 each
= (struct varinfo
*) node
->info
;
2951 if (each
->addr
== addr
2952 && (!each
->sec
|| each
->sec
== sec
))
2955 *filename_ptr
= each
->file
;
2956 *linenumber_ptr
= each
->line
;
2964 /* Update the funcinfo and varinfo info hash tables if they are
2965 not up to date. Returns TRUE if there is no error; otherwise
2966 returns FALSE and disable the info hash tables. */
2969 stash_maybe_update_info_hash_tables (struct dwarf2_debug
*stash
)
2971 struct comp_unit
*each
;
2973 /* Exit if hash tables are up-to-date. */
2974 if (stash
->all_comp_units
== stash
->hash_units_head
)
2977 if (stash
->hash_units_head
)
2978 each
= stash
->hash_units_head
->prev_unit
;
2980 each
= stash
->last_comp_unit
;
2984 if (!comp_unit_hash_info (stash
, each
, stash
->funcinfo_hash_table
,
2985 stash
->varinfo_hash_table
))
2987 stash
->info_hash_status
= STASH_INFO_HASH_DISABLED
;
2990 each
= each
->prev_unit
;
2993 stash
->hash_units_head
= stash
->all_comp_units
;
2997 /* Check consistency of info hash tables. This is for debugging only. */
2999 static void ATTRIBUTE_UNUSED
3000 stash_verify_info_hash_table (struct dwarf2_debug
*stash
)
3002 struct comp_unit
*each_unit
;
3003 struct funcinfo
*each_func
;
3004 struct varinfo
*each_var
;
3005 struct info_list_node
*node
;
3008 for (each_unit
= stash
->all_comp_units
;
3010 each_unit
= each_unit
->next_unit
)
3012 for (each_func
= each_unit
->function_table
;
3014 each_func
= each_func
->prev_func
)
3016 if (!each_func
->name
)
3018 node
= lookup_info_hash_table (stash
->funcinfo_hash_table
,
3022 while (node
&& !found
)
3024 found
= node
->info
== each_func
;
3030 for (each_var
= each_unit
->variable_table
;
3032 each_var
= each_var
->prev_var
)
3034 if (!each_var
->name
|| !each_var
->file
|| each_var
->stack
)
3036 node
= lookup_info_hash_table (stash
->varinfo_hash_table
,
3040 while (node
&& !found
)
3042 found
= node
->info
== each_var
;
3050 /* Check to see if we want to enable the info hash tables, which consume
3051 quite a bit of memory. Currently we only check the number times
3052 bfd_dwarf2_find_line is called. In the future, we may also want to
3053 take the number of symbols into account. */
3056 stash_maybe_enable_info_hash_tables (bfd
*abfd
, struct dwarf2_debug
*stash
)
3058 BFD_ASSERT (stash
->info_hash_status
== STASH_INFO_HASH_OFF
);
3060 if (stash
->info_hash_count
++ < STASH_INFO_HASH_TRIGGER
)
3063 /* FIXME: Maybe we should check the reduce_memory_overheads
3064 and optimize fields in the bfd_link_info structure ? */
3066 /* Create hash tables. */
3067 stash
->funcinfo_hash_table
= create_info_hash_table (abfd
);
3068 stash
->varinfo_hash_table
= create_info_hash_table (abfd
);
3069 if (!stash
->funcinfo_hash_table
|| !stash
->varinfo_hash_table
)
3071 /* Turn off info hashes if any allocation above fails. */
3072 stash
->info_hash_status
= STASH_INFO_HASH_DISABLED
;
3075 /* We need a forced update so that the info hash tables will
3076 be created even though there is no compilation unit. That
3077 happens if STASH_INFO_HASH_TRIGGER is 0. */
3078 stash_maybe_update_info_hash_tables (stash
);
3079 stash
->info_hash_status
= STASH_INFO_HASH_ON
;
3082 /* Find the file and line associated with a symbol and address using the
3083 info hash tables of a stash. If there is a match, the function returns
3084 TRUE and update the locations pointed to by filename_ptr and linenumber_ptr;
3085 otherwise it returns FALSE. */
3088 stash_find_line_fast (struct dwarf2_debug
*stash
,
3091 const char **filename_ptr
,
3092 unsigned int *linenumber_ptr
)
3094 BFD_ASSERT (stash
->info_hash_status
== STASH_INFO_HASH_ON
);
3096 if (sym
->flags
& BSF_FUNCTION
)
3097 return info_hash_lookup_funcinfo (stash
->funcinfo_hash_table
, sym
, addr
,
3098 filename_ptr
, linenumber_ptr
);
3099 return info_hash_lookup_varinfo (stash
->varinfo_hash_table
, sym
, addr
,
3100 filename_ptr
, linenumber_ptr
);
3103 /* Find the source code location of SYMBOL. If SYMBOL is NULL
3104 then find the nearest source code location corresponding to
3105 the address SECTION + OFFSET.
3106 Returns TRUE if the line is found without error and fills in
3107 FILENAME_PTR and LINENUMBER_PTR. In the case where SYMBOL was
3108 NULL the FUNCTIONNAME_PTR is also filled in.
3109 SYMBOLS contains the symbol table for ABFD.
3110 ADDR_SIZE is the number of bytes in the initial .debug_info length
3111 field and in the abbreviation offset, or zero to indicate that the
3112 default value should be used. */
3115 find_line (bfd
*abfd
,
3120 const char **filename_ptr
,
3121 const char **functionname_ptr
,
3122 unsigned int *linenumber_ptr
,
3123 unsigned int addr_size
,
3126 /* Read each compilation unit from the section .debug_info, and check
3127 to see if it contains the address we are searching for. If yes,
3128 lookup the address, and return the line number info. If no, go
3129 on to the next compilation unit.
3131 We keep a list of all the previously read compilation units, and
3132 a pointer to the next un-read compilation unit. Check the
3133 previously read units before reading more. */
3134 struct dwarf2_debug
*stash
;
3135 /* What address are we looking for? */
3137 struct comp_unit
* each
;
3138 bfd_vma found
= FALSE
;
3139 bfd_boolean do_line
;
3141 stash
= (struct dwarf2_debug
*) *pinfo
;
3145 bfd_size_type amt
= sizeof (struct dwarf2_debug
);
3147 stash
= (struct dwarf2_debug
*) bfd_zalloc (abfd
, amt
);
3152 /* In a relocatable file, 2 functions may have the same address.
3153 We change the section vma so that they won't overlap. */
3154 if ((abfd
->flags
& (EXEC_P
| DYNAMIC
)) == 0)
3156 if (! place_sections (abfd
, stash
))
3160 do_line
= (section
== NULL
3162 && functionname_ptr
== NULL
3166 addr
= symbol
->value
;
3167 section
= bfd_get_section (symbol
);
3169 else if (section
!= NULL
3170 && functionname_ptr
!= NULL
3176 if (section
->output_section
)
3177 addr
+= section
->output_section
->vma
+ section
->output_offset
;
3179 addr
+= section
->vma
;
3180 *filename_ptr
= NULL
;
3182 *functionname_ptr
= NULL
;
3183 *linenumber_ptr
= 0;
3188 bfd_size_type total_size
;
3193 msec
= find_debug_info (abfd
, NULL
);
3196 char * debug_filename
= bfd_follow_gnu_debuglink (abfd
, DEBUGDIR
);
3198 if (debug_filename
== NULL
)
3199 /* No dwarf2 info, and no gnu_debuglink to follow.
3200 Note that at this point the stash has been allocated, but
3201 contains zeros. This lets future calls to this function
3202 fail more quickly. */
3205 if ((debug_bfd
= bfd_openr (debug_filename
, NULL
)) == NULL
3206 || ! bfd_check_format (debug_bfd
, bfd_object
)
3207 || (msec
= find_debug_info (debug_bfd
, NULL
)) == NULL
)
3210 bfd_close (debug_bfd
);
3211 /* FIXME: Should we report our failure to follow the debuglink ? */
3212 free (debug_filename
);
3219 /* There can be more than one DWARF2 info section in a BFD these
3220 days. First handle the easy case when there's only one. If
3221 there's more than one, try case two: none of the sections is
3222 compressed. In that case, read them all in and produce one
3223 large stash. We do this in two passes - in the first pass we
3224 just accumulate the section sizes, and in the second pass we
3225 read in the section's contents. (The allows us to avoid
3226 reallocing the data as we add sections to the stash.) If
3227 some or all sections are compressed, then do things the slow
3228 way, with a bunch of reallocs. */
3230 if (! find_debug_info (debug_bfd
, msec
))
3232 /* Case 1: only one info section. */
3233 total_size
= msec
->size
;
3234 if (! read_section (debug_bfd
, debug_info
, symbols
, 0,
3235 &stash
->info_ptr_memory
, &total_size
))
3240 /* Case 2: multiple sections. */
3241 for (total_size
= 0; msec
; msec
= find_debug_info (debug_bfd
, msec
))
3242 total_size
+= msec
->size
;
3244 stash
->info_ptr_memory
= (bfd_byte
*) bfd_malloc (total_size
);
3245 if (stash
->info_ptr_memory
== NULL
)
3249 for (msec
= find_debug_info (debug_bfd
, NULL
);
3251 msec
= find_debug_info (debug_bfd
, msec
))
3259 if (!(bfd_simple_get_relocated_section_contents
3260 (debug_bfd
, msec
, stash
->info_ptr_memory
+ total_size
,
3268 stash
->info_ptr
= stash
->info_ptr_memory
;
3269 stash
->info_ptr_end
= stash
->info_ptr
+ total_size
;
3270 stash
->sec
= find_debug_info (debug_bfd
, NULL
);
3271 stash
->sec_info_ptr
= stash
->info_ptr
;
3272 stash
->syms
= symbols
;
3273 stash
->bfd_ptr
= debug_bfd
;
3276 /* A null info_ptr indicates that there is no dwarf2 info
3277 (or that an error occured while setting up the stash). */
3278 if (! stash
->info_ptr
)
3281 stash
->inliner_chain
= NULL
;
3283 /* Check the previously read comp. units first. */
3286 /* The info hash tables use quite a bit of memory. We may not want to
3287 always use them. We use some heuristics to decide if and when to
3289 if (stash
->info_hash_status
== STASH_INFO_HASH_OFF
)
3290 stash_maybe_enable_info_hash_tables (abfd
, stash
);
3292 /* Keep info hash table up to date if they are available. Note that we
3293 may disable the hash tables if there is any error duing update. */
3294 if (stash
->info_hash_status
== STASH_INFO_HASH_ON
)
3295 stash_maybe_update_info_hash_tables (stash
);
3297 if (stash
->info_hash_status
== STASH_INFO_HASH_ON
)
3299 found
= stash_find_line_fast (stash
, symbol
, addr
, filename_ptr
,
3306 /* Check the previously read comp. units first. */
3307 for (each
= stash
->all_comp_units
; each
; each
= each
->next_unit
)
3308 if ((symbol
->flags
& BSF_FUNCTION
) == 0
3309 || comp_unit_contains_address (each
, addr
))
3311 found
= comp_unit_find_line (each
, symbol
, addr
, filename_ptr
,
3312 linenumber_ptr
, stash
);
3320 for (each
= stash
->all_comp_units
; each
; each
= each
->next_unit
)
3322 found
= (comp_unit_contains_address (each
, addr
)
3323 && comp_unit_find_nearest_line (each
, addr
,
3333 /* The DWARF2 spec says that the initial length field, and the
3334 offset of the abbreviation table, should both be 4-byte values.
3335 However, some compilers do things differently. */
3338 BFD_ASSERT (addr_size
== 4 || addr_size
== 8);
3340 /* Read each remaining comp. units checking each as they are read. */
3341 while (stash
->info_ptr
< stash
->info_ptr_end
)
3344 unsigned int offset_size
= addr_size
;
3345 bfd_byte
*info_ptr_unit
= stash
->info_ptr
;
3347 length
= read_4_bytes (stash
->bfd_ptr
, stash
->info_ptr
);
3348 /* A 0xffffff length is the DWARF3 way of indicating
3349 we use 64-bit offsets, instead of 32-bit offsets. */
3350 if (length
== 0xffffffff)
3353 length
= read_8_bytes (stash
->bfd_ptr
, stash
->info_ptr
+ 4);
3354 stash
->info_ptr
+= 12;
3356 /* A zero length is the IRIX way of indicating 64-bit offsets,
3357 mostly because the 64-bit length will generally fit in 32
3358 bits, and the endianness helps. */
3359 else if (length
== 0)
3362 length
= read_4_bytes (stash
->bfd_ptr
, stash
->info_ptr
+ 4);
3363 stash
->info_ptr
+= 8;
3365 /* In the absence of the hints above, we assume 32-bit DWARF2
3366 offsets even for targets with 64-bit addresses, because:
3367 a) most of the time these targets will not have generated
3368 more than 2Gb of debug info and so will not need 64-bit
3371 b) if they do use 64-bit offsets but they are not using
3372 the size hints that are tested for above then they are
3373 not conforming to the DWARF3 standard anyway. */
3374 else if (addr_size
== 8)
3377 stash
->info_ptr
+= 4;
3380 stash
->info_ptr
+= 4;
3384 each
= parse_comp_unit (stash
, length
, info_ptr_unit
,
3387 /* The dwarf information is damaged, don't trust it any
3390 stash
->info_ptr
+= length
;
3392 if (stash
->all_comp_units
)
3393 stash
->all_comp_units
->prev_unit
= each
;
3395 stash
->last_comp_unit
= each
;
3397 each
->next_unit
= stash
->all_comp_units
;
3398 stash
->all_comp_units
= each
;
3400 /* DW_AT_low_pc and DW_AT_high_pc are optional for
3401 compilation units. If we don't have them (i.e.,
3402 unit->high == 0), we need to consult the line info table
3403 to see if a compilation unit contains the given
3406 found
= (((symbol
->flags
& BSF_FUNCTION
) == 0
3407 || each
->arange
.high
== 0
3408 || comp_unit_contains_address (each
, addr
))
3409 && comp_unit_find_line (each
, symbol
, addr
,
3414 found
= ((each
->arange
.high
== 0
3415 || comp_unit_contains_address (each
, addr
))
3416 && comp_unit_find_nearest_line (each
, addr
,
3422 if ((bfd_vma
) (stash
->info_ptr
- stash
->sec_info_ptr
)
3423 == stash
->sec
->size
)
3425 stash
->sec
= find_debug_info (stash
->bfd_ptr
, stash
->sec
);
3426 stash
->sec_info_ptr
= stash
->info_ptr
;
3435 if ((abfd
->flags
& (EXEC_P
| DYNAMIC
)) == 0)
3436 unset_sections (stash
);
3441 /* The DWARF2 version of find_nearest_line.
3442 Return TRUE if the line is found without error. */
3445 _bfd_dwarf2_find_nearest_line (bfd
*abfd
,
3449 const char **filename_ptr
,
3450 const char **functionname_ptr
,
3451 unsigned int *linenumber_ptr
,
3452 unsigned int addr_size
,
3455 return find_line (abfd
, section
, offset
, NULL
, symbols
, filename_ptr
,
3456 functionname_ptr
, linenumber_ptr
, addr_size
,
3460 /* The DWARF2 version of find_line.
3461 Return TRUE if the line is found without error. */
3464 _bfd_dwarf2_find_line (bfd
*abfd
,
3467 const char **filename_ptr
,
3468 unsigned int *linenumber_ptr
,
3469 unsigned int addr_size
,
3472 return find_line (abfd
, NULL
, 0, symbol
, symbols
, filename_ptr
,
3473 NULL
, linenumber_ptr
, addr_size
,
3478 _bfd_dwarf2_find_inliner_info (bfd
*abfd ATTRIBUTE_UNUSED
,
3479 const char **filename_ptr
,
3480 const char **functionname_ptr
,
3481 unsigned int *linenumber_ptr
,
3484 struct dwarf2_debug
*stash
;
3486 stash
= (struct dwarf2_debug
*) *pinfo
;
3489 struct funcinfo
*func
= stash
->inliner_chain
;
3491 if (func
&& func
->caller_func
)
3493 *filename_ptr
= func
->caller_file
;
3494 *functionname_ptr
= func
->caller_func
->name
;
3495 *linenumber_ptr
= func
->caller_line
;
3496 stash
->inliner_chain
= func
->caller_func
;
3505 _bfd_dwarf2_cleanup_debug_info (bfd
*abfd
)
3507 struct comp_unit
*each
;
3508 struct dwarf2_debug
*stash
;
3510 if (abfd
== NULL
|| elf_tdata (abfd
) == NULL
)
3513 stash
= (struct dwarf2_debug
*) elf_tdata (abfd
)->dwarf2_find_line_info
;
3518 for (each
= stash
->all_comp_units
; each
; each
= each
->next_unit
)
3520 struct abbrev_info
**abbrevs
= each
->abbrevs
;
3521 struct funcinfo
*function_table
= each
->function_table
;
3522 struct varinfo
*variable_table
= each
->variable_table
;
3525 for (i
= 0; i
< ABBREV_HASH_SIZE
; i
++)
3527 struct abbrev_info
*abbrev
= abbrevs
[i
];
3531 free (abbrev
->attrs
);
3532 abbrev
= abbrev
->next
;
3536 if (each
->line_table
)
3538 free (each
->line_table
->dirs
);
3539 free (each
->line_table
->files
);
3542 while (function_table
)
3544 if (function_table
->file
)
3546 free (function_table
->file
);
3547 function_table
->file
= NULL
;
3550 if (function_table
->caller_file
)
3552 free (function_table
->caller_file
);
3553 function_table
->caller_file
= NULL
;
3555 function_table
= function_table
->prev_func
;
3558 while (variable_table
)
3560 if (variable_table
->file
)
3562 free (variable_table
->file
);
3563 variable_table
->file
= NULL
;
3566 variable_table
= variable_table
->prev_var
;
3570 if (stash
->dwarf_abbrev_buffer
)
3571 free (stash
->dwarf_abbrev_buffer
);
3572 if (stash
->dwarf_line_buffer
)
3573 free (stash
->dwarf_line_buffer
);
3574 if (stash
->dwarf_str_buffer
)
3575 free (stash
->dwarf_str_buffer
);
3576 if (stash
->dwarf_ranges_buffer
)
3577 free (stash
->dwarf_ranges_buffer
);
3578 if (stash
->info_ptr_memory
)
3579 free (stash
->info_ptr_memory
);