Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Cherry-pick into next] [lldb] Add a data formatter for Foundation._SwiftURL #10660

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
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
44 changes: 42 additions & 2 deletions lldb/source/Plugins/Language/Swift/FoundationValueTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,53 @@ bool lldb_private::formatters::swift::URL_SummaryProvider(
return false;

std::string summary;
if (!underlying_url_sp->GetSummaryAsCString(summary, options))
auto try_format = [&]() {
if (underlying_url_sp->GetSummaryAsCString(summary, options))
return true;
auto dynval_sp =
underlying_url_sp->GetDynamicValue(lldb::eDynamicCanRunTarget);
if (!dynval_sp)
return false;
return dynval_sp->GetSummaryAsCString(summary, options);
};
if (!try_format())
return false;

stream.PutCString(summary.c_str());
return true;
}

bool lldb_private::formatters::swift::SwiftURL_SummaryProvider(
ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
static ConstString g__baseURL("_baseURL");
static ConstString g__parseInfo("_parseInfo");
static ConstString g_urlString("urlString");

ValueObjectSP rel_str_sp(
valobj.GetChildAtNamePath({g__parseInfo, g_urlString}));
if (!rel_str_sp)
return false;

std::string base;
ValueObjectSP base_url_sp(valobj.GetChildAtNamePath({g__baseURL}));
if (base_url_sp)
if (ValueObjectSP non_synth_valobj = base_url_sp->GetNonSyntheticValue()) {
const char *value = non_synth_valobj->GetValueAsCString();
if (value && llvm::StringRef(value) != "none")
if (!base_url_sp->GetSummaryAsCString(base, options))
return false;
}

std::string summary;
if (!rel_str_sp->GetSummaryAsCString(summary, options))
return false;

// This format matches the implementastion of _SwiftURL.description.
stream << summary;
if (!base.empty())
stream << " -- " << base;
return true;
}

bool lldb_private::formatters::swift::IndexPath_SummaryProvider(
ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
static ConstString g__indexes("_indexes");
Expand Down
3 changes: 3 additions & 0 deletions lldb/source/Plugins/Language/Swift/FoundationValueTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ bool NotificationName_SummaryProvider(ValueObject &valobj, Stream &stream,
bool URL_SummaryProvider(ValueObject &valobj, Stream &stream,
const TypeSummaryOptions &options);

bool SwiftURL_SummaryProvider(ValueObject &valobj, Stream &stream,
const TypeSummaryOptions &options);

bool IndexPath_SummaryProvider(ValueObject &valobj, Stream &stream,
const TypeSummaryOptions &options);

Expand Down
6 changes: 6 additions & 0 deletions lldb/source/Plugins/Language/Swift/SwiftLanguage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,12 @@ LoadFoundationValueTypesFormatters(lldb::TypeCategoryImplSP swift_category_sp) {
"URL summary provider", ConstString("Foundation.URL"),
TypeSummaryImpl::Flags(summary_flags).SetDontShowChildren(true));

lldb_private::formatters::AddCXXSummary(
swift_category_sp,
lldb_private::formatters::swift::SwiftURL_SummaryProvider,
"URL summary provider", ConstString("Foundation._SwiftURL"),
TypeSummaryImpl::Flags(summary_flags).SetDontShowChildren(true));

lldb_private::formatters::AddCXXSummary(
swift_category_sp,
lldb_private::formatters::swift::IndexPath_SummaryProvider,
Expand Down