1 | /** @file
|
---|
2 | *
|
---|
3 | * VBox frontends: Basic Frontend (BFE):
|
---|
4 | * Implementation of MachineDebugger class
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2006-2007 Oracle Corporation
|
---|
9 | *
|
---|
10 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
11 | * available from http://www.virtualbox.org. This file is free software;
|
---|
12 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
13 | * General Public License (GPL) as published by the Free Software
|
---|
14 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
15 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
16 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
17 | */
|
---|
18 |
|
---|
19 | #ifdef VBOXBFE_WITHOUT_COM
|
---|
20 | # include "COMDefs.h"
|
---|
21 | #else
|
---|
22 | # include <VBox/com/defs.h>
|
---|
23 | #endif
|
---|
24 | #include <VBox/em.h>
|
---|
25 | #include <VBox/patm.h>
|
---|
26 | #include <VBox/csam.h>
|
---|
27 | #include <VBox/vm.h>
|
---|
28 | #include <VBox/err.h>
|
---|
29 | #include <VBox/log.h>
|
---|
30 | #include <iprt/semaphore.h>
|
---|
31 | #include <iprt/assert.h>
|
---|
32 |
|
---|
33 | #include "VBoxBFE.h"
|
---|
34 | #include "MachineDebuggerImpl.h"
|
---|
35 |
|
---|
36 | //
|
---|
37 | // defines
|
---|
38 | //
|
---|
39 |
|
---|
40 |
|
---|
41 | //
|
---|
42 | // globals
|
---|
43 | //
|
---|
44 |
|
---|
45 |
|
---|
46 | //
|
---|
47 | // public methods
|
---|
48 | //
|
---|
49 |
|
---|
50 | /**
|
---|
51 | * Initializes the machine debugger object.
|
---|
52 | *
|
---|
53 | * @returns COM result indicator
|
---|
54 | * @param parent handle of our parent object
|
---|
55 | */
|
---|
56 | MachineDebugger::MachineDebugger()
|
---|
57 | {
|
---|
58 | singlestepQueued = ~0;
|
---|
59 | recompileUserQueued = ~0;
|
---|
60 | recompileSupervisorQueued = ~0;
|
---|
61 | patmEnabledQueued = ~0;
|
---|
62 | csamEnabledQueued = ~0;
|
---|
63 | fFlushMode = false;
|
---|
64 | }
|
---|
65 |
|
---|
66 | /**
|
---|
67 | * Returns the current singlestepping flag.
|
---|
68 | *
|
---|
69 | * @returns COM status code
|
---|
70 | * @param enabled address of result variable
|
---|
71 | */
|
---|
72 | STDMETHODIMP MachineDebugger::COMGETTER(Singlestep)(BOOL *enabled)
|
---|
73 | {
|
---|
74 | if (!enabled)
|
---|
75 | return E_POINTER;
|
---|
76 | /** @todo */
|
---|
77 | return E_NOTIMPL;
|
---|
78 | }
|
---|
79 |
|
---|
80 | /**
|
---|
81 | * Sets the singlestepping flag.
|
---|
82 | *
|
---|
83 | * @returns COM status code
|
---|
84 | * @param enable new singlestepping flag
|
---|
85 | */
|
---|
86 | STDMETHODIMP MachineDebugger::COMSETTER(Singlestep)(BOOL enable)
|
---|
87 | {
|
---|
88 | /** @todo */
|
---|
89 | return E_NOTIMPL;
|
---|
90 | }
|
---|
91 |
|
---|
92 | /**
|
---|
93 | * Returns the current recompile user mode code flag.
|
---|
94 | *
|
---|
95 | * @returns COM status code
|
---|
96 | * @param enabled address of result variable
|
---|
97 | */
|
---|
98 | STDMETHODIMP MachineDebugger::COMGETTER(RecompileUser)(BOOL *enabled)
|
---|
99 | {
|
---|
100 | if (!enabled)
|
---|
101 | return E_POINTER;
|
---|
102 | if (gpVM)
|
---|
103 | *enabled = !EMIsRawRing3Enabled(gpVM);
|
---|
104 | else
|
---|
105 | *enabled = false;
|
---|
106 | return S_OK;
|
---|
107 | }
|
---|
108 |
|
---|
109 | /**
|
---|
110 | * Sets the recompile user mode code flag.
|
---|
111 | *
|
---|
112 | * @returns COM status
|
---|
113 | * @param enable new user mode code recompile flag.
|
---|
114 | */
|
---|
115 | STDMETHODIMP MachineDebugger::COMSETTER(RecompileUser)(BOOL enable)
|
---|
116 | {
|
---|
117 | LogFlow(("MachineDebugger:: set user mode recompiler to %d\n", enable));
|
---|
118 |
|
---|
119 | if (!fFlushMode)
|
---|
120 | {
|
---|
121 | // check if the machine is running
|
---|
122 | if (machineState != VMSTATE_RUNNING)
|
---|
123 | {
|
---|
124 | // queue the request
|
---|
125 | recompileUserQueued = enable;
|
---|
126 | return S_OK;
|
---|
127 | }
|
---|
128 | }
|
---|
129 | if (!gpVM)
|
---|
130 | {
|
---|
131 | return E_FAIL;
|
---|
132 | }
|
---|
133 |
|
---|
134 | EMRAWMODE rawModeFlag = enable ? EMRAW_RING3_DISABLE : EMRAW_RING3_ENABLE;
|
---|
135 | int rcVBox = VMR3ReqCallWait(gpVM, VMCPUID_ANY, (PFNRT)EMR3RawSetMode, 2, gpVM, rawModeFlag);
|
---|
136 | if (RT_SUCCESS(rcVBox))
|
---|
137 | return S_OK;
|
---|
138 |
|
---|
139 | AssertMsgFailed(("Could not set raw mode flags to %d, rcVBox = %Rrc\n",
|
---|
140 | rawModeFlag, rcVBox));
|
---|
141 | return E_FAIL;
|
---|
142 | }
|
---|
143 |
|
---|
144 | /**
|
---|
145 | * Returns the current recompile supervisor code flag.
|
---|
146 | *
|
---|
147 | * @returns COM status code
|
---|
148 | * @param enabled address of result variable
|
---|
149 | */
|
---|
150 | STDMETHODIMP MachineDebugger::COMGETTER(RecompileSupervisor)(BOOL *enabled)
|
---|
151 | {
|
---|
152 | if (!enabled)
|
---|
153 | return E_POINTER;
|
---|
154 | if (gpVM)
|
---|
155 | *enabled = !EMIsRawRing0Enabled(gpVM);
|
---|
156 | else
|
---|
157 | *enabled = false;
|
---|
158 | return S_OK;
|
---|
159 | }
|
---|
160 |
|
---|
161 | /**
|
---|
162 | * Sets the new recompile supervisor code flag.
|
---|
163 | *
|
---|
164 | * @returns COM status code
|
---|
165 | * @param enable new recompile supervisor code flag
|
---|
166 | */
|
---|
167 | STDMETHODIMP MachineDebugger::COMSETTER(RecompileSupervisor)(BOOL enable)
|
---|
168 | {
|
---|
169 | LogFlow(("MachineDebugger:: set supervisor mode recompiler to %d\n", enable));
|
---|
170 |
|
---|
171 | if (!fFlushMode)
|
---|
172 | {
|
---|
173 | // check if the machine is running
|
---|
174 | if (machineState != VMSTATE_RUNNING)
|
---|
175 | {
|
---|
176 | // queue the request
|
---|
177 | recompileSupervisorQueued = enable;
|
---|
178 | return S_OK;
|
---|
179 | }
|
---|
180 | }
|
---|
181 | if (!gpVM)
|
---|
182 | {
|
---|
183 | return E_FAIL;
|
---|
184 | }
|
---|
185 |
|
---|
186 | EMRAWMODE rawModeFlag = enable ? EMRAW_RING0_DISABLE : EMRAW_RING0_ENABLE;
|
---|
187 | int rcVBox = VMR3ReqCallWait(gpVM, VMCPUID_ANY, (PFNRT)EMR3RawSetMode, 2, gpVM, rawModeFlag);
|
---|
188 | if (RT_SUCCESS(rcVBox))
|
---|
189 | return S_OK;
|
---|
190 |
|
---|
191 | AssertMsgFailed(("Could not set raw mode flags to %d, rcVBox = %Rrc\n",
|
---|
192 | rawModeFlag, rcVBox));
|
---|
193 | return E_FAIL;
|
---|
194 | }
|
---|
195 |
|
---|
196 | /**
|
---|
197 | * Returns the current patch manager enabled flag.
|
---|
198 | *
|
---|
199 | * @returns COM status code
|
---|
200 | * @param enabled address of result variable
|
---|
201 | */
|
---|
202 | STDMETHODIMP MachineDebugger::COMGETTER(PATMEnabled)(BOOL *enabled)
|
---|
203 | {
|
---|
204 | if (!enabled)
|
---|
205 | return E_POINTER;
|
---|
206 | if (gpVM)
|
---|
207 | *enabled = PATMIsEnabled(gpVM);
|
---|
208 | else
|
---|
209 | *enabled = false;
|
---|
210 | return S_OK;
|
---|
211 | }
|
---|
212 |
|
---|
213 | /**
|
---|
214 | * Set the new patch manager enabled flag.
|
---|
215 | *
|
---|
216 | * @returns COM status code
|
---|
217 | * @param new patch manager enabled flag
|
---|
218 | */
|
---|
219 | STDMETHODIMP MachineDebugger::COMSETTER(PATMEnabled)(BOOL enable)
|
---|
220 | {
|
---|
221 | LogFlow(("MachineDebugger::SetPATMEnabled: %d\n", enable));
|
---|
222 |
|
---|
223 | if (!fFlushMode)
|
---|
224 | {
|
---|
225 | // check if the machine is running
|
---|
226 | if (machineState != VMSTATE_RUNNING)
|
---|
227 | {
|
---|
228 | // queue the request
|
---|
229 | patmEnabledQueued = enable;
|
---|
230 | return S_OK;
|
---|
231 | }
|
---|
232 | }
|
---|
233 |
|
---|
234 | if (!gpVM)
|
---|
235 | return E_FAIL;
|
---|
236 |
|
---|
237 | PATMR3AllowPatching(gpVM, enable);
|
---|
238 | return E_NOTIMPL;
|
---|
239 | }
|
---|
240 |
|
---|
241 | /**
|
---|
242 | * Returns the current code scanner enabled flag.
|
---|
243 | *
|
---|
244 | * @returns COM status code
|
---|
245 | * @param enabled address of result variable
|
---|
246 | */
|
---|
247 | STDMETHODIMP MachineDebugger::COMGETTER(CSAMEnabled)(BOOL *enabled)
|
---|
248 | {
|
---|
249 | if (!enabled)
|
---|
250 | return E_POINTER;
|
---|
251 | if (gpVM)
|
---|
252 | *enabled = CSAMIsEnabled(gpVM);
|
---|
253 | else
|
---|
254 | *enabled = false;
|
---|
255 | return S_OK;
|
---|
256 | }
|
---|
257 |
|
---|
258 | /**
|
---|
259 | * Sets the new code scanner enabled flag.
|
---|
260 | *
|
---|
261 | * @returns COM status code
|
---|
262 | * @param enable new code scanner enabled flag
|
---|
263 | */
|
---|
264 | STDMETHODIMP MachineDebugger::COMSETTER(CSAMEnabled)(BOOL enable)
|
---|
265 | {
|
---|
266 | LogFlow(("MachineDebugger:SetCSAMEnabled: %d\n", enable));
|
---|
267 |
|
---|
268 | if (!fFlushMode)
|
---|
269 | {
|
---|
270 | // check if the machine is running
|
---|
271 | if (machineState != VMSTATE_RUNNING)
|
---|
272 | {
|
---|
273 | // queue the request
|
---|
274 | csamEnabledQueued = enable;
|
---|
275 | return S_OK;
|
---|
276 | }
|
---|
277 | }
|
---|
278 |
|
---|
279 | if (!gpVM)
|
---|
280 | return E_FAIL;
|
---|
281 |
|
---|
282 | if (enable)
|
---|
283 | CSAMEnableScanning(gpVM);
|
---|
284 | else
|
---|
285 | CSAMDisableScanning(gpVM);
|
---|
286 | return E_NOTIMPL;
|
---|
287 | }
|
---|
288 |
|
---|
289 | //
|
---|
290 | // "public-private" methods
|
---|
291 | //
|
---|
292 | void MachineDebugger::flushQueuedSettings()
|
---|
293 | {
|
---|
294 | fFlushMode = true;
|
---|
295 | if (singlestepQueued != ~0)
|
---|
296 | {
|
---|
297 | COMSETTER(Singlestep)(singlestepQueued);
|
---|
298 | singlestepQueued = ~0;
|
---|
299 | }
|
---|
300 | if (recompileUserQueued != ~0)
|
---|
301 | {
|
---|
302 | COMSETTER(RecompileUser)(recompileUserQueued);
|
---|
303 | recompileUserQueued = ~0;
|
---|
304 | }
|
---|
305 | if (recompileSupervisorQueued != ~0)
|
---|
306 | {
|
---|
307 | COMSETTER(RecompileSupervisor)(recompileSupervisorQueued);
|
---|
308 | recompileSupervisorQueued = ~0;
|
---|
309 | }
|
---|
310 | if (patmEnabledQueued != ~0)
|
---|
311 | {
|
---|
312 | COMSETTER(PATMEnabled)(patmEnabledQueued);
|
---|
313 | patmEnabledQueued = ~0;
|
---|
314 | }
|
---|
315 | if (csamEnabledQueued != ~0)
|
---|
316 | {
|
---|
317 | COMSETTER(CSAMEnabled)(csamEnabledQueued);
|
---|
318 | csamEnabledQueued = ~0;
|
---|
319 | }
|
---|
320 | fFlushMode = false;
|
---|
321 | }
|
---|
322 |
|
---|
323 | //
|
---|
324 | // private methods
|
---|
325 | //
|
---|