Skip to content

Commit 03844d1

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 (cherry picked from commit 50b40b0)
1 parent 27222cd commit 03844d1

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
@@ -958,50 +958,65 @@ class CommandObjectMultiwordObjC_TaggedPointer_Info
958958

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

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)