|
27 | 27 | #include "lldb/Core/StructuredDataImpl.h"
|
28 | 28 | #include "lldb/Core/ValueObject.h"
|
29 | 29 | #include "lldb/Core/ValueObjectConstResult.h"
|
| 30 | +#include "lldb/DataFormatters/DataVisualization.h" |
30 | 31 | #include "lldb/Expression/DiagnosticManager.h"
|
31 | 32 | #include "lldb/Expression/ExpressionVariable.h"
|
32 | 33 | #include "lldb/Expression/REPL.h"
|
@@ -1438,6 +1439,54 @@ static void LoadScriptingResourceForModule(const ModuleSP &module_sp,
|
1438 | 1439 | feedback_stream.GetData());
|
1439 | 1440 | }
|
1440 | 1441 |
|
| 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 | + |
1441 | 1490 | void Target::ClearModules(bool delete_locations) {
|
1442 | 1491 | ModulesDidUnload(m_images, delete_locations);
|
1443 | 1492 | m_section_load_history.Clear();
|
@@ -1682,6 +1731,7 @@ void Target::ModulesDidLoad(ModuleList &module_list) {
|
1682 | 1731 | for (size_t idx = 0; idx < num_images; ++idx) {
|
1683 | 1732 | ModuleSP module_sp(module_list.GetModuleAtIndex(idx));
|
1684 | 1733 | LoadScriptingResourceForModule(module_sp, this);
|
| 1734 | + LoadTypeSummariesForModule(module_sp); |
1685 | 1735 | }
|
1686 | 1736 | m_breakpoint_list.UpdateBreakpoints(module_list, true, false);
|
1687 | 1737 | m_internal_breakpoint_list.UpdateBreakpoints(module_list, true, false);
|
|
0 commit comments