1 // dwarf_reader.h -- parse dwarf2/3 debug information for gold -*- C++ -*-
3 // Copyright 2007, 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
4 // Written by Ian Lance Taylor <iant@google.com>.
6 // This file is part of gold.
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 3 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 // MA 02110-1301, USA.
23 #ifndef GOLD_DWARF_READER_H
24 #define GOLD_DWARF_READER_H
29 #include <sys/types.h>
32 #include "elfcpp_swap.h"
39 class Dwarf_info_reader;
40 struct LineStateMachine;
42 // This class is used to extract the section index and offset of
43 // the target of a relocation for a given offset within the section.
45 class Elf_reloc_mapper
55 // Initialize the relocation tracker for section RELOC_SHNDX.
57 initialize(unsigned int reloc_shndx, unsigned int reloc_type)
58 { return this->do_initialize(reloc_shndx, reloc_type); }
60 // Return the next reloc_offset.
63 { return this->do_next_offset(); }
65 // Advance to the next relocation past OFFSET.
68 { this->do_advance(offset); }
70 // Return the section index and offset within the section of the target
71 // of the relocation for RELOC_OFFSET in the referring section.
73 get_reloc_target(off_t reloc_offset, off_t* target_offset)
74 { return this->do_get_reloc_target(reloc_offset, target_offset); }
76 // Checkpoint the current position in the reloc section.
79 { return this->do_checkpoint(); }
81 // Reset the current position to the CHECKPOINT.
83 reset(uint64_t checkpoint)
84 { this->do_reset(checkpoint); }
88 do_initialize(unsigned int, unsigned int) = 0;
90 // Return the next reloc_offset.
94 // Advance to the next relocation past OFFSET.
96 do_advance(off_t offset) = 0;
99 do_get_reloc_target(off_t reloc_offset, off_t* target_offset) = 0;
101 // Checkpoint the current position in the reloc section.
103 do_checkpoint() const = 0;
105 // Reset the current position to the CHECKPOINT.
107 do_reset(uint64_t checkpoint) = 0;
110 template<int size, bool big_endian>
111 class Sized_elf_reloc_mapper : public Elf_reloc_mapper
114 Sized_elf_reloc_mapper(Object* object, const unsigned char* symtab,
116 : object_(object), symtab_(symtab), symtab_size_(symtab_size),
117 reloc_type_(0), track_relocs_()
122 do_initialize(unsigned int reloc_shndx, unsigned int reloc_type);
124 // Return the next reloc_offset.
127 { return this->track_relocs_.next_offset(); }
129 // Advance to the next relocation past OFFSET.
131 do_advance(off_t offset)
132 { this->track_relocs_.advance(offset); }
135 do_get_reloc_target(off_t reloc_offset, off_t* target_offset);
137 // Checkpoint the current position in the reloc section.
139 do_checkpoint() const
140 { return this->track_relocs_.checkpoint(); }
142 // Reset the current position to the CHECKPOINT.
144 do_reset(uint64_t checkpoint)
145 { this->track_relocs_.reset(checkpoint); }
148 typedef typename elfcpp::Elf_types<size>::Elf_Addr Address;
150 // Return the section index of symbol SYMNDX, and copy its value to *VALUE.
151 // Set *IS_ORDINARY true if the section index is an ordinary section index.
153 symbol_section(unsigned int symndx, Address* value, bool* is_ordinary);
157 // The ELF symbol table.
158 const unsigned char* symtab_;
159 // The size of the ELF symbol table.
161 // Type of the relocation section (SHT_REL or SHT_RELA).
162 unsigned int reloc_type_;
163 // Relocations for the referring section.
164 Track_relocs<size, big_endian> track_relocs_;
167 // This class is used to read the abbreviations table from the
168 // .debug_abbrev section of the object file.
170 class Dwarf_abbrev_table
173 // An attribute list entry.
176 Attribute(unsigned int a, unsigned int f)
183 // An abbrev code entry.
186 Abbrev_code(unsigned int t, bool hc)
187 : tag(t), has_children(hc), has_sibling_attribute(false), attributes()
189 this->attributes.reserve(10);
193 add_attribute(unsigned int attr, unsigned int form)
195 this->attributes.push_back(Attribute(attr, form));
200 // True if the DIE has children.
201 bool has_children : 1;
202 // True if the DIE has a sibling attribute.
203 bool has_sibling_attribute : 1;
204 // The list of attributes and forms.
205 std::vector<Attribute> attributes;
209 : abbrev_shndx_(0), abbrev_offset_(0), buffer_(NULL), buffer_end_(NULL),
210 owns_buffer_(false), buffer_pos_(NULL), high_abbrev_codes_()
212 memset(this->low_abbrev_codes_, 0, sizeof(this->low_abbrev_codes_));
215 ~Dwarf_abbrev_table()
217 if (this->owns_buffer_ && this->buffer_ != NULL)
218 delete[] this->buffer_;
219 this->clear_abbrev_codes();
222 // Read the abbrev table from an object file.
224 read_abbrevs(Relobj* object,
225 unsigned int abbrev_shndx,
228 // If we've already read this abbrev table, return immediately.
229 if (this->abbrev_shndx_ > 0
230 && this->abbrev_shndx_ == abbrev_shndx
231 && this->abbrev_offset_ == abbrev_offset)
233 return this->do_read_abbrevs(object, abbrev_shndx, abbrev_offset);
236 // Return the abbrev code entry for CODE. This is a fast path for
237 // abbrev codes that are in the direct lookup table. If not found
238 // there, we call do_get_abbrev() to do the hard work.
240 get_abbrev(unsigned int code)
242 if (code < this->low_abbrev_code_max_
243 && this->low_abbrev_codes_[code] != NULL)
244 return this->low_abbrev_codes_[code];
245 return this->do_get_abbrev(code);
249 // Read the abbrev table from an object file.
251 do_read_abbrevs(Relobj* object,
252 unsigned int abbrev_shndx,
253 off_t abbrev_offset);
255 // Lookup the abbrev code entry for CODE.
257 do_get_abbrev(unsigned int code);
259 // Store an abbrev code entry for CODE.
261 store_abbrev(unsigned int code, const Abbrev_code* entry)
263 if (code < this->low_abbrev_code_max_)
264 this->low_abbrev_codes_[code] = entry;
266 this->high_abbrev_codes_[code] = entry;
269 // Clear the abbrev code table and release the memory it uses.
271 clear_abbrev_codes();
273 typedef Unordered_map<unsigned int, const Abbrev_code*> Abbrev_code_table;
275 // The section index of the current abbrev table.
276 unsigned int abbrev_shndx_;
277 // The offset within the section of the current abbrev table.
278 off_t abbrev_offset_;
279 // The buffer containing the .debug_abbrev section.
280 const unsigned char* buffer_;
281 const unsigned char* buffer_end_;
282 // True if this object owns the buffer and needs to delete it.
284 // Pointer to the current position in the buffer.
285 const unsigned char* buffer_pos_;
286 // The table of abbrev codes.
287 // We use a direct-lookup array for low abbrev codes,
288 // and store the rest in a hash table.
289 static const unsigned int low_abbrev_code_max_ = 256;
290 const Abbrev_code* low_abbrev_codes_[low_abbrev_code_max_];
291 Abbrev_code_table high_abbrev_codes_;
294 // A DWARF range list. The start and end offsets are relative
295 // to the input section SHNDX. Each range must lie entirely
296 // within a single section.
298 class Dwarf_range_list
303 Range(unsigned int a_shndx, off_t a_start, off_t a_end)
304 : shndx(a_shndx), start(a_start), end(a_end)
317 add(unsigned int shndx, off_t start, off_t end)
318 { this->range_list_.push_back(Range(shndx, start, end)); }
322 { return this->range_list_.size(); }
325 operator[](off_t i) const
326 { return this->range_list_[i]; }
329 std::vector<Range> range_list_;
332 // This class is used to read the ranges table from the
333 // .debug_ranges section of the object file.
335 class Dwarf_ranges_table
339 : ranges_shndx_(0), ranges_buffer_(NULL), ranges_buffer_end_(NULL),
340 owns_ranges_buffer_(false), ranges_reloc_mapper_(NULL),
341 output_section_offset_(0)
344 ~Dwarf_ranges_table()
346 if (this->owns_ranges_buffer_ && this->ranges_buffer_ != NULL)
347 delete[] this->ranges_buffer_;
348 if (this->ranges_reloc_mapper_ != NULL)
349 delete this->ranges_reloc_mapper_;
352 // Read the ranges table from an object file.
354 read_ranges_table(Relobj* object,
355 const unsigned char* symtab,
357 unsigned int ranges_shndx);
359 // Read the range table from an object file.
361 read_range_list(Relobj* object,
362 const unsigned char* symtab,
364 unsigned int address_size,
365 unsigned int ranges_shndx,
366 off_t ranges_offset);
369 // The section index of the ranges table.
370 unsigned int ranges_shndx_;
371 // The buffer containing the .debug_ranges section.
372 const unsigned char* ranges_buffer_;
373 const unsigned char* ranges_buffer_end_;
374 // True if this object owns the buffer and needs to delete it.
375 bool owns_ranges_buffer_;
376 // Relocation mapper for the .debug_ranges section.
377 Elf_reloc_mapper* ranges_reloc_mapper_;
378 // For incremental update links, this will hold the offset of the
379 // input section within the output section. Offsets read from
380 // relocated data will be relative to the output section, and need
381 // to be corrected before reading data from the input section.
382 uint64_t output_section_offset_;
385 // This class is used to read the pubnames and pubtypes tables from the
386 // .debug_pubnames and .debug_pubtypes sections of the object file.
388 class Dwarf_pubnames_table
391 Dwarf_pubnames_table(bool is_pubtypes)
392 : buffer_(NULL), buffer_end_(NULL), owns_buffer_(false),
393 offset_size_(0), pinfo_(NULL), is_pubtypes_(is_pubtypes),
394 output_section_offset_(0)
397 ~Dwarf_pubnames_table()
399 if (this->owns_buffer_ && this->buffer_ != NULL)
400 delete[] this->buffer_;
403 // Read the pubnames section SHNDX from the object file.
405 read_section(Relobj* object, unsigned int shndx);
407 // Read the header for the set at OFFSET.
409 read_header(off_t offset);
411 // Read the next name from the set.
416 // The buffer containing the .debug_ranges section.
417 const unsigned char* buffer_;
418 const unsigned char* buffer_end_;
419 // True if this object owns the buffer and needs to delete it.
421 // The size of a DWARF offset for the current set.
422 unsigned int offset_size_;
423 // The current position within the buffer.
424 const unsigned char* pinfo_;
425 // TRUE if this is a .debug_pubtypes section.
427 // For incremental update links, this will hold the offset of the
428 // input section within the output section. Offsets read from
429 // relocated data will be relative to the output section, and need
430 // to be corrected before reading data from the input section.
431 uint64_t output_section_offset_;
434 // This class represents a DWARF Debug Info Entry (DIE).
439 // An attribute value.
440 struct Attribute_value
448 const char* stringval;
449 const unsigned char* blockval;
454 // Section index for reference forms.
456 // Block length for block forms.
457 unsigned int blocklen;
458 // Attribute offset for DW_FORM_strp.
459 unsigned int attr_off;
463 // A list of attribute values.
464 typedef std::vector<Attribute_value> Attributes;
466 Dwarf_die(Dwarf_info_reader* dwinfo,
470 // Return the DWARF tag for this DIE.
474 if (this->abbrev_code_ == NULL)
476 return this->abbrev_code_->tag;
479 // Return true if this DIE has children.
483 gold_assert(this->abbrev_code_ != NULL);
484 return this->abbrev_code_->has_children;
487 // Return true if this DIE has a sibling attribute.
489 has_sibling_attribute() const
491 gold_assert(this->abbrev_code_ != NULL);
492 return this->abbrev_code_->has_sibling_attribute;
495 // Return the value of attribute ATTR.
496 const Attribute_value*
497 attribute(unsigned int attr);
499 // Return the value of the DW_AT_name attribute.
503 if (this->name_ == NULL)
508 // Return the value of the DW_AT_linkage_name
509 // or DW_AT_MIPS_linkage_name attribute.
513 if (this->linkage_name_ == NULL)
514 this->set_linkage_name();
515 return this->linkage_name_;
518 // Return the value of the DW_AT_specification attribute.
522 if (!this->attributes_read_)
523 this->read_attributes();
524 return this->specification_;
527 // Return the value of the DW_AT_abstract_origin attribute.
531 if (!this->attributes_read_)
532 this->read_attributes();
533 return this->abstract_origin_;
536 // Return the value of attribute ATTR as a string.
538 string_attribute(unsigned int attr);
540 // Return the value of attribute ATTR as an integer.
542 int_attribute(unsigned int attr);
544 // Return the value of attribute ATTR as an unsigned integer.
546 uint_attribute(unsigned int attr);
548 // Return the value of attribute ATTR as a reference.
550 ref_attribute(unsigned int attr,
551 unsigned int* shndx);
553 // Return the value of attribute ATTR as a flag.
555 flag_attribute(unsigned int attr)
556 { return this->int_attribute(attr) != 0; }
558 // Return true if this DIE is a declaration.
561 { return this->flag_attribute(elfcpp::DW_AT_declaration); }
563 // Return the parent of this DIE.
566 { return this->parent_; }
568 // Return the offset of this DIE.
571 { return this->die_offset_; }
573 // Return the offset of this DIE's first child.
577 // Set the offset of this DIE's next sibling.
579 set_sibling_offset(off_t sibling_offset)
580 { this->sibling_offset_ = sibling_offset; }
582 // Return the offset of this DIE's next sibling.
587 typedef Dwarf_abbrev_table::Abbrev_code Abbrev_code;
589 // Read all the attributes of the DIE.
593 // Set the name of the DIE if present.
597 // Set the linkage name if present.
601 // Skip all the attributes of the DIE and return the offset
606 // The Dwarf_info_reader, for reading attributes.
607 Dwarf_info_reader* dwinfo_;
608 // The parent of this DIE.
610 // Offset of this DIE within its compilation unit.
612 // Offset of the first attribute, relative to the beginning of the DIE.
614 // Offset of the first child, relative to the compilation unit.
616 // Offset of the next sibling, relative to the compilation unit.
617 off_t sibling_offset_;
618 // The abbreviation table entry.
619 const Abbrev_code* abbrev_code_;
620 // The list of attributes.
621 Attributes attributes_;
622 // True if the attributes have been read.
623 bool attributes_read_;
624 // The following fields hold common attributes to avoid a linear
625 // search through the attribute list.
626 // The DIE name (DW_AT_name).
628 // Offset of the name in the string table (for DW_FORM_strp).
630 // The linkage name (DW_AT_linkage_name or DW_AT_MIPS_linkage_name).
631 const char* linkage_name_;
632 // Offset of the linkage name in the string table (for DW_FORM_strp).
633 off_t linkage_name_off_;
634 // Section index of the string table (for DW_FORM_strp).
635 unsigned int string_shndx_;
636 // The value of a DW_AT_specification attribute.
637 off_t specification_;
638 // The value of a DW_AT_abstract_origin attribute.
639 off_t abstract_origin_;
642 // This class is used to read the debug info from the .debug_info
643 // or .debug_types sections. This is a base class that implements
644 // the generic parsing of the compilation unit header and DIE
645 // structure. The parse() method parses the entire section, and
646 // calls the various visit_xxx() methods for each header. Clients
647 // should derive a new class from this one and implement the
648 // visit_compilation_unit() and visit_type_unit() functions.
650 class Dwarf_info_reader
653 Dwarf_info_reader(bool is_type_unit,
655 const unsigned char* symtab,
658 unsigned int reloc_shndx,
659 unsigned int reloc_type)
660 : is_type_unit_(is_type_unit), object_(object), symtab_(symtab),
661 symtab_size_(symtab_size), shndx_(shndx), reloc_shndx_(reloc_shndx),
662 reloc_type_(reloc_type), string_shndx_(0), buffer_(NULL),
663 buffer_end_(NULL), cu_offset_(0), cu_length_(0), offset_size_(0),
664 address_size_(0), cu_version_(0), type_signature_(0), type_offset_(0),
665 abbrev_table_(), reloc_mapper_(NULL), string_buffer_(NULL),
666 string_buffer_end_(NULL), owns_string_buffer_(false),
667 string_output_section_offset_(0)
673 if (this->reloc_mapper_ != NULL)
674 delete this->reloc_mapper_;
675 if (this->owns_string_buffer_ && this->string_buffer_ != NULL)
676 delete[] this->string_buffer_;
679 // Begin parsing the debug info. This calls visit_compilation_unit()
680 // or visit_type_unit() for each compilation or type unit found in the
681 // section, and visit_die() for each top-level DIE.
685 // Return the abbrev code entry for a CODE.
686 const Dwarf_abbrev_table::Abbrev_code*
687 get_abbrev(unsigned int code)
688 { return this->abbrev_table_.get_abbrev(code); }
690 // Return a pointer to the DWARF info buffer at OFFSET.
692 buffer_at_offset(off_t offset) const
694 const unsigned char* p = this->buffer_ + this->cu_offset_ + offset;
695 if (this->check_buffer(p + 1))
700 // Look for a relocation at offset ATTR_OFF in the dwarf info,
701 // and return the section index and offset of the target.
703 lookup_reloc(off_t attr_off, off_t* target_off);
705 // Return a string from the DWARF string table.
707 get_string(off_t str_off, unsigned int string_shndx);
709 // Return the size of a DWARF offset.
712 { return this->offset_size_; }
714 // Return the size of an address.
717 { return this->address_size_; }
720 // Begin parsing the debug info. This calls visit_compilation_unit()
721 // or visit_type_unit() for each compilation or type unit found in the
722 // section, and visit_die() for each top-level DIE.
723 template<bool big_endian>
727 // The following methods are hooks that are meant to be implemented
728 // by a derived class. A default, do-nothing, implementation of
729 // each is provided for this base class.
731 // Visit a compilation unit.
733 visit_compilation_unit(off_t cu_offset, off_t cu_length, Dwarf_die* root_die);
735 // Visit a type unit.
737 visit_type_unit(off_t tu_offset, off_t type_offset, uint64_t signature,
738 Dwarf_die* root_die);
740 // Read the range table.
742 read_range_list(unsigned int ranges_shndx, off_t ranges_offset)
744 return this->ranges_table_.read_range_list(this->object_,
752 // Return the object.
755 { return this->object_; }
757 // Return a pointer to the object file's ELF symbol table.
760 { return this->symtab_; }
762 // Return the size of the object file's ELF symbol table.
765 { return this->symtab_size_; }
767 // Checkpoint the relocation tracker.
769 get_reloc_checkpoint() const
770 { return this->reloc_mapper_->checkpoint(); }
772 // Reset the relocation tracker to the CHECKPOINT.
774 reset_relocs(uint64_t checkpoint)
775 { this->reloc_mapper_->reset(checkpoint); }
778 // Check that P is within the bounds of the current section.
780 check_buffer(const unsigned char* p) const;
782 // Read the DWARF string table.
784 read_string_table(unsigned int string_shndx)
786 // If we've already read this string table, return immediately.
787 if (this->string_shndx_ > 0 && this->string_shndx_ == string_shndx)
789 if (string_shndx == 0 && this->string_shndx_ > 0)
791 return this->do_read_string_table(string_shndx);
795 do_read_string_table(unsigned int string_shndx);
797 // True if this is a type unit; false for a compilation unit.
799 // The object containing the .debug_info or .debug_types input section.
801 // The ELF symbol table.
802 const unsigned char* symtab_;
803 // The size of the ELF symbol table.
805 // Index of the .debug_info or .debug_types section.
807 // Index of the relocation section.
808 unsigned int reloc_shndx_;
809 // Type of the relocation section (SHT_REL or SHT_RELA).
810 unsigned int reloc_type_;
811 // Index of the .debug_str section.
812 unsigned int string_shndx_;
813 // The buffer for the debug info.
814 const unsigned char* buffer_;
815 const unsigned char* buffer_end_;
816 // Offset of the current compilation unit.
818 // Length of the current compilation unit.
820 // Size of a DWARF offset for the current compilation unit.
821 unsigned int offset_size_;
822 // Size of an address for the target architecture.
823 unsigned int address_size_;
824 // Compilation unit version number.
825 unsigned int cu_version_;
826 // Type signature (for a type unit).
827 uint64_t type_signature_;
828 // Offset from the type unit header to the type DIE (for a type unit).
830 // Abbreviations table for current compilation unit.
831 Dwarf_abbrev_table abbrev_table_;
832 // Ranges table for the current compilation unit.
833 Dwarf_ranges_table ranges_table_;
834 // Relocation mapper for the section.
835 Elf_reloc_mapper* reloc_mapper_;
836 // The buffer for the debug string table.
837 const char* string_buffer_;
838 const char* string_buffer_end_;
839 // True if this object owns the buffer and needs to delete it.
840 bool owns_string_buffer_;
841 // For incremental update links, this will hold the offset of the
842 // input .debug_str section within the output section. Offsets read
843 // from relocated data will be relative to the output section, and need
844 // to be corrected before reading data from the input section.
845 uint64_t string_output_section_offset_;
848 // We can't do better than to keep the offsets in a sorted vector.
849 // Here, offset is the key, and file_num/line_num is the value.
850 struct Offset_to_lineno_entry
853 int header_num; // which file-list to use (i.e. which .o file are we in)
854 // A pointer into files_.
855 unsigned int file_num : sizeof(int) * CHAR_BIT - 1;
856 // True if this was the last entry for the current offset, meaning
857 // it's the line that actually applies.
858 unsigned int last_line_for_offset : 1;
859 // The line number in the source file. -1 to indicate end-of-function.
862 // This sorts by offsets first, and then puts the correct line to
863 // report for a given offset at the beginning of the run of equal
864 // offsets (so that asking for 1 line gives the best answer). This
865 // is not a total ordering.
866 bool operator<(const Offset_to_lineno_entry& that) const
868 if (this->offset != that.offset)
869 return this->offset < that.offset;
870 // Note the '>' which makes this sort 'true' first.
871 return this->last_line_for_offset > that.last_line_for_offset;
875 // This class is used to read the line information from the debugging
876 // section of an object file.
878 class Dwarf_line_info
888 // Given a section number and an offset, returns the associated
889 // file and line-number, as a string: "file:lineno". If unable
890 // to do the mapping, returns the empty string. You must call
891 // read_line_mappings() before calling this function. If
892 // 'other_lines' is non-NULL, fills that in with other line
893 // numbers assigned to the same offset.
895 addr2line(unsigned int shndx, off_t offset,
896 std::vector<std::string>* other_lines)
897 { return this->do_addr2line(shndx, offset, other_lines); }
899 // A helper function for a single addr2line lookup. It also keeps a
900 // cache of the last CACHE_SIZE Dwarf_line_info objects it created;
901 // set to 0 not to cache at all. The larger CACHE_SIZE is, the more
902 // chance this routine won't have to re-create a Dwarf_line_info
903 // object for its addr2line computation; such creations are slow.
904 // NOTE: Not thread-safe, so only call from one thread at a time.
906 one_addr2line(Object* object, unsigned int shndx, off_t offset,
907 size_t cache_size, std::vector<std::string>* other_lines);
909 // This reclaims all the memory that one_addr2line may have cached.
910 // Use this when you know you will not be calling one_addr2line again.
912 clear_addr2line_cache();
916 do_addr2line(unsigned int shndx, off_t offset,
917 std::vector<std::string>* other_lines) = 0;
920 template<int size, bool big_endian>
921 class Sized_dwarf_line_info : public Dwarf_line_info
924 // Initializes a .debug_line reader for a given object file.
925 // If SHNDX is specified and non-negative, only read the debug
926 // information that pertains to the specified section.
927 Sized_dwarf_line_info(Object* object, unsigned int read_shndx = -1U);
930 ~Sized_dwarf_line_info()
932 if (this->buffer_start_ != NULL)
933 delete[] this->buffer_start_;
938 do_addr2line(unsigned int shndx, off_t offset,
939 std::vector<std::string>* other_lines);
941 // Formats a file and line number to a string like "dirname/filename:lineno".
943 format_file_lineno(const Offset_to_lineno_entry& lineno) const;
945 // Start processing line info, and populates the offset_map_.
946 // If SHNDX is non-negative, only store debug information that
947 // pertains to the specified section.
949 read_line_mappings(unsigned int shndx);
951 // Reads the relocation section associated with .debug_line and
952 // stores relocation information in reloc_map_.
956 // Reads the DWARF2/3 header for this line info. Each takes as input
957 // a starting buffer position, and returns the ending position.
959 read_header_prolog(const unsigned char* lineptr);
962 read_header_tables(const unsigned char* lineptr);
964 // Reads the DWARF2/3 line information. If shndx is non-negative,
965 // discard all line information that doesn't pertain to the given
968 read_lines(const unsigned char* lineptr, unsigned int shndx);
970 // Process a single line info opcode at START using the state
971 // machine at LSM. Return true if we should define a line using the
972 // current state of the line state machine. Place the length of the
975 process_one_opcode(const unsigned char* start,
976 struct LineStateMachine* lsm, size_t* len);
978 // Some parts of processing differ depending on whether the input
979 // was a .o file or not.
980 bool input_is_relobj();
982 // If we saw anything amiss while parsing, we set this to false.
983 // Then addr2line will always fail (rather than return possibly-
987 // A DWARF2/3 line info header. This is not the same size as in the
988 // actual file, as the one in the file may have a 32 bit or 64 bit
991 struct Dwarf_line_infoHeader
995 off_t prologue_length;
996 int min_insn_length; // insn stands for instructin
997 bool default_is_stmt; // stmt stands for statement
998 signed char line_base;
1000 unsigned char opcode_base;
1001 std::vector<unsigned char> std_opcode_lengths;
1005 // buffer is the buffer for our line info, starting at exactly where
1006 // the line info to read is.
1007 const unsigned char* buffer_;
1008 const unsigned char* buffer_end_;
1009 // If the buffer was allocated temporarily, and therefore must be
1010 // deallocated in the dtor, this contains a pointer to the start
1012 const unsigned char* buffer_start_;
1014 // This has relocations that point into buffer.
1015 Sized_elf_reloc_mapper<size, big_endian>* reloc_mapper_;
1016 // The type of the reloc section in track_relocs_--SHT_REL or SHT_RELA.
1017 unsigned int track_relocs_type_;
1019 // This is used to figure out what section to apply a relocation to.
1020 const unsigned char* symtab_buffer_;
1021 section_size_type symtab_buffer_size_;
1023 // Holds the directories and files as we see them. We have an array
1024 // of directory-lists, one for each .o file we're reading (usually
1025 // there will just be one, but there may be more if input is a .so).
1026 std::vector<std::vector<std::string> > directories_;
1027 // The first part is an index into directories_, the second the filename.
1028 std::vector<std::vector< std::pair<int, std::string> > > files_;
1030 // An index into the current directories_ and files_ vectors.
1031 int current_header_index_;
1033 // A sorted map from offset of the relocation target to the shndx
1034 // and addend for the relocation.
1035 typedef std::map<off_t, std::pair<unsigned int, off_t> >
1037 Reloc_map reloc_map_;
1039 // We have a vector of offset->lineno entries for every input section.
1040 typedef Unordered_map<unsigned int, std::vector<Offset_to_lineno_entry> >
1043 Lineno_map line_number_map_;
1046 } // End namespace gold.
1048 #endif // !defined(GOLD_DWARF_READER_H)