Skip to content

Commit 81ae1b5

Browse files
authored
[lldb] Fix embedded type summary regex handling (#8121)
Fixes a logic error when determining if a type is a regex. Look for a leading `^` in the type name, not the summary string. Adds a test to verify regex handling. Fixes a log message to help debugging.
1 parent 8c84264 commit 81ae1b5

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

lldb/source/Target/Target.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,7 +1452,7 @@ static void LoadTypeSummariesForModule(ModuleSP module_sp) {
14521452
return;
14531453

14541454
Log *log = GetLog(LLDBLog::DataFormatters);
1455-
const char *module_name = module_sp->GetObjectName().GetCString();
1455+
const char *module_name = module_sp->GetFileSpec().GetFilename().GetCString();
14561456

14571457
TypeCategoryImplSP category;
14581458
DataVisualization::Categories::GetCategory(ConstString("default"), category);
@@ -1488,7 +1488,7 @@ static void LoadTypeSummariesForModule(ModuleSP module_sp) {
14881488
auto summary_sp =
14891489
std::make_shared<StringSummaryFormat>(flags, summary_string.data());
14901490
FormatterMatchType match_type = eFormatterMatchExact;
1491-
if (summary_string.front() == '^' && summary_string.back() == '$')
1491+
if (type_name.front() == '^')
14921492
match_type = eFormatterMatchRegex;
14931493
category->AddTypeSummary(type_name, match_type, summary_sp);
14941494
LLDB_LOGF(log, "Loaded embedded type summary for '%s' from %s.",

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)'])

lldb/test/API/functionalities/data-formatter/embedded-summary/main.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,37 @@ struct Player {
55
int number;
66
};
77

8-
__attribute__((used, section("__DATA_CONST,__lldbsummaries"))) unsigned char
8+
__attribute__((aligned(1), used,
9+
section("__DATA_CONST,__lldbsummaries"))) unsigned char
910
_Player_type_summary[] = "\x01" // version
1011
"\x25" // record size
1112
"\x07" // type name size
1213
"Player\0" // type name
1314
"\x1c" // summary string size
1415
"${var.name} (${var.number})"; // summary string
1516

17+
struct Layer {
18+
char *name;
19+
int number;
20+
};
21+
22+
// Near copy of the record for `Player`, using a regex type name (`^Layer`).
23+
__attribute__((aligned(1), used,
24+
section("__DATA_CONST,__lldbsummaries"))) unsigned char
25+
_Layer_type_summary[] = "\x01" // version
26+
"\x25" // record size
27+
"\x07" // type name size
28+
"^Layer\0" // type name
29+
"\x1c" // summary string size
30+
"${var.name} (${var.number})"; // summary string
31+
1632
int main() {
1733
struct Player player;
1834
player.name = "Dirk";
1935
player.number = 41;
36+
struct Layer layer;
37+
layer.name = "crust";
38+
layer.number = 3;
2039
puts("break here");
2140
return 0;
2241
}

0 commit comments

Comments
 (0)