Index: lldb/trunk/include/lldb/Host/windows/windows.h =================================================================== --- lldb/trunk/include/lldb/Host/windows/windows.h +++ lldb/trunk/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: lldb/trunk/source/Plugins/Process/Windows/x86/RegisterContextWindows_x86.h =================================================================== --- lldb/trunk/source/Plugins/Process/Windows/x86/RegisterContextWindows_x86.h +++ lldb/trunk/source/Plugins/Process/Windows/x86/RegisterContextWindows_x86.h @@ -69,16 +69,9 @@ 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; }; } Index: lldb/trunk/source/Plugins/Process/Windows/x86/RegisterContextWindows_x86.cpp =================================================================== --- lldb/trunk/source/Plugins/Process/Windows/x86/RegisterContextWindows_x86.cpp +++ lldb/trunk/source/Plugins/Process/Windows/x86/RegisterContextWindows_x86.cpp @@ -94,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() { } @@ -141,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; @@ -186,40 +186,40 @@ 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(m_thread); - return ::SetThreadContext(wthread.GetHostThread().GetNativeThread().GetSystemHandle(), m_context_ptr); + return ::SetThreadContext(wthread.GetHostThread().GetNativeThread().GetSystemHandle(), &m_context); } bool @@ -227,32 +227,22 @@ { 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(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 @@ } 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(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;