Skip to content

[lldb] Skip null bytes in embedded type summaries #8132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions lldb/source/Target/Target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1476,8 +1476,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) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is next_offset needed? Does GetU8 modify the parameter in the failure case?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, the passed in offset is an in-out parameter. As far as GetU8 is concerned, reading a zero byte is not a failure case. If there was a PeekU8 method that would be better suited.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

open to suggestions

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No this is fine. I misread the condition, as checking for an error, but it's checking for the NUL byte.

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down