@@ -1439,6 +1439,8 @@ static void LoadScriptingResourceForModule(const ModuleSP &module_sp,
1439
1439
feedback_stream.GetData ());
1440
1440
}
1441
1441
1442
+ // Load type summaries embedded in the binary. These are type summaries provided
1443
+ // by the authors of the code.
1442
1444
static void LoadTypeSummariesForModule (ModuleSP module_sp) {
1443
1445
auto *sections = module_sp->GetSectionList ();
1444
1446
if (!sections)
@@ -1457,9 +1459,27 @@ static void LoadTypeSummariesForModule(ModuleSP module_sp) {
1457
1459
if (!summaries_sp)
1458
1460
return ;
1459
1461
1462
+ Log *log = GetLog (LLDBLog::DataFormatters);
1463
+ const char *module_name = module_sp->GetObjectName ().GetCString ();
1464
+
1460
1465
TypeCategoryImplSP category;
1461
1466
DataVisualization::Categories::GetCategory (ConstString (" default" ), category);
1462
1467
1468
+ // The type summary record is serialized as follows.
1469
+ //
1470
+ // Each record contains, in order:
1471
+ // * Version number of the record format
1472
+ // * The remaining size of the record
1473
+ // * The size of the type identifier
1474
+ // * The type identifier, either a type name, or a regex
1475
+ // * The size of the summary string
1476
+ // * The summary string
1477
+ //
1478
+ // Integers are encoded using ULEB.
1479
+ //
1480
+ // Strings are encoded with first a length (ULEB), then the string contents,
1481
+ // and lastly a null terminator. The length includes the null.
1482
+
1463
1483
DataExtractor extractor;
1464
1484
auto section_size = summaries_sp->GetSectionData (extractor);
1465
1485
lldb::offset_t offset = 0 ;
@@ -1475,14 +1495,24 @@ static void LoadTypeSummariesForModule(ModuleSP module_sp) {
1475
1495
TypeSummaryImpl::Flags flags;
1476
1496
auto summary_sp =
1477
1497
std::make_shared<StringSummaryFormat>(flags, summary_string.data ());
1478
- FormatterMatchType match_type = lldb:: eFormatterMatchExact;
1498
+ FormatterMatchType match_type = eFormatterMatchExact;
1479
1499
if (summary_string.front () == ' ^' && summary_string.back () == ' $' )
1480
1500
match_type = eFormatterMatchRegex;
1481
1501
category->AddTypeSummary (type_name, match_type, summary_sp);
1502
+ LLDB_LOGF (log, " Loaded embedded type summary for '%s' from %s." ,
1503
+ type_name.data (), module_name);
1504
+ } else {
1505
+ if (type_name.empty ())
1506
+ LLDB_LOGF (log, " Missing string(s) in embedded type summary in %s." ,
1507
+ module_name);
1482
1508
}
1483
1509
} else {
1484
1510
// Skip unsupported record.
1485
1511
offset += record_size;
1512
+ LLDB_LOGF (
1513
+ log,
1514
+ " Skipping unsupported embedded type summary of version %llu in %s." ,
1515
+ version, module_name);
1486
1516
}
1487
1517
}
1488
1518
}
0 commit comments