From f9e6be5cc1a2cfe5294d4d55336b23266fcfc26f Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Wed, 3 Nov 2021 14:55:28 -0700 Subject: [PATCH] [lldb] Update tagged pointer command output and test. - Use formatv to print the addresses. - Add check for 0x0 which is treated as an invalid address. - Use a an address that's less likely to be interpreted as a real tagged pointer. --- .../ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp | 23 +++++++++++----------- .../objc/tagged-pointer/TestTaggedPointerCmd.py | 6 ++++-- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp index b4c517e..2cc05f4 100644 --- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp +++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp @@ -976,17 +976,16 @@ protected: 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.AppendErrorWithFormat( - "could not convert '%s' to a valid address\n", arg_str); + result.AppendErrorWithFormatv( + "could not convert '{0}' to a valid address\n", arg_str); result.SetStatus(lldb::eReturnStatusFailed); return false; } auto descriptor_sp = tagged_ptr_vendor->GetClassDescriptor(arg_addr); if (!descriptor_sp) { - result.AppendErrorWithFormat( - "could not get class descriptor for 0x%" PRIx64 "\n", - (uint64_t)arg_addr); + result.AppendErrorWithFormatv( + "could not get class descriptor for {0:x}\n", arg_addr); result.SetStatus(lldb::eReturnStatusFailed); return false; } @@ -996,14 +995,16 @@ protected: 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, + result.GetOutputStream().Format( + "{0:x} is tagged\n" + "\tpayload = {1:x}\n" + "\tvalue = {2:x}\n" + "\tinfo bits = {3:x}\n" + "\tclass = {4}\n", + arg_addr, payload, value_bits, info_bits, descriptor_sp->GetClassName().AsCString("")); } else { - result.GetOutputStream().Printf("0x%" PRIx64 " is not tagged.\n", + result.GetOutputStream().Format("{0:x16} is not tagged\n", (uint64_t)arg_addr); } } diff --git a/lldb/test/API/lang/objc/tagged-pointer/TestTaggedPointerCmd.py b/lldb/test/API/lang/objc/tagged-pointer/TestTaggedPointerCmd.py index 0b9ebd8..fbe9de7 100644 --- a/lldb/test/API/lang/objc/tagged-pointer/TestTaggedPointerCmd.py +++ b/lldb/test/API/lang/objc/tagged-pointer/TestTaggedPointerCmd.py @@ -15,6 +15,8 @@ class TestTaggedPointerCommand(TestBase): 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 0x1", error=True, - patterns=["could not get class descriptor for 0x1"]) + 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"]) -- 2.7.4