Skip to content

[lldb] Fix embedded type summary regex handling #8121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lldb/source/Target/Target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1452,7 +1452,7 @@ static void LoadTypeSummariesForModule(ModuleSP module_sp) {
return;

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Micro-optimization: since this is only used in LLDB_LOGF, we can save the C string conversion by using LLDB_LOG instead and use a StringRef.


TypeCategoryImplSP category;
DataVisualization::Categories::GetCategory(ConstString("default"), category);
Expand Down Expand Up @@ -1488,7 +1488,7 @@ static void LoadTypeSummariesForModule(ModuleSP module_sp) {
auto summary_sp =
std::make_shared<StringSummaryFormat>(flags, summary_string.data());
FormatterMatchType match_type = eFormatterMatchExact;
if (summary_string.front() == '^' && summary_string.back() == '$')
if (type_name.front() == '^')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It just dawned on me that in Pascal, ^ is the equivalent of * in C and thus can be part of a type name. In the next revision we probably should include an isRegex bit in the header.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and AFAIK there are downstream Pascal compilers that target LLDB.

match_type = eFormatterMatchRegex;
category->AddTypeSummary(type_name, match_type, summary_sp);
LLDB_LOGF(log, "Loaded embedded type summary for '%s' from %s.",
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
Expand Up @@ -5,18 +5,37 @@ struct Player {
int number;
};

__attribute__((used, section("__DATA_CONST,__lldbsummaries"))) unsigned char
__attribute__((aligned(1), 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

struct Layer {
char *name;
int number;
};

// Near copy of the record for `Player`, using a regex type name (`^Layer`).
__attribute__((aligned(1), used,
section("__DATA_CONST,__lldbsummaries"))) 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;
}