]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - source/Plugins/Process/Windows/Live/x86/RegisterContextWindowsLive_x86.cpp
Vendor import of lldb trunk r256945:
[FreeBSD/FreeBSD.git] / source / Plugins / Process / Windows / Live / x86 / RegisterContextWindowsLive_x86.cpp
1 //===-- RegisterContextWindowsLive_x86.cpp ------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
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"
15
16 #include "lldb-x86-register-enums.h"
17 #include "ProcessWindowsLog.h"
18 #include "RegisterContextWindowsLive_x86.h"
19 #include "TargetThreadWindows.h"
20
21 #include "llvm/ADT/STLExtras.h"
22
23 using namespace lldb;
24
25 namespace lldb_private
26 {
27
28 RegisterContextWindowsLive_x86::RegisterContextWindowsLive_x86(Thread &thread, uint32_t concrete_frame_idx)
29     : RegisterContextWindows_x86(thread, concrete_frame_idx)
30 {
31 }
32
33 RegisterContextWindowsLive_x86::~RegisterContextWindowsLive_x86()
34 {
35 }
36
37
38 bool
39 RegisterContextWindowsLive_x86::WriteRegister(const RegisterInfo *reg_info, const RegisterValue &reg_value)
40 {
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())
45         return false;
46
47     uint32_t reg = reg_info->kinds[eRegisterKindLLDB];
48     switch (reg)
49     {
50         case lldb_eax_i386:
51             WINLOG_IFALL(WINDOWS_LOG_REGISTERS, "Write value 0x%x to EAX", reg_value.GetAsUInt32());
52             m_context.Eax = reg_value.GetAsUInt32();
53             break;
54         case lldb_ebx_i386:
55             WINLOG_IFALL(WINDOWS_LOG_REGISTERS, "Write value 0x%x to EBX", reg_value.GetAsUInt32());
56             m_context.Ebx = reg_value.GetAsUInt32();
57             break;
58         case lldb_ecx_i386:
59             WINLOG_IFALL(WINDOWS_LOG_REGISTERS, "Write value 0x%x to ECX", reg_value.GetAsUInt32());
60             m_context.Ecx = reg_value.GetAsUInt32();
61             break;
62         case lldb_edx_i386:
63             WINLOG_IFALL(WINDOWS_LOG_REGISTERS, "Write value 0x%x to EDX", reg_value.GetAsUInt32());
64             m_context.Edx = reg_value.GetAsUInt32();
65             break;
66         case lldb_edi_i386:
67             WINLOG_IFALL(WINDOWS_LOG_REGISTERS, "Write value 0x%x to EDI", reg_value.GetAsUInt32());
68             m_context.Edi = reg_value.GetAsUInt32();
69             break;
70         case lldb_esi_i386:
71             WINLOG_IFALL(WINDOWS_LOG_REGISTERS, "Write value 0x%x to ESI", reg_value.GetAsUInt32());
72             m_context.Esi = reg_value.GetAsUInt32();
73             break;
74         case lldb_ebp_i386:
75             WINLOG_IFALL(WINDOWS_LOG_REGISTERS, "Write value 0x%x to EBP", reg_value.GetAsUInt32());
76             m_context.Ebp = reg_value.GetAsUInt32();
77             break;
78         case lldb_esp_i386:
79             WINLOG_IFALL(WINDOWS_LOG_REGISTERS, "Write value 0x%x to ESP", reg_value.GetAsUInt32());
80             m_context.Esp = reg_value.GetAsUInt32();
81             break;
82         case lldb_eip_i386:
83             WINLOG_IFALL(WINDOWS_LOG_REGISTERS, "Write value 0x%x to EIP", reg_value.GetAsUInt32());
84             m_context.Eip = reg_value.GetAsUInt32();
85             break;
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();
89             break;
90         default:
91             WINWARN_IFALL(WINDOWS_LOG_REGISTERS, "Write value 0x%x to unknown register %u", reg_value.GetAsUInt32(),
92                           reg);
93     }
94
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);
98 }
99
100 }  // namespace lldb_private