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

Sean Callanan scallanan at apple.com
Mon Jul 26 19:07:53 PDT 2010


Author: spyffe
Date: Mon Jul 26 21:07:53 2010
New Revision: 109483

URL: http://llvm.org/viewvc/llvm-project?rev=109483&view=rev
Log:
Added support for locating a function that is
referenced in the IR.  We don't yet support updating
the call to that function.

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

Modified: lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h?rev=109483&r1=109482&r2=109483&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h (original)
+++ lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h Mon Jul 26 21:07:53 2010
@@ -88,6 +88,8 @@
                            off_t &offset,
                            uint32_t index);
     
+    uint64_t GetFunctionAddress (const clang::NamedDecl *decl);
+    
     // Interface for DwarfExpression
     Value *GetValueForIndex (uint32_t index);
     

Modified: lldb/trunk/include/lldb/Expression/IRForTarget.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/IRForTarget.h?rev=109483&r1=109482&r2=109483&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Expression/IRForTarget.h (original)
+++ lldb/trunk/include/lldb/Expression/IRForTarget.h Mon Jul 26 21:07:53 2010
@@ -14,6 +14,7 @@
 
 namespace llvm {
     class BasicBlock;
+    class CallInst;
     class Function;
     class Module;
     class TargetData;
@@ -37,15 +38,18 @@
     llvm::PassManagerType getPotentialPassManagerType() const;
 private:
     bool MaybeHandleVariable(llvm::Module &M, 
-                             lldb_private::ClangExpressionDeclMap *DM,
                              llvm::Value *V,
                              bool Store);
+    bool MaybeHandleCall(llvm::Module &M,
+                         llvm::CallInst *C);
     bool runOnBasicBlock(llvm::Module &M,
                          llvm::BasicBlock &BB);
     bool removeGuards(llvm::Module &M,
                       llvm::BasicBlock &BB);
     bool replaceVariables(llvm::Module &M,
                           llvm::Function *F);
+    bool replaceFunctions(llvm::Module &M,
+                          llvm::Function *F);
     
     lldb_private::ClangExpressionDeclMap *m_decl_map;
     const llvm::TargetData *m_target_data;

Modified: lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp?rev=109483&r1=109482&r2=109483&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp (original)
+++ lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp Mon Jul 26 21:07:53 2010
@@ -182,6 +182,24 @@
     return true;
 }
 
+uint64_t
+ClangExpressionDeclMap::GetFunctionAddress (const clang::NamedDecl *decl)
+{
+    TupleIterator iter;
+    
+    for (iter = m_tuples.begin();
+         iter != m_tuples.end();
+         ++iter)
+    {
+        if (decl == iter->m_decl)
+        {
+            return iter->m_value->GetScalar().ULongLong();
+        }
+    }
+    
+    return 0;
+}
+
 // Interface for DwarfExpression
 lldb_private::Value 
 *ClangExpressionDeclMap::GetValueForIndex (uint32_t index)

Modified: lldb/trunk/source/Expression/IRForTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/IRForTarget.cpp?rev=109483&r1=109482&r2=109483&view=diff
==============================================================================
--- lldb/trunk/source/Expression/IRForTarget.cpp (original)
+++ lldb/trunk/source/Expression/IRForTarget.cpp Mon Jul 26 21:07:53 2010
@@ -82,7 +82,6 @@
 
 bool 
 IRForTarget::MaybeHandleVariable(Module &M, 
-                                 lldb_private::ClangExpressionDeclMap *DM,
                                  llvm::Value *V,
                                  bool Store)
 {
@@ -110,13 +109,13 @@
         size_t value_size = m_target_data->getTypeStoreSize(value_type);
         off_t value_alignment = m_target_data->getPrefTypeAlignment(value_type);
         
-        if (named_decl && !DM->AddValueToStruct(V, 
-                                                named_decl,
-                                                name,
-                                                qual_type,
-                                                ast_context,
-                                                value_size, 
-                                                value_alignment))
+        if (named_decl && !m_decl_map->AddValueToStruct(V, 
+                                                        named_decl,
+                                                        name,
+                                                        qual_type,
+                                                        ast_context,
+                                                        value_size, 
+                                                        value_alignment))
             return false;
     }
     
@@ -124,6 +123,41 @@
 }
 
 bool
+IRForTarget::MaybeHandleCall(Module &M,
+                             CallInst *C)
+{
+    lldb_private::Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS);
+
+    llvm::Function *fun = C->getCalledFunction();
+    
+    if (fun == NULL)
+        return true;
+    
+    clang::NamedDecl *fun_decl = DeclForGlobalValue(M, fun);
+    
+    if (!fun_decl)
+    {
+        if (log)
+            log->Printf("Function %s wasn't in the metadata", fun->getName().str().c_str());
+        return false;
+    }
+    
+    uint64_t fun_addr = m_decl_map->GetFunctionAddress(fun_decl);
+    
+    if (fun_addr == 0)
+    {
+        if (log)
+            log->Printf("Function %s had no address", fun_decl->getNameAsCString());
+        return false;
+    }
+        
+    if (log)
+        log->Printf("Found %s at %llx", fun_decl->getNameAsCString(), fun_addr);
+    
+    return true;
+}
+
+bool
 IRForTarget::runOnBasicBlock(Module &M, BasicBlock &BB)
 {        
     /////////////////////////////////////////////////////////////////////////
@@ -139,11 +173,15 @@
         Instruction &inst = *ii;
         
         if (LoadInst *load = dyn_cast<LoadInst>(&inst))
-            if (!MaybeHandleVariable(M, m_decl_map, load->getPointerOperand(), false))
+            if (!MaybeHandleVariable(M, load->getPointerOperand(), false))
                 return false;
         
         if (StoreInst *store = dyn_cast<StoreInst>(&inst))
-            if (!MaybeHandleVariable(M, m_decl_map, store->getPointerOperand(), false))
+            if (!MaybeHandleVariable(M, store->getPointerOperand(), true))
+                return false;
+        
+        if (CallInst *call = dyn_cast<CallInst>(&inst))
+            if (!MaybeHandleCall(M, call))
                 return false;
     }
     





More information about the lldb-commits mailing list