Added an extra parameter to the object-checker

functions in the Objective-C language runtime
that is set to the selector that is being passed
to the object.

llvm-svn: 143083
This commit is contained in:
Sean Callanan 2011-10-27 00:02:05 +00:00
parent 3249a1e862
commit 7ba9636f0a
3 changed files with 53 additions and 25 deletions

View File

@ -275,6 +275,34 @@ protected:
return ConstantExpr::getIntToPtr(fun_addr_int, fun_ptr_ty);
}
//------------------------------------------------------------------
/// Build a function pointer for a function with signature
/// void (*)(uint8_t*, uint8_t*) with a given address
///
/// @param[in] start_address
/// The address of the function.
///
/// @return
/// The function pointer, for use in a CallInst.
//------------------------------------------------------------------
llvm::Value *BuildObjectCheckerFunc(lldb::addr_t start_address)
{
IntegerType *intptr_ty = llvm::Type::getIntNTy(m_module.getContext(),
(m_module.getPointerSize() == llvm::Module::Pointer64) ? 64 : 32);
llvm::Type *param_array[2];
param_array[0] = const_cast<llvm::PointerType*>(GetI8PtrTy());
param_array[1] = const_cast<llvm::PointerType*>(GetI8PtrTy());
ArrayRef<llvm::Type*> params(param_array, 2);
FunctionType *fun_ty = FunctionType::get(llvm::Type::getVoidTy(m_module.getContext()), params, true);
PointerType *fun_ptr_ty = PointerType::getUnqual(fun_ty);
Constant *fun_addr_int = ConstantInt::get(intptr_ty, start_address, false);
return ConstantExpr::getIntToPtr(fun_addr_int, fun_ptr_ty);
}
PointerType *GetI8PtrTy()
{
if (!m_i8ptr_ty)
@ -386,14 +414,13 @@ private:
return false; // call_inst really shouldn't be NULL, because otherwise InspectInstruction wouldn't have registered it
if (!m_objc_object_check_func)
m_objc_object_check_func = BuildPointerValidatorFunc(m_checker_functions.m_objc_object_check->StartAddress());
llvm::Value *target_object = NULL;
m_objc_object_check_func = BuildObjectCheckerFunc(m_checker_functions.m_objc_object_check->StartAddress());
// id objc_msgSend(id theReceiver, SEL theSelector, ...)
target_object = call_inst->getArgOperand(0);
llvm::Value *target_object = call_inst->getArgOperand(0);;
llvm::Value *selector = call_inst->getArgOperand(1);
// Insert an instruction to cast the receiver id to int8_t*
BitCastInst *bit_cast = new BitCastInst(target_object,
@ -403,9 +430,10 @@ private:
// Insert an instruction to call the helper with the result
llvm::Value *arg_array[1];
llvm::Value *arg_array[2];
arg_array[0] = bit_cast;
arg_array[1] = selector;
ArrayRef<llvm::Value*> args(arg_array, 1);

View File

@ -147,7 +147,7 @@ AppleObjCRuntimeV1::CreateObjectChecker(const char *name)
"}; \n"
" \n"
"extern \"C\" void \n"
"%s(void *$__lldb_arg_obj) \n"
"%s(void *$__lldb_arg_obj, void *$__lldb_arg_selector) \n"
"{ \n"
" struct __objc_object *obj = (struct __objc_object*)$__lldb_arg_obj; \n"
" (int)strlen(obj->isa->name); \n"

View File

@ -499,31 +499,31 @@ AppleObjCRuntimeV2::CreateObjectChecker(const char *name)
{
len = ::snprintf (check_function_code,
sizeof(check_function_code),
"extern \"C\" void *gdb_object_getClass(void *); \n"
"extern \"C\" void \n"
"%s(void *$__lldb_arg_obj) \n"
"{ \n"
" if ($__lldb_arg_obj == (void *)0) \n"
" return; // nil is ok \n"
" if (!gdb_object_getClass($__lldb_arg_obj)) \n"
" *((volatile int *)0) = 'ocgc'; \n"
"} \n",
"extern \"C\" void *gdb_object_getClass(void *); \n"
"extern \"C\" void \n"
"%s(void *$__lldb_arg_obj, void *$__lldb_arg_selector) \n"
"{ \n"
" if ($__lldb_arg_obj == (void *)0) \n"
" return; // nil is ok \n"
" if (!gdb_object_getClass($__lldb_arg_obj)) \n"
" *((volatile int *)0) = 'ocgc'; \n"
"} \n",
name);
}
else
{
len = ::snprintf (check_function_code,
sizeof(check_function_code),
"extern \"C\" void *gdb_class_getClass(void *); \n"
"extern \"C\" void \n"
"%s(void *$__lldb_arg_obj) \n"
"{ \n"
" if ($__lldb_arg_obj == (void *)0) \n"
" return; // nil is ok \n"
" void **$isa_ptr = (void **)$__lldb_arg_obj; \n"
"extern \"C\" void *gdb_class_getClass(void *); \n"
"extern \"C\" void \n"
"%s(void *$__lldb_arg_obj, void *$__lldb_arg_selector) \n"
"{ \n"
" if ($__lldb_arg_obj == (void *)0) \n"
" return; // nil is ok \n"
" void **$isa_ptr = (void **)$__lldb_arg_obj; \n"
" if (*$isa_ptr == (void *)0 || !gdb_class_getClass(*$isa_ptr)) \n"
" *((volatile int *)0) = 'ocgc'; \n"
"} \n",
" *((volatile int *)0) = 'ocgc'; \n"
"} \n",
name);
}