Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
51 changes: 45 additions & 6 deletions lldb/source/Plugins/Language/ObjC/NSString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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];
Copy link
Collaborator

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.

Copy link
Collaborator

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good call, done

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;
}
4 changes: 4 additions & 0 deletions lldb/source/Plugins/Language/ObjC/NSString.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 4 additions & 0 deletions lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions lldb/test/API/lang/objc/foundation/tagged/strings/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
OBJC_SOURCES := main.m
LD_EXTRAS := -framework Foundation
include Makefile.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil


class TestCase(TestBase):
def test(self):
"""Verify summary formatter for tagged strings."""
self.build()
lldbutil.run_to_source_breakpoint(self, "break here", lldb.SBFileSpec("main.m"))
self.expect("v str1 str2", patterns=['@"nineDigit"', '@"tenDigitXX"'])
17 changes: 17 additions & 0 deletions lldb/test/API/lang/objc/foundation/tagged/strings/main.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#import <Foundation/Foundation.h>

@interface NSObject (Fake)
// 9 digit selector
- (void)nineDigit;
// 10 digit selector
- (void)tenDigitXX;
@end

int main() {
SEL sel1 = @selector(nineDigit);
NSString *str1 = NSStringFromSelector(sel1);
SEL sel2 = @selector(tenDigitXX);
NSString *str2 = NSStringFromSelector(sel2);
NSLog(@"break here %@, %@", str1, str2);
return 0;
}
Loading