Skip to content

Commit 87ace14

Browse files
authored
[lldb] Skip null bytes in embedded type summaries (#8132)
Handle null padding that may exists between embedded type summary records. This can happen for example on x86-64 where the default alignment of `char[]` is 16 (p2align = 4).
1 parent 5742c05 commit 87ace14

File tree

2 files changed

+20
-4
lines changed
  • lldb
    • source/Target
    • test/API/functionalities/data-formatter/embedded-summary

2 files changed

+20
-4
lines changed

lldb/source/Target/Target.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,8 +1476,26 @@ static void LoadTypeSummariesForModule(ModuleSP module_sp) {
14761476
auto section_size = summaries_sp->GetSectionData(extractor);
14771477
lldb::offset_t offset = 0;
14781478
while (offset < section_size) {
1479+
// Skip null bytes. Can happen with alignment padding.
1480+
while (true) {
1481+
auto next_offset = offset;
1482+
if (extractor.GetU8(&next_offset) != 0) {
1483+
break;
1484+
}
1485+
// Move past the null byte, using the advanced offset.
1486+
offset = next_offset;
1487+
}
1488+
14791489
uint64_t version = extractor.GetULEB128(&offset);
14801490
uint64_t record_size = extractor.GetULEB128(&offset);
1491+
if (record_size == 0) {
1492+
LLDB_LOGF(log,
1493+
"Skipping empty (malformed) embedded type summary of version "
1494+
"%llu in %s.",
1495+
version, module_name);
1496+
continue;
1497+
}
1498+
14811499
if (version == 1) {
14821500
uint64_t type_size = extractor.GetULEB128(&offset);
14831501
llvm::StringRef type_name = extractor.GetCStr(&offset, type_size);

lldb/test/API/functionalities/data-formatter/embedded-summary/main.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ struct Player {
55
int number;
66
};
77

8-
__attribute__((aligned(1), used,
9-
section("__DATA_CONST,__lldbsummaries"))) unsigned char
8+
__attribute__((used, section("__DATA_CONST,__lldbsummaries"))) unsigned char
109
_Player_type_summary[] = "\x01" // version
1110
"\x25" // record size
1211
"\x07" // type name size
@@ -20,8 +19,7 @@ struct Layer {
2019
};
2120

2221
// Near copy of the record for `Player`, using a regex type name (`^Layer`).
23-
__attribute__((aligned(1), used,
24-
section("__DATA_CONST,__lldbsummaries"))) unsigned char
22+
__attribute__((used, section("__DATA_CONST,__lldbsummaries"))) unsigned char
2523
_Layer_type_summary[] = "\x01" // version
2624
"\x25" // record size
2725
"\x07" // type name size

0 commit comments

Comments
 (0)