Skip to content

Commit 3b80523

Browse files
authored
Merge pull request #956 from dcci/dirt-by-alice-in-chains
[AppleObjCRuntimeV2] Force lazily allocated class names to be resolved.
2 parents a964c34 + 70cfcc8 commit 3b80523

File tree

2 files changed

+59
-26
lines changed

2 files changed

+59
-26
lines changed

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

Lines changed: 57 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,6 +1176,28 @@ AppleObjCRuntimeV2::GetClassDescriptorFromISA(ObjCISA isa) {
11761176
return class_descriptor_sp;
11771177
}
11781178

1179+
static std::pair<bool, ConstString> ObjCGetClassNameRaw(
1180+
AppleObjCRuntime::ObjCISA isa,
1181+
Process *process) {
1182+
StreamString expr_string;
1183+
std::string input = std::to_string(isa);
1184+
expr_string.Printf("(const char *)objc_debug_class_getNameRaw(%s)",
1185+
input.c_str());
1186+
1187+
ValueObjectSP result_sp;
1188+
EvaluateExpressionOptions eval_options;
1189+
eval_options.SetLanguage(lldb::eLanguageTypeObjC);
1190+
eval_options.SetResultIsInternal(true);
1191+
eval_options.SetGenerateDebugInfo(true);
1192+
eval_options.SetTimeout(process->GetUtilityExpressionTimeout());
1193+
auto eval_result = process->GetTarget().EvaluateExpression(
1194+
expr_string.GetData(),
1195+
process->GetThreadList().GetSelectedThread()->GetSelectedFrame().get(),
1196+
result_sp, eval_options);
1197+
ConstString type_name(result_sp->GetSummaryAsCString());
1198+
return std::make_pair(eval_result == eExpressionCompleted, type_name);
1199+
}
1200+
11791201
ObjCLanguageRuntime::ClassDescriptorSP
11801202
AppleObjCRuntimeV2::GetClassDescriptor(ValueObject &valobj) {
11811203
ClassDescriptorSP objc_class_sp;
@@ -1192,32 +1214,43 @@ AppleObjCRuntimeV2::GetClassDescriptor(ValueObject &valobj) {
11921214
// if we get an invalid VO (which might still happen when playing around with
11931215
// pointers returned by the expression parser, don't consider this a valid
11941216
// ObjC object)
1195-
if (valobj.GetCompilerType().IsValid()) {
1196-
addr_t isa_pointer = valobj.GetPointerValue();
1217+
if (!valobj.GetCompilerType().IsValid())
1218+
return objc_class_sp;
1219+
addr_t isa_pointer = valobj.GetPointerValue();
11971220

1198-
// tagged pointer
1199-
if (IsTaggedPointer(isa_pointer)) {
1200-
return m_tagged_pointer_vendor_up->GetClassDescriptor(isa_pointer);
1201-
} else {
1202-
ExecutionContext exe_ctx(valobj.GetExecutionContextRef());
1221+
// tagged pointer
1222+
if (IsTaggedPointer(isa_pointer))
1223+
return m_tagged_pointer_vendor_up->GetClassDescriptor(isa_pointer);
1224+
ExecutionContext exe_ctx(valobj.GetExecutionContextRef());
12031225

1204-
Process *process = exe_ctx.GetProcessPtr();
1205-
if (process) {
1206-
Status error;
1207-
ObjCISA isa = process->ReadPointerFromMemory(isa_pointer, error);
1208-
if (isa != LLDB_INVALID_ADDRESS) {
1209-
objc_class_sp = GetClassDescriptorFromISA(isa);
1210-
if (isa && !objc_class_sp) {
1211-
Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
1212-
LLDB_LOGF(log,
1213-
"0x%" PRIx64
1214-
": AppleObjCRuntimeV2::GetClassDescriptor() ISA was "
1215-
"not in class descriptor cache 0x%" PRIx64,
1216-
isa_pointer, isa);
1217-
}
1218-
}
1219-
}
1220-
}
1226+
Process *process = exe_ctx.GetProcessPtr();
1227+
if (!process)
1228+
return objc_class_sp;
1229+
1230+
Status error;
1231+
ObjCISA isa = process->ReadPointerFromMemory(isa_pointer, error);
1232+
if (isa == LLDB_INVALID_ADDRESS)
1233+
return objc_class_sp;
1234+
1235+
objc_class_sp = GetClassDescriptorFromISA(isa);
1236+
1237+
if (objc_class_sp)
1238+
return objc_class_sp;
1239+
else {
1240+
Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS |
1241+
LIBLLDB_LOG_TYPES));
1242+
LLDB_LOGF(log,
1243+
"0x%" PRIx64
1244+
": AppleObjCRuntimeV2::GetClassDescriptor() ISA was "
1245+
"not in class descriptor cache 0x%" PRIx64,
1246+
isa_pointer, isa);
1247+
}
1248+
1249+
ClassDescriptorSP descriptor_sp(new ClassDescriptorV2(*this, isa, nullptr));
1250+
auto resolved = ObjCGetClassNameRaw(isa, process);
1251+
if (resolved.first == true) {
1252+
AddClass(isa, descriptor_sp, resolved.second.AsCString());
1253+
objc_class_sp = descriptor_sp;
12211254
}
12221255
return objc_class_sp;
12231256
}

lldb/test/Shell/ExecControl/StopHook/stop-hook.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ target stop-hook list
4646
run
4747
# Stopping inside of the stop hook range
4848
# CHECK: (lldb) run
49-
# CHECK-NEXT: (void *) $0 = 0x
49+
# CHECK-NEXT: (void *) ${{.*}} = 0x
5050

5151
thread step-over
5252
# Stepping inside of the stop hook range
5353
# CHECK: (lldb) thread step-over
54-
# CHECK-NEXT: (void *) $1 = 0x
54+
# CHECK-NEXT: (void *) ${{.*}} = 0x
5555
# CHECK: ->{{.*}} // We should stop here after stepping.
5656

5757
process continue

0 commit comments

Comments
 (0)