Skip to content

Commit 50b40b0

Browse files
committed
[lldb] Improve error reporting in lang objc tagged-pointer info
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 error: could not get class descriptor for 0xbb6404c47a587764 (lldb) lang objc tagged-pointer info n1 error: could not convert 'n1' to a valid address Differential revision: https://reviews.llvm.org/D112945
1 parent e515d3a commit 50b40b0

File tree

4 files changed

+84
-39
lines changed

4 files changed

+84
-39
lines changed

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

Lines changed: 54 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -951,50 +951,65 @@ class CommandObjectMultiwordObjC_TaggedPointer_Info
951951

952952
Process *process = m_exe_ctx.GetProcessPtr();
953953
ExecutionContext exe_ctx(process);
954+
954955
ObjCLanguageRuntime *objc_runtime = ObjCLanguageRuntime::Get(*process);
955-
if (objc_runtime) {
956-
ObjCLanguageRuntime::TaggedPointerVendor *tagged_ptr_vendor =
957-
objc_runtime->GetTaggedPointerVendor();
958-
if (tagged_ptr_vendor) {
959-
for (size_t i = 0; i < command.GetArgumentCount(); i++) {
960-
const char *arg_str = command.GetArgumentAtIndex(i);
961-
if (!arg_str)
962-
continue;
963-
Status error;
964-
lldb::addr_t arg_addr = OptionArgParser::ToAddress(
965-
&exe_ctx, arg_str, LLDB_INVALID_ADDRESS, &error);
966-
if (arg_addr == 0 || arg_addr == LLDB_INVALID_ADDRESS || error.Fail())
967-
continue;
968-
auto descriptor_sp = tagged_ptr_vendor->GetClassDescriptor(arg_addr);
969-
if (!descriptor_sp)
970-
continue;
971-
uint64_t info_bits = 0;
972-
uint64_t value_bits = 0;
973-
uint64_t payload = 0;
974-
if (descriptor_sp->GetTaggedPointerInfo(&info_bits, &value_bits,
975-
&payload)) {
976-
result.GetOutputStream().Printf(
977-
"0x%" PRIx64 " is tagged.\n\tpayload = 0x%" PRIx64
978-
"\n\tvalue = 0x%" PRIx64 "\n\tinfo bits = 0x%" PRIx64
979-
"\n\tclass = %s\n",
980-
(uint64_t)arg_addr, payload, value_bits, info_bits,
981-
descriptor_sp->GetClassName().AsCString("<unknown>"));
982-
} else {
983-
result.GetOutputStream().Printf("0x%" PRIx64 " is not tagged.\n",
984-
(uint64_t)arg_addr);
985-
}
986-
}
987-
} else {
988-
result.AppendError("current process has no tagged pointer support");
956+
if (!objc_runtime) {
957+
result.AppendError("current process has no Objective-C runtime loaded");
958+
result.SetStatus(lldb::eReturnStatusFailed);
959+
return false;
960+
}
961+
962+
ObjCLanguageRuntime::TaggedPointerVendor *tagged_ptr_vendor =
963+
objc_runtime->GetTaggedPointerVendor();
964+
if (!tagged_ptr_vendor) {
965+
result.AppendError("current process has no tagged pointer support");
966+
result.SetStatus(lldb::eReturnStatusFailed);
967+
return false;
968+
}
969+
970+
for (size_t i = 0; i < command.GetArgumentCount(); i++) {
971+
const char *arg_str = command.GetArgumentAtIndex(i);
972+
if (!arg_str)
973+
continue;
974+
975+
Status error;
976+
lldb::addr_t arg_addr = OptionArgParser::ToAddress(
977+
&exe_ctx, arg_str, LLDB_INVALID_ADDRESS, &error);
978+
if (arg_addr == 0 || arg_addr == LLDB_INVALID_ADDRESS || error.Fail()) {
979+
result.AppendErrorWithFormat(
980+
"could not convert '%s' to a valid address\n", arg_str);
989981
result.SetStatus(lldb::eReturnStatusFailed);
990982
return false;
991983
}
992-
result.SetStatus(lldb::eReturnStatusSuccessFinishResult);
993-
return true;
984+
985+
auto descriptor_sp = tagged_ptr_vendor->GetClassDescriptor(arg_addr);
986+
if (!descriptor_sp) {
987+
result.AppendErrorWithFormat(
988+
"could not get class descriptor for 0x%" PRIx64 "\n",
989+
(uint64_t)arg_addr);
990+
result.SetStatus(lldb::eReturnStatusFailed);
991+
return false;
992+
}
993+
994+
uint64_t info_bits = 0;
995+
uint64_t value_bits = 0;
996+
uint64_t payload = 0;
997+
if (descriptor_sp->GetTaggedPointerInfo(&info_bits, &value_bits,
998+
&payload)) {
999+
result.GetOutputStream().Printf(
1000+
"0x%" PRIx64 " is tagged.\n\tpayload = 0x%" PRIx64
1001+
"\n\tvalue = 0x%" PRIx64 "\n\tinfo bits = 0x%" PRIx64
1002+
"\n\tclass = %s\n",
1003+
(uint64_t)arg_addr, payload, value_bits, info_bits,
1004+
descriptor_sp->GetClassName().AsCString("<unknown>"));
1005+
} else {
1006+
result.GetOutputStream().Printf("0x%" PRIx64 " is not tagged.\n",
1007+
(uint64_t)arg_addr);
1008+
}
9941009
}
995-
result.AppendError("current process has no Objective-C runtime loaded");
996-
result.SetStatus(lldb::eReturnStatusFailed);
997-
return false;
1010+
1011+
result.SetStatus(lldb::eReturnStatusSuccessFinishResult);
1012+
return true;
9981013
}
9991014
};
10001015

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
OBJC_SOURCES := main.m
2+
LD_EXTRAS := -lobjc -framework Foundation
3+
4+
include Makefile.rules
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import lldb
2+
from lldbsuite.test.decorators import *
3+
from lldbsuite.test.lldbtest import *
4+
from lldbsuite.test import lldbutil
5+
6+
7+
class TestTaggedPointerCommand(TestBase):
8+
9+
mydir = TestBase.compute_mydir(__file__)
10+
11+
def test(self):
12+
self.build()
13+
lldbutil.run_to_source_breakpoint(self,"// break here", lldb.SBFileSpec("main.m"))
14+
15+
self.expect("lang objc tagged-pointer info bogus", error=True,
16+
patterns=["could not convert 'bogus' to a valid address"])
17+
18+
self.expect("lang objc tagged-pointer info 0x1", error=True,
19+
patterns=["could not get class descriptor for 0x1"])
20+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#import <Foundation/Foundation.h>
2+
int main() {
3+
id n1 = [NSNumber numberWithInt:1];
4+
printf("%x", n1); // break here
5+
return 0;
6+
}

0 commit comments

Comments
 (0)