-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[lldb] Add summary for NSIndirectTaggedPointerString #136025
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
[lldb] Add summary for NSIndirectTaggedPointerString #136025
Conversation
@llvm/pr-subscribers-lldb Author: Dave Lee (kastiglione) ChangesFull diff: https://github.com/llvm/llvm-project/pull/136025.diff 3 Files Affected:
diff --git a/lldb/source/Plugins/Language/ObjC/NSString.cpp b/lldb/source/Plugins/Language/ObjC/NSString.cpp
index a99d042572bfe..11b4c6c5df8af 100644
--- a/lldb/source/Plugins/Language/ObjC/NSString.cpp
+++ b/lldb/source/Plugins/Language/ObjC/NSString.cpp
@@ -63,12 +63,17 @@ bool lldb_private::formatters::NSStringSummaryProvider(
if (class_name.empty())
return false;
- bool is_tagged_ptr = class_name == "NSTaggedPointerString" &&
- descriptor->GetTaggedPointerInfo();
- // for a tagged pointer, the descriptor has everything we need
- if (is_tagged_ptr)
- return NSTaggedString_SummaryProvider(valobj, descriptor, stream,
- summary_options);
+ // for tagged pointers, the descriptor has everything needed.
+ bool is_tagged = descriptor->GetTaggedPointerInfo();
+ if (is_tagged) {
+ if (class_name == "NSTaggedPointerString")
+ return NSTaggedString_SummaryProvider(valobj, descriptor, stream,
+ summary_options);
+
+ if (class_name == "NSIndirectTaggedPointerString")
+ return NSIndirectTaggedString_SummaryProvider(valobj, descriptor, stream,
+ summary_options);
+ }
auto &additionals_map(NSString_Additionals::GetAdditionalSummaries());
auto iter = additionals_map.find(class_name_cs), end = additionals_map.end();
@@ -368,3 +373,37 @@ bool lldb_private::formatters::NSTaggedString_SummaryProvider(
stream << suffix;
return true;
}
+
+bool lldb_private::formatters::NSIndirectTaggedString_SummaryProvider(
+ ValueObject &valobj, ObjCLanguageRuntime::ClassDescriptorSP descriptor,
+ Stream &stream, const TypeSummaryOptions &summary_options) {
+ if (!descriptor)
+ return false;
+
+ uint64_t payload = 0;
+ if (!descriptor->GetTaggedPointerInfo(nullptr, nullptr, &payload))
+ return false;
+
+ // First 47 bits are the address of the contents.
+ addr_t ptr = payload & 0x7fffffffffffULL;
+ // Next 13 bits are the string's length.
+ size_t size = (payload >> 47) & 0x1fff;
+
+ Status status;
+ char buf[8192];
+ if (auto process_sp = valobj.GetProcessSP())
+ if (process_sp->ReadMemory(ptr, buf, size, status)) {
+ llvm::StringRef prefix, suffix;
+ if (auto *language = Language::FindPlugin(summary_options.GetLanguage()))
+ std::tie(prefix, suffix) =
+ language->GetFormatterPrefixSuffix("NSString");
+ stream << prefix << '"';
+ stream.PutCString({buf, size});
+ stream << '"' << suffix;
+ return true;
+ }
+
+ if (status.Fail())
+ stream.Format("<{0}>", status);
+ return false;
+}
diff --git a/lldb/source/Plugins/Language/ObjC/NSString.h b/lldb/source/Plugins/Language/ObjC/NSString.h
index 8c9fcf955f1f8..5d405b30b6817 100644
--- a/lldb/source/Plugins/Language/ObjC/NSString.h
+++ b/lldb/source/Plugins/Language/ObjC/NSString.h
@@ -25,6 +25,10 @@ bool NSTaggedString_SummaryProvider(
ValueObject &valobj, ObjCLanguageRuntime::ClassDescriptorSP descriptor,
Stream &stream, const TypeSummaryOptions &summary_options);
+bool NSIndirectTaggedString_SummaryProvider(
+ ValueObject &valobj, ObjCLanguageRuntime::ClassDescriptorSP descriptor,
+ Stream &stream, const TypeSummaryOptions &summary_options);
+
bool NSAttributedStringSummaryProvider(ValueObject &valobj, Stream &stream,
const TypeSummaryOptions &options);
diff --git a/lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp b/lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp
index c835b439a64dd..3b8e21cbb9269 100644
--- a/lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp
+++ b/lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp
@@ -691,6 +691,10 @@ static void LoadObjCFormatters(TypeCategoryImplSP objc_category_sp) {
AddCXXSummary(
objc_category_sp, lldb_private::formatters::NSStringSummaryProvider,
"NSString summary provider", "NSTaggedPointerString", appkit_flags);
+ AddCXXSummary(objc_category_sp,
+ lldb_private::formatters::NSStringSummaryProvider,
+ "NSString summary provider", "NSIndirectTaggedPointerString",
+ appkit_flags);
AddCXXSummary(objc_category_sp,
lldb_private::formatters::NSAttributedStringSummaryProvider,
|
size_t size = (payload >> 47) & 0x1fff; | ||
|
||
Status status; | ||
char buf[8192]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given how deeply nested lldb stacks often are, I would probably use a std::vector here and allocate this on the heap.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and then you can reserve()
exactly size
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good call, done
LGTM with some nits |
std::tie(prefix, suffix) = | ||
language->GetFormatterPrefixSuffix("NSString"); | ||
stream << prefix << '"'; | ||
stream.PutCString({buf.data(), size}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does PutCString scan through the buffer until it finds a NUL
byte or does it copy size
bytes (which would be faster).
I doubt this affects the performance measurably. Just being curious.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or does it copy
size
bytes (which would be faster).
It does this, the faster option.
rdar://143164164 (cherry picked from commit 18855ec)
rdar://143164164