[Lldb-commits] [lldb] r179443 - Now that ValueObjects permit writing, made the

Sean Callanan scallanan at apple.com
Fri Apr 12 19:06:42 PDT 2013


Author: spyffe
Date: Fri Apr 12 21:06:42 2013
New Revision: 179443

URL: http://llvm.org/viewvc/llvm-project?rev=179443&view=rev
Log:
Now that ValueObjects permit writing, made the
Materializer use that API when dematerializing
variables.

Modified:
    lldb/trunk/include/lldb/Expression/IRMemoryMap.h
    lldb/trunk/source/Expression/IRMemoryMap.cpp
    lldb/trunk/source/Expression/Materializer.cpp

Modified: lldb/trunk/include/lldb/Expression/IRMemoryMap.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/IRMemoryMap.h?rev=179443&r1=179442&r2=179443&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Expression/IRMemoryMap.h (original)
+++ lldb/trunk/include/lldb/Expression/IRMemoryMap.h Fri Apr 12 21:06:42 2013
@@ -59,6 +59,8 @@ public:
     void ReadMemory (uint8_t *bytes, lldb::addr_t process_address, size_t size, Error &error);
     void ReadScalarFromMemory (Scalar &scalar, lldb::addr_t process_address, size_t size, Error &error);
     
+    void GetMemoryData (DataExtractor &extractor, lldb::addr_t process_address, size_t size, Error &error);
+    
     lldb::ByteOrder GetByteOrder();
     uint32_t GetAddressByteSize();
     

Modified: lldb/trunk/source/Expression/IRMemoryMap.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/IRMemoryMap.cpp?rev=179443&r1=179442&r2=179443&view=diff
==============================================================================
--- lldb/trunk/source/Expression/IRMemoryMap.cpp (original)
+++ lldb/trunk/source/Expression/IRMemoryMap.cpp Fri Apr 12 21:06:42 2013
@@ -535,8 +535,56 @@ IRMemoryMap::ReadScalarFromMemory (Scala
     else
     {
         error.SetErrorToGenericError();
-        error.SetErrorString ("Couldn't write scalar: its size was zero");
+        error.SetErrorString ("Couldn't read scalar: its size was zero");
     }
     return;
 }
 
+void
+IRMemoryMap::GetMemoryData (DataExtractor &extractor, lldb::addr_t process_address, size_t size, Error &error)
+{
+    if (size > 0)
+    {
+        AllocationMap::iterator iter = FindAllocation(process_address, size);
+        
+        if (iter == m_allocations.end())
+        {
+            error.SetErrorToGenericError();
+            error.SetErrorStringWithFormat("Couldn't find an allocation containing [0x%llx..0x%llx)", (unsigned long long)process_address, (unsigned long long)(process_address + size));
+            return;
+        }
+        
+        Allocation &allocation = iter->second;
+        
+        switch (allocation.m_policy)
+        {
+        default:
+            error.SetErrorToGenericError();
+            error.SetErrorString("Couldn't get memory data: invalid allocation policy");
+            return;
+        case eAllocationPolicyProcessOnly:
+            error.SetErrorToGenericError();
+            error.SetErrorString("Couldn't get memory data: memory is only in the target");
+            return;
+        case eAllocationPolicyHostOnly:
+        case eAllocationPolicyMirror:
+            if (!allocation.m_data.get())
+            {
+                error.SetErrorToGenericError();
+                error.SetErrorString("Couldn't get memory data: data buffer is empty");
+                return;
+            }
+            uint64_t offset = process_address - allocation.m_process_start;
+            extractor = DataExtractor(allocation.m_data->GetBytes() + offset, size, GetByteOrder(), GetAddressByteSize());
+            return;
+        }
+    }
+    else
+    {
+        error.SetErrorToGenericError();
+        error.SetErrorString ("Couldn't get memory data: its size was zero");
+        return;
+    }
+}
+
+

Modified: lldb/trunk/source/Expression/Materializer.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/Materializer.cpp?rev=179443&r1=179442&r2=179443&view=diff
==============================================================================
--- lldb/trunk/source/Expression/Materializer.cpp (original)
+++ lldb/trunk/source/Expression/Materializer.cpp Fri Apr 12 21:06:42 2013
@@ -467,7 +467,29 @@ public:
                 return;
             }
             
-            // TODO Write to the ValueObject
+            lldb_private::DataExtractor data;
+            
+            Error extract_error;
+            
+            map.GetMemoryData(data, m_temporary_allocation, valobj_sp->GetByteSize(), extract_error);
+            
+            if (!extract_error.Success())
+            {
+                err.SetErrorToGenericError();
+                err.SetErrorStringWithFormat("Couldn't get the data for variable %s", m_variable_sp->GetName().AsCString());
+                return;
+            }
+            
+            Error set_error;
+            
+            valobj_sp->SetData(data, set_error);
+            
+            if (!set_error.Success())
+            {
+                err.SetErrorToGenericError();
+                err.SetErrorStringWithFormat("Couldn't write the new contents of %s back into the variable", m_variable_sp->GetName().AsCString());
+                return;
+            }
             
             Error free_error;
             





More information about the lldb-commits mailing list