Skip to content

Commit f22cff7

Browse files
[lldb] Support zero-padding in formatter sections (#119934)
1 parent d015578 commit f22cff7

File tree

3 files changed

+37
-8
lines changed

3 files changed

+37
-8
lines changed

lldb/source/DataFormatters/FormatterSection.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ static void ForEachFormatterInModule(
5050
uint8_t addr_size = section.getAddressSize();
5151
llvm::DataExtractor::Cursor cursor(0);
5252
while (cursor && cursor.tell() < section_size) {
53+
while (cursor && cursor.tell() < section_size) {
54+
// Skip over 0 padding.
55+
if (section.getU8(cursor) == 0)
56+
continue;
57+
cursor.seek(cursor.tell() - 1);
58+
break;
59+
}
5360
uint64_t version = section.getULEB128(cursor);
5461
uint64_t record_size = section.getULEB128(cursor);
5562
if (version == 1) {

lldb/test/API/functionalities/data-formatter/embedded-summary/TestEmbeddedTypeSummary.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ def test(self):
1010
self.build()
1111
lldbutil.run_to_source_breakpoint(self, "break here", lldb.SBFileSpec("main.c"))
1212
self.expect("v player", substrs=['"Dirk" (41)'])
13+
self.expect("v layer", substrs=['"crust" (3)'])
Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,43 @@
1-
#include <stdio.h>
1+
void puts(const char *);
2+
3+
#define LLDBSUMMARY __attribute__((section("__TEXT,__lldbsummaries"), used))
24

35
struct Player {
46
char *name;
57
int number;
68
};
79

8-
__attribute__((used, section("__DATA_CONST,__lldbsummaries"))) unsigned char
9-
_Player_type_summary[] = "\x01" // version
10-
"\x25" // record size
11-
"\x07" // type name size
12-
"Player\0" // type name
13-
"\x1c" // summary string size
14-
"${var.name} (${var.number})"; // summary string
10+
LLDBSUMMARY unsigned char _Player_type_summary[] =
11+
"\x01" // version
12+
"\x25" // record size
13+
"\x07" // type name size
14+
"Player\0" // type name
15+
"\x1c" // summary string size
16+
"${var.name} (${var.number})"; // summary string
17+
18+
struct Layer {
19+
char *name;
20+
int number;
21+
};
22+
23+
LLDBSUMMARY unsigned char _padding[] = "\x00\x00";
24+
25+
// Near copy of the record for `Player`, using a regex type name (`^Layer`).
26+
LLDBSUMMARY unsigned char _Layer_type_summary[] =
27+
"\x01" // version
28+
"\x25" // record size
29+
"\x07" // type name size
30+
"^Layer\0" // type name
31+
"\x1c" // summary string size
32+
"${var.name} (${var.number})"; // summary string
1533

1634
int main() {
1735
struct Player player;
1836
player.name = "Dirk";
1937
player.number = 41;
38+
struct Layer layer;
39+
layer.name = "crust";
40+
layer.number = 3;
2041
puts("break here");
2142
return 0;
2243
}

0 commit comments

Comments
 (0)