Skip to content

🍒/FBI/50b40b051890+f9e6be5cc1a2+10eb32f45d40+d09a21a0b378 #3573

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
Original file line number Diff line number Diff line change
Expand Up @@ -958,50 +958,70 @@ class CommandObjectMultiwordObjC_TaggedPointer_Info

Process *process = m_exe_ctx.GetProcessPtr();
ExecutionContext exe_ctx(process);

ObjCLanguageRuntime *objc_runtime = ObjCLanguageRuntime::Get(*process);
if (objc_runtime) {
ObjCLanguageRuntime::TaggedPointerVendor *tagged_ptr_vendor =
objc_runtime->GetTaggedPointerVendor();
if (tagged_ptr_vendor) {
for (size_t i = 0; i < command.GetArgumentCount(); i++) {
const char *arg_str = command.GetArgumentAtIndex(i);
if (!arg_str)
continue;
Status error;
lldb::addr_t arg_addr = OptionArgParser::ToAddress(
&exe_ctx, arg_str, LLDB_INVALID_ADDRESS, &error);
if (arg_addr == 0 || arg_addr == LLDB_INVALID_ADDRESS || error.Fail())
continue;
auto descriptor_sp = tagged_ptr_vendor->GetClassDescriptor(arg_addr);
if (!descriptor_sp)
continue;
uint64_t info_bits = 0;
uint64_t value_bits = 0;
uint64_t payload = 0;
if (descriptor_sp->GetTaggedPointerInfo(&info_bits, &value_bits,
&payload)) {
result.GetOutputStream().Printf(
"0x%" PRIx64 " is tagged.\n\tpayload = 0x%" PRIx64
"\n\tvalue = 0x%" PRIx64 "\n\tinfo bits = 0x%" PRIx64
"\n\tclass = %s\n",
(uint64_t)arg_addr, payload, value_bits, info_bits,
descriptor_sp->GetClassName().AsCString("<unknown>"));
} else {
result.GetOutputStream().Printf("0x%" PRIx64 " is not tagged.\n",
(uint64_t)arg_addr);
}
}
} else {
result.AppendError("current process has no tagged pointer support");
if (!objc_runtime) {
result.AppendError("current process has no Objective-C runtime loaded");
result.SetStatus(lldb::eReturnStatusFailed);
return false;
}

ObjCLanguageRuntime::TaggedPointerVendor *tagged_ptr_vendor =
objc_runtime->GetTaggedPointerVendor();
if (!tagged_ptr_vendor) {
result.AppendError("current process has no tagged pointer support");
result.SetStatus(lldb::eReturnStatusFailed);
return false;
}

for (size_t i = 0; i < command.GetArgumentCount(); i++) {
const char *arg_str = command.GetArgumentAtIndex(i);
if (!arg_str)
continue;

Status error;
lldb::addr_t arg_addr = OptionArgParser::ToAddress(
&exe_ctx, arg_str, LLDB_INVALID_ADDRESS, &error);
if (arg_addr == 0 || arg_addr == LLDB_INVALID_ADDRESS || error.Fail()) {
result.AppendErrorWithFormatv(
"could not convert '{0}' to a valid address\n", arg_str);
result.SetStatus(lldb::eReturnStatusFailed);
return false;
}
result.SetStatus(lldb::eReturnStatusSuccessFinishResult);
return true;

if (!tagged_ptr_vendor->IsPossibleTaggedPointer(arg_addr)) {
result.GetOutputStream().Format("{0:x16} is not tagged\n", arg_addr);
continue;
}

auto descriptor_sp = tagged_ptr_vendor->GetClassDescriptor(arg_addr);
if (!descriptor_sp) {
result.AppendErrorWithFormatv(
"could not get class descriptor for {0:x16}\n", arg_addr);
result.SetStatus(lldb::eReturnStatusFailed);
return false;
}

uint64_t info_bits = 0;
uint64_t value_bits = 0;
uint64_t payload = 0;
if (descriptor_sp->GetTaggedPointerInfo(&info_bits, &value_bits,
&payload)) {
result.GetOutputStream().Format(
"{0:x} is tagged\n"
"\tpayload = {1:x16}\n"
"\tvalue = {2:x16}\n"
"\tinfo bits = {3:x16}\n"
"\tclass = {4}\n",
arg_addr, payload, value_bits, info_bits,
descriptor_sp->GetClassName().AsCString("<unknown>"));
} else {
result.GetOutputStream().Format("{0:x16} is not tagged\n", arg_addr);
}
}
result.AppendError("current process has no Objective-C runtime loaded");
result.SetStatus(lldb::eReturnStatusFailed);
return false;

result.SetStatus(lldb::eReturnStatusSuccessFinishResult);
return true;
}
};

Expand Down
4 changes: 4 additions & 0 deletions lldb/test/API/lang/objc/tagged-pointer/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
OBJC_SOURCES := main.m
LD_EXTRAS := -lobjc -framework Foundation

include Makefile.rules
20 changes: 20 additions & 0 deletions lldb/test/API/lang/objc/tagged-pointer/TestTaggedPointerCmd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil


class TestTaggedPointerCommand(TestBase):

mydir = TestBase.compute_mydir(__file__)

@no_debug_info_test
def test(self):
self.build()
lldbutil.run_to_source_breakpoint(self,"// break here", lldb.SBFileSpec("main.m"))

self.expect("lang objc tagged-pointer info bogus", error=True,
patterns=["could not convert 'bogus' to a valid address"])

self.expect("lang objc tagged-pointer info 0x0", error=True,
patterns=["could not convert '0x0' to a valid address"])
6 changes: 6 additions & 0 deletions lldb/test/API/lang/objc/tagged-pointer/main.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#import <Foundation/Foundation.h>
int main() {
id n1 = [NSNumber numberWithInt:1];
printf("%x\n", n1); // break here
return 0;
}