2019-07-29 18:06:39 +00:00
|
|
|
#pragma once
|
|
|
|
|
2022-06-10 08:22:31 +00:00
|
|
|
#if defined(__ELF__) && !defined(OS_FREEBSD)
|
2019-08-21 00:48:34 +00:00
|
|
|
|
2019-07-29 18:06:39 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2012-present Facebook, Inc.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** This file was edited for ClickHouse.
|
|
|
|
*/
|
|
|
|
|
2021-01-20 23:20:11 +00:00
|
|
|
#include <functional>
|
2021-01-20 17:44:18 +00:00
|
|
|
#include <memory>
|
2021-01-19 12:34:27 +00:00
|
|
|
#include <optional>
|
2019-07-29 18:06:39 +00:00
|
|
|
#include <string>
|
|
|
|
#include <string_view>
|
|
|
|
#include <variant>
|
2021-01-19 12:34:27 +00:00
|
|
|
#include <vector>
|
2019-07-29 18:06:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
class Elf;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2019-07-29 18:38:04 +00:00
|
|
|
class Dwarf final
|
2019-07-29 18:06:39 +00:00
|
|
|
{
|
|
|
|
// Note that Dwarf uses (and returns) std::string_view a lot.
|
|
|
|
// The std::string_view point within sections in the ELF file, and so will
|
|
|
|
// be live for as long as the passed-in Elf is live.
|
|
|
|
public:
|
|
|
|
/** Create a DWARF parser around an ELF file. */
|
2021-01-20 13:03:25 +00:00
|
|
|
explicit Dwarf(const std::shared_ptr<Elf> & elf);
|
2019-07-29 18:06:39 +00:00
|
|
|
|
2021-01-19 12:34:27 +00:00
|
|
|
/**
|
|
|
|
* More than one location info may exist if current frame is an inline
|
|
|
|
* function call.
|
|
|
|
*/
|
|
|
|
static constexpr uint32_t kMaxInlineLocationInfoPerFrame = 10;
|
|
|
|
|
2019-07-29 18:06:39 +00:00
|
|
|
/**
|
|
|
|
* Represent a file path a s collection of three parts (base directory,
|
|
|
|
* subdirectory, and file).
|
|
|
|
*/
|
|
|
|
class Path
|
|
|
|
{
|
|
|
|
public:
|
2021-01-20 13:03:25 +00:00
|
|
|
Path() = default;
|
2019-07-29 18:06:39 +00:00
|
|
|
|
|
|
|
Path(std::string_view baseDir, std::string_view subDir, std::string_view file);
|
|
|
|
|
|
|
|
std::string_view baseDir() const { return baseDir_; }
|
|
|
|
std::string_view subDir() const { return subDir_; }
|
|
|
|
std::string_view file() const { return file_; }
|
|
|
|
|
|
|
|
size_t size() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Copy the Path to a buffer of size bufSize.
|
|
|
|
*
|
|
|
|
* toBuffer behaves like snprintf: It will always null-terminate the
|
|
|
|
* buffer (so it will copy at most bufSize-1 bytes), and it will return
|
|
|
|
* the number of bytes that would have been written if there had been
|
|
|
|
* enough room, so, if toBuffer returns a value >= bufSize, the output
|
|
|
|
* was truncated.
|
|
|
|
*/
|
|
|
|
size_t toBuffer(char * buf, size_t bufSize) const;
|
|
|
|
|
|
|
|
void toString(std::string & dest) const;
|
|
|
|
std::string toString() const
|
|
|
|
{
|
|
|
|
std::string s;
|
|
|
|
toString(s);
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(tudorb): Implement operator==, operator!=; not as easy as it
|
|
|
|
// seems as the same path can be represented in multiple ways
|
|
|
|
private:
|
2022-03-11 21:47:28 +00:00
|
|
|
std::string_view baseDir_; /// NOLINT
|
2022-08-29 11:25:53 +00:00
|
|
|
std::string_view subDir_; /// NOLINT
|
|
|
|
std::string_view file_; /// NOLINT
|
2019-07-29 18:06:39 +00:00
|
|
|
};
|
|
|
|
|
2021-01-20 17:44:18 +00:00
|
|
|
// Indicates inline function `name` is called at `line@file`.
|
2021-01-19 12:34:27 +00:00
|
|
|
struct CallLocation
|
|
|
|
{
|
|
|
|
Path file = {};
|
2021-05-08 20:56:17 +00:00
|
|
|
uint64_t line = 0;
|
2021-01-19 12:34:27 +00:00
|
|
|
std::string_view name;
|
|
|
|
};
|
|
|
|
|
2019-07-29 18:06:39 +00:00
|
|
|
enum class LocationInfoMode
|
|
|
|
{
|
|
|
|
// Don't resolve location info.
|
|
|
|
DISABLED,
|
|
|
|
// Perform CU lookup using .debug_aranges (might be incomplete).
|
|
|
|
FAST,
|
|
|
|
// Scan all CU in .debug_info (slow!) on .debug_aranges lookup failure.
|
|
|
|
FULL,
|
2021-01-19 12:34:27 +00:00
|
|
|
// Scan .debug_info (super slower, use with caution) for inline functions in
|
|
|
|
// addition to FULL.
|
|
|
|
FULL_WITH_INLINE,
|
2019-07-29 18:06:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct LocationInfo
|
|
|
|
{
|
2021-01-19 12:34:27 +00:00
|
|
|
bool has_main_file = false;
|
|
|
|
Path main_file;
|
2019-07-29 18:06:39 +00:00
|
|
|
|
2021-01-19 12:34:27 +00:00
|
|
|
bool has_file_and_line = false;
|
2019-07-29 18:06:39 +00:00
|
|
|
Path file;
|
|
|
|
uint64_t line = 0;
|
|
|
|
};
|
|
|
|
|
2021-01-19 12:34:27 +00:00
|
|
|
/**
|
|
|
|
* Frame information: symbol name and location.
|
|
|
|
*/
|
|
|
|
struct SymbolizedFrame
|
|
|
|
{
|
|
|
|
bool found = false;
|
|
|
|
uintptr_t addr = 0;
|
|
|
|
// Mangled symbol name. Use `folly::demangle()` to demangle it.
|
|
|
|
const char * name = nullptr;
|
|
|
|
LocationInfo location;
|
2021-01-20 13:03:25 +00:00
|
|
|
std::shared_ptr<const Elf> file;
|
2021-01-19 12:34:27 +00:00
|
|
|
|
|
|
|
void clear() { *this = SymbolizedFrame(); }
|
|
|
|
};
|
|
|
|
|
2019-12-24 20:07:44 +00:00
|
|
|
/** Find the file and line number information corresponding to address.
|
|
|
|
* The address must be physical - offset in object file without offset in virtual memory where the object is loaded.
|
2019-07-29 18:38:04 +00:00
|
|
|
*/
|
2021-01-19 12:34:27 +00:00
|
|
|
bool findAddress(uintptr_t address, LocationInfo & info, LocationInfoMode mode, std::vector<SymbolizedFrame> & inline_frames) const;
|
2019-07-29 18:06:39 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
static bool findDebugInfoOffset(uintptr_t address, std::string_view aranges, uint64_t & offset);
|
|
|
|
|
2022-08-29 11:25:53 +00:00
|
|
|
void init();
|
|
|
|
|
2022-03-11 21:47:28 +00:00
|
|
|
std::shared_ptr<const Elf> elf_; /// NOLINT
|
2019-07-29 18:06:39 +00:00
|
|
|
|
|
|
|
// DWARF section made up of chunks, each prefixed with a length header.
|
|
|
|
// The length indicates whether the chunk is DWARF-32 or DWARF-64, which
|
|
|
|
// guides interpretation of "section offset" records.
|
|
|
|
// (yes, DWARF-32 and DWARF-64 sections may coexist in the same file)
|
|
|
|
class Section
|
|
|
|
{
|
|
|
|
public:
|
2022-03-11 21:47:28 +00:00
|
|
|
Section() : is64_bit(false) {}
|
2019-07-29 18:06:39 +00:00
|
|
|
|
|
|
|
explicit Section(std::string_view d);
|
|
|
|
|
|
|
|
// Return next chunk, if any; the 4- or 12-byte length was already
|
|
|
|
// parsed and isn't part of the chunk.
|
|
|
|
bool next(std::string_view & chunk);
|
|
|
|
|
|
|
|
// Is the current chunk 64 bit?
|
2022-03-11 21:47:28 +00:00
|
|
|
bool is64Bit() const { return is64_bit; }
|
2019-07-29 18:06:39 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
// Yes, 32- and 64- bit sections may coexist. Yikes!
|
2022-03-11 21:47:28 +00:00
|
|
|
bool is64_bit;
|
|
|
|
std::string_view data;
|
2019-07-29 18:06:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Abbreviation for a Debugging Information Entry.
|
|
|
|
struct DIEAbbreviation
|
|
|
|
{
|
2021-05-08 20:56:17 +00:00
|
|
|
uint64_t code = 0;
|
|
|
|
uint64_t tag = 0;
|
2021-01-19 12:34:27 +00:00
|
|
|
bool has_children = false;
|
2019-07-29 18:06:39 +00:00
|
|
|
|
|
|
|
std::string_view attributes;
|
|
|
|
};
|
|
|
|
|
2021-01-19 12:34:27 +00:00
|
|
|
// Debugging information entry to define a low-level representation of a
|
|
|
|
// source program. Each debugging information entry consists of an identifying
|
|
|
|
// tag and a series of attributes. An entry, or group of entries together,
|
|
|
|
// provide a description of a corresponding entity in the source program.
|
|
|
|
struct Die
|
|
|
|
{
|
2022-03-11 21:47:28 +00:00
|
|
|
bool is64Bit; /// NOLINT
|
2021-01-19 12:34:27 +00:00
|
|
|
// Offset from start to first attribute
|
|
|
|
uint8_t attr_offset;
|
|
|
|
// Offset within debug info.
|
|
|
|
uint32_t offset;
|
|
|
|
uint64_t code;
|
|
|
|
DIEAbbreviation abbr;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct AttributeSpec
|
|
|
|
{
|
|
|
|
uint64_t name = 0;
|
|
|
|
uint64_t form = 0;
|
|
|
|
|
|
|
|
explicit operator bool() const { return name != 0 || form != 0; }
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Attribute
|
|
|
|
{
|
|
|
|
AttributeSpec spec;
|
|
|
|
const Die & die;
|
|
|
|
std::variant<uint64_t, std::string_view> attr_value;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct CompilationUnit
|
|
|
|
{
|
2022-08-29 11:25:53 +00:00
|
|
|
bool is64Bit; /// NOLINT
|
|
|
|
uint8_t version;
|
|
|
|
uint8_t addr_size;
|
2021-01-19 12:34:27 +00:00
|
|
|
// Offset in .debug_info of this compilation unit.
|
2022-08-29 11:25:53 +00:00
|
|
|
uint32_t offset;
|
|
|
|
uint32_t size;
|
2021-01-19 12:34:27 +00:00
|
|
|
// Offset in .debug_info for the first DIE in this compilation unit.
|
2022-08-29 11:25:53 +00:00
|
|
|
uint32_t first_die;
|
|
|
|
uint64_t abbrev_offset;
|
2021-01-19 12:34:27 +00:00
|
|
|
// Only the CompilationUnit that contains the caller functions needs this cache.
|
|
|
|
// Indexed by (abbr.code - 1) if (abbr.code - 1) < abbrCache.size();
|
|
|
|
std::vector<DIEAbbreviation> abbr_cache;
|
|
|
|
};
|
|
|
|
|
2022-08-29 11:25:53 +00:00
|
|
|
static CompilationUnit getCompilationUnit(std::string_view info, uint64_t offset);
|
|
|
|
|
|
|
|
/** cu must exist during the life cycle of created detail::Die. */
|
2021-01-19 12:34:27 +00:00
|
|
|
Die getDieAtOffset(const CompilationUnit & cu, uint64_t offset) const;
|
|
|
|
|
|
|
|
bool findLocation(
|
|
|
|
uintptr_t address,
|
|
|
|
LocationInfoMode mode,
|
|
|
|
CompilationUnit & cu,
|
|
|
|
LocationInfo & info,
|
|
|
|
std::vector<SymbolizedFrame> & inline_frames) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Finds a subprogram debugging info entry that contains a given address among
|
|
|
|
* children of given die. Depth first search.
|
|
|
|
*/
|
|
|
|
void findSubProgramDieForAddress(
|
|
|
|
const CompilationUnit & cu, const Die & die, uint64_t address, std::optional<uint64_t> base_addr_cu, Die & subprogram) const;
|
|
|
|
|
2019-07-29 18:06:39 +00:00
|
|
|
// Interpreter for the line number bytecode VM
|
|
|
|
class LineNumberVM
|
|
|
|
{
|
|
|
|
public:
|
2022-08-29 11:25:53 +00:00
|
|
|
LineNumberVM(std::string_view data, std::string_view compilationDirectory);
|
2019-07-29 18:06:39 +00:00
|
|
|
|
2020-03-08 21:04:10 +00:00
|
|
|
bool findAddress(uintptr_t target, Path & file, uint64_t & line);
|
2019-07-29 18:06:39 +00:00
|
|
|
|
2021-01-19 12:34:27 +00:00
|
|
|
/** Gets full file name at given index including directory. */
|
2022-08-29 11:25:53 +00:00
|
|
|
Path getFullFileName(uint64_t index) const
|
|
|
|
{
|
|
|
|
auto fn = getFileName(index);
|
|
|
|
return Path({}, getIncludeDirectory(fn.directoryIndex), fn.relativeName);
|
|
|
|
}
|
2021-01-19 12:34:27 +00:00
|
|
|
|
2019-07-29 18:06:39 +00:00
|
|
|
private:
|
|
|
|
void init();
|
|
|
|
void reset();
|
|
|
|
|
|
|
|
// Execute until we commit one new row to the line number matrix
|
|
|
|
bool next(std::string_view & program);
|
|
|
|
enum StepResult
|
|
|
|
{
|
|
|
|
CONTINUE, // Continue feeding opcodes
|
|
|
|
COMMIT, // Commit new <address, file, line> tuple
|
|
|
|
END, // End of sequence
|
|
|
|
};
|
|
|
|
// Execute one opcode
|
|
|
|
StepResult step(std::string_view & program);
|
|
|
|
|
|
|
|
struct FileName
|
|
|
|
{
|
2022-03-11 21:47:28 +00:00
|
|
|
std::string_view relativeName; /// NOLINT
|
2019-07-29 18:06:39 +00:00
|
|
|
// 0 = current compilation directory
|
|
|
|
// otherwise, 1-based index in the list of include directories
|
2022-03-11 21:47:28 +00:00
|
|
|
uint64_t directoryIndex; /// NOLINT
|
2019-07-29 18:06:39 +00:00
|
|
|
};
|
2020-03-08 21:04:10 +00:00
|
|
|
// Read one FileName object, remove_prefix program
|
|
|
|
static bool readFileName(std::string_view & program, FileName & fn);
|
2019-07-29 18:06:39 +00:00
|
|
|
|
|
|
|
// Get file name at given index; may be in the initial table
|
|
|
|
// (fileNames_) or defined using DW_LNE_define_file (and we reexecute
|
|
|
|
// enough of the program to find it, if so)
|
|
|
|
FileName getFileName(uint64_t index) const;
|
|
|
|
|
|
|
|
// Get include directory at given index
|
|
|
|
std::string_view getIncludeDirectory(uint64_t index) const;
|
|
|
|
|
|
|
|
// Execute opcodes until finding a DW_LNE_define_file and return true;
|
|
|
|
// return file at the end.
|
|
|
|
bool nextDefineFile(std::string_view & program, FileName & fn) const;
|
|
|
|
|
|
|
|
// Initialization
|
2022-08-29 11:25:53 +00:00
|
|
|
bool is64Bit_; /// NOLINT
|
|
|
|
std::string_view data_; /// NOLINT
|
|
|
|
std::string_view compilationDirectory_; /// NOLINT
|
2019-07-29 18:06:39 +00:00
|
|
|
|
|
|
|
// Header
|
2022-08-29 11:25:53 +00:00
|
|
|
uint16_t version_; /// NOLINT
|
|
|
|
uint8_t minLength_; /// NOLINT
|
2022-03-11 21:47:28 +00:00
|
|
|
bool defaultIsStmt_; /// NOLINT
|
2022-08-29 11:25:53 +00:00
|
|
|
int8_t lineBase_; /// NOLINT
|
|
|
|
uint8_t lineRange_; /// NOLINT
|
2022-03-11 21:47:28 +00:00
|
|
|
uint8_t opcodeBase_; /// NOLINT
|
|
|
|
const uint8_t * standardOpcodeLengths_; /// NOLINT
|
2019-07-29 18:06:39 +00:00
|
|
|
|
2022-08-29 11:25:53 +00:00
|
|
|
std::string_view includeDirectories_; /// NOLINT
|
|
|
|
size_t includeDirectoryCount_; /// NOLINT
|
2019-07-29 18:06:39 +00:00
|
|
|
|
2022-08-29 11:25:53 +00:00
|
|
|
std::string_view fileNames_; /// NOLINT
|
|
|
|
size_t fileNameCount_; /// NOLINT
|
2019-07-29 18:06:39 +00:00
|
|
|
|
|
|
|
// State machine registers
|
2022-03-11 21:47:28 +00:00
|
|
|
uint64_t address_; /// NOLINT
|
|
|
|
uint64_t file_; /// NOLINT
|
|
|
|
uint64_t line_; /// NOLINT
|
|
|
|
uint64_t column_; /// NOLINT
|
|
|
|
bool isStmt_; /// NOLINT
|
|
|
|
bool basicBlock_; /// NOLINT
|
|
|
|
bool endSequence_; /// NOLINT
|
|
|
|
bool prologueEnd_; /// NOLINT
|
|
|
|
bool epilogueBegin_; /// NOLINT
|
|
|
|
uint64_t isa_; /// NOLINT
|
|
|
|
uint64_t discriminator_; /// NOLINT
|
2019-07-29 18:06:39 +00:00
|
|
|
};
|
|
|
|
|
2021-01-19 12:34:27 +00:00
|
|
|
/**
|
|
|
|
* Finds inlined subroutine DIEs and their caller lines that contains a given
|
|
|
|
* address among children of given die. Depth first search.
|
|
|
|
*/
|
|
|
|
void findInlinedSubroutineDieForAddress(
|
|
|
|
const CompilationUnit & cu,
|
|
|
|
const Die & die,
|
|
|
|
const LineNumberVM & line_vm,
|
|
|
|
uint64_t address,
|
|
|
|
std::optional<uint64_t> base_addr_cu,
|
|
|
|
std::vector<CallLocation> & locations,
|
|
|
|
size_t max_size) const;
|
|
|
|
|
2020-03-08 21:04:10 +00:00
|
|
|
// Read an abbreviation from a std::string_view, return true if at end; remove_prefix section
|
|
|
|
static bool readAbbreviation(std::string_view & section, DIEAbbreviation & abbr);
|
2019-07-29 18:06:39 +00:00
|
|
|
|
2021-01-19 12:34:27 +00:00
|
|
|
static void readCompilationUnitAbbrs(std::string_view abbrev, CompilationUnit & cu);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Iterates over all children of a debugging info entry, calling the given
|
|
|
|
* callable for each. Iteration is stopped early if any of the calls return
|
|
|
|
* false. Returns the offset of next DIE after iterations.
|
|
|
|
*/
|
|
|
|
size_t forEachChild(const CompilationUnit & cu, const Die & die, std::function<bool(const Die & die)> f) const;
|
|
|
|
|
2019-07-29 18:06:39 +00:00
|
|
|
// Get abbreviation corresponding to a code, in the chunk starting at
|
|
|
|
// offset in the .debug_abbrev section
|
|
|
|
DIEAbbreviation getAbbreviation(uint64_t code, uint64_t offset) const;
|
|
|
|
|
2021-01-19 12:34:27 +00:00
|
|
|
/**
|
2021-01-20 17:44:18 +00:00
|
|
|
* Iterates over all attributes of a debugging info entry, calling the given
|
2021-01-19 12:34:27 +00:00
|
|
|
* callable for each. If all attributes are visited, then return the offset of
|
|
|
|
* next DIE, or else iteration is stopped early and return size_t(-1) if any
|
|
|
|
* of the calls return false.
|
|
|
|
*/
|
|
|
|
size_t forEachAttribute(const CompilationUnit & cu, const Die & die, std::function<bool(const Attribute & die)> f) const;
|
|
|
|
|
2022-08-29 11:25:53 +00:00
|
|
|
Attribute readAttribute(const Die & die, AttributeSpec spec, std::string_view & info) const;
|
2021-01-19 12:34:27 +00:00
|
|
|
|
2019-07-29 18:06:39 +00:00
|
|
|
// Read one attribute <name, form> pair, remove_prefix sp; returns <0, 0> at end.
|
2021-01-19 12:34:27 +00:00
|
|
|
static AttributeSpec readAttributeSpec(std::string_view & sp);
|
2019-07-29 18:06:39 +00:00
|
|
|
|
|
|
|
// Read one attribute value, remove_prefix sp
|
2021-01-19 12:34:27 +00:00
|
|
|
using AttributeValue = std::variant<uint64_t, std::string_view>;
|
2022-08-29 11:25:53 +00:00
|
|
|
AttributeValue readAttributeValue(std::string_view & sp, uint64_t form, bool is64Bit) const;
|
2019-07-29 18:06:39 +00:00
|
|
|
|
|
|
|
// Get an ELF section by name, return true if found
|
2022-08-29 11:25:53 +00:00
|
|
|
bool getSection(const char * name, std::string_view * section) const;
|
2019-07-29 18:06:39 +00:00
|
|
|
|
2022-08-29 11:25:53 +00:00
|
|
|
// Get a string from the .debug_str section
|
|
|
|
std::string_view getStringFromStringSection(uint64_t offset) const;
|
2019-07-29 18:06:39 +00:00
|
|
|
|
2021-01-19 12:34:27 +00:00
|
|
|
template <class T>
|
|
|
|
std::optional<T> getAttribute(const CompilationUnit & cu, const Die & die, uint64_t attr_name) const
|
|
|
|
{
|
|
|
|
std::optional<T> result;
|
2021-01-20 17:44:18 +00:00
|
|
|
forEachAttribute(cu, die, [&](const Attribute & attr)
|
|
|
|
{
|
2021-01-19 12:34:27 +00:00
|
|
|
if (attr.spec.name == attr_name)
|
|
|
|
{
|
|
|
|
result = std::get<T>(attr.attr_value);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the given address is in the range list at the given offset in .debug_ranges.
|
2022-08-29 11:25:53 +00:00
|
|
|
bool isAddrInRangeList(uint64_t address, std::optional<uint64_t> base_addr, size_t offset, uint8_t addr_size) const;
|
|
|
|
|
|
|
|
// Finds the Compilation Unit starting at offset.
|
|
|
|
static CompilationUnit findCompilationUnit(std::string_view info, uint64_t targetOffset);
|
|
|
|
|
|
|
|
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 strings_; // .debug_str /// NOLINT
|
|
|
|
std::string_view ranges_; // .debug_ranges /// NOLINT
|
2019-07-29 18:06:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
2019-08-21 00:48:34 +00:00
|
|
|
|
|
|
|
#endif
|