JDevlieghere created this revision. JDevlieghere added a reviewer: aprantl. JDevlieghere requested review of this revision.
Improve error handling for the `lang objc tagged-pointer info`. Rather than failing silently, report an error if we couldn't convert an argument to an address or resolve the class descriptor. (lldb) lang objc tagged-pointer info 0xbb6404c47a587764 could not get class descriptor for 0xbb6404c47a587764 (lldb) lang objc tagged-pointer info n1 could not convert 'n1' to a valid address https://reviews.llvm.org/D112945 Files: lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
Index: lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp =================================================================== --- lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp +++ lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp @@ -951,50 +951,70 @@ 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); - } - } + 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; + } + + bool success = 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.GetErrorStream().Printf( + "could not convert '%s' to a valid address\n", arg_str); + continue; + } + + auto descriptor_sp = tagged_ptr_vendor->GetClassDescriptor(arg_addr); + if (!descriptor_sp) { + result.GetErrorStream().Printf( + "could not get class descriptor for 0x%" PRIx64 "\n", + (uint64_t)arg_addr); + 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.AppendError("current process has no tagged pointer support"); - result.SetStatus(lldb::eReturnStatusFailed); - return false; + result.GetOutputStream().Printf("0x%" PRIx64 " is not tagged.\n", + (uint64_t)arg_addr); } - result.SetStatus(lldb::eReturnStatusSuccessFinishResult); - return true; + success = true; } - result.AppendError("current process has no Objective-C runtime loaded"); - result.SetStatus(lldb::eReturnStatusFailed); - return false; + + if (!success) { + result.SetStatus(lldb::eReturnStatusFailed); + return false; + } + + result.SetStatus(lldb::eReturnStatusSuccessFinishResult); + return true; } };
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits