proxygen
|
#include <Dwarf.h>
Classes | |
struct | DIEAbbreviation |
class | LineNumberVM |
struct | LocationInfo |
class | Path |
class | Section |
Public Types | |
enum | LocationInfoMode { LocationInfoMode::DISABLED, LocationInfoMode::FAST, LocationInfoMode::FULL } |
Public Member Functions | |
Dwarf (const ElfFile *elf) | |
bool | findAddress (uintptr_t address, LocationInfo &info, LocationInfoMode mode) const |
Private Types | |
typedef boost::variant< uint64_t, folly::StringPiece > | AttributeValue |
Private Member Functions | |
void | init () |
bool | findLocation (uintptr_t address, StringPiece &infoEntry, LocationInfo &info) const |
DIEAbbreviation | getAbbreviation (uint64_t code, uint64_t offset) const |
AttributeValue | readAttributeValue (folly::StringPiece &sp, uint64_t form, bool is64Bit) const |
bool | getSection (const char *name, folly::StringPiece *section) const |
folly::StringPiece | getStringFromStringSection (uint64_t offset) const |
Static Private Member Functions | |
static bool | findDebugInfoOffset (uintptr_t address, StringPiece aranges, uint64_t &offset) |
static bool | readAbbreviation (folly::StringPiece &sp, DIEAbbreviation &abbr) |
static DIEAbbreviation::Attribute | readAttribute (folly::StringPiece &sp) |
Private Attributes | |
const ElfFile * | elf_ |
folly::StringPiece | info_ |
folly::StringPiece | abbrev_ |
folly::StringPiece | aranges_ |
folly::StringPiece | line_ |
folly::StringPiece | strings_ |
DWARF record parser.
We only implement enough DWARF functionality to convert from PC address to file and line number information.
This means (although they're not part of the public API of this class), we can parse Debug Information Entries (DIEs), abbreviations, attributes (of all forms), and we can interpret bytecode for the line number VM.
We can interpret DWARF records of version 2, 3, or 4, although we don't actually support many of the version 4 features (such as VLIW, multiple operations per instruction)
Note that the DWARF record parser does not allocate heap memory at all. This is on purpose: you can use the parser from memory-constrained situations (such as an exception handler for std::out_of_memory) If it weren't for this requirement, some things would be much simpler: the Path class would be unnecessary and would be replaced with a std::string; the list of file names in the line number VM would be kept as a vector of strings instead of re-executing the program to look for DW_LNE_define_file instructions, etc.
|
private |
|
strong |
|
explicit |
bool folly::symbolizer::Dwarf::findAddress | ( | uintptr_t | address, |
LocationInfo & | info, | ||
LocationInfoMode | mode | ||
) | const |
Find the file and line number information corresponding to address.
Definition at line 575 of file Dwarf.cpp.
References folly::Range< Iter >::advance(), aranges_, DISABLED, elf_, folly::Range< Iter >::empty(), FAST, findDebugInfoOffset(), findLocation(), FULL, folly::symbolizer::Dwarf::LocationInfo::hasFileAndLine, info_, and uint64_t.
Referenced by dummy().
|
staticprivate |
Find in .debug_aranges and return the offset in .debug_info for compilation unit to which this address belongs.
Definition at line 442 of file Dwarf.cpp.
References folly::Range< Iter >::data(), FOLLY_SAFE_CHECK, folly::symbolizer::Dwarf::Section::is64Bit(), folly::symbolizer::Dwarf::Section::next(), start, and version.
Referenced by findAddress().
|
private |
Find the for in the compilation unit represented by the .debug_info entry. Returns whether the address was found. Advances to the next entry in .debug_info.
Definition at line 485 of file Dwarf.cpp.
References folly::Range< Iter >::advance(), folly::Range< Iter >::begin(), folly::Range< Iter >::empty(), folly::Range< Iter >::end(), folly::symbolizer::Dwarf::LocationInfo::file, folly::symbolizer::Dwarf::LineNumberVM::findAddress(), FOLLY_SAFE_CHECK, folly::symbolizer::Dwarf::DIEAbbreviation::Attribute::form, getAbbreviation(), folly::symbolizer::Dwarf::LocationInfo::hasFileAndLine, folly::symbolizer::Dwarf::LocationInfo::hasMainFile, folly::symbolizer::Dwarf::Section::is64Bit(), folly::symbolizer::Dwarf::LocationInfo::line, line_, folly::symbolizer::Dwarf::LocationInfo::mainFile, folly::symbolizer::Dwarf::DIEAbbreviation::Attribute::name, folly::symbolizer::Dwarf::Section::next(), folly::symbolizer::Dwarf::Path::Path(), readAttribute(), readAttributeValue(), uint64_t, val, and version.
Referenced by findAddress().
|
private |
Definition at line 364 of file Dwarf.cpp.
References abbrev_, folly::Range< Iter >::advance(), folly::symbolizer::Dwarf::DIEAbbreviation::code, FOLLY_SAFE_CHECK, and readAbbreviation().
Referenced by findLocation().
|
private |
Definition at line 302 of file Dwarf.cpp.
References elf_, folly::symbolizer::ElfFile::getSectionBody(), and folly::symbolizer::ElfFile::getSectionByName().
Referenced by init().
|
private |
Definition at line 431 of file Dwarf.cpp.
References FOLLY_SAFE_CHECK, folly::Range< Iter >::size(), and strings_.
Referenced by readAttributeValue().
|
private |
|
staticprivate |
Definition at line 331 of file Dwarf.cpp.
References folly::Range< Iter >::assign(), folly::symbolizer::Dwarf::DIEAbbreviation::attributes, folly::symbolizer::Dwarf::DIEAbbreviation::code, folly::Range< Iter >::data(), folly::Range< Iter >::empty(), FOLLY_SAFE_CHECK, folly::symbolizer::Dwarf::DIEAbbreviation::hasChildren, readAttribute(), and folly::symbolizer::Dwarf::DIEAbbreviation::tag.
Referenced by getAbbreviation().
|
staticprivate |
Definition at line 360 of file Dwarf.cpp.
Referenced by findLocation(), and readAbbreviation().
|
private |
Definition at line 380 of file Dwarf.cpp.
References FOLLY_SAFE_CHECK, and getStringFromStringSection().
Referenced by findLocation().
|
private |
Definition at line 286 of file Dwarf.h.
Referenced by getAbbreviation(), and init().
|
private |
Definition at line 287 of file Dwarf.h.
Referenced by findAddress(), and init().
|
private |
Definition at line 145 of file Dwarf.h.
Referenced by findAddress(), getSection(), and init().
|
private |
Definition at line 285 of file Dwarf.h.
Referenced by findAddress(), and init().
|
private |
Definition at line 288 of file Dwarf.h.
Referenced by findLocation(), and init().
|
private |
Definition at line 289 of file Dwarf.h.
Referenced by getStringFromStringSection(), and init().