1 //===-- RegisterContextWindowsLive_x64.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 "RegisterContextWindowsLive_x64.h"
18 #include "TargetThreadWindows.h"
20 #include "llvm/ADT/STLExtras.h"
23 using namespace lldb_private;
25 RegisterContextWindowsLive_x64::RegisterContextWindowsLive_x64(Thread &thread, uint32_t concrete_frame_idx)
26 : RegisterContextWindows_x64(thread, concrete_frame_idx)
30 RegisterContextWindowsLive_x64::~RegisterContextWindowsLive_x64()
36 RegisterContextWindowsLive_x64::ReadRegister(const RegisterInfo *reg_info, RegisterValue ®_value)
38 if (!CacheAllRegisterValues())
41 switch (reg_info->kinds[eRegisterKindLLDB])
44 reg_value.SetUInt64(m_context.Rax);
47 reg_value.SetUInt64(m_context.Rbx);
50 reg_value.SetUInt64(m_context.Rcx);
53 reg_value.SetUInt64(m_context.Rdx);
56 reg_value.SetUInt64(m_context.Rdi);
59 reg_value.SetUInt64(m_context.Rsi);
62 reg_value.SetUInt64(m_context.R8);
65 reg_value.SetUInt64(m_context.R9);
68 reg_value.SetUInt64(m_context.R10);
71 reg_value.SetUInt64(m_context.R11);
74 reg_value.SetUInt64(m_context.R12);
77 reg_value.SetUInt64(m_context.R13);
80 reg_value.SetUInt64(m_context.R14);
83 reg_value.SetUInt64(m_context.R15);
86 reg_value.SetUInt64(m_context.Rbp);
89 reg_value.SetUInt64(m_context.Rsp);
92 reg_value.SetUInt64(m_context.Rip);
94 case lldb_rflags_x86_64:
95 reg_value.SetUInt64(m_context.EFlags);
102 RegisterContextWindowsLive_x64::WriteRegister(const RegisterInfo *reg_info, const RegisterValue ®_value)
104 // Since we cannot only write a single register value to the inferior, we need to make sure
105 // our cached copy of the register values are fresh. Otherwise when writing EAX, for example,
106 // we may also overwrite some other register with a stale value.
107 if (!CacheAllRegisterValues())
110 switch (reg_info->kinds[eRegisterKindLLDB])
112 case lldb_rax_x86_64:
113 m_context.Rax = reg_value.GetAsUInt64();
115 case lldb_rbx_x86_64:
116 m_context.Rbx = reg_value.GetAsUInt64();
118 case lldb_rcx_x86_64:
119 m_context.Rcx = reg_value.GetAsUInt64();
121 case lldb_rdx_x86_64:
122 m_context.Rdx = reg_value.GetAsUInt64();
124 case lldb_rdi_x86_64:
125 m_context.Rdi = reg_value.GetAsUInt64();
127 case lldb_rsi_x86_64:
128 m_context.Rsi = reg_value.GetAsUInt64();
131 m_context.R8 = reg_value.GetAsUInt64();
134 m_context.R9 = reg_value.GetAsUInt64();
136 case lldb_r10_x86_64:
137 m_context.R10 = reg_value.GetAsUInt64();
139 case lldb_r11_x86_64:
140 m_context.R11 = reg_value.GetAsUInt64();
142 case lldb_r12_x86_64:
143 m_context.R12 = reg_value.GetAsUInt64();
145 case lldb_r13_x86_64:
146 m_context.R13 = reg_value.GetAsUInt64();
148 case lldb_r14_x86_64:
149 m_context.R14 = reg_value.GetAsUInt64();
151 case lldb_r15_x86_64:
152 m_context.R15 = reg_value.GetAsUInt64();
154 case lldb_rbp_x86_64:
155 m_context.Rbp = reg_value.GetAsUInt64();
157 case lldb_rsp_x86_64:
158 m_context.Rsp = reg_value.GetAsUInt64();
160 case lldb_rip_x86_64:
161 m_context.Rip = reg_value.GetAsUInt64();
163 case lldb_rflags_x86_64:
164 m_context.EFlags = reg_value.GetAsUInt64();
168 // Physically update the registers in the target process.
169 TargetThreadWindows &wthread = static_cast<TargetThreadWindows &>(m_thread);
170 return ::SetThreadContext(wthread.GetHostThread().GetNativeThread().GetSystemHandle(), &m_context);