[Lldb-commits] [lldb] r229710 - Don't use AVX/XSTATE API on Windows.

Zachary Turner zturner at google.com
Wed Feb 18 10:04:51 PST 2015


Author: zturner
Date: Wed Feb 18 12:04:50 2015
New Revision: 229710

URL: http://llvm.org/viewvc/llvm-project?rev=229710&view=rev
Log:
Don't use AVX/XSTATE API on Windows.

CopyContext is necessary to safely get the XState, but LLDB doesn't currently
use the XState. CopyContext is available as of Windows 7 SP1, so it can't be
used on Vista.  Furthermore, it requires the Windows 8 SDK it compile,
making the baseline for compiling and running LLDB higher than necessary.

Patch by: Adrian McCarthy
Reviewed by: Zachary Turner
Differential Revision: http://reviews.llvm.org/D7572

Modified:
    lldb/trunk/include/lldb/Host/windows/windows.h
    lldb/trunk/source/Plugins/Process/Windows/x86/RegisterContextWindows_x86.cpp
    lldb/trunk/source/Plugins/Process/Windows/x86/RegisterContextWindows_x86.h

Modified: lldb/trunk/include/lldb/Host/windows/windows.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/windows/windows.h?rev=229710&r1=229709&r2=229710&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/windows/windows.h (original)
+++ lldb/trunk/include/lldb/Host/windows/windows.h Wed Feb 18 12:04:50 2015
@@ -19,8 +19,6 @@
 #undef GetUserName
 #undef LoadImage
 #undef CreateProcess
-#undef LoadImage
-#undef GetUserName
 #undef far
 #undef near
 #undef FAR

Modified: lldb/trunk/source/Plugins/Process/Windows/x86/RegisterContextWindows_x86.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Windows/x86/RegisterContextWindows_x86.cpp?rev=229710&r1=229709&r2=229710&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Windows/x86/RegisterContextWindows_x86.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Windows/x86/RegisterContextWindows_x86.cpp Wed Feb 18 12:04:50 2015
@@ -94,7 +94,7 @@ RegisterSet g_register_sets[] = {
 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()
 {
 }
 
@@ -141,34 +141,34 @@ RegisterContextWindows_x86::ReadRegister
     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;
@@ -186,40 +186,40 @@ RegisterContextWindows_x86::WriteRegiste
     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
@@ -227,32 +227,22 @@ RegisterContextWindows_x86::ReadAllRegis
 {
     if (!CacheAllRegisterValues())
         return false;
-
-    CONTEXT *dest_context = nullptr;
-    if (!InitializeContextDataBuffer(data_sp, &dest_context))
-        return false;
-
-    // Write the OS's internal CONTEXT structure into the buffer.
-    if (!CopyContext(dest_context, kWinContextFlags, m_context_ptr))
-        return false;
+    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;
@@ -323,32 +313,15 @@ RegisterContextWindows_x86::HardwareSing
 }
 
 bool
-RegisterContextWindows_x86::InitializeContextDataBuffer(DataBufferSP &buffer, CONTEXT **context_ptr)
-{
-    DWORD length = 0;
-    if (!::InitializeContext(nullptr, kWinContextFlags, nullptr, &length) && GetLastError() != ERROR_INSUFFICIENT_BUFFER)
-        return false;
-
-    buffer.reset(new DataBufferHeap(length, 0));
-    if (!::InitializeContext(buffer->GetBytes(), kWinContextFlags, context_ptr, &length))
-    {
-        buffer.reset();
-        return false;
-    }
-    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;

Modified: lldb/trunk/source/Plugins/Process/Windows/x86/RegisterContextWindows_x86.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Windows/x86/RegisterContextWindows_x86.h?rev=229710&r1=229709&r2=229710&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Windows/x86/RegisterContextWindows_x86.h (original)
+++ lldb/trunk/source/Plugins/Process/Windows/x86/RegisterContextWindows_x86.h Wed Feb 18 12:04:50 2015
@@ -69,16 +69,9 @@ class RegisterContextWindows_x86 : publi
     bool HardwareSingleStep(bool enable) override;
 
   private:
-    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;
 };
 }





More information about the lldb-commits mailing list