Skip to content

Commit 7aefe77

Browse files
committed
[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. (cherry-picked from commit 81ae1b5)
1 parent 8af00d6 commit 7aefe77

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
@@ -1491,7 +1491,7 @@ static void LoadTypeSummariesForModule(ModuleSP module_sp) {
14911491
return;
14921492

14931493
Log *log = GetLog(LLDBLog::DataFormatters);
1494-
const char *module_name = module_sp->GetObjectName().GetCString();
1494+
const char *module_name = module_sp->GetFileSpec().GetFilename().GetCString();
14951495

14961496
TypeCategoryImplSP category;
14971497
DataVisualization::Categories::GetCategory(ConstString("default"), category);
@@ -1527,7 +1527,7 @@ static void LoadTypeSummariesForModule(ModuleSP module_sp) {
15271527
auto summary_sp =
15281528
std::make_shared<StringSummaryFormat>(flags, summary_string.data());
15291529
FormatterMatchType match_type = eFormatterMatchExact;
1530-
if (summary_string.front() == '^' && summary_string.back() == '$')
1530+
if (type_name.front() == '^')
15311531
match_type = eFormatterMatchRegex;
15321532
category->AddTypeSummary(type_name, match_type, summary_sp);
15331533
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)