1 | /* $Id: VBoxManageDebugVM.cpp 39668 2011-12-20 21:46:30Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxManage - Implementation of the debugvm command.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2010 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/EventQueue.h>
|
---|
29 |
|
---|
30 | #include <VBox/com/VirtualBox.h>
|
---|
31 |
|
---|
32 | #include <iprt/ctype.h>
|
---|
33 | #include <VBox/err.h>
|
---|
34 | #include <iprt/getopt.h>
|
---|
35 | #include <iprt/path.h>
|
---|
36 | #include <iprt/param.h>
|
---|
37 | #include <iprt/stream.h>
|
---|
38 | #include <iprt/string.h>
|
---|
39 | #include <iprt/uuid.h>
|
---|
40 | #include <VBox/log.h>
|
---|
41 |
|
---|
42 | #include "VBoxManage.h"
|
---|
43 |
|
---|
44 |
|
---|
45 | /**
|
---|
46 | * Handles the getregisters sub-command.
|
---|
47 | *
|
---|
48 | * @returns Suitable exit code.
|
---|
49 | * @param pArgs The handler arguments.
|
---|
50 | * @param pDebugger Pointer to the debugger interface.
|
---|
51 | */
|
---|
52 | static RTEXITCODE handleDebugVM_GetRegisters(HandlerArg *pArgs, IMachineDebugger *pDebugger)
|
---|
53 | {
|
---|
54 | /*
|
---|
55 | * We take a list of register names (case insensitive). If 'all' is
|
---|
56 | * encountered we'll dump all registers.
|
---|
57 | */
|
---|
58 | ULONG idCpu = 0;
|
---|
59 | unsigned cRegisters = 0;
|
---|
60 |
|
---|
61 | RTGETOPTSTATE GetState;
|
---|
62 | RTGETOPTUNION ValueUnion;
|
---|
63 | static const RTGETOPTDEF s_aOptions[] =
|
---|
64 | {
|
---|
65 | { "--cpu", 'c', RTGETOPT_REQ_UINT32 },
|
---|
66 | };
|
---|
67 | int rc = RTGetOptInit(&GetState, pArgs->argc, pArgs->argv, s_aOptions, RT_ELEMENTS(s_aOptions), 2, RTGETOPTINIT_FLAGS_OPTS_FIRST);
|
---|
68 | AssertRCReturn(rc, RTEXITCODE_FAILURE);
|
---|
69 |
|
---|
70 | while ((rc = RTGetOpt(&GetState, &ValueUnion)) != 0)
|
---|
71 | {
|
---|
72 | switch (rc)
|
---|
73 | {
|
---|
74 | case 'c':
|
---|
75 | idCpu = ValueUnion.u32;
|
---|
76 | break;
|
---|
77 |
|
---|
78 | case VINF_GETOPT_NOT_OPTION:
|
---|
79 | if (!RTStrICmp(ValueUnion.psz, "all"))
|
---|
80 | {
|
---|
81 | com::SafeArray<BSTR> aBstrNames;
|
---|
82 | com::SafeArray<BSTR> aBstrValues;
|
---|
83 | CHECK_ERROR2_RET(pDebugger, GetRegisters(idCpu, ComSafeArrayAsOutParam(aBstrNames), ComSafeArrayAsOutParam(aBstrValues)),
|
---|
84 | RTEXITCODE_FAILURE);
|
---|
85 | Assert(aBstrNames.size() == aBstrValues.size());
|
---|
86 |
|
---|
87 | size_t cchMaxName = 8;
|
---|
88 | for (size_t i = 0; i < aBstrNames.size(); i++)
|
---|
89 | {
|
---|
90 | size_t cchName = RTUtf16Len(aBstrNames[i]);
|
---|
91 | if (cchName > cchMaxName)
|
---|
92 | cchMaxName = cchName;
|
---|
93 | }
|
---|
94 |
|
---|
95 | for (size_t i = 0; i < aBstrNames.size(); i++)
|
---|
96 | RTPrintf("%-*ls = %ls\n", cchMaxName, aBstrNames[i], aBstrValues[i]);
|
---|
97 | }
|
---|
98 | else
|
---|
99 | {
|
---|
100 | com::Bstr bstrName = ValueUnion.psz;
|
---|
101 | com::Bstr bstrValue;
|
---|
102 | CHECK_ERROR2_RET(pDebugger, GetRegister(idCpu, bstrName.raw(), bstrValue.asOutParam()), RTEXITCODE_FAILURE);
|
---|
103 | RTPrintf("%s = %ls\n", ValueUnion.psz, bstrValue.raw());
|
---|
104 | }
|
---|
105 | cRegisters++;
|
---|
106 | break;
|
---|
107 |
|
---|
108 | default:
|
---|
109 | return errorGetOpt(USAGE_DEBUGVM, rc, &ValueUnion);
|
---|
110 | }
|
---|
111 | }
|
---|
112 |
|
---|
113 | if (!cRegisters)
|
---|
114 | return errorSyntax(USAGE_DEBUGVM, "The getregisters sub-command takes at least one register name");
|
---|
115 | return RTEXITCODE_SUCCESS;
|
---|
116 | }
|
---|
117 |
|
---|
118 | /**
|
---|
119 | * Handles the info sub-command.
|
---|
120 | *
|
---|
121 | * @returns Suitable exit code.
|
---|
122 | * @param a The handler arguments.
|
---|
123 | * @param pDebugger Pointer to the debugger interface.
|
---|
124 | */
|
---|
125 | static RTEXITCODE handleDebugVM_Info(HandlerArg *a, IMachineDebugger *pDebugger)
|
---|
126 | {
|
---|
127 | if (a->argc < 3 || a->argc > 4)
|
---|
128 | return errorSyntax(USAGE_DEBUGVM, "The inject sub-command takes at one or two arguments");
|
---|
129 |
|
---|
130 | com::Bstr bstrName(a->argv[2]);
|
---|
131 | com::Bstr bstrArgs(a->argv[3]);
|
---|
132 | com::Bstr bstrInfo;
|
---|
133 | CHECK_ERROR2_RET(pDebugger, Info(bstrName.raw(), bstrArgs.raw(), bstrInfo.asOutParam()), RTEXITCODE_FAILURE);
|
---|
134 | RTPrintf("%ls", bstrInfo.raw());
|
---|
135 | return RTEXITCODE_SUCCESS;
|
---|
136 | }
|
---|
137 |
|
---|
138 | /**
|
---|
139 | * Handles the inject sub-command.
|
---|
140 | *
|
---|
141 | * @returns Suitable exit code.
|
---|
142 | * @param a The handler arguments.
|
---|
143 | * @param pDebugger Pointer to the debugger interface.
|
---|
144 | */
|
---|
145 | static RTEXITCODE handleDebugVM_InjectNMI(HandlerArg *a, IMachineDebugger *pDebugger)
|
---|
146 | {
|
---|
147 | if (a->argc != 2)
|
---|
148 | return errorSyntax(USAGE_DEBUGVM, "The inject sub-command does not take any arguments");
|
---|
149 | CHECK_ERROR2_RET(pDebugger, InjectNMI(), RTEXITCODE_FAILURE);
|
---|
150 | return RTEXITCODE_SUCCESS;
|
---|
151 | }
|
---|
152 |
|
---|
153 | /**
|
---|
154 | * Handles the log sub-command.
|
---|
155 | *
|
---|
156 | * @returns Suitable exit code.
|
---|
157 | * @param pArgs The handler arguments.
|
---|
158 | * @param pDebugger Pointer to the debugger interface.
|
---|
159 | * @param pszSubCmd The sub command.
|
---|
160 | */
|
---|
161 | static RTEXITCODE handleDebugVM_LogXXXX(HandlerArg *pArgs, IMachineDebugger *pDebugger, const char *pszSubCmd)
|
---|
162 | {
|
---|
163 | /*
|
---|
164 | * Parse arguments.
|
---|
165 | */
|
---|
166 | bool fRelease = false;
|
---|
167 | com::Utf8Str strSettings;
|
---|
168 |
|
---|
169 | RTGETOPTSTATE GetState;
|
---|
170 | RTGETOPTUNION ValueUnion;
|
---|
171 | static const RTGETOPTDEF s_aOptions[] =
|
---|
172 | {
|
---|
173 | { "--release", 'r', RTGETOPT_REQ_NOTHING },
|
---|
174 | };
|
---|
175 | int rc = RTGetOptInit(&GetState, pArgs->argc, pArgs->argv, s_aOptions, RT_ELEMENTS(s_aOptions), 2, 0 /*fFlags*/);
|
---|
176 | AssertRCReturn(rc, RTEXITCODE_FAILURE);
|
---|
177 |
|
---|
178 | while ((rc = RTGetOpt(&GetState, &ValueUnion)) != 0)
|
---|
179 | {
|
---|
180 | switch (rc)
|
---|
181 | {
|
---|
182 | case 'r':
|
---|
183 | fRelease = true;
|
---|
184 | break;
|
---|
185 |
|
---|
186 | case 'd':
|
---|
187 | fRelease = false;
|
---|
188 | break;
|
---|
189 |
|
---|
190 | case VINF_GETOPT_NOT_OPTION:
|
---|
191 | if (strSettings.length() == 0)
|
---|
192 | strSettings = ValueUnion.psz;
|
---|
193 | else
|
---|
194 | {
|
---|
195 | strSettings.append(' ');
|
---|
196 | strSettings.append(ValueUnion.psz);
|
---|
197 | }
|
---|
198 | break;
|
---|
199 |
|
---|
200 | default:
|
---|
201 | return errorGetOpt(USAGE_DEBUGVM, rc, &ValueUnion);
|
---|
202 | }
|
---|
203 | }
|
---|
204 |
|
---|
205 | if (fRelease)
|
---|
206 | {
|
---|
207 | com::Utf8Str strTmp(strSettings);
|
---|
208 | strSettings = "release: ";
|
---|
209 | strSettings.append(strTmp);
|
---|
210 | }
|
---|
211 |
|
---|
212 | com::Bstr bstrSettings(strSettings);
|
---|
213 | if (!strcmp(pszSubCmd, "log"))
|
---|
214 | CHECK_ERROR2_RET(pDebugger, ModifyLogGroups(bstrSettings.raw()), RTEXITCODE_FAILURE);
|
---|
215 | else if (!strcmp(pszSubCmd, "logdest"))
|
---|
216 | CHECK_ERROR2_RET(pDebugger, ModifyLogDestinations(bstrSettings.raw()), RTEXITCODE_FAILURE);
|
---|
217 | else if (!strcmp(pszSubCmd, "logflags"))
|
---|
218 | CHECK_ERROR2_RET(pDebugger, ModifyLogFlags(bstrSettings.raw()), RTEXITCODE_FAILURE);
|
---|
219 | else
|
---|
220 | AssertFailedReturn(RTEXITCODE_FAILURE);
|
---|
221 |
|
---|
222 | return RTEXITCODE_SUCCESS;
|
---|
223 | }
|
---|
224 |
|
---|
225 |
|
---|
226 | /**
|
---|
227 | * Handles the inject sub-command.
|
---|
228 | *
|
---|
229 | * @returns Suitable exit code.
|
---|
230 | * @param pArgs The handler arguments.
|
---|
231 | * @param pDebugger Pointer to the debugger interface.
|
---|
232 | */
|
---|
233 | static RTEXITCODE handleDebugVM_DumpVMCore(HandlerArg *pArgs, IMachineDebugger *pDebugger)
|
---|
234 | {
|
---|
235 | /*
|
---|
236 | * Parse arguments.
|
---|
237 | */
|
---|
238 | const char *pszFilename = NULL;
|
---|
239 | const char *pszCompression = NULL;
|
---|
240 |
|
---|
241 | RTGETOPTSTATE GetState;
|
---|
242 | RTGETOPTUNION ValueUnion;
|
---|
243 | static const RTGETOPTDEF s_aOptions[] =
|
---|
244 | {
|
---|
245 | { "--filename", 'f', RTGETOPT_REQ_STRING },
|
---|
246 | { "--compression", 'c', RTGETOPT_REQ_STRING }
|
---|
247 | };
|
---|
248 | int rc = RTGetOptInit(&GetState, pArgs->argc, pArgs->argv, s_aOptions, RT_ELEMENTS(s_aOptions), 2, 0 /*fFlags*/);
|
---|
249 | AssertRCReturn(rc, RTEXITCODE_FAILURE);
|
---|
250 |
|
---|
251 | while ((rc = RTGetOpt(&GetState, &ValueUnion)) != 0)
|
---|
252 | {
|
---|
253 | switch (rc)
|
---|
254 | {
|
---|
255 | case 'c':
|
---|
256 | if (pszCompression)
|
---|
257 | return errorSyntax(USAGE_DEBUGVM, "The --compression option has already been given");
|
---|
258 | pszCompression = ValueUnion.psz;
|
---|
259 | break;
|
---|
260 | case 'f':
|
---|
261 | if (pszFilename)
|
---|
262 | return errorSyntax(USAGE_DEBUGVM, "The --filename option has already been given");
|
---|
263 | pszFilename = ValueUnion.psz;
|
---|
264 | break;
|
---|
265 | default:
|
---|
266 | return errorGetOpt(USAGE_DEBUGVM, rc, &ValueUnion);
|
---|
267 | }
|
---|
268 | }
|
---|
269 |
|
---|
270 | if (!pszFilename)
|
---|
271 | return errorSyntax(USAGE_DEBUGVM, "The --filename option is required");
|
---|
272 |
|
---|
273 | /*
|
---|
274 | * Make the filename absolute before handing it on to the API.
|
---|
275 | */
|
---|
276 | char szAbsFilename[RTPATH_MAX];
|
---|
277 | rc = RTPathAbs(pszFilename, szAbsFilename, sizeof(szAbsFilename));
|
---|
278 | if (RT_FAILURE(rc))
|
---|
279 | return RTMsgErrorExit(RTEXITCODE_FAILURE, "RTPathAbs failed on '%s': %Rrc", pszFilename, rc);
|
---|
280 |
|
---|
281 | com::Bstr bstrFilename(szAbsFilename);
|
---|
282 | com::Bstr bstrCompression(pszCompression);
|
---|
283 | CHECK_ERROR2_RET(pDebugger, DumpGuestCore(bstrFilename.raw(), bstrCompression.raw()), RTEXITCODE_FAILURE);
|
---|
284 | return RTEXITCODE_SUCCESS;
|
---|
285 | }
|
---|
286 |
|
---|
287 | /**
|
---|
288 | * Handles the os sub-command.
|
---|
289 | *
|
---|
290 | * @returns Suitable exit code.
|
---|
291 | * @param a The handler arguments.
|
---|
292 | * @param pDebugger Pointer to the debugger interface.
|
---|
293 | */
|
---|
294 | static RTEXITCODE handleDebugVM_OSDetect(HandlerArg *a, IMachineDebugger *pDebugger)
|
---|
295 | {
|
---|
296 | if (a->argc != 2)
|
---|
297 | return errorSyntax(USAGE_DEBUGVM, "The osdetect sub-command does not take any arguments");
|
---|
298 |
|
---|
299 | com::Bstr bstrName;
|
---|
300 | CHECK_ERROR2_RET(pDebugger, DetectOS(bstrName.asOutParam()), RTEXITCODE_FAILURE);
|
---|
301 | RTPrintf("Detected: %ls\n", bstrName.raw());
|
---|
302 | return RTEXITCODE_SUCCESS;
|
---|
303 | }
|
---|
304 |
|
---|
305 | /**
|
---|
306 | * Handles the os sub-command.
|
---|
307 | *
|
---|
308 | * @returns Suitable exit code.
|
---|
309 | * @param a The handler arguments.
|
---|
310 | * @param pDebugger Pointer to the debugger interface.
|
---|
311 | */
|
---|
312 | static RTEXITCODE handleDebugVM_OSInfo(HandlerArg *a, IMachineDebugger *pDebugger)
|
---|
313 | {
|
---|
314 | if (a->argc != 2)
|
---|
315 | return errorSyntax(USAGE_DEBUGVM, "The osinfo sub-command does not take any arguments");
|
---|
316 |
|
---|
317 | com::Bstr bstrName;
|
---|
318 | CHECK_ERROR2_RET(pDebugger, COMGETTER(OSName)(bstrName.asOutParam()), RTEXITCODE_FAILURE);
|
---|
319 | com::Bstr bstrVersion;
|
---|
320 | CHECK_ERROR2_RET(pDebugger, COMGETTER(OSVersion)(bstrVersion.asOutParam()), RTEXITCODE_FAILURE);
|
---|
321 | RTPrintf("Name: %ls\n", bstrName.raw());
|
---|
322 | RTPrintf("Version: %ls\n", bstrVersion.raw());
|
---|
323 | return RTEXITCODE_SUCCESS;
|
---|
324 | }
|
---|
325 |
|
---|
326 | /**
|
---|
327 | * Handles the setregisters sub-command.
|
---|
328 | *
|
---|
329 | * @returns Suitable exit code.
|
---|
330 | * @param pArgs The handler arguments.
|
---|
331 | * @param pDebugger Pointer to the debugger interface.
|
---|
332 | */
|
---|
333 | static RTEXITCODE handleDebugVM_SetRegisters(HandlerArg *pArgs, IMachineDebugger *pDebugger)
|
---|
334 | {
|
---|
335 | /*
|
---|
336 | * We take a list of register assignments, that is register=value.
|
---|
337 | */
|
---|
338 | ULONG idCpu = 0;
|
---|
339 | com::SafeArray<IN_BSTR> aBstrNames;
|
---|
340 | com::SafeArray<IN_BSTR> aBstrValues;
|
---|
341 |
|
---|
342 | RTGETOPTSTATE GetState;
|
---|
343 | RTGETOPTUNION ValueUnion;
|
---|
344 | static const RTGETOPTDEF s_aOptions[] =
|
---|
345 | {
|
---|
346 | { "--cpu", 'c', RTGETOPT_REQ_UINT32 },
|
---|
347 | };
|
---|
348 | int rc = RTGetOptInit(&GetState, pArgs->argc, pArgs->argv, s_aOptions, RT_ELEMENTS(s_aOptions), 2, RTGETOPTINIT_FLAGS_OPTS_FIRST);
|
---|
349 | AssertRCReturn(rc, RTEXITCODE_FAILURE);
|
---|
350 |
|
---|
351 | while ((rc = RTGetOpt(&GetState, &ValueUnion)) != 0)
|
---|
352 | {
|
---|
353 | switch (rc)
|
---|
354 | {
|
---|
355 | case 'c':
|
---|
356 | idCpu = ValueUnion.u32;
|
---|
357 | break;
|
---|
358 |
|
---|
359 | case VINF_GETOPT_NOT_OPTION:
|
---|
360 | {
|
---|
361 | const char *pszEqual = strchr(ValueUnion.psz, '=');
|
---|
362 | if (!pszEqual)
|
---|
363 | return errorSyntax(USAGE_DEBUGVM, "setregisters expects input on the form 'register=value' got '%s'", ValueUnion.psz);
|
---|
364 | try
|
---|
365 | {
|
---|
366 | com::Bstr bstrName(ValueUnion.psz, pszEqual - ValueUnion.psz);
|
---|
367 | com::Bstr bstrValue(pszEqual + 1);
|
---|
368 | if ( !aBstrNames.push_back(bstrName.raw())
|
---|
369 | || !aBstrValues.push_back(bstrValue.raw()))
|
---|
370 | throw std::bad_alloc();
|
---|
371 | }
|
---|
372 | catch (std::bad_alloc)
|
---|
373 | {
|
---|
374 | RTMsgError("Out of memory\n");
|
---|
375 | return RTEXITCODE_FAILURE;
|
---|
376 | }
|
---|
377 | break;
|
---|
378 | }
|
---|
379 |
|
---|
380 | default:
|
---|
381 | return errorGetOpt(USAGE_DEBUGVM, rc, &ValueUnion);
|
---|
382 | }
|
---|
383 | }
|
---|
384 |
|
---|
385 | if (!aBstrNames.size())
|
---|
386 | return errorSyntax(USAGE_DEBUGVM, "The setregisters sub-command takes at least one register name");
|
---|
387 |
|
---|
388 | /*
|
---|
389 | * If it is only one register, use the single register method just so
|
---|
390 | * we expose it and can test it from the command line.
|
---|
391 | */
|
---|
392 | if (aBstrNames.size() == 1)
|
---|
393 | {
|
---|
394 | CHECK_ERROR2_RET(pDebugger, SetRegister(idCpu, aBstrNames[0], aBstrValues[0]), RTEXITCODE_FAILURE);
|
---|
395 | RTPrintf("Successfully set %ls\n", aBstrNames[0]);
|
---|
396 | }
|
---|
397 | else
|
---|
398 | {
|
---|
399 | CHECK_ERROR2_RET(pDebugger, SetRegisters(idCpu, ComSafeArrayAsInParam(aBstrNames), ComSafeArrayAsInParam(aBstrValues)), RTEXITCODE_FAILURE);
|
---|
400 | RTPrintf("Successfully set %u registers\n", aBstrNames.size());
|
---|
401 | }
|
---|
402 |
|
---|
403 | return RTEXITCODE_SUCCESS;
|
---|
404 | }
|
---|
405 |
|
---|
406 | /**
|
---|
407 | * Handles the show sub-command.
|
---|
408 | *
|
---|
409 | * @returns Suitable exit code.
|
---|
410 | * @param pArgs The handler arguments.
|
---|
411 | * @param pDebugger Pointer to the debugger interface.
|
---|
412 | */
|
---|
413 | static RTEXITCODE handleDebugVM_Show(HandlerArg *pArgs, IMachineDebugger *pDebugger)
|
---|
414 | {
|
---|
415 | if (pArgs->argc != 3)
|
---|
416 | return errorSyntax(USAGE_DEBUGVM, "The show sub-command takes exactly one argument");
|
---|
417 |
|
---|
418 | const char *pszWhat = pArgs->argv[2];
|
---|
419 | if ( !strcmp(pszWhat, "log-settings")
|
---|
420 | || !strcmp(pszWhat, "logdbg-settings"))
|
---|
421 | {
|
---|
422 | com::Bstr bstrFlags;
|
---|
423 | CHECK_ERROR2_RET(pDebugger, COMGETTER(LogDbgFlags)(bstrFlags.asOutParam()), RTEXITCODE_FAILURE);
|
---|
424 | com::Bstr bstrGroups;
|
---|
425 | CHECK_ERROR2_RET(pDebugger, COMGETTER(LogDbgGroups)(bstrGroups.asOutParam()), RTEXITCODE_FAILURE);
|
---|
426 | com::Bstr bstrDestinations;
|
---|
427 | CHECK_ERROR2_RET(pDebugger, COMGETTER(LogDbgDestinations)(bstrDestinations.asOutParam()), RTEXITCODE_FAILURE);
|
---|
428 | RTPrintf("Debug log settings:\n");
|
---|
429 | RTPrintf(" VBOX_LOG=%ls\n"
|
---|
430 | " VBOX_LOG_FLAGS=%ls\n"
|
---|
431 | " VBOX_LOG_DEST=%ls\n"
|
---|
432 | , bstrGroups.raw(), bstrFlags.raw(), bstrDestinations.raw());
|
---|
433 | }
|
---|
434 | else if (!strcmp(pszWhat, "logrel-settings"))
|
---|
435 | {
|
---|
436 | com::Bstr bstrFlags;
|
---|
437 | CHECK_ERROR2_RET(pDebugger, COMGETTER(LogRelFlags)(bstrFlags.asOutParam()), RTEXITCODE_FAILURE);
|
---|
438 | com::Bstr bstrGroups;
|
---|
439 | CHECK_ERROR2_RET(pDebugger, COMGETTER(LogRelGroups)(bstrGroups.asOutParam()), RTEXITCODE_FAILURE);
|
---|
440 | com::Bstr bstrDestinations;
|
---|
441 | CHECK_ERROR2_RET(pDebugger, COMGETTER(LogRelDestinations)(bstrDestinations.asOutParam()), RTEXITCODE_FAILURE);
|
---|
442 | RTPrintf("Release log settings:\n");
|
---|
443 | RTPrintf(" VBOX_RELEASE_LOG=%ls\n"
|
---|
444 | " VBOX_RELEASE_LOG_FLAGS=%ls\n"
|
---|
445 | " VBOX_RELEASE_LOG_DEST=%ls\n"
|
---|
446 | , bstrGroups.raw(), bstrFlags.raw(), bstrDestinations.raw());
|
---|
447 | }
|
---|
448 | else
|
---|
449 | return errorSyntax(USAGE_DEBUGVM, "The show sub-command has no idea what '%s' might be", pszWhat);
|
---|
450 |
|
---|
451 | return RTEXITCODE_SUCCESS;
|
---|
452 | }
|
---|
453 |
|
---|
454 | /**
|
---|
455 | * Handles the statistics sub-command.
|
---|
456 | *
|
---|
457 | * @returns Suitable exit code.
|
---|
458 | * @param pArgs The handler arguments.
|
---|
459 | * @param pDebugger Pointer to the debugger interface.
|
---|
460 | */
|
---|
461 | static RTEXITCODE handleDebugVM_Statistics(HandlerArg *pArgs, IMachineDebugger *pDebugger)
|
---|
462 | {
|
---|
463 | /*
|
---|
464 | * Parse arguments.
|
---|
465 | */
|
---|
466 | bool fWithDescriptions = false;
|
---|
467 | const char *pszPattern = NULL; /* all */
|
---|
468 | bool fReset = false;
|
---|
469 |
|
---|
470 | RTGETOPTSTATE GetState;
|
---|
471 | RTGETOPTUNION ValueUnion;
|
---|
472 | static const RTGETOPTDEF s_aOptions[] =
|
---|
473 | {
|
---|
474 | { "--descriptions", 'd', RTGETOPT_REQ_NOTHING },
|
---|
475 | { "--pattern", 'p', RTGETOPT_REQ_STRING },
|
---|
476 | { "--reset", 'r', RTGETOPT_REQ_NOTHING },
|
---|
477 | };
|
---|
478 | int rc = RTGetOptInit(&GetState, pArgs->argc, pArgs->argv, s_aOptions, RT_ELEMENTS(s_aOptions), 2, 0 /*fFlags*/);
|
---|
479 | AssertRCReturn(rc, RTEXITCODE_FAILURE);
|
---|
480 |
|
---|
481 | while ((rc = RTGetOpt(&GetState, &ValueUnion)) != 0)
|
---|
482 | {
|
---|
483 | switch (rc)
|
---|
484 | {
|
---|
485 | case 'd':
|
---|
486 | fWithDescriptions = true;
|
---|
487 | break;
|
---|
488 |
|
---|
489 | case 'p':
|
---|
490 | if (pszPattern)
|
---|
491 | return errorSyntax(USAGE_DEBUGVM, "Multiple --pattern options are not permitted");
|
---|
492 | pszPattern = ValueUnion.psz;
|
---|
493 | break;
|
---|
494 |
|
---|
495 | case 'r':
|
---|
496 | fReset = true;
|
---|
497 | break;
|
---|
498 |
|
---|
499 | default:
|
---|
500 | return errorGetOpt(USAGE_DEBUGVM, rc, &ValueUnion);
|
---|
501 | }
|
---|
502 | }
|
---|
503 |
|
---|
504 | if (fReset && fWithDescriptions)
|
---|
505 | return errorSyntax(USAGE_DEBUGVM, "The --reset and --descriptions options does not mix");
|
---|
506 |
|
---|
507 | /*
|
---|
508 | * Execute the order.
|
---|
509 | */
|
---|
510 | com::Bstr bstrPattern(pszPattern);
|
---|
511 | if (fReset)
|
---|
512 | CHECK_ERROR2_RET(pDebugger, ResetStats(bstrPattern.raw()), RTEXITCODE_FAILURE);
|
---|
513 | else
|
---|
514 | {
|
---|
515 | com::Bstr bstrStats;
|
---|
516 | CHECK_ERROR2_RET(pDebugger, GetStats(bstrPattern.raw(), fWithDescriptions, bstrStats.asOutParam()),
|
---|
517 | RTEXITCODE_FAILURE);
|
---|
518 | /* if (fFormatted)
|
---|
519 | { big mess }
|
---|
520 | else
|
---|
521 | */
|
---|
522 | RTPrintf("%ls\n", bstrStats.raw());
|
---|
523 | }
|
---|
524 |
|
---|
525 | return RTEXITCODE_SUCCESS;
|
---|
526 | }
|
---|
527 |
|
---|
528 | int handleDebugVM(HandlerArg *pArgs)
|
---|
529 | {
|
---|
530 | RTEXITCODE rcExit = RTEXITCODE_FAILURE;
|
---|
531 |
|
---|
532 | /*
|
---|
533 | * The first argument is the VM name or UUID. Open a session to it.
|
---|
534 | */
|
---|
535 | if (pArgs->argc < 2)
|
---|
536 | return errorSyntax(USAGE_DEBUGVM, "Too few parameters");
|
---|
537 | ComPtr<IMachine> ptrMachine;
|
---|
538 | CHECK_ERROR2_RET(pArgs->virtualBox, FindMachine(com::Bstr(pArgs->argv[0]).raw(), ptrMachine.asOutParam()), RTEXITCODE_FAILURE);
|
---|
539 | CHECK_ERROR2_RET(ptrMachine, LockMachine(pArgs->session, LockType_Shared), RTEXITCODE_FAILURE);
|
---|
540 |
|
---|
541 | /*
|
---|
542 | * Get the associated console and machine debugger.
|
---|
543 | */
|
---|
544 | HRESULT rc;
|
---|
545 | ComPtr<IConsole> ptrConsole;
|
---|
546 | CHECK_ERROR(pArgs->session, COMGETTER(Console)(ptrConsole.asOutParam()));
|
---|
547 | if (SUCCEEDED(rc))
|
---|
548 | {
|
---|
549 | ComPtr<IMachineDebugger> ptrDebugger;
|
---|
550 | CHECK_ERROR(ptrConsole, COMGETTER(Debugger)(ptrDebugger.asOutParam()));
|
---|
551 | if (SUCCEEDED(rc))
|
---|
552 | {
|
---|
553 | /*
|
---|
554 | * String switch on the sub-command.
|
---|
555 | */
|
---|
556 | const char *pszSubCmd = pArgs->argv[1];
|
---|
557 | if (!strcmp(pszSubCmd, "dumpguestcore"))
|
---|
558 | rcExit = handleDebugVM_DumpVMCore(pArgs, ptrDebugger);
|
---|
559 | else if (!strcmp(pszSubCmd, "getregisters"))
|
---|
560 | rcExit = handleDebugVM_GetRegisters(pArgs, ptrDebugger);
|
---|
561 | else if (!strcmp(pszSubCmd, "info"))
|
---|
562 | rcExit = handleDebugVM_Info(pArgs, ptrDebugger);
|
---|
563 | else if (!strcmp(pszSubCmd, "injectnmi"))
|
---|
564 | rcExit = handleDebugVM_InjectNMI(pArgs, ptrDebugger);
|
---|
565 | else if (!strcmp(pszSubCmd, "log"))
|
---|
566 | rcExit = handleDebugVM_LogXXXX(pArgs, ptrDebugger, pszSubCmd);
|
---|
567 | else if (!strcmp(pszSubCmd, "logdest"))
|
---|
568 | rcExit = handleDebugVM_LogXXXX(pArgs, ptrDebugger, pszSubCmd);
|
---|
569 | else if (!strcmp(pszSubCmd, "logflags"))
|
---|
570 | rcExit = handleDebugVM_LogXXXX(pArgs, ptrDebugger, pszSubCmd);
|
---|
571 | else if (!strcmp(pszSubCmd, "osdetect"))
|
---|
572 | rcExit = handleDebugVM_OSDetect(pArgs, ptrDebugger);
|
---|
573 | else if (!strcmp(pszSubCmd, "osinfo"))
|
---|
574 | rcExit = handleDebugVM_OSInfo(pArgs, ptrDebugger);
|
---|
575 | else if (!strcmp(pszSubCmd, "setregisters"))
|
---|
576 | rcExit = handleDebugVM_SetRegisters(pArgs, ptrDebugger);
|
---|
577 | else if (!strcmp(pszSubCmd, "show"))
|
---|
578 | rcExit = handleDebugVM_Show(pArgs, ptrDebugger);
|
---|
579 | else if (!strcmp(pszSubCmd, "statistics"))
|
---|
580 | rcExit = handleDebugVM_Statistics(pArgs, ptrDebugger);
|
---|
581 | else
|
---|
582 | errorSyntax(USAGE_DEBUGVM, "Invalid parameter '%s'", pArgs->argv[1]);
|
---|
583 | }
|
---|
584 | }
|
---|
585 |
|
---|
586 | pArgs->session->UnlockMachine();
|
---|
587 |
|
---|
588 | return rcExit;
|
---|
589 | }
|
---|
590 |
|
---|