Author: Augusto Noronha Date: 2023-04-10T10:13:06-07:00 New Revision: 19d969e340c9e1b5a83ad5220ba0875393df71e2
URL: https://github.com/llvm/llvm-project/commit/19d969e340c9e1b5a83ad5220ba0875393df71e2 DIFF: https://github.com/llvm/llvm-project/commit/19d969e340c9e1b5a83ad5220ba0875393df71e2.diff LOG: [lldb] Implement SymbolFile::GetCompileOptions Implement SymbolFile::GetCompileOptions, which returns a map from compilation units to compilation arguments associated with that unit. Differential Revision: https://reviews.llvm.org/D147748 Added: Modified: lldb/include/lldb/Symbol/SymbolFile.h lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h Removed: ################################################################################ diff --git a/lldb/include/lldb/Symbol/SymbolFile.h b/lldb/include/lldb/Symbol/SymbolFile.h index d3e3166ab27ff..90162b7827d3a 100644 --- a/lldb/include/lldb/Symbol/SymbolFile.h +++ b/lldb/include/lldb/Symbol/SymbolFile.h @@ -30,6 +30,7 @@ #include <mutex> #include <optional> +#include <unordered_map> #if defined(LLDB_CONFIGURATION_DEBUG) #define ASSERT_MODULE_LOCK(expr) (expr->AssertModuleLock()) @@ -435,9 +436,20 @@ class SymbolFile : public PluginInterface { virtual lldb::TypeSP CopyType(const lldb::TypeSP &other_type) = 0; + /// Returns a map of compilation unit to the compile option arguments + /// associated with that compilation unit. + std::unordered_map<lldb::CompUnitSP, Args> GetCompileOptions() { + std::unordered_map<lldb::CompUnitSP, Args> args; + GetCompileOptions(args); + return args; + } + protected: void AssertModuleLock(); + virtual void GetCompileOptions( + std::unordered_map<lldb::CompUnitSP, lldb_private::Args> &args) {} + private: SymbolFile(const SymbolFile &) = delete; const SymbolFile &operator=(const SymbolFile &) = delete; diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp index c6873a5b7a09a..837d87cdebbb3 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp @@ -4255,3 +4255,30 @@ Status SymbolFileDWARF::CalculateFrameVariableError(StackFrame &frame) { return Status("no variable information is available in debug info for this " "compile unit"); } + +void SymbolFileDWARF::GetCompileOptions( + std::unordered_map<lldb::CompUnitSP, lldb_private::Args> &args) { + + const uint32_t num_compile_units = GetNumCompileUnits(); + + for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) { + lldb::CompUnitSP comp_unit = GetCompileUnitAtIndex(cu_idx); + if (!comp_unit) + continue; + + DWARFUnit *dwarf_cu = GetDWARFCompileUnit(comp_unit.get()); + if (!dwarf_cu) + continue; + + const DWARFBaseDIE die = dwarf_cu->GetUnitDIEOnly(); + if (!die) + continue; + + const char *flags = die.GetAttributeValueAsString(DW_AT_APPLE_flags, NULL); + + if (!flags) + continue; + args.insert({comp_unit, Args(flags)}); + } +} + diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h index 09787d5072aa4..0616846d8dc62 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h @@ -523,6 +523,9 @@ class SymbolFileDWARF : public lldb_private::SymbolFileCommon { void InitializeFirstCodeAddress(); + void GetCompileOptions( + std::unordered_map<lldb::CompUnitSP, lldb_private::Args> &args) override; + lldb::ModuleWP m_debug_map_module_wp; SymbolFileDWARFDebugMap *m_debug_map_symfile; diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp index 9b22b1b94aae4..a07807241deba 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp @@ -1549,3 +1549,12 @@ Status SymbolFileDWARFDebugMap::CalculateFrameVariableError(StackFrame &frame) { } return Status(); } + +void SymbolFileDWARFDebugMap::GetCompileOptions( + std::unordered_map<lldb::CompUnitSP, lldb_private::Args> &args) { + + ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool { + oso_dwarf->GetCompileOptions(args); + return false; + }); +} diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h index 84f78d87d64ca..0313063119c78 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h @@ -153,6 +153,9 @@ class SymbolFileDWARFDebugMap : public lldb_private::SymbolFileCommon { // Statistics overrides. lldb_private::ModuleList GetDebugInfoModules() override; + void GetCompileOptions( + std::unordered_map<lldb::CompUnitSP, lldb_private::Args> &args) override; + protected: enum { kHaveInitializedOSOs = (1 << 0), kNumFlags }; _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits