// This class is used to read the line information from the debugging
// section of an object file.
-template<int size, bool big_endian>
class Dwarf_line_info
{
public:
- // Initializes a .debug_line reader for a given object file.
- Dwarf_line_info(Object* object);
+ Dwarf_line_info()
+ { }
+
+ virtual
+ ~Dwarf_line_info()
+ { }
// 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
// read_line_mappings() before calling this function.
std::string
- addr2line(unsigned int shndx, off_t offset);
+ addr2line(unsigned int shndx, off_t offset)
+ { return do_addr2line(shndx, offset); }
+
+ // A helper function for a single addr2line lookup. It uses
+ // parameters() to figure out the size and endianness. This is less
+ // efficient than using the templatized size and endianness, so only
+ // call this from an un-templatized context.
+ static std::string
+ one_addr2line(Object* object, unsigned int shndx, off_t offset);
+
+ private:
+ virtual std::string
+ do_addr2line(unsigned int shndx, off_t offset) = 0;
+};
+
+template<int size, bool big_endian>
+class Sized_dwarf_line_info
+{
+ public:
+ // Initializes a .debug_line reader for a given object file.
+ Sized_dwarf_line_info(Object* object);
+
+ std::string
+ addr2line(unsigned int shndx, off_t offset)
+ { return do_addr2line(shndx, offset); }
private:
+ std::string
+ do_addr2line(unsigned int shndx, off_t offset);
+
// Start processing line info, and populates the offset_map_.
void
read_line_mappings();
process_one_opcode(const unsigned char* start,
struct LineStateMachine* lsm, size_t* len);
+ // Some parts of processing differ depending on whether the input
+ // was a .o file or not.
+ bool input_is_relobj();
+
// If we saw anything amiss while parsing, we set this to false.
// Then addr2line will always fail (rather than return possibly-
// corrupt data).
// This is used to figure out what section to apply a relocation to.
const unsigned char* symtab_buffer_;
- const unsigned char* symtab_buffer_end_;
+ off_t symtab_buffer_size_;
- // Holds the directories and files as we see them.
- std::vector<std::string> directories_;
+ // 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_;
// The first part is an index into directories_, the second the filename.
- std::vector< std::pair<int, std::string> > files_;
+ std::vector<std::vector< std::pair<int, std::string> > > files_;
+
+ // An index into the current directories_ and files_ vectors.
+ int current_header_index_;
- // A map from offset of the relocation target to the shndx and
- // addend for the relocation.
+ // A sorted map from offset of the relocation target to the shndx
+ // and addend for the relocation.
typedef std::map<typename elfcpp::Elf_types<size>::Elf_Addr,
std::pair<unsigned int,
typename elfcpp::Elf_types<size>::Elf_Swxword> >
struct Offset_to_lineno_entry
{
off_t offset;
+ int header_num; // which file-list to use (i.e. which .o file are we in)
int file_num; // a pointer into files_
- int line_num;
+ int line_num; // the line number in the source file
// Offsets are unique within a section, so that's a sufficient sort key.
bool operator<(const Offset_to_lineno_entry& that) const
{ return this->offset < that.offset; }