diff --git a/lldb/include/lldb/Symbol/SymbolFile.h b/lldb/include/lldb/Symbol/SymbolFile.h --- a/lldb/include/lldb/Symbol/SymbolFile.h +++ b/lldb/include/lldb/Symbol/SymbolFile.h @@ -435,6 +435,12 @@ virtual lldb::TypeSP CopyType(const lldb::TypeSP &other_type) = 0; + /// Returns true if the option exists in the compile options encoded in + /// the symbol file. + virtual bool ContainsCompileOption(const char *option) { + return false; + } + protected: void AssertModuleLock(); diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h @@ -340,6 +340,8 @@ m_file_index = file_index; } + bool ContainsCompileOption(const char *option) override; + protected: typedef llvm::DenseMap DIEToTypePtr; diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp @@ -4255,3 +4255,36 @@ return Status("no variable information is available in debug info for this " "compile unit"); } + +bool SymbolFileDWARF::ContainsCompileOption(const char *option) { + auto check_in_dwarf_cu = [&option](DWARFUnit *dwarf_cu) { + const DWARFBaseDIE die = dwarf_cu->GetUnitDIEOnly(); + if (!die) + return false; + const char *flags = die.GetAttributeValueAsString(DW_AT_APPLE_flags, NULL); + + if (!flags) + return false; + if (!strstr(flags, option)) + return false; + Args compiler_args(flags); + for (auto &arg : compiler_args.GetArgumentArrayRef()) + if (strcmp(arg, option) == 0) + return true; + + return false; + }; + + DWARFDebugInfo &debug_info = DebugInfo(); + const uint32_t num_compile_units = GetNumCompileUnits(); + + for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) { + DWARFUnit *dwarf_cu = debug_info.GetUnitAtIndex(cu_idx); + if (dwarf_cu) { + if (check_in_dwarf_cu(dwarf_cu)) + return true; + } + } + + return false; +} diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h @@ -153,6 +153,8 @@ // Statistics overrides. lldb_private::ModuleList GetDebugInfoModules() override; + bool ContainsCompileOption(const char *option) override; + protected: enum { kHaveInitializedOSOs = (1 << 0), kNumFlags }; diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp @@ -1549,3 +1549,12 @@ } return Status(); } + +bool SymbolFileDWARFDebugMap::ContainsCompileOption(const char *option) { + bool success = false; + ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool { + success |= oso_dwarf->ContainsCompileOption(option); + return success; + }); + return success; +}