VirtualBox

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

最後變更 在這個檔案從35036是 34971,由 vboxsync 提交於 14 年 前

VBoxManage: move vmstatistics to debugvm as a 'statistics' sub-command. Remove injectnmi completely from controlvm - the audience of this features is tiny but smart, so no need for compatibility stuff.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 7.3 KB
 
1/* $Id: VBoxManageDebugVM.cpp 34971 2010-12-11 23:12:01Z 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.alldomusa.eu.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 *
48 * @returns Suitable exit code.
49 * @param a The handler arguments.
50 * @param pDebugger Pointer to the debugger interface.
51 */
52static RTEXITCODE handleDebugVM_InjectNMI(HandlerArg *a, IMachineDebugger *pDebugger)
53{
54 if (a->argc != 2)
55 return errorSyntax(USAGE_DEBUGVM, "The inject sub-command does not take any arguments");
56 CHECK_ERROR2_RET(pDebugger, InjectNMI(), RTEXITCODE_FAILURE);
57 return RTEXITCODE_SUCCESS;
58}
59
60/**
61 * Handles the inject sub-command.
62 *
63 * @returns Suitable exit code.
64 * @param pArgs The handler arguments.
65 * @param pDebugger Pointer to the debugger interface.
66 */
67static RTEXITCODE handleDebugVM_DumpVMCore(HandlerArg *pArgs, IMachineDebugger *pDebugger)
68{
69 /*
70 * Parse arguments.
71 */
72 const char *pszFilename = NULL;
73
74 RTGETOPTSTATE GetState;
75 RTGETOPTUNION ValueUnion;
76 static const RTGETOPTDEF s_aOptions[] =
77 {
78 { "--filename", 'f', RTGETOPT_REQ_STRING }
79 };
80 int rc = RTGetOptInit(&GetState, pArgs->argc, pArgs->argv, s_aOptions, RT_ELEMENTS(s_aOptions), 2, 0 /*fFlags*/);
81 AssertRCReturn(rc, RTEXITCODE_FAILURE);
82
83 while ((rc = RTGetOpt(&GetState, &ValueUnion)) != 0)
84 {
85 switch (rc)
86 {
87 case 'f':
88 if (pszFilename)
89 return errorSyntax(USAGE_DEBUGVM, "The --filename option has already been given");
90 pszFilename = ValueUnion.psz;
91 break;
92 default:
93 return errorGetOpt(USAGE_DEBUGVM, rc, &ValueUnion);
94 }
95 }
96
97 if (!pszFilename)
98 return errorSyntax(USAGE_DEBUGVM, "The --filename option is required");
99
100 /*
101 * Make the filename absolute before handing it on to the API.
102 */
103 char szAbsFilename[RTPATH_MAX];
104 rc = RTPathAbs(pszFilename, szAbsFilename, sizeof(szAbsFilename));
105 if (RT_FAILURE(rc))
106 return RTMsgErrorExit(RTEXITCODE_FAILURE, "RTPathAbs failed on '%s': %Rrc", pszFilename, rc);
107
108 com::Bstr bstrFilename(szAbsFilename);
109 CHECK_ERROR2_RET(pDebugger, DumpGuestCore(bstrFilename.raw()), RTEXITCODE_FAILURE);
110 return RTEXITCODE_SUCCESS;
111}
112
113/**
114 * Handles the statistics sub-command.
115 *
116 * @returns Suitable exit code.
117 * @param pArgs The handler arguments.
118 * @param pDebugger Pointer to the debugger interface.
119 */
120static RTEXITCODE handleDebugVM_Statistics(HandlerArg *pArgs, IMachineDebugger *pDebugger)
121{
122 /*
123 * Parse arguments.
124 */
125 bool fWithDescriptions = false;
126 const char *pszPattern = NULL; /* all */
127 bool fReset = false;
128
129 RTGETOPTSTATE GetState;
130 RTGETOPTUNION ValueUnion;
131 static const RTGETOPTDEF s_aOptions[] =
132 {
133 { "--descriptions", 'd', RTGETOPT_REQ_NOTHING },
134 { "--pattern", 'p', RTGETOPT_REQ_STRING },
135 { "--reset", 'r', RTGETOPT_REQ_NOTHING },
136 };
137 int rc = RTGetOptInit(&GetState, pArgs->argc, pArgs->argv, s_aOptions, RT_ELEMENTS(s_aOptions), 2, 0 /*fFlags*/);
138 AssertRCReturn(rc, RTEXITCODE_FAILURE);
139
140 while ((rc = RTGetOpt(&GetState, &ValueUnion)) != 0)
141 {
142 switch (rc)
143 {
144 case 'd':
145 fWithDescriptions = true;
146 break;
147
148 case 'p':
149 if (pszPattern)
150 return errorSyntax(USAGE_DEBUGVM, "Multiple --pattern options are not permitted");
151 pszPattern = ValueUnion.psz;
152 break;
153
154 case 'r':
155 fReset = true;
156 break;
157
158 default:
159 return errorGetOpt(USAGE_DEBUGVM, rc, &ValueUnion);
160 }
161 }
162
163 if (fReset && fWithDescriptions)
164 return errorSyntax(USAGE_DEBUGVM, "The --reset and --descriptions options does not mix");
165
166 /*
167 * Execute the order.
168 */
169 com::Bstr bstrPattern(pszPattern);
170 if (fReset)
171 CHECK_ERROR2_RET(pDebugger, ResetStats(bstrPattern.raw()), RTEXITCODE_FAILURE);
172 else
173 {
174 com::Bstr bstrStats;
175 CHECK_ERROR2_RET(pDebugger, GetStats(bstrPattern.raw(), fWithDescriptions, bstrStats.asOutParam()),
176 RTEXITCODE_FAILURE);
177 /* if (fFormatted)
178 { big mess }
179 else
180 */
181 RTPrintf("%ls\n", bstrStats.raw());
182 }
183
184 return RTEXITCODE_SUCCESS;
185}
186
187int handleDebugVM(HandlerArg *pArgs)
188{
189 RTEXITCODE rcExit = RTEXITCODE_FAILURE;
190
191 /*
192 * The first argument is the VM name or UUID. Open a session to it.
193 */
194 if (pArgs->argc < 2)
195 return errorSyntax(USAGE_DEBUGVM, "Too few parameters");
196 ComPtr<IMachine> ptrMachine;
197 CHECK_ERROR2_RET(pArgs->virtualBox, FindMachine(com::Bstr(pArgs->argv[0]).raw(), ptrMachine.asOutParam()), RTEXITCODE_FAILURE);
198 CHECK_ERROR2_RET(ptrMachine, LockMachine(pArgs->session, LockType_Shared), RTEXITCODE_FAILURE);
199
200 /*
201 * Get the associated console and machine debugger.
202 */
203 HRESULT rc;
204 ComPtr<IConsole> ptrConsole;
205 CHECK_ERROR(pArgs->session, COMGETTER(Console)(ptrConsole.asOutParam()));
206 if (SUCCEEDED(rc))
207 {
208 ComPtr<IMachineDebugger> ptrDebugger;
209 CHECK_ERROR(ptrConsole, COMGETTER(Debugger)(ptrDebugger.asOutParam()));
210 if (SUCCEEDED(rc))
211 {
212 /*
213 * String switch on the sub-command.
214 */
215 const char *pszSubCmd = pArgs->argv[1];
216 if (!strcmp(pszSubCmd, "dumpguestcore"))
217 rcExit = handleDebugVM_DumpVMCore(pArgs, ptrDebugger);
218 else if (!strcmp(pszSubCmd, "injectnmi"))
219 rcExit = handleDebugVM_InjectNMI(pArgs, ptrDebugger);
220 else if (!strcmp(pszSubCmd, "statistics"))
221 rcExit = handleDebugVM_Statistics(pArgs, ptrDebugger);
222 else
223 errorSyntax(USAGE_DEBUGVM, "Invalid parameter '%s'", pArgs->argv[1]);
224 }
225 }
226
227 pArgs->session->UnlockMachine();
228
229 return rcExit;
230}
231
232
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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