Path: blob/main/contrib/llvm-project/lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.h
39653 views
//===-- SymbolFileBreakpad.h ------------------------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef LLDB_SOURCE_PLUGINS_SYMBOLFILE_BREAKPAD_SYMBOLFILEBREAKPAD_H9#define LLDB_SOURCE_PLUGINS_SYMBOLFILE_BREAKPAD_SYMBOLFILEBREAKPAD_H1011#include "Plugins/ObjectFile/Breakpad/BreakpadRecords.h"12#include "lldb/Symbol/LineTable.h"13#include "lldb/Symbol/PostfixExpression.h"14#include "lldb/Symbol/SymbolFile.h"15#include "lldb/Symbol/UnwindPlan.h"16#include "lldb/Utility/FileSpecList.h"17#include <optional>1819namespace lldb_private {2021namespace breakpad {2223class SymbolFileBreakpad : public SymbolFileCommon {24/// LLVM RTTI support.25static char ID;2627public:28/// LLVM RTTI support.29/// \{30bool isA(const void *ClassID) const override {31return ClassID == &ID || SymbolFileCommon::isA(ClassID);32}33static bool classof(const SymbolFile *obj) { return obj->isA(&ID); }34/// \}3536// Static Functions37static void Initialize();38static void Terminate();39static void DebuggerInitialize(Debugger &debugger) {}40static llvm::StringRef GetPluginNameStatic() { return "breakpad"; }4142static llvm::StringRef GetPluginDescriptionStatic() {43return "Breakpad debug symbol file reader.";44}4546static SymbolFile *CreateInstance(lldb::ObjectFileSP objfile_sp) {47return new SymbolFileBreakpad(std::move(objfile_sp));48}4950// Constructors and Destructors51SymbolFileBreakpad(lldb::ObjectFileSP objfile_sp)52: SymbolFileCommon(std::move(objfile_sp)) {}5354~SymbolFileBreakpad() override = default;5556uint32_t CalculateAbilities() override;5758void InitializeObject() override {}5960// Compile Unit function calls6162lldb::LanguageType ParseLanguage(CompileUnit &comp_unit) override {63return lldb::eLanguageTypeUnknown;64}6566lldb::FunctionSP GetOrCreateFunction(CompileUnit &comp_unit);6768size_t ParseFunctions(CompileUnit &comp_unit) override;6970bool ParseLineTable(CompileUnit &comp_unit) override;7172bool ParseDebugMacros(CompileUnit &comp_unit) override { return false; }7374bool ParseSupportFiles(CompileUnit &comp_unit,75SupportFileList &support_files) override;76size_t ParseTypes(CompileUnit &cu) override { return 0; }7778bool ParseImportedModules(79const SymbolContext &sc,80std::vector<lldb_private::SourceModule> &imported_modules) override {81return false;82}8384size_t ParseBlocksRecursive(Function &func) override;8586void FindGlobalVariables(ConstString name,87const CompilerDeclContext &parent_decl_ctx,88uint32_t max_matches,89VariableList &variables) override {}9091size_t ParseVariablesForContext(const SymbolContext &sc) override {92return 0;93}94Type *ResolveTypeUID(lldb::user_id_t type_uid) override { return nullptr; }95std::optional<ArrayInfo> GetDynamicArrayInfoForUID(96lldb::user_id_t type_uid,97const lldb_private::ExecutionContext *exe_ctx) override {98return std::nullopt;99}100101bool CompleteType(CompilerType &compiler_type) override { return false; }102uint32_t ResolveSymbolContext(const Address &so_addr,103lldb::SymbolContextItem resolve_scope,104SymbolContext &sc) override;105106uint32_t ResolveSymbolContext(const SourceLocationSpec &src_location_spec,107lldb::SymbolContextItem resolve_scope,108SymbolContextList &sc_list) override;109110void GetTypes(SymbolContextScope *sc_scope, lldb::TypeClass type_mask,111TypeList &type_list) override {}112113void FindFunctions(const Module::LookupInfo &lookup_info,114const CompilerDeclContext &parent_decl_ctx,115bool include_inlines, SymbolContextList &sc_list) override;116117void FindFunctions(const RegularExpression ®ex, bool include_inlines,118SymbolContextList &sc_list) override;119120llvm::Expected<lldb::TypeSystemSP>121GetTypeSystemForLanguage(lldb::LanguageType language) override {122return llvm::createStringError(123"SymbolFileBreakpad does not support GetTypeSystemForLanguage");124}125126CompilerDeclContext FindNamespace(ConstString name,127const CompilerDeclContext &parent_decl_ctx,128bool only_root_namespaces) override {129return CompilerDeclContext();130}131132void AddSymbols(Symtab &symtab) override;133134llvm::Expected<lldb::addr_t> GetParameterStackSize(Symbol &symbol) override;135136lldb::UnwindPlanSP137GetUnwindPlan(const Address &address,138const RegisterInfoResolver &resolver) override;139140llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }141142uint64_t GetDebugInfoSize(bool load_all_debug_info = false) override;143144private:145// A class representing a position in the breakpad file. Useful for146// remembering the position so we can go back to it later and parse more data.147// Can be converted to/from a LineIterator, but it has a much smaller memory148// footprint.149struct Bookmark {150uint32_t section;151size_t offset;152153friend bool operator<(const Bookmark &lhs, const Bookmark &rhs) {154return std::tie(lhs.section, lhs.offset) <155std::tie(rhs.section, rhs.offset);156}157};158159// At iterator class for simplifying algorithms reading data from the breakpad160// file. It iterates over all records (lines) in the sections of a given type.161// It also supports saving a specific position (via the GetBookmark() method)162// and then resuming from it afterwards.163class LineIterator;164165// Return an iterator range for all records in the given object file of the166// given type.167llvm::iterator_range<LineIterator> lines(Record::Kind section_type);168169// Breakpad files do not contain sufficient information to correctly170// reconstruct compile units. The approach chosen here is to treat each171// function as a compile unit. The compile unit name is the name if the first172// line entry belonging to this function.173// This class is our internal representation of a compile unit. It stores the174// CompileUnit object and a bookmark pointing to the FUNC record of the175// compile unit function. It also lazily construct the list of support files176// and line table entries for the compile unit, when these are needed.177class CompUnitData {178public:179CompUnitData(Bookmark bookmark) : bookmark(bookmark) {}180181CompUnitData() = default;182CompUnitData(const CompUnitData &rhs) : bookmark(rhs.bookmark) {}183CompUnitData &operator=(const CompUnitData &rhs) {184bookmark = rhs.bookmark;185support_files.reset();186line_table_up.reset();187return *this;188}189friend bool operator<(const CompUnitData &lhs, const CompUnitData &rhs) {190return lhs.bookmark < rhs.bookmark;191}192193Bookmark bookmark;194std::optional<FileSpecList> support_files;195std::unique_ptr<LineTable> line_table_up;196};197198uint32_t CalculateNumCompileUnits() override;199lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override;200201lldb::addr_t GetBaseFileAddress();202void ParseFileRecords();203void ParseCUData();204void ParseLineTableAndSupportFiles(CompileUnit &cu, CompUnitData &data);205void ParseUnwindData();206llvm::ArrayRef<uint8_t> SaveAsDWARF(postfix::Node &node);207lldb::UnwindPlanSP ParseCFIUnwindPlan(const Bookmark &bookmark,208const RegisterInfoResolver &resolver);209bool ParseCFIUnwindRow(llvm::StringRef unwind_rules,210const RegisterInfoResolver &resolver,211UnwindPlan::Row &row);212lldb::UnwindPlanSP ParseWinUnwindPlan(const Bookmark &bookmark,213const RegisterInfoResolver &resolver);214void ParseInlineOriginRecords();215216using CompUnitMap = RangeDataVector<lldb::addr_t, lldb::addr_t, CompUnitData>;217218std::optional<std::vector<FileSpec>> m_files;219std::optional<CompUnitMap> m_cu_data;220std::optional<std::vector<llvm::StringRef>> m_inline_origins;221222using UnwindMap = RangeDataVector<lldb::addr_t, lldb::addr_t, Bookmark>;223struct UnwindData {224UnwindMap cfi;225UnwindMap win;226};227std::optional<UnwindData> m_unwind_data;228llvm::BumpPtrAllocator m_allocator;229};230231} // namespace breakpad232} // namespace lldb_private233234#endif235236237