[Lldb-commits] [lldb] r107559 - in /lldb/trunk: include/lldb/Expression/ClangExpression.h include/lldb/Expression/IRForTarget.h lldb.xcodeproj/project.pbxproj source/Commands/CommandObjectExpression.cpp source/Expression/ClangExpression.cpp source/Expression/IRForTarget.cpp source/Expression/IRToDWARF.cpp

Sean Callanan scallanan at apple.com
Fri Jul 2 18:35:46 PDT 2010


Author: spyffe
Date: Fri Jul  2 20:35:46 2010
New Revision: 107559

URL: http://llvm.org/viewvc/llvm-project?rev=107559&view=rev
Log:
Added the skeleton of an IR transformer that will
prepare IR for execution in the target.  Wired the
expression command to use this IR transformer when
conversion to DWARF fails, and wired conversion to
DWARF to always fail (well, we don't generate any
DWARF...)

Added:
    lldb/trunk/include/lldb/Expression/IRForTarget.h
    lldb/trunk/source/Expression/IRForTarget.cpp
Modified:
    lldb/trunk/include/lldb/Expression/ClangExpression.h
    lldb/trunk/lldb.xcodeproj/project.pbxproj
    lldb/trunk/source/Commands/CommandObjectExpression.cpp
    lldb/trunk/source/Expression/ClangExpression.cpp
    lldb/trunk/source/Expression/IRToDWARF.cpp

Modified: lldb/trunk/include/lldb/Expression/ClangExpression.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ClangExpression.h?rev=107559&r1=107558&r2=107559&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Expression/ClangExpression.h (original)
+++ lldb/trunk/include/lldb/Expression/ClangExpression.h Fri Jul  2 20:35:46 2010
@@ -62,9 +62,12 @@
     ConvertExpressionToDWARF (ClangExpressionVariableList &expr_local_variable_list, 
                               StreamString &dwarf_opcode_strm);
     
-    unsigned
+    bool
     ConvertIRToDWARF (ClangExpressionVariableList &excpr_local_variable_list,
                       StreamString &dwarf_opcode_strm);
+    
+    bool
+    PrepareIRForTarget (ClangExpressionVariableList &excpr_local_variable_list);
 
     bool
     JITFunction (const ExecutionContext &exc_context, const char *func_name);

Added: lldb/trunk/include/lldb/Expression/IRForTarget.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/IRForTarget.h?rev=107559&view=auto
==============================================================================
--- lldb/trunk/include/lldb/Expression/IRForTarget.h (added)
+++ lldb/trunk/include/lldb/Expression/IRForTarget.h Fri Jul  2 20:35:46 2010
@@ -0,0 +1,41 @@
+//===-- IRForTarget.h ---------------------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef liblldb_IRForTarget_h_
+#define liblldb_IRForTarget_h_
+
+#include "llvm/Pass.h"
+#include "llvm/PassManager.h"
+
+namespace llvm {
+    class BasicBlock;
+    class Module;
+}
+
+namespace lldb_private {
+    class ClangExpressionDeclMap;
+}
+
+class IRForTarget : public llvm::ModulePass
+{
+public:
+    IRForTarget(const void *pid,
+                lldb_private::ClangExpressionDeclMap *decl_map);
+    ~IRForTarget();
+    bool runOnModule(llvm::Module &M);
+    void assignPassManager(llvm::PMStack &PMS,
+                           llvm::PassManagerType T = llvm::PMT_ModulePassManager);
+    llvm::PassManagerType getPotentialPassManagerType() const;
+private:
+    bool runOnBasicBlock(llvm::BasicBlock &BB);
+    
+    lldb_private::ClangExpressionDeclMap *m_decl_map;
+};
+
+#endif
\ No newline at end of file

Modified: lldb/trunk/lldb.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lldb.xcodeproj/project.pbxproj?rev=107559&r1=107558&r2=107559&view=diff
==============================================================================
--- lldb/trunk/lldb.xcodeproj/project.pbxproj (original)
+++ lldb/trunk/lldb.xcodeproj/project.pbxproj Fri Jul  2 20:35:46 2010
@@ -328,6 +328,8 @@
 		26F5C32D10F3DFDD009D5894 /* libtermcap.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 26F5C32B10F3DFDD009D5894 /* libtermcap.dylib */; };
 		26F5C37510F3F61B009D5894 /* libobjc.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 26F5C37410F3F61B009D5894 /* libobjc.dylib */; };
 		26F5C39110F3FA26009D5894 /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 26F5C39010F3FA26009D5894 /* CoreFoundation.framework */; };
+		49307AAE11DEA4D90081F992 /* IRForTarget.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 49307AAD11DEA4D90081F992 /* IRForTarget.cpp */; };
+		49307AB211DEA4F20081F992 /* IRForTarget.h in Headers */ = {isa = PBXBuildFile; fileRef = 49307AB111DEA4F20081F992 /* IRForTarget.h */; };
 		49A8A3A011D568A300AD3B68 /* ClangResultSynthesizer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 49A8A39F11D568A300AD3B68 /* ClangResultSynthesizer.cpp */; };
 		49A8A3A411D568BF00AD3B68 /* ClangResultSynthesizer.h in Headers */ = {isa = PBXBuildFile; fileRef = 49A8A3A311D568BF00AD3B68 /* ClangResultSynthesizer.h */; };
 		49D7072711B5AD03001AD875 /* ClangASTSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 49D7072611B5AD03001AD875 /* ClangASTSource.h */; };
@@ -890,6 +892,8 @@
 		26F996A8119B79C300412154 /* ARM_GCC_Registers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ARM_GCC_Registers.h; path = source/Utility/ARM_GCC_Registers.h; sourceTree = "<group>"; };
 		26FE25221146CADE00F4085A /* GDBRemoteCommunication.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = GDBRemoteCommunication.cpp; path = "source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp"; sourceTree = "<group>"; };
 		26FE25231146CADE00F4085A /* GDBRemoteCommunication.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GDBRemoteCommunication.h; path = "source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h"; sourceTree = "<group>"; };
+		49307AAD11DEA4D90081F992 /* IRForTarget.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = IRForTarget.cpp; path = source/Expression/IRForTarget.cpp; sourceTree = "<group>"; };
+		49307AB111DEA4F20081F992 /* IRForTarget.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = IRForTarget.h; path = include/lldb/Expression/IRForTarget.h; sourceTree = "<group>"; };
 		493C63F01189203300914D5E /* ABISysV_x86_64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ABISysV_x86_64.h; path = "ABI/SysV-x86_64/ABISysV_x86_64.h"; sourceTree = "<group>"; };
 		493C63F11189203300914D5E /* ABISysV_x86_64.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ABISysV_x86_64.cpp; path = "ABI/SysV-x86_64/ABISysV_x86_64.cpp"; sourceTree = "<group>"; };
 		495BBACB119A0DBE00418BEA /* PathMappingList.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = PathMappingList.cpp; path = source/Target/PathMappingList.cpp; sourceTree = "<group>"; };
@@ -1836,6 +1840,8 @@
 				26BC7ED710F1B86700F91463 /* ClangStmtVisitor.cpp */,
 				26BC7DC310F1B79500F91463 /* DWARFExpression.h */,
 				26BC7ED810F1B86700F91463 /* DWARFExpression.cpp */,
+				49307AB111DEA4F20081F992 /* IRForTarget.h */,
+				49307AAD11DEA4D90081F992 /* IRForTarget.cpp */,
 				49DA743411DE6BB2006AEF7E /* IRToDWARF.h */,
 				49DA742F11DE6A5A006AEF7E /* IRToDWARF.cpp */,
 				4C98D3E1118FB98F00E575D0 /* RecordingMemoryManager.h */,
@@ -2191,6 +2197,7 @@
 				4C08CDEC11C81F1E001610A8 /* ThreadSpec.h in Headers */,
 				49A8A3A411D568BF00AD3B68 /* ClangResultSynthesizer.h in Headers */,
 				49DA743511DE6BB2006AEF7E /* IRToDWARF.h in Headers */,
+				49307AB211DEA4F20081F992 /* IRForTarget.h in Headers */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -2641,6 +2648,7 @@
 				4C08CDE811C81EF8001610A8 /* ThreadSpec.cpp in Sources */,
 				49A8A3A011D568A300AD3B68 /* ClangResultSynthesizer.cpp in Sources */,
 				49DA743011DE6A5A006AEF7E /* IRToDWARF.cpp in Sources */,
+				49307AAE11DEA4D90081F992 /* IRForTarget.cpp in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

Modified: lldb/trunk/source/Commands/CommandObjectExpression.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectExpression.cpp?rev=107559&r1=107558&r2=107559&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectExpression.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectExpression.cpp Fri Jul  2 20:35:46 2010
@@ -252,11 +252,29 @@
     ClangExpressionVariableList expr_local_vars;
 
     bool success;
+    bool canInterpret = false;
     
     if (m_options.use_ir)
-        success = (clang_expr.ConvertIRToDWARF (expr_local_vars, dwarf_opcodes) == 0);
+    {
+        canInterpret = clang_expr.ConvertIRToDWARF (expr_local_vars, dwarf_opcodes);
+        
+        if (canInterpret)
+        {
+            if (log)
+                log->Printf("Code can be interpreted.");
+            success = true;
+        }
+        else
+        {
+            if (log)
+                log->Printf("Code cannot be interpreted and must be run in the target.");
+            success = clang_expr.PrepareIRForTarget (expr_local_vars);
+        }
+    }
     else
+    {
         success = (clang_expr.ConvertExpressionToDWARF (expr_local_vars, dwarf_opcodes) == 0);
+    }
     
     if (!success)
     {

Modified: lldb/trunk/source/Expression/ClangExpression.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangExpression.cpp?rev=107559&r1=107558&r2=107559&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangExpression.cpp (original)
+++ lldb/trunk/source/Expression/ClangExpression.cpp Fri Jul  2 20:35:46 2010
@@ -58,6 +58,7 @@
 #include "lldb/Expression/ClangASTSource.h"
 #include "lldb/Expression/ClangResultSynthesizer.h"
 #include "lldb/Expression/ClangStmtVisitor.h"
+#include "lldb/Expression/IRForTarget.h"
 #include "lldb/Expression/IRToDWARF.h"
 #include "lldb/Symbol/ClangASTContext.h"
 #include "lldb/Expression/RecordingMemoryManager.h"
@@ -474,7 +475,7 @@
     return 0;
 }
 
-unsigned
+bool
 ClangExpression::ConvertIRToDWARF (ClangExpressionVariableList &expr_local_variable_list,
                                    StreamString &dwarf_opcode_strm)
 {
@@ -496,6 +497,26 @@
 }
 
 bool
+ClangExpression::PrepareIRForTarget (ClangExpressionVariableList &expr_local_variable_list)
+{
+    Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS);
+    
+    llvm::Module *module = m_code_generator_ptr->GetModule();
+    
+    if (!module)
+    {
+        if (log)
+            log->Printf("IR doesn't contain a module");
+        
+        return 1;
+    }
+    
+    IRForTarget ir_for_target("IR for target", m_decl_map);
+    
+    return ir_for_target.runOnModule(*module);
+}
+
+bool
 ClangExpression::JITFunction (const ExecutionContext &exc_context, const char *name)
 {
 

Added: lldb/trunk/source/Expression/IRForTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/IRForTarget.cpp?rev=107559&view=auto
==============================================================================
--- lldb/trunk/source/Expression/IRForTarget.cpp (added)
+++ lldb/trunk/source/Expression/IRForTarget.cpp Fri Jul  2 20:35:46 2010
@@ -0,0 +1,109 @@
+//===-- IRForTarget.cpp -------------------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "lldb/Expression/IRForTarget.h"
+
+#include "llvm/Support/raw_ostream.h"
+#include "llvm/InstrTypes.h"
+#include "llvm/Module.h"
+
+#include "lldb/Core/dwarf.h"
+#include "lldb/Core/Log.h"
+#include "lldb/Core/Scalar.h"
+#include "lldb/Core/StreamString.h"
+#include "lldb/Expression/ClangExpressionDeclMap.h"
+
+#include <map>
+
+using namespace llvm;
+
+IRForTarget::IRForTarget(const void *pid,
+                         lldb_private::ClangExpressionDeclMap *decl_map) :
+    ModulePass(pid),
+    m_decl_map(decl_map)
+{
+}
+
+IRForTarget::~IRForTarget()
+{
+}
+
+bool
+IRForTarget::runOnBasicBlock(BasicBlock &BB)
+{
+    lldb_private::Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS);
+        
+    /////////////////////////////////////////////////////////////////////////
+    // Prepare the current basic block for execution in the remote process
+    //
+    
+    if (log)
+    {
+        log->Printf("Preparing basic block %s:",
+                    BB.hasName() ? BB.getNameStr().c_str() : "[anonymous]");
+        
+        llvm::BasicBlock::iterator ii;
+        
+        for (ii = BB.begin();
+             ii != BB.end();
+             ++ii)
+        {
+            llvm::Instruction &inst = *ii;
+            
+            std::string s;
+            raw_string_ostream os(s);
+            
+            inst.print(os);
+            
+            if (log)
+                log->Printf("  %s", s.c_str());
+        }
+    }
+    
+    return true;
+}
+
+bool
+IRForTarget::runOnModule(Module &M)
+{
+    lldb_private::Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS);
+    
+    llvm::Function* function = M.getFunction(StringRef("___clang_expr"));
+    
+    if (!function)
+    {
+        if (log)
+            log->Printf("Couldn't find ___clang_expr() in the module");
+        
+        return false;
+    }
+        
+    llvm::Function::iterator bbi;
+    
+    for (bbi = function->begin();
+         bbi != function->end();
+         ++bbi)
+    {
+        runOnBasicBlock(*bbi);
+    }
+    
+    return true;    
+}
+
+void
+IRForTarget::assignPassManager(PMStack &PMS,
+                             PassManagerType T)
+{
+}
+
+PassManagerType
+IRForTarget::getPotentialPassManagerType() const
+{
+    return PMT_ModulePassManager;
+}

Modified: lldb/trunk/source/Expression/IRToDWARF.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/IRToDWARF.cpp?rev=107559&r1=107558&r2=107559&view=diff
==============================================================================
--- lldb/trunk/source/Expression/IRToDWARF.cpp (original)
+++ lldb/trunk/source/Expression/IRToDWARF.cpp Fri Jul  2 20:35:46 2010
@@ -207,9 +207,11 @@
     
     Relocator relocator;
     
-    llvm::BasicBlock &currentBB = function->getEntryBlock();
+    if (!runOnBasicBlock(function->getEntryBlock(), relocator))
+        return false;
     
-    runOnBasicBlock(currentBB, relocator);
+    // TEMPORARY: Fail in order to force execution in the target.
+    return false;
     
     return relocator.ResolveRelocations(m_strm);    
 }





More information about the lldb-commits mailing list