1 //===-- RegisterContextWindows_x64.cpp ------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #if defined(__x86_64__) || defined(_M_X64)
10 
11 #include "lldb/Host/windows/HostThreadWindows.h"
12 #include "lldb/Host/windows/windows.h"
13 #include "lldb/Utility/RegisterValue.h"
14 #include "lldb/Utility/Status.h"
15 #include "lldb/lldb-private-types.h"
16 
17 #include "RegisterContextWindows_x64.h"
18 #include "Plugins/Process/Utility/RegisterContext_x86.h"
19 #include "TargetThreadWindows.h"
20 #include "Plugins/Process/Utility/lldb-x86-register-enums.h"
21 
22 #include "llvm/ADT/STLExtras.h"
23 
24 using namespace lldb;
25 using namespace lldb_private;
26 
27 #define DEFINE_GPR(reg, alt, generic)                                          \
28 {                                                                              \
29   #reg, alt, 8, 0, eEncodingUint, eFormatHexUppercase,                         \
30       {dwarf_##reg##_x86_64, dwarf_##reg##_x86_64, generic,                    \
31         LLDB_INVALID_REGNUM, lldb_##reg##_x86_64 },                            \
32         nullptr, nullptr,                                                      \
33 }
34 
35 #define DEFINE_GPR_BIN(reg, alt) #reg, alt, 8, 0, eEncodingUint, eFormatBinary
36 #define DEFINE_FPU_XMM(reg)                                                    \
37   #reg, NULL, 16, 0, eEncodingUint, eFormatVectorOfUInt64,                     \
38   {dwarf_##reg##_x86_64, dwarf_##reg##_x86_64, LLDB_INVALID_REGNUM,            \
39    LLDB_INVALID_REGNUM, lldb_##reg##_x86_64},                                  \
40   nullptr, nullptr
41 
42 #define DEFINE_GPR_PSEUDO_32(reg)                                              \
43 {                                                                              \
44   #reg, nullptr, 4, 0, eEncodingUint, eFormatHexUppercase,                     \
45       {LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,          \
46         LLDB_INVALID_REGNUM, lldb_##reg##_x86_64 },                            \
47         nullptr, nullptr                                                       \
48 }
49 
50 #define DEFINE_GPR_PSEUDO_16(reg)                                              \
51 {                                                                              \
52   #reg, nullptr, 2, 0, eEncodingUint, eFormatHexUppercase,                     \
53       {LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,          \
54         LLDB_INVALID_REGNUM, lldb_##reg##_x86_64 },                            \
55         nullptr, nullptr                                                       \
56 }
57 
58 #define DEFINE_GPR_PSEUDO_8(reg)                                               \
59 {                                                                              \
60   #reg, nullptr, 1, 0, eEncodingUint, eFormatHexUppercase,                     \
61       {LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,          \
62         LLDB_INVALID_REGNUM, lldb_##reg##_x86_64 },                            \
63         nullptr, nullptr                                                       \
64 }
65 
66 namespace {
67 
68 // This enum defines the layout of the global RegisterInfo array.  This is
69 // necessary because lldb register sets are defined in terms of indices into
70 // the register array. As such, the order of RegisterInfos defined in global
71 // registers array must match the order defined here. When defining the
72 // register set layouts, these values can appear in an arbitrary order, and
73 // that determines the order that register values are displayed in a dump.
74 enum RegisterIndex {
75   eRegisterIndexRax,
76   eRegisterIndexRbx,
77   eRegisterIndexRcx,
78   eRegisterIndexRdx,
79   eRegisterIndexRdi,
80   eRegisterIndexRsi,
81   eRegisterIndexRbp,
82   eRegisterIndexRsp,
83   eRegisterIndexR8,
84   eRegisterIndexR9,
85   eRegisterIndexR10,
86   eRegisterIndexR11,
87   eRegisterIndexR12,
88   eRegisterIndexR13,
89   eRegisterIndexR14,
90   eRegisterIndexR15,
91   eRegisterIndexRip,
92   eRegisterIndexRflags,
93   eRegisterIndexEax,
94   eRegisterIndexEbx,
95   eRegisterIndexEcx,
96   eRegisterIndexEdx,
97   eRegisterIndexEdi,
98   eRegisterIndexEsi,
99   eRegisterIndexEbp,
100   eRegisterIndexEsp,
101   eRegisterIndexR8d,
102   eRegisterIndexR9d,
103   eRegisterIndexR10d,
104   eRegisterIndexR11d,
105   eRegisterIndexR12d,
106   eRegisterIndexR13d,
107   eRegisterIndexR14d,
108   eRegisterIndexR15d,
109   eRegisterIndexAx,
110   eRegisterIndexBx,
111   eRegisterIndexCx,
112   eRegisterIndexDx,
113   eRegisterIndexDi,
114   eRegisterIndexSi,
115   eRegisterIndexBp,
116   eRegisterIndexSp,
117   eRegisterIndexR8w,
118   eRegisterIndexR9w,
119   eRegisterIndexR10w,
120   eRegisterIndexR11w,
121   eRegisterIndexR12w,
122   eRegisterIndexR13w,
123   eRegisterIndexR14w,
124   eRegisterIndexR15w,
125   eRegisterIndexAh,
126   eRegisterIndexBh,
127   eRegisterIndexCh,
128   eRegisterIndexDh,
129   eRegisterIndexAl,
130   eRegisterIndexBl,
131   eRegisterIndexCl,
132   eRegisterIndexDl,
133   eRegisterIndexDil,
134   eRegisterIndexSil,
135   eRegisterIndexBpl,
136   eRegisterIndexSpl,
137   eRegisterIndexR8l,
138   eRegisterIndexR9l,
139   eRegisterIndexR10l,
140   eRegisterIndexR11l,
141   eRegisterIndexR12l,
142   eRegisterIndexR13l,
143   eRegisterIndexR14l,
144   eRegisterIndexR15l,
145 
146   eRegisterIndexXmm0,
147   eRegisterIndexXmm1,
148   eRegisterIndexXmm2,
149   eRegisterIndexXmm3,
150   eRegisterIndexXmm4,
151   eRegisterIndexXmm5,
152   eRegisterIndexXmm6,
153   eRegisterIndexXmm7,
154   eRegisterIndexXmm8,
155   eRegisterIndexXmm9,
156   eRegisterIndexXmm10,
157   eRegisterIndexXmm11,
158   eRegisterIndexXmm12,
159   eRegisterIndexXmm13,
160   eRegisterIndexXmm14,
161   eRegisterIndexXmm15
162 };
163 
164 // Array of all register information supported by Windows x86
165 RegisterInfo g_register_infos[] = {
166     //  Macro auto defines most stuff     eh_frame                  DWARF
167     //  GENERIC
168     //  GDB                  LLDB                  VALUE REGS    INVALIDATE REGS
169     //  ================================  =========================
170     //  ======================  =========================
171     //  ===================  =================     ==========    ===============
172     DEFINE_GPR(rax, nullptr, LLDB_INVALID_REGNUM),
173     DEFINE_GPR(rbx, nullptr, LLDB_INVALID_REGNUM),
174     DEFINE_GPR(rcx, nullptr, LLDB_REGNUM_GENERIC_ARG1),
175     DEFINE_GPR(rdx, nullptr, LLDB_REGNUM_GENERIC_ARG2),
176     DEFINE_GPR(rdi, nullptr, LLDB_INVALID_REGNUM),
177     DEFINE_GPR(rsi, nullptr, LLDB_INVALID_REGNUM),
178     DEFINE_GPR(rbp, "fp", LLDB_REGNUM_GENERIC_FP),
179     DEFINE_GPR(rsp, "sp", LLDB_REGNUM_GENERIC_SP),
180     DEFINE_GPR(r8, nullptr, LLDB_REGNUM_GENERIC_ARG3),
181     DEFINE_GPR(r9, nullptr, LLDB_REGNUM_GENERIC_ARG4),
182     DEFINE_GPR(r10, nullptr, LLDB_INVALID_REGNUM),
183     DEFINE_GPR(r11, nullptr, LLDB_INVALID_REGNUM),
184     DEFINE_GPR(r12, nullptr, LLDB_INVALID_REGNUM),
185     DEFINE_GPR(r13, nullptr, LLDB_INVALID_REGNUM),
186     DEFINE_GPR(r14, nullptr, LLDB_INVALID_REGNUM),
187     DEFINE_GPR(r15, nullptr, LLDB_INVALID_REGNUM),
188     DEFINE_GPR(rip, "pc", LLDB_REGNUM_GENERIC_PC),
189     {
190         DEFINE_GPR_BIN(eflags, "flags"),
191         {LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_REGNUM_GENERIC_FLAGS,
192          LLDB_INVALID_REGNUM, lldb_rflags_x86_64},
193         nullptr,
194         nullptr,
195     },
196     DEFINE_GPR_PSEUDO_32(eax),
197     DEFINE_GPR_PSEUDO_32(ebx),
198     DEFINE_GPR_PSEUDO_32(ecx),
199     DEFINE_GPR_PSEUDO_32(edx),
200     DEFINE_GPR_PSEUDO_32(edi),
201     DEFINE_GPR_PSEUDO_32(esi),
202     DEFINE_GPR_PSEUDO_32(ebp),
203     DEFINE_GPR_PSEUDO_32(esp),
204     DEFINE_GPR_PSEUDO_32(r8d),
205     DEFINE_GPR_PSEUDO_32(r9d),
206     DEFINE_GPR_PSEUDO_32(r10d),
207     DEFINE_GPR_PSEUDO_32(r11d),
208     DEFINE_GPR_PSEUDO_32(r12d),
209     DEFINE_GPR_PSEUDO_32(r13d),
210     DEFINE_GPR_PSEUDO_32(r14d),
211     DEFINE_GPR_PSEUDO_32(r15d),
212     DEFINE_GPR_PSEUDO_16(ax),
213     DEFINE_GPR_PSEUDO_16(bx),
214     DEFINE_GPR_PSEUDO_16(cx),
215     DEFINE_GPR_PSEUDO_16(dx),
216     DEFINE_GPR_PSEUDO_16(di),
217     DEFINE_GPR_PSEUDO_16(si),
218     DEFINE_GPR_PSEUDO_16(bp),
219     DEFINE_GPR_PSEUDO_16(sp),
220     DEFINE_GPR_PSEUDO_16(r8w),
221     DEFINE_GPR_PSEUDO_16(r9w),
222     DEFINE_GPR_PSEUDO_16(r10w),
223     DEFINE_GPR_PSEUDO_16(r11w),
224     DEFINE_GPR_PSEUDO_16(r12w),
225     DEFINE_GPR_PSEUDO_16(r13w),
226     DEFINE_GPR_PSEUDO_16(r14w),
227     DEFINE_GPR_PSEUDO_16(r15w),
228     DEFINE_GPR_PSEUDO_8(ah),
229     DEFINE_GPR_PSEUDO_8(bh),
230     DEFINE_GPR_PSEUDO_8(ch),
231     DEFINE_GPR_PSEUDO_8(dh),
232     DEFINE_GPR_PSEUDO_8(al),
233     DEFINE_GPR_PSEUDO_8(bl),
234     DEFINE_GPR_PSEUDO_8(cl),
235     DEFINE_GPR_PSEUDO_8(dl),
236     DEFINE_GPR_PSEUDO_8(dil),
237     DEFINE_GPR_PSEUDO_8(sil),
238     DEFINE_GPR_PSEUDO_8(bpl),
239     DEFINE_GPR_PSEUDO_8(spl),
240     DEFINE_GPR_PSEUDO_8(r8l),
241     DEFINE_GPR_PSEUDO_8(r9l),
242     DEFINE_GPR_PSEUDO_8(r10l),
243     DEFINE_GPR_PSEUDO_8(r11l),
244     DEFINE_GPR_PSEUDO_8(r12l),
245     DEFINE_GPR_PSEUDO_8(r13l),
246     DEFINE_GPR_PSEUDO_8(r14l),
247     DEFINE_GPR_PSEUDO_8(r15l),
248     {DEFINE_FPU_XMM(xmm0)},
249     {DEFINE_FPU_XMM(xmm1)},
250     {DEFINE_FPU_XMM(xmm2)},
251     {DEFINE_FPU_XMM(xmm3)},
252     {DEFINE_FPU_XMM(xmm4)},
253     {DEFINE_FPU_XMM(xmm5)},
254     {DEFINE_FPU_XMM(xmm6)},
255     {DEFINE_FPU_XMM(xmm7)},
256     {DEFINE_FPU_XMM(xmm8)},
257     {DEFINE_FPU_XMM(xmm9)},
258     {DEFINE_FPU_XMM(xmm10)},
259     {DEFINE_FPU_XMM(xmm11)},
260     {DEFINE_FPU_XMM(xmm12)},
261     {DEFINE_FPU_XMM(xmm13)},
262     {DEFINE_FPU_XMM(xmm14)},
263     {DEFINE_FPU_XMM(xmm15)}};
264 
265 static size_t k_num_register_infos = llvm::array_lengthof(g_register_infos);
266 
267 // Array of lldb register numbers used to define the set of all General Purpose
268 // Registers
269 uint32_t g_gpr_reg_indices[] = {
270     eRegisterIndexRax,  eRegisterIndexRbx,  eRegisterIndexRcx,
271     eRegisterIndexRdx,  eRegisterIndexRdi,  eRegisterIndexRsi,
272     eRegisterIndexRbp,  eRegisterIndexRsp,  eRegisterIndexR8,
273     eRegisterIndexR9,   eRegisterIndexR10,  eRegisterIndexR11,
274     eRegisterIndexR12,  eRegisterIndexR13,  eRegisterIndexR14,
275     eRegisterIndexR15,  eRegisterIndexRip,  eRegisterIndexRflags,
276     eRegisterIndexEax,  eRegisterIndexEbx,  eRegisterIndexEcx,
277     eRegisterIndexEdx,  eRegisterIndexEdi,  eRegisterIndexEsi,
278     eRegisterIndexEbp,  eRegisterIndexEsp,  eRegisterIndexR8d,
279     eRegisterIndexR9d,  eRegisterIndexR10d, eRegisterIndexR11d,
280     eRegisterIndexR12d, eRegisterIndexR13d, eRegisterIndexR14d,
281     eRegisterIndexR15d, eRegisterIndexAx,   eRegisterIndexBx,
282     eRegisterIndexCx,   eRegisterIndexDx,   eRegisterIndexDi,
283     eRegisterIndexSi,   eRegisterIndexBp,   eRegisterIndexSp,
284     eRegisterIndexR8w,  eRegisterIndexR9w,  eRegisterIndexR10w,
285     eRegisterIndexR11w, eRegisterIndexR12w, eRegisterIndexR13w,
286     eRegisterIndexR14w, eRegisterIndexR15w, eRegisterIndexAh,
287     eRegisterIndexBh,   eRegisterIndexCh,   eRegisterIndexDh,
288     eRegisterIndexAl,   eRegisterIndexBl,   eRegisterIndexCl,
289     eRegisterIndexDl,   eRegisterIndexDil,  eRegisterIndexSil,
290     eRegisterIndexBpl,  eRegisterIndexSpl,  eRegisterIndexR8l,
291     eRegisterIndexR9l,  eRegisterIndexR10l, eRegisterIndexR11l,
292     eRegisterIndexR12l, eRegisterIndexR13l, eRegisterIndexR14l,
293     eRegisterIndexR15l
294 };
295 
296 uint32_t g_fpu_reg_indices[] = {
297     eRegisterIndexXmm0,  eRegisterIndexXmm1,  eRegisterIndexXmm2,
298     eRegisterIndexXmm3,  eRegisterIndexXmm4,  eRegisterIndexXmm5,
299     eRegisterIndexXmm6,  eRegisterIndexXmm7,  eRegisterIndexXmm8,
300     eRegisterIndexXmm9,  eRegisterIndexXmm10, eRegisterIndexXmm11,
301     eRegisterIndexXmm12, eRegisterIndexXmm13, eRegisterIndexXmm14,
302     eRegisterIndexXmm15
303 };
304 
305 RegisterSet g_register_sets[] = {
306     {"General Purpose Registers", "gpr",
307      llvm::array_lengthof(g_gpr_reg_indices), g_gpr_reg_indices},
308     {"Floating Point Registers", "fpu",
309      llvm::array_lengthof(g_fpu_reg_indices), g_fpu_reg_indices}};
310 }
311 
312 // Constructors and Destructors
RegisterContextWindows_x64(Thread & thread,uint32_t concrete_frame_idx)313 RegisterContextWindows_x64::RegisterContextWindows_x64(
314     Thread &thread, uint32_t concrete_frame_idx)
315     : RegisterContextWindows(thread, concrete_frame_idx) {}
316 
~RegisterContextWindows_x64()317 RegisterContextWindows_x64::~RegisterContextWindows_x64() {}
318 
GetRegisterCount()319 size_t RegisterContextWindows_x64::GetRegisterCount() {
320   return llvm::array_lengthof(g_register_infos);
321 }
322 
323 const RegisterInfo *
GetRegisterInfoAtIndex(size_t reg)324 RegisterContextWindows_x64::GetRegisterInfoAtIndex(size_t reg) {
325   if (reg < k_num_register_infos)
326     return &g_register_infos[reg];
327   return NULL;
328 }
329 
GetRegisterSetCount()330 size_t RegisterContextWindows_x64::GetRegisterSetCount() {
331   return llvm::array_lengthof(g_register_sets);
332 }
333 
GetRegisterSet(size_t reg_set)334 const RegisterSet *RegisterContextWindows_x64::GetRegisterSet(size_t reg_set) {
335   return &g_register_sets[reg_set];
336 }
337 
ReadRegister(const RegisterInfo * reg_info,RegisterValue & reg_value)338 bool RegisterContextWindows_x64::ReadRegister(const RegisterInfo *reg_info,
339                                               RegisterValue &reg_value) {
340   if (!CacheAllRegisterValues())
341     return false;
342 
343   if (reg_info == nullptr)
344     return false;
345 
346   const uint32_t reg = reg_info->kinds[eRegisterKindLLDB];
347 
348   switch (reg) {
349 #define GPR_CASE(size, reg_case, reg_val)                                      \
350   case reg_case:                                                               \
351     reg_value.SetUInt##size(reg_val);                                        \
352     break;
353 
354   GPR_CASE(64, lldb_rax_x86_64, m_context.Rax);
355   GPR_CASE(64, lldb_rbx_x86_64, m_context.Rbx);
356   GPR_CASE(64, lldb_rcx_x86_64, m_context.Rcx);
357   GPR_CASE(64, lldb_rdx_x86_64, m_context.Rdx);
358   GPR_CASE(64, lldb_rdi_x86_64, m_context.Rdi);
359   GPR_CASE(64, lldb_rsi_x86_64, m_context.Rsi);
360   GPR_CASE(64, lldb_r8_x86_64, m_context.R8);
361   GPR_CASE(64, lldb_r9_x86_64, m_context.R9);
362   GPR_CASE(64, lldb_r10_x86_64, m_context.R10);
363   GPR_CASE(64, lldb_r11_x86_64, m_context.R11);
364   GPR_CASE(64, lldb_r12_x86_64, m_context.R12);
365   GPR_CASE(64, lldb_r13_x86_64, m_context.R13);
366   GPR_CASE(64, lldb_r14_x86_64, m_context.R14);
367   GPR_CASE(64, lldb_r15_x86_64, m_context.R15);
368   GPR_CASE(64, lldb_rbp_x86_64, m_context.Rbp);
369   GPR_CASE(64, lldb_rsp_x86_64, m_context.Rsp);
370   GPR_CASE(64, lldb_rip_x86_64, m_context.Rip);
371   GPR_CASE(64, lldb_rflags_x86_64, m_context.EFlags);
372   GPR_CASE(32, lldb_eax_x86_64, static_cast<uint32_t>(m_context.Rax));
373   GPR_CASE(32, lldb_ebx_x86_64, static_cast<uint32_t>(m_context.Rbx));
374   GPR_CASE(32, lldb_ecx_x86_64, static_cast<uint32_t>(m_context.Rcx));
375   GPR_CASE(32, lldb_edx_x86_64, static_cast<uint32_t>(m_context.Rdx));
376   GPR_CASE(32, lldb_edi_x86_64, static_cast<uint32_t>(m_context.Rdi));
377   GPR_CASE(32, lldb_esi_x86_64, static_cast<uint32_t>(m_context.Rsi));
378   GPR_CASE(32, lldb_ebp_x86_64, static_cast<uint32_t>(m_context.Rbp));
379   GPR_CASE(32, lldb_esp_x86_64, static_cast<uint32_t>(m_context.Rsp));
380   GPR_CASE(32, lldb_r8d_x86_64, static_cast<uint32_t>(m_context.R8));
381   GPR_CASE(32, lldb_r9d_x86_64, static_cast<uint32_t>(m_context.R9));
382   GPR_CASE(32, lldb_r10d_x86_64, static_cast<uint32_t>(m_context.R10));
383   GPR_CASE(32, lldb_r11d_x86_64, static_cast<uint32_t>(m_context.R11));
384   GPR_CASE(32, lldb_r12d_x86_64, static_cast<uint32_t>(m_context.R12));
385   GPR_CASE(32, lldb_r13d_x86_64, static_cast<uint32_t>(m_context.R13));
386   GPR_CASE(32, lldb_r14d_x86_64, static_cast<uint32_t>(m_context.R14));
387   GPR_CASE(32, lldb_r15d_x86_64, static_cast<uint32_t>(m_context.R15));
388   GPR_CASE(16, lldb_ax_x86_64, static_cast<uint16_t>(m_context.Rax));
389   GPR_CASE(16, lldb_bx_x86_64, static_cast<uint16_t>(m_context.Rbx));
390   GPR_CASE(16, lldb_cx_x86_64, static_cast<uint16_t>(m_context.Rcx));
391   GPR_CASE(16, lldb_dx_x86_64, static_cast<uint16_t>(m_context.Rdx));
392   GPR_CASE(16, lldb_di_x86_64, static_cast<uint16_t>(m_context.Rdi));
393   GPR_CASE(16, lldb_si_x86_64, static_cast<uint16_t>(m_context.Rsi));
394   GPR_CASE(16, lldb_bp_x86_64, static_cast<uint16_t>(m_context.Rbp));
395   GPR_CASE(16, lldb_sp_x86_64, static_cast<uint16_t>(m_context.Rsp));
396   GPR_CASE(16, lldb_r8w_x86_64, static_cast<uint16_t>(m_context.R8));
397   GPR_CASE(16, lldb_r9w_x86_64, static_cast<uint16_t>(m_context.R9));
398   GPR_CASE(16, lldb_r10w_x86_64, static_cast<uint16_t>(m_context.R10));
399   GPR_CASE(16, lldb_r11w_x86_64, static_cast<uint16_t>(m_context.R11));
400   GPR_CASE(16, lldb_r12w_x86_64, static_cast<uint16_t>(m_context.R12));
401   GPR_CASE(16, lldb_r13w_x86_64, static_cast<uint16_t>(m_context.R13));
402   GPR_CASE(16, lldb_r14w_x86_64, static_cast<uint16_t>(m_context.R14));
403   GPR_CASE(16, lldb_r15w_x86_64, static_cast<uint16_t>(m_context.R15));
404   GPR_CASE(8, lldb_ah_x86_64, static_cast<uint16_t>(m_context.Rax) >> 8);
405   GPR_CASE(8, lldb_bh_x86_64, static_cast<uint16_t>(m_context.Rbx) >> 8);
406   GPR_CASE(8, lldb_ch_x86_64, static_cast<uint16_t>(m_context.Rcx) >> 8);
407   GPR_CASE(8, lldb_dh_x86_64, static_cast<uint16_t>(m_context.Rdx) >> 8);
408   GPR_CASE(8, lldb_al_x86_64, static_cast<uint8_t>(m_context.Rax));
409   GPR_CASE(8, lldb_bl_x86_64, static_cast<uint8_t>(m_context.Rbx));
410   GPR_CASE(8, lldb_cl_x86_64, static_cast<uint8_t>(m_context.Rcx));
411   GPR_CASE(8, lldb_dl_x86_64, static_cast<uint8_t>(m_context.Rdx));
412   GPR_CASE(8, lldb_dil_x86_64, static_cast<uint8_t>(m_context.Rdi));
413   GPR_CASE(8, lldb_sil_x86_64, static_cast<uint8_t>(m_context.Rsi));
414   GPR_CASE(8, lldb_bpl_x86_64, static_cast<uint8_t>(m_context.Rbp));
415   GPR_CASE(8, lldb_spl_x86_64, static_cast<uint8_t>(m_context.Rsp));
416   GPR_CASE(8, lldb_r8l_x86_64, static_cast<uint8_t>(m_context.R8));
417   GPR_CASE(8, lldb_r9l_x86_64, static_cast<uint8_t>(m_context.R9));
418   GPR_CASE(8, lldb_r10l_x86_64, static_cast<uint8_t>(m_context.R10));
419   GPR_CASE(8, lldb_r11l_x86_64, static_cast<uint8_t>(m_context.R11));
420   GPR_CASE(8, lldb_r12l_x86_64, static_cast<uint8_t>(m_context.R12));
421   GPR_CASE(8, lldb_r13l_x86_64, static_cast<uint8_t>(m_context.R13));
422   GPR_CASE(8, lldb_r14l_x86_64, static_cast<uint8_t>(m_context.R14));
423   GPR_CASE(8, lldb_r15l_x86_64, static_cast<uint8_t>(m_context.R15));
424 
425   case lldb_xmm0_x86_64:
426     reg_value.SetBytes(&m_context.Xmm0,
427                        reg_info->byte_size, endian::InlHostByteOrder());
428     break;
429   case lldb_xmm1_x86_64:
430     reg_value.SetBytes(&m_context.Xmm1,
431                        reg_info->byte_size, endian::InlHostByteOrder());
432     break;
433   case lldb_xmm2_x86_64:
434     reg_value.SetBytes(&m_context.Xmm2,
435                        reg_info->byte_size, endian::InlHostByteOrder());
436     break;
437   case lldb_xmm3_x86_64:
438     reg_value.SetBytes(&m_context.Xmm3,
439                        reg_info->byte_size, endian::InlHostByteOrder());
440     break;
441   case lldb_xmm4_x86_64:
442     reg_value.SetBytes(&m_context.Xmm4,
443                        reg_info->byte_size, endian::InlHostByteOrder());
444     break;
445   case lldb_xmm5_x86_64:
446     reg_value.SetBytes(&m_context.Xmm5,
447                        reg_info->byte_size, endian::InlHostByteOrder());
448     break;
449   case lldb_xmm6_x86_64:
450     reg_value.SetBytes(&m_context.Xmm6,
451                        reg_info->byte_size, endian::InlHostByteOrder());
452     break;
453   case lldb_xmm7_x86_64:
454     reg_value.SetBytes(&m_context.Xmm7,
455                        reg_info->byte_size, endian::InlHostByteOrder());
456     break;
457   case lldb_xmm8_x86_64:
458     reg_value.SetBytes(&m_context.Xmm8,
459                        reg_info->byte_size, endian::InlHostByteOrder());
460     break;
461   case lldb_xmm9_x86_64:
462     reg_value.SetBytes(&m_context.Xmm9,
463                        reg_info->byte_size, endian::InlHostByteOrder());
464     break;
465   case lldb_xmm10_x86_64:
466     reg_value.SetBytes(&m_context.Xmm10,
467                        reg_info->byte_size, endian::InlHostByteOrder());
468     break;
469   case lldb_xmm11_x86_64:
470     reg_value.SetBytes(&m_context.Xmm11,
471                        reg_info->byte_size, endian::InlHostByteOrder());
472     break;
473   case lldb_xmm12_x86_64:
474     reg_value.SetBytes(&m_context.Xmm12,
475                        reg_info->byte_size, endian::InlHostByteOrder());
476     break;
477   case lldb_xmm13_x86_64:
478     reg_value.SetBytes(&m_context.Xmm13,
479                        reg_info->byte_size, endian::InlHostByteOrder());
480     break;
481   case lldb_xmm14_x86_64:
482     reg_value.SetBytes(&m_context.Xmm14,
483                        reg_info->byte_size, endian::InlHostByteOrder());
484     break;
485   case lldb_xmm15_x86_64:
486     reg_value.SetBytes(&m_context.Xmm15,
487                        reg_info->byte_size, endian::InlHostByteOrder());
488     break;
489   }
490   return true;
491 }
492 
WriteRegister(const RegisterInfo * reg_info,const RegisterValue & reg_value)493 bool RegisterContextWindows_x64::WriteRegister(const RegisterInfo *reg_info,
494                                                const RegisterValue &reg_value) {
495   // Since we cannot only write a single register value to the inferior, we
496   // need to make sure our cached copy of the register values are fresh.
497   // Otherwise when writing EAX, for example, we may also overwrite some other
498   // register with a stale value.
499   if (!CacheAllRegisterValues())
500     return false;
501 
502   switch (reg_info->kinds[eRegisterKindLLDB]) {
503   case lldb_rax_x86_64:
504     m_context.Rax = reg_value.GetAsUInt64();
505     break;
506   case lldb_rbx_x86_64:
507     m_context.Rbx = reg_value.GetAsUInt64();
508     break;
509   case lldb_rcx_x86_64:
510     m_context.Rcx = reg_value.GetAsUInt64();
511     break;
512   case lldb_rdx_x86_64:
513     m_context.Rdx = reg_value.GetAsUInt64();
514     break;
515   case lldb_rdi_x86_64:
516     m_context.Rdi = reg_value.GetAsUInt64();
517     break;
518   case lldb_rsi_x86_64:
519     m_context.Rsi = reg_value.GetAsUInt64();
520     break;
521   case lldb_r8_x86_64:
522     m_context.R8 = reg_value.GetAsUInt64();
523     break;
524   case lldb_r9_x86_64:
525     m_context.R9 = reg_value.GetAsUInt64();
526     break;
527   case lldb_r10_x86_64:
528     m_context.R10 = reg_value.GetAsUInt64();
529     break;
530   case lldb_r11_x86_64:
531     m_context.R11 = reg_value.GetAsUInt64();
532     break;
533   case lldb_r12_x86_64:
534     m_context.R12 = reg_value.GetAsUInt64();
535     break;
536   case lldb_r13_x86_64:
537     m_context.R13 = reg_value.GetAsUInt64();
538     break;
539   case lldb_r14_x86_64:
540     m_context.R14 = reg_value.GetAsUInt64();
541     break;
542   case lldb_r15_x86_64:
543     m_context.R15 = reg_value.GetAsUInt64();
544     break;
545   case lldb_rbp_x86_64:
546     m_context.Rbp = reg_value.GetAsUInt64();
547     break;
548   case lldb_rsp_x86_64:
549     m_context.Rsp = reg_value.GetAsUInt64();
550     break;
551   case lldb_rip_x86_64:
552     m_context.Rip = reg_value.GetAsUInt64();
553     break;
554   case lldb_rflags_x86_64:
555     m_context.EFlags = reg_value.GetAsUInt64();
556     break;
557   case lldb_xmm0_x86_64:
558     memcpy(&m_context.Xmm0, reg_value.GetBytes(), 16);
559     break;
560   case lldb_xmm1_x86_64:
561     memcpy(&m_context.Xmm1, reg_value.GetBytes(), 16);
562     break;
563   case lldb_xmm2_x86_64:
564     memcpy(&m_context.Xmm2, reg_value.GetBytes(), 16);
565     break;
566   case lldb_xmm3_x86_64:
567     memcpy(&m_context.Xmm3, reg_value.GetBytes(), 16);
568     break;
569   case lldb_xmm4_x86_64:
570     memcpy(&m_context.Xmm4, reg_value.GetBytes(), 16);
571     break;
572   case lldb_xmm5_x86_64:
573     memcpy(&m_context.Xmm5, reg_value.GetBytes(), 16);
574     break;
575   case lldb_xmm6_x86_64:
576     memcpy(&m_context.Xmm6, reg_value.GetBytes(), 16);
577     break;
578   case lldb_xmm7_x86_64:
579     memcpy(&m_context.Xmm7, reg_value.GetBytes(), 16);
580     break;
581   case lldb_xmm8_x86_64:
582     memcpy(&m_context.Xmm8, reg_value.GetBytes(), 16);
583     break;
584   case lldb_xmm9_x86_64:
585     memcpy(&m_context.Xmm9, reg_value.GetBytes(), 16);
586     break;
587   case lldb_xmm10_x86_64:
588     memcpy(&m_context.Xmm10, reg_value.GetBytes(), 16);
589     break;
590   case lldb_xmm11_x86_64:
591     memcpy(&m_context.Xmm11, reg_value.GetBytes(), 16);
592     break;
593   case lldb_xmm12_x86_64:
594     memcpy(&m_context.Xmm12, reg_value.GetBytes(), 16);
595     break;
596   case lldb_xmm13_x86_64:
597     memcpy(&m_context.Xmm13, reg_value.GetBytes(), 16);
598     break;
599   case lldb_xmm14_x86_64:
600     memcpy(&m_context.Xmm14, reg_value.GetBytes(), 16);
601     break;
602   case lldb_xmm15_x86_64:
603     memcpy(&m_context.Xmm15, reg_value.GetBytes(), 16);
604     break;
605   }
606 
607   // Physically update the registers in the target process.
608   return ApplyAllRegisterValues();
609 }
610 
611 #endif // defined(__x86_64__) || defined(_M_X64)
612