2007-11-03 00:02:44 +01:00
|
|
|
// dwarf_reader.h -- parse dwarf2/3 debug information for gold -*- C++ -*-
|
|
|
|
|
2017-01-02 04:36:43 +01:00
|
|
|
// Copyright (C) 2007-2017 Free Software Foundation, Inc.
|
2007-11-03 00:02:44 +01:00
|
|
|
// Written by Ian Lance Taylor <iant@google.com>.
|
|
|
|
|
|
|
|
// This file is part of gold.
|
|
|
|
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation; either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
|
|
|
|
// MA 02110-1301, USA.
|
|
|
|
|
|
|
|
#ifndef GOLD_DWARF_READER_H
|
|
|
|
#define GOLD_DWARF_READER_H
|
|
|
|
|
|
|
|
#include <vector>
|
2007-11-10 00:16:54 +01:00
|
|
|
#include <map>
|
2011-03-10 02:31:33 +01:00
|
|
|
#include <limits.h>
|
2012-03-21 20:02:22 +01:00
|
|
|
#include <sys/types.h>
|
2007-11-03 00:02:44 +01:00
|
|
|
|
2007-11-10 00:16:54 +01:00
|
|
|
#include "elfcpp.h"
|
2007-11-03 00:02:44 +01:00
|
|
|
#include "elfcpp_swap.h"
|
|
|
|
#include "dwarf.h"
|
2007-11-12 20:56:20 +01:00
|
|
|
#include "reloc.h"
|
2007-11-03 00:02:44 +01:00
|
|
|
|
|
|
|
namespace gold
|
|
|
|
{
|
|
|
|
|
2012-03-21 20:02:22 +01:00
|
|
|
class Dwarf_info_reader;
|
2007-11-03 00:02:44 +01:00
|
|
|
struct LineStateMachine;
|
|
|
|
|
2012-03-21 20:02:22 +01:00
|
|
|
// This class is used to extract the section index and offset of
|
|
|
|
// the target of a relocation for a given offset within the section.
|
|
|
|
|
|
|
|
class Elf_reloc_mapper
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Elf_reloc_mapper()
|
|
|
|
{ }
|
|
|
|
|
|
|
|
virtual
|
|
|
|
~Elf_reloc_mapper()
|
|
|
|
{ }
|
|
|
|
|
|
|
|
// Initialize the relocation tracker for section RELOC_SHNDX.
|
|
|
|
bool
|
|
|
|
initialize(unsigned int reloc_shndx, unsigned int reloc_type)
|
|
|
|
{ return this->do_initialize(reloc_shndx, reloc_type); }
|
|
|
|
|
|
|
|
// Return the next reloc_offset.
|
|
|
|
off_t
|
|
|
|
next_offset()
|
|
|
|
{ return this->do_next_offset(); }
|
|
|
|
|
|
|
|
// Advance to the next relocation past OFFSET.
|
|
|
|
void
|
|
|
|
advance(off_t offset)
|
|
|
|
{ this->do_advance(offset); }
|
|
|
|
|
|
|
|
// Return the section index and offset within the section of the target
|
|
|
|
// of the relocation for RELOC_OFFSET in the referring section.
|
|
|
|
unsigned int
|
|
|
|
get_reloc_target(off_t reloc_offset, off_t* target_offset)
|
|
|
|
{ return this->do_get_reloc_target(reloc_offset, target_offset); }
|
|
|
|
|
|
|
|
// Checkpoint the current position in the reloc section.
|
|
|
|
uint64_t
|
|
|
|
checkpoint() const
|
|
|
|
{ return this->do_checkpoint(); }
|
|
|
|
|
|
|
|
// Reset the current position to the CHECKPOINT.
|
|
|
|
void
|
|
|
|
reset(uint64_t checkpoint)
|
|
|
|
{ this->do_reset(checkpoint); }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual bool
|
|
|
|
do_initialize(unsigned int, unsigned int) = 0;
|
|
|
|
|
|
|
|
// Return the next reloc_offset.
|
|
|
|
virtual off_t
|
|
|
|
do_next_offset() = 0;
|
|
|
|
|
|
|
|
// Advance to the next relocation past OFFSET.
|
|
|
|
virtual void
|
|
|
|
do_advance(off_t offset) = 0;
|
|
|
|
|
|
|
|
virtual unsigned int
|
|
|
|
do_get_reloc_target(off_t reloc_offset, off_t* target_offset) = 0;
|
|
|
|
|
|
|
|
// Checkpoint the current position in the reloc section.
|
|
|
|
virtual uint64_t
|
|
|
|
do_checkpoint() const = 0;
|
|
|
|
|
|
|
|
// Reset the current position to the CHECKPOINT.
|
|
|
|
virtual void
|
|
|
|
do_reset(uint64_t checkpoint) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<int size, bool big_endian>
|
|
|
|
class Sized_elf_reloc_mapper : public Elf_reloc_mapper
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Sized_elf_reloc_mapper(Object* object, const unsigned char* symtab,
|
|
|
|
off_t symtab_size)
|
|
|
|
: object_(object), symtab_(symtab), symtab_size_(symtab_size),
|
|
|
|
reloc_type_(0), track_relocs_()
|
|
|
|
{ }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
bool
|
|
|
|
do_initialize(unsigned int reloc_shndx, unsigned int reloc_type);
|
|
|
|
|
|
|
|
// Return the next reloc_offset.
|
|
|
|
virtual off_t
|
|
|
|
do_next_offset()
|
|
|
|
{ return this->track_relocs_.next_offset(); }
|
|
|
|
|
|
|
|
// Advance to the next relocation past OFFSET.
|
|
|
|
virtual void
|
|
|
|
do_advance(off_t offset)
|
|
|
|
{ this->track_relocs_.advance(offset); }
|
|
|
|
|
|
|
|
unsigned int
|
|
|
|
do_get_reloc_target(off_t reloc_offset, off_t* target_offset);
|
|
|
|
|
|
|
|
// Checkpoint the current position in the reloc section.
|
|
|
|
uint64_t
|
|
|
|
do_checkpoint() const
|
|
|
|
{ return this->track_relocs_.checkpoint(); }
|
|
|
|
|
|
|
|
// Reset the current position to the CHECKPOINT.
|
|
|
|
void
|
|
|
|
do_reset(uint64_t checkpoint)
|
|
|
|
{ this->track_relocs_.reset(checkpoint); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef typename elfcpp::Elf_types<size>::Elf_Addr Address;
|
|
|
|
|
|
|
|
// Return the section index of symbol SYMNDX, and copy its value to *VALUE.
|
|
|
|
// Set *IS_ORDINARY true if the section index is an ordinary section index.
|
|
|
|
unsigned int
|
|
|
|
symbol_section(unsigned int symndx, Address* value, bool* is_ordinary);
|
|
|
|
|
|
|
|
// The object file.
|
|
|
|
Object* object_;
|
|
|
|
// The ELF symbol table.
|
|
|
|
const unsigned char* symtab_;
|
|
|
|
// The size of the ELF symbol table.
|
|
|
|
off_t symtab_size_;
|
|
|
|
// Type of the relocation section (SHT_REL or SHT_RELA).
|
|
|
|
unsigned int reloc_type_;
|
|
|
|
// Relocations for the referring section.
|
|
|
|
Track_relocs<size, big_endian> track_relocs_;
|
|
|
|
};
|
|
|
|
|
|
|
|
// This class is used to read the abbreviations table from the
|
|
|
|
// .debug_abbrev section of the object file.
|
|
|
|
|
|
|
|
class Dwarf_abbrev_table
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// An attribute list entry.
|
|
|
|
struct Attribute
|
|
|
|
{
|
|
|
|
Attribute(unsigned int a, unsigned int f)
|
|
|
|
: attr(a), form(f)
|
|
|
|
{ }
|
|
|
|
unsigned int attr;
|
|
|
|
unsigned int form;
|
|
|
|
};
|
|
|
|
|
|
|
|
// An abbrev code entry.
|
|
|
|
struct Abbrev_code
|
|
|
|
{
|
|
|
|
Abbrev_code(unsigned int t, bool hc)
|
|
|
|
: tag(t), has_children(hc), has_sibling_attribute(false), attributes()
|
|
|
|
{
|
|
|
|
this->attributes.reserve(10);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
add_attribute(unsigned int attr, unsigned int form)
|
|
|
|
{
|
|
|
|
this->attributes.push_back(Attribute(attr, form));
|
|
|
|
}
|
|
|
|
|
|
|
|
// The DWARF tag.
|
|
|
|
unsigned int tag;
|
|
|
|
// True if the DIE has children.
|
|
|
|
bool has_children : 1;
|
|
|
|
// True if the DIE has a sibling attribute.
|
|
|
|
bool has_sibling_attribute : 1;
|
|
|
|
// The list of attributes and forms.
|
|
|
|
std::vector<Attribute> attributes;
|
|
|
|
};
|
|
|
|
|
|
|
|
Dwarf_abbrev_table()
|
|
|
|
: abbrev_shndx_(0), abbrev_offset_(0), buffer_(NULL), buffer_end_(NULL),
|
|
|
|
owns_buffer_(false), buffer_pos_(NULL), high_abbrev_codes_()
|
|
|
|
{
|
|
|
|
memset(this->low_abbrev_codes_, 0, sizeof(this->low_abbrev_codes_));
|
|
|
|
}
|
|
|
|
|
|
|
|
~Dwarf_abbrev_table()
|
|
|
|
{
|
|
|
|
if (this->owns_buffer_ && this->buffer_ != NULL)
|
|
|
|
delete[] this->buffer_;
|
|
|
|
this->clear_abbrev_codes();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read the abbrev table from an object file.
|
|
|
|
bool
|
|
|
|
read_abbrevs(Relobj* object,
|
|
|
|
unsigned int abbrev_shndx,
|
|
|
|
off_t abbrev_offset)
|
|
|
|
{
|
|
|
|
// If we've already read this abbrev table, return immediately.
|
|
|
|
if (this->abbrev_shndx_ > 0
|
|
|
|
&& this->abbrev_shndx_ == abbrev_shndx
|
|
|
|
&& this->abbrev_offset_ == abbrev_offset)
|
|
|
|
return true;
|
|
|
|
return this->do_read_abbrevs(object, abbrev_shndx, abbrev_offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return the abbrev code entry for CODE. This is a fast path for
|
|
|
|
// abbrev codes that are in the direct lookup table. If not found
|
|
|
|
// there, we call do_get_abbrev() to do the hard work.
|
|
|
|
const Abbrev_code*
|
|
|
|
get_abbrev(unsigned int code)
|
|
|
|
{
|
|
|
|
if (code < this->low_abbrev_code_max_
|
|
|
|
&& this->low_abbrev_codes_[code] != NULL)
|
|
|
|
return this->low_abbrev_codes_[code];
|
|
|
|
return this->do_get_abbrev(code);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Read the abbrev table from an object file.
|
|
|
|
bool
|
|
|
|
do_read_abbrevs(Relobj* object,
|
|
|
|
unsigned int abbrev_shndx,
|
|
|
|
off_t abbrev_offset);
|
|
|
|
|
|
|
|
// Lookup the abbrev code entry for CODE.
|
|
|
|
const Abbrev_code*
|
|
|
|
do_get_abbrev(unsigned int code);
|
|
|
|
|
|
|
|
// Store an abbrev code entry for CODE.
|
|
|
|
void
|
|
|
|
store_abbrev(unsigned int code, const Abbrev_code* entry)
|
|
|
|
{
|
|
|
|
if (code < this->low_abbrev_code_max_)
|
|
|
|
this->low_abbrev_codes_[code] = entry;
|
|
|
|
else
|
|
|
|
this->high_abbrev_codes_[code] = entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clear the abbrev code table and release the memory it uses.
|
|
|
|
void
|
|
|
|
clear_abbrev_codes();
|
|
|
|
|
|
|
|
typedef Unordered_map<unsigned int, const Abbrev_code*> Abbrev_code_table;
|
|
|
|
|
|
|
|
// The section index of the current abbrev table.
|
|
|
|
unsigned int abbrev_shndx_;
|
|
|
|
// The offset within the section of the current abbrev table.
|
|
|
|
off_t abbrev_offset_;
|
|
|
|
// The buffer containing the .debug_abbrev section.
|
|
|
|
const unsigned char* buffer_;
|
|
|
|
const unsigned char* buffer_end_;
|
|
|
|
// True if this object owns the buffer and needs to delete it.
|
|
|
|
bool owns_buffer_;
|
|
|
|
// Pointer to the current position in the buffer.
|
|
|
|
const unsigned char* buffer_pos_;
|
|
|
|
// The table of abbrev codes.
|
|
|
|
// We use a direct-lookup array for low abbrev codes,
|
|
|
|
// and store the rest in a hash table.
|
|
|
|
static const unsigned int low_abbrev_code_max_ = 256;
|
|
|
|
const Abbrev_code* low_abbrev_codes_[low_abbrev_code_max_];
|
|
|
|
Abbrev_code_table high_abbrev_codes_;
|
|
|
|
};
|
|
|
|
|
|
|
|
// A DWARF range list. The start and end offsets are relative
|
|
|
|
// to the input section SHNDX. Each range must lie entirely
|
|
|
|
// within a single section.
|
|
|
|
|
|
|
|
class Dwarf_range_list
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
struct Range
|
|
|
|
{
|
|
|
|
Range(unsigned int a_shndx, off_t a_start, off_t a_end)
|
|
|
|
: shndx(a_shndx), start(a_start), end(a_end)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
unsigned int shndx;
|
|
|
|
off_t start;
|
|
|
|
off_t end;
|
|
|
|
};
|
|
|
|
|
|
|
|
Dwarf_range_list()
|
|
|
|
: range_list_()
|
|
|
|
{ }
|
|
|
|
|
|
|
|
void
|
|
|
|
add(unsigned int shndx, off_t start, off_t end)
|
|
|
|
{ this->range_list_.push_back(Range(shndx, start, end)); }
|
|
|
|
|
|
|
|
size_t
|
|
|
|
size() const
|
|
|
|
{ return this->range_list_.size(); }
|
|
|
|
|
|
|
|
const Range&
|
|
|
|
operator[](off_t i) const
|
|
|
|
{ return this->range_list_[i]; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::vector<Range> range_list_;
|
|
|
|
};
|
|
|
|
|
|
|
|
// This class is used to read the ranges table from the
|
|
|
|
// .debug_ranges section of the object file.
|
|
|
|
|
|
|
|
class Dwarf_ranges_table
|
|
|
|
{
|
|
|
|
public:
|
2012-10-23 23:41:37 +02:00
|
|
|
Dwarf_ranges_table(Dwarf_info_reader* dwinfo)
|
|
|
|
: dwinfo_(dwinfo), ranges_shndx_(0), ranges_buffer_(NULL),
|
|
|
|
ranges_buffer_end_(NULL), owns_ranges_buffer_(false),
|
2013-07-01 22:12:11 +02:00
|
|
|
ranges_reloc_mapper_(NULL), reloc_type_(0), output_section_offset_(0)
|
2012-03-21 20:02:22 +01:00
|
|
|
{ }
|
|
|
|
|
|
|
|
~Dwarf_ranges_table()
|
|
|
|
{
|
|
|
|
if (this->owns_ranges_buffer_ && this->ranges_buffer_ != NULL)
|
|
|
|
delete[] this->ranges_buffer_;
|
|
|
|
if (this->ranges_reloc_mapper_ != NULL)
|
|
|
|
delete this->ranges_reloc_mapper_;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read the ranges table from an object file.
|
|
|
|
bool
|
|
|
|
read_ranges_table(Relobj* object,
|
|
|
|
const unsigned char* symtab,
|
|
|
|
off_t symtab_size,
|
|
|
|
unsigned int ranges_shndx);
|
|
|
|
|
|
|
|
// Read the range table from an object file.
|
|
|
|
Dwarf_range_list*
|
|
|
|
read_range_list(Relobj* object,
|
|
|
|
const unsigned char* symtab,
|
|
|
|
off_t symtab_size,
|
|
|
|
unsigned int address_size,
|
|
|
|
unsigned int ranges_shndx,
|
|
|
|
off_t ranges_offset);
|
|
|
|
|
2013-07-01 22:12:11 +02:00
|
|
|
// Look for a relocation at offset OFF in the range table,
|
|
|
|
// and return the section index and offset of the target.
|
|
|
|
unsigned int
|
|
|
|
lookup_reloc(off_t off, off_t* target_off);
|
|
|
|
|
2012-03-21 20:02:22 +01:00
|
|
|
private:
|
2012-10-23 23:41:37 +02:00
|
|
|
// The Dwarf_info_reader, for reading data.
|
|
|
|
Dwarf_info_reader* dwinfo_;
|
2012-03-21 20:02:22 +01:00
|
|
|
// The section index of the ranges table.
|
|
|
|
unsigned int ranges_shndx_;
|
|
|
|
// The buffer containing the .debug_ranges section.
|
|
|
|
const unsigned char* ranges_buffer_;
|
|
|
|
const unsigned char* ranges_buffer_end_;
|
|
|
|
// True if this object owns the buffer and needs to delete it.
|
|
|
|
bool owns_ranges_buffer_;
|
|
|
|
// Relocation mapper for the .debug_ranges section.
|
|
|
|
Elf_reloc_mapper* ranges_reloc_mapper_;
|
2013-07-01 22:12:11 +02:00
|
|
|
// Type of the relocation section (SHT_REL or SHT_RELA).
|
|
|
|
unsigned int reloc_type_;
|
2012-03-21 20:02:22 +01:00
|
|
|
// For incremental update links, this will hold the offset of the
|
|
|
|
// input section within the output section. Offsets read from
|
|
|
|
// relocated data will be relative to the output section, and need
|
|
|
|
// to be corrected before reading data from the input section.
|
|
|
|
uint64_t output_section_offset_;
|
|
|
|
};
|
|
|
|
|
|
|
|
// This class is used to read the pubnames and pubtypes tables from the
|
|
|
|
// .debug_pubnames and .debug_pubtypes sections of the object file.
|
|
|
|
|
|
|
|
class Dwarf_pubnames_table
|
|
|
|
{
|
|
|
|
public:
|
2012-10-23 23:41:37 +02:00
|
|
|
Dwarf_pubnames_table(Dwarf_info_reader* dwinfo, bool is_pubtypes)
|
|
|
|
: dwinfo_(dwinfo), buffer_(NULL), buffer_end_(NULL), owns_buffer_(false),
|
2014-01-29 00:35:47 +01:00
|
|
|
offset_size_(0), pinfo_(NULL), end_of_table_(NULL),
|
|
|
|
is_pubtypes_(is_pubtypes), is_gnu_style_(false),
|
2014-06-07 01:23:21 +02:00
|
|
|
unit_length_(0), cu_offset_(0)
|
2012-03-21 20:02:22 +01:00
|
|
|
{ }
|
|
|
|
|
|
|
|
~Dwarf_pubnames_table()
|
|
|
|
{
|
|
|
|
if (this->owns_buffer_ && this->buffer_ != NULL)
|
|
|
|
delete[] this->buffer_;
|
|
|
|
}
|
|
|
|
|
2013-07-22 Sterling Augustine <saugustine@google.com>
* dwarf_reader.cc (Dwarf_pubnames_table::read_section):
Convert parameter shndx to local variable. Add parameters symtab
and symtab_size. Scan over section names. Find relocation
section corresponding to current section. Create and initialize
reloc_mapper_ and reloc_type_.
(Dwarf_pubnames_table::read_header): Add assertion. Change
unit_length to off_t. Initialize member unit_length_. Fill in field
cu_offset_.
* dwarf_reader.h (Dwarf_pubnames_table::Dwarf_pubnames_table):
Initialize new fields unit_length_ and cu_offset_.
(Dwarf_pubnames_table::read_section): Update prototype.
(Dwarf_pubnames_table::cu_offset): New member function.
(Dwarf_pubnames_table::subsection_size): Likewise.
(Dwarf_pubnames_table::cu_offset_, Dwarf_pubnames_table::unit_length):
New fields.
(Dwarf_info_reader::symtab, Dwarf_info_reader::symtab_size): Make
member functions public.
* gdb_index.cc (Gdb_index_info_reader::read_pubnames_and_pubtypes):
Update comment. Rework logic. Move repeated parts to...
(Gdb_index_info_reader::read_pubtable): ...here. New function.
(Gdb_index::Gdb_index): Initialize new fields, pubnames_table_,
pubtypes_table_, and stmt_list_offset.
(Gdb_index::map_pubtable_to_dies, Gdb_index::find_pubname_offset,
Gdb_index::find_pubtype_offset,
Gdb_index::map_pubnames_and_types_to_dies): Define new functions.
(Gdb_index::pubnames_read): Update prototype and rework logic.
* gdb_index.h (Gdb_index_info_reader, Dwarf_pubnames_table):
Forward declare.
(Gdb_index::map_pubtable_to_dies, Gdb_index::find_pubname_offset,
Gdb_index::find_pubtype_offset, Gdb_index::pubnames_table)
Gdb_index::pubtypes_table, Gdb_index::map_pubnames_and_types_to_dies,
Gdb_index::map_pubtable_to_dies):
Declare functions.
(Gdb_index::pubnames_read): Update declaration.
(Gdb_index::Pubname_offset_map): New type.
(Gdb_index::cu_pubname_map_, Gdb_index::cu_pubtype_map_,
Gdb_index::pubnames_table_, Gdb_index::pubtypes_table_,
Gdb_index::stmt_list_offset): Declare.
(Gdb_index::pubnames_shndx_, Gdb_index::pubnames_offet_,
Gdb_index::pubtypes_object_, Gdb_index::pubtypes_shndx_)
Gdb_index::pubtypes_offset_): Remove.
2013-07-29 20:29:12 +02:00
|
|
|
// Read the pubnames section from the object file, using the symbol
|
|
|
|
// table for relocating it.
|
2012-03-21 20:02:22 +01:00
|
|
|
bool
|
2013-07-22 Sterling Augustine <saugustine@google.com>
* dwarf_reader.cc (Dwarf_pubnames_table::read_section):
Convert parameter shndx to local variable. Add parameters symtab
and symtab_size. Scan over section names. Find relocation
section corresponding to current section. Create and initialize
reloc_mapper_ and reloc_type_.
(Dwarf_pubnames_table::read_header): Add assertion. Change
unit_length to off_t. Initialize member unit_length_. Fill in field
cu_offset_.
* dwarf_reader.h (Dwarf_pubnames_table::Dwarf_pubnames_table):
Initialize new fields unit_length_ and cu_offset_.
(Dwarf_pubnames_table::read_section): Update prototype.
(Dwarf_pubnames_table::cu_offset): New member function.
(Dwarf_pubnames_table::subsection_size): Likewise.
(Dwarf_pubnames_table::cu_offset_, Dwarf_pubnames_table::unit_length):
New fields.
(Dwarf_info_reader::symtab, Dwarf_info_reader::symtab_size): Make
member functions public.
* gdb_index.cc (Gdb_index_info_reader::read_pubnames_and_pubtypes):
Update comment. Rework logic. Move repeated parts to...
(Gdb_index_info_reader::read_pubtable): ...here. New function.
(Gdb_index::Gdb_index): Initialize new fields, pubnames_table_,
pubtypes_table_, and stmt_list_offset.
(Gdb_index::map_pubtable_to_dies, Gdb_index::find_pubname_offset,
Gdb_index::find_pubtype_offset,
Gdb_index::map_pubnames_and_types_to_dies): Define new functions.
(Gdb_index::pubnames_read): Update prototype and rework logic.
* gdb_index.h (Gdb_index_info_reader, Dwarf_pubnames_table):
Forward declare.
(Gdb_index::map_pubtable_to_dies, Gdb_index::find_pubname_offset,
Gdb_index::find_pubtype_offset, Gdb_index::pubnames_table)
Gdb_index::pubtypes_table, Gdb_index::map_pubnames_and_types_to_dies,
Gdb_index::map_pubtable_to_dies):
Declare functions.
(Gdb_index::pubnames_read): Update declaration.
(Gdb_index::Pubname_offset_map): New type.
(Gdb_index::cu_pubname_map_, Gdb_index::cu_pubtype_map_,
Gdb_index::pubnames_table_, Gdb_index::pubtypes_table_,
Gdb_index::stmt_list_offset): Declare.
(Gdb_index::pubnames_shndx_, Gdb_index::pubnames_offet_,
Gdb_index::pubtypes_object_, Gdb_index::pubtypes_shndx_)
Gdb_index::pubtypes_offset_): Remove.
2013-07-29 20:29:12 +02:00
|
|
|
read_section(Relobj* object, const unsigned char* symbol_table,
|
|
|
|
off_t symtab_size);
|
2012-03-21 20:02:22 +01:00
|
|
|
|
|
|
|
// Read the header for the set at OFFSET.
|
|
|
|
bool
|
|
|
|
read_header(off_t offset);
|
|
|
|
|
2013-07-22 Sterling Augustine <saugustine@google.com>
* dwarf_reader.cc (Dwarf_pubnames_table::read_section):
Convert parameter shndx to local variable. Add parameters symtab
and symtab_size. Scan over section names. Find relocation
section corresponding to current section. Create and initialize
reloc_mapper_ and reloc_type_.
(Dwarf_pubnames_table::read_header): Add assertion. Change
unit_length to off_t. Initialize member unit_length_. Fill in field
cu_offset_.
* dwarf_reader.h (Dwarf_pubnames_table::Dwarf_pubnames_table):
Initialize new fields unit_length_ and cu_offset_.
(Dwarf_pubnames_table::read_section): Update prototype.
(Dwarf_pubnames_table::cu_offset): New member function.
(Dwarf_pubnames_table::subsection_size): Likewise.
(Dwarf_pubnames_table::cu_offset_, Dwarf_pubnames_table::unit_length):
New fields.
(Dwarf_info_reader::symtab, Dwarf_info_reader::symtab_size): Make
member functions public.
* gdb_index.cc (Gdb_index_info_reader::read_pubnames_and_pubtypes):
Update comment. Rework logic. Move repeated parts to...
(Gdb_index_info_reader::read_pubtable): ...here. New function.
(Gdb_index::Gdb_index): Initialize new fields, pubnames_table_,
pubtypes_table_, and stmt_list_offset.
(Gdb_index::map_pubtable_to_dies, Gdb_index::find_pubname_offset,
Gdb_index::find_pubtype_offset,
Gdb_index::map_pubnames_and_types_to_dies): Define new functions.
(Gdb_index::pubnames_read): Update prototype and rework logic.
* gdb_index.h (Gdb_index_info_reader, Dwarf_pubnames_table):
Forward declare.
(Gdb_index::map_pubtable_to_dies, Gdb_index::find_pubname_offset,
Gdb_index::find_pubtype_offset, Gdb_index::pubnames_table)
Gdb_index::pubtypes_table, Gdb_index::map_pubnames_and_types_to_dies,
Gdb_index::map_pubtable_to_dies):
Declare functions.
(Gdb_index::pubnames_read): Update declaration.
(Gdb_index::Pubname_offset_map): New type.
(Gdb_index::cu_pubname_map_, Gdb_index::cu_pubtype_map_,
Gdb_index::pubnames_table_, Gdb_index::pubtypes_table_,
Gdb_index::stmt_list_offset): Declare.
(Gdb_index::pubnames_shndx_, Gdb_index::pubnames_offet_,
Gdb_index::pubtypes_object_, Gdb_index::pubtypes_shndx_)
Gdb_index::pubtypes_offset_): Remove.
2013-07-29 20:29:12 +02:00
|
|
|
// Return the offset to the cu within the info or types section.
|
|
|
|
off_t
|
|
|
|
cu_offset()
|
|
|
|
{ return this->cu_offset_; }
|
|
|
|
|
|
|
|
// Return the size of this subsection of the table. The unit length
|
|
|
|
// doesn't include the size of its own field.
|
|
|
|
off_t
|
|
|
|
subsection_size()
|
|
|
|
{ return this->unit_length_; }
|
|
|
|
|
2014-01-29 00:35:47 +01:00
|
|
|
// Read the next name from the set. If the pubname table is gnu-style,
|
|
|
|
// FLAG_BYTE is set to the high-byte of a gdb_index version 7 cu_index.
|
2012-03-21 20:02:22 +01:00
|
|
|
const char*
|
2014-01-29 00:35:47 +01:00
|
|
|
next_name(uint8_t* flag_byte);
|
2012-03-21 20:02:22 +01:00
|
|
|
|
|
|
|
private:
|
2012-10-23 23:41:37 +02:00
|
|
|
// The Dwarf_info_reader, for reading data.
|
|
|
|
Dwarf_info_reader* dwinfo_;
|
2012-03-21 20:02:22 +01:00
|
|
|
// The buffer containing the .debug_ranges section.
|
|
|
|
const unsigned char* buffer_;
|
|
|
|
const unsigned char* buffer_end_;
|
|
|
|
// True if this object owns the buffer and needs to delete it.
|
|
|
|
bool owns_buffer_;
|
|
|
|
// The size of a DWARF offset for the current set.
|
|
|
|
unsigned int offset_size_;
|
|
|
|
// The current position within the buffer.
|
|
|
|
const unsigned char* pinfo_;
|
2014-01-29 00:35:47 +01:00
|
|
|
// The end of the current pubnames table.
|
|
|
|
const unsigned char* end_of_table_;
|
2012-03-21 20:02:22 +01:00
|
|
|
// TRUE if this is a .debug_pubtypes section.
|
|
|
|
bool is_pubtypes_;
|
2014-01-29 00:35:47 +01:00
|
|
|
// Gnu-style pubnames table. This style has an extra flag byte between the
|
|
|
|
// offset and the name, and is used for generating version 7 of gdb-index.
|
|
|
|
bool is_gnu_style_;
|
2013-07-22 Sterling Augustine <saugustine@google.com>
* dwarf_reader.cc (Dwarf_pubnames_table::read_section):
Convert parameter shndx to local variable. Add parameters symtab
and symtab_size. Scan over section names. Find relocation
section corresponding to current section. Create and initialize
reloc_mapper_ and reloc_type_.
(Dwarf_pubnames_table::read_header): Add assertion. Change
unit_length to off_t. Initialize member unit_length_. Fill in field
cu_offset_.
* dwarf_reader.h (Dwarf_pubnames_table::Dwarf_pubnames_table):
Initialize new fields unit_length_ and cu_offset_.
(Dwarf_pubnames_table::read_section): Update prototype.
(Dwarf_pubnames_table::cu_offset): New member function.
(Dwarf_pubnames_table::subsection_size): Likewise.
(Dwarf_pubnames_table::cu_offset_, Dwarf_pubnames_table::unit_length):
New fields.
(Dwarf_info_reader::symtab, Dwarf_info_reader::symtab_size): Make
member functions public.
* gdb_index.cc (Gdb_index_info_reader::read_pubnames_and_pubtypes):
Update comment. Rework logic. Move repeated parts to...
(Gdb_index_info_reader::read_pubtable): ...here. New function.
(Gdb_index::Gdb_index): Initialize new fields, pubnames_table_,
pubtypes_table_, and stmt_list_offset.
(Gdb_index::map_pubtable_to_dies, Gdb_index::find_pubname_offset,
Gdb_index::find_pubtype_offset,
Gdb_index::map_pubnames_and_types_to_dies): Define new functions.
(Gdb_index::pubnames_read): Update prototype and rework logic.
* gdb_index.h (Gdb_index_info_reader, Dwarf_pubnames_table):
Forward declare.
(Gdb_index::map_pubtable_to_dies, Gdb_index::find_pubname_offset,
Gdb_index::find_pubtype_offset, Gdb_index::pubnames_table)
Gdb_index::pubtypes_table, Gdb_index::map_pubnames_and_types_to_dies,
Gdb_index::map_pubtable_to_dies):
Declare functions.
(Gdb_index::pubnames_read): Update declaration.
(Gdb_index::Pubname_offset_map): New type.
(Gdb_index::cu_pubname_map_, Gdb_index::cu_pubtype_map_,
Gdb_index::pubnames_table_, Gdb_index::pubtypes_table_,
Gdb_index::stmt_list_offset): Declare.
(Gdb_index::pubnames_shndx_, Gdb_index::pubnames_offet_,
Gdb_index::pubtypes_object_, Gdb_index::pubtypes_shndx_)
Gdb_index::pubtypes_offset_): Remove.
2013-07-29 20:29:12 +02:00
|
|
|
// Fields read from the header.
|
|
|
|
uint64_t unit_length_;
|
|
|
|
off_t cu_offset_;
|
|
|
|
|
|
|
|
// Track relocations for this table so we can find the CUs that
|
|
|
|
// correspond to the subsections.
|
|
|
|
Elf_reloc_mapper* reloc_mapper_;
|
|
|
|
// Type of the relocation section (SHT_REL or SHT_RELA).
|
|
|
|
unsigned int reloc_type_;
|
2012-03-21 20:02:22 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// This class represents a DWARF Debug Info Entry (DIE).
|
|
|
|
|
|
|
|
class Dwarf_die
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// An attribute value.
|
|
|
|
struct Attribute_value
|
|
|
|
{
|
|
|
|
unsigned int attr;
|
|
|
|
unsigned int form;
|
|
|
|
union
|
|
|
|
{
|
|
|
|
int64_t intval;
|
|
|
|
uint64_t uintval;
|
|
|
|
const char* stringval;
|
|
|
|
const unsigned char* blockval;
|
|
|
|
off_t refval;
|
|
|
|
} val;
|
|
|
|
union
|
|
|
|
{
|
|
|
|
// Section index for reference forms.
|
|
|
|
unsigned int shndx;
|
|
|
|
// Block length for block forms.
|
|
|
|
unsigned int blocklen;
|
|
|
|
// Attribute offset for DW_FORM_strp.
|
|
|
|
unsigned int attr_off;
|
|
|
|
} aux;
|
|
|
|
};
|
|
|
|
|
|
|
|
// A list of attribute values.
|
|
|
|
typedef std::vector<Attribute_value> Attributes;
|
|
|
|
|
|
|
|
Dwarf_die(Dwarf_info_reader* dwinfo,
|
|
|
|
off_t die_offset,
|
|
|
|
Dwarf_die* parent);
|
|
|
|
|
|
|
|
// Return the DWARF tag for this DIE.
|
|
|
|
unsigned int
|
|
|
|
tag() const
|
|
|
|
{
|
|
|
|
if (this->abbrev_code_ == NULL)
|
|
|
|
return 0;
|
|
|
|
return this->abbrev_code_->tag;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return true if this DIE has children.
|
|
|
|
bool
|
|
|
|
has_children() const
|
|
|
|
{
|
|
|
|
gold_assert(this->abbrev_code_ != NULL);
|
|
|
|
return this->abbrev_code_->has_children;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return true if this DIE has a sibling attribute.
|
|
|
|
bool
|
|
|
|
has_sibling_attribute() const
|
|
|
|
{
|
|
|
|
gold_assert(this->abbrev_code_ != NULL);
|
|
|
|
return this->abbrev_code_->has_sibling_attribute;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return the value of attribute ATTR.
|
|
|
|
const Attribute_value*
|
|
|
|
attribute(unsigned int attr);
|
|
|
|
|
|
|
|
// Return the value of the DW_AT_name attribute.
|
|
|
|
const char*
|
|
|
|
name()
|
|
|
|
{
|
|
|
|
if (this->name_ == NULL)
|
|
|
|
this->set_name();
|
|
|
|
return this->name_;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return the value of the DW_AT_linkage_name
|
|
|
|
// or DW_AT_MIPS_linkage_name attribute.
|
|
|
|
const char*
|
|
|
|
linkage_name()
|
|
|
|
{
|
|
|
|
if (this->linkage_name_ == NULL)
|
|
|
|
this->set_linkage_name();
|
|
|
|
return this->linkage_name_;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return the value of the DW_AT_specification attribute.
|
|
|
|
off_t
|
|
|
|
specification()
|
|
|
|
{
|
|
|
|
if (!this->attributes_read_)
|
|
|
|
this->read_attributes();
|
|
|
|
return this->specification_;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return the value of the DW_AT_abstract_origin attribute.
|
|
|
|
off_t
|
|
|
|
abstract_origin()
|
|
|
|
{
|
|
|
|
if (!this->attributes_read_)
|
|
|
|
this->read_attributes();
|
|
|
|
return this->abstract_origin_;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return the value of attribute ATTR as a string.
|
|
|
|
const char*
|
|
|
|
string_attribute(unsigned int attr);
|
|
|
|
|
|
|
|
// Return the value of attribute ATTR as an integer.
|
|
|
|
int64_t
|
|
|
|
int_attribute(unsigned int attr);
|
|
|
|
|
|
|
|
// Return the value of attribute ATTR as an unsigned integer.
|
|
|
|
uint64_t
|
|
|
|
uint_attribute(unsigned int attr);
|
|
|
|
|
|
|
|
// Return the value of attribute ATTR as a reference.
|
|
|
|
off_t
|
2012-05-01 21:12:21 +02:00
|
|
|
ref_attribute(unsigned int attr, unsigned int* shndx);
|
|
|
|
|
|
|
|
// Return the value of attribute ATTR as a address.
|
|
|
|
off_t
|
|
|
|
address_attribute(unsigned int attr, unsigned int* shndx);
|
2012-03-21 20:02:22 +01:00
|
|
|
|
|
|
|
// Return the value of attribute ATTR as a flag.
|
|
|
|
bool
|
|
|
|
flag_attribute(unsigned int attr)
|
|
|
|
{ return this->int_attribute(attr) != 0; }
|
|
|
|
|
|
|
|
// Return true if this DIE is a declaration.
|
|
|
|
bool
|
|
|
|
is_declaration()
|
|
|
|
{ return this->flag_attribute(elfcpp::DW_AT_declaration); }
|
|
|
|
|
|
|
|
// Return the parent of this DIE.
|
|
|
|
Dwarf_die*
|
|
|
|
parent() const
|
|
|
|
{ return this->parent_; }
|
|
|
|
|
|
|
|
// Return the offset of this DIE.
|
|
|
|
off_t
|
|
|
|
offset() const
|
|
|
|
{ return this->die_offset_; }
|
|
|
|
|
|
|
|
// Return the offset of this DIE's first child.
|
|
|
|
off_t
|
|
|
|
child_offset();
|
|
|
|
|
|
|
|
// Set the offset of this DIE's next sibling.
|
|
|
|
void
|
|
|
|
set_sibling_offset(off_t sibling_offset)
|
|
|
|
{ this->sibling_offset_ = sibling_offset; }
|
|
|
|
|
|
|
|
// Return the offset of this DIE's next sibling.
|
|
|
|
off_t
|
|
|
|
sibling_offset();
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef Dwarf_abbrev_table::Abbrev_code Abbrev_code;
|
|
|
|
|
|
|
|
// Read all the attributes of the DIE.
|
|
|
|
bool
|
|
|
|
read_attributes();
|
|
|
|
|
|
|
|
// Set the name of the DIE if present.
|
|
|
|
void
|
|
|
|
set_name();
|
|
|
|
|
|
|
|
// Set the linkage name if present.
|
|
|
|
void
|
|
|
|
set_linkage_name();
|
|
|
|
|
|
|
|
// Skip all the attributes of the DIE and return the offset
|
|
|
|
// of the next DIE.
|
|
|
|
off_t
|
|
|
|
skip_attributes();
|
|
|
|
|
|
|
|
// The Dwarf_info_reader, for reading attributes.
|
|
|
|
Dwarf_info_reader* dwinfo_;
|
|
|
|
// The parent of this DIE.
|
|
|
|
Dwarf_die* parent_;
|
|
|
|
// Offset of this DIE within its compilation unit.
|
|
|
|
off_t die_offset_;
|
|
|
|
// Offset of the first attribute, relative to the beginning of the DIE.
|
|
|
|
off_t attr_offset_;
|
|
|
|
// Offset of the first child, relative to the compilation unit.
|
|
|
|
off_t child_offset_;
|
|
|
|
// Offset of the next sibling, relative to the compilation unit.
|
|
|
|
off_t sibling_offset_;
|
|
|
|
// The abbreviation table entry.
|
|
|
|
const Abbrev_code* abbrev_code_;
|
|
|
|
// The list of attributes.
|
|
|
|
Attributes attributes_;
|
|
|
|
// True if the attributes have been read.
|
|
|
|
bool attributes_read_;
|
|
|
|
// The following fields hold common attributes to avoid a linear
|
|
|
|
// search through the attribute list.
|
|
|
|
// The DIE name (DW_AT_name).
|
|
|
|
const char* name_;
|
|
|
|
// Offset of the name in the string table (for DW_FORM_strp).
|
|
|
|
off_t name_off_;
|
|
|
|
// The linkage name (DW_AT_linkage_name or DW_AT_MIPS_linkage_name).
|
|
|
|
const char* linkage_name_;
|
|
|
|
// Offset of the linkage name in the string table (for DW_FORM_strp).
|
|
|
|
off_t linkage_name_off_;
|
|
|
|
// Section index of the string table (for DW_FORM_strp).
|
|
|
|
unsigned int string_shndx_;
|
|
|
|
// The value of a DW_AT_specification attribute.
|
|
|
|
off_t specification_;
|
|
|
|
// The value of a DW_AT_abstract_origin attribute.
|
|
|
|
off_t abstract_origin_;
|
|
|
|
};
|
|
|
|
|
|
|
|
// This class is used to read the debug info from the .debug_info
|
|
|
|
// or .debug_types sections. This is a base class that implements
|
|
|
|
// the generic parsing of the compilation unit header and DIE
|
|
|
|
// structure. The parse() method parses the entire section, and
|
|
|
|
// calls the various visit_xxx() methods for each header. Clients
|
|
|
|
// should derive a new class from this one and implement the
|
|
|
|
// visit_compilation_unit() and visit_type_unit() functions.
|
|
|
|
|
|
|
|
class Dwarf_info_reader
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Dwarf_info_reader(bool is_type_unit,
|
|
|
|
Relobj* object,
|
|
|
|
const unsigned char* symtab,
|
|
|
|
off_t symtab_size,
|
|
|
|
unsigned int shndx,
|
|
|
|
unsigned int reloc_shndx,
|
|
|
|
unsigned int reloc_type)
|
|
|
|
: is_type_unit_(is_type_unit), object_(object), symtab_(symtab),
|
|
|
|
symtab_size_(symtab_size), shndx_(shndx), reloc_shndx_(reloc_shndx),
|
2012-10-23 23:37:26 +02:00
|
|
|
reloc_type_(reloc_type), abbrev_shndx_(0), string_shndx_(0),
|
|
|
|
buffer_(NULL), buffer_end_(NULL), cu_offset_(0), cu_length_(0),
|
2013-10-11 23:11:49 +02:00
|
|
|
offset_size_(0), address_size_(0), cu_version_(0),
|
|
|
|
abbrev_table_(), ranges_table_(this),
|
2012-10-23 23:41:37 +02:00
|
|
|
reloc_mapper_(NULL), string_buffer_(NULL), string_buffer_end_(NULL),
|
2012-10-23 23:37:26 +02:00
|
|
|
owns_string_buffer_(false), string_output_section_offset_(0)
|
2012-03-21 20:02:22 +01:00
|
|
|
{ }
|
|
|
|
|
|
|
|
virtual
|
|
|
|
~Dwarf_info_reader()
|
|
|
|
{
|
|
|
|
if (this->reloc_mapper_ != NULL)
|
|
|
|
delete this->reloc_mapper_;
|
|
|
|
if (this->owns_string_buffer_ && this->string_buffer_ != NULL)
|
|
|
|
delete[] this->string_buffer_;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Begin parsing the debug info. This calls visit_compilation_unit()
|
|
|
|
// or visit_type_unit() for each compilation or type unit found in the
|
|
|
|
// section, and visit_die() for each top-level DIE.
|
|
|
|
void
|
|
|
|
parse();
|
|
|
|
|
|
|
|
// Return the abbrev code entry for a CODE.
|
|
|
|
const Dwarf_abbrev_table::Abbrev_code*
|
|
|
|
get_abbrev(unsigned int code)
|
|
|
|
{ return this->abbrev_table_.get_abbrev(code); }
|
|
|
|
|
|
|
|
// Return a pointer to the DWARF info buffer at OFFSET.
|
|
|
|
const unsigned char*
|
|
|
|
buffer_at_offset(off_t offset) const
|
|
|
|
{
|
|
|
|
const unsigned char* p = this->buffer_ + this->cu_offset_ + offset;
|
|
|
|
if (this->check_buffer(p + 1))
|
|
|
|
return p;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-10-23 23:41:37 +02:00
|
|
|
// Read a possibly unaligned integer of SIZE.
|
|
|
|
template <int valsize>
|
|
|
|
inline typename elfcpp::Valtype_base<valsize>::Valtype
|
|
|
|
read_from_pointer(const unsigned char* source);
|
|
|
|
|
|
|
|
// Read a possibly unaligned integer of SIZE. Update SOURCE after read.
|
|
|
|
template <int valsize>
|
|
|
|
inline typename elfcpp::Valtype_base<valsize>::Valtype
|
|
|
|
read_from_pointer(const unsigned char** source);
|
|
|
|
|
2012-03-21 20:02:22 +01:00
|
|
|
// Look for a relocation at offset ATTR_OFF in the dwarf info,
|
|
|
|
// and return the section index and offset of the target.
|
|
|
|
unsigned int
|
|
|
|
lookup_reloc(off_t attr_off, off_t* target_off);
|
|
|
|
|
|
|
|
// Return a string from the DWARF string table.
|
|
|
|
const char*
|
|
|
|
get_string(off_t str_off, unsigned int string_shndx);
|
|
|
|
|
|
|
|
// Return the size of a DWARF offset.
|
|
|
|
unsigned int
|
|
|
|
offset_size() const
|
|
|
|
{ return this->offset_size_; }
|
|
|
|
|
|
|
|
// Return the size of an address.
|
|
|
|
unsigned int
|
|
|
|
address_size() const
|
|
|
|
{ return this->address_size_; }
|
|
|
|
|
2017-11-20 02:56:30 +01:00
|
|
|
// Return the size of a DW_FORM_ref_addr.
|
|
|
|
// In DWARF v2, this was the size of an address; in DWARF v3 and later,
|
|
|
|
// it is the size of an DWARF offset.
|
|
|
|
unsigned int
|
|
|
|
ref_addr_size() const
|
|
|
|
{ return this->cu_version_ > 2 ? this->offset_size_ : this->address_size_; }
|
|
|
|
|
2012-10-23 23:37:26 +02:00
|
|
|
// Set the section index of the .debug_abbrev section.
|
|
|
|
// We use this if there are no relocations for the .debug_info section.
|
|
|
|
// If not set, the code parse() routine will search for the section by name.
|
|
|
|
void
|
|
|
|
set_abbrev_shndx(unsigned int abbrev_shndx)
|
|
|
|
{ this->abbrev_shndx_ = abbrev_shndx; }
|
|
|
|
|
2013-07-22 Sterling Augustine <saugustine@google.com>
* dwarf_reader.cc (Dwarf_pubnames_table::read_section):
Convert parameter shndx to local variable. Add parameters symtab
and symtab_size. Scan over section names. Find relocation
section corresponding to current section. Create and initialize
reloc_mapper_ and reloc_type_.
(Dwarf_pubnames_table::read_header): Add assertion. Change
unit_length to off_t. Initialize member unit_length_. Fill in field
cu_offset_.
* dwarf_reader.h (Dwarf_pubnames_table::Dwarf_pubnames_table):
Initialize new fields unit_length_ and cu_offset_.
(Dwarf_pubnames_table::read_section): Update prototype.
(Dwarf_pubnames_table::cu_offset): New member function.
(Dwarf_pubnames_table::subsection_size): Likewise.
(Dwarf_pubnames_table::cu_offset_, Dwarf_pubnames_table::unit_length):
New fields.
(Dwarf_info_reader::symtab, Dwarf_info_reader::symtab_size): Make
member functions public.
* gdb_index.cc (Gdb_index_info_reader::read_pubnames_and_pubtypes):
Update comment. Rework logic. Move repeated parts to...
(Gdb_index_info_reader::read_pubtable): ...here. New function.
(Gdb_index::Gdb_index): Initialize new fields, pubnames_table_,
pubtypes_table_, and stmt_list_offset.
(Gdb_index::map_pubtable_to_dies, Gdb_index::find_pubname_offset,
Gdb_index::find_pubtype_offset,
Gdb_index::map_pubnames_and_types_to_dies): Define new functions.
(Gdb_index::pubnames_read): Update prototype and rework logic.
* gdb_index.h (Gdb_index_info_reader, Dwarf_pubnames_table):
Forward declare.
(Gdb_index::map_pubtable_to_dies, Gdb_index::find_pubname_offset,
Gdb_index::find_pubtype_offset, Gdb_index::pubnames_table)
Gdb_index::pubtypes_table, Gdb_index::map_pubnames_and_types_to_dies,
Gdb_index::map_pubtable_to_dies):
Declare functions.
(Gdb_index::pubnames_read): Update declaration.
(Gdb_index::Pubname_offset_map): New type.
(Gdb_index::cu_pubname_map_, Gdb_index::cu_pubtype_map_,
Gdb_index::pubnames_table_, Gdb_index::pubtypes_table_,
Gdb_index::stmt_list_offset): Declare.
(Gdb_index::pubnames_shndx_, Gdb_index::pubnames_offet_,
Gdb_index::pubtypes_object_, Gdb_index::pubtypes_shndx_)
Gdb_index::pubtypes_offset_): Remove.
2013-07-29 20:29:12 +02:00
|
|
|
// Return a pointer to the object file's ELF symbol table.
|
|
|
|
const unsigned char*
|
|
|
|
symtab() const
|
|
|
|
{ return this->symtab_; }
|
|
|
|
|
|
|
|
// Return the size of the object file's ELF symbol table.
|
|
|
|
off_t
|
|
|
|
symtab_size() const
|
|
|
|
{ return this->symtab_size_; }
|
|
|
|
|
|
|
|
// Return the offset of the current compilation unit.
|
|
|
|
off_t
|
|
|
|
cu_offset() const
|
|
|
|
{ return this->cu_offset_; }
|
|
|
|
|
2012-03-21 20:02:22 +01:00
|
|
|
protected:
|
|
|
|
// Begin parsing the debug info. This calls visit_compilation_unit()
|
|
|
|
// or visit_type_unit() for each compilation or type unit found in the
|
|
|
|
// section, and visit_die() for each top-level DIE.
|
|
|
|
template<bool big_endian>
|
|
|
|
void
|
|
|
|
do_parse();
|
|
|
|
|
|
|
|
// The following methods are hooks that are meant to be implemented
|
|
|
|
// by a derived class. A default, do-nothing, implementation of
|
|
|
|
// each is provided for this base class.
|
|
|
|
|
|
|
|
// Visit a compilation unit.
|
|
|
|
virtual void
|
|
|
|
visit_compilation_unit(off_t cu_offset, off_t cu_length, Dwarf_die* root_die);
|
|
|
|
|
|
|
|
// Visit a type unit.
|
|
|
|
virtual void
|
2013-10-31 19:43:23 +01:00
|
|
|
visit_type_unit(off_t tu_offset, off_t tu_length, off_t type_offset,
|
|
|
|
uint64_t signature, Dwarf_die* root_die);
|
2012-03-21 20:02:22 +01:00
|
|
|
|
|
|
|
// Read the range table.
|
|
|
|
Dwarf_range_list*
|
|
|
|
read_range_list(unsigned int ranges_shndx, off_t ranges_offset)
|
|
|
|
{
|
|
|
|
return this->ranges_table_.read_range_list(this->object_,
|
|
|
|
this->symtab_,
|
|
|
|
this->symtab_size_,
|
|
|
|
this->address_size_,
|
|
|
|
ranges_shndx,
|
|
|
|
ranges_offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return the object.
|
|
|
|
Relobj*
|
|
|
|
object() const
|
|
|
|
{ return this->object_; }
|
|
|
|
|
|
|
|
// Checkpoint the relocation tracker.
|
|
|
|
uint64_t
|
|
|
|
get_reloc_checkpoint() const
|
|
|
|
{ return this->reloc_mapper_->checkpoint(); }
|
|
|
|
|
|
|
|
// Reset the relocation tracker to the CHECKPOINT.
|
|
|
|
void
|
|
|
|
reset_relocs(uint64_t checkpoint)
|
|
|
|
{ this->reloc_mapper_->reset(checkpoint); }
|
|
|
|
|
|
|
|
private:
|
2013-03-01 23:53:02 +01:00
|
|
|
// Print a warning about a corrupt debug section.
|
|
|
|
void
|
|
|
|
warn_corrupt_debug_section() const;
|
|
|
|
|
2012-03-21 20:02:22 +01:00
|
|
|
// Check that P is within the bounds of the current section.
|
|
|
|
bool
|
2013-03-01 23:53:02 +01:00
|
|
|
check_buffer(const unsigned char* p) const
|
|
|
|
{
|
|
|
|
if (p > this->buffer_ + this->cu_offset_ + this->cu_length_)
|
|
|
|
{
|
|
|
|
this->warn_corrupt_debug_section();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2012-03-21 20:02:22 +01:00
|
|
|
|
|
|
|
// Read the DWARF string table.
|
|
|
|
bool
|
|
|
|
read_string_table(unsigned int string_shndx)
|
|
|
|
{
|
|
|
|
// If we've already read this string table, return immediately.
|
|
|
|
if (this->string_shndx_ > 0 && this->string_shndx_ == string_shndx)
|
|
|
|
return true;
|
|
|
|
if (string_shndx == 0 && this->string_shndx_ > 0)
|
|
|
|
return true;
|
|
|
|
return this->do_read_string_table(string_shndx);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
do_read_string_table(unsigned int string_shndx);
|
|
|
|
|
|
|
|
// True if this is a type unit; false for a compilation unit.
|
|
|
|
bool is_type_unit_;
|
|
|
|
// The object containing the .debug_info or .debug_types input section.
|
|
|
|
Relobj* object_;
|
|
|
|
// The ELF symbol table.
|
|
|
|
const unsigned char* symtab_;
|
|
|
|
// The size of the ELF symbol table.
|
|
|
|
off_t symtab_size_;
|
|
|
|
// Index of the .debug_info or .debug_types section.
|
|
|
|
unsigned int shndx_;
|
|
|
|
// Index of the relocation section.
|
|
|
|
unsigned int reloc_shndx_;
|
|
|
|
// Type of the relocation section (SHT_REL or SHT_RELA).
|
|
|
|
unsigned int reloc_type_;
|
2012-10-23 23:37:26 +02:00
|
|
|
// Index of the .debug_abbrev section (0 if not known).
|
|
|
|
unsigned int abbrev_shndx_;
|
2012-03-21 20:02:22 +01:00
|
|
|
// Index of the .debug_str section.
|
|
|
|
unsigned int string_shndx_;
|
|
|
|
// The buffer for the debug info.
|
|
|
|
const unsigned char* buffer_;
|
|
|
|
const unsigned char* buffer_end_;
|
|
|
|
// Offset of the current compilation unit.
|
|
|
|
off_t cu_offset_;
|
|
|
|
// Length of the current compilation unit.
|
|
|
|
off_t cu_length_;
|
|
|
|
// Size of a DWARF offset for the current compilation unit.
|
|
|
|
unsigned int offset_size_;
|
|
|
|
// Size of an address for the target architecture.
|
|
|
|
unsigned int address_size_;
|
|
|
|
// Compilation unit version number.
|
|
|
|
unsigned int cu_version_;
|
|
|
|
// Abbreviations table for current compilation unit.
|
|
|
|
Dwarf_abbrev_table abbrev_table_;
|
|
|
|
// Ranges table for the current compilation unit.
|
|
|
|
Dwarf_ranges_table ranges_table_;
|
|
|
|
// Relocation mapper for the section.
|
|
|
|
Elf_reloc_mapper* reloc_mapper_;
|
|
|
|
// The buffer for the debug string table.
|
|
|
|
const char* string_buffer_;
|
|
|
|
const char* string_buffer_end_;
|
|
|
|
// True if this object owns the buffer and needs to delete it.
|
|
|
|
bool owns_string_buffer_;
|
|
|
|
// For incremental update links, this will hold the offset of the
|
|
|
|
// input .debug_str section within the output section. Offsets read
|
|
|
|
// from relocated data will be relative to the output section, and need
|
|
|
|
// to be corrected before reading data from the input section.
|
|
|
|
uint64_t string_output_section_offset_;
|
|
|
|
};
|
|
|
|
|
2007-11-28 19:01:06 +01:00
|
|
|
// We can't do better than to keep the offsets in a sorted vector.
|
|
|
|
// Here, offset is the key, and file_num/line_num is the value.
|
|
|
|
struct Offset_to_lineno_entry
|
|
|
|
{
|
|
|
|
off_t offset;
|
|
|
|
int header_num; // which file-list to use (i.e. which .o file are we in)
|
2011-03-10 02:31:33 +01:00
|
|
|
// A pointer into files_.
|
|
|
|
unsigned int file_num : sizeof(int) * CHAR_BIT - 1;
|
|
|
|
// True if this was the last entry for the current offset, meaning
|
|
|
|
// it's the line that actually applies.
|
|
|
|
unsigned int last_line_for_offset : 1;
|
|
|
|
// The line number in the source file. -1 to indicate end-of-function.
|
|
|
|
int line_num;
|
|
|
|
|
|
|
|
// This sorts by offsets first, and then puts the correct line to
|
|
|
|
// report for a given offset at the beginning of the run of equal
|
|
|
|
// offsets (so that asking for 1 line gives the best answer). This
|
|
|
|
// is not a total ordering.
|
2007-11-28 19:01:06 +01:00
|
|
|
bool operator<(const Offset_to_lineno_entry& that) const
|
2011-03-10 02:31:33 +01:00
|
|
|
{
|
|
|
|
if (this->offset != that.offset)
|
|
|
|
return this->offset < that.offset;
|
|
|
|
// Note the '>' which makes this sort 'true' first.
|
|
|
|
return this->last_line_for_offset > that.last_line_for_offset;
|
|
|
|
}
|
2007-11-28 19:01:06 +01:00
|
|
|
};
|
|
|
|
|
2007-11-03 00:02:44 +01:00
|
|
|
// This class is used to read the line information from the debugging
|
|
|
|
// section of an object file.
|
|
|
|
|
|
|
|
class Dwarf_line_info
|
|
|
|
{
|
|
|
|
public:
|
2007-11-14 02:03:01 +01:00
|
|
|
Dwarf_line_info()
|
|
|
|
{ }
|
|
|
|
|
|
|
|
virtual
|
|
|
|
~Dwarf_line_info()
|
|
|
|
{ }
|
2007-11-03 00:02:44 +01:00
|
|
|
|
|
|
|
// Given a section number and an offset, returns the associated
|
|
|
|
// file and line-number, as a string: "file:lineno". If unable
|
|
|
|
// to do the mapping, returns the empty string. You must call
|
2011-03-10 02:31:33 +01:00
|
|
|
// read_line_mappings() before calling this function. If
|
|
|
|
// 'other_lines' is non-NULL, fills that in with other line
|
|
|
|
// numbers assigned to the same offset.
|
2007-11-03 00:02:44 +01:00
|
|
|
std::string
|
2011-03-10 02:31:33 +01:00
|
|
|
addr2line(unsigned int shndx, off_t offset,
|
|
|
|
std::vector<std::string>* other_lines)
|
|
|
|
{ return this->do_addr2line(shndx, offset, other_lines); }
|
2007-11-14 02:03:01 +01:00
|
|
|
|
2008-05-01 02:25:33 +02:00
|
|
|
// A helper function for a single addr2line lookup. It also keeps a
|
|
|
|
// cache of the last CACHE_SIZE Dwarf_line_info objects it created;
|
|
|
|
// set to 0 not to cache at all. The larger CACHE_SIZE is, the more
|
|
|
|
// chance this routine won't have to re-create a Dwarf_line_info
|
|
|
|
// object for its addr2line computation; such creations are slow.
|
|
|
|
// NOTE: Not thread-safe, so only call from one thread at a time.
|
2007-11-14 02:03:01 +01:00
|
|
|
static std::string
|
2008-05-01 02:25:33 +02:00
|
|
|
one_addr2line(Object* object, unsigned int shndx, off_t offset,
|
2011-03-10 02:31:33 +01:00
|
|
|
size_t cache_size, std::vector<std::string>* other_lines);
|
2008-05-01 02:25:33 +02:00
|
|
|
|
|
|
|
// This reclaims all the memory that one_addr2line may have cached.
|
|
|
|
// Use this when you know you will not be calling one_addr2line again.
|
|
|
|
static void
|
|
|
|
clear_addr2line_cache();
|
2007-11-03 00:02:44 +01:00
|
|
|
|
|
|
|
private:
|
2007-11-14 02:03:01 +01:00
|
|
|
virtual std::string
|
2011-03-10 02:31:33 +01:00
|
|
|
do_addr2line(unsigned int shndx, off_t offset,
|
|
|
|
std::vector<std::string>* other_lines) = 0;
|
2007-11-14 02:03:01 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
template<int size, bool big_endian>
|
2007-11-14 19:33:47 +01:00
|
|
|
class Sized_dwarf_line_info : public Dwarf_line_info
|
2007-11-14 02:03:01 +01:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
// Initializes a .debug_line reader for a given object file.
|
2007-12-11 19:17:31 +01:00
|
|
|
// If SHNDX is specified and non-negative, only read the debug
|
|
|
|
// information that pertains to the specified section.
|
2009-10-10 01:05:21 +02:00
|
|
|
Sized_dwarf_line_info(Object* object, unsigned int read_shndx = -1U);
|
2007-11-14 02:03:01 +01:00
|
|
|
|
2012-02-29 22:22:29 +01:00
|
|
|
virtual
|
|
|
|
~Sized_dwarf_line_info()
|
|
|
|
{
|
|
|
|
if (this->buffer_start_ != NULL)
|
|
|
|
delete[] this->buffer_start_;
|
|
|
|
}
|
|
|
|
|
2007-11-14 02:03:01 +01:00
|
|
|
private:
|
|
|
|
std::string
|
2011-03-10 02:31:33 +01:00
|
|
|
do_addr2line(unsigned int shndx, off_t offset,
|
|
|
|
std::vector<std::string>* other_lines);
|
|
|
|
|
|
|
|
// Formats a file and line number to a string like "dirname/filename:lineno".
|
|
|
|
std::string
|
|
|
|
format_file_lineno(const Offset_to_lineno_entry& lineno) const;
|
2007-11-14 02:03:01 +01:00
|
|
|
|
2007-11-12 20:56:20 +01:00
|
|
|
// Start processing line info, and populates the offset_map_.
|
2007-12-11 19:17:31 +01:00
|
|
|
// If SHNDX is non-negative, only store debug information that
|
|
|
|
// pertains to the specified section.
|
2007-11-12 20:56:20 +01:00
|
|
|
void
|
2012-03-21 20:02:22 +01:00
|
|
|
read_line_mappings(unsigned int shndx);
|
2007-11-12 20:56:20 +01:00
|
|
|
|
2007-11-10 00:16:54 +01:00
|
|
|
// Reads the relocation section associated with .debug_line and
|
|
|
|
// stores relocation information in reloc_map_.
|
|
|
|
void
|
2012-03-21 20:02:22 +01:00
|
|
|
read_relocs();
|
2007-11-10 00:16:54 +01:00
|
|
|
|
2007-11-03 00:02:44 +01:00
|
|
|
// Reads the DWARF2/3 header for this line info. Each takes as input
|
|
|
|
// a starting buffer position, and returns the ending position.
|
|
|
|
const unsigned char*
|
|
|
|
read_header_prolog(const unsigned char* lineptr);
|
|
|
|
|
|
|
|
const unsigned char*
|
|
|
|
read_header_tables(const unsigned char* lineptr);
|
|
|
|
|
2007-12-11 19:17:31 +01:00
|
|
|
// Reads the DWARF2/3 line information. If shndx is non-negative,
|
|
|
|
// discard all line information that doesn't pertain to the given
|
|
|
|
// section.
|
2007-11-03 00:02:44 +01:00
|
|
|
const unsigned char*
|
2009-10-10 01:05:21 +02:00
|
|
|
read_lines(const unsigned char* lineptr, unsigned int shndx);
|
2007-11-03 00:02:44 +01:00
|
|
|
|
|
|
|
// Process a single line info opcode at START using the state
|
|
|
|
// machine at LSM. Return true if we should define a line using the
|
|
|
|
// current state of the line state machine. Place the length of the
|
|
|
|
// opcode in LEN.
|
|
|
|
bool
|
2007-11-07 01:49:56 +01:00
|
|
|
process_one_opcode(const unsigned char* start,
|
2007-11-03 00:02:44 +01:00
|
|
|
struct LineStateMachine* lsm, size_t* len);
|
|
|
|
|
2007-11-13 02:26:27 +01:00
|
|
|
// Some parts of processing differ depending on whether the input
|
|
|
|
// was a .o file or not.
|
|
|
|
bool input_is_relobj();
|
|
|
|
|
2007-11-10 00:16:54 +01:00
|
|
|
// If we saw anything amiss while parsing, we set this to false.
|
|
|
|
// Then addr2line will always fail (rather than return possibly-
|
|
|
|
// corrupt data).
|
|
|
|
bool data_valid_;
|
|
|
|
|
2007-11-03 00:02:44 +01:00
|
|
|
// A DWARF2/3 line info header. This is not the same size as in the
|
|
|
|
// actual file, as the one in the file may have a 32 bit or 64 bit
|
|
|
|
// lengths.
|
|
|
|
|
|
|
|
struct Dwarf_line_infoHeader
|
|
|
|
{
|
|
|
|
off_t total_length;
|
|
|
|
int version;
|
|
|
|
off_t prologue_length;
|
|
|
|
int min_insn_length; // insn stands for instructin
|
|
|
|
bool default_is_stmt; // stmt stands for statement
|
|
|
|
signed char line_base;
|
|
|
|
int line_range;
|
|
|
|
unsigned char opcode_base;
|
|
|
|
std::vector<unsigned char> std_opcode_lengths;
|
|
|
|
int offset_size;
|
|
|
|
} header_;
|
|
|
|
|
|
|
|
// buffer is the buffer for our line info, starting at exactly where
|
|
|
|
// the line info to read is.
|
|
|
|
const unsigned char* buffer_;
|
2007-11-12 20:56:20 +01:00
|
|
|
const unsigned char* buffer_end_;
|
2012-02-29 22:22:29 +01:00
|
|
|
// If the buffer was allocated temporarily, and therefore must be
|
|
|
|
// deallocated in the dtor, this contains a pointer to the start
|
|
|
|
// of the buffer.
|
|
|
|
const unsigned char* buffer_start_;
|
2007-11-03 00:02:44 +01:00
|
|
|
|
2007-11-10 00:16:54 +01:00
|
|
|
// This has relocations that point into buffer.
|
2012-03-21 20:02:22 +01:00
|
|
|
Sized_elf_reloc_mapper<size, big_endian>* reloc_mapper_;
|
2010-12-01 20:49:22 +01:00
|
|
|
// The type of the reloc section in track_relocs_--SHT_REL or SHT_RELA.
|
|
|
|
unsigned int track_relocs_type_;
|
2007-11-10 00:16:54 +01:00
|
|
|
|
|
|
|
// This is used to figure out what section to apply a relocation to.
|
2007-11-12 20:56:20 +01:00
|
|
|
const unsigned char* symtab_buffer_;
|
2007-12-18 01:48:04 +01:00
|
|
|
section_size_type symtab_buffer_size_;
|
2007-11-10 00:16:54 +01:00
|
|
|
|
2007-11-13 02:26:27 +01:00
|
|
|
// Holds the directories and files as we see them. We have an array
|
|
|
|
// of directory-lists, one for each .o file we're reading (usually
|
|
|
|
// there will just be one, but there may be more if input is a .so).
|
|
|
|
std::vector<std::vector<std::string> > directories_;
|
2007-11-03 00:02:44 +01:00
|
|
|
// The first part is an index into directories_, the second the filename.
|
2007-11-13 02:26:27 +01:00
|
|
|
std::vector<std::vector< std::pair<int, std::string> > > files_;
|
|
|
|
|
|
|
|
// An index into the current directories_ and files_ vectors.
|
|
|
|
int current_header_index_;
|
2007-11-03 00:02:44 +01:00
|
|
|
|
2007-11-13 02:26:27 +01:00
|
|
|
// A sorted map from offset of the relocation target to the shndx
|
|
|
|
// and addend for the relocation.
|
2012-03-21 20:02:22 +01:00
|
|
|
typedef std::map<off_t, std::pair<unsigned int, off_t> >
|
2007-11-10 00:16:54 +01:00
|
|
|
Reloc_map;
|
|
|
|
Reloc_map reloc_map_;
|
|
|
|
|
2007-11-03 00:02:44 +01:00
|
|
|
// We have a vector of offset->lineno entries for every input section.
|
|
|
|
typedef Unordered_map<unsigned int, std::vector<Offset_to_lineno_entry> >
|
|
|
|
Lineno_map;
|
|
|
|
|
|
|
|
Lineno_map line_number_map_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // End namespace gold.
|
|
|
|
|
|
|
|
#endif // !defined(GOLD_DWARF_READER_H)
|