Skip to content

Commit

Permalink
[lldb] Support zero-padding in formatter sections (#119934)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrian-prantl authored Dec 14, 2024
1 parent d015578 commit f22cff7
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
7 changes: 7 additions & 0 deletions lldb/source/DataFormatters/FormatterSection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ def test(self):
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)'])
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit f22cff7

Please sign in to comment.