[lldb] Improve 'lang objc tagged-pointer info' command
authorJonas Devlieghere <jonas@devlieghere.com>
Fri, 5 Nov 2021 20:13:41 +0000 (13:13 -0700)
committerJonas Devlieghere <jonas@devlieghere.com>
Fri, 5 Nov 2021 20:19:00 +0000 (13:19 -0700)
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.

lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
lldb/test/API/lang/objc/tagged-pointer/TestTaggedPointerCmd.py
lldb/test/API/lang/objc/tagged-pointer/main.m

index 2cc05f4..bd6b633 100644 (file)
@@ -982,10 +982,15 @@ protected:
         return false;
       }
 
+      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:x}\n", arg_addr);
+            "could not get class descriptor for {0:x16}\n", arg_addr);
         result.SetStatus(lldb::eReturnStatusFailed);
         return false;
       }
@@ -997,15 +1002,14 @@ protected:
                                               &payload)) {
         result.GetOutputStream().Format(
             "{0:x} is tagged\n"
-            "\tpayload = {1:x}\n"
-            "\tvalue = {2:x}\n"
-            "\tinfo bits = {3:x}\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",
-                                        (uint64_t)arg_addr);
+        result.GetOutputStream().Format("{0:x16} is not tagged\n", arg_addr);
       }
     }
 
index fbe9de7..4c70b53 100644 (file)
@@ -8,6 +8,7 @@ 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"))
@@ -18,5 +19,5 @@ class TestTaggedPointerCommand(TestBase):
         self.expect("lang objc tagged-pointer info 0x0", error=True,
                     patterns=["could not convert '0x0' to a valid address"])
 
-        self.expect("lang objc tagged-pointer info 0xffffffff", error=True,
-                    patterns=["could not get class descriptor for 0xffffffff"])
+        self.expect("lang objc tagged-pointer info 0x00000001",
+                    patterns=["0x0000000000000001 is not tagged"])
index 4d2ccf5..11a9781 100644 (file)
@@ -1,6 +1,6 @@
 #import <Foundation/Foundation.h>
 int main() {
   id n1 = [NSNumber numberWithInt:1];
-  printf("%x", n1); // break here
+  printf("%x\n", n1); // break here
   return 0;
 }