2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
3 2004, 2005 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 02110-1301, 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. */
88 bfd_byte *info_ptr_end;
90 /* Pointer to the section and address of the beginning of the
93 bfd_byte *sec_info_ptr;
95 /* Pointer to the symbol table. */
98 /* Pointer to the .debug_abbrev section loaded into memory. */
99 bfd_byte *dwarf_abbrev_buffer;
101 /* Length of the loaded .debug_abbrev section. */
102 unsigned long dwarf_abbrev_size;
104 /* Buffer for decode_line_info. */
105 bfd_byte *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 bfd_byte *dwarf_str_buffer;
113 /* Length of the loaded .debug_str section. */
114 unsigned long dwarf_str_size;
116 /* Pointer to the .debug_ranges section loaded into memory. */
117 bfd_byte *dwarf_ranges_buffer;
119 /* Length of the loaded .debug_ranges section. */
120 unsigned long dwarf_ranges_size;
130 /* A minimal decoding of DWARF2 compilation units. We only decode
131 what's needed to get to the line number information. */
135 /* Chain the previously read compilation units. */
136 struct comp_unit *next_unit;
138 /* Keep the bdf convenient (for memory allocation). */
141 /* The lowest and highest addresses contained in this compilation
142 unit as specified in the compilation unit header. */
143 struct arange arange;
145 /* The DW_AT_name attribute (for error messages). */
148 /* The abbrev hash table. */
149 struct abbrev_info **abbrevs;
151 /* Note that an error was found by comp_unit_find_nearest_line. */
154 /* The DW_AT_comp_dir attribute. */
157 /* TRUE if there is a line number table associated with this comp. unit. */
160 /* Pointer to the current comp_unit so that we can find a given entry
162 bfd_byte *info_ptr_unit;
164 /* The offset into .debug_line of the line number table. */
165 unsigned long line_offset;
167 /* Pointer to the first child die for the comp unit. */
168 bfd_byte *first_child_die_ptr;
170 /* The end of the comp unit. */
173 /* The decoded line number, NULL if not yet decoded. */
174 struct line_info_table *line_table;
176 /* A list of the functions found in this comp. unit. */
177 struct funcinfo *function_table;
179 /* Pointer to dwarf2_debug structure. */
180 struct dwarf2_debug *stash;
182 /* Address size for this unit - from unit header. */
183 unsigned char addr_size;
185 /* Offset size for this unit - from unit header. */
186 unsigned char offset_size;
188 /* Base address for this unit - from DW_AT_low_pc attribute of
189 DW_TAG_compile_unit DIE */
190 bfd_vma base_address;
193 /* This data structure holds the information of an abbrev. */
196 unsigned int number; /* Number identifying abbrev. */
197 enum dwarf_tag tag; /* DWARF tag. */
198 int has_children; /* Boolean. */
199 unsigned int num_attrs; /* Number of attributes. */
200 struct attr_abbrev *attrs; /* An array of attribute descriptions. */
201 struct abbrev_info *next; /* Next in chain. */
206 enum dwarf_attribute name;
207 enum dwarf_form form;
210 #ifndef ABBREV_HASH_SIZE
211 #define ABBREV_HASH_SIZE 121
213 #ifndef ATTR_ALLOC_CHUNK
214 #define ATTR_ALLOC_CHUNK 4
218 The following function up to the END VERBATIM mark are
219 copied directly from dwarf2read.c. */
221 /* Read dwarf information from a buffer. */
224 read_1_byte (bfd *abfd ATTRIBUTE_UNUSED, bfd_byte *buf)
226 return bfd_get_8 (abfd, buf);
230 read_1_signed_byte (bfd *abfd ATTRIBUTE_UNUSED, bfd_byte *buf)
232 return bfd_get_signed_8 (abfd, buf);
236 read_2_bytes (bfd *abfd, bfd_byte *buf)
238 return bfd_get_16 (abfd, buf);
242 read_4_bytes (bfd *abfd, bfd_byte *buf)
244 return bfd_get_32 (abfd, buf);
248 read_8_bytes (bfd *abfd, bfd_byte *buf)
250 return bfd_get_64 (abfd, buf);
254 read_n_bytes (bfd *abfd ATTRIBUTE_UNUSED,
256 unsigned int size ATTRIBUTE_UNUSED)
258 /* If the size of a host char is 8 bits, we can return a pointer
259 to the buffer, otherwise we have to copy the data to a buffer
260 allocated on the temporary obstack. */
265 read_string (bfd *abfd ATTRIBUTE_UNUSED,
267 unsigned int *bytes_read_ptr)
269 /* Return a pointer to the embedded string. */
270 char *str = (char *) buf;
277 *bytes_read_ptr = strlen (str) + 1;
282 read_indirect_string (struct comp_unit* unit,
284 unsigned int *bytes_read_ptr)
287 struct dwarf2_debug *stash = unit->stash;
290 if (unit->offset_size == 4)
291 offset = read_4_bytes (unit->abfd, buf);
293 offset = read_8_bytes (unit->abfd, buf);
294 *bytes_read_ptr = unit->offset_size;
296 if (! stash->dwarf_str_buffer)
299 bfd *abfd = unit->abfd;
302 msec = bfd_get_section_by_name (abfd, ".debug_str");
305 (*_bfd_error_handler)
306 (_("Dwarf Error: Can't find .debug_str section."));
307 bfd_set_error (bfd_error_bad_value);
311 sz = msec->rawsize ? msec->rawsize : msec->size;
312 stash->dwarf_str_size = sz;
313 stash->dwarf_str_buffer = bfd_alloc (abfd, sz);
314 if (! stash->dwarf_str_buffer)
317 if (! bfd_get_section_contents (abfd, msec, stash->dwarf_str_buffer,
322 if (offset >= stash->dwarf_str_size)
324 (*_bfd_error_handler) (_("Dwarf Error: DW_FORM_strp offset (%lu) greater than or equal to .debug_str size (%lu)."),
325 (unsigned long) offset, stash->dwarf_str_size);
326 bfd_set_error (bfd_error_bad_value);
330 str = (char *) stash->dwarf_str_buffer + offset;
339 read_address (struct comp_unit *unit, bfd_byte *buf)
341 switch (unit->addr_size)
344 return bfd_get_64 (unit->abfd, buf);
346 return bfd_get_32 (unit->abfd, buf);
348 return bfd_get_16 (unit->abfd, buf);
354 /* Lookup an abbrev_info structure in the abbrev hash table. */
356 static struct abbrev_info *
357 lookup_abbrev (unsigned int number, struct abbrev_info **abbrevs)
359 unsigned int hash_number;
360 struct abbrev_info *abbrev;
362 hash_number = number % ABBREV_HASH_SIZE;
363 abbrev = abbrevs[hash_number];
367 if (abbrev->number == number)
370 abbrev = abbrev->next;
376 /* In DWARF version 2, the description of the debugging information is
377 stored in a separate .debug_abbrev section. Before we read any
378 dies from a section we read in all abbreviations and install them
381 static struct abbrev_info**
382 read_abbrevs (bfd *abfd, bfd_uint64_t offset, struct dwarf2_debug *stash)
384 struct abbrev_info **abbrevs;
385 bfd_byte *abbrev_ptr;
386 struct abbrev_info *cur_abbrev;
387 unsigned int abbrev_number, bytes_read, abbrev_name;
388 unsigned int abbrev_form, hash_number;
391 if (! stash->dwarf_abbrev_buffer)
395 msec = bfd_get_section_by_name (abfd, ".debug_abbrev");
398 (*_bfd_error_handler) (_("Dwarf Error: Can't find .debug_abbrev section."));
399 bfd_set_error (bfd_error_bad_value);
403 stash->dwarf_abbrev_size = msec->size;
404 stash->dwarf_abbrev_buffer
405 = bfd_simple_get_relocated_section_contents (abfd, msec, NULL,
407 if (! stash->dwarf_abbrev_buffer)
411 if (offset >= stash->dwarf_abbrev_size)
413 (*_bfd_error_handler) (_("Dwarf Error: Abbrev offset (%lu) greater than or equal to .debug_abbrev size (%lu)."),
414 (unsigned long) offset, stash->dwarf_abbrev_size);
415 bfd_set_error (bfd_error_bad_value);
419 amt = sizeof (struct abbrev_info*) * ABBREV_HASH_SIZE;
420 abbrevs = bfd_zalloc (abfd, amt);
422 abbrev_ptr = stash->dwarf_abbrev_buffer + offset;
423 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
424 abbrev_ptr += bytes_read;
426 /* Loop until we reach an abbrev number of 0. */
427 while (abbrev_number)
429 amt = sizeof (struct abbrev_info);
430 cur_abbrev = bfd_zalloc (abfd, amt);
432 /* Read in abbrev header. */
433 cur_abbrev->number = abbrev_number;
434 cur_abbrev->tag = (enum dwarf_tag)
435 read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
436 abbrev_ptr += bytes_read;
437 cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr);
440 /* Now read in declarations. */
441 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
442 abbrev_ptr += bytes_read;
443 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
444 abbrev_ptr += bytes_read;
448 if ((cur_abbrev->num_attrs % ATTR_ALLOC_CHUNK) == 0)
450 amt = cur_abbrev->num_attrs + ATTR_ALLOC_CHUNK;
451 amt *= sizeof (struct attr_abbrev);
452 cur_abbrev->attrs = bfd_realloc (cur_abbrev->attrs, amt);
453 if (! cur_abbrev->attrs)
457 cur_abbrev->attrs[cur_abbrev->num_attrs].name
458 = (enum dwarf_attribute) abbrev_name;
459 cur_abbrev->attrs[cur_abbrev->num_attrs++].form
460 = (enum dwarf_form) abbrev_form;
461 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
462 abbrev_ptr += bytes_read;
463 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
464 abbrev_ptr += bytes_read;
467 hash_number = abbrev_number % ABBREV_HASH_SIZE;
468 cur_abbrev->next = abbrevs[hash_number];
469 abbrevs[hash_number] = cur_abbrev;
471 /* Get next abbreviation.
472 Under Irix6 the abbreviations for a compilation unit are not
473 always properly terminated with an abbrev number of 0.
474 Exit loop if we encounter an abbreviation which we have
475 already read (which means we are about to read the abbreviations
476 for the next compile unit) or if the end of the abbreviation
478 if ((unsigned int) (abbrev_ptr - stash->dwarf_abbrev_buffer)
479 >= stash->dwarf_abbrev_size)
481 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
482 abbrev_ptr += bytes_read;
483 if (lookup_abbrev (abbrev_number,abbrevs) != NULL)
490 /* Read an attribute value described by an attribute form. */
493 read_attribute_value (struct attribute *attr,
495 struct comp_unit *unit,
498 bfd *abfd = unit->abfd;
499 unsigned int bytes_read;
500 struct dwarf_block *blk;
503 attr->form = (enum dwarf_form) form;
508 /* FIXME: DWARF3 draft says DW_FORM_ref_addr is offset_size. */
509 case DW_FORM_ref_addr:
510 attr->u.val = read_address (unit, info_ptr);
511 info_ptr += unit->addr_size;
514 amt = sizeof (struct dwarf_block);
515 blk = bfd_alloc (abfd, amt);
516 blk->size = read_2_bytes (abfd, info_ptr);
518 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
519 info_ptr += blk->size;
523 amt = sizeof (struct dwarf_block);
524 blk = bfd_alloc (abfd, amt);
525 blk->size = read_4_bytes (abfd, info_ptr);
527 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
528 info_ptr += blk->size;
532 attr->u.val = read_2_bytes (abfd, info_ptr);
536 attr->u.val = read_4_bytes (abfd, info_ptr);
540 attr->u.val = read_8_bytes (abfd, info_ptr);
544 attr->u.str = read_string (abfd, info_ptr, &bytes_read);
545 info_ptr += bytes_read;
548 attr->u.str = read_indirect_string (unit, info_ptr, &bytes_read);
549 info_ptr += bytes_read;
552 amt = sizeof (struct dwarf_block);
553 blk = bfd_alloc (abfd, amt);
554 blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
555 info_ptr += bytes_read;
556 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
557 info_ptr += blk->size;
561 amt = sizeof (struct dwarf_block);
562 blk = bfd_alloc (abfd, amt);
563 blk->size = read_1_byte (abfd, info_ptr);
565 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
566 info_ptr += blk->size;
570 attr->u.val = read_1_byte (abfd, info_ptr);
574 attr->u.val = read_1_byte (abfd, info_ptr);
578 attr->u.sval = read_signed_leb128 (abfd, info_ptr, &bytes_read);
579 info_ptr += bytes_read;
582 attr->u.val = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
583 info_ptr += bytes_read;
586 attr->u.val = read_1_byte (abfd, info_ptr);
590 attr->u.val = read_2_bytes (abfd, info_ptr);
594 attr->u.val = read_4_bytes (abfd, info_ptr);
598 attr->u.val = read_8_bytes (abfd, info_ptr);
601 case DW_FORM_ref_udata:
602 attr->u.val = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
603 info_ptr += bytes_read;
605 case DW_FORM_indirect:
606 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
607 info_ptr += bytes_read;
608 info_ptr = read_attribute_value (attr, form, unit, info_ptr);
611 (*_bfd_error_handler) (_("Dwarf Error: Invalid or unhandled FORM value: %u."),
613 bfd_set_error (bfd_error_bad_value);
618 /* Read an attribute described by an abbreviated attribute. */
621 read_attribute (struct attribute *attr,
622 struct attr_abbrev *abbrev,
623 struct comp_unit *unit,
626 attr->name = abbrev->name;
627 info_ptr = read_attribute_value (attr, abbrev->form, unit, info_ptr);
631 /* Source line information table routines. */
633 #define FILE_ALLOC_CHUNK 5
634 #define DIR_ALLOC_CHUNK 5
638 struct line_info* prev_line;
643 int end_sequence; /* End of (sequential) code sequence. */
654 struct line_info_table
657 unsigned int num_files;
658 unsigned int num_dirs;
661 struct fileinfo* files;
662 struct line_info* last_line; /* largest VMA */
663 struct line_info* lcl_head; /* local head; used in 'add_line_info' */
668 struct funcinfo *prev_func;
670 struct arange arange;
673 /* Adds a new entry to the line_info list in the line_info_table, ensuring
674 that the list is sorted. Note that the line_info list is sorted from
675 highest to lowest VMA (with possible duplicates); that is,
676 line_info->prev_line always accesses an equal or smaller VMA. */
679 add_line_info (struct line_info_table *table,
686 bfd_size_type amt = sizeof (struct line_info);
687 struct line_info* info = bfd_alloc (table->abfd, amt);
689 /* Find the correct location for 'info'. Normally we will receive
690 new line_info data 1) in order and 2) with increasing VMAs.
691 However some compilers break the rules (cf. decode_line_info) and
692 so we include some heuristics for quickly finding the correct
693 location for 'info'. In particular, these heuristics optimize for
694 the common case in which the VMA sequence that we receive is a
695 list of locally sorted VMAs such as
696 p...z a...j (where a < j < p < z)
698 Note: table->lcl_head is used to head an *actual* or *possible*
699 sequence within the list (such as a...j) that is not directly
700 headed by table->last_line
702 Note: we may receive duplicate entries from 'decode_line_info'. */
705 if (!table->last_line
706 || address >= table->last_line->address)
708 /* Normal case: add 'info' to the beginning of the list */
709 info->prev_line = table->last_line;
710 table->last_line = info;
712 /* lcl_head: initialize to head a *possible* sequence at the end. */
713 if (!table->lcl_head)
714 table->lcl_head = info;
717 else if (!table->lcl_head->prev_line
718 && table->lcl_head->address > address)
720 /* Abnormal but easy: lcl_head is 1) at the *end* of the line
721 list and 2) the head of 'info'. */
722 info->prev_line = NULL;
723 table->lcl_head->prev_line = info;
726 else if (table->lcl_head->prev_line
727 && table->lcl_head->address > address
728 && address >= table->lcl_head->prev_line->address)
730 /* Abnormal but easy: lcl_head is 1) in the *middle* of the line
731 list and 2) the head of 'info'. */
732 info->prev_line = table->lcl_head->prev_line;
733 table->lcl_head->prev_line = info;
738 /* Abnormal and hard: Neither 'last_line' nor 'lcl_head' are valid
739 heads for 'info'. Reset 'lcl_head' and repeat. */
740 struct line_info* li2 = table->last_line; /* always non-NULL */
741 struct line_info* li1 = li2->prev_line;
745 if (li2->address > address && address >= li1->address)
748 li2 = li1; /* always non-NULL */
749 li1 = li1->prev_line;
751 table->lcl_head = li2;
754 /* Set member data of 'info'. */
755 info->address = address;
757 info->column = column;
758 info->end_sequence = end_sequence;
760 if (filename && filename[0])
762 info->filename = bfd_alloc (table->abfd, strlen (filename) + 1);
764 strcpy (info->filename, filename);
767 info->filename = NULL;
770 /* Extract a fully qualified filename from a line info table.
771 The returned string has been malloc'ed and it is the caller's
772 responsibility to free it. */
775 concat_filename (struct line_info_table *table, unsigned int file)
779 if (file - 1 >= table->num_files)
781 (*_bfd_error_handler)
782 (_("Dwarf Error: mangled line number section (bad file number)."));
783 return strdup ("<unknown>");
786 filename = table->files[file - 1].name;
788 if (! IS_ABSOLUTE_PATH (filename))
790 char *dirname = (table->files[file - 1].dir
791 ? table->dirs[table->files[file - 1].dir - 1]
794 /* Not all tools set DW_AT_comp_dir, so dirname may be unknown.
795 The best we can do is return the filename part. */
798 unsigned int len = strlen (dirname) + strlen (filename) + 2;
801 name = bfd_malloc (len);
803 sprintf (name, "%s/%s", dirname, filename);
808 return strdup (filename);
812 arange_add (bfd *abfd, struct arange *first_arange, bfd_vma low_pc, bfd_vma high_pc)
814 struct arange *arange;
816 /* If the first arange is empty, use it. */
817 if (first_arange->high == 0)
819 first_arange->low = low_pc;
820 first_arange->high = high_pc;
824 /* Next see if we can cheaply extend an existing range. */
825 arange = first_arange;
828 if (low_pc == arange->high)
830 arange->high = high_pc;
833 if (high_pc == arange->low)
835 arange->low = low_pc;
838 arange = arange->next;
842 /* Need to allocate a new arange and insert it into the arange list.
843 Order isn't significant, so just insert after the first arange. */
844 arange = bfd_zalloc (abfd, sizeof (*arange));
845 arange->low = low_pc;
846 arange->high = high_pc;
847 arange->next = first_arange->next;
848 first_arange->next = arange;
851 /* Decode the line number information for UNIT. */
853 static struct line_info_table*
854 decode_line_info (struct comp_unit *unit, struct dwarf2_debug *stash)
856 bfd *abfd = unit->abfd;
857 struct line_info_table* table;
861 unsigned int i, bytes_read, offset_size;
862 char *cur_file, *cur_dir;
863 unsigned char op_code, extended_op, adj_opcode;
866 if (! stash->dwarf_line_buffer)
870 msec = bfd_get_section_by_name (abfd, ".debug_line");
873 (*_bfd_error_handler) (_("Dwarf Error: Can't find .debug_line section."));
874 bfd_set_error (bfd_error_bad_value);
878 stash->dwarf_line_size = msec->size;
879 stash->dwarf_line_buffer
880 = bfd_simple_get_relocated_section_contents (abfd, msec, NULL,
882 if (! stash->dwarf_line_buffer)
886 /* It is possible to get a bad value for the line_offset. Validate
887 it here so that we won't get a segfault below. */
888 if (unit->line_offset >= stash->dwarf_line_size)
890 (*_bfd_error_handler) (_("Dwarf Error: Line offset (%lu) greater than or equal to .debug_line size (%lu)."),
891 unit->line_offset, stash->dwarf_line_size);
892 bfd_set_error (bfd_error_bad_value);
896 amt = sizeof (struct line_info_table);
897 table = bfd_alloc (abfd, amt);
899 table->comp_dir = unit->comp_dir;
901 table->num_files = 0;
908 table->last_line = NULL;
909 table->lcl_head = NULL;
911 line_ptr = stash->dwarf_line_buffer + unit->line_offset;
913 /* Read in the prologue. */
914 lh.total_length = read_4_bytes (abfd, line_ptr);
917 if (lh.total_length == 0xffffffff)
919 lh.total_length = read_8_bytes (abfd, line_ptr);
923 else if (lh.total_length == 0 && unit->addr_size == 8)
925 /* Handle (non-standard) 64-bit DWARF2 formats. */
926 lh.total_length = read_4_bytes (abfd, line_ptr);
930 line_end = line_ptr + lh.total_length;
931 lh.version = read_2_bytes (abfd, line_ptr);
933 if (offset_size == 4)
934 lh.prologue_length = read_4_bytes (abfd, line_ptr);
936 lh.prologue_length = read_8_bytes (abfd, line_ptr);
937 line_ptr += offset_size;
938 lh.minimum_instruction_length = read_1_byte (abfd, line_ptr);
940 lh.default_is_stmt = read_1_byte (abfd, line_ptr);
942 lh.line_base = read_1_signed_byte (abfd, line_ptr);
944 lh.line_range = read_1_byte (abfd, line_ptr);
946 lh.opcode_base = read_1_byte (abfd, line_ptr);
948 amt = lh.opcode_base * sizeof (unsigned char);
949 lh.standard_opcode_lengths = bfd_alloc (abfd, amt);
951 lh.standard_opcode_lengths[0] = 1;
953 for (i = 1; i < lh.opcode_base; ++i)
955 lh.standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr);
959 /* Read directory table. */
960 while ((cur_dir = read_string (abfd, line_ptr, &bytes_read)) != NULL)
962 line_ptr += bytes_read;
964 if ((table->num_dirs % DIR_ALLOC_CHUNK) == 0)
966 amt = table->num_dirs + DIR_ALLOC_CHUNK;
967 amt *= sizeof (char *);
968 table->dirs = bfd_realloc (table->dirs, amt);
973 table->dirs[table->num_dirs++] = cur_dir;
976 line_ptr += bytes_read;
978 /* Read file name table. */
979 while ((cur_file = read_string (abfd, line_ptr, &bytes_read)) != NULL)
981 line_ptr += bytes_read;
983 if ((table->num_files % FILE_ALLOC_CHUNK) == 0)
985 amt = table->num_files + FILE_ALLOC_CHUNK;
986 amt *= sizeof (struct fileinfo);
987 table->files = bfd_realloc (table->files, amt);
992 table->files[table->num_files].name = cur_file;
993 table->files[table->num_files].dir =
994 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
995 line_ptr += bytes_read;
996 table->files[table->num_files].time =
997 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
998 line_ptr += bytes_read;
999 table->files[table->num_files].size =
1000 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
1001 line_ptr += bytes_read;
1005 line_ptr += bytes_read;
1007 /* Read the statement sequences until there's nothing left. */
1008 while (line_ptr < line_end)
1010 /* State machine registers. */
1011 bfd_vma address = 0;
1012 char * filename = table->num_files ? concat_filename (table, 1) : NULL;
1013 unsigned int line = 1;
1014 unsigned int column = 0;
1015 int is_stmt = lh.default_is_stmt;
1016 int basic_block = 0;
1017 int end_sequence = 0;
1018 /* eraxxon@alumni.rice.edu: Against the DWARF2 specs, some
1019 compilers generate address sequences that are wildly out of
1020 order using DW_LNE_set_address (e.g. Intel C++ 6.0 compiler
1021 for ia64-Linux). Thus, to determine the low and high
1022 address, we must compare on every DW_LNS_copy, etc. */
1024 bfd_vma high_pc = 0;
1026 /* Decode the table. */
1027 while (! end_sequence)
1029 op_code = read_1_byte (abfd, line_ptr);
1032 if (op_code >= lh.opcode_base)
1034 /* Special operand. */
1035 adj_opcode = op_code - lh.opcode_base;
1036 address += (adj_opcode / lh.line_range)
1037 * lh.minimum_instruction_length;
1038 line += lh.line_base + (adj_opcode % lh.line_range);
1039 /* Append row to matrix using current values. */
1040 add_line_info (table, address, filename, line, column, 0);
1042 if (low_pc == 0 || address < low_pc)
1044 if (address > high_pc)
1047 else switch (op_code)
1049 case DW_LNS_extended_op:
1050 /* Ignore length. */
1052 extended_op = read_1_byte (abfd, line_ptr);
1055 switch (extended_op)
1057 case DW_LNE_end_sequence:
1059 add_line_info (table, address, filename, line, column,
1061 if (low_pc == 0 || address < low_pc)
1063 if (address > high_pc)
1065 arange_add (unit->abfd, &unit->arange, low_pc, high_pc);
1067 case DW_LNE_set_address:
1068 address = read_address (unit, line_ptr);
1069 line_ptr += unit->addr_size;
1071 case DW_LNE_define_file:
1072 cur_file = read_string (abfd, line_ptr, &bytes_read);
1073 line_ptr += bytes_read;
1074 if ((table->num_files % FILE_ALLOC_CHUNK) == 0)
1076 amt = table->num_files + FILE_ALLOC_CHUNK;
1077 amt *= sizeof (struct fileinfo);
1078 table->files = bfd_realloc (table->files, amt);
1082 table->files[table->num_files].name = cur_file;
1083 table->files[table->num_files].dir =
1084 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
1085 line_ptr += bytes_read;
1086 table->files[table->num_files].time =
1087 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
1088 line_ptr += bytes_read;
1089 table->files[table->num_files].size =
1090 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
1091 line_ptr += bytes_read;
1095 (*_bfd_error_handler) (_("Dwarf Error: mangled line number section."));
1096 bfd_set_error (bfd_error_bad_value);
1101 add_line_info (table, address, filename, line, column, 0);
1103 if (low_pc == 0 || address < low_pc)
1105 if (address > high_pc)
1108 case DW_LNS_advance_pc:
1109 address += lh.minimum_instruction_length
1110 * read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
1111 line_ptr += bytes_read;
1113 case DW_LNS_advance_line:
1114 line += read_signed_leb128 (abfd, line_ptr, &bytes_read);
1115 line_ptr += bytes_read;
1117 case DW_LNS_set_file:
1121 /* The file and directory tables are 0
1122 based, the references are 1 based. */
1123 file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
1124 line_ptr += bytes_read;
1127 filename = concat_filename (table, file);
1130 case DW_LNS_set_column:
1131 column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
1132 line_ptr += bytes_read;
1134 case DW_LNS_negate_stmt:
1135 is_stmt = (!is_stmt);
1137 case DW_LNS_set_basic_block:
1140 case DW_LNS_const_add_pc:
1141 address += lh.minimum_instruction_length
1142 * ((255 - lh.opcode_base) / lh.line_range);
1144 case DW_LNS_fixed_advance_pc:
1145 address += read_2_bytes (abfd, line_ptr);
1152 /* Unknown standard opcode, ignore it. */
1153 for (i = 0; i < lh.standard_opcode_lengths[op_code]; i++)
1155 (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
1156 line_ptr += bytes_read;
1169 /* If ADDR is within TABLE set the output parameters and return TRUE,
1170 otherwise return FALSE. The output parameters, FILENAME_PTR and
1171 LINENUMBER_PTR, are pointers to the objects to be filled in. */
1174 lookup_address_in_line_info_table (struct line_info_table *table,
1176 struct funcinfo *function,
1177 const char **filename_ptr,
1178 unsigned int *linenumber_ptr)
1180 /* Note: table->last_line should be a descendingly sorted list. */
1181 struct line_info* next_line = table->last_line;
1182 struct line_info* each_line = NULL;
1183 *filename_ptr = NULL;
1188 each_line = next_line->prev_line;
1190 /* Check for large addresses */
1191 if (addr > next_line->address)
1192 each_line = NULL; /* ensure we skip over the normal case */
1194 /* Normal case: search the list; save */
1195 while (each_line && next_line)
1197 /* If we have an address match, save this info. This allows us
1198 to return as good as results as possible for strange debugging
1200 bfd_boolean addr_match = FALSE;
1201 if (each_line->address <= addr && addr < next_line->address)
1205 /* If this line appears to span functions, and addr is in the
1206 later function, return the first line of that function instead
1207 of the last line of the earlier one. This check is for GCC
1208 2.95, which emits the first line number for a function late. */
1210 if (function != NULL)
1213 struct arange *arange;
1215 /* Find the lowest address in the function's range list */
1216 lowest_pc = function->arange.low;
1217 for (arange = &function->arange;
1219 arange = arange->next)
1221 if (function->arange.low < lowest_pc)
1222 lowest_pc = function->arange.low;
1224 /* Check for spanning function and set outgoing line info */
1225 if (addr >= lowest_pc
1226 && each_line->address < lowest_pc
1227 && next_line->address > lowest_pc)
1229 *filename_ptr = next_line->filename;
1230 *linenumber_ptr = next_line->line;
1234 *filename_ptr = each_line->filename;
1235 *linenumber_ptr = each_line->line;
1240 if (addr_match && !each_line->end_sequence)
1241 return TRUE; /* we have definitely found what we want */
1243 next_line = each_line;
1244 each_line = each_line->prev_line;
1247 /* At this point each_line is NULL but next_line is not. If we found
1248 a candidate end-of-sequence point in the loop above, we can return
1249 that (compatibility with a bug in the Intel compiler); otherwise,
1250 assuming that we found the containing function for this address in
1251 this compilation unit, return the first line we have a number for
1252 (compatibility with GCC 2.95). */
1253 if (*filename_ptr == NULL && function != NULL)
1255 *filename_ptr = next_line->filename;
1256 *linenumber_ptr = next_line->line;
1263 /* Read in the .debug_ranges section for future reference */
1266 read_debug_ranges (struct comp_unit *unit)
1268 struct dwarf2_debug *stash = unit->stash;
1269 if (! stash->dwarf_ranges_buffer)
1271 bfd *abfd = unit->abfd;
1274 msec = bfd_get_section_by_name (abfd, ".debug_ranges");
1277 (*_bfd_error_handler) (_("Dwarf Error: Can't find .debug_ranges section."));
1278 bfd_set_error (bfd_error_bad_value);
1282 stash->dwarf_ranges_size = msec->size;
1283 stash->dwarf_ranges_buffer
1284 = bfd_simple_get_relocated_section_contents (abfd, msec, NULL,
1286 if (! stash->dwarf_ranges_buffer)
1292 /* Function table functions. */
1294 /* If ADDR is within TABLE, set FUNCTIONNAME_PTR, and return TRUE.
1295 Note that we need to find the function that has the smallest
1296 range that contains ADDR, to handle inlined functions without
1297 depending upon them being ordered in TABLE by increasing range. */
1300 lookup_address_in_function_table (struct funcinfo *table,
1302 struct funcinfo **function_ptr,
1303 const char **functionname_ptr)
1305 struct funcinfo* each_func;
1306 struct funcinfo* best_fit = NULL;
1307 struct arange *arange;
1309 for (each_func = table;
1311 each_func = each_func->prev_func)
1313 for (arange = &each_func->arange;
1315 arange = arange->next)
1317 if (addr >= arange->low && addr < arange->high)
1320 ((arange->high - arange->low) < (best_fit->arange.high - best_fit->arange.low)))
1321 best_fit = each_func;
1328 *functionname_ptr = best_fit->name;
1329 *function_ptr = best_fit;
1339 find_abstract_instance_name (struct comp_unit *unit, bfd_uint64_t die_ref)
1341 bfd *abfd = unit->abfd;
1343 unsigned int abbrev_number, bytes_read, i;
1344 struct abbrev_info *abbrev;
1345 struct attribute attr;
1348 info_ptr = unit->info_ptr_unit + die_ref;
1349 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
1350 info_ptr += bytes_read;
1354 abbrev = lookup_abbrev (abbrev_number, unit->abbrevs);
1357 (*_bfd_error_handler) (_("Dwarf Error: Could not find abbrev number %u."),
1359 bfd_set_error (bfd_error_bad_value);
1363 for (i = 0; i < abbrev->num_attrs && !name; ++i)
1365 info_ptr = read_attribute (&attr, &abbrev->attrs[i], unit, info_ptr);
1371 case DW_AT_specification:
1372 name = find_abstract_instance_name (unit, attr.u.val);
1384 read_rangelist (struct comp_unit *unit, struct arange *arange, bfd_uint64_t offset)
1386 bfd_byte *ranges_ptr;
1387 bfd_vma base_address = unit->base_address;
1389 if (! unit->stash->dwarf_ranges_buffer)
1391 if (! read_debug_ranges (unit))
1394 ranges_ptr = unit->stash->dwarf_ranges_buffer + offset;
1401 if (unit->offset_size == 4)
1403 low_pc = read_4_bytes (unit->abfd, ranges_ptr);
1405 high_pc = read_4_bytes (unit->abfd, ranges_ptr);
1410 low_pc = read_8_bytes (unit->abfd, ranges_ptr);
1412 high_pc = read_8_bytes (unit->abfd, ranges_ptr);
1415 if (low_pc == 0 && high_pc == 0)
1417 if (low_pc == -1UL && high_pc != -1UL)
1418 base_address = high_pc;
1420 arange_add (unit->abfd, arange, base_address + low_pc, base_address + high_pc);
1424 /* DWARF2 Compilation unit functions. */
1426 /* Scan over each die in a comp. unit looking for functions to add
1427 to the function table. */
1430 scan_unit_for_functions (struct comp_unit *unit)
1432 bfd *abfd = unit->abfd;
1433 bfd_byte *info_ptr = unit->first_child_die_ptr;
1434 int nesting_level = 1;
1436 while (nesting_level)
1438 unsigned int abbrev_number, bytes_read, i;
1439 struct abbrev_info *abbrev;
1440 struct attribute attr;
1441 struct funcinfo *func;
1443 bfd_vma high_pc = 0;
1445 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
1446 info_ptr += bytes_read;
1448 if (! abbrev_number)
1454 abbrev = lookup_abbrev (abbrev_number,unit->abbrevs);
1457 (*_bfd_error_handler) (_("Dwarf Error: Could not find abbrev number %u."),
1459 bfd_set_error (bfd_error_bad_value);
1463 if (abbrev->tag == DW_TAG_subprogram
1464 || abbrev->tag == DW_TAG_inlined_subroutine)
1466 bfd_size_type amt = sizeof (struct funcinfo);
1467 func = bfd_zalloc (abfd, amt);
1468 func->prev_func = unit->function_table;
1469 unit->function_table = func;
1474 for (i = 0; i < abbrev->num_attrs; ++i)
1476 info_ptr = read_attribute (&attr, &abbrev->attrs[i], unit, info_ptr);
1482 case DW_AT_abstract_origin:
1483 func->name = find_abstract_instance_name (unit, attr.u.val);
1487 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
1488 if (func->name == NULL)
1489 func->name = attr.u.str;
1492 case DW_AT_MIPS_linkage_name:
1493 func->name = attr.u.str;
1497 low_pc = attr.u.val;
1501 high_pc = attr.u.val;
1505 read_rangelist (unit, &func->arange, attr.u.val);
1514 if (func && high_pc != 0)
1516 arange_add (unit->abfd, &func->arange, low_pc, high_pc);
1519 if (abbrev->has_children)
1526 /* Parse a DWARF2 compilation unit starting at INFO_PTR. This
1527 includes the compilation unit header that proceeds the DIE's, but
1528 does not include the length field that precedes each compilation
1529 unit header. END_PTR points one past the end of this comp unit.
1530 OFFSET_SIZE is the size of DWARF2 offsets (either 4 or 8 bytes).
1532 This routine does not read the whole compilation unit; only enough
1533 to get to the line number information for the compilation unit. */
1535 static struct comp_unit *
1536 parse_comp_unit (bfd *abfd,
1537 struct dwarf2_debug *stash,
1538 bfd_vma unit_length,
1539 bfd_byte *info_ptr_unit,
1540 unsigned int offset_size)
1542 struct comp_unit* unit;
1543 unsigned int version;
1544 bfd_uint64_t abbrev_offset = 0;
1545 unsigned int addr_size;
1546 struct abbrev_info** abbrevs;
1547 unsigned int abbrev_number, bytes_read, i;
1548 struct abbrev_info *abbrev;
1549 struct attribute attr;
1550 bfd_byte *info_ptr = stash->info_ptr;
1551 bfd_byte *end_ptr = info_ptr + unit_length;
1554 bfd_vma high_pc = 0;
1556 version = read_2_bytes (abfd, info_ptr);
1558 BFD_ASSERT (offset_size == 4 || offset_size == 8);
1559 if (offset_size == 4)
1560 abbrev_offset = read_4_bytes (abfd, info_ptr);
1562 abbrev_offset = read_8_bytes (abfd, info_ptr);
1563 info_ptr += offset_size;
1564 addr_size = read_1_byte (abfd, info_ptr);
1569 (*_bfd_error_handler) (_("Dwarf Error: found dwarf version '%u', this reader only handles version 2 information."), version);
1570 bfd_set_error (bfd_error_bad_value);
1574 if (addr_size > sizeof (bfd_vma))
1576 (*_bfd_error_handler) (_("Dwarf Error: found address size '%u', this reader can not handle sizes greater than '%u'."),
1578 (unsigned int) sizeof (bfd_vma));
1579 bfd_set_error (bfd_error_bad_value);
1583 if (addr_size != 2 && addr_size != 4 && addr_size != 8)
1585 (*_bfd_error_handler) ("Dwarf Error: found address size '%u', this reader can only handle address sizes '2', '4' and '8'.", addr_size);
1586 bfd_set_error (bfd_error_bad_value);
1590 /* Read the abbrevs for this compilation unit into a table. */
1591 abbrevs = read_abbrevs (abfd, abbrev_offset, stash);
1595 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
1596 info_ptr += bytes_read;
1597 if (! abbrev_number)
1599 (*_bfd_error_handler) (_("Dwarf Error: Bad abbrev number: %u."),
1601 bfd_set_error (bfd_error_bad_value);
1605 abbrev = lookup_abbrev (abbrev_number, abbrevs);
1608 (*_bfd_error_handler) (_("Dwarf Error: Could not find abbrev number %u."),
1610 bfd_set_error (bfd_error_bad_value);
1614 amt = sizeof (struct comp_unit);
1615 unit = bfd_zalloc (abfd, amt);
1617 unit->addr_size = addr_size;
1618 unit->offset_size = offset_size;
1619 unit->abbrevs = abbrevs;
1620 unit->end_ptr = end_ptr;
1621 unit->stash = stash;
1622 unit->info_ptr_unit = info_ptr_unit;
1624 for (i = 0; i < abbrev->num_attrs; ++i)
1626 info_ptr = read_attribute (&attr, &abbrev->attrs[i], unit, info_ptr);
1628 /* Store the data if it is of an attribute we want to keep in a
1629 partial symbol table. */
1632 case DW_AT_stmt_list:
1634 unit->line_offset = attr.u.val;
1638 unit->name = attr.u.str;
1642 low_pc = attr.u.val;
1643 /* If the compilation unit DIE has a DW_AT_low_pc attribute,
1644 this is the base address to use when reading location
1645 lists or range lists. */
1646 unit->base_address = low_pc;
1650 high_pc = attr.u.val;
1654 read_rangelist (unit, &unit->arange, attr.u.val);
1657 case DW_AT_comp_dir:
1659 char *comp_dir = attr.u.str;
1662 /* Irix 6.2 native cc prepends <machine>.: to the compilation
1663 directory, get rid of it. */
1664 char *cp = strchr (comp_dir, ':');
1666 if (cp && cp != comp_dir && cp[-1] == '.' && cp[1] == '/')
1669 unit->comp_dir = comp_dir;
1679 arange_add (unit->abfd, &unit->arange, low_pc, high_pc);
1682 unit->first_child_die_ptr = info_ptr;
1686 /* Return TRUE if UNIT contains the address given by ADDR. */
1689 comp_unit_contains_address (struct comp_unit *unit, bfd_vma addr)
1691 struct arange *arange;
1696 arange = &unit->arange;
1699 if (addr >= arange->low && addr < arange->high)
1701 arange = arange->next;
1708 /* If UNIT contains ADDR, set the output parameters to the values for
1709 the line containing ADDR. The output parameters, FILENAME_PTR,
1710 FUNCTIONNAME_PTR, and LINENUMBER_PTR, are pointers to the objects
1713 Return TRUE if UNIT contains ADDR, and no errors were encountered;
1717 comp_unit_find_nearest_line (struct comp_unit *unit,
1719 const char **filename_ptr,
1720 const char **functionname_ptr,
1721 unsigned int *linenumber_ptr,
1722 struct dwarf2_debug *stash)
1726 struct funcinfo *function;
1731 if (! unit->line_table)
1733 if (! unit->stmtlist)
1739 unit->line_table = decode_line_info (unit, stash);
1741 if (! unit->line_table)
1747 if (unit->first_child_die_ptr < unit->end_ptr
1748 && ! scan_unit_for_functions (unit))
1756 func_p = lookup_address_in_function_table (unit->function_table, addr,
1757 &function, functionname_ptr);
1758 line_p = lookup_address_in_line_info_table (unit->line_table, addr,
1759 function, filename_ptr,
1761 return line_p || func_p;
1764 /* Locate a section in a BFD containing debugging info. The search starts
1765 from the section after AFTER_SEC, or from the first section in the BFD if
1766 AFTER_SEC is NULL. The search works by examining the names of the
1767 sections. There are two permissiable names. The first is .debug_info.
1768 This is the standard DWARF2 name. The second is a prefix .gnu.linkonce.wi.
1769 This is a variation on the .debug_info section which has a checksum
1770 describing the contents appended onto the name. This allows the linker to
1771 identify and discard duplicate debugging sections for different
1772 compilation units. */
1773 #define DWARF2_DEBUG_INFO ".debug_info"
1774 #define GNU_LINKONCE_INFO ".gnu.linkonce.wi."
1777 find_debug_info (bfd *abfd, asection *after_sec)
1782 msec = after_sec->next;
1784 msec = abfd->sections;
1788 if (strcmp (msec->name, DWARF2_DEBUG_INFO) == 0)
1791 if (strncmp (msec->name, GNU_LINKONCE_INFO, strlen (GNU_LINKONCE_INFO)) == 0)
1800 /* The DWARF2 version of find_nearest_line. Return TRUE if the line
1801 is found without error. ADDR_SIZE is the number of bytes in the
1802 initial .debug_info length field and in the abbreviation offset.
1803 You may use zero to indicate that the default value should be
1807 _bfd_dwarf2_find_nearest_line (bfd *abfd,
1811 const char **filename_ptr,
1812 const char **functionname_ptr,
1813 unsigned int *linenumber_ptr,
1814 unsigned int addr_size,
1817 /* Read each compilation unit from the section .debug_info, and check
1818 to see if it contains the address we are searching for. If yes,
1819 lookup the address, and return the line number info. If no, go
1820 on to the next compilation unit.
1822 We keep a list of all the previously read compilation units, and
1823 a pointer to the next un-read compilation unit. Check the
1824 previously read units before reading more. */
1825 struct dwarf2_debug *stash;
1827 /* What address are we looking for? */
1830 struct comp_unit* each;
1834 if (section->output_section)
1835 addr += section->output_section->vma + section->output_offset;
1837 addr += section->vma;
1838 *filename_ptr = NULL;
1839 *functionname_ptr = NULL;
1840 *linenumber_ptr = 0;
1842 /* The DWARF2 spec says that the initial length field, and the
1843 offset of the abbreviation table, should both be 4-byte values.
1844 However, some compilers do things differently. */
1847 BFD_ASSERT (addr_size == 4 || addr_size == 8);
1851 bfd_size_type total_size;
1853 bfd_size_type amt = sizeof (struct dwarf2_debug);
1855 stash = bfd_zalloc (abfd, amt);
1861 msec = find_debug_info (abfd, NULL);
1863 /* No dwarf2 info. Note that at this point the stash
1864 has been allocated, but contains zeros, this lets
1865 future calls to this function fail quicker. */
1868 /* There can be more than one DWARF2 info section in a BFD these days.
1869 Read them all in and produce one large stash. We do this in two
1870 passes - in the first pass we just accumulate the section sizes.
1871 In the second pass we read in the section's contents. The allows
1872 us to avoid reallocing the data as we add sections to the stash. */
1873 for (total_size = 0; msec; msec = find_debug_info (abfd, msec))
1874 total_size += msec->size;
1876 stash->info_ptr = bfd_alloc (abfd, total_size);
1877 if (stash->info_ptr == NULL)
1880 stash->info_ptr_end = stash->info_ptr;
1882 for (msec = find_debug_info (abfd, NULL);
1884 msec = find_debug_info (abfd, msec))
1887 bfd_size_type start;
1893 start = stash->info_ptr_end - stash->info_ptr;
1895 if ((bfd_simple_get_relocated_section_contents
1896 (abfd, msec, stash->info_ptr + start, symbols)) == NULL)
1899 stash->info_ptr_end = stash->info_ptr + start + size;
1902 BFD_ASSERT (stash->info_ptr_end == stash->info_ptr + total_size);
1904 stash->sec = find_debug_info (abfd, NULL);
1905 stash->sec_info_ptr = stash->info_ptr;
1906 stash->syms = symbols;
1909 /* A null info_ptr indicates that there is no dwarf2 info
1910 (or that an error occured while setting up the stash). */
1911 if (! stash->info_ptr)
1914 /* Check the previously read comp. units first. */
1915 for (each = stash->all_comp_units; each; each = each->next_unit)
1916 if (comp_unit_contains_address (each, addr))
1917 return comp_unit_find_nearest_line (each, addr, filename_ptr,
1918 functionname_ptr, linenumber_ptr,
1921 /* Read each remaining comp. units checking each as they are read. */
1922 while (stash->info_ptr < stash->info_ptr_end)
1926 unsigned int offset_size = addr_size;
1927 bfd_byte *info_ptr_unit = stash->info_ptr;
1929 length = read_4_bytes (abfd, stash->info_ptr);
1930 /* A 0xffffff length is the DWARF3 way of indicating we use
1931 64-bit offsets, instead of 32-bit offsets. */
1932 if (length == 0xffffffff)
1935 length = read_8_bytes (abfd, stash->info_ptr + 4);
1936 stash->info_ptr += 12;
1938 /* A zero length is the IRIX way of indicating 64-bit offsets,
1939 mostly because the 64-bit length will generally fit in 32
1940 bits, and the endianness helps. */
1941 else if (length == 0)
1944 length = read_4_bytes (abfd, stash->info_ptr + 4);
1945 stash->info_ptr += 8;
1947 /* In the absence of the hints above, we assume addr_size-sized
1948 offsets, for backward-compatibility with pre-DWARF3 64-bit
1950 else if (addr_size == 8)
1952 length = read_8_bytes (abfd, stash->info_ptr);
1953 stash->info_ptr += 8;
1956 stash->info_ptr += 4;
1960 each = parse_comp_unit (abfd, stash, length, info_ptr_unit,
1962 stash->info_ptr += length;
1964 if ((bfd_vma) (stash->info_ptr - stash->sec_info_ptr)
1965 == stash->sec->size)
1967 stash->sec = find_debug_info (abfd, stash->sec);
1968 stash->sec_info_ptr = stash->info_ptr;
1973 each->next_unit = stash->all_comp_units;
1974 stash->all_comp_units = each;
1976 /* DW_AT_low_pc and DW_AT_high_pc are optional for
1977 compilation units. If we don't have them (i.e.,
1978 unit->high == 0), we need to consult the line info
1979 table to see if a compilation unit contains the given
1981 if (each->arange.high > 0)
1983 if (comp_unit_contains_address (each, addr))
1984 return comp_unit_find_nearest_line (each, addr,
1992 found = comp_unit_find_nearest_line (each, addr,