[Lldb-commits] [lldb] r118388 - in /lldb/trunk: include/lldb/Expression/IRForTarget.h source/Expression/IRForTarget.cpp

Sean Callanan scallanan at apple.com
Sun Nov 7 16:31:32 PST 2010


Author: spyffe
Date: Sun Nov  7 18:31:32 2010
New Revision: 118388

URL: http://llvm.org/viewvc/llvm-project?rev=118388&view=rev
Log:
Made variable resolution more robust by handling
every external variable reference in the module,
and returning a clean error (instead of letting
LLVM issue a fatal error) if the variable could
not be resolved.

Modified:
    lldb/trunk/include/lldb/Expression/IRForTarget.h
    lldb/trunk/source/Expression/IRForTarget.cpp

Modified: lldb/trunk/include/lldb/Expression/IRForTarget.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/IRForTarget.h?rev=118388&r1=118387&r2=118388&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Expression/IRForTarget.h (original)
+++ lldb/trunk/include/lldb/Expression/IRForTarget.h Sun Nov  7 18:31:32 2010
@@ -193,11 +193,11 @@
                                  llvm::BasicBlock &BB);
     
     //------------------------------------------------------------------
-    /// A basic block-level pass to find all external variables and
-    /// functions used in the IR.  Each found external variable is added
-    /// to the struct, and each external function is resolved in place,
-    /// its call replaced with a call to a function pointer whose value
-    /// is the address of the function in the target process.
+    /// A function-level pass to find all external variables and functions 
+    /// used in the IR.  Each found external variable is added to the 
+    /// struct, and each external function is resolved in place, its call
+    /// replaced with a call to a function pointer whose value is the 
+    /// address of the function in the target process.
     //------------------------------------------------------------------
     
     //------------------------------------------------------------------
@@ -216,8 +216,7 @@
     ///     True on success; false otherwise
     //------------------------------------------------------------------
     bool MaybeHandleVariable(llvm::Module &M, 
-                             llvm::Value *V,
-                             bool Store);
+                             llvm::Value *V);
     
     //------------------------------------------------------------------
     /// Handle all the arguments to a function call
@@ -250,7 +249,7 @@
                          llvm::CallInst *C);
     
     //------------------------------------------------------------------
-    /// The top-level pass implementation
+    /// Resolve calls to external functions
     ///
     /// @param[in] M
     ///     The module currently being processed.
@@ -261,8 +260,23 @@
     /// @return
     ///     True on success; false otherwise
     //------------------------------------------------------------------
+    bool resolveCalls(llvm::Module &M,
+                      llvm::BasicBlock &BB);
+    
+    //------------------------------------------------------------------
+    /// The top-level pass implementation
+    ///
+    /// @param[in] M
+    ///     The module currently being processed.
+    ///
+    /// @param[in] BB
+    ///     The function currently being processed.
+    ///
+    /// @return
+    ///     True on success; false otherwise
+    //------------------------------------------------------------------
     bool resolveExternals(llvm::Module &M,
-                          llvm::BasicBlock &BB);
+                          llvm::Function &F);
     
     //------------------------------------------------------------------
     /// A basic block-level pass to excise guard variables from the code.

Modified: lldb/trunk/source/Expression/IRForTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/IRForTarget.cpp?rev=118388&r1=118387&r2=118388&view=diff
==============================================================================
--- lldb/trunk/source/Expression/IRForTarget.cpp (original)
+++ lldb/trunk/source/Expression/IRForTarget.cpp Sun Nov  7 18:31:32 2010
@@ -563,8 +563,7 @@
 IRForTarget::MaybeHandleVariable 
 (
     Module &llvm_module, 
-    Value *llvm_value_ptr,
-    bool Store
+    Value *llvm_value_ptr
 )
 {
     lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
@@ -578,7 +577,7 @@
         case Instruction::GetElementPtr:
         case Instruction::BitCast:
             Value *s = constant_expr->getOperand(0);
-            MaybeHandleVariable(llvm_module, s, Store);
+            MaybeHandleVariable(llvm_module, s);
         }
     }
     if (GlobalVariable *global_variable = dyn_cast<GlobalVariable>(llvm_value_ptr))
@@ -646,7 +645,7 @@
     for (unsigned op_index = 0, num_ops = C->getNumArgOperands();
          op_index < num_ops;
          ++op_index)
-        if (!MaybeHandleVariable(M, C->getArgOperand(op_index), true)) // conservatively believe that this is a store
+        if (!MaybeHandleVariable(M, C->getArgOperand(op_index))) // conservatively believe that this is a store
             return false;
     
     return true;
@@ -773,7 +772,7 @@
 }
 
 bool
-IRForTarget::resolveExternals(Module &M, BasicBlock &BB)
+IRForTarget::resolveCalls(Module &M, BasicBlock &BB)
 {        
     /////////////////////////////////////////////////////////////////////////
     // Prepare the current basic block for execution in the remote process
@@ -787,31 +786,31 @@
     {
         Instruction &inst = *ii;
         
-        if (m_resolve_vars)
-        {
-            if (LoadInst *load = dyn_cast<LoadInst>(&inst))
-                if (!MaybeHandleVariable(M, load->getPointerOperand(), false))
-                    return false;
-            
-            if (StoreInst *store = dyn_cast<StoreInst>(&inst))
-                if (!MaybeHandleVariable(M, store->getValueOperand(), true) ||
-                    !MaybeHandleVariable(M, store->getPointerOperand(), true))
-                    return false;
-        }
+        CallInst *call = dyn_cast<CallInst>(&inst);
         
-        if (CallInst *call = dyn_cast<CallInst>(&inst))
-        {
-            if (!MaybeHandleCallArguments(M, call))
-                return false;
-            
-            if (!MaybeHandleCall(M, call))
-                return false;
-        }
+        if (call && !MaybeHandleCall(M, call))
+            return false;
     }
     
     return true;
 }
 
+bool
+IRForTarget::resolveExternals(Module &M,
+                              Function &F)
+{
+    for (Module::global_iterator global = M.global_begin(), end = M.global_end();
+         global != end;
+         ++global)
+    {
+        if ((*global).hasExternalLinkage() &&
+            !MaybeHandleVariable (M, global))
+            return false;
+    }
+        
+    return true;
+}
+
 static bool isGuardVariableRef(Value *V)
 {
     Constant *C;
@@ -1156,7 +1155,7 @@
         if (!rewriteObjCSelectors(M, *bbi))
             return false;
 
-        if (!resolveExternals(M, *bbi))
+        if (!resolveCalls(M, *bbi))
             return false;
     }
     
@@ -1164,6 +1163,9 @@
     // Run function-level passes
     //
     
+    if (!resolveExternals(M, *function))
+        return false;
+    
     if (!replaceVariables(M, *function))
         return false;
     





More information about the lldb-commits mailing list