1 | /* $Id: MachineDebuggerImpl.cpp 26154 2010-02-02 16:09:14Z vboxsync $ */
|
---|
2 |
|
---|
3 | /** @file
|
---|
4 | *
|
---|
5 | * VirtualBox COM class implementation
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * Copyright (C) 2006-2008 Sun Microsystems, Inc.
|
---|
10 | *
|
---|
11 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
12 | * available from http://www.virtualbox.org. This file is free software;
|
---|
13 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
14 | * General Public License (GPL) as published by the Free Software
|
---|
15 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
16 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
17 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
18 | *
|
---|
19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
20 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
21 | * additional information or have any questions.
|
---|
22 | */
|
---|
23 |
|
---|
24 | #include "MachineDebuggerImpl.h"
|
---|
25 |
|
---|
26 | #include "Global.h"
|
---|
27 | #include "ConsoleImpl.h"
|
---|
28 |
|
---|
29 | #include "AutoCaller.h"
|
---|
30 | #include "Logging.h"
|
---|
31 |
|
---|
32 | #include <VBox/em.h>
|
---|
33 | #include <VBox/patm.h>
|
---|
34 | #include <VBox/csam.h>
|
---|
35 | #include <VBox/vm.h>
|
---|
36 | #include <VBox/tm.h>
|
---|
37 | #include <VBox/err.h>
|
---|
38 | #include <VBox/hwaccm.h>
|
---|
39 |
|
---|
40 | // defines
|
---|
41 | /////////////////////////////////////////////////////////////////////////////
|
---|
42 |
|
---|
43 |
|
---|
44 | // globals
|
---|
45 | /////////////////////////////////////////////////////////////////////////////
|
---|
46 |
|
---|
47 |
|
---|
48 | // constructor / destructor
|
---|
49 | /////////////////////////////////////////////////////////////////////////////
|
---|
50 |
|
---|
51 | DEFINE_EMPTY_CTOR_DTOR (MachineDebugger)
|
---|
52 |
|
---|
53 | HRESULT MachineDebugger::FinalConstruct()
|
---|
54 | {
|
---|
55 | unconst(mParent) = NULL;
|
---|
56 | return S_OK;
|
---|
57 | }
|
---|
58 |
|
---|
59 | void MachineDebugger::FinalRelease()
|
---|
60 | {
|
---|
61 | uninit();
|
---|
62 | }
|
---|
63 |
|
---|
64 | // public initializer/uninitializer for internal purposes only
|
---|
65 | /////////////////////////////////////////////////////////////////////////////
|
---|
66 |
|
---|
67 | /**
|
---|
68 | * Initializes the machine debugger object.
|
---|
69 | *
|
---|
70 | * @returns COM result indicator
|
---|
71 | * @param aParent handle of our parent object
|
---|
72 | */
|
---|
73 | HRESULT MachineDebugger::init (Console *aParent)
|
---|
74 | {
|
---|
75 | LogFlowThisFunc(("aParent=%p\n", aParent));
|
---|
76 |
|
---|
77 | ComAssertRet (aParent, E_INVALIDARG);
|
---|
78 |
|
---|
79 | /* Enclose the state transition NotReady->InInit->Ready */
|
---|
80 | AutoInitSpan autoInitSpan(this);
|
---|
81 | AssertReturn(autoInitSpan.isOk(), E_FAIL);
|
---|
82 |
|
---|
83 | unconst(mParent) = aParent;
|
---|
84 |
|
---|
85 | mSinglestepQueued = ~0;
|
---|
86 | mRecompileUserQueued = ~0;
|
---|
87 | mRecompileSupervisorQueued = ~0;
|
---|
88 | mPatmEnabledQueued = ~0;
|
---|
89 | mCsamEnabledQueued = ~0;
|
---|
90 | mLogEnabledQueued = ~0;
|
---|
91 | mVirtualTimeRateQueued = ~0;
|
---|
92 | mFlushMode = false;
|
---|
93 |
|
---|
94 | /* Confirm a successful initialization */
|
---|
95 | autoInitSpan.setSucceeded();
|
---|
96 |
|
---|
97 | return S_OK;
|
---|
98 | }
|
---|
99 |
|
---|
100 | /**
|
---|
101 | * Uninitializes the instance and sets the ready flag to FALSE.
|
---|
102 | * Called either from FinalRelease() or by the parent when it gets destroyed.
|
---|
103 | */
|
---|
104 | void MachineDebugger::uninit()
|
---|
105 | {
|
---|
106 | LogFlowThisFunc(("\n"));
|
---|
107 |
|
---|
108 | /* Enclose the state transition Ready->InUninit->NotReady */
|
---|
109 | AutoUninitSpan autoUninitSpan(this);
|
---|
110 | if (autoUninitSpan.uninitDone())
|
---|
111 | return;
|
---|
112 |
|
---|
113 | unconst(mParent).setNull();
|
---|
114 | mFlushMode = false;
|
---|
115 | }
|
---|
116 |
|
---|
117 | // IMachineDebugger properties
|
---|
118 | /////////////////////////////////////////////////////////////////////////////
|
---|
119 |
|
---|
120 | /**
|
---|
121 | * Returns the current singlestepping flag.
|
---|
122 | *
|
---|
123 | * @returns COM status code
|
---|
124 | * @param aEnabled address of result variable
|
---|
125 | */
|
---|
126 | STDMETHODIMP MachineDebugger::COMGETTER(Singlestep) (BOOL *aEnabled)
|
---|
127 | {
|
---|
128 | CheckComArgOutPointerValid(aEnabled);
|
---|
129 |
|
---|
130 | AutoCaller autoCaller(this);
|
---|
131 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
132 |
|
---|
133 | /** @todo */
|
---|
134 | ReturnComNotImplemented();
|
---|
135 | }
|
---|
136 |
|
---|
137 | /**
|
---|
138 | * Sets the singlestepping flag.
|
---|
139 | *
|
---|
140 | * @returns COM status code
|
---|
141 | * @param aEnable new singlestepping flag
|
---|
142 | */
|
---|
143 | STDMETHODIMP MachineDebugger::COMSETTER(Singlestep) (BOOL aEnable)
|
---|
144 | {
|
---|
145 | AutoCaller autoCaller(this);
|
---|
146 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
147 |
|
---|
148 | /** @todo */
|
---|
149 | ReturnComNotImplemented();
|
---|
150 | }
|
---|
151 |
|
---|
152 | /**
|
---|
153 | * Returns the current recompile user mode code flag.
|
---|
154 | *
|
---|
155 | * @returns COM status code
|
---|
156 | * @param aEnabled address of result variable
|
---|
157 | */
|
---|
158 | STDMETHODIMP MachineDebugger::COMGETTER(RecompileUser) (BOOL *aEnabled)
|
---|
159 | {
|
---|
160 | CheckComArgOutPointerValid(aEnabled);
|
---|
161 |
|
---|
162 | AutoCaller autoCaller(this);
|
---|
163 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
164 |
|
---|
165 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
166 |
|
---|
167 | Console::SafeVMPtrQuiet pVM (mParent);
|
---|
168 |
|
---|
169 | if (pVM.isOk())
|
---|
170 | *aEnabled = !EMIsRawRing3Enabled (pVM.raw());
|
---|
171 | else
|
---|
172 | *aEnabled = false;
|
---|
173 |
|
---|
174 | return S_OK;
|
---|
175 | }
|
---|
176 |
|
---|
177 | /**
|
---|
178 | * Sets the recompile user mode code flag.
|
---|
179 | *
|
---|
180 | * @returns COM status
|
---|
181 | * @param aEnable new user mode code recompile flag.
|
---|
182 | */
|
---|
183 | STDMETHODIMP MachineDebugger::COMSETTER(RecompileUser) (BOOL aEnable)
|
---|
184 | {
|
---|
185 | LogFlowThisFunc(("enable=%d\n", aEnable));
|
---|
186 |
|
---|
187 | AutoCaller autoCaller(this);
|
---|
188 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
189 |
|
---|
190 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
191 |
|
---|
192 | if (queueSettings())
|
---|
193 | {
|
---|
194 | // queue the request
|
---|
195 | mRecompileUserQueued = aEnable;
|
---|
196 | return S_OK;
|
---|
197 | }
|
---|
198 |
|
---|
199 | Console::SafeVMPtr pVM (mParent);
|
---|
200 | if (FAILED(pVM.rc())) return pVM.rc();
|
---|
201 |
|
---|
202 | EMRAWMODE rawModeFlag = aEnable ? EMRAW_RING3_DISABLE : EMRAW_RING3_ENABLE;
|
---|
203 | int rcVBox = VMR3ReqCallWait(pVM, VMCPUID_ANY, (PFNRT)EMR3RawSetMode, 2, pVM.raw(), rawModeFlag);
|
---|
204 | if (RT_SUCCESS(rcVBox))
|
---|
205 | return S_OK;
|
---|
206 |
|
---|
207 | AssertMsgFailed (("Could not set raw mode flags to %d, rcVBox = %Rrc\n",
|
---|
208 | rawModeFlag, rcVBox));
|
---|
209 | return E_FAIL;
|
---|
210 | }
|
---|
211 |
|
---|
212 | /**
|
---|
213 | * Returns the current recompile supervisor code flag.
|
---|
214 | *
|
---|
215 | * @returns COM status code
|
---|
216 | * @param aEnabled address of result variable
|
---|
217 | */
|
---|
218 | STDMETHODIMP MachineDebugger::COMGETTER(RecompileSupervisor) (BOOL *aEnabled)
|
---|
219 | {
|
---|
220 | CheckComArgOutPointerValid(aEnabled);
|
---|
221 |
|
---|
222 | AutoCaller autoCaller(this);
|
---|
223 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
224 |
|
---|
225 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
226 |
|
---|
227 | Console::SafeVMPtrQuiet pVM (mParent);
|
---|
228 |
|
---|
229 | if (pVM.isOk())
|
---|
230 | *aEnabled = !EMIsRawRing0Enabled (pVM.raw());
|
---|
231 | else
|
---|
232 | *aEnabled = false;
|
---|
233 |
|
---|
234 | return S_OK;
|
---|
235 | }
|
---|
236 |
|
---|
237 | /**
|
---|
238 | * Sets the new recompile supervisor code flag.
|
---|
239 | *
|
---|
240 | * @returns COM status code
|
---|
241 | * @param aEnable new recompile supervisor code flag
|
---|
242 | */
|
---|
243 | STDMETHODIMP MachineDebugger::COMSETTER(RecompileSupervisor) (BOOL aEnable)
|
---|
244 | {
|
---|
245 | LogFlowThisFunc(("enable=%d\n", aEnable));
|
---|
246 |
|
---|
247 | AutoCaller autoCaller(this);
|
---|
248 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
249 |
|
---|
250 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
251 |
|
---|
252 | if (queueSettings())
|
---|
253 | {
|
---|
254 | // queue the request
|
---|
255 | mRecompileSupervisorQueued = aEnable;
|
---|
256 | return S_OK;
|
---|
257 | }
|
---|
258 |
|
---|
259 | Console::SafeVMPtr pVM (mParent);
|
---|
260 | if (FAILED(pVM.rc())) return pVM.rc();
|
---|
261 |
|
---|
262 | EMRAWMODE rawModeFlag = aEnable ? EMRAW_RING0_DISABLE : EMRAW_RING0_ENABLE;
|
---|
263 | int rcVBox = VMR3ReqCallWait(pVM, VMCPUID_ANY, (PFNRT)EMR3RawSetMode, 2, pVM.raw(), rawModeFlag);
|
---|
264 | if (RT_SUCCESS(rcVBox))
|
---|
265 | return S_OK;
|
---|
266 |
|
---|
267 | AssertMsgFailed (("Could not set raw mode flags to %d, rcVBox = %Rrc\n",
|
---|
268 | rawModeFlag, rcVBox));
|
---|
269 | return E_FAIL;
|
---|
270 | }
|
---|
271 |
|
---|
272 | /**
|
---|
273 | * Returns the current patch manager enabled flag.
|
---|
274 | *
|
---|
275 | * @returns COM status code
|
---|
276 | * @param aEnabled address of result variable
|
---|
277 | */
|
---|
278 | STDMETHODIMP MachineDebugger::COMGETTER(PATMEnabled) (BOOL *aEnabled)
|
---|
279 | {
|
---|
280 | CheckComArgOutPointerValid(aEnabled);
|
---|
281 |
|
---|
282 | AutoCaller autoCaller(this);
|
---|
283 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
284 |
|
---|
285 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
286 |
|
---|
287 | Console::SafeVMPtrQuiet pVM (mParent);
|
---|
288 |
|
---|
289 | if (pVM.isOk())
|
---|
290 | *aEnabled = PATMIsEnabled (pVM.raw());
|
---|
291 | else
|
---|
292 | *aEnabled = false;
|
---|
293 |
|
---|
294 | return S_OK;
|
---|
295 | }
|
---|
296 |
|
---|
297 | /**
|
---|
298 | * Set the new patch manager enabled flag.
|
---|
299 | *
|
---|
300 | * @returns COM status code
|
---|
301 | * @param aEnable new patch manager enabled flag
|
---|
302 | */
|
---|
303 | STDMETHODIMP MachineDebugger::COMSETTER(PATMEnabled) (BOOL aEnable)
|
---|
304 | {
|
---|
305 | LogFlowThisFunc(("enable=%d\n", aEnable));
|
---|
306 |
|
---|
307 | AutoCaller autoCaller(this);
|
---|
308 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
309 |
|
---|
310 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
311 |
|
---|
312 | if (queueSettings())
|
---|
313 | {
|
---|
314 | // queue the request
|
---|
315 | mPatmEnabledQueued = aEnable;
|
---|
316 | return S_OK;
|
---|
317 | }
|
---|
318 |
|
---|
319 | Console::SafeVMPtr pVM(mParent);
|
---|
320 | if (FAILED(pVM.rc())) return pVM.rc();
|
---|
321 |
|
---|
322 | PATMR3AllowPatching (pVM, aEnable);
|
---|
323 |
|
---|
324 | return S_OK;
|
---|
325 | }
|
---|
326 |
|
---|
327 | /**
|
---|
328 | * Returns the current code scanner enabled flag.
|
---|
329 | *
|
---|
330 | * @returns COM status code
|
---|
331 | * @param aEnabled address of result variable
|
---|
332 | */
|
---|
333 | STDMETHODIMP MachineDebugger::COMGETTER(CSAMEnabled) (BOOL *aEnabled)
|
---|
334 | {
|
---|
335 | CheckComArgOutPointerValid(aEnabled);
|
---|
336 |
|
---|
337 | AutoCaller autoCaller(this);
|
---|
338 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
339 |
|
---|
340 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
341 |
|
---|
342 | Console::SafeVMPtrQuiet pVM (mParent);
|
---|
343 |
|
---|
344 | if (pVM.isOk())
|
---|
345 | *aEnabled = CSAMIsEnabled (pVM.raw());
|
---|
346 | else
|
---|
347 | *aEnabled = false;
|
---|
348 |
|
---|
349 | return S_OK;
|
---|
350 | }
|
---|
351 |
|
---|
352 | /**
|
---|
353 | * Sets the new code scanner enabled flag.
|
---|
354 | *
|
---|
355 | * @returns COM status code
|
---|
356 | * @param aEnable new code scanner enabled flag
|
---|
357 | */
|
---|
358 | STDMETHODIMP MachineDebugger::COMSETTER(CSAMEnabled) (BOOL aEnable)
|
---|
359 | {
|
---|
360 | LogFlowThisFunc(("enable=%d\n", aEnable));
|
---|
361 |
|
---|
362 | AutoCaller autoCaller(this);
|
---|
363 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
364 |
|
---|
365 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
366 |
|
---|
367 | if (queueSettings())
|
---|
368 | {
|
---|
369 | // queue the request
|
---|
370 | mCsamEnabledQueued = aEnable;
|
---|
371 | return S_OK;
|
---|
372 | }
|
---|
373 |
|
---|
374 | Console::SafeVMPtr pVM(mParent);
|
---|
375 | if (FAILED(pVM.rc())) return pVM.rc();
|
---|
376 |
|
---|
377 | int vrc;
|
---|
378 | if (aEnable)
|
---|
379 | vrc = CSAMEnableScanning (pVM);
|
---|
380 | else
|
---|
381 | vrc = CSAMDisableScanning (pVM);
|
---|
382 |
|
---|
383 | if (RT_FAILURE(vrc))
|
---|
384 | {
|
---|
385 | /** @todo handle error case */
|
---|
386 | }
|
---|
387 |
|
---|
388 | return S_OK;
|
---|
389 | }
|
---|
390 |
|
---|
391 | /**
|
---|
392 | * Returns the log enabled / disabled status.
|
---|
393 | *
|
---|
394 | * @returns COM status code
|
---|
395 | * @param aEnabled address of result variable
|
---|
396 | */
|
---|
397 | STDMETHODIMP MachineDebugger::COMGETTER(LogEnabled) (BOOL *aEnabled)
|
---|
398 | {
|
---|
399 | CheckComArgOutPointerValid(aEnabled);
|
---|
400 |
|
---|
401 | AutoCaller autoCaller(this);
|
---|
402 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
403 |
|
---|
404 | #ifdef LOG_ENABLED
|
---|
405 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
406 |
|
---|
407 | const PRTLOGGER pLogInstance = RTLogDefaultInstance();
|
---|
408 | *aEnabled = pLogInstance && !(pLogInstance->fFlags & RTLOGFLAGS_DISABLED);
|
---|
409 | #else
|
---|
410 | *aEnabled = false;
|
---|
411 | #endif
|
---|
412 |
|
---|
413 | return S_OK;
|
---|
414 | }
|
---|
415 |
|
---|
416 | /**
|
---|
417 | * Enables or disables logging.
|
---|
418 | *
|
---|
419 | * @returns COM status code
|
---|
420 | * @param aEnabled The new code log state.
|
---|
421 | */
|
---|
422 | STDMETHODIMP MachineDebugger::COMSETTER(LogEnabled) (BOOL aEnabled)
|
---|
423 | {
|
---|
424 | LogFlowThisFunc(("aEnabled=%d\n", aEnabled));
|
---|
425 |
|
---|
426 | AutoCaller autoCaller(this);
|
---|
427 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
428 |
|
---|
429 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
430 |
|
---|
431 | if (queueSettings())
|
---|
432 | {
|
---|
433 | // queue the request
|
---|
434 | mLogEnabledQueued = aEnabled;
|
---|
435 | return S_OK;
|
---|
436 | }
|
---|
437 |
|
---|
438 | Console::SafeVMPtr pVM(mParent);
|
---|
439 | if (FAILED(pVM.rc())) return pVM.rc();
|
---|
440 |
|
---|
441 | #ifdef LOG_ENABLED
|
---|
442 | int vrc = DBGFR3LogModifyFlags (pVM, aEnabled ? "enabled" : "disabled");
|
---|
443 | if (RT_FAILURE(vrc))
|
---|
444 | {
|
---|
445 | /** @todo handle error code. */
|
---|
446 | }
|
---|
447 | #endif
|
---|
448 |
|
---|
449 | return S_OK;
|
---|
450 | }
|
---|
451 |
|
---|
452 | /**
|
---|
453 | * Returns the current hardware virtualization flag.
|
---|
454 | *
|
---|
455 | * @returns COM status code
|
---|
456 | * @param aEnabled address of result variable
|
---|
457 | */
|
---|
458 | STDMETHODIMP MachineDebugger::COMGETTER(HWVirtExEnabled) (BOOL *aEnabled)
|
---|
459 | {
|
---|
460 | CheckComArgOutPointerValid(aEnabled);
|
---|
461 |
|
---|
462 | AutoCaller autoCaller(this);
|
---|
463 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
464 |
|
---|
465 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
466 |
|
---|
467 | Console::SafeVMPtrQuiet pVM (mParent);
|
---|
468 |
|
---|
469 | if (pVM.isOk())
|
---|
470 | *aEnabled = HWACCMIsEnabled (pVM.raw());
|
---|
471 | else
|
---|
472 | *aEnabled = false;
|
---|
473 |
|
---|
474 | return S_OK;
|
---|
475 | }
|
---|
476 |
|
---|
477 | /**
|
---|
478 | * Returns the current nested paging flag.
|
---|
479 | *
|
---|
480 | * @returns COM status code
|
---|
481 | * @param aEnabled address of result variable
|
---|
482 | */
|
---|
483 | STDMETHODIMP MachineDebugger::COMGETTER(HWVirtExNestedPagingEnabled) (BOOL *aEnabled)
|
---|
484 | {
|
---|
485 | CheckComArgOutPointerValid(aEnabled);
|
---|
486 |
|
---|
487 | AutoCaller autoCaller(this);
|
---|
488 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
489 |
|
---|
490 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
491 |
|
---|
492 | Console::SafeVMPtrQuiet pVM (mParent);
|
---|
493 |
|
---|
494 | if (pVM.isOk())
|
---|
495 | *aEnabled = HWACCMR3IsNestedPagingActive (pVM.raw());
|
---|
496 | else
|
---|
497 | *aEnabled = false;
|
---|
498 |
|
---|
499 | return S_OK;
|
---|
500 | }
|
---|
501 |
|
---|
502 | /**
|
---|
503 | * Returns the current VPID flag.
|
---|
504 | *
|
---|
505 | * @returns COM status code
|
---|
506 | * @param aEnabled address of result variable
|
---|
507 | */
|
---|
508 | STDMETHODIMP MachineDebugger::COMGETTER(HWVirtExVPIDEnabled) (BOOL *aEnabled)
|
---|
509 | {
|
---|
510 | CheckComArgOutPointerValid(aEnabled);
|
---|
511 |
|
---|
512 | AutoCaller autoCaller(this);
|
---|
513 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
514 |
|
---|
515 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
516 |
|
---|
517 | Console::SafeVMPtrQuiet pVM (mParent);
|
---|
518 |
|
---|
519 | if (pVM.isOk())
|
---|
520 | *aEnabled = HWACCMR3IsVPIDActive (pVM.raw());
|
---|
521 | else
|
---|
522 | *aEnabled = false;
|
---|
523 |
|
---|
524 | return S_OK;
|
---|
525 | }
|
---|
526 |
|
---|
527 | /**
|
---|
528 | * Returns the current PAE flag.
|
---|
529 | *
|
---|
530 | * @returns COM status code
|
---|
531 | * @param aEnabled address of result variable
|
---|
532 | */
|
---|
533 | STDMETHODIMP MachineDebugger::COMGETTER(PAEEnabled) (BOOL *aEnabled)
|
---|
534 | {
|
---|
535 | CheckComArgOutPointerValid(aEnabled);
|
---|
536 |
|
---|
537 | AutoCaller autoCaller(this);
|
---|
538 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
539 |
|
---|
540 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
541 |
|
---|
542 | Console::SafeVMPtrQuiet pVM (mParent);
|
---|
543 |
|
---|
544 | if (pVM.isOk())
|
---|
545 | {
|
---|
546 | uint64_t cr4 = CPUMGetGuestCR4 (VMMGetCpu0(pVM.raw()));
|
---|
547 | *aEnabled = !!(cr4 & X86_CR4_PAE);
|
---|
548 | }
|
---|
549 | else
|
---|
550 | *aEnabled = false;
|
---|
551 |
|
---|
552 | return S_OK;
|
---|
553 | }
|
---|
554 |
|
---|
555 | /**
|
---|
556 | * Returns the current virtual time rate.
|
---|
557 | *
|
---|
558 | * @returns COM status code.
|
---|
559 | * @param aPct Where to store the rate.
|
---|
560 | */
|
---|
561 | STDMETHODIMP MachineDebugger::COMGETTER(VirtualTimeRate) (ULONG *aPct)
|
---|
562 | {
|
---|
563 | CheckComArgOutPointerValid(aPct);
|
---|
564 |
|
---|
565 | AutoCaller autoCaller(this);
|
---|
566 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
567 |
|
---|
568 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
569 |
|
---|
570 | Console::SafeVMPtrQuiet pVM (mParent);
|
---|
571 |
|
---|
572 | if (pVM.isOk())
|
---|
573 | *aPct = TMGetWarpDrive (pVM);
|
---|
574 | else
|
---|
575 | *aPct = 100;
|
---|
576 |
|
---|
577 | return S_OK;
|
---|
578 | }
|
---|
579 |
|
---|
580 | /**
|
---|
581 | * Returns the current virtual time rate.
|
---|
582 | *
|
---|
583 | * @returns COM status code.
|
---|
584 | * @param aPct Where to store the rate.
|
---|
585 | */
|
---|
586 | STDMETHODIMP MachineDebugger::COMSETTER(VirtualTimeRate) (ULONG aPct)
|
---|
587 | {
|
---|
588 | if (aPct < 2 || aPct > 20000)
|
---|
589 | return E_INVALIDARG;
|
---|
590 |
|
---|
591 | AutoCaller autoCaller(this);
|
---|
592 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
593 |
|
---|
594 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
595 |
|
---|
596 | if (queueSettings())
|
---|
597 | {
|
---|
598 | // queue the request
|
---|
599 | mVirtualTimeRateQueued = aPct;
|
---|
600 | return S_OK;
|
---|
601 | }
|
---|
602 |
|
---|
603 | Console::SafeVMPtr pVM(mParent);
|
---|
604 | if (FAILED(pVM.rc())) return pVM.rc();
|
---|
605 |
|
---|
606 | int vrc = TMR3SetWarpDrive (pVM, aPct);
|
---|
607 | if (RT_FAILURE(vrc))
|
---|
608 | {
|
---|
609 | /** @todo handle error code. */
|
---|
610 | }
|
---|
611 |
|
---|
612 | return S_OK;
|
---|
613 | }
|
---|
614 |
|
---|
615 | /**
|
---|
616 | * Hack for getting the VM handle.
|
---|
617 | * This is only temporary (promise) while prototyping the debugger.
|
---|
618 | *
|
---|
619 | * @returns COM status code
|
---|
620 | * @param aVm Where to store the vm handle.
|
---|
621 | * Since there is no uintptr_t in COM, we're using the max integer.
|
---|
622 | * (No, ULONG is not pointer sized!)
|
---|
623 | */
|
---|
624 | STDMETHODIMP MachineDebugger::COMGETTER(VM) (ULONG64 *aVm)
|
---|
625 | {
|
---|
626 | CheckComArgOutPointerValid(aVm);
|
---|
627 |
|
---|
628 | AutoCaller autoCaller(this);
|
---|
629 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
630 |
|
---|
631 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
632 |
|
---|
633 | Console::SafeVMPtr pVM(mParent);
|
---|
634 | if (FAILED(pVM.rc())) return pVM.rc();
|
---|
635 |
|
---|
636 | *aVm = (uintptr_t)pVM.raw();
|
---|
637 |
|
---|
638 | /*
|
---|
639 | * Note: pVM protection provided by SafeVMPtr is no more effective
|
---|
640 | * after we return from this method.
|
---|
641 | */
|
---|
642 |
|
---|
643 | return S_OK;
|
---|
644 | }
|
---|
645 |
|
---|
646 | // IMachineDebugger methods
|
---|
647 | /////////////////////////////////////////////////////////////////////////////
|
---|
648 |
|
---|
649 | /**
|
---|
650 | * Resets VM statistics.
|
---|
651 | *
|
---|
652 | * @returns COM status code.
|
---|
653 | * @param aPattern The selection pattern. A bit similar to filename globbing.
|
---|
654 | */
|
---|
655 | STDMETHODIMP MachineDebugger::ResetStats (IN_BSTR aPattern)
|
---|
656 | {
|
---|
657 | Console::SafeVMPtrQuiet pVM (mParent);
|
---|
658 |
|
---|
659 | if (!pVM.isOk())
|
---|
660 | return setError(VBOX_E_INVALID_VM_STATE, "Machine is not running");
|
---|
661 |
|
---|
662 | STAMR3Reset (pVM, Utf8Str (aPattern).raw());
|
---|
663 |
|
---|
664 | return S_OK;
|
---|
665 | }
|
---|
666 |
|
---|
667 | /**
|
---|
668 | * Dumps VM statistics to the log.
|
---|
669 | *
|
---|
670 | * @returns COM status code.
|
---|
671 | * @param aPattern The selection pattern. A bit similar to filename globbing.
|
---|
672 | */
|
---|
673 | STDMETHODIMP MachineDebugger::DumpStats (IN_BSTR aPattern)
|
---|
674 | {
|
---|
675 | Console::SafeVMPtrQuiet pVM (mParent);
|
---|
676 |
|
---|
677 | if (!pVM.isOk())
|
---|
678 | return setError(VBOX_E_INVALID_VM_STATE, "Machine is not running");
|
---|
679 |
|
---|
680 | STAMR3Dump (pVM, Utf8Str (aPattern).raw());
|
---|
681 |
|
---|
682 | return S_OK;
|
---|
683 | }
|
---|
684 |
|
---|
685 | /**
|
---|
686 | * Get the VM statistics in an XML format.
|
---|
687 | *
|
---|
688 | * @returns COM status code.
|
---|
689 | * @param aPattern The selection pattern. A bit similar to filename globbing.
|
---|
690 | * @param aWithDescriptions Whether to include the descriptions.
|
---|
691 | * @param aStats The XML document containing the statistics.
|
---|
692 | */
|
---|
693 | STDMETHODIMP MachineDebugger::GetStats (IN_BSTR aPattern, BOOL aWithDescriptions, BSTR *aStats)
|
---|
694 | {
|
---|
695 | Console::SafeVMPtrQuiet pVM (mParent);
|
---|
696 |
|
---|
697 | if (!pVM.isOk())
|
---|
698 | return setError(VBOX_E_INVALID_VM_STATE, "Machine is not running");
|
---|
699 |
|
---|
700 | char *pszSnapshot;
|
---|
701 | int vrc = STAMR3Snapshot (pVM, Utf8Str (aPattern).raw(), &pszSnapshot, NULL,
|
---|
702 | !!aWithDescriptions);
|
---|
703 | if (RT_FAILURE(vrc))
|
---|
704 | return vrc == VERR_NO_MEMORY ? E_OUTOFMEMORY : E_FAIL;
|
---|
705 |
|
---|
706 | /** @todo this is horribly inefficient! And it's kinda difficult to tell whether it failed...
|
---|
707 | * Must use UTF-8 or ASCII here and completely avoid these two extra copy operations.
|
---|
708 | * Until that's done, this method is kind of useless for debugger statistics GUI because
|
---|
709 | * of the amount statistics in a debug build. */
|
---|
710 | Bstr (pszSnapshot).cloneTo(aStats);
|
---|
711 |
|
---|
712 | return S_OK;
|
---|
713 | }
|
---|
714 |
|
---|
715 | /**
|
---|
716 | * Set the new patch manager enabled flag.
|
---|
717 | *
|
---|
718 | * @returns COM status code
|
---|
719 | * @param new patch manager enabled flag
|
---|
720 | */
|
---|
721 | STDMETHODIMP MachineDebugger::InjectNMI()
|
---|
722 | {
|
---|
723 | LogFlowThisFunc(("\n"));
|
---|
724 |
|
---|
725 | AutoCaller autoCaller(this);
|
---|
726 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
727 |
|
---|
728 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
729 |
|
---|
730 | Console::SafeVMPtr pVM(mParent);
|
---|
731 | if (FAILED(pVM.rc())) return pVM.rc();
|
---|
732 |
|
---|
733 | HWACCMR3InjectNMI(pVM);
|
---|
734 |
|
---|
735 | return S_OK;
|
---|
736 | }
|
---|
737 |
|
---|
738 |
|
---|
739 | // public methods only for internal purposes
|
---|
740 | /////////////////////////////////////////////////////////////////////////////
|
---|
741 |
|
---|
742 | void MachineDebugger::flushQueuedSettings()
|
---|
743 | {
|
---|
744 | mFlushMode = true;
|
---|
745 | if (mSinglestepQueued != ~0)
|
---|
746 | {
|
---|
747 | COMSETTER(Singlestep) (mSinglestepQueued);
|
---|
748 | mSinglestepQueued = ~0;
|
---|
749 | }
|
---|
750 | if (mRecompileUserQueued != ~0)
|
---|
751 | {
|
---|
752 | COMSETTER(RecompileUser) (mRecompileUserQueued);
|
---|
753 | mRecompileUserQueued = ~0;
|
---|
754 | }
|
---|
755 | if (mRecompileSupervisorQueued != ~0)
|
---|
756 | {
|
---|
757 | COMSETTER(RecompileSupervisor) (mRecompileSupervisorQueued);
|
---|
758 | mRecompileSupervisorQueued = ~0;
|
---|
759 | }
|
---|
760 | if (mPatmEnabledQueued != ~0)
|
---|
761 | {
|
---|
762 | COMSETTER(PATMEnabled) (mPatmEnabledQueued);
|
---|
763 | mPatmEnabledQueued = ~0;
|
---|
764 | }
|
---|
765 | if (mCsamEnabledQueued != ~0)
|
---|
766 | {
|
---|
767 | COMSETTER(CSAMEnabled) (mCsamEnabledQueued);
|
---|
768 | mCsamEnabledQueued = ~0;
|
---|
769 | }
|
---|
770 | if (mLogEnabledQueued != ~0)
|
---|
771 | {
|
---|
772 | COMSETTER(LogEnabled) (mLogEnabledQueued);
|
---|
773 | mLogEnabledQueued = ~0;
|
---|
774 | }
|
---|
775 | if (mVirtualTimeRateQueued != ~(uint32_t)0)
|
---|
776 | {
|
---|
777 | COMSETTER(VirtualTimeRate) (mVirtualTimeRateQueued);
|
---|
778 | mVirtualTimeRateQueued = ~0;
|
---|
779 | }
|
---|
780 | mFlushMode = false;
|
---|
781 | }
|
---|
782 |
|
---|
783 | // private methods
|
---|
784 | /////////////////////////////////////////////////////////////////////////////
|
---|
785 |
|
---|
786 | bool MachineDebugger::queueSettings() const
|
---|
787 | {
|
---|
788 | if (!mFlushMode)
|
---|
789 | {
|
---|
790 | // check if the machine is running
|
---|
791 | MachineState_T machineState;
|
---|
792 | mParent->COMGETTER(State) (&machineState);
|
---|
793 | switch (machineState)
|
---|
794 | {
|
---|
795 | // queue the request
|
---|
796 | default:
|
---|
797 | return true;
|
---|
798 |
|
---|
799 | case MachineState_Running:
|
---|
800 | case MachineState_Paused:
|
---|
801 | case MachineState_Stuck:
|
---|
802 | case MachineState_LiveSnapshotting:
|
---|
803 | case MachineState_Teleporting:
|
---|
804 | break;
|
---|
805 | }
|
---|
806 | }
|
---|
807 | return false;
|
---|
808 | }
|
---|
809 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|