[Lldb-commits] [PATCH] Don't use CopyContext in RegisterContextWin

Adrian McCarthy amccarth at google.com
Thu Feb 12 14:59:59 PST 2015


Addressed review comments.


http://reviews.llvm.org/D7572

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

Index: include/lldb/Host/windows/windows.h
===================================================================
--- include/lldb/Host/windows/windows.h
+++ include/lldb/Host/windows/windows.h
@@ -19,8 +19,6 @@
 #undef GetUserName
 #undef LoadImage
 #undef CreateProcess
-#undef LoadImage
-#undef GetUserName
 #undef far
 #undef near
 #undef FAR
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,6 +20,7 @@
 #include "TargetThreadWindows.h"
 
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/Support/MathExtras.h"
 
 using namespace lldb;
 using namespace lldb_private;
@@ -232,9 +233,10 @@
     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;
+    // 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));
     return true;
 }
 
@@ -325,16 +327,16 @@
 bool
 RegisterContextWindows_x86::InitializeContextDataBuffer(DataBufferSP &buffer, CONTEXT **context_ptr)
 {
-    DWORD length = 0;
-    if (!::InitializeContext(nullptr, kWinContextFlags, nullptr, &length) && GetLastError() != ERROR_INSUFFICIENT_BUFFER)
-        return false;
+    // 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;
 
-    buffer.reset(new DataBufferHeap(length, 0));
-    if (!::InitializeContext(buffer->GetBytes(), kWinContextFlags, context_ptr, &length))
-    {
-        buffer.reset();
-        return 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,7 +69,7 @@
     bool HardwareSingleStep(bool enable) override;
 
   private:
-    bool InitializeContextDataBuffer(lldb::DataBufferSP &buffer, CONTEXT **context_ptr);
+    static bool InitializeContextDataBuffer(lldb::DataBufferSP &buffer, CONTEXT **context_ptr);
 
     bool CacheAllRegisterValues();

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D7572.19859.patch
Type: text/x-patch
Size: 3128 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20150212/274507d7/attachment.bin>


More information about the lldb-commits mailing list