Skip to content

Commit 7f3c702

Browse files
committed
[lldb] Load embedded type summary section
1 parent 91cd37b commit 7f3c702

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

lldb/source/Target/Target.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "lldb/Core/StructuredDataImpl.h"
2828
#include "lldb/Core/ValueObject.h"
2929
#include "lldb/Core/ValueObjectConstResult.h"
30+
#include "lldb/DataFormatters/DataVisualization.h"
3031
#include "lldb/Expression/DiagnosticManager.h"
3132
#include "lldb/Expression/ExpressionVariable.h"
3233
#include "lldb/Expression/REPL.h"
@@ -1438,6 +1439,54 @@ static void LoadScriptingResourceForModule(const ModuleSP &module_sp,
14381439
feedback_stream.GetData());
14391440
}
14401441

1442+
static void LoadTypeSummariesForModule(ModuleSP module_sp) {
1443+
auto *sections = module_sp->GetSectionList();
1444+
if (!sections)
1445+
return;
1446+
1447+
llvm::Triple triple = module_sp->GetArchitecture().GetTriple();
1448+
SectionSP summaries_sp;
1449+
if (triple.isOSDarwin()) {
1450+
if (auto data_sp = sections->FindSectionByName(ConstString("__DATA_CONST")))
1451+
summaries_sp = data_sp->GetChildren().FindSectionByName(
1452+
ConstString("__lldbsummaries"));
1453+
} else if (triple.isOSLinux() || triple.isOSWindows()) {
1454+
summaries_sp = sections->FindSectionByName(ConstString(".lldbsummaries"));
1455+
}
1456+
1457+
if (!summaries_sp)
1458+
return;
1459+
1460+
TypeCategoryImplSP category;
1461+
DataVisualization::Categories::GetCategory(ConstString("default"), category);
1462+
1463+
DataExtractor extractor;
1464+
auto section_size = summaries_sp->GetSectionData(extractor);
1465+
lldb::offset_t offset = 0;
1466+
while (offset < section_size) {
1467+
uint64_t version = extractor.GetULEB128(&offset);
1468+
uint64_t record_size = extractor.GetULEB128(&offset);
1469+
if (version == 1) {
1470+
uint64_t type_size = extractor.GetULEB128(&offset);
1471+
llvm::StringRef type_name = extractor.GetCStr(&offset, type_size);
1472+
uint64_t summary_size = extractor.GetULEB128(&offset);
1473+
llvm::StringRef summary_string = extractor.GetCStr(&offset, summary_size);
1474+
if (!type_name.empty() && !summary_string.empty()) {
1475+
TypeSummaryImpl::Flags flags;
1476+
auto summary_sp =
1477+
std::make_shared<StringSummaryFormat>(flags, summary_string.data());
1478+
FormatterMatchType match_type = lldb::eFormatterMatchExact;
1479+
if (summary_string.front() == '^' && summary_string.back() == '$')
1480+
match_type = eFormatterMatchRegex;
1481+
category->AddTypeSummary(type_name, match_type, summary_sp);
1482+
}
1483+
} else {
1484+
// Skip unsupported record.
1485+
offset += record_size;
1486+
}
1487+
}
1488+
}
1489+
14411490
void Target::ClearModules(bool delete_locations) {
14421491
ModulesDidUnload(m_images, delete_locations);
14431492
m_section_load_history.Clear();
@@ -1682,6 +1731,7 @@ void Target::ModulesDidLoad(ModuleList &module_list) {
16821731
for (size_t idx = 0; idx < num_images; ++idx) {
16831732
ModuleSP module_sp(module_list.GetModuleAtIndex(idx));
16841733
LoadScriptingResourceForModule(module_sp, this);
1734+
LoadTypeSummariesForModule(module_sp);
16851735
}
16861736
m_breakpoint_list.UpdateBreakpoints(module_list, true, false);
16871737
m_internal_breakpoint_list.UpdateBreakpoints(module_list, true, false);

0 commit comments

Comments
 (0)