1 | /* $Id: DBGConsole.cpp 103490 2024-02-21 12:33:44Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * DBGC - Debugger Console.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2023 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 | /* Set the resume flag to ignore the breakpoint when resuming execution. */
|
---|
736 | if ( RT_SUCCESS(rc)
|
---|
737 | && pEvent->enmType == DBGFEVENT_BREAKPOINT)
|
---|
738 | rc = pDbgc->CmdHlp.pfnExec(&pDbgc->CmdHlp, "r eflags.rf = 1");
|
---|
739 | }
|
---|
740 | else
|
---|
741 | pDbgc->idCpu = idCpuSaved;
|
---|
742 | break;
|
---|
743 | }
|
---|
744 |
|
---|
745 | case DBGFEVENT_STEPPED:
|
---|
746 | case DBGFEVENT_STEPPED_HYPER:
|
---|
747 | {
|
---|
748 | if (!pDbgc->cMultiStepsLeft || pEvent->idCpu != idCpuSaved)
|
---|
749 | rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "\ndbgf event/%u: Single step! (%s)\n",
|
---|
750 | pEvent->idCpu, dbgcGetEventCtx(pEvent->enmCtx));
|
---|
751 | else
|
---|
752 | pDbgc->cMultiStepsLeft -= 1;
|
---|
753 | if (RT_SUCCESS(rc))
|
---|
754 | {
|
---|
755 | if (pDbgc->fStepTraceRegs)
|
---|
756 | rc = DBGCCmdHlpRegPrintf(&pDbgc->CmdHlp, pEvent->idCpu, -1, pDbgc->fRegTerse);
|
---|
757 | else
|
---|
758 | {
|
---|
759 | char szCmd[80];
|
---|
760 | if (DBGFR3CpuIsIn64BitCode(pDbgc->pUVM, pDbgc->idCpu))
|
---|
761 | rc = DBGFR3RegPrintf(pDbgc->pUVM, pDbgc->idCpu, szCmd, sizeof(szCmd), "u %016VR{rip} L 0");
|
---|
762 | else if (DBGFR3CpuIsInV86Code(pDbgc->pUVM, pDbgc->idCpu))
|
---|
763 | rc = DBGFR3RegPrintf(pDbgc->pUVM, pDbgc->idCpu, szCmd, sizeof(szCmd), "uv86 %04VR{cs}:%08VR{eip} L 0");
|
---|
764 | else
|
---|
765 | rc = DBGFR3RegPrintf(pDbgc->pUVM, pDbgc->idCpu, szCmd, sizeof(szCmd), "u %04VR{cs}:%08VR{eip} L 0");
|
---|
766 | if (RT_SUCCESS(rc))
|
---|
767 | rc = pDbgc->CmdHlp.pfnExec(&pDbgc->CmdHlp, "%s", szCmd);
|
---|
768 | }
|
---|
769 | }
|
---|
770 |
|
---|
771 | /* If multi-stepping, take the next step: */
|
---|
772 | if (pDbgc->cMultiStepsLeft > 0 && pEvent->idCpu == idCpuSaved)
|
---|
773 | {
|
---|
774 | int rc2 = DBGFR3StepEx(pDbgc->pUVM, pDbgc->idCpu, DBGF_STEP_F_INTO, NULL, NULL, 0, pDbgc->uMultiStepStrideLength);
|
---|
775 | if (RT_SUCCESS(rc2))
|
---|
776 | fPrintPrompt = false;
|
---|
777 | else
|
---|
778 | DBGCCmdHlpFailRc(&pDbgc->CmdHlp, pDbgc->pMultiStepCmd, rc2, "DBGFR3StepEx(,,DBGF_STEP_F_INTO,) failed");
|
---|
779 | }
|
---|
780 | else
|
---|
781 | pDbgc->idCpu = pEvent->idCpu;
|
---|
782 | break;
|
---|
783 | }
|
---|
784 |
|
---|
785 | case DBGFEVENT_ASSERTION_HYPER:
|
---|
786 | {
|
---|
787 | pDbgc->idCpu = pEvent->idCpu;
|
---|
788 | rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL,
|
---|
789 | "\ndbgf event/%u: Hypervisor Assertion! (%s)\n"
|
---|
790 | "%s"
|
---|
791 | "%s"
|
---|
792 | "\n",
|
---|
793 | pEvent->idCpu,
|
---|
794 | dbgcGetEventCtx(pEvent->enmCtx),
|
---|
795 | pEvent->u.Assert.pszMsg1,
|
---|
796 | pEvent->u.Assert.pszMsg2);
|
---|
797 | if (RT_SUCCESS(rc))
|
---|
798 | rc = DBGCCmdHlpRegPrintf(&pDbgc->CmdHlp, pEvent->idCpu, -1, pDbgc->fRegTerse);
|
---|
799 | break;
|
---|
800 | }
|
---|
801 |
|
---|
802 | case DBGFEVENT_DEV_STOP:
|
---|
803 | {
|
---|
804 | pDbgc->idCpu = pEvent->idCpu;
|
---|
805 | rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL,
|
---|
806 | "\n"
|
---|
807 | "dbgf event/%u: DBGFSTOP (%s)\n"
|
---|
808 | "File: %s\n"
|
---|
809 | "Line: %d\n"
|
---|
810 | "Function: %s\n",
|
---|
811 | pEvent->idCpu,
|
---|
812 | dbgcGetEventCtx(pEvent->enmCtx),
|
---|
813 | pEvent->u.Src.pszFile,
|
---|
814 | pEvent->u.Src.uLine,
|
---|
815 | pEvent->u.Src.pszFunction);
|
---|
816 | if (RT_SUCCESS(rc) && pEvent->u.Src.pszMessage && *pEvent->u.Src.pszMessage)
|
---|
817 | rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL,
|
---|
818 | "Message: %s\n",
|
---|
819 | pEvent->u.Src.pszMessage);
|
---|
820 | if (RT_SUCCESS(rc))
|
---|
821 | rc = DBGCCmdHlpRegPrintf(&pDbgc->CmdHlp, pEvent->idCpu, -1, pDbgc->fRegTerse);
|
---|
822 | break;
|
---|
823 | }
|
---|
824 |
|
---|
825 |
|
---|
826 | case DBGFEVENT_INVALID_COMMAND:
|
---|
827 | {
|
---|
828 | rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "\ndbgf/dbgc error: Invalid command event!\n");
|
---|
829 | break;
|
---|
830 | }
|
---|
831 |
|
---|
832 | case DBGFEVENT_POWERING_OFF:
|
---|
833 | {
|
---|
834 | pDbgc->fReady = false;
|
---|
835 | pDbgc->pIo->pfnSetReady(pDbgc->pIo, false);
|
---|
836 | pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "\nVM is powering off!\n");
|
---|
837 | fPrintPrompt = false;
|
---|
838 | rc = VERR_GENERAL_FAILURE;
|
---|
839 | break;
|
---|
840 | }
|
---|
841 |
|
---|
842 |
|
---|
843 | default:
|
---|
844 | {
|
---|
845 | /*
|
---|
846 | * Probably a generic event. Look it up to find its name.
|
---|
847 | */
|
---|
848 | PCDBGCSXEVT pEvtDesc = dbgcEventLookup(pEvent->enmType);
|
---|
849 | if (pEvtDesc)
|
---|
850 | {
|
---|
851 | if (pEvtDesc->enmKind == kDbgcSxEventKind_Interrupt)
|
---|
852 | {
|
---|
853 | Assert(pEvtDesc->pszDesc);
|
---|
854 | Assert(pEvent->u.Generic.cArgs == 1);
|
---|
855 | rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "\ndbgf event/%u: %s no %#llx! (%s)\n",
|
---|
856 | pEvent->idCpu, pEvtDesc->pszDesc, pEvent->u.Generic.auArgs[0], pEvtDesc->pszName);
|
---|
857 | }
|
---|
858 | else if (pEvtDesc->fFlags & DBGCSXEVT_F_BUGCHECK)
|
---|
859 | {
|
---|
860 | Assert(pEvent->u.Generic.cArgs >= 5);
|
---|
861 | char szDetails[512];
|
---|
862 | DBGFR3FormatBugCheck(pDbgc->pUVM, szDetails, sizeof(szDetails), pEvent->u.Generic.auArgs[0],
|
---|
863 | pEvent->u.Generic.auArgs[1], pEvent->u.Generic.auArgs[2],
|
---|
864 | pEvent->u.Generic.auArgs[3], pEvent->u.Generic.auArgs[4]);
|
---|
865 | rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "\ndbgf event/%u: %s %s%s!\n%s", pEvent->idCpu,
|
---|
866 | pEvtDesc->pszName, pEvtDesc->pszDesc ? "- " : "",
|
---|
867 | pEvtDesc->pszDesc ? pEvtDesc->pszDesc : "", szDetails);
|
---|
868 | }
|
---|
869 | else if ( (pEvtDesc->fFlags & DBGCSXEVT_F_TAKE_ARG)
|
---|
870 | || pEvent->u.Generic.cArgs > 1
|
---|
871 | || ( pEvent->u.Generic.cArgs == 1
|
---|
872 | && pEvent->u.Generic.auArgs[0] != 0))
|
---|
873 | {
|
---|
874 | if (pEvtDesc->pszDesc)
|
---|
875 | rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "\ndbgf event/%u: %s - %s!",
|
---|
876 | pEvent->idCpu, pEvtDesc->pszName, pEvtDesc->pszDesc);
|
---|
877 | else
|
---|
878 | rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "\ndbgf event/%u: %s!",
|
---|
879 | pEvent->idCpu, pEvtDesc->pszName);
|
---|
880 | if (pEvent->u.Generic.cArgs <= 1)
|
---|
881 | rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, " arg=%#llx\n", pEvent->u.Generic.auArgs[0]);
|
---|
882 | else
|
---|
883 | {
|
---|
884 | for (uint32_t i = 0; i < pEvent->u.Generic.cArgs; i++)
|
---|
885 | rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, " args[%u]=%#llx", i, pEvent->u.Generic.auArgs[i]);
|
---|
886 | rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "\n");
|
---|
887 | }
|
---|
888 | }
|
---|
889 | else
|
---|
890 | {
|
---|
891 | if (pEvtDesc->pszDesc)
|
---|
892 | rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "\ndbgf event/%u: %s - %s!\n",
|
---|
893 | pEvent->idCpu, pEvtDesc->pszName, pEvtDesc->pszDesc);
|
---|
894 | else
|
---|
895 | rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "\ndbgf event/%u: %s!\n",
|
---|
896 | pEvent->idCpu, pEvtDesc->pszName);
|
---|
897 | }
|
---|
898 | }
|
---|
899 | else
|
---|
900 | rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "\ndbgf/dbgc error: Unknown event %d on CPU %u!\n",
|
---|
901 | pEvent->enmType, pEvent->idCpu);
|
---|
902 | break;
|
---|
903 | }
|
---|
904 | }
|
---|
905 |
|
---|
906 | /*
|
---|
907 | * Prompt, anyone?
|
---|
908 | */
|
---|
909 | if (fPrintPrompt && RT_SUCCESS(rc))
|
---|
910 | {
|
---|
911 | /** @todo add CPU indicator to the prompt if an SMP VM? */
|
---|
912 | rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "VBoxDbg> ");
|
---|
913 | pDbgc->fReady = true;
|
---|
914 | if (RT_SUCCESS(rc))
|
---|
915 | pDbgc->pIo->pfnSetReady(pDbgc->pIo, true);
|
---|
916 | pDbgc->cMultiStepsLeft = 0;
|
---|
917 | }
|
---|
918 |
|
---|
919 | return rc;
|
---|
920 | }
|
---|
921 |
|
---|
922 |
|
---|
923 | /**
|
---|
924 | * Prints any log lines from the log buffer.
|
---|
925 | *
|
---|
926 | * The caller must not call function this unless pDbgc->fLog is set.
|
---|
927 | *
|
---|
928 | * @returns VBox status code. (output related)
|
---|
929 | * @param pDbgc Debugger console instance data.
|
---|
930 | */
|
---|
931 | static int dbgcProcessLog(PDBGC pDbgc)
|
---|
932 | {
|
---|
933 | /** @todo */
|
---|
934 | NOREF(pDbgc);
|
---|
935 | return 0;
|
---|
936 | }
|
---|
937 |
|
---|
938 | /** @callback_method_impl{FNRTDBGCFGLOG} */
|
---|
939 | static DECLCALLBACK(void) dbgcDbgCfgLogCallback(RTDBGCFG hDbgCfg, uint32_t iLevel, const char *pszMsg, void *pvUser)
|
---|
940 | {
|
---|
941 | /** @todo Add symbol noise setting. */
|
---|
942 | NOREF(hDbgCfg); NOREF(iLevel);
|
---|
943 | PDBGC pDbgc = (PDBGC)pvUser;
|
---|
944 | pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "%s", pszMsg);
|
---|
945 | }
|
---|
946 |
|
---|
947 |
|
---|
948 | /**
|
---|
949 | * Run the debugger console.
|
---|
950 | *
|
---|
951 | * @returns VBox status code.
|
---|
952 | * @param pDbgc Pointer to the debugger console instance data.
|
---|
953 | */
|
---|
954 | int dbgcRun(PDBGC pDbgc)
|
---|
955 | {
|
---|
956 | /*
|
---|
957 | * We're ready for commands now.
|
---|
958 | */
|
---|
959 | pDbgc->fReady = true;
|
---|
960 | pDbgc->pIo->pfnSetReady(pDbgc->pIo, true);
|
---|
961 |
|
---|
962 | /*
|
---|
963 | * Main Debugger Loop.
|
---|
964 | *
|
---|
965 | * This loop will either block on waiting for input or on waiting on
|
---|
966 | * debug events. If we're forwarding the log we cannot wait for long
|
---|
967 | * before we must flush the log.
|
---|
968 | */
|
---|
969 | int rc;
|
---|
970 | for (;;)
|
---|
971 | {
|
---|
972 | rc = VERR_SEM_OUT_OF_TURN;
|
---|
973 | if (pDbgc->pUVM)
|
---|
974 | rc = DBGFR3QueryWaitable(pDbgc->pUVM);
|
---|
975 |
|
---|
976 | if (RT_SUCCESS(rc))
|
---|
977 | {
|
---|
978 | /*
|
---|
979 | * Wait for a debug event.
|
---|
980 | */
|
---|
981 | DBGFEVENT Event;
|
---|
982 | rc = DBGFR3EventWait(pDbgc->pUVM, pDbgc->fLog ? 1 : 32, &Event);
|
---|
983 | if (RT_SUCCESS(rc))
|
---|
984 | {
|
---|
985 | rc = dbgcProcessEvent(pDbgc, &Event);
|
---|
986 | if (RT_FAILURE(rc))
|
---|
987 | break;
|
---|
988 | }
|
---|
989 | else if (rc != VERR_TIMEOUT)
|
---|
990 | break;
|
---|
991 |
|
---|
992 | /*
|
---|
993 | * Check for input.
|
---|
994 | */
|
---|
995 | if (pDbgc->pIo->pfnInput(pDbgc->pIo, 0))
|
---|
996 | {
|
---|
997 | rc = dbgcProcessInput(pDbgc, false /* fNoExecute */);
|
---|
998 | if (RT_FAILURE(rc))
|
---|
999 | break;
|
---|
1000 | }
|
---|
1001 | }
|
---|
1002 | else if (rc == VERR_SEM_OUT_OF_TURN)
|
---|
1003 | {
|
---|
1004 | /*
|
---|
1005 | * Wait for input. If Logging is enabled we'll only wait very briefly.
|
---|
1006 | */
|
---|
1007 | if (pDbgc->pIo->pfnInput(pDbgc->pIo, pDbgc->fLog ? 1 : 1000))
|
---|
1008 | {
|
---|
1009 | rc = dbgcProcessInput(pDbgc, false /* fNoExecute */);
|
---|
1010 | if (RT_FAILURE(rc))
|
---|
1011 | break;
|
---|
1012 | }
|
---|
1013 | }
|
---|
1014 | else
|
---|
1015 | break;
|
---|
1016 |
|
---|
1017 | /*
|
---|
1018 | * Forward log output.
|
---|
1019 | */
|
---|
1020 | if (pDbgc->fLog)
|
---|
1021 | {
|
---|
1022 | rc = dbgcProcessLog(pDbgc);
|
---|
1023 | if (RT_FAILURE(rc))
|
---|
1024 | break;
|
---|
1025 | }
|
---|
1026 | }
|
---|
1027 |
|
---|
1028 | return rc;
|
---|
1029 | }
|
---|
1030 |
|
---|
1031 |
|
---|
1032 | /**
|
---|
1033 | * Run the init scripts, if present.
|
---|
1034 | *
|
---|
1035 | * @param pDbgc The console instance.
|
---|
1036 | */
|
---|
1037 | static void dbgcRunInitScripts(PDBGC pDbgc)
|
---|
1038 | {
|
---|
1039 | /*
|
---|
1040 | * Do the global one, if it exists.
|
---|
1041 | */
|
---|
1042 | if ( pDbgc->pszGlobalInitScript
|
---|
1043 | && *pDbgc->pszGlobalInitScript != '\0'
|
---|
1044 | && RTFileExists(pDbgc->pszGlobalInitScript))
|
---|
1045 | dbgcEvalScript(pDbgc, pDbgc->pszGlobalInitScript, true /*fAnnounce*/);
|
---|
1046 |
|
---|
1047 | /*
|
---|
1048 | * Then do the local one, if it exists.
|
---|
1049 | */
|
---|
1050 | if ( pDbgc->pszLocalInitScript
|
---|
1051 | && *pDbgc->pszLocalInitScript != '\0'
|
---|
1052 | && RTFileExists(pDbgc->pszLocalInitScript))
|
---|
1053 | dbgcEvalScript(pDbgc, pDbgc->pszLocalInitScript, true /*fAnnounce*/);
|
---|
1054 | }
|
---|
1055 |
|
---|
1056 |
|
---|
1057 | /**
|
---|
1058 | * Reads the CFGM configuration of the DBGC.
|
---|
1059 | *
|
---|
1060 | * Popuplates the PDBGC::pszHistoryFile, PDBGC::pszGlobalInitScript and
|
---|
1061 | * PDBGC::pszLocalInitScript members.
|
---|
1062 | *
|
---|
1063 | * @returns VBox status code.
|
---|
1064 | * @param pDbgc The console instance.
|
---|
1065 | * @param pUVM The user mode VM handle.
|
---|
1066 | */
|
---|
1067 | static int dbgcReadConfig(PDBGC pDbgc, PUVM pUVM)
|
---|
1068 | {
|
---|
1069 | /*
|
---|
1070 | * Get and validate the configuration node.
|
---|
1071 | */
|
---|
1072 | PCFGMNODE pNode = CFGMR3GetChild(CFGMR3GetRootU(pUVM), "DBGC");
|
---|
1073 | int rc = CFGMR3ValidateConfig(pNode, "/DBGC/",
|
---|
1074 | "Enabled|"
|
---|
1075 | "HistoryFile|"
|
---|
1076 | "LocalInitScript|"
|
---|
1077 | "GlobalInitScript|",
|
---|
1078 | "*", "DBGC", 0);
|
---|
1079 | AssertRCReturn(rc, rc);
|
---|
1080 |
|
---|
1081 | /*
|
---|
1082 | * Query the values.
|
---|
1083 | */
|
---|
1084 | char szHomeDefault[RTPATH_MAX];
|
---|
1085 | rc = RTPathUserHome(szHomeDefault, sizeof(szHomeDefault) - 32);
|
---|
1086 | AssertLogRelRCReturn(rc, rc);
|
---|
1087 | size_t cchHome = strlen(szHomeDefault);
|
---|
1088 |
|
---|
1089 | /** @cfgm{/DBGC/HistoryFile, string, ${HOME}/.vboxdbgc-history}
|
---|
1090 | * The command history file of the VBox debugger. */
|
---|
1091 | rc = RTPathAppend(szHomeDefault, sizeof(szHomeDefault), ".vboxdbgc-history");
|
---|
1092 | AssertLogRelRCReturn(rc, rc);
|
---|
1093 |
|
---|
1094 | char szPath[RTPATH_MAX];
|
---|
1095 | rc = CFGMR3QueryStringDef(pNode, "HistoryFile", szPath, sizeof(szPath), szHomeDefault);
|
---|
1096 | AssertLogRelRCReturn(rc, rc);
|
---|
1097 |
|
---|
1098 | pDbgc->pszHistoryFile = RTStrDup(szPath);
|
---|
1099 | AssertReturn(pDbgc->pszHistoryFile, VERR_NO_STR_MEMORY);
|
---|
1100 |
|
---|
1101 | /** @cfgm{/DBGC/GlobalInitFile, string, ${HOME}/.vboxdbgc-init}
|
---|
1102 | * The global init script of the VBox debugger. */
|
---|
1103 | szHomeDefault[cchHome] = '\0';
|
---|
1104 | rc = RTPathAppend(szHomeDefault, sizeof(szHomeDefault), ".vboxdbgc-init");
|
---|
1105 | AssertLogRelRCReturn(rc, rc);
|
---|
1106 |
|
---|
1107 | rc = CFGMR3QueryStringDef(pNode, "GlobalInitScript", szPath, sizeof(szPath), szHomeDefault);
|
---|
1108 | AssertLogRelRCReturn(rc, rc);
|
---|
1109 |
|
---|
1110 | pDbgc->pszGlobalInitScript = RTStrDup(szPath);
|
---|
1111 | AssertReturn(pDbgc->pszGlobalInitScript, VERR_NO_STR_MEMORY);
|
---|
1112 |
|
---|
1113 | /** @cfgm{/DBGC/LocalInitFile, string, none}
|
---|
1114 | * The VM local init script of the VBox debugger. */
|
---|
1115 | rc = CFGMR3QueryString(pNode, "LocalInitScript", szPath, sizeof(szPath));
|
---|
1116 | if (RT_SUCCESS(rc))
|
---|
1117 | {
|
---|
1118 | pDbgc->pszLocalInitScript = RTStrDup(szPath);
|
---|
1119 | AssertReturn(pDbgc->pszLocalInitScript, VERR_NO_STR_MEMORY);
|
---|
1120 | }
|
---|
1121 | else
|
---|
1122 | {
|
---|
1123 | AssertLogRelReturn(rc == VERR_CFGM_VALUE_NOT_FOUND || rc == VERR_CFGM_NO_PARENT, rc);
|
---|
1124 | pDbgc->pszLocalInitScript = NULL;
|
---|
1125 | }
|
---|
1126 |
|
---|
1127 | return VINF_SUCCESS;
|
---|
1128 | }
|
---|
1129 |
|
---|
1130 |
|
---|
1131 | /**
|
---|
1132 | * @copydoc DBGC::pfnOutput
|
---|
1133 | */
|
---|
1134 | static DECLCALLBACK(int) dbgcOutputNative(void *pvUser, const char *pachChars, size_t cbChars)
|
---|
1135 | {
|
---|
1136 | PDBGC pDbgc = (PDBGC)pvUser;
|
---|
1137 | return pDbgc->pIo->pfnWrite(pDbgc->pIo, pachChars, cbChars, NULL /*pcbWritten*/);
|
---|
1138 | }
|
---|
1139 |
|
---|
1140 |
|
---|
1141 | /**
|
---|
1142 | * Creates a a new instance.
|
---|
1143 | *
|
---|
1144 | * @returns VBox status code.
|
---|
1145 | * @param ppDbgc Where to store the pointer to the instance data.
|
---|
1146 | * @param pIo Pointer to the I/O callback table.
|
---|
1147 | * @param fFlags The flags.
|
---|
1148 | */
|
---|
1149 | int dbgcCreate(PDBGC *ppDbgc, PCDBGCIO pIo, unsigned fFlags)
|
---|
1150 | {
|
---|
1151 | /*
|
---|
1152 | * Validate input.
|
---|
1153 | */
|
---|
1154 | AssertPtrReturn(pIo, VERR_INVALID_POINTER);
|
---|
1155 | AssertMsgReturn(!fFlags, ("%#x", fFlags), VERR_INVALID_PARAMETER);
|
---|
1156 |
|
---|
1157 | /*
|
---|
1158 | * Allocate and initialize.
|
---|
1159 | */
|
---|
1160 | PDBGC pDbgc = (PDBGC)RTMemAllocZ(sizeof(*pDbgc));
|
---|
1161 | if (!pDbgc)
|
---|
1162 | return VERR_NO_MEMORY;
|
---|
1163 |
|
---|
1164 | dbgcInitCmdHlp(pDbgc);
|
---|
1165 | pDbgc->pIo = pIo;
|
---|
1166 | pDbgc->pfnOutput = dbgcOutputNative;
|
---|
1167 | pDbgc->pvOutputUser = pDbgc;
|
---|
1168 | pDbgc->pVM = NULL;
|
---|
1169 | pDbgc->pUVM = NULL;
|
---|
1170 | pDbgc->idCpu = 0;
|
---|
1171 | pDbgc->hDbgAs = DBGF_AS_GLOBAL;
|
---|
1172 | pDbgc->pszEmulation = "CodeView/WinDbg";
|
---|
1173 | pDbgc->paEmulationCmds = &g_aCmdsCodeView[0];
|
---|
1174 | pDbgc->cEmulationCmds = g_cCmdsCodeView;
|
---|
1175 | pDbgc->paEmulationFuncs = &g_aFuncsCodeView[0];
|
---|
1176 | pDbgc->cEmulationFuncs = g_cFuncsCodeView;
|
---|
1177 | //pDbgc->fLog = false;
|
---|
1178 | pDbgc->fRegTerse = true;
|
---|
1179 | pDbgc->fStepTraceRegs = true;
|
---|
1180 | //pDbgc->cPagingHierarchyDumps = 0;
|
---|
1181 | //pDbgc->DisasmPos = {0};
|
---|
1182 | //pDbgc->SourcePos = {0};
|
---|
1183 | //pDbgc->DumpPos = {0};
|
---|
1184 | pDbgc->pLastPos = &pDbgc->DisasmPos;
|
---|
1185 | //pDbgc->cbDumpElement = 0;
|
---|
1186 | //pDbgc->cVars = 0;
|
---|
1187 | //pDbgc->paVars = NULL;
|
---|
1188 | //pDbgc->pPlugInHead = NULL;
|
---|
1189 | //pDbgc->pFirstBp = NULL;
|
---|
1190 | RTListInit(&pDbgc->LstTraceFlowMods);
|
---|
1191 | //pDbgc->abSearch = {0};
|
---|
1192 | //pDbgc->cbSearch = 0;
|
---|
1193 | pDbgc->cbSearchUnit = 1;
|
---|
1194 | pDbgc->cMaxSearchHits = 1;
|
---|
1195 | //pDbgc->SearchAddr = {0};
|
---|
1196 | //pDbgc->cbSearchRange = 0;
|
---|
1197 |
|
---|
1198 | //pDbgc->uInputZero = 0;
|
---|
1199 | //pDbgc->iRead = 0;
|
---|
1200 | //pDbgc->iWrite = 0;
|
---|
1201 | //pDbgc->cInputLines = 0;
|
---|
1202 | //pDbgc->fInputOverflow = false;
|
---|
1203 | pDbgc->fReady = true;
|
---|
1204 | pDbgc->pszScratch = &pDbgc->achScratch[0];
|
---|
1205 | //pDbgc->iArg = 0;
|
---|
1206 | //pDbgc->rcOutput = 0;
|
---|
1207 | //pDbgc->rcCmd = 0;
|
---|
1208 |
|
---|
1209 | //pDbgc->pszHistoryFile = NULL;
|
---|
1210 | //pDbgc->pszGlobalInitScript = NULL;
|
---|
1211 | //pDbgc->pszLocalInitScript = NULL;
|
---|
1212 |
|
---|
1213 | dbgcEvalInit();
|
---|
1214 |
|
---|
1215 | *ppDbgc = pDbgc;
|
---|
1216 | return VINF_SUCCESS;
|
---|
1217 | }
|
---|
1218 |
|
---|
1219 | /**
|
---|
1220 | * Destroys a DBGC instance created by dbgcCreate.
|
---|
1221 | *
|
---|
1222 | * @param pDbgc Pointer to the debugger console instance data.
|
---|
1223 | */
|
---|
1224 | void dbgcDestroy(PDBGC pDbgc)
|
---|
1225 | {
|
---|
1226 | AssertPtr(pDbgc);
|
---|
1227 |
|
---|
1228 | /* Disable log hook. */
|
---|
1229 | if (pDbgc->fLog)
|
---|
1230 | {
|
---|
1231 |
|
---|
1232 | }
|
---|
1233 |
|
---|
1234 | /* Detach from the VM. */
|
---|
1235 | if (pDbgc->pUVM)
|
---|
1236 | DBGFR3Detach(pDbgc->pUVM);
|
---|
1237 |
|
---|
1238 | /* Free config strings. */
|
---|
1239 | RTStrFree(pDbgc->pszGlobalInitScript);
|
---|
1240 | pDbgc->pszGlobalInitScript = NULL;
|
---|
1241 | RTStrFree(pDbgc->pszLocalInitScript);
|
---|
1242 | pDbgc->pszLocalInitScript = NULL;
|
---|
1243 | RTStrFree(pDbgc->pszHistoryFile);
|
---|
1244 | pDbgc->pszHistoryFile = NULL;
|
---|
1245 |
|
---|
1246 | /* Finally, free the instance memory. */
|
---|
1247 | RTMemFree(pDbgc);
|
---|
1248 | }
|
---|
1249 |
|
---|
1250 |
|
---|
1251 | /**
|
---|
1252 | * Make a console instance.
|
---|
1253 | *
|
---|
1254 | * This will not return until either an 'exit' command is issued or a error code
|
---|
1255 | * indicating connection loss is encountered.
|
---|
1256 | *
|
---|
1257 | * @returns VINF_SUCCESS if console termination caused by the 'exit' command.
|
---|
1258 | * @returns The VBox status code causing the console termination.
|
---|
1259 | *
|
---|
1260 | * @param pUVM The user mode VM handle.
|
---|
1261 | * @param pIo Pointer to the I/O callback structure. This must contain
|
---|
1262 | * a full set of function pointers to service the console.
|
---|
1263 | * @param fFlags Reserved, must be zero.
|
---|
1264 | * @remarks A forced termination of the console is easiest done by forcing the
|
---|
1265 | * callbacks to return fatal failures.
|
---|
1266 | */
|
---|
1267 | DBGDECL(int) DBGCCreate(PUVM pUVM, PCDBGCIO pIo, unsigned fFlags)
|
---|
1268 | {
|
---|
1269 | /*
|
---|
1270 | * Validate input.
|
---|
1271 | */
|
---|
1272 | AssertPtrNullReturn(pUVM, VERR_INVALID_VM_HANDLE);
|
---|
1273 | PVM pVM = NULL;
|
---|
1274 | if (pUVM)
|
---|
1275 | {
|
---|
1276 | pVM = VMR3GetVM(pUVM);
|
---|
1277 | AssertPtrReturn(pVM, VERR_INVALID_VM_HANDLE);
|
---|
1278 | }
|
---|
1279 |
|
---|
1280 | /*
|
---|
1281 | * Allocate and initialize instance data
|
---|
1282 | */
|
---|
1283 | PDBGC pDbgc;
|
---|
1284 | int rc = dbgcCreate(&pDbgc, pIo, fFlags);
|
---|
1285 | if (RT_FAILURE(rc))
|
---|
1286 | return rc;
|
---|
1287 | if (!HMR3IsEnabled(pUVM) && !NEMR3IsEnabled(pUVM))
|
---|
1288 | pDbgc->hDbgAs = DBGF_AS_RC_AND_GC_GLOBAL;
|
---|
1289 |
|
---|
1290 | /*
|
---|
1291 | * Print welcome message.
|
---|
1292 | */
|
---|
1293 | rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL,
|
---|
1294 | "Welcome to the VirtualBox Debugger!\n");
|
---|
1295 |
|
---|
1296 | /*
|
---|
1297 | * Attach to the specified VM.
|
---|
1298 | */
|
---|
1299 | if (RT_SUCCESS(rc) && pUVM)
|
---|
1300 | {
|
---|
1301 | rc = dbgcReadConfig(pDbgc, pUVM);
|
---|
1302 | if (RT_SUCCESS(rc))
|
---|
1303 | {
|
---|
1304 | rc = DBGFR3Attach(pUVM);
|
---|
1305 | if (RT_SUCCESS(rc))
|
---|
1306 | {
|
---|
1307 | pDbgc->pVM = pVM;
|
---|
1308 | pDbgc->pUVM = pUVM;
|
---|
1309 | pDbgc->idCpu = 0;
|
---|
1310 | rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL,
|
---|
1311 | "Current VM is %08x, CPU #%u\n" /** @todo get and print the VM name! */
|
---|
1312 | , pDbgc->pVM, pDbgc->idCpu);
|
---|
1313 | }
|
---|
1314 | else
|
---|
1315 | rc = pDbgc->CmdHlp.pfnVBoxError(&pDbgc->CmdHlp, rc, "When trying to attach to VM %p\n", pDbgc->pVM);
|
---|
1316 | }
|
---|
1317 | else
|
---|
1318 | rc = pDbgc->CmdHlp.pfnVBoxError(&pDbgc->CmdHlp, rc, "Error reading configuration\n");
|
---|
1319 | }
|
---|
1320 |
|
---|
1321 | /*
|
---|
1322 | * Load plugins.
|
---|
1323 | */
|
---|
1324 | if (RT_SUCCESS(rc))
|
---|
1325 | {
|
---|
1326 | if (pVM)
|
---|
1327 | DBGFR3PlugInLoadAll(pDbgc->pUVM);
|
---|
1328 | dbgcEventInit(pDbgc);
|
---|
1329 | dbgcRunInitScripts(pDbgc);
|
---|
1330 |
|
---|
1331 | rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "VBoxDbg> ");
|
---|
1332 | if (RT_SUCCESS(rc))
|
---|
1333 | {
|
---|
1334 | /*
|
---|
1335 | * Set debug config log callback.
|
---|
1336 | */
|
---|
1337 | RTDBGCFG hDbgCfg = DBGFR3AsGetConfig(pUVM);
|
---|
1338 | if ( hDbgCfg != NIL_RTDBGCFG
|
---|
1339 | && RTDbgCfgRetain(hDbgCfg) != UINT32_MAX)
|
---|
1340 | {
|
---|
1341 | int rc2 = RTDbgCfgSetLogCallback(hDbgCfg, dbgcDbgCfgLogCallback, pDbgc);
|
---|
1342 | if (RT_FAILURE(rc2))
|
---|
1343 | {
|
---|
1344 | hDbgCfg = NIL_RTDBGCFG;
|
---|
1345 | RTDbgCfgRelease(hDbgCfg);
|
---|
1346 | }
|
---|
1347 | }
|
---|
1348 | else
|
---|
1349 | hDbgCfg = NIL_RTDBGCFG;
|
---|
1350 |
|
---|
1351 |
|
---|
1352 | /*
|
---|
1353 | * Run the debugger main loop.
|
---|
1354 | */
|
---|
1355 | rc = dbgcRun(pDbgc);
|
---|
1356 |
|
---|
1357 |
|
---|
1358 | /*
|
---|
1359 | * Remove debug config log callback.
|
---|
1360 | */
|
---|
1361 | if (hDbgCfg != NIL_RTDBGCFG)
|
---|
1362 | {
|
---|
1363 | RTDbgCfgSetLogCallback(hDbgCfg, NULL, NULL);
|
---|
1364 | RTDbgCfgRelease(hDbgCfg);
|
---|
1365 | }
|
---|
1366 | }
|
---|
1367 | dbgcEventTerm(pDbgc);
|
---|
1368 | }
|
---|
1369 | else
|
---|
1370 | pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "\nDBGCCreate error: %Rrc\n", rc);
|
---|
1371 |
|
---|
1372 |
|
---|
1373 | /*
|
---|
1374 | * Cleanup console debugger session.
|
---|
1375 | */
|
---|
1376 | dbgcDestroy(pDbgc);
|
---|
1377 | return rc == VERR_DBGC_QUIT ? VINF_SUCCESS : rc;
|
---|
1378 | }
|
---|
1379 |
|
---|