Revert "Support for DWARF-5 in in house DWARF parser"

This commit is contained in:
Alexander Tokmakov 2022-08-29 14:25:53 +03:00 committed by GitHub
parent 8d90d30d37
commit 69387acffa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 232 additions and 897 deletions

View File

@ -368,7 +368,8 @@ endif()
set (COMPILER_FLAGS "${COMPILER_FLAGS}") set (COMPILER_FLAGS "${COMPILER_FLAGS}")
set (DEBUG_INFO_FLAGS "-g") # Our built-in unwinder only supports DWARF version up to 4.
set (DEBUG_INFO_FLAGS "-g -gdwarf-4")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMPILER_FLAGS}") set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMPILER_FLAGS}")
set (CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -O3 ${DEBUG_INFO_FLAGS} ${CMAKE_CXX_FLAGS_ADD}") set (CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -O3 ${DEBUG_INFO_FLAGS} ${CMAKE_CXX_FLAGS_ADD}")

File diff suppressed because it is too large Load Diff

View File

@ -19,7 +19,6 @@
*/ */
/** This file was edited for ClickHouse. /** This file was edited for ClickHouse.
* Original is from folly library.
*/ */
#include <functional> #include <functional>
@ -172,6 +171,8 @@ public:
private: private:
static bool findDebugInfoOffset(uintptr_t address, std::string_view aranges, uint64_t & offset); static bool findDebugInfoOffset(uintptr_t address, std::string_view aranges, uint64_t & offset);
void init();
std::shared_ptr<const Elf> elf_; /// NOLINT std::shared_ptr<const Elf> elf_; /// NOLINT
// DWARF section made up of chunks, each prefixed with a length header. // DWARF section made up of chunks, each prefixed with a length header.
@ -227,7 +228,6 @@ private:
{ {
uint64_t name = 0; uint64_t name = 0;
uint64_t form = 0; uint64_t form = 0;
int64_t implicitConst = 0; // only set when form=DW_FORM_implicit_const
explicit operator bool() const { return name != 0 || form != 0; } explicit operator bool() const { return name != 0 || form != 0; }
}; };
@ -239,43 +239,25 @@ private:
std::variant<uint64_t, std::string_view> attr_value; std::variant<uint64_t, std::string_view> attr_value;
}; };
enum
{
DW_UT_compile = 0x01,
DW_UT_skeleton = 0x04,
};
struct CompilationUnit struct CompilationUnit
{ {
bool is64Bit = false; /// NOLINT bool is64Bit; /// NOLINT
uint8_t version = 0; uint8_t version;
uint8_t unit_type = DW_UT_compile; // DW_UT_compile or DW_UT_skeleton uint8_t addr_size;
uint8_t addr_size = 0;
// Offset in .debug_info of this compilation unit. // Offset in .debug_info of this compilation unit.
uint32_t offset = 0; uint32_t offset;
uint32_t size = 0; uint32_t size;
// Offset in .debug_info for the first DIE in this compilation unit. // Offset in .debug_info for the first DIE in this compilation unit.
uint32_t first_die = 0; uint32_t first_die;
uint64_t abbrev_offset = 0; uint64_t abbrev_offset;
// The beginning of the CU's contribution to .debug_addr
std::optional<uint64_t> addr_base; // DW_AT_addr_base (DWARF 5)
// The beginning of the offsets table (immediately following the
// header) of the CU's contribution to .debug_loclists
std::optional<uint64_t> loclists_base; // DW_AT_loclists_base (DWARF 5)
// The beginning of the offsets table (immediately following the
// header) of the CU's contribution to .debug_rnglists
std::optional<uint64_t> rnglists_base; // DW_AT_rnglists_base (DWARF 5)
// Points to the first string offset of the compilation units
// contribution to the .debug_str_offsets (or .debug_str_offsets.dwo) section.
std::optional<uint64_t> str_offsets_base; // DW_AT_str_offsets_base (DWARF 5)
// Only the CompilationUnit that contains the caller functions needs this cache. // Only the CompilationUnit that contains the caller functions needs this cache.
// Indexed by (abbr.code - 1) if (abbr.code - 1) < abbrCache.size(); // Indexed by (abbr.code - 1) if (abbr.code - 1) < abbrCache.size();
std::vector<DIEAbbreviation> abbr_cache; std::vector<DIEAbbreviation> abbr_cache;
}; };
/** cu must exist during the life cycle of created Die. */ static CompilationUnit getCompilationUnit(std::string_view info, uint64_t offset);
/** cu must exist during the life cycle of created detail::Die. */
Die getDieAtOffset(const CompilationUnit & cu, uint64_t offset) const; Die getDieAtOffset(const CompilationUnit & cu, uint64_t offset) const;
bool findLocation( bool findLocation(
@ -296,16 +278,16 @@ private:
class LineNumberVM class LineNumberVM
{ {
public: public:
LineNumberVM( LineNumberVM(std::string_view data, std::string_view compilationDirectory);
std::string_view data,
std::string_view compilationDirectory,
std::string_view debugStr,
std::string_view debugLineStr);
bool findAddress(uintptr_t target, Path & file, uint64_t & line); bool findAddress(uintptr_t target, Path & file, uint64_t & line);
/** Gets full file name at given index including directory. */ /** Gets full file name at given index including directory. */
Path getFullFileName(uint64_t index) const; Path getFullFileName(uint64_t index) const
{
auto fn = getFileName(index);
return Path({}, getIncludeDirectory(fn.directoryIndex), fn.relativeName);
}
private: private:
void init(); void init();
@ -348,8 +330,6 @@ private:
bool is64Bit_; /// NOLINT bool is64Bit_; /// NOLINT
std::string_view data_; /// NOLINT std::string_view data_; /// NOLINT
std::string_view compilationDirectory_; /// NOLINT std::string_view compilationDirectory_; /// NOLINT
std::string_view debugStr_; // needed for DWARF 5 /// NOLINT
std::string_view debugLineStr_; // DWARF 5 /// NOLINT
// Header // Header
uint16_t version_; /// NOLINT uint16_t version_; /// NOLINT
@ -360,27 +340,11 @@ private:
uint8_t opcodeBase_; /// NOLINT uint8_t opcodeBase_; /// NOLINT
const uint8_t * standardOpcodeLengths_; /// NOLINT const uint8_t * standardOpcodeLengths_; /// NOLINT
// 6.2.4 The Line Number Program Header. std::string_view includeDirectories_; /// NOLINT
struct size_t includeDirectoryCount_; /// NOLINT
{
size_t includeDirectoryCount;
std::string_view includeDirectories;
size_t fileNameCount;
std::string_view fileNames;
} v4_;
struct std::string_view fileNames_; /// NOLINT
{ size_t fileNameCount_; /// NOLINT
uint8_t directoryEntryFormatCount;
std::string_view directoryEntryFormat;
uint64_t directoriesCount;
std::string_view directories;
uint8_t fileNameEntryFormatCount;
std::string_view fileNameEntryFormat;
uint64_t fileNamesCount;
std::string_view fileNames;
} v5_;
// State machine registers // State machine registers
uint64_t address_; /// NOLINT uint64_t address_; /// NOLINT
@ -433,26 +397,20 @@ private:
*/ */
size_t forEachAttribute(const CompilationUnit & cu, const Die & die, std::function<bool(const Attribute & die)> f) const; size_t forEachAttribute(const CompilationUnit & cu, const Die & die, std::function<bool(const Attribute & die)> f) const;
Attribute readAttribute( Attribute readAttribute(const Die & die, AttributeSpec spec, std::string_view & info) const;
const CompilationUnit & cu,
const Die & die,
AttributeSpec spec,
std::string_view & info) const;
// Read one attribute <name, form> pair, remove_prefix sp; returns <0, 0> at end. // Read one attribute <name, form> pair, remove_prefix sp; returns <0, 0> at end.
static AttributeSpec readAttributeSpec(std::string_view & sp); static AttributeSpec readAttributeSpec(std::string_view & sp);
// Read one attribute value, remove_prefix sp // Read one attribute value, remove_prefix sp
using AttributeValue = std::variant<uint64_t, std::string_view>; using AttributeValue = std::variant<uint64_t, std::string_view>;
AttributeValue readAttributeValue(std::string_view & sp, uint64_t form, bool is64_bit) const; AttributeValue readAttributeValue(std::string_view & sp, uint64_t form, bool is64Bit) const;
// Get an ELF section by name, return true if found // Get an ELF section by name, return true if found
std::string_view getSection(const char * name) const; bool getSection(const char * name, std::string_view * section) const;
CompilationUnit getCompilationUnit(uint64_t offset) const;
// Finds the Compilation Unit starting at offset.
CompilationUnit findCompilationUnit(uint64_t targetOffset) const;
// Get a string from the .debug_str section
std::string_view getStringFromStringSection(uint64_t offset) const;
template <class T> template <class T>
std::optional<T> getAttribute(const CompilationUnit & cu, const Die & die, uint64_t attr_name) const std::optional<T> getAttribute(const CompilationUnit & cu, const Die & die, uint64_t attr_name) const
@ -471,24 +429,17 @@ private:
} }
// Check if the given address is in the range list at the given offset in .debug_ranges. // Check if the given address is in the range list at the given offset in .debug_ranges.
bool isAddrInRangeList( bool isAddrInRangeList(uint64_t address, std::optional<uint64_t> base_addr, size_t offset, uint8_t addr_size) const;
const CompilationUnit & cu,
uint64_t address, // Finds the Compilation Unit starting at offset.
std::optional<uint64_t> base_addr, static CompilationUnit findCompilationUnit(std::string_view info, uint64_t targetOffset);
size_t offset,
uint8_t addr_size) const;
std::string_view abbrev_; // .debug_abbrev /// NOLINT
std::string_view addr_; // .debug_addr (DWARF 5) /// NOLINT
std::string_view aranges_; // .debug_aranges /// NOLINT
std::string_view info_; // .debug_info /// NOLINT std::string_view info_; // .debug_info /// NOLINT
std::string_view abbrev_; // .debug_abbrev /// NOLINT
std::string_view aranges_; // .debug_aranges /// NOLINT
std::string_view line_; // .debug_line /// NOLINT std::string_view line_; // .debug_line /// NOLINT
std::string_view line_str_; // .debug_line_str (DWARF 5) /// NOLINT std::string_view strings_; // .debug_str /// NOLINT
std::string_view loclists_; // .debug_loclists (DWARF 5) /// NOLINT
std::string_view ranges_; // .debug_ranges /// NOLINT std::string_view ranges_; // .debug_ranges /// NOLINT
std::string_view rnglists_; // .debug_rnglists (DWARF 5) /// NOLINT
std::string_view str_; // .debug_str /// NOLINT
std::string_view str_offsets_; // .debug_str_offsets (DWARF 5) /// NOLINT
}; };
} }