#include "SymbolFileDWARF.h"
#include "llvm/DebugInfo/DWARF/DWARFDebugLoc.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/FileUtilities.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/Threading.h"
#include "lldb/Core/Module.h"
#include "lldb/Core/ModuleList.h"
#include "lldb/Core/ModuleSpec.h"
#include "lldb/Core/PluginManager.h"
#include "lldb/Core/Progress.h"
#include "lldb/Core/Section.h"
#include "lldb/Core/Value.h"
#include "lldb/Utility/ArchSpec.h"
#include "lldb/Utility/LLDBLog.h"
#include "lldb/Utility/RegularExpression.h"
#include "lldb/Utility/Scalar.h"
#include "lldb/Utility/StreamString.h"
#include "lldb/Utility/StructuredData.h"
#include "lldb/Utility/Timer.h"
#include "Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.h"
#include "Plugins/Language/CPlusPlus/CPlusPlusLanguage.h"
#include "lldb/Host/FileSystem.h"
#include "lldb/Host/Host.h"
#include "lldb/Interpreter/OptionValueFileSpecList.h"
#include "lldb/Interpreter/OptionValueProperties.h"
#include "Plugins/ExpressionParser/Clang/ClangUtil.h"
#include "Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h"
#include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
#include "lldb/Symbol/Block.h"
#include "lldb/Symbol/CompileUnit.h"
#include "lldb/Symbol/CompilerDecl.h"
#include "lldb/Symbol/CompilerDeclContext.h"
#include "lldb/Symbol/DebugMacros.h"
#include "lldb/Symbol/LineTable.h"
#include "lldb/Symbol/ObjectFile.h"
#include "lldb/Symbol/SymbolFile.h"
#include "lldb/Symbol/TypeMap.h"
#include "lldb/Symbol/TypeSystem.h"
#include "lldb/Symbol/VariableList.h"
#include "lldb/Target/Language.h"
#include "lldb/Target/Target.h"
#include "AppleDWARFIndex.h"
#include "DWARFASTParser.h"
#include "DWARFASTParserClang.h"
#include "DWARFCompileUnit.h"
#include "DWARFDebugAranges.h"
#include "DWARFDebugInfo.h"
#include "DWARFDebugMacro.h"
#include "DWARFDebugRanges.h"
#include "DWARFDeclContext.h"
#include "DWARFFormValue.h"
#include "DWARFTypeUnit.h"
#include "DWARFUnit.h"
#include "DebugNamesDWARFIndex.h"
#include "LogChannelDWARF.h"
#include "ManualDWARFIndex.h"
#include "SymbolFileDWARFDebugMap.h"
#include "SymbolFileDWARFDwo.h"
#include "llvm/DebugInfo/DWARF/DWARFContext.h"
#include "llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/FormatVariadic.h"
#include <algorithm>
#include <map>
#include <memory>
#include <optional>
#include <cctype>
#include <cstring>
#ifdef ENABLE_DEBUG_PRINTF
#include <cstdio>
#define DEBUG_PRINTF …
#else
#define DEBUG_PRINTF(fmt, ...) …
#endif
usingnamespacelldb;
usingnamespacelldb_private;
usingnamespacelldb_private::dwarf;
usingnamespacelldb_private::plugin::dwarf;
LLDB_PLUGIN_DEFINE(…)
char SymbolFileDWARF::ID;
namespace {
#define LLDB_PROPERTIES_symbolfiledwarf
#include "SymbolFileDWARFProperties.inc"
enum { … };
class PluginProperties : public Properties { … };
}
bool IsStructOrClassTag(llvm::dwarf::Tag Tag) { … }
static PluginProperties &GetGlobalPluginProperties() { … }
static const llvm::DWARFDebugLine::LineTable *
ParseLLVMLineTable(DWARFContext &context, llvm::DWARFDebugLine &line,
dw_offset_t line_offset, dw_offset_t unit_offset) { … }
static bool ParseLLVMLineTablePrologue(DWARFContext &context,
llvm::DWARFDebugLine::Prologue &prologue,
dw_offset_t line_offset,
dw_offset_t unit_offset) { … }
static std::optional<std::string>
GetFileByIndex(const llvm::DWARFDebugLine::Prologue &prologue, size_t idx,
llvm::StringRef compile_dir, FileSpec::Style style) { … }
static void ParseSupportFilesFromPrologue(
SupportFileList &support_files, const lldb::ModuleSP &module,
const llvm::DWARFDebugLine::Prologue &prologue, FileSpec::Style style,
llvm::StringRef compile_dir = { … }
void SymbolFileDWARF::Initialize() { … }
void SymbolFileDWARF::DebuggerInitialize(Debugger &debugger) { … }
void SymbolFileDWARF::Terminate() { … }
llvm::StringRef SymbolFileDWARF::GetPluginDescriptionStatic() { … }
SymbolFile *SymbolFileDWARF::CreateInstance(ObjectFileSP objfile_sp) { … }
TypeList &SymbolFileDWARF::GetTypeList() { … }
void SymbolFileDWARF::GetTypes(const DWARFDIE &die, dw_offset_t min_die_offset,
dw_offset_t max_die_offset, uint32_t type_mask,
TypeSet &type_set) { … }
void SymbolFileDWARF::GetTypes(SymbolContextScope *sc_scope,
TypeClass type_mask, TypeList &type_list)
{ … }
DWARFDIE
SymbolFileDWARF::GetParentSymbolContextDIE(const DWARFDIE &child_die) { … }
SymbolFileDWARF::SymbolFileDWARF(ObjectFileSP objfile_sp,
SectionList *dwo_section_list)
: … { … }
SymbolFileDWARF::~SymbolFileDWARF() = default;
static ConstString GetDWARFMachOSegmentName() { … }
llvm::DenseMap<lldb::opaque_compiler_type_t, DIERef> &
SymbolFileDWARF::GetForwardDeclCompilerTypeToDIE() { … }
UniqueDWARFASTTypeMap &SymbolFileDWARF::GetUniqueDWARFASTTypeMap() { … }
llvm::Expected<lldb::TypeSystemSP>
SymbolFileDWARF::GetTypeSystemForLanguage(LanguageType language) { … }
void SymbolFileDWARF::InitializeObject() { … }
void SymbolFileDWARF::InitializeFirstCodeAddress() { … }
void SymbolFileDWARF::InitializeFirstCodeAddressRecursive(
const lldb_private::SectionList §ion_list) { … }
bool SymbolFileDWARF::SupportedVersion(uint16_t version) { … }
static std::set<dw_form_t>
GetUnsupportedForms(llvm::DWARFDebugAbbrev *debug_abbrev) { … }
uint32_t SymbolFileDWARF::CalculateAbilities() { … }
void SymbolFileDWARF::LoadSectionData(lldb::SectionType sect_type,
DWARFDataExtractor &data) { … }
llvm::DWARFDebugAbbrev *SymbolFileDWARF::DebugAbbrev() { … }
DWARFDebugInfo &SymbolFileDWARF::DebugInfo() { … }
DWARFCompileUnit *SymbolFileDWARF::GetDWARFCompileUnit(CompileUnit *comp_unit) { … }
DWARFDebugRanges *SymbolFileDWARF::GetDebugRanges() { … }
static void MakeAbsoluteAndRemap(FileSpec &file_spec, DWARFUnit &dwarf_cu,
const ModuleSP &module_sp) { … }
static const char *GetDWOName(DWARFCompileUnit &dwarf_cu,
const DWARFDebugInfoEntry &cu_die) { … }
lldb::CompUnitSP SymbolFileDWARF::ParseCompileUnit(DWARFCompileUnit &dwarf_cu) { … }
void SymbolFileDWARF::BuildCuTranslationTable() { … }
std::optional<uint32_t> SymbolFileDWARF::GetDWARFUnitIndex(uint32_t cu_idx) { … }
uint32_t SymbolFileDWARF::CalculateNumCompileUnits() { … }
CompUnitSP SymbolFileDWARF::ParseCompileUnitAtIndex(uint32_t cu_idx) { … }
Function *SymbolFileDWARF::ParseFunction(CompileUnit &comp_unit,
const DWARFDIE &die) { … }
ConstString
SymbolFileDWARF::ConstructFunctionDemangledName(const DWARFDIE &die) { … }
lldb::addr_t SymbolFileDWARF::FixupAddress(lldb::addr_t file_addr) { … }
bool SymbolFileDWARF::FixupAddress(Address &addr) { … }
lldb::LanguageType SymbolFileDWARF::ParseLanguage(CompileUnit &comp_unit) { … }
XcodeSDK SymbolFileDWARF::ParseXcodeSDK(CompileUnit &comp_unit) { … }
size_t SymbolFileDWARF::ParseFunctions(CompileUnit &comp_unit) { … }
bool SymbolFileDWARF::ForEachExternalModule(
CompileUnit &comp_unit,
llvm::DenseSet<lldb_private::SymbolFile *> &visited_symbol_files,
llvm::function_ref<bool(Module &)> lambda) { … }
bool SymbolFileDWARF::ParseSupportFiles(CompileUnit &comp_unit,
SupportFileList &support_files) { … }
bool SymbolFileDWARF::ParseSupportFiles(DWARFUnit &dwarf_cu,
const ModuleSP &module,
SupportFileList &support_files) { … }
FileSpec SymbolFileDWARF::GetFile(DWARFUnit &unit, size_t file_idx) { … }
const SupportFileList *
SymbolFileDWARF::GetTypeUnitSupportFiles(DWARFTypeUnit &tu) { … }
bool SymbolFileDWARF::ParseIsOptimized(CompileUnit &comp_unit) { … }
bool SymbolFileDWARF::ParseImportedModules(
const lldb_private::SymbolContext &sc,
std::vector<SourceModule> &imported_modules) { … }
bool SymbolFileDWARF::ParseLineTable(CompileUnit &comp_unit) { … }
lldb_private::DebugMacrosSP
SymbolFileDWARF::ParseDebugMacros(lldb::offset_t *offset) { … }
bool SymbolFileDWARF::ParseDebugMacros(CompileUnit &comp_unit) { … }
size_t SymbolFileDWARF::ParseBlocksRecursive(
lldb_private::CompileUnit &comp_unit, Block *parent_block,
const DWARFDIE &orig_die, addr_t subprogram_low_pc, uint32_t depth) { … }
bool SymbolFileDWARF::ClassOrStructIsVirtual(const DWARFDIE &parent_die) { … }
void SymbolFileDWARF::ParseDeclsForContext(CompilerDeclContext decl_ctx) { … }
DWARFDIE
SymbolFileDWARF::GetDIE(lldb::user_id_t uid) { … }
CompilerDecl SymbolFileDWARF::GetDeclForUID(lldb::user_id_t type_uid) { … }
CompilerDeclContext
SymbolFileDWARF::GetDeclContextForUID(lldb::user_id_t type_uid) { … }
CompilerDeclContext
SymbolFileDWARF::GetDeclContextContainingUID(lldb::user_id_t type_uid) { … }
std::vector<CompilerContext>
SymbolFileDWARF::GetCompilerContextForUID(lldb::user_id_t type_uid) { … }
Type *SymbolFileDWARF::ResolveTypeUID(lldb::user_id_t type_uid) { … }
std::optional<SymbolFile::ArrayInfo> SymbolFileDWARF::GetDynamicArrayInfoForUID(
lldb::user_id_t type_uid, const lldb_private::ExecutionContext *exe_ctx) { … }
Type *SymbolFileDWARF::ResolveTypeUID(const DIERef &die_ref) { … }
Type *SymbolFileDWARF::ResolveTypeUID(const DWARFDIE &die,
bool assert_not_being_parsed) { … }
bool SymbolFileDWARF::HasForwardDeclForCompilerType(
const CompilerType &compiler_type) { … }
bool SymbolFileDWARF::CompleteType(CompilerType &compiler_type) { … }
Type *SymbolFileDWARF::ResolveType(const DWARFDIE &die,
bool assert_not_being_parsed,
bool resolve_function_context) { … }
CompileUnit *
SymbolFileDWARF::GetCompUnitForDWARFCompUnit(DWARFCompileUnit &dwarf_cu) { … }
void SymbolFileDWARF::GetObjCMethods(
ConstString class_name, llvm::function_ref<bool(DWARFDIE die)> callback) { … }
bool SymbolFileDWARF::GetFunction(const DWARFDIE &die, SymbolContext &sc) { … }
lldb::ModuleSP SymbolFileDWARF::GetExternalModule(ConstString name) { … }
SymbolFileDWARF *SymbolFileDWARF::GetDIERefSymbolFile(const DIERef &die_ref) { … }
DWARFDIE
SymbolFileDWARF::GetDIE(const DIERef &die_ref) { … }
static std::optional<uint64_t> GetDWOId(DWARFCompileUnit &dwarf_cu,
const DWARFDebugInfoEntry &cu_die) { … }
std::optional<uint64_t> SymbolFileDWARF::GetDWOId() { … }
DWARFUnit *SymbolFileDWARF::GetSkeletonUnit(DWARFUnit *dwo_unit) { … }
std::shared_ptr<SymbolFileDWARFDwo>
SymbolFileDWARF::GetDwoSymbolFileForCompileUnit(
DWARFUnit &unit, const DWARFDebugInfoEntry &cu_die) { … }
void SymbolFileDWARF::UpdateExternalModuleListIfNeeded() { … }
SymbolFileDWARF::GlobalVariableMap &SymbolFileDWARF::GetGlobalAranges() { … }
void SymbolFileDWARF::ResolveFunctionAndBlock(lldb::addr_t file_vm_addr,
bool lookup_block,
SymbolContext &sc) { … }
uint32_t SymbolFileDWARF::ResolveSymbolContext(const Address &so_addr,
SymbolContextItem resolve_scope,
SymbolContext &sc) { … }
uint32_t SymbolFileDWARF::ResolveSymbolContext(
const SourceLocationSpec &src_location_spec,
SymbolContextItem resolve_scope, SymbolContextList &sc_list) { … }
void SymbolFileDWARF::PreloadSymbols() { … }
std::recursive_mutex &SymbolFileDWARF::GetModuleMutex() const { … }
bool SymbolFileDWARF::DeclContextMatchesThisSymbolFile(
const lldb_private::CompilerDeclContext &decl_ctx) { … }
void SymbolFileDWARF::FindGlobalVariables(
ConstString name, const CompilerDeclContext &parent_decl_ctx,
uint32_t max_matches, VariableList &variables) { … }
void SymbolFileDWARF::FindGlobalVariables(const RegularExpression ®ex,
uint32_t max_matches,
VariableList &variables) { … }
bool SymbolFileDWARF::ResolveFunction(const DWARFDIE &orig_die,
bool include_inlines,
SymbolContextList &sc_list) { … }
bool SymbolFileDWARF::DIEInDeclContext(const CompilerDeclContext &decl_ctx,
const DWARFDIE &die,
bool only_root_namespaces) { … }
void SymbolFileDWARF::FindFunctions(const Module::LookupInfo &lookup_info,
const CompilerDeclContext &parent_decl_ctx,
bool include_inlines,
SymbolContextList &sc_list) { … }
void SymbolFileDWARF::FindFunctions(const RegularExpression ®ex,
bool include_inlines,
SymbolContextList &sc_list) { … }
void SymbolFileDWARF::GetMangledNamesForFunction(
const std::string &scope_qualified_name,
std::vector<ConstString> &mangled_names) { … }
static bool SplitTemplateParams(llvm::StringRef fullname,
llvm::StringRef &basename,
llvm::StringRef &template_params) { … }
static bool UpdateCompilerContextForSimpleTemplateNames(TypeQuery &match) { … }
uint64_t SymbolFileDWARF::GetDebugInfoSize(bool load_all_debug_info) { … }
void SymbolFileDWARF::FindTypes(const TypeQuery &query, TypeResults &results) { … }
CompilerDeclContext
SymbolFileDWARF::FindNamespace(ConstString name,
const CompilerDeclContext &parent_decl_ctx,
bool only_root_namespaces) { … }
TypeSP SymbolFileDWARF::GetTypeForDIE(const DWARFDIE &die,
bool resolve_function_context) { … }
DWARFDIE
SymbolFileDWARF::GetDeclContextDIEContainingDIE(const DWARFDIE &orig_die) { … }
Symbol *SymbolFileDWARF::GetObjCClassSymbol(ConstString objc_class_name) { … }
bool SymbolFileDWARF::Supports_DW_AT_APPLE_objc_complete_type(DWARFUnit *cu) { … }
TypeSP SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE(
const DWARFDIE &die, ConstString type_name, bool must_be_implementation) { … }
DWARFDIE
SymbolFileDWARF::FindDefinitionDIE(const DWARFDIE &die) { … }
TypeSP SymbolFileDWARF::ParseType(const SymbolContext &sc, const DWARFDIE &die,
bool *type_is_new_ptr) { … }
size_t SymbolFileDWARF::ParseTypes(const SymbolContext &sc,
const DWARFDIE &orig_die,
bool parse_siblings, bool parse_children) { … }
size_t SymbolFileDWARF::ParseBlocksRecursive(Function &func) { … }
size_t SymbolFileDWARF::ParseTypes(CompileUnit &comp_unit) { … }
size_t SymbolFileDWARF::ParseVariablesForContext(const SymbolContext &sc) { … }
VariableSP SymbolFileDWARF::ParseVariableDIECached(const SymbolContext &sc,
const DWARFDIE &die) { … }
static DWARFExpressionList GetExprListFromAtLocation(DWARFFormValue form_value,
ModuleSP module,
const DWARFDIE &die,
const addr_t func_low_pc) { … }
static DWARFExpressionList
GetExprListFromAtConstValue(DWARFFormValue form_value, ModuleSP module,
const DWARFDIE &die) { … }
static Symbol *fixupExternalAddrZeroVariable(
SymbolFileDWARFDebugMap &debug_map_symfile, llvm::StringRef name,
DWARFExpressionList &expr_list, const DWARFDIE &die) { … }
VariableSP SymbolFileDWARF::ParseVariableDIE(const SymbolContext &sc,
const DWARFDIE &die,
const lldb::addr_t func_low_pc) { … }
DWARFDIE
SymbolFileDWARF::FindBlockContainingSpecification(
const DIERef &func_die_ref, dw_offset_t spec_block_die_offset) { … }
DWARFDIE
SymbolFileDWARF::FindBlockContainingSpecification(
const DWARFDIE &die, dw_offset_t spec_block_die_offset) { … }
void SymbolFileDWARF::ParseAndAppendGlobalVariable(
const SymbolContext &sc, const DWARFDIE &die,
VariableList &cc_variable_list) { … }
DIEArray
SymbolFileDWARF::MergeBlockAbstractParameters(const DWARFDIE &block_die,
DIEArray &&variable_dies) { … }
size_t SymbolFileDWARF::ParseVariablesInFunctionContext(
const SymbolContext &sc, const DWARFDIE &die,
const lldb::addr_t func_low_pc) { … }
size_t SymbolFileDWARF::ParseVariablesInFunctionContextRecursive(
const lldb_private::SymbolContext &sc, const DWARFDIE &die,
lldb::addr_t func_low_pc, DIEArray &accumulator) { … }
size_t SymbolFileDWARF::PopulateBlockVariableList(
VariableList &variable_list, const lldb_private::SymbolContext &sc,
llvm::ArrayRef<DIERef> variable_dies, lldb::addr_t func_low_pc) { … }
static CallSiteParameterArray
CollectCallSiteParameters(ModuleSP module, DWARFDIE call_site_die) { … }
std::vector<std::unique_ptr<lldb_private::CallEdge>>
SymbolFileDWARF::CollectCallEdges(ModuleSP module, DWARFDIE function_die) { … }
std::vector<std::unique_ptr<lldb_private::CallEdge>>
SymbolFileDWARF::ParseCallEdgesInFunction(lldb_private::UserID func_id) { … }
void SymbolFileDWARF::Dump(lldb_private::Stream &s) { … }
void SymbolFileDWARF::DumpClangAST(Stream &s) { … }
bool SymbolFileDWARF::GetSeparateDebugInfo(StructuredData::Dictionary &d,
bool errors_only) { … }
SymbolFileDWARFDebugMap *SymbolFileDWARF::GetDebugMapSymfile() { … }
const std::shared_ptr<SymbolFileDWARFDwo> &SymbolFileDWARF::GetDwpSymbolFile() { … }
llvm::Expected<lldb::TypeSystemSP>
SymbolFileDWARF::GetTypeSystem(DWARFUnit &unit) { … }
DWARFASTParser *SymbolFileDWARF::GetDWARFParser(DWARFUnit &unit) { … }
CompilerDecl SymbolFileDWARF::GetDecl(const DWARFDIE &die) { … }
CompilerDeclContext SymbolFileDWARF::GetDeclContext(const DWARFDIE &die) { … }
CompilerDeclContext
SymbolFileDWARF::GetContainingDeclContext(const DWARFDIE &die) { … }
LanguageType SymbolFileDWARF::LanguageTypeFromDWARF(uint64_t val) { … }
LanguageType SymbolFileDWARF::GetLanguage(DWARFUnit &unit) { … }
LanguageType SymbolFileDWARF::GetLanguageFamily(DWARFUnit &unit) { … }
StatsDuration::Duration SymbolFileDWARF::GetDebugInfoIndexTime() { … }
Status SymbolFileDWARF::CalculateFrameVariableError(StackFrame &frame) { … }
void SymbolFileDWARF::GetCompileOptions(
std::unordered_map<lldb::CompUnitSP, lldb_private::Args> &args) { … }