2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
3 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;
71 /* Get at parts of an attribute structure. */
73 #define DW_STRING(attr) ((attr)->u.str)
74 #define DW_UNSND(attr) ((attr)->u.unsnd)
75 #define DW_BLOCK(attr) ((attr)->u.blk)
76 #define DW_SND(attr) ((attr)->u.snd)
77 #define DW_ADDR(attr) ((attr)->u.addr)
79 /* Blocks are a bunch of untyped bytes. */
88 /* A list of all previously read comp_units. */
89 struct comp_unit* all_comp_units;
91 /* The next unread compilation unit within the .debug_info section.
92 Zero indicates that the .debug_info section has not been loaded
96 /* Pointer to the end of the .debug_info section memory buffer. */
99 /* Pointer to the section and address of the beginning of the
104 /* Pointer to the symbol table. */
107 /* Pointer to the .debug_abbrev section loaded into memory. */
108 char* dwarf_abbrev_buffer;
110 /* Length of the loaded .debug_abbrev section. */
111 unsigned long dwarf_abbrev_size;
113 /* Buffer for decode_line_info. */
114 char *dwarf_line_buffer;
116 /* Length of the loaded .debug_line section. */
117 unsigned long dwarf_line_size;
119 /* Pointer to the .debug_str section loaded into memory. */
120 char* dwarf_str_buffer;
122 /* Length of the loaded .debug_str section. */
123 unsigned long dwarf_str_size;
133 /* A minimal decoding of DWARF2 compilation units. We only decode
134 what's needed to get to the line number information. */
138 /* Chain the previously read compilation units. */
139 struct comp_unit* next_unit;
141 /* Keep the bdf convenient (for memory allocation). */
144 /* The lowest and higest addresses contained in this compilation
145 unit as specified in the compilation unit header. */
146 struct arange arange;
148 /* The DW_AT_name attribute (for error messages). */
151 /* The abbrev hash table. */
152 struct abbrev_info** abbrevs;
154 /* Note that an error was found by comp_unit_find_nearest_line. */
157 /* The DW_AT_comp_dir attribute. */
160 /* True if there is a line number table associated with this comp. unit. */
163 /* The offset into .debug_line of the line number table. */
164 unsigned long line_offset;
166 /* Pointer to the first child die for the comp unit. */
167 char *first_child_die_ptr;
169 /* The end of the comp unit. */
172 /* The decoded line number, NULL if not yet decoded. */
173 struct line_info_table* line_table;
175 /* A list of the functions found in this comp. unit. */
176 struct funcinfo* function_table;
178 /* Pointer to dwarf2_debug structure. */
179 struct dwarf2_debug *stash;
181 /* Address size for this unit - from unit header. */
182 unsigned char addr_size;
184 /* Offset size for this unit - from unit header. */
185 unsigned char offset_size;
188 /* This data structure holds the information of an abbrev. */
191 unsigned int number; /* Number identifying abbrev. */
192 enum dwarf_tag tag; /* DWARF tag. */
193 int has_children; /* Boolean. */
194 unsigned int num_attrs; /* Number of attributes. */
195 struct attr_abbrev *attrs; /* An array of attribute descriptions. */
196 struct abbrev_info *next; /* Next in chain. */
201 enum dwarf_attribute name;
202 enum dwarf_form form;
205 #ifndef ABBREV_HASH_SIZE
206 #define ABBREV_HASH_SIZE 121
208 #ifndef ATTR_ALLOC_CHUNK
209 #define ATTR_ALLOC_CHUNK 4
212 static unsigned int read_1_byte PARAMS ((bfd *, char *));
213 static int read_1_signed_byte PARAMS ((bfd *, char *));
214 static unsigned int read_2_bytes PARAMS ((bfd *, char *));
215 static unsigned int read_4_bytes PARAMS ((bfd *, char *));
216 static bfd_vma read_8_bytes PARAMS ((bfd *, char *));
217 static char *read_n_bytes PARAMS ((bfd *, char *, unsigned int));
218 static char *read_string PARAMS ((bfd *, char *, unsigned int *));
219 static char *read_indirect_string PARAMS ((struct comp_unit *, char *, unsigned int *));
220 static unsigned int read_unsigned_leb128
221 PARAMS ((bfd *, char *, unsigned int *));
222 static int read_signed_leb128
223 PARAMS ((bfd *, char *, unsigned int *));
224 static bfd_vma read_address PARAMS ((struct comp_unit *, char *));
225 static struct abbrev_info *lookup_abbrev
226 PARAMS ((unsigned int, struct abbrev_info **));
227 static struct abbrev_info **read_abbrevs
228 PARAMS ((bfd *, bfd_vma, struct dwarf2_debug *));
229 static char *read_attribute
230 PARAMS ((struct attribute *, struct attr_abbrev *,
231 struct comp_unit *, char *));
232 static char *read_attribute_value
233 PARAMS ((struct attribute *, unsigned,
234 struct comp_unit *, char *));
235 static void add_line_info
236 PARAMS ((struct line_info_table *, bfd_vma, char *,
237 unsigned int, unsigned int, int));
238 static char *concat_filename PARAMS ((struct line_info_table *, unsigned int));
239 static void arange_add PARAMS ((struct comp_unit *, bfd_vma, bfd_vma));
240 static struct line_info_table *decode_line_info
241 PARAMS ((struct comp_unit *, struct dwarf2_debug *));
242 static boolean lookup_address_in_line_info_table
243 PARAMS ((struct line_info_table *, bfd_vma, struct funcinfo *,
244 const char **, unsigned int *));
245 static boolean lookup_address_in_function_table
246 PARAMS ((struct funcinfo *, bfd_vma, struct funcinfo **, const char **));
247 static boolean scan_unit_for_functions PARAMS ((struct comp_unit *));
248 static bfd_vma find_rela_addend
249 PARAMS ((bfd *, asection *, bfd_size_type, asymbol**));
250 static struct comp_unit *parse_comp_unit
251 PARAMS ((bfd *, struct dwarf2_debug *, bfd_vma, unsigned int));
252 static boolean comp_unit_contains_address
253 PARAMS ((struct comp_unit *, bfd_vma));
254 static boolean comp_unit_find_nearest_line
255 PARAMS ((struct comp_unit *, bfd_vma, const char **, const char **,
256 unsigned int *, struct dwarf2_debug *));
257 static asection *find_debug_info PARAMS ((bfd *, asection *));
260 The following function up to the END VERBATIM mark are
261 copied directly from dwarf2read.c. */
263 /* Read dwarf information from a buffer. */
266 read_1_byte (abfd, buf)
267 bfd *abfd ATTRIBUTE_UNUSED;
270 return bfd_get_8 (abfd, (bfd_byte *) buf);
274 read_1_signed_byte (abfd, buf)
275 bfd *abfd ATTRIBUTE_UNUSED;
278 return bfd_get_signed_8 (abfd, (bfd_byte *) buf);
282 read_2_bytes (abfd, buf)
286 return bfd_get_16 (abfd, (bfd_byte *) buf);
289 #if 0 /* This is not used. */
292 read_2_signed_bytes (abfd, buf)
296 return bfd_get_signed_16 (abfd, (bfd_byte *) buf);
302 read_4_bytes (abfd, buf)
306 return bfd_get_32 (abfd, (bfd_byte *) buf);
309 #if 0 /* This is not used. */
312 read_4_signed_bytes (abfd, buf)
316 return bfd_get_signed_32 (abfd, (bfd_byte *) buf);
322 read_8_bytes (abfd, buf)
326 return bfd_get_64 (abfd, (bfd_byte *) buf);
330 read_n_bytes (abfd, buf, size)
331 bfd *abfd ATTRIBUTE_UNUSED;
333 unsigned int size ATTRIBUTE_UNUSED;
335 /* If the size of a host char is 8 bits, we can return a pointer
336 to the buffer, otherwise we have to copy the data to a buffer
337 allocated on the temporary obstack. */
342 read_string (abfd, buf, bytes_read_ptr)
343 bfd *abfd ATTRIBUTE_UNUSED;
345 unsigned int *bytes_read_ptr;
347 /* Return a pointer to the embedded string. */
354 *bytes_read_ptr = strlen (buf) + 1;
359 read_indirect_string (unit, buf, bytes_read_ptr)
360 struct comp_unit* unit;
362 unsigned int *bytes_read_ptr;
365 struct dwarf2_debug *stash = unit->stash;
367 if (unit->offset_size == 4)
368 offset = read_4_bytes (unit->abfd, buf);
370 offset = read_8_bytes (unit->abfd, buf);
371 *bytes_read_ptr = unit->offset_size;
373 if (! stash->dwarf_str_buffer)
376 bfd *abfd = unit->abfd;
378 msec = bfd_get_section_by_name (abfd, ".debug_str");
381 (*_bfd_error_handler)
382 (_("Dwarf Error: Can't find .debug_str section."));
383 bfd_set_error (bfd_error_bad_value);
387 stash->dwarf_str_size = msec->_raw_size;
388 stash->dwarf_str_buffer = (char*) bfd_alloc (abfd, msec->_raw_size);
389 if (! stash->dwarf_abbrev_buffer)
392 if (! bfd_get_section_contents (abfd, msec, stash->dwarf_str_buffer,
393 (bfd_vma) 0, msec->_raw_size))
397 if (offset >= stash->dwarf_str_size)
399 (*_bfd_error_handler) (_("Dwarf Error: DW_FORM_strp offset (%lu) greater than or equal to .debug_str size (%lu)."),
400 (unsigned long) offset, stash->dwarf_str_size);
401 bfd_set_error (bfd_error_bad_value);
405 buf = stash->dwarf_str_buffer + offset;
412 read_unsigned_leb128 (abfd, buf, bytes_read_ptr)
413 bfd *abfd ATTRIBUTE_UNUSED;
415 unsigned int *bytes_read_ptr;
418 unsigned int num_read;
428 byte = bfd_get_8 (abfd, (bfd_byte *) buf);
431 result |= ((byte & 0x7f) << shift);
436 * bytes_read_ptr = num_read;
442 read_signed_leb128 (abfd, buf, bytes_read_ptr)
443 bfd *abfd ATTRIBUTE_UNUSED;
445 unsigned int * bytes_read_ptr;
458 byte = bfd_get_8 (abfd, (bfd_byte *) buf);
461 result |= ((byte & 0x7f) << shift);
466 if ((shift < 32) && (byte & 0x40))
467 result |= -(1 << shift);
469 * bytes_read_ptr = num_read;
477 read_address (unit, buf)
478 struct comp_unit* unit;
481 switch (unit->addr_size)
484 return bfd_get_64 (unit->abfd, (bfd_byte *) buf);
486 return bfd_get_32 (unit->abfd, (bfd_byte *) buf);
488 return bfd_get_16 (unit->abfd, (bfd_byte *) buf);
494 /* Lookup an abbrev_info structure in the abbrev hash table. */
496 static struct abbrev_info *
497 lookup_abbrev (number,abbrevs)
499 struct abbrev_info **abbrevs;
501 unsigned int hash_number;
502 struct abbrev_info *abbrev;
504 hash_number = number % ABBREV_HASH_SIZE;
505 abbrev = abbrevs[hash_number];
509 if (abbrev->number == number)
512 abbrev = abbrev->next;
518 /* In DWARF version 2, the description of the debugging information is
519 stored in a separate .debug_abbrev section. Before we read any
520 dies from a section we read in all abbreviations and install them
523 static struct abbrev_info**
524 read_abbrevs (abfd, offset, stash)
527 struct dwarf2_debug *stash;
529 struct abbrev_info **abbrevs;
531 struct abbrev_info *cur_abbrev;
532 unsigned int abbrev_number, bytes_read, abbrev_name;
533 unsigned int abbrev_form, hash_number;
536 if (! stash->dwarf_abbrev_buffer)
540 msec = bfd_get_section_by_name (abfd, ".debug_abbrev");
543 (*_bfd_error_handler) (_("Dwarf Error: Can't find .debug_abbrev section."));
544 bfd_set_error (bfd_error_bad_value);
548 stash->dwarf_abbrev_size = msec->_raw_size;
549 stash->dwarf_abbrev_buffer = (char*) bfd_alloc (abfd, msec->_raw_size);
550 if (! stash->dwarf_abbrev_buffer)
553 if (! bfd_get_section_contents (abfd, msec, stash->dwarf_abbrev_buffer,
554 (bfd_vma) 0, msec->_raw_size))
558 if (offset >= stash->dwarf_abbrev_size)
560 (*_bfd_error_handler) (_("Dwarf Error: Abbrev offset (%lu) greater than or equal to .debug_abbrev size (%lu)."),
561 (unsigned long) offset, stash->dwarf_abbrev_size);
562 bfd_set_error (bfd_error_bad_value);
566 amt = sizeof (struct abbrev_info*) * ABBREV_HASH_SIZE;
567 abbrevs = (struct abbrev_info**) bfd_zalloc (abfd, amt);
569 abbrev_ptr = stash->dwarf_abbrev_buffer + offset;
570 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
571 abbrev_ptr += bytes_read;
573 /* Loop until we reach an abbrev number of 0. */
574 while (abbrev_number)
576 amt = sizeof (struct abbrev_info);
577 cur_abbrev = (struct abbrev_info *) bfd_zalloc (abfd, amt);
579 /* Read in abbrev header. */
580 cur_abbrev->number = abbrev_number;
581 cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
582 abbrev_ptr += bytes_read;
583 cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr);
586 /* Now read in declarations. */
587 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
588 abbrev_ptr += bytes_read;
589 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
590 abbrev_ptr += bytes_read;
594 if ((cur_abbrev->num_attrs % ATTR_ALLOC_CHUNK) == 0)
596 amt = cur_abbrev->num_attrs + ATTR_ALLOC_CHUNK;
597 amt *= sizeof (struct attr_abbrev);
598 cur_abbrev->attrs = ((struct attr_abbrev *)
599 bfd_realloc (cur_abbrev->attrs, amt));
600 if (! cur_abbrev->attrs)
604 cur_abbrev->attrs[cur_abbrev->num_attrs].name = abbrev_name;
605 cur_abbrev->attrs[cur_abbrev->num_attrs++].form = abbrev_form;
606 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
607 abbrev_ptr += bytes_read;
608 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
609 abbrev_ptr += bytes_read;
612 hash_number = abbrev_number % ABBREV_HASH_SIZE;
613 cur_abbrev->next = abbrevs[hash_number];
614 abbrevs[hash_number] = cur_abbrev;
616 /* Get next abbreviation.
617 Under Irix6 the abbreviations for a compilation unit are not
618 always properly terminated with an abbrev number of 0.
619 Exit loop if we encounter an abbreviation which we have
620 already read (which means we are about to read the abbreviations
621 for the next compile unit) or if the end of the abbreviation
623 if ((unsigned int) (abbrev_ptr - stash->dwarf_abbrev_buffer)
624 >= stash->dwarf_abbrev_size)
626 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
627 abbrev_ptr += bytes_read;
628 if (lookup_abbrev (abbrev_number,abbrevs) != NULL)
635 /* Read an attribute value described by an attribute form. */
638 read_attribute_value (attr, form, unit, info_ptr)
639 struct attribute *attr;
641 struct comp_unit *unit;
644 bfd *abfd = unit->abfd;
645 unsigned int bytes_read;
646 struct dwarf_block *blk;
654 /* FIXME: DWARF3 draft sais DW_FORM_ref_addr is offset_size. */
655 case DW_FORM_ref_addr:
656 DW_ADDR (attr) = read_address (unit, info_ptr);
657 info_ptr += unit->addr_size;
660 amt = sizeof (struct dwarf_block);
661 blk = (struct dwarf_block *) bfd_alloc (abfd, amt);
662 blk->size = read_2_bytes (abfd, info_ptr);
664 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
665 info_ptr += blk->size;
666 DW_BLOCK (attr) = blk;
669 amt = sizeof (struct dwarf_block);
670 blk = (struct dwarf_block *) bfd_alloc (abfd, amt);
671 blk->size = read_4_bytes (abfd, info_ptr);
673 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
674 info_ptr += blk->size;
675 DW_BLOCK (attr) = blk;
678 DW_UNSND (attr) = read_2_bytes (abfd, info_ptr);
682 DW_UNSND (attr) = read_4_bytes (abfd, info_ptr);
686 DW_UNSND (attr) = read_8_bytes (abfd, info_ptr);
690 DW_STRING (attr) = read_string (abfd, info_ptr, &bytes_read);
691 info_ptr += bytes_read;
694 DW_STRING (attr) = read_indirect_string (unit, info_ptr, &bytes_read);
695 info_ptr += bytes_read;
698 amt = sizeof (struct dwarf_block);
699 blk = (struct dwarf_block *) bfd_alloc (abfd, amt);
700 blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
701 info_ptr += bytes_read;
702 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
703 info_ptr += blk->size;
704 DW_BLOCK (attr) = blk;
707 amt = sizeof (struct dwarf_block);
708 blk = (struct dwarf_block *) bfd_alloc (abfd, amt);
709 blk->size = read_1_byte (abfd, info_ptr);
711 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
712 info_ptr += blk->size;
713 DW_BLOCK (attr) = blk;
716 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
720 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
724 DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read);
725 info_ptr += bytes_read;
728 DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
729 info_ptr += bytes_read;
732 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
736 DW_UNSND (attr) = read_2_bytes (abfd, info_ptr);
740 DW_UNSND (attr) = read_4_bytes (abfd, info_ptr);
744 DW_UNSND (attr) = read_8_bytes (abfd, info_ptr);
747 case DW_FORM_ref_udata:
748 DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
749 info_ptr += bytes_read;
751 case DW_FORM_indirect:
752 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
753 info_ptr += bytes_read;
754 info_ptr = read_attribute_value (attr, form, unit, info_ptr);
757 (*_bfd_error_handler) (_("Dwarf Error: Invalid or unhandled FORM value: %u."),
759 bfd_set_error (bfd_error_bad_value);
764 /* Read an attribute described by an abbreviated attribute. */
767 read_attribute (attr, abbrev, unit, info_ptr)
768 struct attribute *attr;
769 struct attr_abbrev *abbrev;
770 struct comp_unit *unit;
773 attr->name = abbrev->name;
774 info_ptr = read_attribute_value (attr, abbrev->form, unit, info_ptr);
778 /* Source line information table routines. */
780 #define FILE_ALLOC_CHUNK 5
781 #define DIR_ALLOC_CHUNK 5
785 struct line_info* prev_line;
790 int end_sequence; /* End of (sequential) code sequence. */
801 struct line_info_table
804 unsigned int num_files;
805 unsigned int num_dirs;
808 struct fileinfo* files;
809 struct line_info* last_line;
814 struct funcinfo *prev_func;
821 add_line_info (table, address, filename, line, column, end_sequence)
822 struct line_info_table* table;
829 bfd_size_type amt = sizeof (struct line_info);
830 struct line_info* info = (struct line_info*) bfd_alloc (table->abfd, amt);
832 info->prev_line = table->last_line;
833 table->last_line = info;
835 info->address = address;
836 info->filename = filename;
838 info->column = column;
839 info->end_sequence = end_sequence;
843 concat_filename (table, file)
844 struct line_info_table* table;
849 if (file - 1 >= table->num_files)
851 (*_bfd_error_handler)
852 (_("Dwarf Error: mangled line number section (bad file number)."));
856 filename = table->files[file - 1].name;
857 if (IS_ABSOLUTE_PATH(filename))
861 char* dirname = (table->files[file - 1].dir
862 ? table->dirs[table->files[file - 1].dir - 1]
865 /* Not all tools set DW_AT_comp_dir, so dirname may be unknown. The
866 best we can do is return the filename part. */
870 return (char*) concat (dirname, "/", filename, NULL);
875 arange_add (unit, low_pc, high_pc)
876 struct comp_unit *unit;
880 struct arange *arange;
882 /* First see if we can cheaply extend an existing range. */
883 arange = &unit->arange;
887 if (low_pc == arange->high)
889 arange->high = high_pc;
892 if (high_pc == arange->low)
894 arange->low = low_pc;
897 arange = arange->next;
901 if (unit->arange.high == 0)
903 /* This is the first address range: store it in unit->arange. */
904 unit->arange.next = 0;
905 unit->arange.low = low_pc;
906 unit->arange.high = high_pc;
910 /* Need to allocate a new arange and insert it into the arange list. */
911 arange = bfd_zalloc (unit->abfd, (bfd_size_type) sizeof (*arange));
912 arange->low = low_pc;
913 arange->high = high_pc;
915 arange->next = unit->arange.next;
916 unit->arange.next = arange;
919 /* Decode the line number information for UNIT. */
921 static struct line_info_table*
922 decode_line_info (unit, stash)
923 struct comp_unit *unit;
924 struct dwarf2_debug *stash;
926 bfd *abfd = unit->abfd;
927 struct line_info_table* table;
931 unsigned int i, bytes_read, offset_size;
932 char *cur_file, *cur_dir;
933 unsigned char op_code, extended_op, adj_opcode;
936 if (! stash->dwarf_line_buffer)
940 msec = bfd_get_section_by_name (abfd, ".debug_line");
943 (*_bfd_error_handler) (_("Dwarf Error: Can't find .debug_line section."));
944 bfd_set_error (bfd_error_bad_value);
948 stash->dwarf_line_size = msec->_raw_size;
949 stash->dwarf_line_buffer = (char *) bfd_alloc (abfd, msec->_raw_size);
950 if (! stash->dwarf_line_buffer)
953 if (! bfd_get_section_contents (abfd, msec, stash->dwarf_line_buffer,
954 (bfd_vma) 0, msec->_raw_size))
957 /* FIXME: We ought to apply the relocs against this section before
961 /* Since we are using un-relocated data, it is possible to get a bad value
962 for the line_offset. Validate it here so that we won't get a segfault
964 if (unit->line_offset >= stash->dwarf_line_size)
966 (*_bfd_error_handler) (_("Dwarf Error: Line offset (%lu) greater than or equal to .debug_line size (%lu)."),
967 unit->line_offset, stash->dwarf_line_size);
968 bfd_set_error (bfd_error_bad_value);
972 amt = sizeof (struct line_info_table);
973 table = (struct line_info_table*) bfd_alloc (abfd, amt);
975 table->comp_dir = unit->comp_dir;
977 table->num_files = 0;
984 table->last_line = NULL;
986 line_ptr = stash->dwarf_line_buffer + unit->line_offset;
988 /* Read in the prologue. */
989 lh.total_length = read_4_bytes (abfd, line_ptr);
992 if (lh.total_length == 0xffffffff)
994 lh.total_length = read_8_bytes (abfd, line_ptr);
998 else if (lh.total_length == 0 && unit->addr_size == 8)
1000 /* Handle (non-standard) 64-bit DWARF2 formats. */
1001 lh.total_length = read_4_bytes (abfd, line_ptr);
1005 line_end = line_ptr + lh.total_length;
1006 lh.version = read_2_bytes (abfd, line_ptr);
1008 if (offset_size == 4)
1009 lh.prologue_length = read_4_bytes (abfd, line_ptr);
1011 lh.prologue_length = read_8_bytes (abfd, line_ptr);
1012 line_ptr += offset_size;
1013 lh.minimum_instruction_length = read_1_byte (abfd, line_ptr);
1015 lh.default_is_stmt = read_1_byte (abfd, line_ptr);
1017 lh.line_base = read_1_signed_byte (abfd, line_ptr);
1019 lh.line_range = read_1_byte (abfd, line_ptr);
1021 lh.opcode_base = read_1_byte (abfd, line_ptr);
1023 amt = lh.opcode_base * sizeof (unsigned char);
1024 lh.standard_opcode_lengths = (unsigned char *) bfd_alloc (abfd, amt);
1026 lh.standard_opcode_lengths[0] = 1;
1028 for (i = 1; i < lh.opcode_base; ++i)
1030 lh.standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr);
1034 /* Read directory table. */
1035 while ((cur_dir = read_string (abfd, line_ptr, &bytes_read)) != NULL)
1037 line_ptr += bytes_read;
1039 if ((table->num_dirs % DIR_ALLOC_CHUNK) == 0)
1041 amt = table->num_dirs + DIR_ALLOC_CHUNK;
1042 amt *= sizeof (char *);
1043 table->dirs = (char **) bfd_realloc (table->dirs, amt);
1048 table->dirs[table->num_dirs++] = cur_dir;
1051 line_ptr += bytes_read;
1053 /* Read file name table. */
1054 while ((cur_file = read_string (abfd, line_ptr, &bytes_read)) != NULL)
1056 line_ptr += bytes_read;
1058 if ((table->num_files % FILE_ALLOC_CHUNK) == 0)
1060 amt = table->num_files + FILE_ALLOC_CHUNK;
1061 amt *= sizeof (struct fileinfo);
1062 table->files = (struct fileinfo *) bfd_realloc (table->files, amt);
1067 table->files[table->num_files].name = cur_file;
1068 table->files[table->num_files].dir =
1069 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
1070 line_ptr += bytes_read;
1071 table->files[table->num_files].time =
1072 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
1073 line_ptr += bytes_read;
1074 table->files[table->num_files].size =
1075 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
1076 line_ptr += bytes_read;
1080 line_ptr += bytes_read;
1082 /* Read the statement sequences until there's nothing left. */
1083 while (line_ptr < line_end)
1085 /* State machine registers. */
1086 bfd_vma address = 0;
1087 char * filename = concat_filename (table, 1);
1088 unsigned int line = 1;
1089 unsigned int column = 0;
1090 int is_stmt = lh.default_is_stmt;
1091 int basic_block = 0;
1092 int end_sequence = 0;
1093 /* eraxxon@alumni.rice.edu: Against the DWARF2 specs, some
1094 compilers generate address sequences that are wildly out of
1095 order using DW_LNE_set_address (e.g. Intel C++ 6.0 compiler
1096 for ia64-Linux). Thus, to determine the low and high
1097 address, we must compare on every DW_LNS_copy, etc. */
1099 bfd_vma high_pc = 0;
1101 /* Decode the table. */
1102 while (! end_sequence)
1104 op_code = read_1_byte (abfd, line_ptr);
1107 if (op_code >= lh.opcode_base)
1109 /* Special operand. */
1110 adj_opcode = op_code - lh.opcode_base;
1111 address += (adj_opcode / lh.line_range)
1112 * lh.minimum_instruction_length;
1113 line += lh.line_base + (adj_opcode % lh.line_range);
1114 /* Append row to matrix using current values. */
1115 add_line_info (table, address, filename, line, column, 0);
1117 if (low_pc == 0 || address < low_pc)
1119 if (address > high_pc)
1122 else switch (op_code)
1124 case DW_LNS_extended_op:
1125 /* Ignore length. */
1127 extended_op = read_1_byte (abfd, line_ptr);
1130 switch (extended_op)
1132 case DW_LNE_end_sequence:
1134 add_line_info (table, address, filename, line, column,
1136 arange_add (unit, low_pc, high_pc);
1137 if (low_pc == 0 || address < low_pc)
1139 if (address > high_pc)
1141 arange_add (unit, low_pc, address);
1143 case DW_LNE_set_address:
1144 address = read_address (unit, line_ptr);
1145 line_ptr += unit->addr_size;
1147 case DW_LNE_define_file:
1148 cur_file = read_string (abfd, line_ptr, &bytes_read);
1149 line_ptr += bytes_read;
1150 if ((table->num_files % FILE_ALLOC_CHUNK) == 0)
1152 amt = table->num_files + FILE_ALLOC_CHUNK;
1153 amt *= sizeof (struct fileinfo);
1155 (struct fileinfo *) bfd_realloc (table->files, amt);
1159 table->files[table->num_files].name = cur_file;
1160 table->files[table->num_files].dir =
1161 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
1162 line_ptr += bytes_read;
1163 table->files[table->num_files].time =
1164 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
1165 line_ptr += bytes_read;
1166 table->files[table->num_files].size =
1167 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
1168 line_ptr += bytes_read;
1172 (*_bfd_error_handler) (_("Dwarf Error: mangled line number section."));
1173 bfd_set_error (bfd_error_bad_value);
1178 add_line_info (table, address, filename, line, column, 0);
1180 if (low_pc == 0 || address < low_pc)
1182 if (address > high_pc)
1185 case DW_LNS_advance_pc:
1186 address += lh.minimum_instruction_length
1187 * read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
1188 line_ptr += bytes_read;
1190 case DW_LNS_advance_line:
1191 line += read_signed_leb128 (abfd, line_ptr, &bytes_read);
1192 line_ptr += bytes_read;
1194 case DW_LNS_set_file:
1198 /* The file and directory tables are 0
1199 based, the references are 1 based. */
1200 file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
1201 line_ptr += bytes_read;
1202 filename = concat_filename (table, file);
1205 case DW_LNS_set_column:
1206 column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
1207 line_ptr += bytes_read;
1209 case DW_LNS_negate_stmt:
1210 is_stmt = (!is_stmt);
1212 case DW_LNS_set_basic_block:
1215 case DW_LNS_const_add_pc:
1216 address += lh.minimum_instruction_length
1217 * ((255 - lh.opcode_base) / lh.line_range);
1219 case DW_LNS_fixed_advance_pc:
1220 address += read_2_bytes (abfd, line_ptr);
1226 /* Unknown standard opcode, ignore it. */
1227 for (i = 0; i < lh.standard_opcode_lengths[op_code]; i++)
1229 (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
1230 line_ptr += bytes_read;
1240 /* If ADDR is within TABLE set the output parameters and return true,
1241 otherwise return false. The output parameters, FILENAME_PTR and
1242 LINENUMBER_PTR, are pointers to the objects to be filled in. */
1245 lookup_address_in_line_info_table (table, addr, function, filename_ptr,
1247 struct line_info_table* table;
1249 struct funcinfo *function;
1250 const char **filename_ptr;
1251 unsigned int *linenumber_ptr;
1253 struct line_info* next_line = table->last_line;
1254 struct line_info* each_line;
1259 each_line = next_line->prev_line;
1261 while (each_line && next_line)
1263 if (!each_line->end_sequence
1264 && addr >= each_line->address && addr < next_line->address)
1266 /* If this line appears to span functions, and addr is in the
1267 later function, return the first line of that function instead
1268 of the last line of the earlier one. This check is for GCC
1269 2.95, which emits the first line number for a function late. */
1270 if (function != NULL
1271 && each_line->address < function->low
1272 && next_line->address > function->low)
1274 *filename_ptr = next_line->filename;
1275 *linenumber_ptr = next_line->line;
1279 *filename_ptr = each_line->filename;
1280 *linenumber_ptr = each_line->line;
1284 next_line = each_line;
1285 each_line = each_line->prev_line;
1288 /* At this point each_line is NULL but next_line is not. If we found the
1289 containing function in this compilation unit, return the first line we
1290 have a number for. This is also for compatibility with GCC 2.95. */
1291 if (function != NULL)
1293 *filename_ptr = next_line->filename;
1294 *linenumber_ptr = next_line->line;
1301 /* Function table functions. */
1303 /* If ADDR is within TABLE, set FUNCTIONNAME_PTR, and return true. */
1306 lookup_address_in_function_table (table, addr, function_ptr,
1308 struct funcinfo* table;
1310 struct funcinfo** function_ptr;
1311 const char **functionname_ptr;
1313 struct funcinfo* each_func;
1315 for (each_func = table;
1317 each_func = each_func->prev_func)
1319 if (addr >= each_func->low && addr < each_func->high)
1321 *functionname_ptr = each_func->name;
1322 *function_ptr = each_func;
1330 /* DWARF2 Compilation unit functions. */
1332 /* Scan over each die in a comp. unit looking for functions to add
1333 to the function table. */
1336 scan_unit_for_functions (unit)
1337 struct comp_unit *unit;
1339 bfd *abfd = unit->abfd;
1340 char *info_ptr = unit->first_child_die_ptr;
1341 int nesting_level = 1;
1343 while (nesting_level)
1345 unsigned int abbrev_number, bytes_read, i;
1346 struct abbrev_info *abbrev;
1347 struct attribute attr;
1348 struct funcinfo *func;
1351 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
1352 info_ptr += bytes_read;
1354 if (! abbrev_number)
1360 abbrev = lookup_abbrev (abbrev_number,unit->abbrevs);
1363 (*_bfd_error_handler) (_("Dwarf Error: Could not find abbrev number %u."),
1365 bfd_set_error (bfd_error_bad_value);
1369 if (abbrev->tag == DW_TAG_subprogram)
1371 bfd_size_type amt = sizeof (struct funcinfo);
1372 func = (struct funcinfo *) bfd_zalloc (abfd, amt);
1373 func->prev_func = unit->function_table;
1374 unit->function_table = func;
1379 for (i = 0; i < abbrev->num_attrs; ++i)
1381 info_ptr = read_attribute (&attr, &abbrev->attrs[i], unit, info_ptr);
1389 name = DW_STRING (&attr);
1391 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
1392 if (func->name == NULL)
1393 func->name = DW_STRING (&attr);
1396 case DW_AT_MIPS_linkage_name:
1397 func->name = DW_STRING (&attr);
1401 func->low = DW_ADDR (&attr);
1405 func->high = DW_ADDR (&attr);
1417 name = DW_STRING (&attr);
1426 if (abbrev->has_children)
1433 /* Look for a RELA relocation to be applied on OFFSET of section SEC,
1434 and return the addend if such a relocation is found. Since this is
1435 only used to find relocations referring to the .debug_abbrev
1436 section, we make sure the relocation refers to this section, but
1437 this is not strictly necessary, and it can probably be safely
1438 removed if needed. However, it is important to note that this
1439 function only returns the addend, it doesn't serve the purpose of
1440 applying a generic relocation.
1442 If no suitable relocation is found, or if it is not a real RELA
1443 relocation, this function returns 0. */
1446 find_rela_addend (abfd, sec, offset, syms)
1449 bfd_size_type offset;
1452 long reloc_size = bfd_get_reloc_upper_bound (abfd, sec);
1453 arelent **relocs = NULL;
1454 long reloc_count, relc;
1456 if (reloc_size <= 0)
1459 relocs = (arelent **) bfd_malloc ((bfd_size_type) reloc_size);
1463 reloc_count = bfd_canonicalize_reloc (abfd, sec, relocs, syms);
1465 if (reloc_count <= 0)
1471 for (relc = 0; relc < reloc_count; relc++)
1472 if (relocs[relc]->address == offset
1473 && (*relocs[relc]->sym_ptr_ptr)->flags & BSF_SECTION_SYM
1474 && strcmp ((*relocs[relc]->sym_ptr_ptr)->name,
1475 ".debug_abbrev") == 0)
1477 bfd_vma addend = (relocs[relc]->howto->partial_inplace
1478 ? 0 : relocs[relc]->addend);
1487 /* Parse a DWARF2 compilation unit starting at INFO_PTR. This
1488 includes the compilation unit header that proceeds the DIE's, but
1489 does not include the length field that preceeds each compilation
1490 unit header. END_PTR points one past the end of this comp unit.
1491 OFFSET_SIZE is the size of DWARF2 offsets (either 4 or 8 bytes).
1493 This routine does not read the whole compilation unit; only enough
1494 to get to the line number information for the compilation unit. */
1496 static struct comp_unit *
1497 parse_comp_unit (abfd, stash, unit_length, offset_size)
1499 struct dwarf2_debug *stash;
1500 bfd_vma unit_length;
1501 unsigned int offset_size;
1503 struct comp_unit* unit;
1504 unsigned int version;
1505 bfd_vma abbrev_offset = 0;
1506 unsigned int addr_size;
1507 struct abbrev_info** abbrevs;
1508 unsigned int abbrev_number, bytes_read, i;
1509 struct abbrev_info *abbrev;
1510 struct attribute attr;
1511 char *info_ptr = stash->info_ptr;
1512 char *end_ptr = info_ptr + unit_length;
1516 version = read_2_bytes (abfd, info_ptr);
1518 BFD_ASSERT (offset_size == 4 || offset_size == 8);
1519 if (offset_size == 4)
1520 abbrev_offset = read_4_bytes (abfd, info_ptr);
1522 abbrev_offset = read_8_bytes (abfd, info_ptr);
1523 /* The abbrev offset is generally a relocation pointing to
1524 .debug_abbrev+offset. On RELA targets, we have to find the
1525 relocation and extract the addend to obtain the actual
1526 abbrev_offset, so do it here. */
1527 off = info_ptr - stash->sec_info_ptr;
1528 abbrev_offset += find_rela_addend (abfd, stash->sec, off, stash->syms);
1529 info_ptr += offset_size;
1530 addr_size = read_1_byte (abfd, info_ptr);
1535 (*_bfd_error_handler) (_("Dwarf Error: found dwarf version '%u', this reader only handles version 2 information."), version);
1536 bfd_set_error (bfd_error_bad_value);
1540 if (addr_size > sizeof (bfd_vma))
1542 (*_bfd_error_handler) (_("Dwarf Error: found address size '%u', this reader can not handle sizes greater than '%u'."),
1544 (unsigned int) sizeof (bfd_vma));
1545 bfd_set_error (bfd_error_bad_value);
1549 if (addr_size != 2 && addr_size != 4 && addr_size != 8)
1551 (*_bfd_error_handler) ("Dwarf Error: found address size '%u', this reader can only handle address sizes '2', '4' and '8'.", addr_size);
1552 bfd_set_error (bfd_error_bad_value);
1556 /* Read the abbrevs for this compilation unit into a table. */
1557 abbrevs = read_abbrevs (abfd, abbrev_offset, stash);
1561 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
1562 info_ptr += bytes_read;
1563 if (! abbrev_number)
1565 (*_bfd_error_handler) (_("Dwarf Error: Bad abbrev number: %u."),
1567 bfd_set_error (bfd_error_bad_value);
1571 abbrev = lookup_abbrev (abbrev_number, abbrevs);
1574 (*_bfd_error_handler) (_("Dwarf Error: Could not find abbrev number %u."),
1576 bfd_set_error (bfd_error_bad_value);
1580 amt = sizeof (struct comp_unit);
1581 unit = (struct comp_unit*) bfd_zalloc (abfd, amt);
1583 unit->addr_size = addr_size;
1584 unit->offset_size = offset_size;
1585 unit->abbrevs = abbrevs;
1586 unit->end_ptr = end_ptr;
1587 unit->stash = stash;
1589 for (i = 0; i < abbrev->num_attrs; ++i)
1591 info_ptr = read_attribute (&attr, &abbrev->attrs[i], unit, info_ptr);
1593 /* Store the data if it is of an attribute we want to keep in a
1594 partial symbol table. */
1597 case DW_AT_stmt_list:
1599 unit->line_offset = DW_UNSND (&attr);
1603 unit->name = DW_STRING (&attr);
1607 unit->arange.low = DW_ADDR (&attr);
1611 unit->arange.high = DW_ADDR (&attr);
1614 case DW_AT_comp_dir:
1616 char* comp_dir = DW_STRING (&attr);
1619 /* Irix 6.2 native cc prepends <machine>.: to the compilation
1620 directory, get rid of it. */
1621 char *cp = (char*) strchr (comp_dir, ':');
1623 if (cp && cp != comp_dir && cp[-1] == '.' && cp[1] == '/')
1626 unit->comp_dir = comp_dir;
1635 unit->first_child_die_ptr = info_ptr;
1639 /* Return true if UNIT contains the address given by ADDR. */
1642 comp_unit_contains_address (unit, addr)
1643 struct comp_unit* unit;
1646 struct arange *arange;
1651 arange = &unit->arange;
1654 if (addr >= arange->low && addr < arange->high)
1656 arange = arange->next;
1663 /* If UNIT contains ADDR, set the output parameters to the values for
1664 the line containing ADDR. The output parameters, FILENAME_PTR,
1665 FUNCTIONNAME_PTR, and LINENUMBER_PTR, are pointers to the objects
1668 Return true of UNIT contains ADDR, and no errors were encountered;
1672 comp_unit_find_nearest_line (unit, addr, filename_ptr, functionname_ptr,
1673 linenumber_ptr, stash)
1674 struct comp_unit* unit;
1676 const char **filename_ptr;
1677 const char **functionname_ptr;
1678 unsigned int *linenumber_ptr;
1679 struct dwarf2_debug *stash;
1683 struct funcinfo *function;
1688 if (! unit->line_table)
1690 if (! unit->stmtlist)
1696 unit->line_table = decode_line_info (unit, stash);
1698 if (! unit->line_table)
1704 if (unit->first_child_die_ptr < unit->end_ptr
1705 && ! scan_unit_for_functions (unit))
1713 func_p = lookup_address_in_function_table (unit->function_table, addr,
1714 &function, functionname_ptr);
1715 line_p = lookup_address_in_line_info_table (unit->line_table, addr,
1716 function, filename_ptr,
1718 return line_p || func_p;
1721 /* Locate a section in a BFD containing debugging info. The search starts
1722 from the section after AFTER_SEC, or from the first section in the BFD if
1723 AFTER_SEC is NULL. The search works by examining the names of the
1724 sections. There are two permissiable names. The first is .debug_info.
1725 This is the standard DWARF2 name. The second is a prefix .gnu.linkonce.wi.
1726 This is a variation on the .debug_info section which has a checksum
1727 describing the contents appended onto the name. This allows the linker to
1728 identify and discard duplicate debugging sections for different
1729 compilation units. */
1730 #define DWARF2_DEBUG_INFO ".debug_info"
1731 #define GNU_LINKONCE_INFO ".gnu.linkonce.wi."
1734 find_debug_info (abfd, after_sec)
1736 asection * after_sec;
1741 msec = after_sec->next;
1743 msec = abfd->sections;
1747 if (strcmp (msec->name, DWARF2_DEBUG_INFO) == 0)
1750 if (strncmp (msec->name, GNU_LINKONCE_INFO, strlen (GNU_LINKONCE_INFO)) == 0)
1759 /* The DWARF2 version of find_nearest line. Return true if the line
1760 is found without error. ADDR_SIZE is the number of bytes in the
1761 initial .debug_info length field and in the abbreviation offset.
1762 You may use zero to indicate that the default value should be
1766 _bfd_dwarf2_find_nearest_line (abfd, section, symbols, offset,
1767 filename_ptr, functionname_ptr,
1768 linenumber_ptr, addr_size, pinfo)
1773 const char **filename_ptr;
1774 const char **functionname_ptr;
1775 unsigned int *linenumber_ptr;
1776 unsigned int addr_size;
1779 /* Read each compilation unit from the section .debug_info, and check
1780 to see if it contains the address we are searching for. If yes,
1781 lookup the address, and return the line number info. If no, go
1782 on to the next compilation unit.
1784 We keep a list of all the previously read compilation units, and
1785 a pointer to the next un-read compilation unit. Check the
1786 previously read units before reading more. */
1787 struct dwarf2_debug *stash = (struct dwarf2_debug *) *pinfo;
1789 /* What address are we looking for? */
1790 bfd_vma addr = offset + section->vma;
1792 struct comp_unit* each;
1794 *filename_ptr = NULL;
1795 *functionname_ptr = NULL;
1796 *linenumber_ptr = 0;
1798 /* The DWARF2 spec says that the initial length field, and the
1799 offset of the abbreviation table, should both be 4-byte values.
1800 However, some compilers do things differently. */
1803 BFD_ASSERT (addr_size == 4 || addr_size == 8);
1807 bfd_size_type total_size;
1809 bfd_size_type amt = sizeof (struct dwarf2_debug);
1811 stash = (struct dwarf2_debug*) bfd_zalloc (abfd, amt);
1815 *pinfo = (PTR) stash;
1817 msec = find_debug_info (abfd, NULL);
1819 /* No dwarf2 info. Note that at this point the stash
1820 has been allocated, but contains zeros, this lets
1821 future calls to this function fail quicker. */
1824 /* There can be more than one DWARF2 info section in a BFD these days.
1825 Read them all in and produce one large stash. We do this in two
1826 passes - in the first pass we just accumulate the section sizes.
1827 In the second pass we read in the section's contents. The allows
1828 us to avoid reallocing the data as we add sections to the stash. */
1829 for (total_size = 0; msec; msec = find_debug_info (abfd, msec))
1830 total_size += msec->_raw_size;
1832 stash->info_ptr = (char *) bfd_alloc (abfd, total_size);
1833 if (stash->info_ptr == NULL)
1836 stash->info_ptr_end = stash->info_ptr;
1838 for (msec = find_debug_info (abfd, NULL);
1840 msec = find_debug_info (abfd, msec))
1843 bfd_size_type start;
1845 size = msec->_raw_size;
1849 start = stash->info_ptr_end - stash->info_ptr;
1851 if (! bfd_get_section_contents (abfd, msec, stash->info_ptr + start,
1855 stash->info_ptr_end = stash->info_ptr + start + size;
1858 BFD_ASSERT (stash->info_ptr_end == stash->info_ptr + total_size);
1860 stash->sec = find_debug_info (abfd, NULL);
1861 stash->sec_info_ptr = stash->info_ptr;
1862 stash->syms = symbols;
1865 /* FIXME: There is a problem with the contents of the
1866 .debug_info section. The 'low' and 'high' addresses of the
1867 comp_units are computed by relocs against symbols in the
1868 .text segment. We need these addresses in order to determine
1869 the nearest line number, and so we have to resolve the
1870 relocs. There is a similar problem when the .debug_line
1871 section is processed as well (e.g., there may be relocs
1872 against the operand of the DW_LNE_set_address operator).
1874 Unfortunately getting hold of the reloc information is hard...
1876 For now, this means that disassembling object files (as
1877 opposed to fully executables) does not always work as well as
1880 /* A null info_ptr indicates that there is no dwarf2 info
1881 (or that an error occured while setting up the stash). */
1882 if (! stash->info_ptr)
1885 /* Check the previously read comp. units first. */
1886 for (each = stash->all_comp_units; each; each = each->next_unit)
1887 if (comp_unit_contains_address (each, addr))
1888 return comp_unit_find_nearest_line (each, addr, filename_ptr,
1889 functionname_ptr, linenumber_ptr,
1892 /* Read each remaining comp. units checking each as they are read. */
1893 while (stash->info_ptr < stash->info_ptr_end)
1897 unsigned int offset_size = addr_size;
1901 length = read_4_bytes (abfd, stash->info_ptr);
1902 if (length == 0xffffffff)
1905 length = read_8_bytes (abfd, stash->info_ptr + 4);
1906 stash->info_ptr += 8;
1908 else if (length == 0)
1910 /* Handle (non-standard) 64-bit DWARF2 formats. */
1912 length = read_4_bytes (abfd, stash->info_ptr + 4);
1913 stash->info_ptr += 4;
1917 length = read_8_bytes (abfd, stash->info_ptr);
1918 stash->info_ptr += addr_size;
1922 each = parse_comp_unit (abfd, stash, length, offset_size);
1923 stash->info_ptr += length;
1925 if ((bfd_vma) (stash->info_ptr - stash->sec_info_ptr)
1926 == stash->sec->_raw_size)
1928 stash->sec = find_debug_info (abfd, stash->sec);
1929 stash->sec_info_ptr = stash->info_ptr;
1934 each->next_unit = stash->all_comp_units;
1935 stash->all_comp_units = each;
1937 /* DW_AT_low_pc and DW_AT_high_pc are optional for
1938 compilation units. If we don't have them (i.e.,
1939 unit->high == 0), we need to consult the line info
1940 table to see if a compilation unit contains the given
1942 if (each->arange.high > 0)
1944 if (comp_unit_contains_address (each, addr))
1945 return comp_unit_find_nearest_line (each, addr,
1953 found = comp_unit_find_nearest_line (each, addr,