[Lldb-commits] [lldb] r177456 - Updated the IRExecutionUnit to keep local copies

Sean Callanan scallanan at apple.com
Tue Mar 19 16:03:21 PDT 2013


Author: spyffe
Date: Tue Mar 19 18:03:21 2013
New Revision: 177456

URL: http://llvm.org/viewvc/llvm-project?rev=177456&view=rev
Log:
Updated the IRExecutionUnit to keep local copies
of the data it writes down into the process even
if the process doesn't exist.  This will allow
the IR interpreter to access static data allocated
on the expression's behalf.

Also cleaned up object ownership in the
IRExecutionUnit so that allocations are created
into the allocations vector.  This avoids needless
data copies.

<rdar://problem/13424594>

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

Modified: lldb/trunk/include/lldb/Expression/IRExecutionUnit.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/IRExecutionUnit.h?rev=177456&r1=177455&r2=177456&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Expression/IRExecutionUnit.h (original)
+++ lldb/trunk/include/lldb/Expression/IRExecutionUnit.h Tue Mar 19 18:03:21 2013
@@ -22,6 +22,7 @@
 #include "lldb/lldb-forward.h"
 #include "lldb/lldb-private.h"
 #include "lldb/Core/ClangForward.h"
+#include "lldb/Core/DataBufferHeap.h"
 #include "llvm/ExecutionEngine/JITMemoryManager.h"
 #include "lldb/Expression/ClangExpression.h"
 #include "lldb/Expression/ClangExpressionParser.h"
@@ -424,13 +425,15 @@ private:
     {
         lldb::addr_t    m_remote_allocation;///< The (unaligned) base for the remote allocation
         lldb::addr_t    m_remote_start;     ///< The base address of the remote allocation
-        uintptr_t       m_local_start;      ///< The base address of the local allocation - LLDB_INVALID_ADDRESS means it was allocated with WriteNow
+        uintptr_t       m_local_start;      ///< The base address of the local allocation
         uintptr_t       m_size;             ///< The size of the allocation
         unsigned        m_section_id;       ///< The ID of the section
         unsigned        m_alignment;        ///< The required alignment for the allocation
         bool            m_executable;       ///< True <=> the allocation must be executable in the target
         bool            m_allocated;        ///< True <=> the allocation has been propagated to the target
 
+        std::unique_ptr<DataBufferHeap> m_data;   ///< If non-NULL, a local data buffer containing the written bytes.  Only populated by WriteNow.
+        
         static const unsigned eSectionIDNone = (unsigned)-1;
         
         //------------------------------------------------------------------

Modified: lldb/trunk/source/Expression/IRExecutionUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/IRExecutionUnit.cpp?rev=177456&r1=177455&r2=177456&view=diff
==============================================================================
--- lldb/trunk/source/Expression/IRExecutionUnit.cpp (original)
+++ lldb/trunk/source/Expression/IRExecutionUnit.cpp Tue Mar 19 18:03:21 2013
@@ -30,16 +30,12 @@ IRExecutionUnit::IRExecutionUnit (std::a
     m_process_wp(process_sp),
     m_module_ap(module_ap),
     m_module(m_module_ap.get()),
-    m_cpu_features(),
+    m_cpu_features(cpu_features),
     m_name(name),
     m_did_jit(false),
     m_function_load_addr(LLDB_INVALID_ADDRESS),
     m_function_end_load_addr(LLDB_INVALID_ADDRESS)
 {
-    for (std::string &feature : cpu_features)
-    {
-        m_cpu_features.push_back(std::string(feature.c_str()));
-    }
 }
 
 lldb::addr_t
@@ -49,10 +45,14 @@ IRExecutionUnit::WriteNow (const uint8_t
 {    
     lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
 
-    Allocation allocation;
+    auto iter = m_allocations.insert(m_allocations.end(), Allocation());
+    
+    Allocation &allocation(*iter);
+    
     allocation.m_size = size;
     allocation.m_alignment = 8;
-    allocation.m_local_start = LLDB_INVALID_ADDRESS;
+    allocation.m_data.reset(new DataBufferHeap(bytes, size));
+    allocation.m_local_start = (uintptr_t)allocation.m_data->GetBytes();
     allocation.m_section_id = Allocation::eSectionIDNone;
         
     lldb_private::Error err;
@@ -68,6 +68,7 @@ IRExecutionUnit::WriteNow (const uint8_t
     {
         err.SetErrorToGenericError();
         err.SetErrorString("Couldn't find the process");
+        return LLDB_INVALID_ADDRESS;
     }
     
     allocation.m_remote_allocation = process_sp->AllocateMemory(allocation_size,
@@ -97,9 +98,7 @@ IRExecutionUnit::WriteNow (const uint8_t
         log->Printf("IRExecutionUnit::WriteNow() wrote to 0x%llx", allocation.m_remote_start);
         allocation.dump(log);
     }
-    
-    m_allocations.push_back(allocation);
-    
+        
     return allocation.m_remote_start;
 }
 
@@ -466,7 +465,10 @@ IRExecutionUnit::MemoryManager::allocate
 
     uint8_t *return_value = m_default_mm_ap->allocateStub(F, StubSize, Alignment);
     
-    Allocation allocation;
+    auto iter = m_parent.m_allocations.insert(m_parent.m_allocations.end(), Allocation());
+    
+    Allocation &allocation(*iter);
+    
     allocation.m_size = StubSize;
     allocation.m_alignment = Alignment;
     allocation.m_local_start = (uintptr_t)return_value;
@@ -477,9 +479,7 @@ IRExecutionUnit::MemoryManager::allocate
                     F, StubSize, Alignment, return_value);
         allocation.dump(log);
     }
-    
-    m_parent.m_allocations.push_back(allocation);
-    
+        
     return return_value;
 }
 
@@ -498,7 +498,10 @@ IRExecutionUnit::MemoryManager::allocate
 
     uint8_t *return_value = m_default_mm_ap->allocateSpace(Size, Alignment);
     
-    Allocation allocation;
+    auto iter = m_parent.m_allocations.insert(m_parent.m_allocations.end(), Allocation());
+    
+    Allocation &allocation(*iter);
+    
     allocation.m_size = Size;
     allocation.m_alignment = Alignment;
     allocation.m_local_start = (uintptr_t)return_value;
@@ -509,9 +512,7 @@ IRExecutionUnit::MemoryManager::allocate
                                (uint64_t)Size, Alignment, return_value);
         allocation.dump(log);
     }
-    
-    m_parent.m_allocations.push_back(allocation);
-    
+        
     return return_value;
 }
 
@@ -524,7 +525,10 @@ IRExecutionUnit::MemoryManager::allocate
     
     uint8_t *return_value = m_default_mm_ap->allocateCodeSection(Size, Alignment, SectionID);
     
-    Allocation allocation;
+    auto iter = m_parent.m_allocations.insert(m_parent.m_allocations.end(), Allocation());
+    
+    Allocation &allocation(*iter);
+    
     allocation.m_size = Size;
     allocation.m_alignment = Alignment;
     allocation.m_local_start = (uintptr_t)return_value;
@@ -537,9 +541,7 @@ IRExecutionUnit::MemoryManager::allocate
                     (uint64_t)Size, Alignment, SectionID, return_value);
         allocation.dump(log);
     }
-    
-    m_parent.m_allocations.push_back(allocation);
-    
+        
     return return_value;
 }
 
@@ -553,7 +555,10 @@ IRExecutionUnit::MemoryManager::allocate
 
     uint8_t *return_value = m_default_mm_ap->allocateDataSection(Size, Alignment, SectionID, IsReadOnly);
     
-    Allocation allocation;
+    auto iter = m_parent.m_allocations.insert(m_parent.m_allocations.end(), Allocation());
+    
+    Allocation &allocation(*iter);
+
     allocation.m_size = Size;
     allocation.m_alignment = Alignment;
     allocation.m_local_start = (uintptr_t)return_value;
@@ -565,9 +570,7 @@ IRExecutionUnit::MemoryManager::allocate
                     (uint64_t)Size, Alignment, SectionID, return_value);
         allocation.dump(log);
     }
-    
-    m_parent.m_allocations.push_back(allocation);
-    
+        
     return return_value; 
 }
 
@@ -579,7 +582,10 @@ IRExecutionUnit::MemoryManager::allocate
 
     uint8_t *return_value = m_default_mm_ap->allocateGlobal(Size, Alignment);
     
-    Allocation allocation;
+    auto iter = m_parent.m_allocations.insert(m_parent.m_allocations.end(), Allocation());
+    
+    Allocation &allocation(*iter);
+    
     allocation.m_size = Size;
     allocation.m_alignment = Alignment;
     allocation.m_local_start = (uintptr_t)return_value;
@@ -591,8 +597,6 @@ IRExecutionUnit::MemoryManager::allocate
         allocation.dump(log);
     }
     
-    m_parent.m_allocations.push_back(allocation);
-
     return return_value;
 }
 
@@ -714,7 +718,7 @@ IRExecutionUnit::ReportAllocations (llvm
         if (!allocation.m_allocated)
             continue;
         
-        if (allocation.m_local_start == LLDB_INVALID_ADDRESS)
+        if (allocation.m_section_id == Allocation::eSectionIDNone)
             continue;
         
         engine.mapSectionAddress((void*)allocation.m_local_start, allocation.m_remote_start);





More information about the lldb-commits mailing list