2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
3 2004 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 2 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
34 #include "libiberty.h"
37 #include "elf/dwarf2.h"
39 /* The data in the .debug_line statement prologue looks like this. */
44 unsigned short version
;
45 bfd_vma prologue_length
;
46 unsigned char minimum_instruction_length
;
47 unsigned char default_is_stmt
;
49 unsigned char line_range
;
50 unsigned char opcode_base
;
51 unsigned char *standard_opcode_lengths
;
54 /* Attributes have a name and a value. */
58 enum dwarf_attribute name
;
63 struct dwarf_block
*blk
;
70 /* Blocks are a bunch of untyped bytes. */
79 /* A list of all previously read comp_units. */
80 struct comp_unit
* all_comp_units
;
82 /* The next unread compilation unit within the .debug_info section.
83 Zero indicates that the .debug_info section has not been loaded
87 /* Pointer to the end of the .debug_info section memory buffer. */
90 /* Pointer to the section and address of the beginning of the
95 /* Pointer to the symbol table. */
98 /* Pointer to the .debug_abbrev section loaded into memory. */
99 char* dwarf_abbrev_buffer
;
101 /* Length of the loaded .debug_abbrev section. */
102 unsigned long dwarf_abbrev_size
;
104 /* Buffer for decode_line_info. */
105 char *dwarf_line_buffer
;
107 /* Length of the loaded .debug_line section. */
108 unsigned long dwarf_line_size
;
110 /* Pointer to the .debug_str section loaded into memory. */
111 char* dwarf_str_buffer
;
113 /* Length of the loaded .debug_str section. */
114 unsigned long dwarf_str_size
;
124 /* A minimal decoding of DWARF2 compilation units. We only decode
125 what's needed to get to the line number information. */
129 /* Chain the previously read compilation units. */
130 struct comp_unit
* next_unit
;
132 /* Keep the bdf convenient (for memory allocation). */
135 /* The lowest and higest addresses contained in this compilation
136 unit as specified in the compilation unit header. */
137 struct arange arange
;
139 /* The DW_AT_name attribute (for error messages). */
142 /* The abbrev hash table. */
143 struct abbrev_info
** abbrevs
;
145 /* Note that an error was found by comp_unit_find_nearest_line. */
148 /* The DW_AT_comp_dir attribute. */
151 /* TRUE if there is a line number table associated with this comp. unit. */
154 /* The offset into .debug_line of the line number table. */
155 unsigned long line_offset
;
157 /* Pointer to the first child die for the comp unit. */
158 char *first_child_die_ptr
;
160 /* The end of the comp unit. */
163 /* The decoded line number, NULL if not yet decoded. */
164 struct line_info_table
* line_table
;
166 /* A list of the functions found in this comp. unit. */
167 struct funcinfo
* function_table
;
169 /* Pointer to dwarf2_debug structure. */
170 struct dwarf2_debug
*stash
;
172 /* Address size for this unit - from unit header. */
173 unsigned char addr_size
;
175 /* Offset size for this unit - from unit header. */
176 unsigned char offset_size
;
179 /* This data structure holds the information of an abbrev. */
182 unsigned int number
; /* Number identifying abbrev. */
183 enum dwarf_tag tag
; /* DWARF tag. */
184 int has_children
; /* Boolean. */
185 unsigned int num_attrs
; /* Number of attributes. */
186 struct attr_abbrev
*attrs
; /* An array of attribute descriptions. */
187 struct abbrev_info
*next
; /* Next in chain. */
192 enum dwarf_attribute name
;
193 enum dwarf_form form
;
196 #ifndef ABBREV_HASH_SIZE
197 #define ABBREV_HASH_SIZE 121
199 #ifndef ATTR_ALLOC_CHUNK
200 #define ATTR_ALLOC_CHUNK 4
204 The following function up to the END VERBATIM mark are
205 copied directly from dwarf2read.c. */
207 /* Read dwarf information from a buffer. */
210 read_1_byte (bfd
*abfd ATTRIBUTE_UNUSED
, char *buf
)
212 return bfd_get_8 (abfd
, buf
);
216 read_1_signed_byte (bfd
*abfd ATTRIBUTE_UNUSED
, char *buf
)
218 return bfd_get_signed_8 (abfd
, buf
);
222 read_2_bytes (bfd
*abfd
, char *buf
)
224 return bfd_get_16 (abfd
, buf
);
228 read_4_bytes (bfd
*abfd
, char *buf
)
230 return bfd_get_32 (abfd
, buf
);
234 read_8_bytes (bfd
*abfd
, char *buf
)
236 return bfd_get_64 (abfd
, buf
);
240 read_n_bytes (bfd
*abfd ATTRIBUTE_UNUSED
,
242 unsigned int size ATTRIBUTE_UNUSED
)
244 /* If the size of a host char is 8 bits, we can return a pointer
245 to the buffer, otherwise we have to copy the data to a buffer
246 allocated on the temporary obstack. */
251 read_string (bfd
*abfd ATTRIBUTE_UNUSED
,
253 unsigned int *bytes_read_ptr
)
255 /* Return a pointer to the embedded string. */
262 *bytes_read_ptr
= strlen (buf
) + 1;
267 read_indirect_string (struct comp_unit
* unit
,
269 unsigned int *bytes_read_ptr
)
272 struct dwarf2_debug
*stash
= unit
->stash
;
274 if (unit
->offset_size
== 4)
275 offset
= read_4_bytes (unit
->abfd
, buf
);
277 offset
= read_8_bytes (unit
->abfd
, buf
);
278 *bytes_read_ptr
= unit
->offset_size
;
280 if (! stash
->dwarf_str_buffer
)
283 bfd
*abfd
= unit
->abfd
;
286 msec
= bfd_get_section_by_name (abfd
, ".debug_str");
289 (*_bfd_error_handler
)
290 (_("Dwarf Error: Can't find .debug_str section."));
291 bfd_set_error (bfd_error_bad_value
);
295 sz
= msec
->rawsize
? msec
->rawsize
: msec
->size
;
296 stash
->dwarf_str_size
= sz
;
297 stash
->dwarf_str_buffer
= bfd_alloc (abfd
, sz
);
298 if (! stash
->dwarf_abbrev_buffer
)
301 if (! bfd_get_section_contents (abfd
, msec
, stash
->dwarf_str_buffer
,
306 if (offset
>= stash
->dwarf_str_size
)
308 (*_bfd_error_handler
) (_("Dwarf Error: DW_FORM_strp offset (%lu) greater than or equal to .debug_str size (%lu)."),
309 (unsigned long) offset
, stash
->dwarf_str_size
);
310 bfd_set_error (bfd_error_bad_value
);
314 buf
= stash
->dwarf_str_buffer
+ offset
;
321 read_unsigned_leb128 (bfd
*abfd ATTRIBUTE_UNUSED
,
323 unsigned int *bytes_read_ptr
)
326 unsigned int num_read
;
336 byte
= bfd_get_8 (abfd
, buf
);
339 result
|= ((byte
& 0x7f) << shift
);
344 * bytes_read_ptr
= num_read
;
350 read_signed_leb128 (bfd
*abfd ATTRIBUTE_UNUSED
,
352 unsigned int * bytes_read_ptr
)
365 byte
= bfd_get_8 (abfd
, buf
);
368 result
|= ((byte
& 0x7f) << shift
);
373 if ((shift
< 32) && (byte
& 0x40))
374 result
|= -(1 << shift
);
376 * bytes_read_ptr
= num_read
;
384 read_address (struct comp_unit
*unit
, char *buf
)
386 switch (unit
->addr_size
)
389 return bfd_get_64 (unit
->abfd
, buf
);
391 return bfd_get_32 (unit
->abfd
, buf
);
393 return bfd_get_16 (unit
->abfd
, buf
);
399 /* Lookup an abbrev_info structure in the abbrev hash table. */
401 static struct abbrev_info
*
402 lookup_abbrev (unsigned int number
, struct abbrev_info
**abbrevs
)
404 unsigned int hash_number
;
405 struct abbrev_info
*abbrev
;
407 hash_number
= number
% ABBREV_HASH_SIZE
;
408 abbrev
= abbrevs
[hash_number
];
412 if (abbrev
->number
== number
)
415 abbrev
= abbrev
->next
;
421 /* In DWARF version 2, the description of the debugging information is
422 stored in a separate .debug_abbrev section. Before we read any
423 dies from a section we read in all abbreviations and install them
426 static struct abbrev_info
**
427 read_abbrevs (bfd
*abfd
, bfd_uint64_t offset
, struct dwarf2_debug
*stash
)
429 struct abbrev_info
**abbrevs
;
431 struct abbrev_info
*cur_abbrev
;
432 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
433 unsigned int abbrev_form
, hash_number
;
436 if (! stash
->dwarf_abbrev_buffer
)
440 msec
= bfd_get_section_by_name (abfd
, ".debug_abbrev");
443 (*_bfd_error_handler
) (_("Dwarf Error: Can't find .debug_abbrev section."));
444 bfd_set_error (bfd_error_bad_value
);
448 stash
->dwarf_abbrev_size
= msec
->size
;
449 stash
->dwarf_abbrev_buffer
450 = bfd_simple_get_relocated_section_contents (abfd
, msec
, NULL
,
452 if (! stash
->dwarf_abbrev_buffer
)
456 if (offset
>= stash
->dwarf_abbrev_size
)
458 (*_bfd_error_handler
) (_("Dwarf Error: Abbrev offset (%lu) greater than or equal to .debug_abbrev size (%lu)."),
459 (unsigned long) offset
, stash
->dwarf_abbrev_size
);
460 bfd_set_error (bfd_error_bad_value
);
464 amt
= sizeof (struct abbrev_info
*) * ABBREV_HASH_SIZE
;
465 abbrevs
= bfd_zalloc (abfd
, amt
);
467 abbrev_ptr
= stash
->dwarf_abbrev_buffer
+ offset
;
468 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
469 abbrev_ptr
+= bytes_read
;
471 /* Loop until we reach an abbrev number of 0. */
472 while (abbrev_number
)
474 amt
= sizeof (struct abbrev_info
);
475 cur_abbrev
= bfd_zalloc (abfd
, amt
);
477 /* Read in abbrev header. */
478 cur_abbrev
->number
= abbrev_number
;
479 cur_abbrev
->tag
= (enum dwarf_tag
)
480 read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
481 abbrev_ptr
+= bytes_read
;
482 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
485 /* Now read in declarations. */
486 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
487 abbrev_ptr
+= bytes_read
;
488 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
489 abbrev_ptr
+= bytes_read
;
493 if ((cur_abbrev
->num_attrs
% ATTR_ALLOC_CHUNK
) == 0)
495 amt
= cur_abbrev
->num_attrs
+ ATTR_ALLOC_CHUNK
;
496 amt
*= sizeof (struct attr_abbrev
);
497 cur_abbrev
->attrs
= bfd_realloc (cur_abbrev
->attrs
, amt
);
498 if (! cur_abbrev
->attrs
)
502 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
].name
503 = (enum dwarf_attribute
) abbrev_name
;
504 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
++].form
505 = (enum dwarf_form
) abbrev_form
;
506 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
507 abbrev_ptr
+= bytes_read
;
508 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
509 abbrev_ptr
+= bytes_read
;
512 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
513 cur_abbrev
->next
= abbrevs
[hash_number
];
514 abbrevs
[hash_number
] = cur_abbrev
;
516 /* Get next abbreviation.
517 Under Irix6 the abbreviations for a compilation unit are not
518 always properly terminated with an abbrev number of 0.
519 Exit loop if we encounter an abbreviation which we have
520 already read (which means we are about to read the abbreviations
521 for the next compile unit) or if the end of the abbreviation
523 if ((unsigned int) (abbrev_ptr
- stash
->dwarf_abbrev_buffer
)
524 >= stash
->dwarf_abbrev_size
)
526 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
527 abbrev_ptr
+= bytes_read
;
528 if (lookup_abbrev (abbrev_number
,abbrevs
) != NULL
)
535 /* Read an attribute value described by an attribute form. */
538 read_attribute_value (struct attribute
*attr
,
540 struct comp_unit
*unit
,
543 bfd
*abfd
= unit
->abfd
;
544 unsigned int bytes_read
;
545 struct dwarf_block
*blk
;
548 attr
->form
= (enum dwarf_form
) form
;
553 /* FIXME: DWARF3 draft says DW_FORM_ref_addr is offset_size. */
554 case DW_FORM_ref_addr
:
555 attr
->u
.val
= read_address (unit
, info_ptr
);
556 info_ptr
+= unit
->addr_size
;
559 amt
= sizeof (struct dwarf_block
);
560 blk
= bfd_alloc (abfd
, amt
);
561 blk
->size
= read_2_bytes (abfd
, info_ptr
);
563 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
564 info_ptr
+= blk
->size
;
568 amt
= sizeof (struct dwarf_block
);
569 blk
= bfd_alloc (abfd
, amt
);
570 blk
->size
= read_4_bytes (abfd
, info_ptr
);
572 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
573 info_ptr
+= blk
->size
;
577 attr
->u
.val
= read_2_bytes (abfd
, info_ptr
);
581 attr
->u
.val
= read_4_bytes (abfd
, info_ptr
);
585 attr
->u
.val
= read_8_bytes (abfd
, info_ptr
);
589 attr
->u
.str
= read_string (abfd
, info_ptr
, &bytes_read
);
590 info_ptr
+= bytes_read
;
593 attr
->u
.str
= read_indirect_string (unit
, info_ptr
, &bytes_read
);
594 info_ptr
+= bytes_read
;
597 amt
= sizeof (struct dwarf_block
);
598 blk
= bfd_alloc (abfd
, amt
);
599 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
600 info_ptr
+= bytes_read
;
601 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
602 info_ptr
+= blk
->size
;
606 amt
= sizeof (struct dwarf_block
);
607 blk
= bfd_alloc (abfd
, amt
);
608 blk
->size
= read_1_byte (abfd
, info_ptr
);
610 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
611 info_ptr
+= blk
->size
;
615 attr
->u
.val
= read_1_byte (abfd
, info_ptr
);
619 attr
->u
.val
= read_1_byte (abfd
, info_ptr
);
623 attr
->u
.sval
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
624 info_ptr
+= bytes_read
;
627 attr
->u
.val
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
628 info_ptr
+= bytes_read
;
631 attr
->u
.val
= read_1_byte (abfd
, info_ptr
);
635 attr
->u
.val
= read_2_bytes (abfd
, info_ptr
);
639 attr
->u
.val
= read_4_bytes (abfd
, info_ptr
);
643 attr
->u
.val
= read_8_bytes (abfd
, info_ptr
);
646 case DW_FORM_ref_udata
:
647 attr
->u
.val
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
648 info_ptr
+= bytes_read
;
650 case DW_FORM_indirect
:
651 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
652 info_ptr
+= bytes_read
;
653 info_ptr
= read_attribute_value (attr
, form
, unit
, info_ptr
);
656 (*_bfd_error_handler
) (_("Dwarf Error: Invalid or unhandled FORM value: %u."),
658 bfd_set_error (bfd_error_bad_value
);
663 /* Read an attribute described by an abbreviated attribute. */
666 read_attribute (struct attribute
*attr
,
667 struct attr_abbrev
*abbrev
,
668 struct comp_unit
*unit
,
671 attr
->name
= abbrev
->name
;
672 info_ptr
= read_attribute_value (attr
, abbrev
->form
, unit
, info_ptr
);
676 /* Source line information table routines. */
678 #define FILE_ALLOC_CHUNK 5
679 #define DIR_ALLOC_CHUNK 5
683 struct line_info
* prev_line
;
688 int end_sequence
; /* End of (sequential) code sequence. */
699 struct line_info_table
702 unsigned int num_files
;
703 unsigned int num_dirs
;
706 struct fileinfo
* files
;
707 struct line_info
* last_line
; /* largest VMA */
708 struct line_info
* lcl_head
; /* local head; used in 'add_line_info' */
713 struct funcinfo
*prev_func
;
719 /* Adds a new entry to the line_info list in the line_info_table, ensuring
720 that the list is sorted. Note that the line_info list is sorted from
721 highest to lowest VMA (with possible duplicates); that is,
722 line_info->prev_line always accesses an equal or smaller VMA. */
725 add_line_info (struct line_info_table
*table
,
732 bfd_size_type amt
= sizeof (struct line_info
);
733 struct line_info
* info
= bfd_alloc (table
->abfd
, amt
);
735 /* Find the correct location for 'info'. Normally we will receive
736 new line_info data 1) in order and 2) with increasing VMAs.
737 However some compilers break the rules (cf. decode_line_info) and
738 so we include some heuristics for quickly finding the correct
739 location for 'info'. In particular, these heuristics optimize for
740 the common case in which the VMA sequence that we receive is a
741 list of locally sorted VMAs such as
742 p...z a...j (where a < j < p < z)
744 Note: table->lcl_head is used to head an *actual* or *possible*
745 sequence within the list (such as a...j) that is not directly
746 headed by table->last_line
748 Note: we may receive duplicate entries from 'decode_line_info'. */
751 if (!table
->last_line
752 || address
>= table
->last_line
->address
)
754 /* Normal case: add 'info' to the beginning of the list */
755 info
->prev_line
= table
->last_line
;
756 table
->last_line
= info
;
758 /* lcl_head: initialize to head a *possible* sequence at the end. */
759 if (!table
->lcl_head
)
760 table
->lcl_head
= info
;
763 else if (!table
->lcl_head
->prev_line
764 && table
->lcl_head
->address
> address
)
766 /* Abnormal but easy: lcl_head is 1) at the *end* of the line
767 list and 2) the head of 'info'. */
768 info
->prev_line
= NULL
;
769 table
->lcl_head
->prev_line
= info
;
772 else if (table
->lcl_head
->prev_line
773 && table
->lcl_head
->address
> address
774 && address
>= table
->lcl_head
->prev_line
->address
)
776 /* Abnormal but easy: lcl_head is 1) in the *middle* of the line
777 list and 2) the head of 'info'. */
778 info
->prev_line
= table
->lcl_head
->prev_line
;
779 table
->lcl_head
->prev_line
= info
;
784 /* Abnormal and hard: Neither 'last_line' nor 'lcl_head' are valid
785 heads for 'info'. Reset 'lcl_head' and repeat. */
786 struct line_info
* li2
= table
->last_line
; /* always non-NULL */
787 struct line_info
* li1
= li2
->prev_line
;
791 if (li2
->address
> address
&& address
>= li1
->address
)
794 li2
= li1
; /* always non-NULL */
795 li1
= li1
->prev_line
;
797 table
->lcl_head
= li2
;
800 /* Set member data of 'info'. */
801 info
->address
= address
;
803 info
->column
= column
;
804 info
->end_sequence
= end_sequence
;
806 if (filename
&& filename
[0])
808 info
->filename
= bfd_alloc (table
->abfd
, strlen (filename
) + 1);
810 strcpy (info
->filename
, filename
);
813 info
->filename
= NULL
;
816 /* Extract a fully qualified filename from a line info table.
817 The returned string has been malloc'ed and it is the caller's
818 responsibility to free it. */
821 concat_filename (struct line_info_table
*table
, unsigned int file
)
825 if (file
- 1 >= table
->num_files
)
827 (*_bfd_error_handler
)
828 (_("Dwarf Error: mangled line number section (bad file number)."));
829 return strdup ("<unknown>");
832 filename
= table
->files
[file
- 1].name
;
834 if (! IS_ABSOLUTE_PATH (filename
))
836 char* dirname
= (table
->files
[file
- 1].dir
837 ? table
->dirs
[table
->files
[file
- 1].dir
- 1]
840 /* Not all tools set DW_AT_comp_dir, so dirname may be unknown.
841 The best we can do is return the filename part. */
844 unsigned int len
= strlen (dirname
) + strlen (filename
) + 2;
847 name
= bfd_malloc (len
);
849 sprintf (name
, "%s/%s", dirname
, filename
);
854 return strdup (filename
);
858 arange_add (struct comp_unit
*unit
, bfd_vma low_pc
, bfd_vma high_pc
)
860 struct arange
*arange
;
862 /* First see if we can cheaply extend an existing range. */
863 arange
= &unit
->arange
;
867 if (low_pc
== arange
->high
)
869 arange
->high
= high_pc
;
872 if (high_pc
== arange
->low
)
874 arange
->low
= low_pc
;
877 arange
= arange
->next
;
881 if (unit
->arange
.high
== 0)
883 /* This is the first address range: store it in unit->arange. */
884 unit
->arange
.next
= 0;
885 unit
->arange
.low
= low_pc
;
886 unit
->arange
.high
= high_pc
;
890 /* Need to allocate a new arange and insert it into the arange list. */
891 arange
= bfd_zalloc (unit
->abfd
, sizeof (*arange
));
892 arange
->low
= low_pc
;
893 arange
->high
= high_pc
;
895 arange
->next
= unit
->arange
.next
;
896 unit
->arange
.next
= arange
;
899 /* Decode the line number information for UNIT. */
901 static struct line_info_table
*
902 decode_line_info (struct comp_unit
*unit
, struct dwarf2_debug
*stash
)
904 bfd
*abfd
= unit
->abfd
;
905 struct line_info_table
* table
;
909 unsigned int i
, bytes_read
, offset_size
;
910 char *cur_file
, *cur_dir
;
911 unsigned char op_code
, extended_op
, adj_opcode
;
914 if (! stash
->dwarf_line_buffer
)
918 msec
= bfd_get_section_by_name (abfd
, ".debug_line");
921 (*_bfd_error_handler
) (_("Dwarf Error: Can't find .debug_line section."));
922 bfd_set_error (bfd_error_bad_value
);
926 stash
->dwarf_line_size
= msec
->size
;
927 stash
->dwarf_line_buffer
928 = bfd_simple_get_relocated_section_contents (abfd
, msec
, NULL
,
930 if (! stash
->dwarf_line_buffer
)
934 /* It is possible to get a bad value for the line_offset. Validate
935 it here so that we won't get a segfault below. */
936 if (unit
->line_offset
>= stash
->dwarf_line_size
)
938 (*_bfd_error_handler
) (_("Dwarf Error: Line offset (%lu) greater than or equal to .debug_line size (%lu)."),
939 unit
->line_offset
, stash
->dwarf_line_size
);
940 bfd_set_error (bfd_error_bad_value
);
944 amt
= sizeof (struct line_info_table
);
945 table
= bfd_alloc (abfd
, amt
);
947 table
->comp_dir
= unit
->comp_dir
;
949 table
->num_files
= 0;
956 table
->last_line
= NULL
;
957 table
->lcl_head
= NULL
;
959 line_ptr
= stash
->dwarf_line_buffer
+ unit
->line_offset
;
961 /* Read in the prologue. */
962 lh
.total_length
= read_4_bytes (abfd
, line_ptr
);
965 if (lh
.total_length
== 0xffffffff)
967 lh
.total_length
= read_8_bytes (abfd
, line_ptr
);
971 else if (lh
.total_length
== 0 && unit
->addr_size
== 8)
973 /* Handle (non-standard) 64-bit DWARF2 formats. */
974 lh
.total_length
= read_4_bytes (abfd
, line_ptr
);
978 line_end
= line_ptr
+ lh
.total_length
;
979 lh
.version
= read_2_bytes (abfd
, line_ptr
);
981 if (offset_size
== 4)
982 lh
.prologue_length
= read_4_bytes (abfd
, line_ptr
);
984 lh
.prologue_length
= read_8_bytes (abfd
, line_ptr
);
985 line_ptr
+= offset_size
;
986 lh
.minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
988 lh
.default_is_stmt
= read_1_byte (abfd
, line_ptr
);
990 lh
.line_base
= read_1_signed_byte (abfd
, line_ptr
);
992 lh
.line_range
= read_1_byte (abfd
, line_ptr
);
994 lh
.opcode_base
= read_1_byte (abfd
, line_ptr
);
996 amt
= lh
.opcode_base
* sizeof (unsigned char);
997 lh
.standard_opcode_lengths
= bfd_alloc (abfd
, amt
);
999 lh
.standard_opcode_lengths
[0] = 1;
1001 for (i
= 1; i
< lh
.opcode_base
; ++i
)
1003 lh
.standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
1007 /* Read directory table. */
1008 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
1010 line_ptr
+= bytes_read
;
1012 if ((table
->num_dirs
% DIR_ALLOC_CHUNK
) == 0)
1014 amt
= table
->num_dirs
+ DIR_ALLOC_CHUNK
;
1015 amt
*= sizeof (char *);
1016 table
->dirs
= bfd_realloc (table
->dirs
, amt
);
1021 table
->dirs
[table
->num_dirs
++] = cur_dir
;
1024 line_ptr
+= bytes_read
;
1026 /* Read file name table. */
1027 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
1029 line_ptr
+= bytes_read
;
1031 if ((table
->num_files
% FILE_ALLOC_CHUNK
) == 0)
1033 amt
= table
->num_files
+ FILE_ALLOC_CHUNK
;
1034 amt
*= sizeof (struct fileinfo
);
1035 table
->files
= bfd_realloc (table
->files
, amt
);
1040 table
->files
[table
->num_files
].name
= cur_file
;
1041 table
->files
[table
->num_files
].dir
=
1042 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
1043 line_ptr
+= bytes_read
;
1044 table
->files
[table
->num_files
].time
=
1045 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
1046 line_ptr
+= bytes_read
;
1047 table
->files
[table
->num_files
].size
=
1048 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
1049 line_ptr
+= bytes_read
;
1053 line_ptr
+= bytes_read
;
1055 /* Read the statement sequences until there's nothing left. */
1056 while (line_ptr
< line_end
)
1058 /* State machine registers. */
1059 bfd_vma address
= 0;
1060 char * filename
= table
->num_files
? concat_filename (table
, 1) : NULL
;
1061 unsigned int line
= 1;
1062 unsigned int column
= 0;
1063 int is_stmt
= lh
.default_is_stmt
;
1064 int basic_block
= 0;
1065 int end_sequence
= 0;
1066 /* eraxxon@alumni.rice.edu: Against the DWARF2 specs, some
1067 compilers generate address sequences that are wildly out of
1068 order using DW_LNE_set_address (e.g. Intel C++ 6.0 compiler
1069 for ia64-Linux). Thus, to determine the low and high
1070 address, we must compare on every DW_LNS_copy, etc. */
1072 bfd_vma high_pc
= 0;
1074 /* Decode the table. */
1075 while (! end_sequence
)
1077 op_code
= read_1_byte (abfd
, line_ptr
);
1080 if (op_code
>= lh
.opcode_base
)
1082 /* Special operand. */
1083 adj_opcode
= op_code
- lh
.opcode_base
;
1084 address
+= (adj_opcode
/ lh
.line_range
)
1085 * lh
.minimum_instruction_length
;
1086 line
+= lh
.line_base
+ (adj_opcode
% lh
.line_range
);
1087 /* Append row to matrix using current values. */
1088 add_line_info (table
, address
, filename
, line
, column
, 0);
1090 if (low_pc
== 0 || address
< low_pc
)
1092 if (address
> high_pc
)
1095 else switch (op_code
)
1097 case DW_LNS_extended_op
:
1098 /* Ignore length. */
1100 extended_op
= read_1_byte (abfd
, line_ptr
);
1103 switch (extended_op
)
1105 case DW_LNE_end_sequence
:
1107 add_line_info (table
, address
, filename
, line
, column
,
1109 if (low_pc
== 0 || address
< low_pc
)
1111 if (address
> high_pc
)
1113 arange_add (unit
, low_pc
, high_pc
);
1115 case DW_LNE_set_address
:
1116 address
= read_address (unit
, line_ptr
);
1117 line_ptr
+= unit
->addr_size
;
1119 case DW_LNE_define_file
:
1120 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
1121 line_ptr
+= bytes_read
;
1122 if ((table
->num_files
% FILE_ALLOC_CHUNK
) == 0)
1124 amt
= table
->num_files
+ FILE_ALLOC_CHUNK
;
1125 amt
*= sizeof (struct fileinfo
);
1126 table
->files
= bfd_realloc (table
->files
, amt
);
1130 table
->files
[table
->num_files
].name
= cur_file
;
1131 table
->files
[table
->num_files
].dir
=
1132 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
1133 line_ptr
+= bytes_read
;
1134 table
->files
[table
->num_files
].time
=
1135 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
1136 line_ptr
+= bytes_read
;
1137 table
->files
[table
->num_files
].size
=
1138 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
1139 line_ptr
+= bytes_read
;
1143 (*_bfd_error_handler
) (_("Dwarf Error: mangled line number section."));
1144 bfd_set_error (bfd_error_bad_value
);
1149 add_line_info (table
, address
, filename
, line
, column
, 0);
1151 if (low_pc
== 0 || address
< low_pc
)
1153 if (address
> high_pc
)
1156 case DW_LNS_advance_pc
:
1157 address
+= lh
.minimum_instruction_length
1158 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
1159 line_ptr
+= bytes_read
;
1161 case DW_LNS_advance_line
:
1162 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
1163 line_ptr
+= bytes_read
;
1165 case DW_LNS_set_file
:
1169 /* The file and directory tables are 0
1170 based, the references are 1 based. */
1171 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
1172 line_ptr
+= bytes_read
;
1175 filename
= concat_filename (table
, file
);
1178 case DW_LNS_set_column
:
1179 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
1180 line_ptr
+= bytes_read
;
1182 case DW_LNS_negate_stmt
:
1183 is_stmt
= (!is_stmt
);
1185 case DW_LNS_set_basic_block
:
1188 case DW_LNS_const_add_pc
:
1189 address
+= lh
.minimum_instruction_length
1190 * ((255 - lh
.opcode_base
) / lh
.line_range
);
1192 case DW_LNS_fixed_advance_pc
:
1193 address
+= read_2_bytes (abfd
, line_ptr
);
1200 /* Unknown standard opcode, ignore it. */
1201 for (i
= 0; i
< lh
.standard_opcode_lengths
[op_code
]; i
++)
1203 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
1204 line_ptr
+= bytes_read
;
1217 /* If ADDR is within TABLE set the output parameters and return TRUE,
1218 otherwise return FALSE. The output parameters, FILENAME_PTR and
1219 LINENUMBER_PTR, are pointers to the objects to be filled in. */
1222 lookup_address_in_line_info_table (struct line_info_table
*table
,
1224 struct funcinfo
*function
,
1225 const char **filename_ptr
,
1226 unsigned int *linenumber_ptr
)
1228 /* Note: table->last_line should be a descendingly sorted list. */
1229 struct line_info
* next_line
= table
->last_line
;
1230 struct line_info
* each_line
= NULL
;
1231 *filename_ptr
= NULL
;
1236 each_line
= next_line
->prev_line
;
1238 /* Check for large addresses */
1239 if (addr
> next_line
->address
)
1240 each_line
= NULL
; /* ensure we skip over the normal case */
1242 /* Normal case: search the list; save */
1243 while (each_line
&& next_line
)
1245 /* If we have an address match, save this info. This allows us
1246 to return as good as results as possible for strange debugging
1248 bfd_boolean addr_match
= FALSE
;
1249 if (each_line
->address
<= addr
&& addr
<= next_line
->address
)
1253 /* If this line appears to span functions, and addr is in the
1254 later function, return the first line of that function instead
1255 of the last line of the earlier one. This check is for GCC
1256 2.95, which emits the first line number for a function late. */
1257 if (function
!= NULL
1258 && each_line
->address
< function
->low
1259 && next_line
->address
> function
->low
)
1261 *filename_ptr
= next_line
->filename
;
1262 *linenumber_ptr
= next_line
->line
;
1266 *filename_ptr
= each_line
->filename
;
1267 *linenumber_ptr
= each_line
->line
;
1271 if (addr_match
&& !each_line
->end_sequence
)
1272 return TRUE
; /* we have definitely found what we want */
1274 next_line
= each_line
;
1275 each_line
= each_line
->prev_line
;
1278 /* At this point each_line is NULL but next_line is not. If we found
1279 a candidate end-of-sequence point in the loop above, we can return
1280 that (compatibility with a bug in the Intel compiler); otherwise,
1281 assuming that we found the containing function for this address in
1282 this compilation unit, return the first line we have a number for
1283 (compatibility with GCC 2.95). */
1284 if (*filename_ptr
== NULL
&& function
!= NULL
)
1286 *filename_ptr
= next_line
->filename
;
1287 *linenumber_ptr
= next_line
->line
;
1294 /* Function table functions. */
1296 /* If ADDR is within TABLE, set FUNCTIONNAME_PTR, and return TRUE. */
1299 lookup_address_in_function_table (struct funcinfo
*table
,
1301 struct funcinfo
**function_ptr
,
1302 const char **functionname_ptr
)
1304 struct funcinfo
* each_func
;
1306 for (each_func
= table
;
1308 each_func
= each_func
->prev_func
)
1310 if (addr
>= each_func
->low
&& addr
< each_func
->high
)
1312 *functionname_ptr
= each_func
->name
;
1313 *function_ptr
= each_func
;
1321 /* DWARF2 Compilation unit functions. */
1323 /* Scan over each die in a comp. unit looking for functions to add
1324 to the function table. */
1327 scan_unit_for_functions (struct comp_unit
*unit
)
1329 bfd
*abfd
= unit
->abfd
;
1330 char *info_ptr
= unit
->first_child_die_ptr
;
1331 int nesting_level
= 1;
1333 while (nesting_level
)
1335 unsigned int abbrev_number
, bytes_read
, i
;
1336 struct abbrev_info
*abbrev
;
1337 struct attribute attr
;
1338 struct funcinfo
*func
;
1341 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
1342 info_ptr
+= bytes_read
;
1344 if (! abbrev_number
)
1350 abbrev
= lookup_abbrev (abbrev_number
,unit
->abbrevs
);
1353 (*_bfd_error_handler
) (_("Dwarf Error: Could not find abbrev number %u."),
1355 bfd_set_error (bfd_error_bad_value
);
1359 if (abbrev
->tag
== DW_TAG_subprogram
)
1361 bfd_size_type amt
= sizeof (struct funcinfo
);
1362 func
= bfd_zalloc (abfd
, amt
);
1363 func
->prev_func
= unit
->function_table
;
1364 unit
->function_table
= func
;
1369 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
1371 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], unit
, info_ptr
);
1381 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
1382 if (func
->name
== NULL
)
1383 func
->name
= attr
.u
.str
;
1386 case DW_AT_MIPS_linkage_name
:
1387 func
->name
= attr
.u
.str
;
1391 func
->low
= attr
.u
.val
;
1395 func
->high
= attr
.u
.val
;
1416 if (abbrev
->has_children
)
1423 /* Parse a DWARF2 compilation unit starting at INFO_PTR. This
1424 includes the compilation unit header that proceeds the DIE's, but
1425 does not include the length field that precedes each compilation
1426 unit header. END_PTR points one past the end of this comp unit.
1427 OFFSET_SIZE is the size of DWARF2 offsets (either 4 or 8 bytes).
1429 This routine does not read the whole compilation unit; only enough
1430 to get to the line number information for the compilation unit. */
1432 static struct comp_unit
*
1433 parse_comp_unit (bfd
*abfd
,
1434 struct dwarf2_debug
*stash
,
1435 bfd_vma unit_length
,
1436 unsigned int offset_size
)
1438 struct comp_unit
* unit
;
1439 unsigned int version
;
1440 bfd_uint64_t abbrev_offset
= 0;
1441 unsigned int addr_size
;
1442 struct abbrev_info
** abbrevs
;
1443 unsigned int abbrev_number
, bytes_read
, i
;
1444 struct abbrev_info
*abbrev
;
1445 struct attribute attr
;
1446 char *info_ptr
= stash
->info_ptr
;
1447 char *end_ptr
= info_ptr
+ unit_length
;
1450 version
= read_2_bytes (abfd
, info_ptr
);
1452 BFD_ASSERT (offset_size
== 4 || offset_size
== 8);
1453 if (offset_size
== 4)
1454 abbrev_offset
= read_4_bytes (abfd
, info_ptr
);
1456 abbrev_offset
= read_8_bytes (abfd
, info_ptr
);
1457 info_ptr
+= offset_size
;
1458 addr_size
= read_1_byte (abfd
, info_ptr
);
1463 (*_bfd_error_handler
) (_("Dwarf Error: found dwarf version '%u', this reader only handles version 2 information."), version
);
1464 bfd_set_error (bfd_error_bad_value
);
1468 if (addr_size
> sizeof (bfd_vma
))
1470 (*_bfd_error_handler
) (_("Dwarf Error: found address size '%u', this reader can not handle sizes greater than '%u'."),
1472 (unsigned int) sizeof (bfd_vma
));
1473 bfd_set_error (bfd_error_bad_value
);
1477 if (addr_size
!= 2 && addr_size
!= 4 && addr_size
!= 8)
1479 (*_bfd_error_handler
) ("Dwarf Error: found address size '%u', this reader can only handle address sizes '2', '4' and '8'.", addr_size
);
1480 bfd_set_error (bfd_error_bad_value
);
1484 /* Read the abbrevs for this compilation unit into a table. */
1485 abbrevs
= read_abbrevs (abfd
, abbrev_offset
, stash
);
1489 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
1490 info_ptr
+= bytes_read
;
1491 if (! abbrev_number
)
1493 (*_bfd_error_handler
) (_("Dwarf Error: Bad abbrev number: %u."),
1495 bfd_set_error (bfd_error_bad_value
);
1499 abbrev
= lookup_abbrev (abbrev_number
, abbrevs
);
1502 (*_bfd_error_handler
) (_("Dwarf Error: Could not find abbrev number %u."),
1504 bfd_set_error (bfd_error_bad_value
);
1508 amt
= sizeof (struct comp_unit
);
1509 unit
= bfd_zalloc (abfd
, amt
);
1511 unit
->addr_size
= addr_size
;
1512 unit
->offset_size
= offset_size
;
1513 unit
->abbrevs
= abbrevs
;
1514 unit
->end_ptr
= end_ptr
;
1515 unit
->stash
= stash
;
1517 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
1519 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], unit
, info_ptr
);
1521 /* Store the data if it is of an attribute we want to keep in a
1522 partial symbol table. */
1525 case DW_AT_stmt_list
:
1527 unit
->line_offset
= attr
.u
.val
;
1531 unit
->name
= attr
.u
.str
;
1535 unit
->arange
.low
= attr
.u
.val
;
1539 unit
->arange
.high
= attr
.u
.val
;
1542 case DW_AT_comp_dir
:
1544 char* comp_dir
= attr
.u
.str
;
1547 /* Irix 6.2 native cc prepends <machine>.: to the compilation
1548 directory, get rid of it. */
1549 char *cp
= strchr (comp_dir
, ':');
1551 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
1554 unit
->comp_dir
= comp_dir
;
1563 unit
->first_child_die_ptr
= info_ptr
;
1567 /* Return TRUE if UNIT contains the address given by ADDR. */
1570 comp_unit_contains_address (struct comp_unit
*unit
, bfd_vma addr
)
1572 struct arange
*arange
;
1577 arange
= &unit
->arange
;
1580 if (addr
>= arange
->low
&& addr
< arange
->high
)
1582 arange
= arange
->next
;
1589 /* If UNIT contains ADDR, set the output parameters to the values for
1590 the line containing ADDR. The output parameters, FILENAME_PTR,
1591 FUNCTIONNAME_PTR, and LINENUMBER_PTR, are pointers to the objects
1594 Return TRUE if UNIT contains ADDR, and no errors were encountered;
1598 comp_unit_find_nearest_line (struct comp_unit
*unit
,
1600 const char **filename_ptr
,
1601 const char **functionname_ptr
,
1602 unsigned int *linenumber_ptr
,
1603 struct dwarf2_debug
*stash
)
1607 struct funcinfo
*function
;
1612 if (! unit
->line_table
)
1614 if (! unit
->stmtlist
)
1620 unit
->line_table
= decode_line_info (unit
, stash
);
1622 if (! unit
->line_table
)
1628 if (unit
->first_child_die_ptr
< unit
->end_ptr
1629 && ! scan_unit_for_functions (unit
))
1637 func_p
= lookup_address_in_function_table (unit
->function_table
, addr
,
1638 &function
, functionname_ptr
);
1639 line_p
= lookup_address_in_line_info_table (unit
->line_table
, addr
,
1640 function
, filename_ptr
,
1642 return line_p
|| func_p
;
1645 /* Locate a section in a BFD containing debugging info. The search starts
1646 from the section after AFTER_SEC, or from the first section in the BFD if
1647 AFTER_SEC is NULL. The search works by examining the names of the
1648 sections. There are two permissiable names. The first is .debug_info.
1649 This is the standard DWARF2 name. The second is a prefix .gnu.linkonce.wi.
1650 This is a variation on the .debug_info section which has a checksum
1651 describing the contents appended onto the name. This allows the linker to
1652 identify and discard duplicate debugging sections for different
1653 compilation units. */
1654 #define DWARF2_DEBUG_INFO ".debug_info"
1655 #define GNU_LINKONCE_INFO ".gnu.linkonce.wi."
1658 find_debug_info (bfd
*abfd
, asection
*after_sec
)
1663 msec
= after_sec
->next
;
1665 msec
= abfd
->sections
;
1669 if (strcmp (msec
->name
, DWARF2_DEBUG_INFO
) == 0)
1672 if (strncmp (msec
->name
, GNU_LINKONCE_INFO
, strlen (GNU_LINKONCE_INFO
)) == 0)
1681 /* The DWARF2 version of find_nearest_line. Return TRUE if the line
1682 is found without error. ADDR_SIZE is the number of bytes in the
1683 initial .debug_info length field and in the abbreviation offset.
1684 You may use zero to indicate that the default value should be
1688 _bfd_dwarf2_find_nearest_line (bfd
*abfd
,
1692 const char **filename_ptr
,
1693 const char **functionname_ptr
,
1694 unsigned int *linenumber_ptr
,
1695 unsigned int addr_size
,
1698 /* Read each compilation unit from the section .debug_info, and check
1699 to see if it contains the address we are searching for. If yes,
1700 lookup the address, and return the line number info. If no, go
1701 on to the next compilation unit.
1703 We keep a list of all the previously read compilation units, and
1704 a pointer to the next un-read compilation unit. Check the
1705 previously read units before reading more. */
1706 struct dwarf2_debug
*stash
= *pinfo
;
1708 /* What address are we looking for? */
1709 bfd_vma addr
= offset
+ section
->vma
;
1711 struct comp_unit
* each
;
1713 *filename_ptr
= NULL
;
1714 *functionname_ptr
= NULL
;
1715 *linenumber_ptr
= 0;
1717 /* The DWARF2 spec says that the initial length field, and the
1718 offset of the abbreviation table, should both be 4-byte values.
1719 However, some compilers do things differently. */
1722 BFD_ASSERT (addr_size
== 4 || addr_size
== 8);
1726 bfd_size_type total_size
;
1728 bfd_size_type amt
= sizeof (struct dwarf2_debug
);
1730 stash
= bfd_zalloc (abfd
, amt
);
1736 msec
= find_debug_info (abfd
, NULL
);
1738 /* No dwarf2 info. Note that at this point the stash
1739 has been allocated, but contains zeros, this lets
1740 future calls to this function fail quicker. */
1743 /* There can be more than one DWARF2 info section in a BFD these days.
1744 Read them all in and produce one large stash. We do this in two
1745 passes - in the first pass we just accumulate the section sizes.
1746 In the second pass we read in the section's contents. The allows
1747 us to avoid reallocing the data as we add sections to the stash. */
1748 for (total_size
= 0; msec
; msec
= find_debug_info (abfd
, msec
))
1749 total_size
+= msec
->size
;
1751 stash
->info_ptr
= bfd_alloc (abfd
, total_size
);
1752 if (stash
->info_ptr
== NULL
)
1755 stash
->info_ptr_end
= stash
->info_ptr
;
1757 for (msec
= find_debug_info (abfd
, NULL
);
1759 msec
= find_debug_info (abfd
, msec
))
1762 bfd_size_type start
;
1768 start
= stash
->info_ptr_end
- stash
->info_ptr
;
1770 if ((bfd_simple_get_relocated_section_contents
1771 (abfd
, msec
, stash
->info_ptr
+ start
, symbols
)) == NULL
)
1774 stash
->info_ptr_end
= stash
->info_ptr
+ start
+ size
;
1777 BFD_ASSERT (stash
->info_ptr_end
== stash
->info_ptr
+ total_size
);
1779 stash
->sec
= find_debug_info (abfd
, NULL
);
1780 stash
->sec_info_ptr
= stash
->info_ptr
;
1781 stash
->syms
= symbols
;
1784 /* A null info_ptr indicates that there is no dwarf2 info
1785 (or that an error occured while setting up the stash). */
1786 if (! stash
->info_ptr
)
1789 /* Check the previously read comp. units first. */
1790 for (each
= stash
->all_comp_units
; each
; each
= each
->next_unit
)
1791 if (comp_unit_contains_address (each
, addr
))
1792 return comp_unit_find_nearest_line (each
, addr
, filename_ptr
,
1793 functionname_ptr
, linenumber_ptr
,
1796 /* Read each remaining comp. units checking each as they are read. */
1797 while (stash
->info_ptr
< stash
->info_ptr_end
)
1801 unsigned int offset_size
= addr_size
;
1803 length
= read_4_bytes (abfd
, stash
->info_ptr
);
1804 /* A 0xffffff length is the DWARF3 way of indicating we use
1805 64-bit offsets, instead of 32-bit offsets. */
1806 if (length
== 0xffffffff)
1809 length
= read_8_bytes (abfd
, stash
->info_ptr
+ 4);
1810 stash
->info_ptr
+= 12;
1812 /* A zero length is the IRIX way of indicating 64-bit offsets,
1813 mostly because the 64-bit length will generally fit in 32
1814 bits, and the endianness helps. */
1815 else if (length
== 0)
1818 length
= read_4_bytes (abfd
, stash
->info_ptr
+ 4);
1819 stash
->info_ptr
+= 8;
1821 /* In the absence of the hints above, we assume addr_size-sized
1822 offsets, for backward-compatibility with pre-DWARF3 64-bit
1824 else if (addr_size
== 8)
1826 length
= read_8_bytes (abfd
, stash
->info_ptr
);
1827 stash
->info_ptr
+= 8;
1830 stash
->info_ptr
+= 4;
1834 each
= parse_comp_unit (abfd
, stash
, length
, offset_size
);
1835 stash
->info_ptr
+= length
;
1837 if ((bfd_vma
) (stash
->info_ptr
- stash
->sec_info_ptr
)
1838 == stash
->sec
->size
)
1840 stash
->sec
= find_debug_info (abfd
, stash
->sec
);
1841 stash
->sec_info_ptr
= stash
->info_ptr
;
1846 each
->next_unit
= stash
->all_comp_units
;
1847 stash
->all_comp_units
= each
;
1849 /* DW_AT_low_pc and DW_AT_high_pc are optional for
1850 compilation units. If we don't have them (i.e.,
1851 unit->high == 0), we need to consult the line info
1852 table to see if a compilation unit contains the given
1854 if (each
->arange
.high
> 0)
1856 if (comp_unit_contains_address (each
, addr
))
1857 return comp_unit_find_nearest_line (each
, addr
,
1865 found
= comp_unit_find_nearest_line (each
, addr
,