VirtualBox

source: vbox/trunk/src/VBox/Main/MachineDebuggerImpl.cpp@ 2397

Last change on this file since 2397 was 776, checked in by vboxsync, 18 years ago

warning

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 14.0 KB
Line 
1/** @file
2 *
3 * VirtualBox COM class implementation
4 */
5
6/*
7 * Copyright (C) 2006 InnoTek Systemberatung GmbH
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License as published by the Free Software Foundation,
13 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14 * distribution. VirtualBox OSE is distributed in the hope that it will
15 * be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * If you received this file as part of a commercial VirtualBox
18 * distribution, then only the terms of your commercial VirtualBox
19 * license agreement apply instead of the previous paragraph.
20 */
21
22#include "MachineDebuggerImpl.h"
23#include "ConsoleImpl.h"
24#include "Logging.h"
25
26#include <VBox/em.h>
27#include <VBox/patm.h>
28#include <VBox/csam.h>
29#include <VBox/vm.h>
30#include <VBox/tm.h>
31#include <VBox/err.h>
32#include <VBox/hwaccm.h>
33
34//
35// defines
36//
37
38
39//
40// globals
41//
42
43
44//
45// constructor / destructor
46//
47
48HRESULT MachineDebugger::FinalConstruct()
49{
50 mParent = NULL;
51 return S_OK;
52}
53
54void MachineDebugger::FinalRelease()
55{
56 if (isReady())
57 uninit();
58}
59
60//
61// public methods
62//
63
64/**
65 * Initializes the machine debugger object.
66 *
67 * @returns COM result indicator
68 * @param parent handle of our parent object
69 */
70HRESULT MachineDebugger::init(Console *parent)
71{
72 LogFlow(("MachineDebugger::init(): isReady=%d\n", isReady()));
73
74 ComAssertRet (parent, E_INVALIDARG);
75
76 AutoLock lock(this);
77 ComAssertRet (!isReady(), E_UNEXPECTED);
78
79 mParent = parent;
80 singlestepQueued = ~0;
81 recompileUserQueued = ~0;
82 recompileSupervisorQueued = ~0;
83 patmEnabledQueued = ~0;
84 csamEnabledQueued = ~0;
85 mLogEnabledQueued = ~0;
86 mVirtualTimeRateQueued = ~0;
87 fFlushMode = false;
88 setReady(true);
89 return S_OK;
90}
91
92/**
93 * Uninitializes the instance and sets the ready flag to FALSE.
94 * Called either from FinalRelease() or by the parent when it gets destroyed.
95 */
96void MachineDebugger::uninit()
97{
98 LogFlow(("MachineDebugger::uninit(): isReady=%d\n", isReady()));
99
100 AutoLock lock(this);
101 AssertReturn (isReady(), (void) 0);
102
103 setReady (false);
104}
105
106/**
107 * Returns the current singlestepping flag.
108 *
109 * @returns COM status code
110 * @param enabled address of result variable
111 */
112STDMETHODIMP MachineDebugger::COMGETTER(Singlestep)(BOOL *enabled)
113{
114 if (!enabled)
115 return E_POINTER;
116 AutoLock lock(this);
117 CHECK_READY();
118 /** @todo */
119 return E_NOTIMPL;
120}
121
122/**
123 * Sets the singlestepping flag.
124 *
125 * @returns COM status code
126 * @param enable new singlestepping flag
127 */
128STDMETHODIMP MachineDebugger::COMSETTER(Singlestep)(BOOL enable)
129{
130 AutoLock lock(this);
131 CHECK_READY();
132 /** @todo */
133 return E_NOTIMPL;
134}
135
136/**
137 * Resets VM statistics
138 *
139 * @returns COM status code
140 */
141STDMETHODIMP MachineDebugger::ResetStats()
142{
143 Console::SafeVMPtrQuiet pVM (mParent);
144 if (pVM.isOk())
145 STAMR3Reset(pVM, NULL);
146 return S_OK;
147}
148
149/**
150 * Dumps VM statistics to the log
151 *
152 * @returns COM status code
153 */
154STDMETHODIMP MachineDebugger::DumpStats()
155{
156 Console::SafeVMPtrQuiet pVM (mParent);
157 if (pVM.isOk())
158 STAMR3Dump(pVM, NULL);
159 return S_OK;
160}
161
162/**
163 * Returns the current recompile user mode code flag.
164 *
165 * @returns COM status code
166 * @param enabled address of result variable
167 */
168STDMETHODIMP MachineDebugger::COMGETTER(RecompileUser)(BOOL *enabled)
169{
170 if (!enabled)
171 return E_POINTER;
172 AutoLock lock(this);
173 CHECK_READY();
174 Console::SafeVMPtrQuiet pVM (mParent);
175 if (pVM.isOk())
176 *enabled = !EMIsRawRing3Enabled(pVM.raw());
177 else
178 *enabled = false;
179 return S_OK;
180}
181
182/**
183 * Sets the recompile user mode code flag.
184 *
185 * @returns COM status
186 * @param enable new user mode code recompile flag.
187 */
188STDMETHODIMP MachineDebugger::COMSETTER(RecompileUser)(BOOL enable)
189{
190 LogFlowThisFunc (("enable=%d\n", enable));
191
192 AutoLock lock(this);
193 CHECK_READY();
194
195 if (!fFlushMode)
196 {
197 // check if the machine is running
198 MachineState_T machineState;
199 mParent->COMGETTER(State)(&machineState);
200 if (machineState != MachineState_Running)
201 {
202 // queue the request
203 recompileUserQueued = enable;
204 return S_OK;
205 }
206 }
207
208 Console::SafeVMPtr pVM (mParent);
209 CheckComRCReturnRC (pVM.rc());
210
211 PVMREQ pReq;
212 EMRAWMODE rawModeFlag = enable ? EMRAW_RING3_DISABLE : EMRAW_RING3_ENABLE;
213 int rcVBox = VMR3ReqCall(pVM, &pReq, RT_INDEFINITE_WAIT,
214 (PFNRT)EMR3RawSetMode, 2, pVM.raw(), rawModeFlag);
215 if (VBOX_SUCCESS(rcVBox))
216 {
217 rcVBox = pReq->iStatus;
218 VMR3ReqFree(pReq);
219 }
220
221 if (VBOX_SUCCESS(rcVBox))
222 return S_OK;
223
224 AssertMsgFailed(("Could not set raw mode flags to %d, rcVBox = %Vrc\n",
225 rawModeFlag, rcVBox));
226 return E_FAIL;
227}
228
229/**
230 * Returns the current recompile supervisor code flag.
231 *
232 * @returns COM status code
233 * @param enabled address of result variable
234 */
235STDMETHODIMP MachineDebugger::COMGETTER(RecompileSupervisor)(BOOL *enabled)
236{
237 if (!enabled)
238 return E_POINTER;
239 AutoLock lock(this);
240 CHECK_READY();
241 Console::SafeVMPtrQuiet pVM (mParent);
242 if (pVM.isOk())
243 *enabled = !EMIsRawRing0Enabled(pVM.raw());
244 else
245 *enabled = false;
246 return S_OK;
247}
248
249/**
250 * Sets the new recompile supervisor code flag.
251 *
252 * @returns COM status code
253 * @param enable new recompile supervisor code flag
254 */
255STDMETHODIMP MachineDebugger::COMSETTER(RecompileSupervisor)(BOOL enable)
256{
257 LogFlowThisFunc (("enable=%d\n", enable));
258
259 AutoLock lock(this);
260 CHECK_READY();
261
262 if (!fFlushMode)
263 {
264 // check if the machine is running
265 MachineState_T machineState;
266 mParent->COMGETTER(State)(&machineState);
267 if (machineState != MachineState_Running)
268 {
269 // queue the request
270 recompileSupervisorQueued = enable;
271 return S_OK;
272 }
273 }
274
275 Console::SafeVMPtr pVM (mParent);
276 CheckComRCReturnRC (pVM.rc());
277
278 PVMREQ pReq;
279 EMRAWMODE rawModeFlag = enable ? EMRAW_RING0_DISABLE : EMRAW_RING0_ENABLE;
280 int rcVBox = VMR3ReqCall(pVM, &pReq, RT_INDEFINITE_WAIT,
281 (PFNRT)EMR3RawSetMode, 2, pVM.raw(), rawModeFlag);
282 if (VBOX_SUCCESS(rcVBox))
283 {
284 rcVBox = pReq->iStatus;
285 VMR3ReqFree(pReq);
286 }
287
288 if (VBOX_SUCCESS(rcVBox))
289 return S_OK;
290
291 AssertMsgFailed(("Could not set raw mode flags to %d, rcVBox = %Vrc\n",
292 rawModeFlag, rcVBox));
293 return E_FAIL;
294}
295
296/**
297 * Returns the current patch manager enabled flag.
298 *
299 * @returns COM status code
300 * @param enabled address of result variable
301 */
302STDMETHODIMP MachineDebugger::COMGETTER(PATMEnabled)(BOOL *enabled)
303{
304 if (!enabled)
305 return E_POINTER;
306 AutoLock lock(this);
307 CHECK_READY();
308 Console::SafeVMPtrQuiet pVM (mParent);
309 if (pVM.isOk())
310 *enabled = PATMIsEnabled(pVM.raw());
311 else
312 *enabled = false;
313 return S_OK;
314}
315
316/**
317 * Set the new patch manager enabled flag.
318 *
319 * @returns COM status code
320 * @param new patch manager enabled flag
321 */
322STDMETHODIMP MachineDebugger::COMSETTER(PATMEnabled)(BOOL enable)
323{
324 AutoLock lock(this);
325 CHECK_READY();
326 LogFlowThisFunc (("enable=%d\n", enable));
327
328 if (!fFlushMode)
329 {
330 // check if the machine is running
331 MachineState_T machineState;
332 mParent->COMGETTER(State)(&machineState);
333 if (machineState != MachineState_Running)
334 {
335 // queue the request
336 patmEnabledQueued = enable;
337 return S_OK;
338 }
339 }
340
341 Console::SafeVMPtr pVM (mParent);
342 CheckComRCReturnRC (pVM.rc());
343
344 PATMR3AllowPatching(pVM, enable);
345 return E_NOTIMPL;
346}
347
348/**
349 * Returns the current code scanner enabled flag.
350 *
351 * @returns COM status code
352 * @param enabled address of result variable
353 */
354STDMETHODIMP MachineDebugger::COMGETTER(CSAMEnabled)(BOOL *enabled)
355{
356 if (!enabled)
357 return E_POINTER;
358 AutoLock lock(this);
359 CHECK_READY();
360 Console::SafeVMPtrQuiet pVM (mParent);
361 if (pVM.isOk())
362 *enabled = CSAMIsEnabled(pVM.raw());
363 else
364 *enabled = false;
365 return S_OK;
366}
367
368/**
369 * Sets the new code scanner enabled flag.
370 *
371 * @returns COM status code
372 * @param enable new code scanner enabled flag
373 */
374STDMETHODIMP MachineDebugger::COMSETTER(CSAMEnabled)(BOOL enable)
375{
376 AutoLock lock(this);
377 CHECK_READY();
378 LogFlowThisFunc (("enable=%d\n", enable));
379
380 if (!fFlushMode)
381 {
382 // check if the machine is running
383 MachineState_T machineState;
384 mParent->COMGETTER(State)(&machineState);
385 if (machineState != MachineState_Running)
386 {
387 // queue the request
388 csamEnabledQueued = enable;
389 return S_OK;
390 }
391 }
392
393 Console::SafeVMPtr pVM (mParent);
394 CheckComRCReturnRC (pVM.rc());
395
396 int vrc;
397 if (enable)
398 vrc = CSAMEnableScanning(pVM);
399 else
400 vrc = CSAMDisableScanning(pVM);
401 if (VBOX_FAILURE(vrc))
402 {
403 /** @todo handle error case */
404 }
405 return S_OK;
406}
407
408/**
409 * Returns the log enabled / disabled status.
410 *
411 * @returns COM status code
412 * @param aEnabled address of result variable
413 */
414STDMETHODIMP MachineDebugger::COMGETTER(LogEnabled)(BOOL *aEnabled)
415{
416 if (!aEnabled)
417 return E_POINTER;
418 AutoLock alock(this);
419 CHECK_READY();
420 PRTLOGGER pLogInstance = RTLogDefaultInstance();
421 *aEnabled = pLogInstance && !(pLogInstance->fFlags & RTLOGFLAGS_DISABLED);
422 return S_OK;
423}
424
425/**
426 * Enables or disables logging.
427 *
428 * @returns COM status code
429 * @param aEnabled The new code log state.
430 */
431STDMETHODIMP MachineDebugger::COMSETTER(LogEnabled)(BOOL aEnabled)
432{
433 AutoLock alock(this);
434
435 CHECK_READY();
436 LogFlowThisFunc (("aEnabled=%d\n", aEnabled));
437
438 if (!fFlushMode)
439 {
440 // check if the machine is running
441 MachineState_T machineState;
442 mParent->COMGETTER(State)(&machineState);
443 if (machineState != MachineState_Running)
444 {
445 // queue the request
446 mLogEnabledQueued = aEnabled;
447 return S_OK;
448 }
449 }
450
451 Console::SafeVMPtr pVM (mParent);
452 CheckComRCReturnRC (pVM.rc());
453
454 int vrc = DBGFR3LogModifyFlags(pVM, aEnabled ? "enabled" : "disabled");
455 if (VBOX_FAILURE(vrc))
456 {
457 /** @todo handle error code. */
458 }
459 return S_OK;
460}
461
462/**
463 * Returns the current hardware virtualization flag.
464 *
465 * @returns COM status code
466 * @param enabled address of result variable
467 */
468STDMETHODIMP MachineDebugger::COMGETTER(HWVirtExEnabled)(BOOL *enabled)
469{
470 if (!enabled)
471 return E_POINTER;
472
473 AutoLock lock(this);
474 CHECK_READY();
475
476 Console::SafeVMPtrQuiet pVM (mParent);
477 if (pVM.isOk())
478 *enabled = HWACCMIsEnabled(pVM.raw());
479 else
480 *enabled = false;
481 return S_OK;
482}
483
484/**
485 * Returns the current virtual time rate.
486 *
487 * @returns COM status code.
488 * @param pct Where to store the rate.
489 */
490STDMETHODIMP MachineDebugger::COMGETTER(VirtualTimeRate)(ULONG *pct)
491{
492 if (!pct)
493 return E_POINTER;
494
495 AutoLock lock(this);
496 CHECK_READY();
497
498 Console::SafeVMPtrQuiet pVM (mParent);
499 if (pVM.isOk())
500 *pct = TMVirtualGetWarpDrive(pVM);
501 else
502 *pct = 100;
503 return S_OK;
504}
505
506/**
507 * Returns the current virtual time rate.
508 *
509 * @returns COM status code.
510 * @param pct Where to store the rate.
511 */
512STDMETHODIMP MachineDebugger::COMSETTER(VirtualTimeRate)(ULONG pct)
513{
514 if (pct < 2 || pct > 20000)
515 return E_INVALIDARG;
516
517 AutoLock lock(this);
518 CHECK_READY();
519
520 if (!fFlushMode)
521 {
522 // check if the machine is running
523 MachineState_T machineState;
524 mParent->COMGETTER(State)(&machineState);
525 if (machineState != MachineState_Running)
526 {
527 // queue the request
528 mVirtualTimeRateQueued = pct;
529 return S_OK;
530 }
531 }
532
533 Console::SafeVMPtr pVM (mParent);
534 CheckComRCReturnRC (pVM.rc());
535
536 int vrc = TMVirtualSetWarpDrive(pVM, pct);
537 if (VBOX_FAILURE(vrc))
538 {
539 /** @todo handle error code. */
540 }
541 return S_OK;
542}
543
544/**
545 * Hack for getting the VM handle.
546 * This is only temporary (promise) while prototyping the debugger.
547 *
548 * @returns COM status code
549 * @param vm Where to store the vm handle.
550 * Since there is no uintptr_t in COM, we're using the max integer.
551 * (No, ULONG is not pointer sized!)
552 */
553STDMETHODIMP MachineDebugger::COMGETTER(VM)(ULONG64 *vm)
554{
555 if (!vm)
556 return E_POINTER;
557
558 AutoLock lock(this);
559 CHECK_READY();
560
561 Console::SafeVMPtr pVM (mParent);
562 CheckComRCReturnRC (pVM.rc());
563
564 *vm = (uintptr_t)pVM.raw();
565
566 /*
567 * Note: pVM protection provided by SafeVMPtr is no more effective
568 * after we return from this method.
569 */
570
571 return S_OK;
572}
573
574//
575// "public-private" methods
576//
577void MachineDebugger::flushQueuedSettings()
578{
579 fFlushMode = true;
580 if (singlestepQueued != ~0)
581 {
582 COMSETTER(Singlestep)(singlestepQueued);
583 singlestepQueued = ~0;
584 }
585 if (recompileUserQueued != ~0)
586 {
587 COMSETTER(RecompileUser)(recompileUserQueued);
588 recompileUserQueued = ~0;
589 }
590 if (recompileSupervisorQueued != ~0)
591 {
592 COMSETTER(RecompileSupervisor)(recompileSupervisorQueued);
593 recompileSupervisorQueued = ~0;
594 }
595 if (patmEnabledQueued != ~0)
596 {
597 COMSETTER(PATMEnabled)(patmEnabledQueued);
598 patmEnabledQueued = ~0;
599 }
600 if (csamEnabledQueued != ~0)
601 {
602 COMSETTER(CSAMEnabled)(csamEnabledQueued);
603 csamEnabledQueued = ~0;
604 }
605 if (mLogEnabledQueued != ~0)
606 {
607 COMSETTER(LogEnabled)(mLogEnabledQueued);
608 mLogEnabledQueued = ~0;
609 }
610 if (mVirtualTimeRateQueued != ~(uint32_t)0)
611 {
612 COMSETTER(VirtualTimeRate)(mVirtualTimeRateQueued);
613 mVirtualTimeRateQueued = ~0;
614 }
615 fFlushMode = false;
616}
617
618//
619// private methods
620//
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette