Skip to content

Commit 19d969e

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
1 parent d5a50b0 commit 19d969e

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 <optional>
33+
#include <unordered_map>
3334

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

436437
virtual lldb::TypeSP CopyType(const lldb::TypeSP &other_type) = 0;
437438

439+
/// Returns a map of compilation unit to the compile option arguments
440+
/// associated with that compilation unit.
441+
std::unordered_map<lldb::CompUnitSP, Args> GetCompileOptions() {
442+
std::unordered_map<lldb::CompUnitSP, Args> args;
443+
GetCompileOptions(args);
444+
return args;
445+
}
446+
438447
protected:
439448
void AssertModuleLock();
440449

450+
virtual void GetCompileOptions(
451+
std::unordered_map<lldb::CompUnitSP, lldb_private::Args> &args) {}
452+
441453
private:
442454
SymbolFile(const SymbolFile &) = delete;
443455
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
@@ -4255,3 +4255,30 @@ Status SymbolFileDWARF::CalculateFrameVariableError(StackFrame &frame) {
42554255
return Status("no variable information is available in debug info for this "
42564256
"compile unit");
42574257
}
4258+
4259+
void SymbolFileDWARF::GetCompileOptions(
4260+
std::unordered_map<lldb::CompUnitSP, lldb_private::Args> &args) {
4261+
4262+
const uint32_t num_compile_units = GetNumCompileUnits();
4263+
4264+
for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) {
4265+
lldb::CompUnitSP comp_unit = GetCompileUnitAtIndex(cu_idx);
4266+
if (!comp_unit)
4267+
continue;
4268+
4269+
DWARFUnit *dwarf_cu = GetDWARFCompileUnit(comp_unit.get());
4270+
if (!dwarf_cu)
4271+
continue;
4272+
4273+
const DWARFBaseDIE die = dwarf_cu->GetUnitDIEOnly();
4274+
if (!die)
4275+
continue;
4276+
4277+
const char *flags = die.GetAttributeValueAsString(DW_AT_APPLE_flags, NULL);
4278+
4279+
if (!flags)
4280+
continue;
4281+
args.insert({comp_unit, Args(flags)});
4282+
}
4283+
}
4284+

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

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

524524
void InitializeFirstCodeAddress();
525525

526+
void GetCompileOptions(
527+
std::unordered_map<lldb::CompUnitSP, lldb_private::Args> &args) override;
528+
526529
lldb::ModuleWP m_debug_map_module_wp;
527530
SymbolFileDWARFDebugMap *m_debug_map_symfile;
528531

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,3 +1549,12 @@ Status SymbolFileDWARFDebugMap::CalculateFrameVariableError(StackFrame &frame) {
15491549
}
15501550
return Status();
15511551
}
1552+
1553+
void SymbolFileDWARFDebugMap::GetCompileOptions(
1554+
std::unordered_map<lldb::CompUnitSP, lldb_private::Args> &args) {
1555+
1556+
ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool {
1557+
oso_dwarf->GetCompileOptions(args);
1558+
return false;
1559+
});
1560+
}

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

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

156+
void GetCompileOptions(
157+
std::unordered_map<lldb::CompUnitSP, lldb_private::Args> &args) override;
158+
156159
protected:
157160
enum { kHaveInitializedOSOs = (1 << 0), kNumFlags };
158161

0 commit comments

Comments
 (0)