VirtualBox

source: vbox/trunk/src/VBox/Frontends/VBoxManage/VBoxManageDebugVM.cpp@ 61226

Last change on this file since 61226 was 58212, checked in by vboxsync, 9 years ago

DnD: Updates.

  • Introduced protocol changelog in DragAndDropSvc.h.
  • Implemented protocol v3 with HOST_DND_HG_SND_DATA_HDR message for doing proper object accounting, among other parameters like checksumming and compression flags.
  • Encapsulated a lot of functionality in class hierarchies.
  • Renamed a lot of functions to make the usage more clear.
  • Various other bugfixes.
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 28.9 KB
Line 
1/* $Id: VBoxManageDebugVM.cpp 58212 2015-10-13 11:49:33Z vboxsync $ */
2/** @file
3 * VBoxManage - Implementation of the debugvm command.
4 */
5
6/*
7 * Copyright (C) 2012 Oracle Corporation
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 (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18
19/*********************************************************************************************************************************
20* Header Files *
21*********************************************************************************************************************************/
22#include <VBox/com/com.h>
23#include <VBox/com/string.h>
24#include <VBox/com/Guid.h>
25#include <VBox/com/array.h>
26#include <VBox/com/ErrorInfo.h>
27#include <VBox/com/errorprint.h>
28#include <VBox/com/VirtualBox.h>
29
30#include <iprt/ctype.h>
31#include <VBox/err.h>
32#include <iprt/getopt.h>
33#include <iprt/path.h>
34#include <iprt/param.h>
35#include <iprt/stream.h>
36#include <iprt/string.h>
37#include <iprt/uuid.h>
38#include <VBox/log.h>
39
40#include "VBoxManage.h"
41
42
43/**
44 * Handles the getregisters sub-command.
45 *
46 * @returns Suitable exit code.
47 * @param pArgs The handler arguments.
48 * @param pDebugger Pointer to the debugger interface.
49 */
50static RTEXITCODE handleDebugVM_GetRegisters(HandlerArg *pArgs, IMachineDebugger *pDebugger)
51{
52 /*
53 * We take a list of register names (case insensitive). If 'all' is
54 * encountered we'll dump all registers.
55 */
56 ULONG idCpu = 0;
57 unsigned cRegisters = 0;
58
59 RTGETOPTSTATE GetState;
60 RTGETOPTUNION ValueUnion;
61 static const RTGETOPTDEF s_aOptions[] =
62 {
63 { "--cpu", 'c', RTGETOPT_REQ_UINT32 },
64 };
65 int rc = RTGetOptInit(&GetState, pArgs->argc, pArgs->argv, s_aOptions, RT_ELEMENTS(s_aOptions), 2, RTGETOPTINIT_FLAGS_OPTS_FIRST);
66 AssertRCReturn(rc, RTEXITCODE_FAILURE);
67
68 while ((rc = RTGetOpt(&GetState, &ValueUnion)) != 0)
69 {
70 switch (rc)
71 {
72 case 'c':
73 idCpu = ValueUnion.u32;
74 break;
75
76 case VINF_GETOPT_NOT_OPTION:
77 if (!RTStrICmp(ValueUnion.psz, "all"))
78 {
79 com::SafeArray<BSTR> aBstrNames;
80 com::SafeArray<BSTR> aBstrValues;
81 CHECK_ERROR2I_RET(pDebugger, GetRegisters(idCpu, ComSafeArrayAsOutParam(aBstrNames),
82 ComSafeArrayAsOutParam(aBstrValues)),
83 RTEXITCODE_FAILURE);
84 Assert(aBstrNames.size() == aBstrValues.size());
85
86 size_t cchMaxName = 8;
87 for (size_t i = 0; i < aBstrNames.size(); i++)
88 {
89 size_t cchName = RTUtf16Len(aBstrNames[i]);
90 if (cchName > cchMaxName)
91 cchMaxName = cchName;
92 }
93
94 for (size_t i = 0; i < aBstrNames.size(); i++)
95 RTPrintf("%-*ls = %ls\n", cchMaxName, aBstrNames[i], aBstrValues[i]);
96 }
97 else
98 {
99 com::Bstr bstrName = ValueUnion.psz;
100 com::Bstr bstrValue;
101 CHECK_ERROR2I_RET(pDebugger, GetRegister(idCpu, bstrName.raw(), bstrValue.asOutParam()), RTEXITCODE_FAILURE);
102 RTPrintf("%s = %ls\n", ValueUnion.psz, bstrValue.raw());
103 }
104 cRegisters++;
105 break;
106
107 default:
108 return errorGetOpt(rc, &ValueUnion);
109 }
110 }
111
112 if (!cRegisters)
113 return errorSyntax("The getregisters sub-command takes at least one register name");
114 return RTEXITCODE_SUCCESS;
115}
116
117/**
118 * Handles the info sub-command.
119 *
120 * @returns Suitable exit code.
121 * @param pArgs The handler arguments.
122 * @param pDebugger Pointer to the debugger interface.
123 */
124static RTEXITCODE handleDebugVM_Info(HandlerArg *pArgs, IMachineDebugger *pDebugger)
125{
126 /*
127 * Parse arguments.
128 */
129 const char *pszInfo = NULL;
130 const char *pszArgs = NULL;
131 RTGETOPTSTATE GetState;
132 RTGETOPTUNION ValueUnion;
133 int rc = RTGetOptInit(&GetState, pArgs->argc, pArgs->argv, NULL, 0, 2, RTGETOPTINIT_FLAGS_OPTS_FIRST);
134 AssertRCReturn(rc, RTEXITCODE_FAILURE);
135
136 while ((rc = RTGetOpt(&GetState, &ValueUnion)) != 0)
137 {
138 switch (rc)
139 {
140 case VINF_GETOPT_NOT_OPTION:
141 if (!pszInfo)
142 pszInfo = ValueUnion.psz;
143 else if (!pszArgs)
144 pszArgs = ValueUnion.psz;
145 else
146 return errorTooManyParameters(&pArgs->argv[GetState.iNext - 1]);
147 break;
148 default:
149 return errorGetOpt(rc, &ValueUnion);
150 }
151 }
152
153 if (!pszInfo)
154 return errorSyntax("Must specify info item to display");
155
156 /*
157 * Do the work.
158 */
159 com::Bstr bstrName(pszInfo);
160 com::Bstr bstrArgs(pszArgs);
161 com::Bstr bstrInfo;
162 CHECK_ERROR2I_RET(pDebugger, Info(bstrName.raw(), bstrArgs.raw(), bstrInfo.asOutParam()), RTEXITCODE_FAILURE);
163 RTPrintf("%ls", bstrInfo.raw());
164 return RTEXITCODE_SUCCESS;
165}
166
167/**
168 * Handles the inject sub-command.
169 *
170 * @returns Suitable exit code.
171 * @param a The handler arguments.
172 * @param pDebugger Pointer to the debugger interface.
173 */
174static RTEXITCODE handleDebugVM_InjectNMI(HandlerArg *a, IMachineDebugger *pDebugger)
175{
176 if (a->argc != 2)
177 return errorTooManyParameters(&a->argv[1]);
178 CHECK_ERROR2I_RET(pDebugger, InjectNMI(), RTEXITCODE_FAILURE);
179 return RTEXITCODE_SUCCESS;
180}
181
182/**
183 * Handles the log sub-command.
184 *
185 * @returns Suitable exit code.
186 * @param pArgs The handler arguments.
187 * @param pDebugger Pointer to the debugger interface.
188 * @param pszSubCmd The sub command.
189 */
190static RTEXITCODE handleDebugVM_LogXXXX(HandlerArg *pArgs, IMachineDebugger *pDebugger, const char *pszSubCmd)
191{
192 /*
193 * Parse arguments.
194 */
195 bool fRelease = false;
196 com::Utf8Str strSettings;
197
198 RTGETOPTSTATE GetState;
199 RTGETOPTUNION ValueUnion;
200
201 /*
202 * NB: don't use short options to prevent log specifications like
203 * "-drv_foo" from being interpreted as options.
204 */
205# define DEBUGVM_LOG_DEBUG (VINF_GETOPT_NOT_OPTION + 'd')
206# define DEBUGVM_LOG_RELEASE (VINF_GETOPT_NOT_OPTION + 'r')
207
208 static const RTGETOPTDEF s_aOptions[] =
209 {
210 { "--debug", DEBUGVM_LOG_DEBUG, RTGETOPT_REQ_NOTHING },
211 { "--release", DEBUGVM_LOG_RELEASE, RTGETOPT_REQ_NOTHING }
212 };
213 int rc = RTGetOptInit(&GetState, pArgs->argc, pArgs->argv, s_aOptions, RT_ELEMENTS(s_aOptions), 2,
214 /*
215 * Note: RTGETOPTINIT_FLAGS_NO_STD_OPTS is needed to not get into an infinite hang in the following
216 * while-loop when processing log groups starting with "h",
217 * e.g. "VBoxManage debugvm <VM Name> log --debug -hex".
218 */
219 RTGETOPTINIT_FLAGS_OPTS_FIRST | RTGETOPTINIT_FLAGS_NO_STD_OPTS);
220 AssertRCReturn(rc, RTEXITCODE_FAILURE);
221
222 while ((rc = RTGetOpt(&GetState, &ValueUnion)) != 0)
223 {
224 switch (rc)
225 {
226 case DEBUGVM_LOG_RELEASE:
227 fRelease = true;
228 break;
229
230 case DEBUGVM_LOG_DEBUG:
231 fRelease = false;
232 break;
233
234 /* Because log strings can start with "-" (like "-all+dev_foo")
235 * we have to take everything we got as a setting and apply it.
236 * IPRT will take care of the validation afterwards. */
237 default:
238 if (strSettings.length() == 0)
239 strSettings = ValueUnion.psz;
240 else
241 {
242 strSettings.append(' ');
243 strSettings.append(ValueUnion.psz);
244 }
245 break;
246 }
247 }
248
249 if (fRelease)
250 {
251 com::Utf8Str strTmp(strSettings);
252 strSettings = "release:";
253 strSettings.append(strTmp);
254 }
255
256 com::Bstr bstrSettings(strSettings);
257 if (!strcmp(pszSubCmd, "log"))
258 CHECK_ERROR2I_RET(pDebugger, ModifyLogGroups(bstrSettings.raw()), RTEXITCODE_FAILURE);
259 else if (!strcmp(pszSubCmd, "logdest"))
260 CHECK_ERROR2I_RET(pDebugger, ModifyLogDestinations(bstrSettings.raw()), RTEXITCODE_FAILURE);
261 else if (!strcmp(pszSubCmd, "logflags"))
262 CHECK_ERROR2I_RET(pDebugger, ModifyLogFlags(bstrSettings.raw()), RTEXITCODE_FAILURE);
263 else
264 AssertFailedReturn(RTEXITCODE_FAILURE);
265
266 return RTEXITCODE_SUCCESS;
267}
268
269
270/**
271 * Handles the inject sub-command.
272 *
273 * @returns Suitable exit code.
274 * @param pArgs The handler arguments.
275 * @param pDebugger Pointer to the debugger interface.
276 */
277static RTEXITCODE handleDebugVM_DumpVMCore(HandlerArg *pArgs, IMachineDebugger *pDebugger)
278{
279 /*
280 * Parse arguments.
281 */
282 const char *pszFilename = NULL;
283 const char *pszCompression = NULL;
284
285 RTGETOPTSTATE GetState;
286 RTGETOPTUNION ValueUnion;
287 static const RTGETOPTDEF s_aOptions[] =
288 {
289 { "--filename", 'f', RTGETOPT_REQ_STRING },
290 { "--compression", 'c', RTGETOPT_REQ_STRING }
291 };
292 int rc = RTGetOptInit(&GetState, pArgs->argc, pArgs->argv, s_aOptions, RT_ELEMENTS(s_aOptions), 2, 0 /*fFlags*/);
293 AssertRCReturn(rc, RTEXITCODE_FAILURE);
294
295 while ((rc = RTGetOpt(&GetState, &ValueUnion)) != 0)
296 {
297 switch (rc)
298 {
299 case 'c':
300 if (pszCompression)
301 return errorSyntax("The --compression option has already been given");
302 pszCompression = ValueUnion.psz;
303 break;
304 case 'f':
305 if (pszFilename)
306 return errorSyntax("The --filename option has already been given");
307 pszFilename = ValueUnion.psz;
308 break;
309 default:
310 return errorGetOpt(rc, &ValueUnion);
311 }
312 }
313
314 if (!pszFilename)
315 return errorSyntax("The --filename option is required");
316
317 /*
318 * Make the filename absolute before handing it on to the API.
319 */
320 char szAbsFilename[RTPATH_MAX];
321 rc = RTPathAbs(pszFilename, szAbsFilename, sizeof(szAbsFilename));
322 if (RT_FAILURE(rc))
323 return RTMsgErrorExit(RTEXITCODE_FAILURE, "RTPathAbs failed on '%s': %Rrc", pszFilename, rc);
324
325 com::Bstr bstrFilename(szAbsFilename);
326 com::Bstr bstrCompression(pszCompression);
327 CHECK_ERROR2I_RET(pDebugger, DumpGuestCore(bstrFilename.raw(), bstrCompression.raw()), RTEXITCODE_FAILURE);
328 return RTEXITCODE_SUCCESS;
329}
330
331/**
332 * Handles the osdetect sub-command.
333 *
334 * @returns Suitable exit code.
335 * @param a The handler arguments.
336 * @param pDebugger Pointer to the debugger interface.
337 */
338static RTEXITCODE handleDebugVM_OSDetect(HandlerArg *a, IMachineDebugger *pDebugger)
339{
340 if (a->argc != 2)
341 return errorTooManyParameters(&a->argv[1]);
342
343 com::Bstr bstrIgnore;
344 com::Bstr bstrAll("all");
345 CHECK_ERROR2I_RET(pDebugger, LoadPlugIn(bstrAll.raw(), bstrIgnore.asOutParam()), RTEXITCODE_FAILURE);
346
347 com::Bstr bstrName;
348 CHECK_ERROR2I_RET(pDebugger, DetectOS(bstrName.asOutParam()), RTEXITCODE_FAILURE);
349 RTPrintf("Detected: %ls\n", bstrName.raw());
350 return RTEXITCODE_SUCCESS;
351}
352
353/**
354 * Handles the osinfo sub-command.
355 *
356 * @returns Suitable exit code.
357 * @param a The handler arguments.
358 * @param pDebugger Pointer to the debugger interface.
359 */
360static RTEXITCODE handleDebugVM_OSInfo(HandlerArg *a, IMachineDebugger *pDebugger)
361{
362 if (a->argc != 2)
363 return errorTooManyParameters(&a->argv[1]);
364
365 com::Bstr bstrName;
366 CHECK_ERROR2I_RET(pDebugger, COMGETTER(OSName)(bstrName.asOutParam()), RTEXITCODE_FAILURE);
367 com::Bstr bstrVersion;
368 CHECK_ERROR2I_RET(pDebugger, COMGETTER(OSVersion)(bstrVersion.asOutParam()), RTEXITCODE_FAILURE);
369 RTPrintf("Name: %ls\n", bstrName.raw());
370 RTPrintf("Version: %ls\n", bstrVersion.raw());
371 return RTEXITCODE_SUCCESS;
372}
373
374/**
375 * Handles the osdmsg sub-command.
376 *
377 * @returns Suitable exit code.
378 * @param pArgs The handler arguments.
379 * @param pDebugger Pointer to the debugger interface.
380 */
381static RTEXITCODE handleDebugVM_OSDmesg(HandlerArg *pArgs, IMachineDebugger *pDebugger)
382{
383 /*
384 * Parse argument.
385 */
386 uint32_t uMaxMessages = 0;
387 RTGETOPTSTATE GetState;
388 RTGETOPTUNION ValueUnion;
389 static const RTGETOPTDEF s_aOptions[] =
390 {
391 { "--lines", 'n', RTGETOPT_REQ_UINT32 },
392 };
393 int rc = RTGetOptInit(&GetState, pArgs->argc, pArgs->argv, s_aOptions, RT_ELEMENTS(s_aOptions), 2, RTGETOPTINIT_FLAGS_OPTS_FIRST);
394 AssertRCReturn(rc, RTEXITCODE_FAILURE);
395 while ((rc = RTGetOpt(&GetState, &ValueUnion)) != 0)
396 switch (rc)
397 {
398 case 'n': uMaxMessages = ValueUnion.u32; break;
399 default: return errorGetOpt(rc, &ValueUnion);
400 }
401
402 /*
403 * Do it.
404 */
405 com::Bstr bstrDmesg;
406 CHECK_ERROR2I_RET(pDebugger, QueryOSKernelLog(uMaxMessages, bstrDmesg.asOutParam()), RTEXITCODE_FAILURE);
407 RTPrintf("%ls\n", bstrDmesg.raw());
408 return RTEXITCODE_SUCCESS;
409}
410
411/**
412 * Handles the setregisters sub-command.
413 *
414 * @returns Suitable exit code.
415 * @param pArgs The handler arguments.
416 * @param pDebugger Pointer to the debugger interface.
417 */
418static RTEXITCODE handleDebugVM_SetRegisters(HandlerArg *pArgs, IMachineDebugger *pDebugger)
419{
420 /*
421 * We take a list of register assignments, that is register=value.
422 */
423 ULONG idCpu = 0;
424 com::SafeArray<IN_BSTR> aBstrNames;
425 com::SafeArray<IN_BSTR> aBstrValues;
426
427 RTGETOPTSTATE GetState;
428 RTGETOPTUNION ValueUnion;
429 static const RTGETOPTDEF s_aOptions[] =
430 {
431 { "--cpu", 'c', RTGETOPT_REQ_UINT32 },
432 };
433 int rc = RTGetOptInit(&GetState, pArgs->argc, pArgs->argv, s_aOptions, RT_ELEMENTS(s_aOptions), 2, RTGETOPTINIT_FLAGS_OPTS_FIRST);
434 AssertRCReturn(rc, RTEXITCODE_FAILURE);
435
436 while ((rc = RTGetOpt(&GetState, &ValueUnion)) != 0)
437 {
438 switch (rc)
439 {
440 case 'c':
441 idCpu = ValueUnion.u32;
442 break;
443
444 case VINF_GETOPT_NOT_OPTION:
445 {
446 const char *pszEqual = strchr(ValueUnion.psz, '=');
447 if (!pszEqual)
448 return errorSyntax("setregisters expects input on the form 'register=value' got '%s'", ValueUnion.psz);
449 try
450 {
451 com::Bstr bstrName(ValueUnion.psz, pszEqual - ValueUnion.psz);
452 com::Bstr bstrValue(pszEqual + 1);
453 if ( !aBstrNames.push_back(bstrName.raw())
454 || !aBstrValues.push_back(bstrValue.raw()))
455 throw std::bad_alloc();
456 }
457 catch (std::bad_alloc)
458 {
459 RTMsgError("Out of memory\n");
460 return RTEXITCODE_FAILURE;
461 }
462 break;
463 }
464
465 default:
466 return errorGetOpt(rc, &ValueUnion);
467 }
468 }
469
470 if (!aBstrNames.size())
471 return errorSyntax("The setregisters sub-command takes at least one register name");
472
473 /*
474 * If it is only one register, use the single register method just so
475 * we expose it and can test it from the command line.
476 */
477 if (aBstrNames.size() == 1)
478 {
479 CHECK_ERROR2I_RET(pDebugger, SetRegister(idCpu, aBstrNames[0], aBstrValues[0]), RTEXITCODE_FAILURE);
480 RTPrintf("Successfully set %ls\n", aBstrNames[0]);
481 }
482 else
483 {
484 CHECK_ERROR2I_RET(pDebugger, SetRegisters(idCpu, ComSafeArrayAsInParam(aBstrNames), ComSafeArrayAsInParam(aBstrValues)),
485 RTEXITCODE_FAILURE);
486 RTPrintf("Successfully set %u registers\n", aBstrNames.size());
487 }
488
489 return RTEXITCODE_SUCCESS;
490}
491
492/** @name debugvm show flags
493 * @{ */
494#define DEBUGVM_SHOW_FLAGS_HUMAN_READABLE UINT32_C(0x00000000)
495#define DEBUGVM_SHOW_FLAGS_SH_EXPORT UINT32_C(0x00000001)
496#define DEBUGVM_SHOW_FLAGS_SH_EVAL UINT32_C(0x00000002)
497#define DEBUGVM_SHOW_FLAGS_CMD_SET UINT32_C(0x00000003)
498#define DEBUGVM_SHOW_FLAGS_FMT_MASK UINT32_C(0x00000003)
499/** @} */
500
501/**
502 * Prints a variable according to the @a fFlags.
503 *
504 * @param pszVar The variable name.
505 * @param pbstrValue The variable value.
506 * @param fFlags The debugvm show flags.
507 */
508static void handleDebugVM_Show_PrintVar(const char *pszVar, com::Bstr const *pbstrValue, uint32_t fFlags)
509{
510 switch (fFlags & DEBUGVM_SHOW_FLAGS_FMT_MASK)
511 {
512 case DEBUGVM_SHOW_FLAGS_HUMAN_READABLE: RTPrintf(" %27s=%ls\n", pszVar, pbstrValue->raw()); break;
513 case DEBUGVM_SHOW_FLAGS_SH_EXPORT: RTPrintf("export %s='%ls'\n", pszVar, pbstrValue->raw()); break;
514 case DEBUGVM_SHOW_FLAGS_SH_EVAL: RTPrintf("%s='%ls'\n", pszVar, pbstrValue->raw()); break;
515 case DEBUGVM_SHOW_FLAGS_CMD_SET: RTPrintf("set %s=%ls\n", pszVar, pbstrValue->raw()); break;
516 default: AssertFailed();
517 }
518}
519
520/**
521 * Handles logdbg-settings.
522 *
523 * @returns Exit code.
524 * @param pDebugger The debugger interface.
525 * @param fFlags The debugvm show flags.
526 */
527static RTEXITCODE handleDebugVM_Show_LogDbgSettings(IMachineDebugger *pDebugger, uint32_t fFlags)
528{
529 if ((fFlags & DEBUGVM_SHOW_FLAGS_FMT_MASK) == DEBUGVM_SHOW_FLAGS_HUMAN_READABLE)
530 RTPrintf("Debug logger settings:\n");
531
532 com::Bstr bstr;
533 CHECK_ERROR2I_RET(pDebugger, COMGETTER(LogDbgGroups)(bstr.asOutParam()), RTEXITCODE_FAILURE);
534 handleDebugVM_Show_PrintVar("VBOX_LOG", &bstr, fFlags);
535
536 CHECK_ERROR2I_RET(pDebugger, COMGETTER(LogDbgFlags)(bstr.asOutParam()), RTEXITCODE_FAILURE);
537 handleDebugVM_Show_PrintVar("VBOX_LOG_FLAGS", &bstr, fFlags);
538
539 CHECK_ERROR2I_RET(pDebugger, COMGETTER(LogDbgDestinations)(bstr.asOutParam()), RTEXITCODE_FAILURE);
540 handleDebugVM_Show_PrintVar("VBOX_LOG_DEST", &bstr, fFlags);
541 return RTEXITCODE_SUCCESS;
542}
543
544/**
545 * Handles logrel-settings.
546 *
547 * @returns Exit code.
548 * @param pDebugger The debugger interface.
549 * @param fFlags The debugvm show flags.
550 */
551static RTEXITCODE handleDebugVM_Show_LogRelSettings(IMachineDebugger *pDebugger, uint32_t fFlags)
552{
553 if ((fFlags & DEBUGVM_SHOW_FLAGS_FMT_MASK) == DEBUGVM_SHOW_FLAGS_HUMAN_READABLE)
554 RTPrintf("Release logger settings:\n");
555
556 com::Bstr bstr;
557 CHECK_ERROR2I_RET(pDebugger, COMGETTER(LogRelGroups)(bstr.asOutParam()), RTEXITCODE_FAILURE);
558 handleDebugVM_Show_PrintVar("VBOX_RELEASE_LOG", &bstr, fFlags);
559
560 CHECK_ERROR2I_RET(pDebugger, COMGETTER(LogRelFlags)(bstr.asOutParam()), RTEXITCODE_FAILURE);
561 handleDebugVM_Show_PrintVar("VBOX_RELEASE_LOG_FLAGS", &bstr, fFlags);
562
563 CHECK_ERROR2I_RET(pDebugger, COMGETTER(LogRelDestinations)(bstr.asOutParam()), RTEXITCODE_FAILURE);
564 handleDebugVM_Show_PrintVar("VBOX_RELEASE_LOG_DEST", &bstr, fFlags);
565 return RTEXITCODE_SUCCESS;
566}
567
568/**
569 * Handles the show sub-command.
570 *
571 * @returns Suitable exit code.
572 * @param pArgs The handler arguments.
573 * @param pDebugger Pointer to the debugger interface.
574 */
575static RTEXITCODE handleDebugVM_Show(HandlerArg *pArgs, IMachineDebugger *pDebugger)
576{
577 /*
578 * Parse arguments and what to show. Order dependent.
579 */
580 uint32_t fFlags = DEBUGVM_SHOW_FLAGS_HUMAN_READABLE;
581
582 RTGETOPTSTATE GetState;
583 RTGETOPTUNION ValueUnion;
584 static const RTGETOPTDEF s_aOptions[] =
585 {
586 { "--human-readable", 'H', RTGETOPT_REQ_NOTHING },
587 { "--sh-export", 'e', RTGETOPT_REQ_NOTHING },
588 { "--sh-eval", 'E', RTGETOPT_REQ_NOTHING },
589 { "--cmd-set", 's', RTGETOPT_REQ_NOTHING },
590 };
591 int rc = RTGetOptInit(&GetState, pArgs->argc, pArgs->argv, s_aOptions, RT_ELEMENTS(s_aOptions), 2, 0 /*fFlags*/);
592 AssertRCReturn(rc, RTEXITCODE_FAILURE);
593
594 while ((rc = RTGetOpt(&GetState, &ValueUnion)) != 0)
595 {
596 switch (rc)
597 {
598 case 'H':
599 fFlags = (fFlags & ~DEBUGVM_SHOW_FLAGS_FMT_MASK) | DEBUGVM_SHOW_FLAGS_HUMAN_READABLE;
600 break;
601
602 case 'e':
603 fFlags = (fFlags & ~DEBUGVM_SHOW_FLAGS_FMT_MASK) | DEBUGVM_SHOW_FLAGS_SH_EXPORT;
604 break;
605
606 case 'E':
607 fFlags = (fFlags & ~DEBUGVM_SHOW_FLAGS_FMT_MASK) | DEBUGVM_SHOW_FLAGS_SH_EVAL;
608 break;
609
610 case 's':
611 fFlags = (fFlags & ~DEBUGVM_SHOW_FLAGS_FMT_MASK) | DEBUGVM_SHOW_FLAGS_CMD_SET;
612 break;
613
614 case VINF_GETOPT_NOT_OPTION:
615 {
616 RTEXITCODE rcExit;
617 if (!strcmp(ValueUnion.psz, "log-settings"))
618 {
619 rcExit = handleDebugVM_Show_LogDbgSettings(pDebugger, fFlags);
620 if (rcExit == RTEXITCODE_SUCCESS)
621 rcExit = handleDebugVM_Show_LogRelSettings(pDebugger, fFlags);
622 }
623 else if (!strcmp(ValueUnion.psz, "logdbg-settings"))
624 rcExit = handleDebugVM_Show_LogDbgSettings(pDebugger, fFlags);
625 else if (!strcmp(ValueUnion.psz, "logrel-settings"))
626 rcExit = handleDebugVM_Show_LogRelSettings(pDebugger, fFlags);
627 else
628 rcExit = errorSyntax("The show sub-command has no idea what '%s' might be", ValueUnion.psz);
629 if (rcExit != RTEXITCODE_SUCCESS)
630 return rcExit;
631 break;
632 }
633
634 default:
635 return errorGetOpt(rc, &ValueUnion);
636 }
637 }
638 return RTEXITCODE_SUCCESS;
639}
640
641/**
642 * Handles the statistics sub-command.
643 *
644 * @returns Suitable exit code.
645 * @param pArgs The handler arguments.
646 * @param pDebugger Pointer to the debugger interface.
647 */
648static RTEXITCODE handleDebugVM_Statistics(HandlerArg *pArgs, IMachineDebugger *pDebugger)
649{
650 /*
651 * Parse arguments.
652 */
653 bool fWithDescriptions = false;
654 const char *pszPattern = NULL; /* all */
655 bool fReset = false;
656
657 RTGETOPTSTATE GetState;
658 RTGETOPTUNION ValueUnion;
659 static const RTGETOPTDEF s_aOptions[] =
660 {
661 { "--descriptions", 'd', RTGETOPT_REQ_NOTHING },
662 { "--pattern", 'p', RTGETOPT_REQ_STRING },
663 { "--reset", 'r', RTGETOPT_REQ_NOTHING },
664 };
665 int rc = RTGetOptInit(&GetState, pArgs->argc, pArgs->argv, s_aOptions, RT_ELEMENTS(s_aOptions), 2, 0 /*fFlags*/);
666 AssertRCReturn(rc, RTEXITCODE_FAILURE);
667
668 while ((rc = RTGetOpt(&GetState, &ValueUnion)) != 0)
669 {
670 switch (rc)
671 {
672 case 'd':
673 fWithDescriptions = true;
674 break;
675
676 case 'p':
677 if (pszPattern)
678 return errorSyntax("Multiple --pattern options are not permitted");
679 pszPattern = ValueUnion.psz;
680 break;
681
682 case 'r':
683 fReset = true;
684 break;
685
686 default:
687 return errorGetOpt(rc, &ValueUnion);
688 }
689 }
690
691 if (fReset && fWithDescriptions)
692 return errorSyntax("The --reset and --descriptions options does not mix");
693
694 /*
695 * Execute the order.
696 */
697 com::Bstr bstrPattern(pszPattern);
698 if (fReset)
699 CHECK_ERROR2I_RET(pDebugger, ResetStats(bstrPattern.raw()), RTEXITCODE_FAILURE);
700 else
701 {
702 com::Bstr bstrStats;
703 CHECK_ERROR2I_RET(pDebugger, GetStats(bstrPattern.raw(), fWithDescriptions, bstrStats.asOutParam()),
704 RTEXITCODE_FAILURE);
705 /* if (fFormatted)
706 { big mess }
707 else
708 */
709 RTPrintf("%ls\n", bstrStats.raw());
710 }
711
712 return RTEXITCODE_SUCCESS;
713}
714
715RTEXITCODE handleDebugVM(HandlerArg *pArgs)
716{
717 RTEXITCODE rcExit = RTEXITCODE_FAILURE;
718
719 /*
720 * The first argument is the VM name or UUID. Open a session to it.
721 */
722 if (pArgs->argc < 2)
723 return errorNoSubcommand();
724 ComPtr<IMachine> ptrMachine;
725 CHECK_ERROR2I_RET(pArgs->virtualBox, FindMachine(com::Bstr(pArgs->argv[0]).raw(), ptrMachine.asOutParam()), RTEXITCODE_FAILURE);
726 CHECK_ERROR2I_RET(ptrMachine, LockMachine(pArgs->session, LockType_Shared), RTEXITCODE_FAILURE);
727
728 /*
729 * Get the associated console and machine debugger.
730 */
731 HRESULT rc;
732 ComPtr<IConsole> ptrConsole;
733 CHECK_ERROR(pArgs->session, COMGETTER(Console)(ptrConsole.asOutParam()));
734 if (SUCCEEDED(rc))
735 {
736 if (ptrConsole.isNotNull())
737 {
738 ComPtr<IMachineDebugger> ptrDebugger;
739 CHECK_ERROR(ptrConsole, COMGETTER(Debugger)(ptrDebugger.asOutParam()));
740 if (SUCCEEDED(rc))
741 {
742 /*
743 * String switch on the sub-command.
744 */
745 const char *pszSubCmd = pArgs->argv[1];
746 if (!strcmp(pszSubCmd, "dumpvmcore"))
747 {
748 setCurrentSubcommand(HELP_SCOPE_DEBUGVM_DUMPVMCORE);
749 rcExit = handleDebugVM_DumpVMCore(pArgs, ptrDebugger);
750 }
751 else if (!strcmp(pszSubCmd, "getregisters"))
752 {
753 setCurrentSubcommand(HELP_SCOPE_DEBUGVM_GETREGISTERS);
754 rcExit = handleDebugVM_GetRegisters(pArgs, ptrDebugger);
755 }
756 else if (!strcmp(pszSubCmd, "info"))
757 {
758 setCurrentSubcommand(HELP_SCOPE_DEBUGVM_INFO);
759 rcExit = handleDebugVM_Info(pArgs, ptrDebugger);
760 }
761 else if (!strcmp(pszSubCmd, "injectnmi"))
762 {
763 setCurrentSubcommand(HELP_SCOPE_DEBUGVM_INJECTNMI);
764 rcExit = handleDebugVM_InjectNMI(pArgs, ptrDebugger);
765 }
766 else if (!strcmp(pszSubCmd, "log"))
767 {
768 setCurrentSubcommand(HELP_SCOPE_DEBUGVM_LOG);
769 rcExit = handleDebugVM_LogXXXX(pArgs, ptrDebugger, pszSubCmd);
770 }
771 else if (!strcmp(pszSubCmd, "logdest"))
772 {
773 setCurrentSubcommand(HELP_SCOPE_DEBUGVM_LOGDEST);
774 rcExit = handleDebugVM_LogXXXX(pArgs, ptrDebugger, pszSubCmd);
775 }
776 else if (!strcmp(pszSubCmd, "logflags"))
777 {
778 setCurrentSubcommand(HELP_SCOPE_DEBUGVM_LOGFLAGS);
779 rcExit = handleDebugVM_LogXXXX(pArgs, ptrDebugger, pszSubCmd);
780 }
781 else if (!strcmp(pszSubCmd, "osdetect"))
782 {
783 setCurrentSubcommand(HELP_SCOPE_DEBUGVM_OSDETECT);
784 rcExit = handleDebugVM_OSDetect(pArgs, ptrDebugger);
785 }
786 else if (!strcmp(pszSubCmd, "osinfo"))
787 {
788 setCurrentSubcommand(HELP_SCOPE_DEBUGVM_OSINFO);
789 rcExit = handleDebugVM_OSInfo(pArgs, ptrDebugger);
790 }
791 else if (!strcmp(pszSubCmd, "osdmesg"))
792 {
793 setCurrentSubcommand(HELP_SCOPE_DEBUGVM_OSDMESG);
794 rcExit = handleDebugVM_OSDmesg(pArgs, ptrDebugger);
795 }
796 else if (!strcmp(pszSubCmd, "setregisters"))
797 {
798 setCurrentSubcommand(HELP_SCOPE_DEBUGVM_SETREGISTERS);
799 rcExit = handleDebugVM_SetRegisters(pArgs, ptrDebugger);
800 }
801 else if (!strcmp(pszSubCmd, "show"))
802 {
803 setCurrentSubcommand(HELP_SCOPE_DEBUGVM_SHOW);
804 rcExit = handleDebugVM_Show(pArgs, ptrDebugger);
805 }
806 else if (!strcmp(pszSubCmd, "statistics"))
807 {
808 setCurrentSubcommand(HELP_SCOPE_DEBUGVM_STATISTICS);
809 rcExit = handleDebugVM_Statistics(pArgs, ptrDebugger);
810 }
811 else
812 errorUnknownSubcommand(pszSubCmd);
813 }
814 }
815 else
816 RTMsgError("Machine '%s' is not currently running.\n", pArgs->argv[0]);
817 }
818
819 pArgs->session->UnlockMachine();
820
821 return rcExit;
822}
823
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