VirtualBox

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

Last change on this file since 34913 was 34913, checked in by vboxsync, 14 years ago

VBoxManage: Added a debugvm command for injectnmi and dumpguestcore.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.0 KB
Line 
1/* $Id: VBoxManageDebugVM.cpp 34913 2010-12-09 17:20:41Z vboxsync $ */
2/** @file
3 * VBoxManage - Implementation of the debugvm command.
4 */
5
6/*
7 * Copyright (C) 2006-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 inject sub-command.
47 * @returns Suitable exit code.
48 * @param a The handler arguments.
49 * @param pDebugger Pointer to the debugger interface.
50 */
51static RTEXITCODE handleDebugVM_InjectNMI(HandlerArg *a, IMachineDebugger *pDebugger)
52{
53 if (a->argc != 2)
54 return errorSyntax(USAGE_DEBUGVM, "The inject sub-command does not take any arguments");
55 CHECK_ERROR2_RET(pDebugger, InjectNMI(), RTEXITCODE_FAILURE);
56 return RTEXITCODE_SUCCESS;
57}
58
59/**
60 * Handles the inject sub-command.
61 * @returns Suitable exit code.
62 * @param pArgs The handler arguments.
63 * @param pDebugger Pointer to the debugger interface.
64 */
65static RTEXITCODE handleDebugVM_DumpVMCore(HandlerArg *pArgs, IMachineDebugger *pDebugger)
66{
67 /*
68 * Parse arguments.
69 */
70 const char *pszFilename = NULL;
71
72 RTGETOPTSTATE GetState;
73 RTGETOPTUNION ValueUnion;
74 static const RTGETOPTDEF s_aOptions[] =
75 {
76 { "--filename", 'f', RTGETOPT_REQ_STRING }
77 };
78 int rc = RTGetOptInit(&GetState, pArgs->argc, pArgs->argv, s_aOptions, RT_ELEMENTS(s_aOptions), 2, 0 /*fFlags*/);
79 AssertRCReturn(rc, RTEXITCODE_FAILURE);
80
81 while ((rc = RTGetOpt(&GetState, &ValueUnion)) != 0)
82 {
83 switch (rc)
84 {
85 case 'f':
86 if (pszFilename)
87 return errorSyntax(USAGE_DEBUGVM, "The --filename option has already been given");
88 pszFilename = ValueUnion.psz;
89 break;
90 default:
91 return errorGetOpt(USAGE_DEBUGVM, rc, &ValueUnion);
92 }
93 }
94
95 if (!pszFilename)
96 return errorSyntax(USAGE_DEBUGVM, "The --filename option is required");
97
98 /*
99 * Make the filename absolute before handing it on to the API.
100 */
101 char szAbsFilename[RTPATH_MAX];
102 rc = RTPathAbs(pszFilename, szAbsFilename, sizeof(szAbsFilename));
103 if (RT_FAILURE(rc))
104 return RTMsgErrorExit(RTEXITCODE_FAILURE, "RTPathAbs failed on '%s': %Rrc", pszFilename, rc);
105
106 com::Bstr bstrFilename(szAbsFilename);
107 CHECK_ERROR2_RET(pDebugger, DumpGuestCore(bstrFilename.raw()), RTEXITCODE_FAILURE);
108 return RTEXITCODE_SUCCESS;
109}
110
111int handleDebugVM(HandlerArg *pArgs)
112{
113 RTEXITCODE rcExit = RTEXITCODE_FAILURE;
114
115 /*
116 * The first argument is the VM name or UUID. Open a session to it.
117 */
118 if (pArgs->argc < 2)
119 return errorSyntax(USAGE_DEBUGVM, "Too few parameters");
120 ComPtr<IMachine> ptrMachine;
121 CHECK_ERROR2_RET(pArgs->virtualBox, FindMachine(com::Bstr(pArgs->argv[0]).raw(), ptrMachine.asOutParam()), RTEXITCODE_FAILURE);
122 CHECK_ERROR2_RET(ptrMachine, LockMachine(pArgs->session, LockType_Shared), RTEXITCODE_FAILURE);
123
124 /*
125 * Get the associated console and machine debugger.
126 */
127 HRESULT rc;
128 ComPtr<IConsole> ptrConsole;
129 CHECK_ERROR(pArgs->session, COMGETTER(Console)(ptrConsole.asOutParam()));
130 if (SUCCEEDED(rc))
131 {
132 ComPtr<IMachineDebugger> ptrDebugger;
133 CHECK_ERROR(ptrConsole, COMGETTER(Debugger)(ptrDebugger.asOutParam()));
134 if (SUCCEEDED(rc))
135 {
136 /*
137 * String switch on the sub-command.
138 */
139 const char *pszSubCmd = pArgs->argv[1];
140 if (!strcmp(pszSubCmd, "injectnmi"))
141 rcExit = handleDebugVM_InjectNMI(pArgs, ptrDebugger);
142 else if (!strcmp(pszSubCmd, "dumpguestcore"))
143 rcExit = handleDebugVM_DumpVMCore(pArgs, ptrDebugger);
144 else
145 errorSyntax(USAGE_DEBUGVM, "Invalid parameter '%s'", pArgs->argv[1]);
146 }
147 }
148
149 pArgs->session->UnlockMachine();
150
151 return rcExit;
152}
153
154
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