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