From 3313225fad5f8654c62aa29eaf3d4b9468e28dac Mon Sep 17 00:00:00 2001 From: Dave Lee Date: Thu, 8 Feb 2024 09:33:28 -0800 Subject: [PATCH] [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). (cherry-picked from commit 87ace14daa2139a1095d0be7bf5702c12c2befa8) --- lldb/source/Target/Target.cpp | 18 ++++++++++++++++++ .../data-formatter/embedded-summary/main.c | 6 ++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp index 074f8840011a0..93e1edb3e4bcc 100644 --- a/lldb/source/Target/Target.cpp +++ b/lldb/source/Target/Target.cpp @@ -1515,8 +1515,26 @@ static void LoadTypeSummariesForModule(ModuleSP module_sp) { auto section_size = summaries_sp->GetSectionData(extractor); lldb::offset_t offset = 0; while (offset < section_size) { + // Skip null bytes. Can happen with alignment padding. + while (true) { + auto next_offset = offset; + if (extractor.GetU8(&next_offset) != 0) { + break; + } + // Move past the null byte, using the advanced offset. + offset = next_offset; + } + uint64_t version = extractor.GetULEB128(&offset); uint64_t record_size = extractor.GetULEB128(&offset); + if (record_size == 0) { + LLDB_LOGF(log, + "Skipping empty (malformed) embedded type summary of version " + "%llu in %s.", + version, module_name); + continue; + } + if (version == 1) { uint64_t type_size = extractor.GetULEB128(&offset); llvm::StringRef type_name = extractor.GetCStr(&offset, type_size); diff --git a/lldb/test/API/functionalities/data-formatter/embedded-summary/main.c b/lldb/test/API/functionalities/data-formatter/embedded-summary/main.c index 6459f6de9a006..d16a90471d3c9 100644 --- a/lldb/test/API/functionalities/data-formatter/embedded-summary/main.c +++ b/lldb/test/API/functionalities/data-formatter/embedded-summary/main.c @@ -5,8 +5,7 @@ struct Player { int number; }; -__attribute__((aligned(1), used, - section("__DATA_CONST,__lldbsummaries"))) unsigned char +__attribute__((used, section("__DATA_CONST,__lldbsummaries"))) unsigned char _Player_type_summary[] = "\x01" // version "\x25" // record size "\x07" // type name size @@ -20,8 +19,7 @@ struct Layer { }; // Near copy of the record for `Player`, using a regex type name (`^Layer`). -__attribute__((aligned(1), used, - section("__DATA_CONST,__lldbsummaries"))) unsigned char +__attribute__((used, section("__DATA_CONST,__lldbsummaries"))) unsigned char _Layer_type_summary[] = "\x01" // version "\x25" // record size "\x07" // type name size