Skip to content

Commit 401d748

Browse files
committed
[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 (cherry picked from commit 19d969e)
1 parent a34ab3c commit 401d748

File tree

5 files changed

+54
-0
lines changed

5 files changed

+54
-0
lines changed

lldb/include/lldb/Symbol/SymbolFile.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
#include <mutex>
3232
#include <vector>
33+
#include <unordered_map>
3334

3435
#if defined(LLDB_CONFIGURATION_DEBUG)
3536
#define ASSERT_MODULE_LOCK(expr) (expr->AssertModuleLock())
@@ -471,9 +472,20 @@ class SymbolFile : public PluginInterface {
471472

472473
virtual lldb::TypeSP CopyType(const lldb::TypeSP &other_type) = 0;
473474

475+
/// Returns a map of compilation unit to the compile option arguments
476+
/// associated with that compilation unit.
477+
std::unordered_map<lldb::CompUnitSP, Args> GetCompileOptions() {
478+
std::unordered_map<lldb::CompUnitSP, Args> args;
479+
GetCompileOptions(args);
480+
return args;
481+
}
482+
474483
protected:
475484
void AssertModuleLock();
476485

486+
virtual void GetCompileOptions(
487+
std::unordered_map<lldb::CompUnitSP, lldb_private::Args> &args) {}
488+
477489
private:
478490
SymbolFile(const SymbolFile &) = delete;
479491
const SymbolFile &operator=(const SymbolFile &) = delete;

lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4282,3 +4282,30 @@ Status SymbolFileDWARF::CalculateFrameVariableError(StackFrame &frame) {
42824282
return Status("no variable information is available in debug info for this "
42834283
"compile unit");
42844284
}
4285+
4286+
void SymbolFileDWARF::GetCompileOptions(
4287+
std::unordered_map<lldb::CompUnitSP, lldb_private::Args> &args) {
4288+
4289+
const uint32_t num_compile_units = GetNumCompileUnits();
4290+
4291+
for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) {
4292+
lldb::CompUnitSP comp_unit = GetCompileUnitAtIndex(cu_idx);
4293+
if (!comp_unit)
4294+
continue;
4295+
4296+
DWARFUnit *dwarf_cu = GetDWARFCompileUnit(comp_unit.get());
4297+
if (!dwarf_cu)
4298+
continue;
4299+
4300+
const DWARFBaseDIE die = dwarf_cu->GetUnitDIEOnly();
4301+
if (!die)
4302+
continue;
4303+
4304+
const char *flags = die.GetAttributeValueAsString(DW_AT_APPLE_flags, NULL);
4305+
4306+
if (!flags)
4307+
continue;
4308+
args.insert({comp_unit, Args(flags)});
4309+
}
4310+
}
4311+

lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,9 @@ class SymbolFileDWARF : public lldb_private::SymbolFileCommon,
545545

546546
void InitializeFirstCodeAddress();
547547

548+
void GetCompileOptions(
549+
std::unordered_map<lldb::CompUnitSP, lldb_private::Args> &args) override;
550+
548551
lldb::ModuleWP m_debug_map_module_wp;
549552
SymbolFileDWARFDebugMap *m_debug_map_symfile;
550553

lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1642,3 +1642,12 @@ Status SymbolFileDWARFDebugMap::CalculateFrameVariableError(StackFrame &frame) {
16421642
}
16431643
return Status();
16441644
}
1645+
1646+
void SymbolFileDWARFDebugMap::GetCompileOptions(
1647+
std::unordered_map<lldb::CompUnitSP, lldb_private::Args> &args) {
1648+
1649+
ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool {
1650+
oso_dwarf->GetCompileOptions(args);
1651+
return false;
1652+
});
1653+
}

lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ class SymbolFileDWARFDebugMap : public lldb_private::SymbolFileCommon {
160160
// Statistics overrides.
161161
lldb_private::ModuleList GetDebugInfoModules() override;
162162

163+
void GetCompileOptions(
164+
std::unordered_map<lldb::CompUnitSP, lldb_private::Args> &args) override;
165+
163166
protected:
164167
enum { kHaveInitializedOSOs = (1 << 0), kNumFlags };
165168

0 commit comments

Comments
 (0)