#include "src/profiling/symbolizer/local_symbolizer.h"
#include <fcntl.h>
#include <charconv>
#include <cinttypes>
#include <limits>
#include <memory>
#include <optional>
#include <sstream>
#include <string>
#include <vector>
#include "perfetto/base/build_config.h"
#include "perfetto/base/compiler.h"
#include "perfetto/base/logging.h"
#include "perfetto/ext/base/file_utils.h"
#include "perfetto/ext/base/scoped_file.h"
#include "perfetto/ext/base/scoped_mmap.h"
#include "perfetto/ext/base/string_utils.h"
#include "src/profiling/symbolizer/elf.h"
#include "src/profiling/symbolizer/filesystem.h"
namespace perfetto {
namespace profiling {
std::unique_ptr<Symbolizer> LocalSymbolizerOrDie(
std::vector<std::string> binary_path,
const char* mode) { … }
}
}
#if PERFETTO_BUILDFLAG(PERFETTO_LOCAL_SYMBOLIZER)
#include "perfetto/ext/base/string_splitter.h"
#include "perfetto/ext/base/string_utils.h"
#include "perfetto/ext/base/utils.h"
#include <signal.h>
#include <sys/stat.h>
#include <sys/types.h>
#if PERFETTO_BUILDFLAG(PERFETTO_OS_WIN)
constexpr const char* kDefaultSymbolizer = "llvm-symbolizer.exe";
#else
constexpr const char* kDefaultSymbolizer = …;
#endif
namespace perfetto {
namespace profiling {
namespace {
std::string GetLine(std::function<int64_t(char*, size_t)> fn_read) { … }
bool InRange(const void* base,
size_t total_size,
const void* ptr,
size_t size) { … }
template <typename E>
std::optional<uint64_t> GetElfLoadBias(void* mem, size_t size) { … }
template <typename E>
std::optional<std::string> GetElfBuildId(void* mem, size_t size) { … }
std::string SplitBuildID(const std::string& hex_build_id) { … }
bool IsElf(const char* mem, size_t size) { … }
constexpr uint32_t kMachO64Magic = …;
bool IsMachO64(const char* mem, size_t size) { … }
struct mach_header_64 { … };
struct load_command { … };
struct segment_64_command { … };
struct BinaryInfo { … };
std::optional<BinaryInfo> GetMachOBinaryInfo(char* mem, size_t size) { … }
std::optional<BinaryInfo> GetBinaryInfo(const char* fname, size_t size) { … }
std::map<std::string, FoundBinary> BuildIdIndex(std::vector<std::string> dirs) { … }
bool ParseJsonString(const char*& it, const char* end, std::string* out) { … }
bool ParseJsonNumber(const char*& it, const char* end, double* out) { … }
bool ParseJsonArray(
const char*& it,
const char* end,
std::function<bool(const char*&, const char*)> process_value) { … }
bool ParseJsonObject(
const char*& it,
const char* end,
std::function<bool(const char*&, const char*, const std::string&)>
process_value) { … }
bool SkipJsonValue(const char*& it, const char* end) { … }
}
bool ParseLlvmSymbolizerJsonLine(const std::string& line,
std::vector<SymbolizedFrame>* result) { … }
BinaryFinder::~BinaryFinder() = default;
LocalBinaryIndexer::LocalBinaryIndexer(std::vector<std::string> roots)
: … { … }
std::optional<FoundBinary> LocalBinaryIndexer::FindBinary(
const std::string& abspath,
const std::string& build_id) { … }
LocalBinaryIndexer::~LocalBinaryIndexer() = default;
LocalBinaryFinder::LocalBinaryFinder(std::vector<std::string> roots)
: … { … }
std::optional<FoundBinary> LocalBinaryFinder::FindBinary(
const std::string& abspath,
const std::string& build_id) { … }
std::optional<FoundBinary> LocalBinaryFinder::IsCorrectFile(
const std::string& symbol_file,
const std::string& build_id) { … }
std::optional<FoundBinary> LocalBinaryFinder::FindBinaryInRoot(
const std::string& root_str,
const std::string& abspath,
const std::string& build_id) { … }
LocalBinaryFinder::~LocalBinaryFinder() = default;
LLVMSymbolizerProcess::LLVMSymbolizerProcess(const std::string& symbolizer_path)
: … { … }
#endif
std::vector<SymbolizedFrame> LLVMSymbolizerProcess::Symbolize(
const std::string& binary,
uint64_t address) { … }
std::vector<std::vector<SymbolizedFrame>> LocalSymbolizer::Symbolize(
const std::string& mapping_name,
const std::string& build_id,
uint64_t load_bias,
const std::vector<uint64_t>& addresses) { … }
LocalSymbolizer::LocalSymbolizer(const std::string& symbolizer_path,
std::unique_ptr<BinaryFinder> finder)
: … { … }
LocalSymbolizer::LocalSymbolizer(std::unique_ptr<BinaryFinder> finder)
: … { … }
LocalSymbolizer::~LocalSymbolizer() = default;
}
}
#endif