Skip to content

Commit 10eb32f

Browse files
committed
[lldb] Improve 'lang objc tagged-pointer info' command
Don't try to get a class descriptor for a pointer that doesn't look like a tagged pointer. Also print addresses as fixed-width hex and update the test.
1 parent c92a253 commit 10eb32f

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -982,10 +982,15 @@ class CommandObjectMultiwordObjC_TaggedPointer_Info
982982
return false;
983983
}
984984

985+
if (!tagged_ptr_vendor->IsPossibleTaggedPointer(arg_addr)) {
986+
result.GetOutputStream().Format("{0:x16} is not tagged\n", arg_addr);
987+
continue;
988+
}
989+
985990
auto descriptor_sp = tagged_ptr_vendor->GetClassDescriptor(arg_addr);
986991
if (!descriptor_sp) {
987992
result.AppendErrorWithFormatv(
988-
"could not get class descriptor for {0:x}\n", arg_addr);
993+
"could not get class descriptor for {0:x16}\n", arg_addr);
989994
result.SetStatus(lldb::eReturnStatusFailed);
990995
return false;
991996
}
@@ -997,15 +1002,14 @@ class CommandObjectMultiwordObjC_TaggedPointer_Info
9971002
&payload)) {
9981003
result.GetOutputStream().Format(
9991004
"{0:x} is tagged\n"
1000-
"\tpayload = {1:x}\n"
1001-
"\tvalue = {2:x}\n"
1002-
"\tinfo bits = {3:x}\n"
1005+
"\tpayload = {1:x16}\n"
1006+
"\tvalue = {2:x16}\n"
1007+
"\tinfo bits = {3:x16}\n"
10031008
"\tclass = {4}\n",
10041009
arg_addr, payload, value_bits, info_bits,
10051010
descriptor_sp->GetClassName().AsCString("<unknown>"));
10061011
} else {
1007-
result.GetOutputStream().Format("{0:x16} is not tagged\n",
1008-
(uint64_t)arg_addr);
1012+
result.GetOutputStream().Format("{0:x16} is not tagged\n", arg_addr);
10091013
}
10101014
}
10111015

lldb/test/API/lang/objc/tagged-pointer/TestTaggedPointerCmd.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class TestTaggedPointerCommand(TestBase):
88

99
mydir = TestBase.compute_mydir(__file__)
1010

11+
@no_debug_info_test
1112
def test(self):
1213
self.build()
1314
lldbutil.run_to_source_breakpoint(self,"// break here", lldb.SBFileSpec("main.m"))
@@ -18,5 +19,5 @@ def test(self):
1819
self.expect("lang objc tagged-pointer info 0x0", error=True,
1920
patterns=["could not convert '0x0' to a valid address"])
2021

21-
self.expect("lang objc tagged-pointer info 0xffffffff", error=True,
22-
patterns=["could not get class descriptor for 0xffffffff"])
22+
self.expect("lang objc tagged-pointer info 0x00000001",
23+
patterns=["0x0000000000000001 is not tagged"])
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#import <Foundation/Foundation.h>
22
int main() {
33
id n1 = [NSNumber numberWithInt:1];
4-
printf("%x", n1); // break here
4+
printf("%x\n", n1); // break here
55
return 0;
66
}

0 commit comments

Comments
 (0)