|
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,76 @@ static void LoadScriptingResourceForModule(const ModuleSP &module_sp,
|
1438 | 1439 | feedback_stream.GetData());
|
1439 | 1440 | }
|
1440 | 1441 |
|
| 1442 | +// Load type summaries embedded in the binary. These are type summaries provided |
| 1443 | +// by the authors of the code. |
| 1444 | +static void LoadTypeSummariesForModule(ModuleSP module_sp) { |
| 1445 | + auto *sections = module_sp->GetSectionList(); |
| 1446 | + if (!sections) |
| 1447 | + return; |
| 1448 | + |
| 1449 | + auto summaries_sp = |
| 1450 | + sections->FindSectionByType(eSectionTypeLLDBTypeSummaries, true); |
| 1451 | + if (!summaries_sp) |
| 1452 | + return; |
| 1453 | + |
| 1454 | + Log *log = GetLog(LLDBLog::DataFormatters); |
| 1455 | + const char *module_name = module_sp->GetObjectName().GetCString(); |
| 1456 | + |
| 1457 | + TypeCategoryImplSP category; |
| 1458 | + DataVisualization::Categories::GetCategory(ConstString("default"), category); |
| 1459 | + |
| 1460 | + // The type summary record is serialized as follows. |
| 1461 | + // |
| 1462 | + // Each record contains, in order: |
| 1463 | + // * Version number of the record format |
| 1464 | + // * The remaining size of the record |
| 1465 | + // * The size of the type identifier |
| 1466 | + // * The type identifier, either a type name, or a regex |
| 1467 | + // * The size of the summary string |
| 1468 | + // * The summary string |
| 1469 | + // |
| 1470 | + // Integers are encoded using ULEB. |
| 1471 | + // |
| 1472 | + // Strings are encoded with first a length (ULEB), then the string contents, |
| 1473 | + // and lastly a null terminator. The length includes the null. |
| 1474 | + |
| 1475 | + DataExtractor extractor; |
| 1476 | + auto section_size = summaries_sp->GetSectionData(extractor); |
| 1477 | + lldb::offset_t offset = 0; |
| 1478 | + while (offset < section_size) { |
| 1479 | + uint64_t version = extractor.GetULEB128(&offset); |
| 1480 | + uint64_t record_size = extractor.GetULEB128(&offset); |
| 1481 | + if (version == 1) { |
| 1482 | + uint64_t type_size = extractor.GetULEB128(&offset); |
| 1483 | + llvm::StringRef type_name = extractor.GetCStr(&offset, type_size); |
| 1484 | + uint64_t summary_size = extractor.GetULEB128(&offset); |
| 1485 | + llvm::StringRef summary_string = extractor.GetCStr(&offset, summary_size); |
| 1486 | + if (!type_name.empty() && !summary_string.empty()) { |
| 1487 | + TypeSummaryImpl::Flags flags; |
| 1488 | + auto summary_sp = |
| 1489 | + std::make_shared<StringSummaryFormat>(flags, summary_string.data()); |
| 1490 | + FormatterMatchType match_type = eFormatterMatchExact; |
| 1491 | + if (summary_string.front() == '^' && summary_string.back() == '$') |
| 1492 | + match_type = eFormatterMatchRegex; |
| 1493 | + category->AddTypeSummary(type_name, match_type, summary_sp); |
| 1494 | + LLDB_LOGF(log, "Loaded embedded type summary for '%s' from %s.", |
| 1495 | + type_name.data(), module_name); |
| 1496 | + } else { |
| 1497 | + if (type_name.empty()) |
| 1498 | + LLDB_LOGF(log, "Missing string(s) in embedded type summary in %s.", |
| 1499 | + module_name); |
| 1500 | + } |
| 1501 | + } else { |
| 1502 | + // Skip unsupported record. |
| 1503 | + offset += record_size; |
| 1504 | + LLDB_LOGF( |
| 1505 | + log, |
| 1506 | + "Skipping unsupported embedded type summary of version %llu in %s.", |
| 1507 | + version, module_name); |
| 1508 | + } |
| 1509 | + } |
| 1510 | +} |
| 1511 | + |
1441 | 1512 | void Target::ClearModules(bool delete_locations) {
|
1442 | 1513 | ModulesDidUnload(m_images, delete_locations);
|
1443 | 1514 | m_section_load_history.Clear();
|
@@ -1682,6 +1753,7 @@ void Target::ModulesDidLoad(ModuleList &module_list) {
|
1682 | 1753 | for (size_t idx = 0; idx < num_images; ++idx) {
|
1683 | 1754 | ModuleSP module_sp(module_list.GetModuleAtIndex(idx));
|
1684 | 1755 | LoadScriptingResourceForModule(module_sp, this);
|
| 1756 | + LoadTypeSummariesForModule(module_sp); |
1685 | 1757 | }
|
1686 | 1758 | m_breakpoint_list.UpdateBreakpoints(module_list, true, false);
|
1687 | 1759 | m_internal_breakpoint_list.UpdateBreakpoints(module_list, true, false);
|
|
0 commit comments