[lldb] Support zero-padding in formatter sections (#119934)

This commit is contained in:
Adrian Prantl
2024-12-13 16:09:31 -08:00
committed by GitHub
parent d015578961
commit f22cff7675
3 changed files with 37 additions and 8 deletions

View File

@@ -50,6 +50,13 @@ static void ForEachFormatterInModule(
uint8_t addr_size = section.getAddressSize();
llvm::DataExtractor::Cursor cursor(0);
while (cursor && cursor.tell() < section_size) {
while (cursor && cursor.tell() < section_size) {
// Skip over 0 padding.
if (section.getU8(cursor) == 0)
continue;
cursor.seek(cursor.tell() - 1);
break;
}
uint64_t version = section.getULEB128(cursor);
uint64_t record_size = section.getULEB128(cursor);
if (version == 1) {

View File

@@ -10,3 +10,4 @@ class TestCase(TestBase):
self.build()
lldbutil.run_to_source_breakpoint(self, "break here", lldb.SBFileSpec("main.c"))
self.expect("v player", substrs=['"Dirk" (41)'])
self.expect("v layer", substrs=['"crust" (3)'])

View File

@@ -1,22 +1,43 @@
#include <stdio.h>
void puts(const char *);
#define LLDBSUMMARY __attribute__((section("__TEXT,__lldbsummaries"), used))
struct Player {
char *name;
int number;
};
__attribute__((used, section("__DATA_CONST,__lldbsummaries"))) unsigned char
_Player_type_summary[] = "\x01" // version
"\x25" // record size
"\x07" // type name size
"Player\0" // type name
"\x1c" // summary string size
"${var.name} (${var.number})"; // summary string
LLDBSUMMARY unsigned char _Player_type_summary[] =
"\x01" // version
"\x25" // record size
"\x07" // type name size
"Player\0" // type name
"\x1c" // summary string size
"${var.name} (${var.number})"; // summary string
struct Layer {
char *name;
int number;
};
LLDBSUMMARY unsigned char _padding[] = "\x00\x00";
// Near copy of the record for `Player`, using a regex type name (`^Layer`).
LLDBSUMMARY unsigned char _Layer_type_summary[] =
"\x01" // version
"\x25" // record size
"\x07" // type name size
"^Layer\0" // type name
"\x1c" // summary string size
"${var.name} (${var.number})"; // summary string
int main() {
struct Player player;
player.name = "Dirk";
player.number = 41;
struct Layer layer;
layer.name = "crust";
layer.number = 3;
puts("break here");
return 0;
}