]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - source/Plugins/Process/Windows/Live/x64/RegisterContextWindowsLive_x64.cpp
Vendor import of lldb trunk r256945:
[FreeBSD/FreeBSD.git] / source / Plugins / Process / Windows / Live / x64 / RegisterContextWindowsLive_x64.cpp
1 //===-- RegisterContextWindowsLive_x64.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 "RegisterContextWindowsLive_x64.h"
18 #include "TargetThreadWindows.h"
19
20 #include "llvm/ADT/STLExtras.h"
21
22 using namespace lldb;
23 using namespace lldb_private;
24
25 RegisterContextWindowsLive_x64::RegisterContextWindowsLive_x64(Thread &thread, uint32_t concrete_frame_idx)
26     : RegisterContextWindows_x64(thread, concrete_frame_idx)
27 {
28 }
29
30 RegisterContextWindowsLive_x64::~RegisterContextWindowsLive_x64()
31 {
32 }
33
34
35 bool
36 RegisterContextWindowsLive_x64::ReadRegister(const RegisterInfo *reg_info, RegisterValue &reg_value)
37 {
38     if (!CacheAllRegisterValues())
39         return false;
40
41     switch (reg_info->kinds[eRegisterKindLLDB])
42     {
43         case lldb_rax_x86_64:
44             reg_value.SetUInt64(m_context.Rax);
45             break;
46         case lldb_rbx_x86_64:
47             reg_value.SetUInt64(m_context.Rbx);
48             break;
49         case lldb_rcx_x86_64:
50             reg_value.SetUInt64(m_context.Rcx);
51             break;
52         case lldb_rdx_x86_64:
53             reg_value.SetUInt64(m_context.Rdx);
54             break;
55         case lldb_rdi_x86_64:
56             reg_value.SetUInt64(m_context.Rdi);
57             break;
58         case lldb_rsi_x86_64:
59             reg_value.SetUInt64(m_context.Rsi);
60             break;
61         case lldb_r8_x86_64:
62             reg_value.SetUInt64(m_context.R8);
63             break;
64         case lldb_r9_x86_64:
65             reg_value.SetUInt64(m_context.R9);
66             break;
67         case lldb_r10_x86_64:
68             reg_value.SetUInt64(m_context.R10);
69             break;
70         case lldb_r11_x86_64:
71             reg_value.SetUInt64(m_context.R11);
72             break;
73         case lldb_r12_x86_64:
74             reg_value.SetUInt64(m_context.R12);
75             break;
76         case lldb_r13_x86_64:
77             reg_value.SetUInt64(m_context.R13);
78             break;
79         case lldb_r14_x86_64:
80             reg_value.SetUInt64(m_context.R14);
81             break;
82         case lldb_r15_x86_64:
83             reg_value.SetUInt64(m_context.R15);
84             break;
85         case lldb_rbp_x86_64:
86             reg_value.SetUInt64(m_context.Rbp);
87             break;
88         case lldb_rsp_x86_64:
89             reg_value.SetUInt64(m_context.Rsp);
90             break;
91         case lldb_rip_x86_64:
92             reg_value.SetUInt64(m_context.Rip);
93             break;
94         case lldb_rflags_x86_64:
95             reg_value.SetUInt64(m_context.EFlags);
96             break;
97     }
98     return true;
99 }
100
101 bool
102 RegisterContextWindowsLive_x64::WriteRegister(const RegisterInfo *reg_info, const RegisterValue &reg_value)
103 {
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())
108         return false;
109
110     switch (reg_info->kinds[eRegisterKindLLDB])
111     {
112         case lldb_rax_x86_64:
113             m_context.Rax = reg_value.GetAsUInt64();
114             break;
115         case lldb_rbx_x86_64:
116             m_context.Rbx = reg_value.GetAsUInt64();
117             break;
118         case lldb_rcx_x86_64:
119             m_context.Rcx = reg_value.GetAsUInt64();
120             break;
121         case lldb_rdx_x86_64:
122             m_context.Rdx = reg_value.GetAsUInt64();
123             break;
124         case lldb_rdi_x86_64:
125             m_context.Rdi = reg_value.GetAsUInt64();
126             break;
127         case lldb_rsi_x86_64:
128             m_context.Rsi = reg_value.GetAsUInt64();
129             break;
130         case lldb_r8_x86_64:
131             m_context.R8 = reg_value.GetAsUInt64();
132             break;
133         case lldb_r9_x86_64:
134             m_context.R9 = reg_value.GetAsUInt64();
135             break;
136         case lldb_r10_x86_64:
137             m_context.R10 = reg_value.GetAsUInt64();
138             break;
139         case lldb_r11_x86_64:
140             m_context.R11 = reg_value.GetAsUInt64();
141             break;
142         case lldb_r12_x86_64:
143             m_context.R12 = reg_value.GetAsUInt64();
144             break;
145         case lldb_r13_x86_64:
146             m_context.R13 = reg_value.GetAsUInt64();
147             break;
148         case lldb_r14_x86_64:
149             m_context.R14 = reg_value.GetAsUInt64();
150             break;
151         case lldb_r15_x86_64:
152             m_context.R15 = reg_value.GetAsUInt64();
153             break;
154         case lldb_rbp_x86_64:
155             m_context.Rbp = reg_value.GetAsUInt64();
156             break;
157         case lldb_rsp_x86_64:
158             m_context.Rsp = reg_value.GetAsUInt64();
159             break;
160         case lldb_rip_x86_64:
161             m_context.Rip = reg_value.GetAsUInt64();
162             break;
163         case lldb_rflags_x86_64:
164             m_context.EFlags = reg_value.GetAsUInt64();
165             break;
166     }
167
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);
171 }