[Lldb-commits] [lldb] r109568 - in /lldb/trunk: include/lldb/Expression/RecordingMemoryManager.h source/Expression/ClangExpression.cpp source/Expression/IRForTarget.cpp source/Expression/IRToDWARF.cpp source/Expression/RecordingMemoryManager.cpp

Sean Callanan scallanan at apple.com
Tue Jul 27 18:00:59 PDT 2010


Author: spyffe
Date: Tue Jul 27 20:00:59 2010
New Revision: 109568

URL: http://llvm.org/viewvc/llvm-project?rev=109568&view=rev
Log:
Added and improved logging.  This is helping us as we
diagnose a problem where we're not correctly emitting
PIC code.

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

Modified: lldb/trunk/include/lldb/Expression/RecordingMemoryManager.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/RecordingMemoryManager.h?rev=109568&r1=109567&r2=109568&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Expression/RecordingMemoryManager.h (original)
+++ lldb/trunk/include/lldb/Expression/RecordingMemoryManager.h Tue Jul 27 20:00:59 2010
@@ -21,6 +21,7 @@
 #include "lldb/lldb-forward.h"
 #include "lldb/lldb-private.h"
 #include "lldb/Core/ClangForward.h"
+#include "lldb/Core/Log.h"
 #include "llvm/ExecutionEngine/JITMemoryManager.h"
 #include "lldb/Expression/ClangExpression.h"
 
@@ -128,6 +129,8 @@
     std::map<uint8_t *, unsigned> m_stubs;
     std::map<uint8_t *, uintptr_t> m_globals;
     std::map<uint8_t *, uint8_t *> m_exception_tables;
+    
+    lldb_private::Log *m_log;
 
     struct LocalToRemoteAddressRange
     {

Modified: lldb/trunk/source/Expression/ClangExpression.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangExpression.cpp?rev=109568&r1=109567&r2=109568&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangExpression.cpp (original)
+++ lldb/trunk/source/Expression/ClangExpression.cpp Tue Jul 27 20:00:59 2010
@@ -527,6 +527,7 @@
 bool
 ClangExpression::JITFunction (const ExecutionContext &exc_context, const char *name)
 {
+    Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS);
 
     llvm::Module *module = m_code_generator_ptr->GetModule();
 
@@ -538,11 +539,41 @@
             m_jit_mm_ptr = new RecordingMemoryManager();
 
         //llvm::InitializeNativeTarget();
+                        
         if (m_execution_engine.get() == 0)
-            m_execution_engine.reset(llvm::ExecutionEngine::createJIT (module, &error, m_jit_mm_ptr));
+            m_execution_engine.reset(llvm::ExecutionEngine::createJIT (module, 
+                                                                       &error, 
+                                                                       m_jit_mm_ptr,
+                                                                       CodeGenOpt::Default,
+                                                                       true,
+                                                                       CodeModel::Default));
+        
         m_execution_engine->DisableLazyCompilation();
         llvm::Function *function = module->getFunction (llvm::StringRef (name));
-
+        
+        if (log)
+        {
+            const char *relocation_model_string;
+            
+            switch (llvm::TargetMachine::getRelocationModel())
+            {
+            case llvm::Reloc::Default:
+                relocation_model_string = "Default";
+                break;
+            case llvm::Reloc::Static:
+                relocation_model_string = "Static";
+                break;
+            case llvm::Reloc::PIC_:
+                relocation_model_string = "PIC_++";
+                break;
+            case llvm::Reloc::DynamicNoPIC:
+                relocation_model_string = "DynamicNoPIC";
+                break;
+            }
+            
+            log->Printf("Target machine's relocation model: %s", relocation_model_string);
+        }
+            
         // We don't actually need the function pointer here, this just forces it to get resolved.
         void *fun_ptr = m_execution_engine->getPointerToFunction(function);
         // Note, you probably won't get here on error, since the LLVM JIT tends to just
@@ -558,6 +589,8 @@
 bool
 ClangExpression::WriteJITCode (const ExecutionContext &exc_context)
 {
+    Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS);
+
     if (m_jit_mm_ptr == NULL)
         return false;
 
@@ -586,6 +619,9 @@
     lldb::addr_t cursor = target_addr;
     for (fun_pos = m_jit_mm_ptr->m_functions.begin(); fun_pos != fun_end; fun_pos++)
     {
+        if (log)
+            log->Printf("Reading [%p-%p] from m_functions", fun_pos->first, fun_pos->second);
+        
         lldb::addr_t lstart = (lldb::addr_t) (*fun_pos).first;
         lldb::addr_t lend = (lldb::addr_t) (*fun_pos).second;
         size_t size = lend - lstart;

Modified: lldb/trunk/source/Expression/IRForTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/IRForTarget.cpp?rev=109568&r1=109567&r2=109568&view=diff
==============================================================================
--- lldb/trunk/source/Expression/IRForTarget.cpp (original)
+++ lldb/trunk/source/Expression/IRForTarget.cpp Tue Jul 27 20:00:59 2010
@@ -511,20 +511,22 @@
             return false;
     }
     
+    // TEMPORARY FOR DEBUGGING
+    M.dump();
+    
     if (!replaceVariables(M, function))
         return false;
     
     if (log)
     {
-        for (bbi = function->begin();
-             bbi != function->end();
-             ++bbi)
-        {
-            log->Printf("Rewrote basic block %s for running: \n%s", 
-                        bbi->hasName() ? bbi->getNameStr().c_str() : "[anonymous]",
-                        PrintValue(bbi).c_str());
-        }
+        std::string s;
+        raw_string_ostream oss(s);
+        
+        M.print(oss, NULL);
+        
+        oss.flush();
         
+        log->Printf("Module after preparing for execution: \n%s", s.c_str());
     }
     
     return true;    

Modified: lldb/trunk/source/Expression/IRToDWARF.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/IRToDWARF.cpp?rev=109568&r1=109567&r2=109568&view=diff
==============================================================================
--- lldb/trunk/source/Expression/IRToDWARF.cpp (original)
+++ lldb/trunk/source/Expression/IRToDWARF.cpp Tue Jul 27 20:00:59 2010
@@ -119,9 +119,7 @@
 
 bool
 IRToDWARF::runOnBasicBlock(BasicBlock &BB, Relocator &R)
-{
-    lldb_private::Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS);
-    
+{    
     ///////////////////////////////////////
     // Mark the current block as visited
     //
@@ -139,29 +137,6 @@
     // Translate the current basic block to DWARF
     //
     
-    if (log)
-    {
-        log->Printf("Translating 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());
-        }
-    }
-    
     /////////////////////////////////////////////////
     // Visit all successors we haven't visited yet
     //
@@ -210,6 +185,18 @@
     if (!runOnBasicBlock(function->getEntryBlock(), relocator))
         return false;
     
+    if (log)
+    {
+        std::string s;
+        raw_string_ostream oss(s);
+        
+        M.print(oss, NULL);
+        
+        oss.flush();
+        
+        log->Printf("Module being translated to DWARF: \n%s", s.c_str());
+    }
+    
     // TEMPORARY: Fail in order to force execution in the target.
     return false;
     

Modified: lldb/trunk/source/Expression/RecordingMemoryManager.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/RecordingMemoryManager.cpp?rev=109568&r1=109567&r2=109568&view=diff
==============================================================================
--- lldb/trunk/source/Expression/RecordingMemoryManager.cpp (original)
+++ lldb/trunk/source/Expression/RecordingMemoryManager.cpp Tue Jul 27 20:00:59 2010
@@ -19,6 +19,7 @@
     llvm::JITMemoryManager(),
     m_default_mm_ap (llvm::JITMemoryManager::CreateDefaultMemManager())
 {
+    m_log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS);
 }
 
 RecordingMemoryManager::~RecordingMemoryManager ()
@@ -60,6 +61,9 @@
                uint8_t *FunctionEnd)
 {
     m_default_mm_ap->endFunctionBody(F, FunctionStart, FunctionEnd);
+    if (m_log)
+        m_log->Printf("Adding [%p-%p] to m_functions",
+                      FunctionStart, FunctionEnd);
     m_functions.insert(std::pair<uint8_t *, uint8_t *>(FunctionStart, FunctionEnd));
 }
 
@@ -67,6 +71,9 @@
 RecordingMemoryManager::allocateSpace(intptr_t Size, unsigned Alignment)
 {
     uint8_t *return_value = m_default_mm_ap->allocateSpace(Size, Alignment);
+    if (m_log)
+        m_log->Printf("RecordingMemoryManager::allocateSpace(Size=0x%llx, Alignment=%u) = %p",
+                      (uint64_t)Size, Alignment, return_value);
     m_spaceBlocks.insert (std::pair<uint8_t *, intptr_t>(return_value, Size));
     return return_value;
 }
@@ -75,6 +82,9 @@
 RecordingMemoryManager::allocateGlobal(uintptr_t Size, unsigned Alignment)
 {
     uint8_t *return_value = m_default_mm_ap->allocateGlobal(Size, Alignment);
+    if (m_log)
+        m_log->Printf("RecordingMemoryManager::allocateGlobal(Size=0x%llx, Alignment=%u) = %p",
+                      (uint64_t)Size, Alignment, return_value);
     m_globals.insert (std::pair<uint8_t *, uintptr_t>(return_value, Size));
     return return_value;
 }
@@ -144,6 +154,9 @@
 void
 RecordingMemoryManager::AddToLocalToRemoteMap (lldb::addr_t lstart, size_t size, lldb::addr_t rstart)
 {
+    if (m_log)
+        m_log->Printf("Adding local [0x%llx-0x%llx], remote [0x%llx-0x%llx] to local->remote map", lstart, lstart + size, rstart, rstart + size);
+    
     m_address_map.push_back (LocalToRemoteAddressRange(lstart, size, rstart));
 }
 





More information about the lldb-commits mailing list