diff options
author | Sean Callanan <scallanan@apple.com> | 2010-11-04 01:51:38 +0000 |
---|---|---|
committer | Sean Callanan <scallanan@apple.com> | 2010-11-04 01:51:38 +0000 |
commit | 10af7c430a426ab649ac000152bc51c3601eb395 (patch) | |
tree | f1b9df6c5f74117250ad3d64a198bc7ab44faa69 /lldb | |
parent | 7108dad1308e3b7718bf048980f9944e4e3d1a58 (diff) | |
download | bcm5719-llvm-10af7c430a426ab649ac000152bc51c3601eb395.tar.gz bcm5719-llvm-10af7c430a426ab649ac000152bc51c3601eb395.zip |
Re-enabled LLDB's pointer checkers, and moved the
implementation of the Objective-C object checkers
into the Objective-C language runtime.
llvm-svn: 118226
Diffstat (limited to 'lldb')
-rw-r--r-- | lldb/include/lldb/Target/ObjCLanguageRuntime.h | 5 | ||||
-rw-r--r-- | lldb/include/lldb/Target/ThreadPlanCallFunction.h | 3 | ||||
-rw-r--r-- | lldb/source/Expression/ClangExpressionParser.cpp | 3 | ||||
-rw-r--r-- | lldb/source/Expression/IRDynamicChecks.cpp | 86 | ||||
-rw-r--r-- | lldb/source/Target/ObjCLanguageRuntime.cpp | 19 | ||||
-rw-r--r-- | lldb/source/Target/ThreadPlanCallFunction.cpp | 16 |
6 files changed, 67 insertions, 65 deletions
diff --git a/lldb/include/lldb/Target/ObjCLanguageRuntime.h b/lldb/include/lldb/Target/ObjCLanguageRuntime.h index 81da4a6defe..76ba4056e32 100644 --- a/lldb/include/lldb/Target/ObjCLanguageRuntime.h +++ b/lldb/include/lldb/Target/ObjCLanguageRuntime.h @@ -21,6 +21,8 @@ #include "lldb/Target/LanguageRuntime.h" namespace lldb_private { + +class ClangUtilityFunction; class ObjCLanguageRuntime : public LanguageRuntime @@ -53,6 +55,9 @@ public: void AddToMethodCache (lldb::addr_t class_addr, lldb::addr_t sel, lldb::addr_t impl_addr); + ClangUtilityFunction * + CreateObjectChecker (const char *); + protected: //------------------------------------------------------------------ // Classes that inherit from ObjCLanguageRuntime can see and modify these diff --git a/lldb/include/lldb/Target/ThreadPlanCallFunction.h b/lldb/include/lldb/Target/ThreadPlanCallFunction.h index e22d9944591..f0e8f2c8df4 100644 --- a/lldb/include/lldb/Target/ThreadPlanCallFunction.h +++ b/lldb/include/lldb/Target/ThreadPlanCallFunction.h @@ -78,6 +78,9 @@ public: protected: private: void + DoTakedown (); + + void SetBreakpoints (); void diff --git a/lldb/source/Expression/ClangExpressionParser.cpp b/lldb/source/Expression/ClangExpressionParser.cpp index 97d54a89e0f..016a637fdee 100644 --- a/lldb/source/Expression/ClangExpressionParser.cpp +++ b/lldb/source/Expression/ClangExpressionParser.cpp @@ -454,8 +454,6 @@ ClangExpressionParser::MakeJIT (lldb::addr_t &func_addr, if (m_expr.NeedsValidation() && exe_ctx.process->GetDynamicCheckers()) { - /* - Disabled temporarily - TODO Centralize and re-enable this inside Process to avoid race conditions IRDynamicChecks ir_dynamic_checks(*exe_ctx.process->GetDynamicCheckers(), function_name.c_str()); if (!ir_dynamic_checks.runOnModule(*module)) @@ -464,7 +462,6 @@ ClangExpressionParser::MakeJIT (lldb::addr_t &func_addr, err.SetErrorString("Couldn't add dynamic checks to the expression"); return err; } - */ } } diff --git a/lldb/source/Expression/IRDynamicChecks.cpp b/lldb/source/Expression/IRDynamicChecks.cpp index ca2f8d0af57..f68be96541d 100644 --- a/lldb/source/Expression/IRDynamicChecks.cpp +++ b/lldb/source/Expression/IRDynamicChecks.cpp @@ -13,6 +13,8 @@ #include "lldb/Core/Log.h" #include "lldb/Expression/ClangUtilityFunction.h" #include "lldb/Target/ExecutionContext.h" +#include "lldb/Target/ObjCLanguageRuntime.h" +#include "lldb/Target/Process.h" #include "lldb/Target/StackFrame.h" #include "llvm/Support/raw_ostream.h" @@ -36,52 +38,6 @@ static const char g_valid_pointer_check_text[] = " unsigned char $__lldb_local_val = *$__lldb_arg_ptr;\n" "}"; -static bool FunctionExists(const SymbolContext &sym_ctx, const char *name) -{ - ConstString name_cs(name); - - SymbolContextList sym_ctxs; - - sym_ctx.FindFunctionsByName(name_cs, false, sym_ctxs); - - return (sym_ctxs.GetSize() != 0); -} - -static const char *objc_object_check_text(ExecutionContext &exe_ctx) -{ - std::string ret; - - if (!exe_ctx.frame) - return "extern \"C\" void $__lldb_objc_object_check (unsigned char *obj) { }"; - - const SymbolContext &sym_ctx(exe_ctx.frame->GetSymbolContext(lldb::eSymbolContextEverything)); - - if (FunctionExists(sym_ctx, "gdb_object_getClass")) - { - return "extern \"C\" void " - "$__lldb_objc_object_check(uint8_t *$__lldb_arg_obj)" - "{" - "" - "}"; - } - else if (FunctionExists(sym_ctx, "gdb_class_getClass")) - { - return "extern \"C\" void " - "$__lldb_objc_object_check(uint8_t *$__lldb_arg_obj)" - "{" - "" - "}"; - } - else - { - return "extern \"C\" void " - "$__lldb_objc_object_check(uint8_t *$__lldb_arg_obj)" - "{" - "" - "}"; - } -} - DynamicCheckerFunctions::DynamicCheckerFunctions () { } @@ -96,9 +52,21 @@ DynamicCheckerFunctions::Install(Stream &error_stream, { m_valid_pointer_check.reset(new ClangUtilityFunction(g_valid_pointer_check_text, VALID_POINTER_CHECK_NAME)); - if (!m_valid_pointer_check->Install(error_stream, exe_ctx)) return false; + + if (exe_ctx.process) + { + ObjCLanguageRuntime *objc_language_runtime = exe_ctx.process->GetObjCLanguageRuntime(); + + if (objc_language_runtime) + { + m_objc_object_check.reset(objc_language_runtime->CreateObjectChecker(VALID_OBJC_OBJECT_CHECK_NAME)); + + if (!m_objc_object_check->Install(error_stream, exe_ctx)) + return false; + } + } return true; } @@ -290,10 +258,7 @@ protected: const IntegerType *intptr_ty = llvm::Type::getIntNTy(m_module.getContext(), (m_module.getPointerSize() == llvm::Module::Pointer64) ? 64 : 32); - if (!m_i8ptr_ty) - m_i8ptr_ty = llvm::Type::getInt8PtrTy(m_module.getContext()); - - params.push_back(m_i8ptr_ty); + params.push_back(GetI8PtrTy()); FunctionType *fun_ty = FunctionType::get(llvm::Type::getVoidTy(m_module.getContext()), params, true); PointerType *fun_ptr_ty = PointerType::getUnqual(fun_ty); @@ -301,13 +266,21 @@ protected: return ConstantExpr::getIntToPtr(fun_addr_int, fun_ptr_ty); } + const PointerType *GetI8PtrTy() + { + if (!m_i8ptr_ty) + m_i8ptr_ty = llvm::Type::getInt8PtrTy(m_module.getContext()); + + return m_i8ptr_ty; + } + typedef std::vector <llvm::Instruction *> InstVector; typedef InstVector::iterator InstIterator; InstVector m_to_instrument; ///< List of instructions the inspector found llvm::Module &m_module; ///< The module which is being instrumented DynamicCheckerFunctions &m_checker_functions; ///< The dynamic checker functions for the process - +private: const PointerType *m_i8ptr_ty; }; @@ -344,7 +317,7 @@ private: // Insert an instruction to cast the loaded value to int8_t* BitCastInst *bit_cast = new BitCastInst(dereferenced_ptr, - m_i8ptr_ty, + GetI8PtrTy(), "", inst); @@ -389,7 +362,7 @@ private: CallInst *call_inst = dyn_cast<CallInst>(inst); if (!call_inst) - return false; // this really should be true, because otherwise InspectInstruction wouldn't have registered it + 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()); @@ -403,7 +376,7 @@ private: // Insert an instruction to cast the receiver id to int8_t* BitCastInst *bit_cast = new BitCastInst(target_object, - m_i8ptr_ty, + GetI8PtrTy(), "", inst); @@ -470,7 +443,6 @@ private: } llvm::Value *m_objc_object_check_func; - const PointerType *m_i8ptr_ty; }; IRDynamicChecks::IRDynamicChecks(DynamicCheckerFunctions &checker_functions, @@ -508,7 +480,6 @@ IRDynamicChecks::runOnModule(llvm::Module &M) if (!vpc.Instrument()) return false; - /* ObjcObjectChecker ooc(M, m_checker_functions); if (!ooc.Inspect(*function)) @@ -516,7 +487,6 @@ IRDynamicChecks::runOnModule(llvm::Module &M) if (!ooc.Instrument()) return false; - */ if (log) { diff --git a/lldb/source/Target/ObjCLanguageRuntime.cpp b/lldb/source/Target/ObjCLanguageRuntime.cpp index 7f4de245116..46587a8cc68 100644 --- a/lldb/source/Target/ObjCLanguageRuntime.cpp +++ b/lldb/source/Target/ObjCLanguageRuntime.cpp @@ -11,6 +11,7 @@ #include "lldb/Core/Log.h" #include "lldb/Core/PluginManager.h" #include "lldb/Core/ValueObject.h" +#include "lldb/Expression/ClangUtilityFunction.h" #include "lldb/Symbol/ClangASTContext.h" #include "lldb/Target/ObjCLanguageRuntime.h" @@ -51,3 +52,21 @@ ObjCLanguageRuntime::LookupInMethodCache (lldb::addr_t class_addr, lldb::addr_t return LLDB_INVALID_ADDRESS; } +ClangUtilityFunction * +ObjCLanguageRuntime::CreateObjectChecker(const char *name) +{ + char buf[256]; + + assert(snprintf(&buf[0], sizeof(buf), + "extern \"C\" int gdb_object_getClass(void *);" + "extern \"C\" void " + "%s(void *$__lldb_arg_obj)" + "{" + " void **isa_ptr = (void **)$__lldb_arg_obj;" + " if (!isa_ptr || !gdb_class_getClass(*isa_ptr))" + " abort();" + "}", + name) < sizeof(buf)); + + return new ClangUtilityFunction(buf, name); +} diff --git a/lldb/source/Target/ThreadPlanCallFunction.cpp b/lldb/source/Target/ThreadPlanCallFunction.cpp index 65349ddaeb7..85de672a63d 100644 --- a/lldb/source/Target/ThreadPlanCallFunction.cpp +++ b/lldb/source/Target/ThreadPlanCallFunction.cpp @@ -150,6 +150,17 @@ ThreadPlanCallFunction::ThreadPlanCallFunction (Thread &thread, ThreadPlanCallFunction::~ThreadPlanCallFunction () { + if (m_valid && !IsPlanComplete()) + DoTakedown(); +} + +void +ThreadPlanCallFunction::DoTakedown () +{ + m_thread.RestoreSaveFrameZero(m_register_backup); + m_thread.ClearStackFrames(); + SetPlanComplete(); + ClearBreakpoints(); } void @@ -253,11 +264,8 @@ ThreadPlanCallFunction::ShouldStop (Event *event_ptr) } } - m_thread.RestoreSaveFrameZero(m_register_backup); - m_thread.ClearStackFrames(); - SetPlanComplete(); + DoTakedown(); - ClearBreakpoints(); return true; } else |