|
26 | 26 | #include "lldb/Core/StructuredDataImpl.h"
|
27 | 27 | #include "lldb/Core/ValueObject.h"
|
28 | 28 | #include "lldb/Core/ValueObjectConstResult.h"
|
| 29 | +#include "lldb/DataFormatters/DataVisualization.h" |
29 | 30 | #include "lldb/Expression/DiagnosticManager.h"
|
30 | 31 | #include "lldb/Expression/ExpressionVariable.h"
|
31 | 32 | #include "lldb/Expression/REPL.h"
|
@@ -1537,6 +1538,76 @@ static void LoadScriptingResourceForModule(const ModuleSP &module_sp,
|
1537 | 1538 | feedback_stream.GetData());
|
1538 | 1539 | }
|
1539 | 1540 |
|
| 1541 | +// Load type summaries embedded in the binary. These are type summaries provided |
| 1542 | +// by the authors of the code. |
| 1543 | +static void LoadTypeSummariesForModule(ModuleSP module_sp) { |
| 1544 | + auto *sections = module_sp->GetSectionList(); |
| 1545 | + if (!sections) |
| 1546 | + return; |
| 1547 | + |
| 1548 | + auto summaries_sp = |
| 1549 | + sections->FindSectionByType(eSectionTypeLLDBTypeSummaries, true); |
| 1550 | + if (!summaries_sp) |
| 1551 | + return; |
| 1552 | + |
| 1553 | + Log *log = GetLog(LLDBLog::DataFormatters); |
| 1554 | + const char *module_name = module_sp->GetObjectName().GetCString(); |
| 1555 | + |
| 1556 | + TypeCategoryImplSP category; |
| 1557 | + DataVisualization::Categories::GetCategory(ConstString("default"), category); |
| 1558 | + |
| 1559 | + // The type summary record is serialized as follows. |
| 1560 | + // |
| 1561 | + // Each record contains, in order: |
| 1562 | + // * Version number of the record format |
| 1563 | + // * The remaining size of the record |
| 1564 | + // * The size of the type identifier |
| 1565 | + // * The type identifier, either a type name, or a regex |
| 1566 | + // * The size of the summary string |
| 1567 | + // * The summary string |
| 1568 | + // |
| 1569 | + // Integers are encoded using ULEB. |
| 1570 | + // |
| 1571 | + // Strings are encoded with first a length (ULEB), then the string contents, |
| 1572 | + // and lastly a null terminator. The length includes the null. |
| 1573 | + |
| 1574 | + DataExtractor extractor; |
| 1575 | + auto section_size = summaries_sp->GetSectionData(extractor); |
| 1576 | + lldb::offset_t offset = 0; |
| 1577 | + while (offset < section_size) { |
| 1578 | + uint64_t version = extractor.GetULEB128(&offset); |
| 1579 | + uint64_t record_size = extractor.GetULEB128(&offset); |
| 1580 | + if (version == 1) { |
| 1581 | + uint64_t type_size = extractor.GetULEB128(&offset); |
| 1582 | + llvm::StringRef type_name = extractor.GetCStr(&offset, type_size); |
| 1583 | + uint64_t summary_size = extractor.GetULEB128(&offset); |
| 1584 | + llvm::StringRef summary_string = extractor.GetCStr(&offset, summary_size); |
| 1585 | + if (!type_name.empty() && !summary_string.empty()) { |
| 1586 | + TypeSummaryImpl::Flags flags; |
| 1587 | + auto summary_sp = |
| 1588 | + std::make_shared<StringSummaryFormat>(flags, summary_string.data()); |
| 1589 | + FormatterMatchType match_type = eFormatterMatchExact; |
| 1590 | + if (summary_string.front() == '^' && summary_string.back() == '$') |
| 1591 | + match_type = eFormatterMatchRegex; |
| 1592 | + category->AddTypeSummary(type_name, match_type, summary_sp); |
| 1593 | + LLDB_LOGF(log, "Loaded embedded type summary for '%s' from %s.", |
| 1594 | + type_name.data(), module_name); |
| 1595 | + } else { |
| 1596 | + if (type_name.empty()) |
| 1597 | + LLDB_LOGF(log, "Missing string(s) in embedded type summary in %s.", |
| 1598 | + module_name); |
| 1599 | + } |
| 1600 | + } else { |
| 1601 | + // Skip unsupported record. |
| 1602 | + offset += record_size; |
| 1603 | + LLDB_LOGF( |
| 1604 | + log, |
| 1605 | + "Skipping unsupported embedded type summary of version %llu in %s.", |
| 1606 | + version, module_name); |
| 1607 | + } |
| 1608 | + } |
| 1609 | +} |
| 1610 | + |
1540 | 1611 | void Target::ClearModules(bool delete_locations) {
|
1541 | 1612 | ModulesDidUnload(m_images, delete_locations);
|
1542 | 1613 | m_section_load_history.Clear();
|
@@ -1775,6 +1846,7 @@ void Target::ModulesDidLoad(ModuleList &module_list) {
|
1775 | 1846 | for (size_t idx = 0; idx < num_images; ++idx) {
|
1776 | 1847 | ModuleSP module_sp(module_list.GetModuleAtIndex(idx));
|
1777 | 1848 | LoadScriptingResourceForModule(module_sp, this);
|
| 1849 | + LoadTypeSummariesForModule(module_sp); |
1778 | 1850 | }
|
1779 | 1851 | m_breakpoint_list.UpdateBreakpoints(module_list, true, false);
|
1780 | 1852 | m_internal_breakpoint_list.UpdateBreakpoints(module_list, true, false);
|
|
0 commit comments