Skip to content

Commit c930e74

Browse files
authored
[lldb] Skip null bytes in embedded type summaries (#8132) (#8221)
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). (cherry-picked from commit 87ace14)
1 parent 6316425 commit c930e74

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
@@ -1515,8 +1515,26 @@ static void LoadTypeSummariesForModule(ModuleSP module_sp) {
15151515
auto section_size = summaries_sp->GetSectionData(extractor);
15161516
lldb::offset_t offset = 0;
15171517
while (offset < section_size) {
1518+
// Skip null bytes. Can happen with alignment padding.
1519+
while (true) {
1520+
auto next_offset = offset;
1521+
if (extractor.GetU8(&next_offset) != 0) {
1522+
break;
1523+
}
1524+
// Move past the null byte, using the advanced offset.
1525+
offset = next_offset;
1526+
}
1527+
15181528
uint64_t version = extractor.GetULEB128(&offset);
15191529
uint64_t record_size = extractor.GetULEB128(&offset);
1530+
if (record_size == 0) {
1531+
LLDB_LOGF(log,
1532+
"Skipping empty (malformed) embedded type summary of version "
1533+
"%llu in %s.",
1534+
version, module_name);
1535+
continue;
1536+
}
1537+
15201538
if (version == 1) {
15211539
uint64_t type_size = extractor.GetULEB128(&offset);
15221540
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)