1 //===-- RegisterContextWindowsLive_x86.cpp ------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/lldb-private-types.h"
11 #include "lldb/Core/Error.h"
12 #include "lldb/Core/RegisterValue.h"
13 #include "lldb/Host/windows/HostThreadWindows.h"
14 #include "lldb/Host/windows/windows.h"
16 #include "lldb-x86-register-enums.h"
17 #include "ProcessWindowsLog.h"
18 #include "RegisterContextWindowsLive_x86.h"
19 #include "TargetThreadWindows.h"
21 #include "llvm/ADT/STLExtras.h"
25 namespace lldb_private
28 RegisterContextWindowsLive_x86::RegisterContextWindowsLive_x86(Thread &thread, uint32_t concrete_frame_idx)
29 : RegisterContextWindows_x86(thread, concrete_frame_idx)
33 RegisterContextWindowsLive_x86::~RegisterContextWindowsLive_x86()
39 RegisterContextWindowsLive_x86::WriteRegister(const RegisterInfo *reg_info, const RegisterValue ®_value)
41 // Since we cannot only write a single register value to the inferior, we need to make sure
42 // our cached copy of the register values are fresh. Otherwise when writing EAX, for example,
43 // we may also overwrite some other register with a stale value.
44 if (!CacheAllRegisterValues())
47 uint32_t reg = reg_info->kinds[eRegisterKindLLDB];
51 WINLOG_IFALL(WINDOWS_LOG_REGISTERS, "Write value 0x%x to EAX", reg_value.GetAsUInt32());
52 m_context.Eax = reg_value.GetAsUInt32();
55 WINLOG_IFALL(WINDOWS_LOG_REGISTERS, "Write value 0x%x to EBX", reg_value.GetAsUInt32());
56 m_context.Ebx = reg_value.GetAsUInt32();
59 WINLOG_IFALL(WINDOWS_LOG_REGISTERS, "Write value 0x%x to ECX", reg_value.GetAsUInt32());
60 m_context.Ecx = reg_value.GetAsUInt32();
63 WINLOG_IFALL(WINDOWS_LOG_REGISTERS, "Write value 0x%x to EDX", reg_value.GetAsUInt32());
64 m_context.Edx = reg_value.GetAsUInt32();
67 WINLOG_IFALL(WINDOWS_LOG_REGISTERS, "Write value 0x%x to EDI", reg_value.GetAsUInt32());
68 m_context.Edi = reg_value.GetAsUInt32();
71 WINLOG_IFALL(WINDOWS_LOG_REGISTERS, "Write value 0x%x to ESI", reg_value.GetAsUInt32());
72 m_context.Esi = reg_value.GetAsUInt32();
75 WINLOG_IFALL(WINDOWS_LOG_REGISTERS, "Write value 0x%x to EBP", reg_value.GetAsUInt32());
76 m_context.Ebp = reg_value.GetAsUInt32();
79 WINLOG_IFALL(WINDOWS_LOG_REGISTERS, "Write value 0x%x to ESP", reg_value.GetAsUInt32());
80 m_context.Esp = reg_value.GetAsUInt32();
83 WINLOG_IFALL(WINDOWS_LOG_REGISTERS, "Write value 0x%x to EIP", reg_value.GetAsUInt32());
84 m_context.Eip = reg_value.GetAsUInt32();
86 case lldb_eflags_i386:
87 WINLOG_IFALL(WINDOWS_LOG_REGISTERS, "Write value 0x%x to EFLAGS", reg_value.GetAsUInt32());
88 m_context.EFlags = reg_value.GetAsUInt32();
91 WINWARN_IFALL(WINDOWS_LOG_REGISTERS, "Write value 0x%x to unknown register %u", reg_value.GetAsUInt32(),
95 // Physically update the registers in the target process.
96 TargetThreadWindows &wthread = static_cast<TargetThreadWindows &>(m_thread);
97 return ::SetThreadContext(wthread.GetHostThread().GetNativeThread().GetSystemHandle(), &m_context);
100 } // namespace lldb_private