1 | /* $Id: DBGConsole.cpp 106377 2024-10-16 13:43:29Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * DBGC - Debugger Console.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2024 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
26 | */
|
---|
27 |
|
---|
28 |
|
---|
29 | /** @page pg_dbgc DBGC - The Debug Console
|
---|
30 | *
|
---|
31 | * The debugger console is an early attempt to make some interactive
|
---|
32 | * debugging facilities for the VirtualBox VMM. It was initially only
|
---|
33 | * accessible thru a telnet session in debug builds. Later it was hastily built
|
---|
34 | * into the VBoxDbg module with a very simple Qt wrapper around it.
|
---|
35 | *
|
---|
36 | * The current state is that it's by default shipped with all standard
|
---|
37 | * VirtualBox builds. The GUI component is by default accessible in all
|
---|
38 | * non-release builds, while release builds require extra data, environment or
|
---|
39 | * command line options to make it visible.
|
---|
40 | *
|
---|
41 | * Now, even if we ship it with all standard builds we would like it to remain
|
---|
42 | * an optional feature that can be omitted when building VirtualBox. Therefore,
|
---|
43 | * all external code interfacing DBGC need to be enclosed in
|
---|
44 | * \#ifdef VBOX_WITH_DEBUGGER blocks. This is mandatory for components that
|
---|
45 | * register external commands.
|
---|
46 | *
|
---|
47 | *
|
---|
48 | * @section sec_dbgc_op Operation
|
---|
49 | *
|
---|
50 | * The console will process commands in a manner similar to the OS/2 and Windows
|
---|
51 | * kernel debuggers. This means ';' is a command separator and that when
|
---|
52 | * possible we'll use the same command names as these two uses. As an
|
---|
53 | * alternative we intent to provide a set of gdb-like commands as well and let
|
---|
54 | * the user decide which should take precedence.
|
---|
55 | *
|
---|
56 | *
|
---|
57 | * @subsection sec_dbg_op_numbers Numbers
|
---|
58 | *
|
---|
59 | * Numbers are hexadecimal unless specified with a prefix indicating
|
---|
60 | * elsewise. Prefixes:
|
---|
61 | * - '0x' - hexadecimal.
|
---|
62 | * - '0n' - decimal
|
---|
63 | * - '0t' - octal.
|
---|
64 | * - '0y' - binary.
|
---|
65 | *
|
---|
66 | * Some of the prefixes are a bit uncommon, the reason for this that the
|
---|
67 | * typical binary prefix '0b' can also be a hexadecimal value since no prefix or
|
---|
68 | * suffix is required for such values. Ditto for '0n' and '0' for decimal and
|
---|
69 | * octal.
|
---|
70 | *
|
---|
71 | * The '`' can be used in the numeric value to separate parts as the user
|
---|
72 | * wishes. Generally, though the debugger may use it in output as thousand
|
---|
73 | * separator in decimal numbers and 32-bit separator in hex numbers.
|
---|
74 | *
|
---|
75 | * For historical reasons, a 'h' suffix is suffered on hex numbers. Unlike most
|
---|
76 | * assemblers, a leading 0 before a-f is not required with the 'h' suffix.
|
---|
77 | *
|
---|
78 | * The prefix '0i' can be used instead of '0n', as it was the early decimal
|
---|
79 | * prefix employed by DBGC. It's being deprecated and may be removed later.
|
---|
80 | *
|
---|
81 | *
|
---|
82 | * @subsection sec_dbg_op_strings Strings and Symbols
|
---|
83 | *
|
---|
84 | * The debugger will try to guess, convert or promote what the type of an
|
---|
85 | * argument to a command, function or operator based on the input description of
|
---|
86 | * the receiver. If the user wants to make it clear to the debugger that
|
---|
87 | * something is a string, put it inside double quotes. Symbols should use
|
---|
88 | * single quotes, though we're current still a bit flexible on this point.
|
---|
89 | *
|
---|
90 | * If you need to put a quote character inside the quoted text, you escape it by
|
---|
91 | * repating it once: echo "printf(""hello world"");"
|
---|
92 | *
|
---|
93 | *
|
---|
94 | * @subsection sec_dbg_op_address Addressing modes
|
---|
95 | *
|
---|
96 | * - Default is flat. For compatibility '%' also means flat.
|
---|
97 | * - Segmented addresses are specified selector:offset.
|
---|
98 | * - Physical addresses are specified using '%%'.
|
---|
99 | * - The default target for the addressing is the guest context, the '#'
|
---|
100 | * will override this and set it to the host.
|
---|
101 | * Note that several operations won't work on host addresses.
|
---|
102 | *
|
---|
103 | * The '%', '%%' and '#' prefixes is implemented as unary operators, while ':'
|
---|
104 | * is a binary operator. Operator precedence takes care of evaluation order.
|
---|
105 | *
|
---|
106 | *
|
---|
107 | * @subsection sec_dbg_op_c_operators C/C++ Operators
|
---|
108 | *
|
---|
109 | * Most unary and binary arithmetic, comparison, logical and bitwise C/C++
|
---|
110 | * operators are supported by the debugger, with the same precedence rules of
|
---|
111 | * course. There is one notable change made due to the unary '%' and '%%'
|
---|
112 | * operators, and that is that the modulo (remainder) operator is called 'mod'
|
---|
113 | * instead of '%'. This saves a lot of trouble separating argument.
|
---|
114 | *
|
---|
115 | * There are no assignment operators. Instead some simple global variable space
|
---|
116 | * is provided thru the 'set' and 'unset' commands and the unary '$' operator.
|
---|
117 | *
|
---|
118 | *
|
---|
119 | * @subsection sec_dbg_op_registers Registers
|
---|
120 | *
|
---|
121 | * All registers and their sub-fields exposed by the DBGF API are accessible via
|
---|
122 | * the '\@' operator. A few CPU register are accessible directly (as symbols)
|
---|
123 | * without using the '\@' operator. Hypervisor registers are accessible by
|
---|
124 | * prefixing the register name with a dot ('.').
|
---|
125 | *
|
---|
126 | *
|
---|
127 | * @subsection sec_dbg_op_commands Commands
|
---|
128 | *
|
---|
129 | * Commands names are case sensitive. By convention they are lower cased, starts
|
---|
130 | * with a letter but may contain digits and underscores afterwards. Operators
|
---|
131 | * are not allowed in the name (not even part of it), as we would risk
|
---|
132 | * misunderstanding it otherwise.
|
---|
133 | *
|
---|
134 | * Commands returns a status code.
|
---|
135 | *
|
---|
136 | * The '.' prefix indicates the set of external commands. External commands are
|
---|
137 | * command registered by VMM components.
|
---|
138 | *
|
---|
139 | *
|
---|
140 | * @subsection sec_dbg_op_functions Functions
|
---|
141 | *
|
---|
142 | * Functions are similar to commands, but return a variable and can only be used
|
---|
143 | * as part of an expression making up the argument of a command, function,
|
---|
144 | * operator or language statement (if we get around to implement that).
|
---|
145 | *
|
---|
146 | *
|
---|
147 | * @section sec_dbgc_logging Logging
|
---|
148 | *
|
---|
149 | * The idea is to be able to pass thru debug and release logs to the console
|
---|
150 | * if the user so wishes. This feature requires some kind of hook into the
|
---|
151 | * logger instance and while this was sketched it hasn't yet been implemented
|
---|
152 | * (dbgcProcessLog and DBGC::fLog).
|
---|
153 | *
|
---|
154 | * This feature has not materialized and probably never will.
|
---|
155 | *
|
---|
156 | *
|
---|
157 | * @section sec_dbgc_linking Linking and API
|
---|
158 | *
|
---|
159 | * The DBGC code is linked into the VBoxVMM module.
|
---|
160 | *
|
---|
161 | * IMachineDebugger may one day be extended with a DBGC interface so we can work
|
---|
162 | * with DBGC remotely without requiring TCP. Some questions about callbacks
|
---|
163 | * (for output) and security (you may wish to restrict users from debugging a
|
---|
164 | * VM) needs to be answered first though.
|
---|
165 | */
|
---|
166 |
|
---|
167 |
|
---|
168 | /*********************************************************************************************************************************
|
---|
169 | * Header Files *
|
---|
170 | *********************************************************************************************************************************/
|
---|
171 | #define LOG_GROUP LOG_GROUP_DBGC
|
---|
172 | #include <VBox/dbg.h>
|
---|
173 | #include <VBox/vmm/cfgm.h>
|
---|
174 | #include <VBox/vmm/dbgf.h>
|
---|
175 | #include <VBox/vmm/vmapi.h> /* VMR3GetVM() */
|
---|
176 | #include <VBox/vmm/hm.h> /* HMR3IsEnabled */
|
---|
177 | #include <VBox/vmm/nem.h> /* NEMR3IsEnabled */
|
---|
178 | #include <VBox/err.h>
|
---|
179 | #include <VBox/log.h>
|
---|
180 |
|
---|
181 | #include <iprt/asm.h>
|
---|
182 | #include <iprt/assert.h>
|
---|
183 | #include <iprt/file.h>
|
---|
184 | #include <iprt/mem.h>
|
---|
185 | #include <iprt/path.h>
|
---|
186 | #include <iprt/string.h>
|
---|
187 |
|
---|
188 | #include "DBGCInternal.h"
|
---|
189 | #include "DBGPlugIns.h"
|
---|
190 |
|
---|
191 |
|
---|
192 | /*********************************************************************************************************************************
|
---|
193 | * Internal Functions *
|
---|
194 | *********************************************************************************************************************************/
|
---|
195 | static int dbgcProcessLog(PDBGC pDbgc);
|
---|
196 |
|
---|
197 |
|
---|
198 | /**
|
---|
199 | * Resolves a symbol (or tries to do so at least).
|
---|
200 | *
|
---|
201 | * @returns 0 on success.
|
---|
202 | * @returns VBox status on failure.
|
---|
203 | * @param pDbgc The debug console instance.
|
---|
204 | * @param pszSymbol The symbol name.
|
---|
205 | * @param enmType The result type. Specifying DBGCVAR_TYPE_GC_FAR may
|
---|
206 | * cause failure, avoid it.
|
---|
207 | * @param pResult Where to store the result.
|
---|
208 | */
|
---|
209 | int dbgcSymbolGet(PDBGC pDbgc, const char *pszSymbol, DBGCVARTYPE enmType, PDBGCVAR pResult)
|
---|
210 | {
|
---|
211 | int rc;
|
---|
212 |
|
---|
213 | /*
|
---|
214 | * Builtin?
|
---|
215 | */
|
---|
216 | PCDBGCSYM pSymDesc = dbgcLookupRegisterSymbol(pDbgc, pszSymbol);
|
---|
217 | if (pSymDesc)
|
---|
218 | {
|
---|
219 | if (!pSymDesc->pfnGet)
|
---|
220 | return VERR_DBGC_PARSE_WRITEONLY_SYMBOL;
|
---|
221 | return pSymDesc->pfnGet(pSymDesc, &pDbgc->CmdHlp, enmType, pResult);
|
---|
222 | }
|
---|
223 |
|
---|
224 | /*
|
---|
225 | * A typical register? (Guest only)
|
---|
226 | */
|
---|
227 | static const char s_szSixLetterRegisters[] =
|
---|
228 | "rflags;eflags;"
|
---|
229 | ;
|
---|
230 | static const char s_szThreeLetterRegisters[] =
|
---|
231 | "eax;rax;" "r10;" "r8d;r8w;r8b;" "cr0;" "dr0;"
|
---|
232 | "ebx;rbx;" "r11;" "r9d;r9w;r8b;" "dr1;"
|
---|
233 | "ecx;rcx;" "r12;" "cr2;" "dr2;"
|
---|
234 | "edx;rdx;" "r13;" "cr3;" "dr3;"
|
---|
235 | "edi;rdi;dil;" "r14;" "cr4;" "dr4;"
|
---|
236 | "esi;rsi;sil;" "r15;" "cr8;"
|
---|
237 | "ebp;rbp;"
|
---|
238 | "esp;rsp;" "dr6;"
|
---|
239 | "rip;eip;" "dr7;"
|
---|
240 | "efl;"
|
---|
241 | ;
|
---|
242 | static const char s_szTwoLetterRegisters[] =
|
---|
243 | "ax;al;ah;" "r8;"
|
---|
244 | "bx;bl;bh;" "r9;"
|
---|
245 | "cx;cl;ch;" "cs;"
|
---|
246 | "dx;dl;dh;" "ds;"
|
---|
247 | "di;" "es;"
|
---|
248 | "si;" "fs;"
|
---|
249 | "bp;" "gs;"
|
---|
250 | "sp;" "ss;"
|
---|
251 | "ip;"
|
---|
252 | ;
|
---|
253 | const char *pszRegSym = *pszSymbol == '.' ? pszSymbol + 1 : pszSymbol;
|
---|
254 | size_t const cchRegSym = strlen(pszRegSym);
|
---|
255 | if ( (cchRegSym == 2 && strstr(s_szTwoLetterRegisters, pszRegSym))
|
---|
256 | || (cchRegSym == 3 && strstr(s_szThreeLetterRegisters, pszRegSym))
|
---|
257 | || (cchRegSym == 6 && strstr(s_szSixLetterRegisters, pszRegSym)))
|
---|
258 | {
|
---|
259 | if (!strchr(pszSymbol, ';'))
|
---|
260 | {
|
---|
261 | DBGCVAR Var;
|
---|
262 | DBGCVAR_INIT_SYMBOL(&Var, pszSymbol);
|
---|
263 | rc = dbgcOpRegister(pDbgc, &Var, DBGCVAR_CAT_ANY, pResult);
|
---|
264 | if (RT_SUCCESS(rc))
|
---|
265 | return DBGCCmdHlpConvert(&pDbgc->CmdHlp, pResult, enmType, false /*fConvSyms*/, pResult);
|
---|
266 | }
|
---|
267 | }
|
---|
268 |
|
---|
269 | /*
|
---|
270 | * Ask PDM.
|
---|
271 | */
|
---|
272 | /** @todo resolve symbols using PDM. */
|
---|
273 |
|
---|
274 | /*
|
---|
275 | * Ask the debug info manager.
|
---|
276 | */
|
---|
277 | RTDBGSYMBOL Symbol;
|
---|
278 | rc = DBGFR3AsSymbolByName(pDbgc->pUVM, pDbgc->hDbgAs, pszSymbol, &Symbol, NULL);
|
---|
279 | if (RT_SUCCESS(rc))
|
---|
280 | {
|
---|
281 | /*
|
---|
282 | * Default return is a flat gc address.
|
---|
283 | */
|
---|
284 | DBGCVAR_INIT_GC_FLAT(pResult, Symbol.Value);
|
---|
285 | if (Symbol.cb)
|
---|
286 | DBGCVAR_SET_RANGE(pResult, DBGCVAR_RANGE_BYTES, Symbol.cb);
|
---|
287 |
|
---|
288 | switch (enmType)
|
---|
289 | {
|
---|
290 | /* nothing to do. */
|
---|
291 | case DBGCVAR_TYPE_GC_FLAT:
|
---|
292 | case DBGCVAR_TYPE_ANY:
|
---|
293 | return VINF_SUCCESS;
|
---|
294 |
|
---|
295 | /* impossible at the moment. */
|
---|
296 | case DBGCVAR_TYPE_GC_FAR:
|
---|
297 | return VERR_DBGC_PARSE_CONVERSION_FAILED;
|
---|
298 |
|
---|
299 | /* simply make it numeric. */
|
---|
300 | case DBGCVAR_TYPE_NUMBER:
|
---|
301 | pResult->enmType = DBGCVAR_TYPE_NUMBER;
|
---|
302 | pResult->u.u64Number = Symbol.Value;
|
---|
303 | return VINF_SUCCESS;
|
---|
304 |
|
---|
305 | /* cast it. */
|
---|
306 | case DBGCVAR_TYPE_GC_PHYS:
|
---|
307 | case DBGCVAR_TYPE_HC_FLAT:
|
---|
308 | case DBGCVAR_TYPE_HC_PHYS:
|
---|
309 | return DBGCCmdHlpConvert(&pDbgc->CmdHlp, pResult, enmType, false /*fConvSyms*/, pResult);
|
---|
310 |
|
---|
311 | default:
|
---|
312 | AssertMsgFailed(("Internal error enmType=%d\n", enmType));
|
---|
313 | return VERR_INVALID_PARAMETER;
|
---|
314 | }
|
---|
315 | }
|
---|
316 |
|
---|
317 | return VERR_DBGC_PARSE_NOT_IMPLEMENTED;
|
---|
318 | }
|
---|
319 |
|
---|
320 |
|
---|
321 | /**
|
---|
322 | * Process all commands currently in the buffer.
|
---|
323 | *
|
---|
324 | * @returns VBox status code. Any error indicates the termination of the console session.
|
---|
325 | * @param pDbgc Debugger console instance data.
|
---|
326 | * @param fNoExecute Indicates that no commands should actually be executed.
|
---|
327 | */
|
---|
328 | static int dbgcProcessCommands(PDBGC pDbgc, bool fNoExecute)
|
---|
329 | {
|
---|
330 | /** @todo Replace this with a sh/ksh/csh/rexx like toplevel language that
|
---|
331 | * allows doing function, loops, if, cases, and such. */
|
---|
332 | int rc = VINF_SUCCESS;
|
---|
333 | while (pDbgc->cInputLines)
|
---|
334 | {
|
---|
335 | /*
|
---|
336 | * Empty the log buffer if we're hooking the log.
|
---|
337 | */
|
---|
338 | if (pDbgc->fLog)
|
---|
339 | {
|
---|
340 | rc = dbgcProcessLog(pDbgc);
|
---|
341 | if (RT_FAILURE(rc))
|
---|
342 | break;
|
---|
343 | }
|
---|
344 |
|
---|
345 | if (pDbgc->iRead == pDbgc->iWrite)
|
---|
346 | {
|
---|
347 | AssertMsgFailed(("The input buffer is empty while cInputLines=%d!\n", pDbgc->cInputLines));
|
---|
348 | pDbgc->cInputLines = 0;
|
---|
349 | return 0;
|
---|
350 | }
|
---|
351 |
|
---|
352 | /*
|
---|
353 | * Copy the command to the parse buffer.
|
---|
354 | */
|
---|
355 | char chQuote = 0;
|
---|
356 | char ch;
|
---|
357 | char *psz = &pDbgc->achInput[pDbgc->iRead];
|
---|
358 | char *pszTrg = &pDbgc->achScratch[0];
|
---|
359 | AssertCompile(sizeof(pDbgc->achScratch) > sizeof(pDbgc->achInput));
|
---|
360 | while ((ch = *psz++) != '\0')
|
---|
361 | {
|
---|
362 | /* ';' and '\n' are termination characters, except for when they are
|
---|
363 | inside quotes. So, track quoting. */
|
---|
364 | if (ch == '"' || ch == '\'')
|
---|
365 | chQuote = chQuote == ch ? 0 : chQuote == 0 ? ch : chQuote;
|
---|
366 | else if ((ch == ';' || ch == '\n') && chQuote == 0)
|
---|
367 | break;
|
---|
368 |
|
---|
369 | *pszTrg = ch;
|
---|
370 |
|
---|
371 | if (psz == &pDbgc->achInput[sizeof(pDbgc->achInput)])
|
---|
372 | psz = &pDbgc->achInput[0];
|
---|
373 |
|
---|
374 | /** @todo r=bird: off by one issue here? */
|
---|
375 | if (psz == &pDbgc->achInput[pDbgc->iWrite])
|
---|
376 | {
|
---|
377 | AssertMsgFailed(("The buffer contains no commands while cInputLines=%d!\n", pDbgc->cInputLines));
|
---|
378 | pDbgc->cInputLines = 0;
|
---|
379 | pDbgc->iRead = pDbgc->iWrite;
|
---|
380 | return 0;
|
---|
381 | }
|
---|
382 |
|
---|
383 | pszTrg++;
|
---|
384 | }
|
---|
385 | *pszTrg = '\0';
|
---|
386 |
|
---|
387 | /*
|
---|
388 | * Advance the buffer.
|
---|
389 | */
|
---|
390 | pDbgc->iRead = psz - &pDbgc->achInput[0];
|
---|
391 | if (ch == '\n')
|
---|
392 | pDbgc->cInputLines--;
|
---|
393 |
|
---|
394 | /*
|
---|
395 | * Parse and execute this command.
|
---|
396 | */
|
---|
397 | pDbgc->pszScratch = pszTrg + 1;
|
---|
398 | pDbgc->iArg = 0;
|
---|
399 | rc = dbgcEvalCommand(pDbgc, &pDbgc->achScratch[0], pszTrg - &pDbgc->achScratch[0], fNoExecute);
|
---|
400 | if ( rc == VERR_DBGC_QUIT
|
---|
401 | || rc == VWRN_DBGC_CMD_PENDING)
|
---|
402 | break;
|
---|
403 | rc = VINF_SUCCESS; /* ignore other statuses */
|
---|
404 | }
|
---|
405 |
|
---|
406 | return rc;
|
---|
407 | }
|
---|
408 |
|
---|
409 |
|
---|
410 | /**
|
---|
411 | * Handle input buffer overflow.
|
---|
412 | *
|
---|
413 | * Will read any available input looking for a '\n' to reset the buffer on.
|
---|
414 | *
|
---|
415 | * @returns VBox status code.
|
---|
416 | * @param pDbgc Debugger console instance data.
|
---|
417 | */
|
---|
418 | static int dbgcInputOverflow(PDBGC pDbgc)
|
---|
419 | {
|
---|
420 | /*
|
---|
421 | * Assert overflow status and reset the input buffer.
|
---|
422 | */
|
---|
423 | if (!pDbgc->fInputOverflow)
|
---|
424 | {
|
---|
425 | pDbgc->fInputOverflow = true;
|
---|
426 | pDbgc->iRead = pDbgc->iWrite = 0;
|
---|
427 | pDbgc->cInputLines = 0;
|
---|
428 | pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "Input overflow!!\n");
|
---|
429 | }
|
---|
430 |
|
---|
431 | /*
|
---|
432 | * Eat input till no more or there is a '\n'.
|
---|
433 | * When finding a '\n' we'll continue normal processing.
|
---|
434 | */
|
---|
435 | while (pDbgc->pIo->pfnInput(pDbgc->pIo, 0))
|
---|
436 | {
|
---|
437 | size_t cbRead;
|
---|
438 | int rc = pDbgc->pIo->pfnRead(pDbgc->pIo, &pDbgc->achInput[0], sizeof(pDbgc->achInput) - 1, &cbRead);
|
---|
439 | if (RT_FAILURE(rc))
|
---|
440 | return rc;
|
---|
441 | char *psz = (char *)memchr(&pDbgc->achInput[0], '\n', cbRead);
|
---|
442 | if (psz)
|
---|
443 | {
|
---|
444 | pDbgc->fInputOverflow = false;
|
---|
445 | pDbgc->iRead = psz - &pDbgc->achInput[0] + 1;
|
---|
446 | pDbgc->iWrite = (unsigned)cbRead;
|
---|
447 | pDbgc->cInputLines = 0;
|
---|
448 | break;
|
---|
449 | }
|
---|
450 | }
|
---|
451 |
|
---|
452 | return 0;
|
---|
453 | }
|
---|
454 |
|
---|
455 |
|
---|
456 | /**
|
---|
457 | * Read input and do some preprocessing.
|
---|
458 | *
|
---|
459 | * @returns VBox status code.
|
---|
460 | * In addition to the iWrite and achInput, cInputLines is maintained.
|
---|
461 | * In case of an input overflow the fInputOverflow flag will be set.
|
---|
462 | * @param pDbgc Debugger console instance data.
|
---|
463 | */
|
---|
464 | static int dbgcInputRead(PDBGC pDbgc)
|
---|
465 | {
|
---|
466 | /*
|
---|
467 | * We have ready input.
|
---|
468 | * Read it till we don't have any or we have a full input buffer.
|
---|
469 | */
|
---|
470 | int rc = 0;
|
---|
471 | do
|
---|
472 | {
|
---|
473 | /*
|
---|
474 | * More available buffer space?
|
---|
475 | */
|
---|
476 | size_t cbLeft;
|
---|
477 | if (pDbgc->iWrite > pDbgc->iRead)
|
---|
478 | cbLeft = sizeof(pDbgc->achInput) - pDbgc->iWrite - (pDbgc->iRead == 0);
|
---|
479 | else
|
---|
480 | cbLeft = pDbgc->iRead - pDbgc->iWrite - 1;
|
---|
481 | if (!cbLeft)
|
---|
482 | {
|
---|
483 | /* overflow? */
|
---|
484 | if (!pDbgc->cInputLines)
|
---|
485 | rc = dbgcInputOverflow(pDbgc);
|
---|
486 | break;
|
---|
487 | }
|
---|
488 |
|
---|
489 | /*
|
---|
490 | * Read one char and interpret it.
|
---|
491 | */
|
---|
492 | char achRead[128];
|
---|
493 | size_t cbRead;
|
---|
494 | rc = pDbgc->pIo->pfnRead(pDbgc->pIo, &achRead[0], RT_MIN(cbLeft, sizeof(achRead)), &cbRead);
|
---|
495 | if (RT_FAILURE(rc))
|
---|
496 | return rc;
|
---|
497 | char *psz = &achRead[0];
|
---|
498 | while (cbRead-- > 0)
|
---|
499 | {
|
---|
500 | char ch = *psz++;
|
---|
501 | switch (ch)
|
---|
502 | {
|
---|
503 | /*
|
---|
504 | * Ignore.
|
---|
505 | */
|
---|
506 | case '\0':
|
---|
507 | case '\r':
|
---|
508 | case '\a':
|
---|
509 | break;
|
---|
510 |
|
---|
511 | /*
|
---|
512 | * Backspace.
|
---|
513 | */
|
---|
514 | case '\b':
|
---|
515 | Log2(("DBGC: backspace\n"));
|
---|
516 | if (pDbgc->iRead != pDbgc->iWrite)
|
---|
517 | {
|
---|
518 | unsigned iWriteUndo = pDbgc->iWrite;
|
---|
519 | if (pDbgc->iWrite)
|
---|
520 | pDbgc->iWrite--;
|
---|
521 | else
|
---|
522 | pDbgc->iWrite = sizeof(pDbgc->achInput) - 1;
|
---|
523 |
|
---|
524 | if (pDbgc->achInput[pDbgc->iWrite] == '\n')
|
---|
525 | pDbgc->iWrite = iWriteUndo;
|
---|
526 | }
|
---|
527 | break;
|
---|
528 |
|
---|
529 | /*
|
---|
530 | * Add char to buffer.
|
---|
531 | */
|
---|
532 | case '\t':
|
---|
533 | case '\n':
|
---|
534 | case ';':
|
---|
535 | switch (ch)
|
---|
536 | {
|
---|
537 | case '\t': ch = ' '; break;
|
---|
538 | case '\n': pDbgc->cInputLines++; break;
|
---|
539 | }
|
---|
540 | RT_FALL_THRU();
|
---|
541 | default:
|
---|
542 | Log2(("DBGC: ch=%02x\n", (unsigned char)ch));
|
---|
543 | pDbgc->achInput[pDbgc->iWrite] = ch;
|
---|
544 | if (++pDbgc->iWrite >= sizeof(pDbgc->achInput))
|
---|
545 | pDbgc->iWrite = 0;
|
---|
546 | break;
|
---|
547 | }
|
---|
548 | }
|
---|
549 |
|
---|
550 | /* Terminate it to make it easier to read in the debugger. */
|
---|
551 | pDbgc->achInput[pDbgc->iWrite] = '\0';
|
---|
552 | } while (pDbgc->pIo->pfnInput(pDbgc->pIo, 0));
|
---|
553 |
|
---|
554 | return rc;
|
---|
555 | }
|
---|
556 |
|
---|
557 |
|
---|
558 | /**
|
---|
559 | * Reads input, parses it and executes commands on '\n'.
|
---|
560 | *
|
---|
561 | * @returns VBox status code.
|
---|
562 | * @param pDbgc Debugger console instance data.
|
---|
563 | * @param fNoExecute Indicates that no commands should actually be executed.
|
---|
564 | */
|
---|
565 | int dbgcProcessInput(PDBGC pDbgc, bool fNoExecute)
|
---|
566 | {
|
---|
567 | /*
|
---|
568 | * We know there's input ready, so let's read it first.
|
---|
569 | */
|
---|
570 | int rc = dbgcInputRead(pDbgc);
|
---|
571 | if (RT_FAILURE(rc))
|
---|
572 | return rc;
|
---|
573 |
|
---|
574 | /*
|
---|
575 | * Now execute any ready commands.
|
---|
576 | */
|
---|
577 | if (pDbgc->cInputLines)
|
---|
578 | {
|
---|
579 | pDbgc->pIo->pfnSetReady(pDbgc->pIo, false);
|
---|
580 | pDbgc->fReady = false;
|
---|
581 | rc = dbgcProcessCommands(pDbgc, fNoExecute);
|
---|
582 | if (RT_SUCCESS(rc) && rc != VWRN_DBGC_CMD_PENDING)
|
---|
583 | pDbgc->fReady = true;
|
---|
584 |
|
---|
585 | if ( RT_SUCCESS(rc)
|
---|
586 | && pDbgc->iRead == pDbgc->iWrite
|
---|
587 | && pDbgc->fReady)
|
---|
588 | rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "VBoxDbg> ");
|
---|
589 |
|
---|
590 | if ( RT_SUCCESS(rc)
|
---|
591 | && pDbgc->fReady)
|
---|
592 | pDbgc->pIo->pfnSetReady(pDbgc->pIo, true);
|
---|
593 | }
|
---|
594 | /*
|
---|
595 | * else - we have incomplete line, so leave it in the buffer and
|
---|
596 | * wait for more input.
|
---|
597 | *
|
---|
598 | * Windows telnet client is in "character at a time" mode by
|
---|
599 | * default and putty sends eol as a separate packet that will be
|
---|
600 | * most likely read separately from the command line it
|
---|
601 | * terminates.
|
---|
602 | */
|
---|
603 |
|
---|
604 | return rc;
|
---|
605 | }
|
---|
606 |
|
---|
607 |
|
---|
608 | /**
|
---|
609 | * Gets the event context identifier string.
|
---|
610 | * @returns Read only string.
|
---|
611 | * @param enmCtx The context.
|
---|
612 | */
|
---|
613 | DECLHIDDEN(const char *) dbgcGetEventCtx(DBGFEVENTCTX enmCtx)
|
---|
614 | {
|
---|
615 | switch (enmCtx)
|
---|
616 | {
|
---|
617 | case DBGFEVENTCTX_RAW: return "raw";
|
---|
618 | case DBGFEVENTCTX_REM: return "rem";
|
---|
619 | case DBGFEVENTCTX_HM: return "hwaccl";
|
---|
620 | case DBGFEVENTCTX_HYPER: return "hyper";
|
---|
621 | case DBGFEVENTCTX_OTHER: return "other";
|
---|
622 |
|
---|
623 | case DBGFEVENTCTX_INVALID: return "!Invalid Event Ctx!";
|
---|
624 | default:
|
---|
625 | AssertMsgFailed(("enmCtx=%d\n", enmCtx));
|
---|
626 | return "!Unknown Event Ctx!";
|
---|
627 | }
|
---|
628 | }
|
---|
629 |
|
---|
630 |
|
---|
631 | /**
|
---|
632 | * Looks up a generic debug event.
|
---|
633 | *
|
---|
634 | * @returns Pointer to DBGCSXEVT structure if found, otherwise NULL.
|
---|
635 | * @param enmType The possibly generic event to find the descriptor for.
|
---|
636 | */
|
---|
637 | DECLHIDDEN(PCDBGCSXEVT) dbgcEventLookup(DBGFEVENTTYPE enmType)
|
---|
638 | {
|
---|
639 | uint32_t i = g_cDbgcSxEvents;
|
---|
640 | while (i-- > 0)
|
---|
641 | if (g_aDbgcSxEvents[i].enmType == enmType)
|
---|
642 | return &g_aDbgcSxEvents[i];
|
---|
643 | return NULL;
|
---|
644 | }
|
---|
645 |
|
---|
646 |
|
---|
647 | /**
|
---|
648 | * Processes debugger events.
|
---|
649 | *
|
---|
650 | * @returns VBox status code.
|
---|
651 | * @param pDbgc DBGC Instance data.
|
---|
652 | * @param pEvent Pointer to event data.
|
---|
653 | */
|
---|
654 | static int dbgcProcessEvent(PDBGC pDbgc, PCDBGFEVENT pEvent)
|
---|
655 | {
|
---|
656 | /*
|
---|
657 | * Flush log first.
|
---|
658 | */
|
---|
659 | if (pDbgc->fLog)
|
---|
660 | {
|
---|
661 | int rc = dbgcProcessLog(pDbgc);
|
---|
662 | if (RT_FAILURE(rc))
|
---|
663 | return rc;
|
---|
664 | }
|
---|
665 |
|
---|
666 | /*
|
---|
667 | * Process the event.
|
---|
668 | */
|
---|
669 | pDbgc->pszScratch = &pDbgc->achInput[0];
|
---|
670 | pDbgc->iArg = 0;
|
---|
671 | bool fPrintPrompt = true;
|
---|
672 | int rc = VINF_SUCCESS;
|
---|
673 | VMCPUID const idCpuSaved = pDbgc->idCpu;
|
---|
674 | switch (pEvent->enmType)
|
---|
675 | {
|
---|
676 | /*
|
---|
677 | * The first part is events we have initiated with commands.
|
---|
678 | */
|
---|
679 | case DBGFEVENT_HALT_DONE:
|
---|
680 | {
|
---|
681 | /** @todo add option to suppress this on CPUs that aren't selected (like
|
---|
682 | * fRegTerse). */
|
---|
683 | rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "\ndbgf event/%u: CPU %u has halted! (%s)\n",
|
---|
684 | pEvent->idCpu, pEvent->idCpu, dbgcGetEventCtx(pEvent->enmCtx));
|
---|
685 | if (RT_SUCCESS(rc))
|
---|
686 | rc = DBGCCmdHlpRegPrintf(&pDbgc->CmdHlp, pEvent->idCpu, -1, pDbgc->fRegTerse);
|
---|
687 | break;
|
---|
688 | }
|
---|
689 |
|
---|
690 |
|
---|
691 | /*
|
---|
692 | * The second part is events which can occur at any time.
|
---|
693 | */
|
---|
694 | case DBGFEVENT_FATAL_ERROR:
|
---|
695 | {
|
---|
696 | pDbgc->idCpu = pEvent->idCpu;
|
---|
697 | rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "\ndbf event/%u: Fatal error! (%s)\n",
|
---|
698 | pEvent->idCpu, dbgcGetEventCtx(pEvent->enmCtx));
|
---|
699 | if (RT_SUCCESS(rc))
|
---|
700 | rc = DBGCCmdHlpRegPrintf(&pDbgc->CmdHlp, pEvent->idCpu, -1, pDbgc->fRegTerse);
|
---|
701 | break;
|
---|
702 | }
|
---|
703 |
|
---|
704 | case DBGFEVENT_BREAKPOINT:
|
---|
705 | case DBGFEVENT_BREAKPOINT_IO:
|
---|
706 | case DBGFEVENT_BREAKPOINT_MMIO:
|
---|
707 | case DBGFEVENT_BREAKPOINT_HYPER:
|
---|
708 | {
|
---|
709 | pDbgc->idCpu = pEvent->idCpu;
|
---|
710 | rc = dbgcBpExec(pDbgc, pEvent->u.Bp.hBp);
|
---|
711 | switch (rc)
|
---|
712 | {
|
---|
713 | case VERR_DBGC_BP_NOT_FOUND:
|
---|
714 | rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "\ndbgf event/%u: Unknown breakpoint %u! (%s)\n",
|
---|
715 | pEvent->idCpu, pEvent->u.Bp.hBp, dbgcGetEventCtx(pEvent->enmCtx));
|
---|
716 | break;
|
---|
717 |
|
---|
718 | case VINF_DBGC_BP_NO_COMMAND:
|
---|
719 | rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "\ndbgf event/%u: Breakpoint %u! (%s)\n",
|
---|
720 | pEvent->idCpu, pEvent->u.Bp.hBp, dbgcGetEventCtx(pEvent->enmCtx));
|
---|
721 | break;
|
---|
722 |
|
---|
723 | case VINF_BUFFER_OVERFLOW:
|
---|
724 | rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "\ndbgf event/%u: Breakpoint %u! Command too long to execute! (%s)\n",
|
---|
725 | pEvent->idCpu, pEvent->u.Bp.hBp, dbgcGetEventCtx(pEvent->enmCtx));
|
---|
726 | break;
|
---|
727 |
|
---|
728 | default:
|
---|
729 | break;
|
---|
730 | }
|
---|
731 | if (RT_SUCCESS(rc) && DBGFR3IsHalted(pDbgc->pUVM, pEvent->idCpu))
|
---|
732 | {
|
---|
733 | rc = DBGCCmdHlpRegPrintf(&pDbgc->CmdHlp, pEvent->idCpu, -1, pDbgc->fRegTerse);
|
---|
734 |
|
---|
735 | #ifndef VBOX_VMM_TARGET_ARMV8
|
---|
736 | /* Set the resume flag to ignore the breakpoint when resuming execution. */
|
---|
737 | if ( RT_SUCCESS(rc)
|
---|
738 | && pEvent->enmType == DBGFEVENT_BREAKPOINT)
|
---|
739 | rc = pDbgc->CmdHlp.pfnExec(&pDbgc->CmdHlp, "r eflags.rf = 1");
|
---|
740 | #endif
|
---|
741 | }
|
---|
742 | else
|
---|
743 | pDbgc->idCpu = idCpuSaved;
|
---|
744 | break;
|
---|
745 | }
|
---|
746 |
|
---|
747 | case DBGFEVENT_STEPPED:
|
---|
748 | case DBGFEVENT_STEPPED_HYPER:
|
---|
749 | {
|
---|
750 | if (!pDbgc->cMultiStepsLeft || pEvent->idCpu != idCpuSaved)
|
---|
751 | rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "\ndbgf event/%u: Single step! (%s)\n",
|
---|
752 | pEvent->idCpu, dbgcGetEventCtx(pEvent->enmCtx));
|
---|
753 | else
|
---|
754 | pDbgc->cMultiStepsLeft -= 1;
|
---|
755 | if (RT_SUCCESS(rc))
|
---|
756 | {
|
---|
757 | if (pDbgc->fStepTraceRegs)
|
---|
758 | rc = DBGCCmdHlpRegPrintf(&pDbgc->CmdHlp, pEvent->idCpu, -1, pDbgc->fRegTerse);
|
---|
759 | else
|
---|
760 | {
|
---|
761 | char szCmd[80];
|
---|
762 | if (DBGFR3CpuIsIn64BitCode(pDbgc->pUVM, pDbgc->idCpu))
|
---|
763 | rc = DBGFR3RegPrintf(pDbgc->pUVM, pDbgc->idCpu, szCmd, sizeof(szCmd), "u %016VR{rip} L 0");
|
---|
764 | else if (DBGFR3CpuIsInV86Code(pDbgc->pUVM, pDbgc->idCpu))
|
---|
765 | rc = DBGFR3RegPrintf(pDbgc->pUVM, pDbgc->idCpu, szCmd, sizeof(szCmd), "uv86 %04VR{cs}:%08VR{eip} L 0");
|
---|
766 | else
|
---|
767 | rc = DBGFR3RegPrintf(pDbgc->pUVM, pDbgc->idCpu, szCmd, sizeof(szCmd), "u %04VR{cs}:%08VR{eip} L 0");
|
---|
768 | if (RT_SUCCESS(rc))
|
---|
769 | rc = pDbgc->CmdHlp.pfnExec(&pDbgc->CmdHlp, "%s", szCmd);
|
---|
770 | }
|
---|
771 | }
|
---|
772 |
|
---|
773 | /* If multi-stepping, take the next step: */
|
---|
774 | if (pDbgc->cMultiStepsLeft > 0 && pEvent->idCpu == idCpuSaved)
|
---|
775 | {
|
---|
776 | int rc2 = DBGFR3StepEx(pDbgc->pUVM, pDbgc->idCpu, DBGF_STEP_F_INTO, NULL, NULL, 0, pDbgc->uMultiStepStrideLength);
|
---|
777 | if (RT_SUCCESS(rc2))
|
---|
778 | fPrintPrompt = false;
|
---|
779 | else
|
---|
780 | DBGCCmdHlpFailRc(&pDbgc->CmdHlp, pDbgc->pMultiStepCmd, rc2, "DBGFR3StepEx(,,DBGF_STEP_F_INTO,) failed");
|
---|
781 | }
|
---|
782 | else
|
---|
783 | pDbgc->idCpu = pEvent->idCpu;
|
---|
784 | break;
|
---|
785 | }
|
---|
786 |
|
---|
787 | case DBGFEVENT_ASSERTION_HYPER:
|
---|
788 | {
|
---|
789 | pDbgc->idCpu = pEvent->idCpu;
|
---|
790 | rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL,
|
---|
791 | "\ndbgf event/%u: Hypervisor Assertion! (%s)\n"
|
---|
792 | "%s"
|
---|
793 | "%s"
|
---|
794 | "\n",
|
---|
795 | pEvent->idCpu,
|
---|
796 | dbgcGetEventCtx(pEvent->enmCtx),
|
---|
797 | pEvent->u.Assert.pszMsg1,
|
---|
798 | pEvent->u.Assert.pszMsg2);
|
---|
799 | if (RT_SUCCESS(rc))
|
---|
800 | rc = DBGCCmdHlpRegPrintf(&pDbgc->CmdHlp, pEvent->idCpu, -1, pDbgc->fRegTerse);
|
---|
801 | break;
|
---|
802 | }
|
---|
803 |
|
---|
804 | case DBGFEVENT_DEV_STOP:
|
---|
805 | {
|
---|
806 | pDbgc->idCpu = pEvent->idCpu;
|
---|
807 | rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL,
|
---|
808 | "\n"
|
---|
809 | "dbgf event/%u: DBGFSTOP (%s)\n"
|
---|
810 | "File: %s\n"
|
---|
811 | "Line: %d\n"
|
---|
812 | "Function: %s\n",
|
---|
813 | pEvent->idCpu,
|
---|
814 | dbgcGetEventCtx(pEvent->enmCtx),
|
---|
815 | pEvent->u.Src.pszFile,
|
---|
816 | pEvent->u.Src.uLine,
|
---|
817 | pEvent->u.Src.pszFunction);
|
---|
818 | if (RT_SUCCESS(rc) && pEvent->u.Src.pszMessage && *pEvent->u.Src.pszMessage)
|
---|
819 | rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL,
|
---|
820 | "Message: %s\n",
|
---|
821 | pEvent->u.Src.pszMessage);
|
---|
822 | if (RT_SUCCESS(rc))
|
---|
823 | rc = DBGCCmdHlpRegPrintf(&pDbgc->CmdHlp, pEvent->idCpu, -1, pDbgc->fRegTerse);
|
---|
824 | break;
|
---|
825 | }
|
---|
826 |
|
---|
827 |
|
---|
828 | case DBGFEVENT_INVALID_COMMAND:
|
---|
829 | {
|
---|
830 | rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "\ndbgf/dbgc error: Invalid command event!\n");
|
---|
831 | break;
|
---|
832 | }
|
---|
833 |
|
---|
834 | case DBGFEVENT_POWERING_OFF:
|
---|
835 | {
|
---|
836 | pDbgc->fReady = false;
|
---|
837 | pDbgc->pIo->pfnSetReady(pDbgc->pIo, false);
|
---|
838 | pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "\nVM is powering off!\n");
|
---|
839 | fPrintPrompt = false;
|
---|
840 | rc = VERR_GENERAL_FAILURE;
|
---|
841 | break;
|
---|
842 | }
|
---|
843 |
|
---|
844 |
|
---|
845 | default:
|
---|
846 | {
|
---|
847 | /*
|
---|
848 | * Probably a generic event. Look it up to find its name.
|
---|
849 | */
|
---|
850 | PCDBGCSXEVT pEvtDesc = dbgcEventLookup(pEvent->enmType);
|
---|
851 | if (pEvtDesc)
|
---|
852 | {
|
---|
853 | if (pEvtDesc->enmKind == kDbgcSxEventKind_Interrupt)
|
---|
854 | {
|
---|
855 | Assert(pEvtDesc->pszDesc);
|
---|
856 | Assert(pEvent->u.Generic.cArgs == 1);
|
---|
857 | rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "\ndbgf event/%u: %s no %#llx! (%s)\n",
|
---|
858 | pEvent->idCpu, pEvtDesc->pszDesc, pEvent->u.Generic.auArgs[0], pEvtDesc->pszName);
|
---|
859 | }
|
---|
860 | else if (pEvtDesc->fFlags & DBGCSXEVT_F_BUGCHECK)
|
---|
861 | {
|
---|
862 | Assert(pEvent->u.Generic.cArgs >= 5);
|
---|
863 | char szDetails[512];
|
---|
864 | DBGFR3FormatBugCheck(pDbgc->pUVM, szDetails, sizeof(szDetails), pEvent->u.Generic.auArgs[0],
|
---|
865 | pEvent->u.Generic.auArgs[1], pEvent->u.Generic.auArgs[2],
|
---|
866 | pEvent->u.Generic.auArgs[3], pEvent->u.Generic.auArgs[4]);
|
---|
867 | rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "\ndbgf event/%u: %s %s%s!\n%s", pEvent->idCpu,
|
---|
868 | pEvtDesc->pszName, pEvtDesc->pszDesc ? "- " : "",
|
---|
869 | pEvtDesc->pszDesc ? pEvtDesc->pszDesc : "", szDetails);
|
---|
870 | }
|
---|
871 | else if ( (pEvtDesc->fFlags & DBGCSXEVT_F_TAKE_ARG)
|
---|
872 | || pEvent->u.Generic.cArgs > 1
|
---|
873 | || ( pEvent->u.Generic.cArgs == 1
|
---|
874 | && pEvent->u.Generic.auArgs[0] != 0))
|
---|
875 | {
|
---|
876 | if (pEvtDesc->pszDesc)
|
---|
877 | rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "\ndbgf event/%u: %s - %s!",
|
---|
878 | pEvent->idCpu, pEvtDesc->pszName, pEvtDesc->pszDesc);
|
---|
879 | else
|
---|
880 | rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "\ndbgf event/%u: %s!",
|
---|
881 | pEvent->idCpu, pEvtDesc->pszName);
|
---|
882 | if (RT_SUCCESS(rc))
|
---|
883 | {
|
---|
884 | if (pEvent->u.Generic.cArgs <= 1)
|
---|
885 | rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, " arg=%#llx\n", pEvent->u.Generic.auArgs[0]);
|
---|
886 | else
|
---|
887 | {
|
---|
888 | for (uint32_t i = 0; i < pEvent->u.Generic.cArgs; i++)
|
---|
889 | rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, " args[%u]=%#llx", i, pEvent->u.Generic.auArgs[i]);
|
---|
890 | if (RT_SUCCESS(rc))
|
---|
891 | rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "\n");
|
---|
892 | }
|
---|
893 | }
|
---|
894 | }
|
---|
895 | else
|
---|
896 | {
|
---|
897 | if (pEvtDesc->pszDesc)
|
---|
898 | rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "\ndbgf event/%u: %s - %s!\n",
|
---|
899 | pEvent->idCpu, pEvtDesc->pszName, pEvtDesc->pszDesc);
|
---|
900 | else
|
---|
901 | rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "\ndbgf event/%u: %s!\n",
|
---|
902 | pEvent->idCpu, pEvtDesc->pszName);
|
---|
903 | }
|
---|
904 | }
|
---|
905 | else
|
---|
906 | rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "\ndbgf/dbgc error: Unknown event %d on CPU %u!\n",
|
---|
907 | pEvent->enmType, pEvent->idCpu);
|
---|
908 | break;
|
---|
909 | }
|
---|
910 | }
|
---|
911 |
|
---|
912 | /*
|
---|
913 | * Prompt, anyone?
|
---|
914 | */
|
---|
915 | if (fPrintPrompt && RT_SUCCESS(rc))
|
---|
916 | {
|
---|
917 | /** @todo add CPU indicator to the prompt if an SMP VM? */
|
---|
918 | rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "VBoxDbg> ");
|
---|
919 | pDbgc->fReady = true;
|
---|
920 | if (RT_SUCCESS(rc))
|
---|
921 | pDbgc->pIo->pfnSetReady(pDbgc->pIo, true);
|
---|
922 | pDbgc->cMultiStepsLeft = 0;
|
---|
923 | }
|
---|
924 |
|
---|
925 | return rc;
|
---|
926 | }
|
---|
927 |
|
---|
928 |
|
---|
929 | /**
|
---|
930 | * Prints any log lines from the log buffer.
|
---|
931 | *
|
---|
932 | * The caller must not call function this unless pDbgc->fLog is set.
|
---|
933 | *
|
---|
934 | * @returns VBox status code. (output related)
|
---|
935 | * @param pDbgc Debugger console instance data.
|
---|
936 | */
|
---|
937 | static int dbgcProcessLog(PDBGC pDbgc)
|
---|
938 | {
|
---|
939 | /** @todo */
|
---|
940 | NOREF(pDbgc);
|
---|
941 | return 0;
|
---|
942 | }
|
---|
943 |
|
---|
944 | /** @callback_method_impl{FNRTDBGCFGLOG} */
|
---|
945 | static DECLCALLBACK(void) dbgcDbgCfgLogCallback(RTDBGCFG hDbgCfg, uint32_t iLevel, const char *pszMsg, void *pvUser)
|
---|
946 | {
|
---|
947 | /** @todo Add symbol noise setting. */
|
---|
948 | NOREF(hDbgCfg); NOREF(iLevel);
|
---|
949 | PDBGC pDbgc = (PDBGC)pvUser;
|
---|
950 | pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "%s", pszMsg);
|
---|
951 | }
|
---|
952 |
|
---|
953 |
|
---|
954 | /**
|
---|
955 | * Run the debugger console.
|
---|
956 | *
|
---|
957 | * @returns VBox status code.
|
---|
958 | * @param pDbgc Pointer to the debugger console instance data.
|
---|
959 | */
|
---|
960 | int dbgcRun(PDBGC pDbgc)
|
---|
961 | {
|
---|
962 | /*
|
---|
963 | * We're ready for commands now.
|
---|
964 | */
|
---|
965 | pDbgc->fReady = true;
|
---|
966 | pDbgc->pIo->pfnSetReady(pDbgc->pIo, true);
|
---|
967 |
|
---|
968 | /*
|
---|
969 | * Main Debugger Loop.
|
---|
970 | *
|
---|
971 | * This loop will either block on waiting for input or on waiting on
|
---|
972 | * debug events. If we're forwarding the log we cannot wait for long
|
---|
973 | * before we must flush the log.
|
---|
974 | */
|
---|
975 | int rc;
|
---|
976 | for (;;)
|
---|
977 | {
|
---|
978 | rc = VERR_SEM_OUT_OF_TURN;
|
---|
979 | if (pDbgc->pUVM)
|
---|
980 | rc = DBGFR3QueryWaitable(pDbgc->pUVM);
|
---|
981 |
|
---|
982 | if (RT_SUCCESS(rc))
|
---|
983 | {
|
---|
984 | /*
|
---|
985 | * Wait for a debug event.
|
---|
986 | */
|
---|
987 | DBGFEVENT Event;
|
---|
988 | rc = DBGFR3EventWait(pDbgc->pUVM, pDbgc->fLog ? 1 : 32, &Event);
|
---|
989 | if (RT_SUCCESS(rc))
|
---|
990 | {
|
---|
991 | rc = dbgcProcessEvent(pDbgc, &Event);
|
---|
992 | if (RT_FAILURE(rc))
|
---|
993 | break;
|
---|
994 | }
|
---|
995 | else if (rc != VERR_TIMEOUT)
|
---|
996 | break;
|
---|
997 |
|
---|
998 | /*
|
---|
999 | * Check for input.
|
---|
1000 | */
|
---|
1001 | if (pDbgc->pIo->pfnInput(pDbgc->pIo, 0))
|
---|
1002 | {
|
---|
1003 | rc = dbgcProcessInput(pDbgc, false /* fNoExecute */);
|
---|
1004 | if (RT_FAILURE(rc))
|
---|
1005 | break;
|
---|
1006 | }
|
---|
1007 | }
|
---|
1008 | else if (rc == VERR_SEM_OUT_OF_TURN)
|
---|
1009 | {
|
---|
1010 | /*
|
---|
1011 | * Wait for input. If Logging is enabled we'll only wait very briefly.
|
---|
1012 | */
|
---|
1013 | if (pDbgc->pIo->pfnInput(pDbgc->pIo, pDbgc->fLog ? 1 : 1000))
|
---|
1014 | {
|
---|
1015 | rc = dbgcProcessInput(pDbgc, false /* fNoExecute */);
|
---|
1016 | if (RT_FAILURE(rc))
|
---|
1017 | break;
|
---|
1018 | }
|
---|
1019 | }
|
---|
1020 | else
|
---|
1021 | break;
|
---|
1022 |
|
---|
1023 | /*
|
---|
1024 | * Forward log output.
|
---|
1025 | */
|
---|
1026 | if (pDbgc->fLog)
|
---|
1027 | {
|
---|
1028 | rc = dbgcProcessLog(pDbgc);
|
---|
1029 | if (RT_FAILURE(rc))
|
---|
1030 | break;
|
---|
1031 | }
|
---|
1032 | }
|
---|
1033 |
|
---|
1034 | return rc;
|
---|
1035 | }
|
---|
1036 |
|
---|
1037 |
|
---|
1038 | /**
|
---|
1039 | * Run the init scripts, if present.
|
---|
1040 | *
|
---|
1041 | * @param pDbgc The console instance.
|
---|
1042 | */
|
---|
1043 | static void dbgcRunInitScripts(PDBGC pDbgc)
|
---|
1044 | {
|
---|
1045 | /*
|
---|
1046 | * Do the global one, if it exists.
|
---|
1047 | */
|
---|
1048 | if ( pDbgc->pszGlobalInitScript
|
---|
1049 | && *pDbgc->pszGlobalInitScript != '\0'
|
---|
1050 | && RTFileExists(pDbgc->pszGlobalInitScript))
|
---|
1051 | dbgcEvalScript(pDbgc, pDbgc->pszGlobalInitScript, true /*fAnnounce*/);
|
---|
1052 |
|
---|
1053 | /*
|
---|
1054 | * Then do the local one, if it exists.
|
---|
1055 | */
|
---|
1056 | if ( pDbgc->pszLocalInitScript
|
---|
1057 | && *pDbgc->pszLocalInitScript != '\0'
|
---|
1058 | && RTFileExists(pDbgc->pszLocalInitScript))
|
---|
1059 | dbgcEvalScript(pDbgc, pDbgc->pszLocalInitScript, true /*fAnnounce*/);
|
---|
1060 | }
|
---|
1061 |
|
---|
1062 |
|
---|
1063 | /**
|
---|
1064 | * Reads the CFGM configuration of the DBGC.
|
---|
1065 | *
|
---|
1066 | * Popuplates the PDBGC::pszHistoryFile, PDBGC::pszGlobalInitScript and
|
---|
1067 | * PDBGC::pszLocalInitScript members.
|
---|
1068 | *
|
---|
1069 | * @returns VBox status code.
|
---|
1070 | * @param pDbgc The console instance.
|
---|
1071 | * @param pUVM The user mode VM handle.
|
---|
1072 | */
|
---|
1073 | static int dbgcReadConfig(PDBGC pDbgc, PUVM pUVM)
|
---|
1074 | {
|
---|
1075 | /*
|
---|
1076 | * Get and validate the configuration node.
|
---|
1077 | */
|
---|
1078 | PCFGMNODE pNode = CFGMR3GetChild(CFGMR3GetRootU(pUVM), "DBGC");
|
---|
1079 | int rc = CFGMR3ValidateConfig(pNode, "/DBGC/",
|
---|
1080 | "Enabled|"
|
---|
1081 | "HistoryFile|"
|
---|
1082 | "LocalInitScript|"
|
---|
1083 | "GlobalInitScript|",
|
---|
1084 | "*", "DBGC", 0);
|
---|
1085 | AssertRCReturn(rc, rc);
|
---|
1086 |
|
---|
1087 | /*
|
---|
1088 | * Query the values.
|
---|
1089 | */
|
---|
1090 | char szHomeDefault[RTPATH_MAX];
|
---|
1091 | rc = RTPathUserHome(szHomeDefault, sizeof(szHomeDefault) - 32);
|
---|
1092 | AssertLogRelRCReturn(rc, rc);
|
---|
1093 | size_t cchHome = strlen(szHomeDefault);
|
---|
1094 |
|
---|
1095 | /** @cfgm{/DBGC/HistoryFile, string, ${HOME}/.vboxdbgc-history}
|
---|
1096 | * The command history file of the VBox debugger. */
|
---|
1097 | rc = RTPathAppend(szHomeDefault, sizeof(szHomeDefault), ".vboxdbgc-history");
|
---|
1098 | AssertLogRelRCReturn(rc, rc);
|
---|
1099 |
|
---|
1100 | char szPath[RTPATH_MAX];
|
---|
1101 | rc = CFGMR3QueryStringDef(pNode, "HistoryFile", szPath, sizeof(szPath), szHomeDefault);
|
---|
1102 | AssertLogRelRCReturn(rc, rc);
|
---|
1103 |
|
---|
1104 | pDbgc->pszHistoryFile = RTStrDup(szPath);
|
---|
1105 | AssertReturn(pDbgc->pszHistoryFile, VERR_NO_STR_MEMORY);
|
---|
1106 |
|
---|
1107 | /** @cfgm{/DBGC/GlobalInitFile, string, ${HOME}/.vboxdbgc-init}
|
---|
1108 | * The global init script of the VBox debugger. */
|
---|
1109 | szHomeDefault[cchHome] = '\0';
|
---|
1110 | rc = RTPathAppend(szHomeDefault, sizeof(szHomeDefault), ".vboxdbgc-init");
|
---|
1111 | AssertLogRelRCReturn(rc, rc);
|
---|
1112 |
|
---|
1113 | rc = CFGMR3QueryStringDef(pNode, "GlobalInitScript", szPath, sizeof(szPath), szHomeDefault);
|
---|
1114 | AssertLogRelRCReturn(rc, rc);
|
---|
1115 |
|
---|
1116 | pDbgc->pszGlobalInitScript = RTStrDup(szPath);
|
---|
1117 | AssertReturn(pDbgc->pszGlobalInitScript, VERR_NO_STR_MEMORY);
|
---|
1118 |
|
---|
1119 | /** @cfgm{/DBGC/LocalInitFile, string, none}
|
---|
1120 | * The VM local init script of the VBox debugger. */
|
---|
1121 | rc = CFGMR3QueryString(pNode, "LocalInitScript", szPath, sizeof(szPath));
|
---|
1122 | if (RT_SUCCESS(rc))
|
---|
1123 | {
|
---|
1124 | pDbgc->pszLocalInitScript = RTStrDup(szPath);
|
---|
1125 | AssertReturn(pDbgc->pszLocalInitScript, VERR_NO_STR_MEMORY);
|
---|
1126 | }
|
---|
1127 | else
|
---|
1128 | {
|
---|
1129 | AssertLogRelReturn(rc == VERR_CFGM_VALUE_NOT_FOUND || rc == VERR_CFGM_NO_PARENT, rc);
|
---|
1130 | pDbgc->pszLocalInitScript = NULL;
|
---|
1131 | }
|
---|
1132 |
|
---|
1133 | return VINF_SUCCESS;
|
---|
1134 | }
|
---|
1135 |
|
---|
1136 |
|
---|
1137 | /**
|
---|
1138 | * @copydoc DBGC::pfnOutput
|
---|
1139 | */
|
---|
1140 | static DECLCALLBACK(int) dbgcOutputNative(void *pvUser, const char *pachChars, size_t cbChars)
|
---|
1141 | {
|
---|
1142 | PDBGC pDbgc = (PDBGC)pvUser;
|
---|
1143 | return pDbgc->pIo->pfnWrite(pDbgc->pIo, pachChars, cbChars, NULL /*pcbWritten*/);
|
---|
1144 | }
|
---|
1145 |
|
---|
1146 |
|
---|
1147 | /**
|
---|
1148 | * Creates a a new instance.
|
---|
1149 | *
|
---|
1150 | * @returns VBox status code.
|
---|
1151 | * @param ppDbgc Where to store the pointer to the instance data.
|
---|
1152 | * @param pIo Pointer to the I/O callback table.
|
---|
1153 | * @param fFlags The flags.
|
---|
1154 | */
|
---|
1155 | int dbgcCreate(PDBGC *ppDbgc, PCDBGCIO pIo, unsigned fFlags)
|
---|
1156 | {
|
---|
1157 | /*
|
---|
1158 | * Validate input.
|
---|
1159 | */
|
---|
1160 | AssertPtrReturn(pIo, VERR_INVALID_POINTER);
|
---|
1161 | AssertMsgReturn(!fFlags, ("%#x", fFlags), VERR_INVALID_PARAMETER);
|
---|
1162 |
|
---|
1163 | /*
|
---|
1164 | * Allocate and initialize.
|
---|
1165 | */
|
---|
1166 | PDBGC pDbgc = (PDBGC)RTMemAllocZ(sizeof(*pDbgc));
|
---|
1167 | if (!pDbgc)
|
---|
1168 | return VERR_NO_MEMORY;
|
---|
1169 |
|
---|
1170 | dbgcInitCmdHlp(pDbgc);
|
---|
1171 | pDbgc->pIo = pIo;
|
---|
1172 | pDbgc->pfnOutput = dbgcOutputNative;
|
---|
1173 | pDbgc->pvOutputUser = pDbgc;
|
---|
1174 | pDbgc->pVM = NULL;
|
---|
1175 | pDbgc->pUVM = NULL;
|
---|
1176 | pDbgc->idCpu = 0;
|
---|
1177 | pDbgc->hDbgAs = DBGF_AS_GLOBAL;
|
---|
1178 | pDbgc->pszEmulation = "CodeView/WinDbg";
|
---|
1179 | pDbgc->paEmulationCmds = &g_aCmdsCodeView[0];
|
---|
1180 | pDbgc->cEmulationCmds = g_cCmdsCodeView;
|
---|
1181 | pDbgc->paEmulationFuncs = &g_aFuncsCodeView[0];
|
---|
1182 | pDbgc->cEmulationFuncs = g_cFuncsCodeView;
|
---|
1183 | //pDbgc->fLog = false;
|
---|
1184 | pDbgc->fRegTerse = true;
|
---|
1185 | pDbgc->fStepTraceRegs = true;
|
---|
1186 | //pDbgc->cPagingHierarchyDumps = 0;
|
---|
1187 | //pDbgc->DisasmPos = {0};
|
---|
1188 | //pDbgc->SourcePos = {0};
|
---|
1189 | //pDbgc->DumpPos = {0};
|
---|
1190 | pDbgc->pLastPos = &pDbgc->DisasmPos;
|
---|
1191 | //pDbgc->cbDumpElement = 0;
|
---|
1192 | //pDbgc->cVars = 0;
|
---|
1193 | //pDbgc->paVars = NULL;
|
---|
1194 | //pDbgc->pPlugInHead = NULL;
|
---|
1195 | //pDbgc->pFirstBp = NULL;
|
---|
1196 | RTListInit(&pDbgc->LstTraceFlowMods);
|
---|
1197 | //pDbgc->abSearch = {0};
|
---|
1198 | //pDbgc->cbSearch = 0;
|
---|
1199 | pDbgc->cbSearchUnit = 1;
|
---|
1200 | pDbgc->cMaxSearchHits = 1;
|
---|
1201 | //pDbgc->SearchAddr = {0};
|
---|
1202 | //pDbgc->cbSearchRange = 0;
|
---|
1203 |
|
---|
1204 | //pDbgc->uInputZero = 0;
|
---|
1205 | //pDbgc->iRead = 0;
|
---|
1206 | //pDbgc->iWrite = 0;
|
---|
1207 | //pDbgc->cInputLines = 0;
|
---|
1208 | //pDbgc->fInputOverflow = false;
|
---|
1209 | pDbgc->fReady = true;
|
---|
1210 | pDbgc->pszScratch = &pDbgc->achScratch[0];
|
---|
1211 | //pDbgc->iArg = 0;
|
---|
1212 | //pDbgc->rcOutput = 0;
|
---|
1213 | //pDbgc->rcCmd = 0;
|
---|
1214 |
|
---|
1215 | //pDbgc->pszHistoryFile = NULL;
|
---|
1216 | //pDbgc->pszGlobalInitScript = NULL;
|
---|
1217 | //pDbgc->pszLocalInitScript = NULL;
|
---|
1218 |
|
---|
1219 | dbgcEvalInit();
|
---|
1220 |
|
---|
1221 | *ppDbgc = pDbgc;
|
---|
1222 | return VINF_SUCCESS;
|
---|
1223 | }
|
---|
1224 |
|
---|
1225 | /**
|
---|
1226 | * Destroys a DBGC instance created by dbgcCreate.
|
---|
1227 | *
|
---|
1228 | * @param pDbgc Pointer to the debugger console instance data.
|
---|
1229 | */
|
---|
1230 | void dbgcDestroy(PDBGC pDbgc)
|
---|
1231 | {
|
---|
1232 | AssertPtr(pDbgc);
|
---|
1233 |
|
---|
1234 | /* Disable log hook. */
|
---|
1235 | if (pDbgc->fLog)
|
---|
1236 | {
|
---|
1237 |
|
---|
1238 | }
|
---|
1239 |
|
---|
1240 | /* Detach from the VM. */
|
---|
1241 | if (pDbgc->pUVM)
|
---|
1242 | DBGFR3Detach(pDbgc->pUVM);
|
---|
1243 |
|
---|
1244 | /* Free config strings. */
|
---|
1245 | RTStrFree(pDbgc->pszGlobalInitScript);
|
---|
1246 | pDbgc->pszGlobalInitScript = NULL;
|
---|
1247 | RTStrFree(pDbgc->pszLocalInitScript);
|
---|
1248 | pDbgc->pszLocalInitScript = NULL;
|
---|
1249 | RTStrFree(pDbgc->pszHistoryFile);
|
---|
1250 | pDbgc->pszHistoryFile = NULL;
|
---|
1251 |
|
---|
1252 | /* Finally, free the instance memory. */
|
---|
1253 | RTMemFree(pDbgc);
|
---|
1254 | }
|
---|
1255 |
|
---|
1256 |
|
---|
1257 | /**
|
---|
1258 | * Make a console instance.
|
---|
1259 | *
|
---|
1260 | * This will not return until either an 'exit' command is issued or a error code
|
---|
1261 | * indicating connection loss is encountered.
|
---|
1262 | *
|
---|
1263 | * @returns VINF_SUCCESS if console termination caused by the 'exit' command.
|
---|
1264 | * @returns The VBox status code causing the console termination.
|
---|
1265 | *
|
---|
1266 | * @param pUVM The user mode VM handle.
|
---|
1267 | * @param pIo Pointer to the I/O callback structure. This must contain
|
---|
1268 | * a full set of function pointers to service the console.
|
---|
1269 | * @param fFlags Reserved, must be zero.
|
---|
1270 | * @remarks A forced termination of the console is easiest done by forcing the
|
---|
1271 | * callbacks to return fatal failures.
|
---|
1272 | */
|
---|
1273 | DBGDECL(int) DBGCCreate(PUVM pUVM, PCDBGCIO pIo, unsigned fFlags)
|
---|
1274 | {
|
---|
1275 | /*
|
---|
1276 | * Validate input.
|
---|
1277 | */
|
---|
1278 | AssertPtrNullReturn(pUVM, VERR_INVALID_VM_HANDLE);
|
---|
1279 | PVM pVM = NULL;
|
---|
1280 | if (pUVM)
|
---|
1281 | {
|
---|
1282 | pVM = VMR3GetVM(pUVM);
|
---|
1283 | AssertPtrReturn(pVM, VERR_INVALID_VM_HANDLE);
|
---|
1284 | }
|
---|
1285 |
|
---|
1286 | /*
|
---|
1287 | * Allocate and initialize instance data
|
---|
1288 | */
|
---|
1289 | PDBGC pDbgc;
|
---|
1290 | int rc = dbgcCreate(&pDbgc, pIo, fFlags);
|
---|
1291 | if (RT_FAILURE(rc))
|
---|
1292 | return rc;
|
---|
1293 | if (!HMR3IsEnabled(pUVM) && !NEMR3IsEnabled(pUVM))
|
---|
1294 | pDbgc->hDbgAs = DBGF_AS_RC_AND_GC_GLOBAL;
|
---|
1295 |
|
---|
1296 | /*
|
---|
1297 | * Print welcome message.
|
---|
1298 | */
|
---|
1299 | rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL,
|
---|
1300 | "Welcome to the VirtualBox Debugger!\n");
|
---|
1301 |
|
---|
1302 | /*
|
---|
1303 | * Attach to the specified VM.
|
---|
1304 | */
|
---|
1305 | if (RT_SUCCESS(rc) && pUVM)
|
---|
1306 | {
|
---|
1307 | rc = dbgcReadConfig(pDbgc, pUVM);
|
---|
1308 | if (RT_SUCCESS(rc))
|
---|
1309 | {
|
---|
1310 | rc = DBGFR3Attach(pUVM);
|
---|
1311 | if (RT_SUCCESS(rc))
|
---|
1312 | {
|
---|
1313 | pDbgc->pVM = pVM;
|
---|
1314 | pDbgc->pUVM = pUVM;
|
---|
1315 | pDbgc->idCpu = 0;
|
---|
1316 | rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL,
|
---|
1317 | "Current VM is %08x, CPU #%u\n" /** @todo get and print the VM name! */
|
---|
1318 | , pDbgc->pVM, pDbgc->idCpu);
|
---|
1319 | }
|
---|
1320 | else
|
---|
1321 | rc = pDbgc->CmdHlp.pfnVBoxError(&pDbgc->CmdHlp, rc, "When trying to attach to VM %p\n", pDbgc->pVM);
|
---|
1322 | }
|
---|
1323 | else
|
---|
1324 | rc = pDbgc->CmdHlp.pfnVBoxError(&pDbgc->CmdHlp, rc, "Error reading configuration\n");
|
---|
1325 | }
|
---|
1326 |
|
---|
1327 | /*
|
---|
1328 | * Load plugins.
|
---|
1329 | */
|
---|
1330 | if (RT_SUCCESS(rc))
|
---|
1331 | {
|
---|
1332 | if (pVM)
|
---|
1333 | DBGFR3PlugInLoadAll(pDbgc->pUVM);
|
---|
1334 | dbgcEventInit(pDbgc);
|
---|
1335 | dbgcRunInitScripts(pDbgc);
|
---|
1336 |
|
---|
1337 | rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "VBoxDbg> ");
|
---|
1338 | if (RT_SUCCESS(rc))
|
---|
1339 | {
|
---|
1340 | /*
|
---|
1341 | * Set debug config log callback.
|
---|
1342 | */
|
---|
1343 | RTDBGCFG hDbgCfg = DBGFR3AsGetConfig(pUVM);
|
---|
1344 | if ( hDbgCfg != NIL_RTDBGCFG
|
---|
1345 | && RTDbgCfgRetain(hDbgCfg) != UINT32_MAX)
|
---|
1346 | {
|
---|
1347 | int rc2 = RTDbgCfgSetLogCallback(hDbgCfg, dbgcDbgCfgLogCallback, pDbgc);
|
---|
1348 | if (RT_FAILURE(rc2))
|
---|
1349 | {
|
---|
1350 | hDbgCfg = NIL_RTDBGCFG;
|
---|
1351 | RTDbgCfgRelease(hDbgCfg);
|
---|
1352 | }
|
---|
1353 | }
|
---|
1354 | else
|
---|
1355 | hDbgCfg = NIL_RTDBGCFG;
|
---|
1356 |
|
---|
1357 |
|
---|
1358 | /*
|
---|
1359 | * Run the debugger main loop.
|
---|
1360 | */
|
---|
1361 | rc = dbgcRun(pDbgc);
|
---|
1362 |
|
---|
1363 |
|
---|
1364 | /*
|
---|
1365 | * Remove debug config log callback.
|
---|
1366 | */
|
---|
1367 | if (hDbgCfg != NIL_RTDBGCFG)
|
---|
1368 | {
|
---|
1369 | RTDbgCfgSetLogCallback(hDbgCfg, NULL, NULL);
|
---|
1370 | RTDbgCfgRelease(hDbgCfg);
|
---|
1371 | }
|
---|
1372 | }
|
---|
1373 | dbgcEventTerm(pDbgc);
|
---|
1374 | }
|
---|
1375 | else
|
---|
1376 | pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "\nDBGCCreate error: %Rrc\n", rc);
|
---|
1377 |
|
---|
1378 |
|
---|
1379 | /*
|
---|
1380 | * Cleanup console debugger session.
|
---|
1381 | */
|
---|
1382 | dbgcDestroy(pDbgc);
|
---|
1383 | return rc == VERR_DBGC_QUIT ? VINF_SUCCESS : rc;
|
---|
1384 | }
|
---|
1385 |
|
---|