[Lldb-commits] [lldb] r118226 - in /lldb/trunk: include/lldb/Target/ObjCLanguageRuntime.h include/lldb/Target/ThreadPlanCallFunction.h source/Expression/ClangExpressionParser.cpp source/Expression/IRDynamicChecks.cpp source/Target/ObjCLanguageRuntime.cpp source/Target/ThreadPlanCallFunction.cpp

Sean Callanan scallanan at apple.com
Wed Nov 3 18:51:39 PDT 2010


Author: spyffe
Date: Wed Nov  3 20:51:38 2010
New Revision: 118226

URL: http://llvm.org/viewvc/llvm-project?rev=118226&view=rev
Log:
Re-enabled LLDB's pointer checkers, and moved the
implementation of the Objective-C object checkers
into the Objective-C language runtime.

Modified:
    lldb/trunk/include/lldb/Target/ObjCLanguageRuntime.h
    lldb/trunk/include/lldb/Target/ThreadPlanCallFunction.h
    lldb/trunk/source/Expression/ClangExpressionParser.cpp
    lldb/trunk/source/Expression/IRDynamicChecks.cpp
    lldb/trunk/source/Target/ObjCLanguageRuntime.cpp
    lldb/trunk/source/Target/ThreadPlanCallFunction.cpp

Modified: lldb/trunk/include/lldb/Target/ObjCLanguageRuntime.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/ObjCLanguageRuntime.h?rev=118226&r1=118225&r2=118226&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/ObjCLanguageRuntime.h (original)
+++ lldb/trunk/include/lldb/Target/ObjCLanguageRuntime.h Wed Nov  3 20:51:38 2010
@@ -21,6 +21,8 @@
 #include "lldb/Target/LanguageRuntime.h"
 
 namespace lldb_private {
+    
+class ClangUtilityFunction;
 
 class ObjCLanguageRuntime :
     public LanguageRuntime
@@ -53,6 +55,9 @@
     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

Modified: lldb/trunk/include/lldb/Target/ThreadPlanCallFunction.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/ThreadPlanCallFunction.h?rev=118226&r1=118225&r2=118226&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/ThreadPlanCallFunction.h (original)
+++ lldb/trunk/include/lldb/Target/ThreadPlanCallFunction.h Wed Nov  3 20:51:38 2010
@@ -78,6 +78,9 @@
 protected:
 private:
     void
+    DoTakedown ();
+    
+    void
     SetBreakpoints ();
     
     void

Modified: lldb/trunk/source/Expression/ClangExpressionParser.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangExpressionParser.cpp?rev=118226&r1=118225&r2=118226&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangExpressionParser.cpp (original)
+++ lldb/trunk/source/Expression/ClangExpressionParser.cpp Wed Nov  3 20:51:38 2010
@@ -454,8 +454,6 @@
         
         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 @@
                 err.SetErrorString("Couldn't add dynamic checks to the expression");
                 return err;
             }
-             */
         }
     }
     

Modified: lldb/trunk/source/Expression/IRDynamicChecks.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/IRDynamicChecks.cpp?rev=118226&r1=118225&r2=118226&view=diff
==============================================================================
--- lldb/trunk/source/Expression/IRDynamicChecks.cpp (original)
+++ lldb/trunk/source/Expression/IRDynamicChecks.cpp Wed Nov  3 20:51:38 2010
@@ -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 @@
 "    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 @@
 {
     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 @@
         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 @@
         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 @@
         // 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 @@
         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 @@
         // 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 @@
     }
     
     llvm::Value         *m_objc_object_check_func;
-    const PointerType   *m_i8ptr_ty;
 };
 
 IRDynamicChecks::IRDynamicChecks(DynamicCheckerFunctions &checker_functions,
@@ -508,7 +480,6 @@
     if (!vpc.Instrument())
         return false;
     
-    /*
     ObjcObjectChecker ooc(M, m_checker_functions);
     
     if (!ooc.Inspect(*function))
@@ -516,7 +487,6 @@
     
     if (!ooc.Instrument())
         return false;
-    */
     
     if (log)
     {

Modified: lldb/trunk/source/Target/ObjCLanguageRuntime.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/ObjCLanguageRuntime.cpp?rev=118226&r1=118225&r2=118226&view=diff
==============================================================================
--- lldb/trunk/source/Target/ObjCLanguageRuntime.cpp (original)
+++ lldb/trunk/source/Target/ObjCLanguageRuntime.cpp Wed Nov  3 20:51:38 2010
@@ -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 @@
     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);
+}

Modified: lldb/trunk/source/Target/ThreadPlanCallFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/ThreadPlanCallFunction.cpp?rev=118226&r1=118225&r2=118226&view=diff
==============================================================================
--- lldb/trunk/source/Target/ThreadPlanCallFunction.cpp (original)
+++ lldb/trunk/source/Target/ThreadPlanCallFunction.cpp Wed Nov  3 20:51:38 2010
@@ -150,6 +150,17 @@
 
 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 @@
             }
         }
         
-        m_thread.RestoreSaveFrameZero(m_register_backup);
-        m_thread.ClearStackFrames();
-        SetPlanComplete();
+        DoTakedown();
         
-        ClearBreakpoints();
         return true;
     }
     else





More information about the lldb-commits mailing list