Restored initialization of the ContextFlags in the context.

http://reviews.llvm.org/D7572

Files:
  source/Plugins/Process/Windows/x86/RegisterContextWindows_x86.cpp
  source/Plugins/Process/Windows/x86/RegisterContextWindows_x86.h

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
Index: source/Plugins/Process/Windows/x86/RegisterContextWindows_x86.cpp
===================================================================
--- source/Plugins/Process/Windows/x86/RegisterContextWindows_x86.cpp
+++ source/Plugins/Process/Windows/x86/RegisterContextWindows_x86.cpp
@@ -20,7 +20,6 @@
 #include "TargetThreadWindows.h"
 
 #include "llvm/ADT/STLExtras.h"
-#include "llvm/Support/MathExtras.h"
 
 using namespace lldb;
 using namespace lldb_private;
@@ -95,7 +94,7 @@
 RegisterContextWindows_x86::RegisterContextWindows_x86(Thread &thread, uint32_t concrete_frame_idx)
     : RegisterContext(thread, concrete_frame_idx)
     , m_context_stale(true)
-    , m_context_ptr(nullptr)
+    , m_context()
 {
 }
 
@@ -142,34 +141,34 @@
     switch (reg_info->kinds[eRegisterKindLLDB])
     {
         case lldb_eax_i386:
-            reg_value.SetUInt32(m_context_ptr->Eax);
+            reg_value.SetUInt32(m_context.Eax);
             break;
         case lldb_ebx_i386:
-            reg_value.SetUInt32(m_context_ptr->Ebx);
+            reg_value.SetUInt32(m_context.Ebx);
             break;
         case lldb_ecx_i386:
-            reg_value.SetUInt32(m_context_ptr->Ecx);
+            reg_value.SetUInt32(m_context.Ecx);
             break;
         case lldb_edx_i386:
-            reg_value.SetUInt32(m_context_ptr->Edx);
+            reg_value.SetUInt32(m_context.Edx);
             break;
         case lldb_edi_i386:
-            reg_value.SetUInt32(m_context_ptr->Edi);
+            reg_value.SetUInt32(m_context.Edi);
             break;
         case lldb_esi_i386:
-            reg_value.SetUInt32(m_context_ptr->Esi);
+            reg_value.SetUInt32(m_context.Esi);
             break;
         case lldb_ebp_i386:
-            reg_value.SetUInt32(m_context_ptr->Ebp);
+            reg_value.SetUInt32(m_context.Ebp);
             break;
         case lldb_esp_i386:
-            reg_value.SetUInt32(m_context_ptr->Esp);
+            reg_value.SetUInt32(m_context.Esp);
             break;
         case lldb_eip_i386:
-            reg_value.SetUInt32(m_context_ptr->Eip);
+            reg_value.SetUInt32(m_context.Eip);
             break;
         case lldb_eflags_i386:
-            reg_value.SetUInt32(m_context_ptr->EFlags);
+            reg_value.SetUInt32(m_context.EFlags);
             break;
     }
     return true;
@@ -187,74 +186,63 @@
     switch (reg_info->kinds[eRegisterKindLLDB])
     {
         case lldb_eax_i386:
-            m_context_ptr->Eax = reg_value.GetAsUInt32();
+            m_context.Eax = reg_value.GetAsUInt32();
             break;
         case lldb_ebx_i386:
-            m_context_ptr->Ebx = reg_value.GetAsUInt32();
+            m_context.Ebx = reg_value.GetAsUInt32();
             break;
         case lldb_ecx_i386:
-            m_context_ptr->Ecx = reg_value.GetAsUInt32();
+            m_context.Ecx = reg_value.GetAsUInt32();
             break;
         case lldb_edx_i386:
-            m_context_ptr->Edx = reg_value.GetAsUInt32();
+            m_context.Edx = reg_value.GetAsUInt32();
             break;
         case lldb_edi_i386:
-            m_context_ptr->Edi = reg_value.GetAsUInt32();
+            m_context.Edi = reg_value.GetAsUInt32();
             break;
         case lldb_esi_i386:
-            m_context_ptr->Esi = reg_value.GetAsUInt32();
+            m_context.Esi = reg_value.GetAsUInt32();
             break;
         case lldb_ebp_i386:
-            m_context_ptr->Ebp = reg_value.GetAsUInt32();
+            m_context.Ebp = reg_value.GetAsUInt32();
             break;
         case lldb_esp_i386:
-            m_context_ptr->Esp = reg_value.GetAsUInt32();
+            m_context.Esp = reg_value.GetAsUInt32();
             break;
         case lldb_eip_i386:
-            m_context_ptr->Eip = reg_value.GetAsUInt32();
+            m_context.Eip = reg_value.GetAsUInt32();
             break;
         case lldb_eflags_i386:
-            m_context_ptr->EFlags = reg_value.GetAsUInt32();
+            m_context.EFlags = reg_value.GetAsUInt32();
             break;
     }
 
     // Physically update the registers in the target process.
     TargetThreadWindows &wthread = static_cast<TargetThreadWindows &>(m_thread);
-    return ::SetThreadContext(wthread.GetHostThread().GetNativeThread().GetSystemHandle(), m_context_ptr);
+    return ::SetThreadContext(wthread.GetHostThread().GetNativeThread().GetSystemHandle(), &m_context);
 }
 
 bool
 RegisterContextWindows_x86::ReadAllRegisterValues(lldb::DataBufferSP &data_sp)
 {
     if (!CacheAllRegisterValues())
         return false;
-
-    CONTEXT *dest_context = nullptr;
-    if (!InitializeContextDataBuffer(data_sp, &dest_context))
-        return false;
-
-    // In the future, we should use CopyContext to safely get XState.  Since
-    // we're not using XState at this time, we're doing a straight memcpy to
-    // avoid relying on AVX APIs that aren't available prior to Windows 7 SP1.
-    memcpy(data_sp->GetBytes(), m_context_ptr, sizeof(*m_context_ptr));
+    if (data_sp->GetByteSize() < sizeof(m_context))
+    {
+        data_sp.reset(new DataBufferHeap(sizeof(CONTEXT), 0));
+    }
+    memcpy(data_sp->GetBytes(), &m_context, sizeof(m_context));
     return true;
 }
 
 bool
 RegisterContextWindows_x86::WriteAllRegisterValues(const lldb::DataBufferSP &data_sp)
 {
-    // data_sp could only ever have been generated by a call to ReadAllRegisterValues(), so
-    // m_cached_context should already have the correct size and alignment properties.
-    assert(m_cached_context->GetByteSize() == data_sp->GetByteSize());
-
-    // As a result, we can simply memcpy the entire buffer and assume that the alignment remains
-    // the same.
-    memcpy(m_cached_context->GetBytes(), data_sp->GetBytes(), data_sp->GetByteSize());
+    assert(data_sp->GetByteSize() >= sizeof(m_context));
+    memcpy(&m_context, data_sp->GetBytes(), sizeof(m_context));
 
-    // m_context_ptr still points to the beginning of the CONTEXT structure, so use that for
-    // updating the thread state.
     TargetThreadWindows &wthread = static_cast<TargetThreadWindows &>(m_thread);
-    if (!::SetThreadContext(wthread.GetHostThread().GetNativeThread().GetSystemHandle(), m_context_ptr))
+    if (!::SetThreadContext(wthread.GetHostThread().GetNativeThread().GetSystemHandle(), &m_context))
         return false;
 
     return true;
@@ -325,32 +313,15 @@
 }
 
 bool
-RegisterContextWindows_x86::InitializeContextDataBuffer(DataBufferSP &buffer, CONTEXT **context_ptr)
-{
-    // In the future, we should use InitializeContext to ensure proper size and
-    // alignment.  Since we're not using XState at this time, we're doing a
-    // straight allocation and manually aligning to a 16-byte boundary in order
-    // to avoid relying on AVX APIs that aren't available prior to Windows 7 SP1.
-    const std::size_t kAlignment = 16;
-    buffer.reset(new DataBufferHeap(sizeof(CONTEXT) + kAlignment, 0));
-    *context_ptr = reinterpret_cast<CONTEXT *>(llvm::alignAddr(buffer->GetBytes(), kAlignment));
-
-    (*context_ptr)->ContextFlags = CONTEXT_CONTROL | CONTEXT_INTEGER;
-
-    return true;
-}
-
-bool
 RegisterContextWindows_x86::CacheAllRegisterValues()
 {
     if (!m_context_stale)
         return true;
 
-    if (!m_cached_context && !InitializeContextDataBuffer(m_cached_context, &m_context_ptr))
-        return false;
-
     TargetThreadWindows &wthread = static_cast<TargetThreadWindows &>(m_thread);
-    if (!::GetThreadContext(wthread.GetHostThread().GetNativeThread().GetSystemHandle(), m_context_ptr))
+    memset(&m_context, 0, sizeof(m_context));
+    m_context.ContextFlags = kWinContextFlags;
+    if (!::GetThreadContext(wthread.GetHostThread().GetNativeThread().GetSystemHandle(), &m_context))
         return false;
     m_context_stale = false;
     return true;
Index: source/Plugins/Process/Windows/x86/RegisterContextWindows_x86.h
===================================================================
--- source/Plugins/Process/Windows/x86/RegisterContextWindows_x86.h
+++ source/Plugins/Process/Windows/x86/RegisterContextWindows_x86.h
@@ -69,16 +69,9 @@
     bool HardwareSingleStep(bool enable) override;
 
   private:
-    static bool InitializeContextDataBuffer(lldb::DataBufferSP &buffer, CONTEXT **context_ptr);
-
     bool CacheAllRegisterValues();
 
-    // The system CONTEXT structure.  m_context_ptr is backed by m_cached_context, but
-    // m_context_ptr may not point to the beginning of the buffer allocated in m_cached_context,
-    // due to alignment requirements of CONTEXT structures.
-    lldb::DataBufferSP m_cached_context;
-    CONTEXT *m_context_ptr;
-
+    CONTEXT m_context;
     bool m_context_stale;
 };
 }
_______________________________________________
lldb-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits

Reply via email to