DBGConsole.cpp revision bb5391c96a16b4ba7f86878998710d4a8e7fce53
6739cf90e4aa3b3344768b8da241802f80ff455cvboxsync/* $Id$ */
46f059bea92bedbd395793702c73946ead235586vboxsync/** @file
46f059bea92bedbd395793702c73946ead235586vboxsync * DBGC - Debugger Console.
46f059bea92bedbd395793702c73946ead235586vboxsync */
46f059bea92bedbd395793702c73946ead235586vboxsync
46f059bea92bedbd395793702c73946ead235586vboxsync/*
46f059bea92bedbd395793702c73946ead235586vboxsync * Copyright (C) 2006-2011 Oracle Corporation
46f059bea92bedbd395793702c73946ead235586vboxsync *
46f059bea92bedbd395793702c73946ead235586vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
46f059bea92bedbd395793702c73946ead235586vboxsync * available from http://www.virtualbox.org. This file is free software;
46f059bea92bedbd395793702c73946ead235586vboxsync * you can redistribute it and/or modify it under the terms of the GNU
46f059bea92bedbd395793702c73946ead235586vboxsync * General Public License (GPL) as published by the Free Software
46f059bea92bedbd395793702c73946ead235586vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
46f059bea92bedbd395793702c73946ead235586vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
e64031e20c39650a7bc902a3e1aba613b9415deevboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync */
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync/** @page pg_dbgc DBGC - The Debug Console
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync *
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * The debugger console is an early attempt to make some interactive
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * debugging facilities for the VirtualBox VMM. It was initially only
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * accessible thru a telnet session on debug builds. Later it was hastily
46f059bea92bedbd395793702c73946ead235586vboxsync * built into the VBoxDbg module with a very simple Qt wrapper around it.
46f059bea92bedbd395793702c73946ead235586vboxsync *
46f059bea92bedbd395793702c73946ead235586vboxsync * The debugger is optional and presently not built into release builds
46f059bea92bedbd395793702c73946ead235586vboxsync * of VirtualBox. It is therefore necessary to enclose code related to it
46f059bea92bedbd395793702c73946ead235586vboxsync * in \#ifdef VBOX_WITH_DEBUGGER blocks. This is mandatory for components
46f059bea92bedbd395793702c73946ead235586vboxsync * that register extenral commands.
46f059bea92bedbd395793702c73946ead235586vboxsync *
46f059bea92bedbd395793702c73946ead235586vboxsync *
46f059bea92bedbd395793702c73946ead235586vboxsync * @section sec_dbgc_op Operation (intentions)
46f059bea92bedbd395793702c73946ead235586vboxsync *
46f059bea92bedbd395793702c73946ead235586vboxsync * The console will process commands in a manner similar to the OS/2 and
46f059bea92bedbd395793702c73946ead235586vboxsync * windows kernel debuggers. This means ';' is a command separator and
46f059bea92bedbd395793702c73946ead235586vboxsync * that when possible we'll use the same command names as these two uses.
46f059bea92bedbd395793702c73946ead235586vboxsync *
46f059bea92bedbd395793702c73946ead235586vboxsync *
46f059bea92bedbd395793702c73946ead235586vboxsync * @subsection sec_dbg_op_numbers Numbers
46f059bea92bedbd395793702c73946ead235586vboxsync *
46f059bea92bedbd395793702c73946ead235586vboxsync * Numbers are hexadecimal unless specified with a prefix indicating
46f059bea92bedbd395793702c73946ead235586vboxsync * elsewise. Prefixes:
46f059bea92bedbd395793702c73946ead235586vboxsync * - '0x' - hexadecimal.
46f059bea92bedbd395793702c73946ead235586vboxsync * - '0i' - decimal
46f059bea92bedbd395793702c73946ead235586vboxsync * - '0t' - octal.
46f059bea92bedbd395793702c73946ead235586vboxsync * - '0y' - binary.
46f059bea92bedbd395793702c73946ead235586vboxsync *
46f059bea92bedbd395793702c73946ead235586vboxsync * Some of the prefixes are a bit uncommon, the reason for this that
46f059bea92bedbd395793702c73946ead235586vboxsync * the typical binary prefix '0b' can also be a hexadecimal value since
46f059bea92bedbd395793702c73946ead235586vboxsync * no prefix or suffix is required for such values. Ditto for '0d' and
46f059bea92bedbd395793702c73946ead235586vboxsync * '0' for decimal and octal.
46f059bea92bedbd395793702c73946ead235586vboxsync *
46f059bea92bedbd395793702c73946ead235586vboxsync *
46f059bea92bedbd395793702c73946ead235586vboxsync * @subsection sec_dbg_op_address Addressing modes
46f059bea92bedbd395793702c73946ead235586vboxsync *
46f059bea92bedbd395793702c73946ead235586vboxsync * - Default is flat. For compatibility '%' also means flat.
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync * - Segmented addresses are specified selector:offset.
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync * - Physical addresses are specified using '%%'.
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync * - The default target for the addressing is the guest context, the '#'
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync * will override this and set it to the host.
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync * Note that several operations won't work on host addresses.
46f059bea92bedbd395793702c73946ead235586vboxsync *
46f059bea92bedbd395793702c73946ead235586vboxsync * The '%', '%%' and '#' prefixes is implemented as unary operators, while ':'
46f059bea92bedbd395793702c73946ead235586vboxsync * is a binary operator. Operator precedence takes care of evaluation order.
46f059bea92bedbd395793702c73946ead235586vboxsync *
46f059bea92bedbd395793702c73946ead235586vboxsync *
46f059bea92bedbd395793702c73946ead235586vboxsync * @subsection sec_dbg_op_evalution Evaluation
46f059bea92bedbd395793702c73946ead235586vboxsync *
46f059bea92bedbd395793702c73946ead235586vboxsync * Most unary and binary C operators are supported, check the help text for
46f059bea92bedbd395793702c73946ead235586vboxsync * details. However, some of these are not yet implemented because this is
46f059bea92bedbd395793702c73946ead235586vboxsync * tiresome and annoying work. So, if something is missing and you need it
1bef0d3fd3b2fe689a4eaa9ebf0647b8bf7c662evboxsync * you implement it or complain to bird. (Ditto for missing functions.)
46f059bea92bedbd395793702c73946ead235586vboxsync *
46f059bea92bedbd395793702c73946ead235586vboxsync * Simple variable support is provided thru the 'set' and 'unset' commands and
46f059bea92bedbd395793702c73946ead235586vboxsync * the unary '$' operator.
46f059bea92bedbd395793702c73946ead235586vboxsync *
46f059bea92bedbd395793702c73946ead235586vboxsync * The unary '@' operator will indicate function calls. Commands and functions
46f059bea92bedbd395793702c73946ead235586vboxsync * are the same thing, except that functions has a return type.
46f059bea92bedbd395793702c73946ead235586vboxsync *
46f059bea92bedbd395793702c73946ead235586vboxsync *
46f059bea92bedbd395793702c73946ead235586vboxsync * @subsection sec_dbg_op_registers Registers
46f059bea92bedbd395793702c73946ead235586vboxsync *
46f059bea92bedbd395793702c73946ead235586vboxsync * Registers are addressed using their name. Some registers which have several fields
46f059bea92bedbd395793702c73946ead235586vboxsync * (like gdtr) will have separate names indicating the different fields. The default
46f059bea92bedbd395793702c73946ead235586vboxsync * register set is the guest one. To access the hypervisor register one have to
46f059bea92bedbd395793702c73946ead235586vboxsync * prefix the register names with '.'.
46f059bea92bedbd395793702c73946ead235586vboxsync *
46f059bea92bedbd395793702c73946ead235586vboxsync * The registers are implemented as built-in symbols. For making gdb guys more at
46f059bea92bedbd395793702c73946ead235586vboxsync * home it is possible to access them with the '$' operator, i.e. as a variable.
46f059bea92bedbd395793702c73946ead235586vboxsync *
46f059bea92bedbd395793702c73946ead235586vboxsync *
46f059bea92bedbd395793702c73946ead235586vboxsync * @subsection sec_dbg_op_commands Commands and Functions
46f059bea92bedbd395793702c73946ead235586vboxsync *
46f059bea92bedbd395793702c73946ead235586vboxsync * Commands and functions are the same thing, except that functions may return a
46f059bea92bedbd395793702c73946ead235586vboxsync * value. So, functions may be used as commands. The command/function handlers
46f059bea92bedbd395793702c73946ead235586vboxsync * can detect whether they are invoked as a command or function by checking whether
46f059bea92bedbd395793702c73946ead235586vboxsync * there is a return variable or not.
46f059bea92bedbd395793702c73946ead235586vboxsync *
46f059bea92bedbd395793702c73946ead235586vboxsync * The command/function names are all lowercase, case sensitive, and starting
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync * with a letter. Operator characters are not permitted in the names of course.
46f059bea92bedbd395793702c73946ead235586vboxsync * Space is allowed, but must be flagged so the parser can check for multiple
46f059bea92bedbd395793702c73946ead235586vboxsync * spaces and tabs. (This feature is for 'dump xyz' and for emulating the
46f059bea92bedbd395793702c73946ead235586vboxsync * gdb 'info abc'.)
46f059bea92bedbd395793702c73946ead235586vboxsync *
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync * The '.' prefix indicates the set of external commands. External commands are
46f059bea92bedbd395793702c73946ead235586vboxsync * command registered by VMM components.
46f059bea92bedbd395793702c73946ead235586vboxsync *
46f059bea92bedbd395793702c73946ead235586vboxsync *
46f059bea92bedbd395793702c73946ead235586vboxsync * @section sec_dbgc_logging Logging
46f059bea92bedbd395793702c73946ead235586vboxsync *
46f059bea92bedbd395793702c73946ead235586vboxsync * The idea is to be able to pass thru debug and release logs to the console
46f059bea92bedbd395793702c73946ead235586vboxsync * if the user so wishes. This feature requires some kind of hook into the
46f059bea92bedbd395793702c73946ead235586vboxsync * logger instance and while this was sketched it hasn't yet been implemented
46f059bea92bedbd395793702c73946ead235586vboxsync * (dbgcProcessLog and DBGC::fLog).
46f059bea92bedbd395793702c73946ead235586vboxsync *
46f059bea92bedbd395793702c73946ead235586vboxsync *
46f059bea92bedbd395793702c73946ead235586vboxsync *
46f059bea92bedbd395793702c73946ead235586vboxsync * @section sec_dbgc_linking Linking and API
46f059bea92bedbd395793702c73946ead235586vboxsync *
46f059bea92bedbd395793702c73946ead235586vboxsync * The DBGC code is linked into the VBoxVMM module. (At present it is also
46f059bea92bedbd395793702c73946ead235586vboxsync * linked into VBoxDbg, but this is obviously very wrong.)
46f059bea92bedbd395793702c73946ead235586vboxsync *
46f059bea92bedbd395793702c73946ead235586vboxsync * A COM object will be created for the DBGC so it can be operated remotely
46f059bea92bedbd395793702c73946ead235586vboxsync * without using TCP. VBoxDbg is the intended audience for this usage. Some
46f059bea92bedbd395793702c73946ead235586vboxsync * questions about callbacks (for output) and security (you may wish to
46f059bea92bedbd395793702c73946ead235586vboxsync * restrict users from debugging a VM) needs to be answered first though.
46f059bea92bedbd395793702c73946ead235586vboxsync */
46f059bea92bedbd395793702c73946ead235586vboxsync
46f059bea92bedbd395793702c73946ead235586vboxsync
46f059bea92bedbd395793702c73946ead235586vboxsync/*******************************************************************************
46f059bea92bedbd395793702c73946ead235586vboxsync* Header Files *
46f059bea92bedbd395793702c73946ead235586vboxsync*******************************************************************************/
46f059bea92bedbd395793702c73946ead235586vboxsync#define LOG_GROUP LOG_GROUP_DBGC
46f059bea92bedbd395793702c73946ead235586vboxsync#include <VBox/dbg.h>
46f059bea92bedbd395793702c73946ead235586vboxsync#include <VBox/vmm/dbgf.h>
46f059bea92bedbd395793702c73946ead235586vboxsync#include <VBox/err.h>
46f059bea92bedbd395793702c73946ead235586vboxsync#include <VBox/log.h>
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync#include <iprt/asm.h>
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync#include <iprt/assert.h>
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync#include <iprt/mem.h>
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync#include <iprt/string.h>
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync#include "DBGCInternal.h"
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync#include "DBGPlugIns.h"
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync/*******************************************************************************
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync* Internal Functions *
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync*******************************************************************************/
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsyncstatic int dbgcProcessLog(PDBGC pDbgc);
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync/**
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync * Resolves a symbol (or tries to do so at least).
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync *
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync * @returns 0 on success.
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync * @returns VBox status on failure.
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync * @param pDbgc The debug console instance.
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync * @param pszSymbol The symbol name.
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync * @param enmType The result type. Specifying DBGCVAR_TYPE_GC_FAR may
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync * cause failure, avoid it.
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync * @param pResult Where to store the result.
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync */
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsyncint dbgcSymbolGet(PDBGC pDbgc, const char *pszSymbol, DBGCVARTYPE enmType, PDBGCVAR pResult)
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync{
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync int rc;
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync /*
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync * Builtin?
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync */
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync PCDBGCSYM pSymDesc = dbgcLookupRegisterSymbol(pDbgc, pszSymbol);
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync if (pSymDesc)
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync {
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync if (!pSymDesc->pfnGet)
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync return VERR_PARSE_WRITEONLY_SYMBOL;
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync return pSymDesc->pfnGet(pSymDesc, &pDbgc->CmdHlp, enmType, pResult);
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync }
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync /*
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync * A typical register? (Guest only)
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync */
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync static const char s_szSixLetterRegisters[] =
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync "rflags;eflags;"
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync ;
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync static const char s_szThreeLetterRegisters[] =
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync "eax;rax;" "r10;" "r8d;r8w;r8b;" "cr0;" "dr0;"
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync "ebx;rbx;" "r11;" "r9d;r9w;r8b;" "dr1;"
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync "ecx;rcx;" "r12;" "cr2;" "dr2;"
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync "edx;rdx;" "r13;" "cr3;" "dr3;"
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync "edi;rdi;dil;" "r14;" "cr4;" "dr4;"
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync "esi;rsi;sil;" "r15;" "cr8;"
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync "ebp;rbp;"
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync "esp;rsp;" "dr6;"
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync "rip;eip;" "dr7;"
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync "efl;"
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync ;
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync static const char s_szTwoLetterRegisters[] =
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync "ax;al;ah;" "r8;"
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync "bx;bl;bh;" "r9;"
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync "cx;cl;ch;" "cs;"
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync "dx;dl;dh;" "ds;"
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync "di;" "es;"
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync "si;" "fs;"
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync "bp;" "gs;"
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync "sp;" "ss;"
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync "ip;"
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync ;
57134cc31d26d91192e87a4541b4f82fbdb2c297vboxsync size_t const cchSymbol = strlen(pszSymbol);
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync if ( (cchSymbol == 2 && strstr(s_szTwoLetterRegisters, pszSymbol))
194a8ad893b721dfc22ac5f955671f09db015a3fvboxsync || (cchSymbol == 3 && strstr(s_szThreeLetterRegisters, pszSymbol))
194a8ad893b721dfc22ac5f955671f09db015a3fvboxsync || (cchSymbol == 6 && strstr(s_szSixLetterRegisters, pszSymbol)))
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync {
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync if (!strchr(pszSymbol, ';'))
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync {
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync DBGCVAR Var;
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync DBGCVAR_INIT_STRING(&Var, pszSymbol);
57134cc31d26d91192e87a4541b4f82fbdb2c297vboxsync rc = dbgcOpRegister(pDbgc, &Var, DBGCVAR_CAT_ANY, pResult);
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync if (RT_SUCCESS(rc))
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync return DBGCCmdHlpConvert(&pDbgc->CmdHlp, &Var, enmType, false /*fConvSyms*/, pResult);
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync }
57134cc31d26d91192e87a4541b4f82fbdb2c297vboxsync }
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync /*
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync * Ask PDM.
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync */
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync /** @todo resolve symbols using PDM. */
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync /*
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync * Ask the debug info manager.
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync */
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync RTDBGSYMBOL Symbol;
57134cc31d26d91192e87a4541b4f82fbdb2c297vboxsync rc = DBGFR3AsSymbolByName(pDbgc->pVM, pDbgc->hDbgAs, pszSymbol, &Symbol, NULL);
57134cc31d26d91192e87a4541b4f82fbdb2c297vboxsync if (RT_SUCCESS(rc))
57134cc31d26d91192e87a4541b4f82fbdb2c297vboxsync {
57134cc31d26d91192e87a4541b4f82fbdb2c297vboxsync /*
57134cc31d26d91192e87a4541b4f82fbdb2c297vboxsync * Default return is a flat gc address.
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync */
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync DBGCVAR_INIT_GC_FLAT(pResult, Symbol.Value);
57134cc31d26d91192e87a4541b4f82fbdb2c297vboxsync if (Symbol.cb)
57134cc31d26d91192e87a4541b4f82fbdb2c297vboxsync DBGCVAR_SET_RANGE(pResult, DBGCVAR_RANGE_BYTES, Symbol.cb);
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync switch (enmType)
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync {
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync /* nothing to do. */
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync case DBGCVAR_TYPE_GC_FLAT:
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync case DBGCVAR_TYPE_ANY:
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync return VINF_SUCCESS;
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync /* impossible at the moment. */
46f059bea92bedbd395793702c73946ead235586vboxsync case DBGCVAR_TYPE_GC_FAR:
46f059bea92bedbd395793702c73946ead235586vboxsync return VERR_PARSE_CONVERSION_FAILED;
46f059bea92bedbd395793702c73946ead235586vboxsync
46f059bea92bedbd395793702c73946ead235586vboxsync /* simply make it numeric. */
46f059bea92bedbd395793702c73946ead235586vboxsync case DBGCVAR_TYPE_NUMBER:
46f059bea92bedbd395793702c73946ead235586vboxsync pResult->enmType = DBGCVAR_TYPE_NUMBER;
46f059bea92bedbd395793702c73946ead235586vboxsync pResult->u.u64Number = Symbol.Value;
46f059bea92bedbd395793702c73946ead235586vboxsync return VINF_SUCCESS;
46f059bea92bedbd395793702c73946ead235586vboxsync
46f059bea92bedbd395793702c73946ead235586vboxsync /* cast it. */
46f059bea92bedbd395793702c73946ead235586vboxsync case DBGCVAR_TYPE_GC_PHYS:
46f059bea92bedbd395793702c73946ead235586vboxsync case DBGCVAR_TYPE_HC_FLAT:
46f059bea92bedbd395793702c73946ead235586vboxsync case DBGCVAR_TYPE_HC_PHYS:
46f059bea92bedbd395793702c73946ead235586vboxsync return DBGCCmdHlpConvert(&pDbgc->CmdHlp, pResult, enmType, false /*fConvSyms*/, pResult);
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync
46f059bea92bedbd395793702c73946ead235586vboxsync default:
46f059bea92bedbd395793702c73946ead235586vboxsync AssertMsgFailed(("Internal error enmType=%d\n", enmType));
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync return VERR_INVALID_PARAMETER;
46f059bea92bedbd395793702c73946ead235586vboxsync }
46f059bea92bedbd395793702c73946ead235586vboxsync }
46f059bea92bedbd395793702c73946ead235586vboxsync
46f059bea92bedbd395793702c73946ead235586vboxsync return VERR_PARSE_NOT_IMPLEMENTED;
46f059bea92bedbd395793702c73946ead235586vboxsync}
46f059bea92bedbd395793702c73946ead235586vboxsync
46f059bea92bedbd395793702c73946ead235586vboxsync
46f059bea92bedbd395793702c73946ead235586vboxsync/**
46f059bea92bedbd395793702c73946ead235586vboxsync * Process all commands currently in the buffer.
46f059bea92bedbd395793702c73946ead235586vboxsync *
46f059bea92bedbd395793702c73946ead235586vboxsync * @returns VBox status code. Any error indicates the termination of the console session.
46f059bea92bedbd395793702c73946ead235586vboxsync * @param pDbgc Debugger console instance data.
46f059bea92bedbd395793702c73946ead235586vboxsync * @param fNoExecute Indicates that no commands should actually be executed.
46f059bea92bedbd395793702c73946ead235586vboxsync */
46f059bea92bedbd395793702c73946ead235586vboxsyncstatic int dbgcProcessCommands(PDBGC pDbgc, bool fNoExecute)
46f059bea92bedbd395793702c73946ead235586vboxsync{
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync /** @todo Replace this with a sh/ksh/csh/rexx like toplevel language that
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync * allows doing function, loops, if, cases, and such. */
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync int rc = VINF_SUCCESS;
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync while (pDbgc->cInputLines)
46f059bea92bedbd395793702c73946ead235586vboxsync {
46f059bea92bedbd395793702c73946ead235586vboxsync /*
46f059bea92bedbd395793702c73946ead235586vboxsync * Empty the log buffer if we're hooking the log.
46f059bea92bedbd395793702c73946ead235586vboxsync */
46f059bea92bedbd395793702c73946ead235586vboxsync if (pDbgc->fLog)
46f059bea92bedbd395793702c73946ead235586vboxsync {
46f059bea92bedbd395793702c73946ead235586vboxsync rc = dbgcProcessLog(pDbgc);
46f059bea92bedbd395793702c73946ead235586vboxsync if (RT_FAILURE(rc))
break;
}
if (pDbgc->iRead == pDbgc->iWrite)
{
AssertMsgFailed(("The input buffer is empty while cInputLines=%d!\n", pDbgc->cInputLines));
pDbgc->cInputLines = 0;
return 0;
}
/*
* Copy the command to the parse buffer.
*/
char ch;
char *psz = &pDbgc->achInput[pDbgc->iRead];
char *pszTrg = &pDbgc->achScratch[0];
while ((*pszTrg = ch = *psz++) != ';' && ch != '\n' )
{
if (psz == &pDbgc->achInput[sizeof(pDbgc->achInput)])
psz = &pDbgc->achInput[0];
if (psz == &pDbgc->achInput[pDbgc->iWrite])
{
AssertMsgFailed(("The buffer contains no commands while cInputLines=%d!\n", pDbgc->cInputLines));
pDbgc->cInputLines = 0;
return 0;
}
pszTrg++;
}
*pszTrg = '\0';
/*
* Advance the buffer.
*/
pDbgc->iRead = psz - &pDbgc->achInput[0];
if (ch == '\n')
pDbgc->cInputLines--;
/*
* Parse and execute this command.
*/
pDbgc->pszScratch = psz;
pDbgc->iArg = 0;
rc = dbgcEvalCommand(pDbgc, &pDbgc->achScratch[0], psz - &pDbgc->achScratch[0] - 1, fNoExecute);
if ( rc == VERR_DBGC_QUIT
|| rc == VWRN_DBGC_CMD_PENDING)
break;
rc = VINF_SUCCESS; /* ignore other statuses */
}
return rc;
}
/**
* Handle input buffer overflow.
*
* Will read any available input looking for a '\n' to reset the buffer on.
*
* @returns VBox status.
* @param pDbgc Debugger console instance data.
*/
static int dbgcInputOverflow(PDBGC pDbgc)
{
/*
* Assert overflow status and reset the input buffer.
*/
if (!pDbgc->fInputOverflow)
{
pDbgc->fInputOverflow = true;
pDbgc->iRead = pDbgc->iWrite = 0;
pDbgc->cInputLines = 0;
pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "Input overflow!!\n");
}
/*
* Eat input till no more or there is a '\n'.
* When finding a '\n' we'll continue normal processing.
*/
while (pDbgc->pBack->pfnInput(pDbgc->pBack, 0))
{
size_t cbRead;
int rc = pDbgc->pBack->pfnRead(pDbgc->pBack, &pDbgc->achInput[0], sizeof(pDbgc->achInput) - 1, &cbRead);
if (RT_FAILURE(rc))
return rc;
char *psz = (char *)memchr(&pDbgc->achInput[0], '\n', cbRead);
if (psz)
{
pDbgc->fInputOverflow = false;
pDbgc->iRead = psz - &pDbgc->achInput[0] + 1;
pDbgc->iWrite = (unsigned)cbRead;
pDbgc->cInputLines = 0;
break;
}
}
return 0;
}
/**
* Read input and do some preprocessing.
*
* @returns VBox status.
* In addition to the iWrite and achInput, cInputLines is maintained.
* In case of an input overflow the fInputOverflow flag will be set.
* @param pDbgc Debugger console instance data.
*/
static int dbgcInputRead(PDBGC pDbgc)
{
/*
* We have ready input.
* Read it till we don't have any or we have a full input buffer.
*/
int rc = 0;
do
{
/*
* More available buffer space?
*/
size_t cbLeft;
if (pDbgc->iWrite > pDbgc->iRead)
cbLeft = sizeof(pDbgc->achInput) - pDbgc->iWrite - (pDbgc->iRead == 0);
else
cbLeft = pDbgc->iRead - pDbgc->iWrite - 1;
if (!cbLeft)
{
/* overflow? */
if (!pDbgc->cInputLines)
rc = dbgcInputOverflow(pDbgc);
break;
}
/*
* Read one char and interpret it.
*/
char achRead[128];
size_t cbRead;
rc = pDbgc->pBack->pfnRead(pDbgc->pBack, &achRead[0], RT_MIN(cbLeft, sizeof(achRead)), &cbRead);
if (RT_FAILURE(rc))
return rc;
char *psz = &achRead[0];
while (cbRead-- > 0)
{
char ch = *psz++;
switch (ch)
{
/*
* Ignore.
*/
case '\0':
case '\r':
case '\a':
break;
/*
* Backspace.
*/
case '\b':
Log2(("DBGC: backspace\n"));
if (pDbgc->iRead != pDbgc->iWrite)
{
unsigned iWriteUndo = pDbgc->iWrite;
if (pDbgc->iWrite)
pDbgc->iWrite--;
else
pDbgc->iWrite = sizeof(pDbgc->achInput) - 1;
if (pDbgc->achInput[pDbgc->iWrite] == '\n')
pDbgc->iWrite = iWriteUndo;
}
break;
/*
* Add char to buffer.
*/
case '\t':
case '\n':
case ';':
switch (ch)
{
case '\t': ch = ' '; break;
case '\n': pDbgc->cInputLines++; break;
}
default:
Log2(("DBGC: ch=%02x\n", (unsigned char)ch));
pDbgc->achInput[pDbgc->iWrite] = ch;
if (++pDbgc->iWrite >= sizeof(pDbgc->achInput))
pDbgc->iWrite = 0;
break;
}
}
/* Terminate it to make it easier to read in the debugger. */
pDbgc->achInput[pDbgc->iWrite] = '\0';
} while (pDbgc->pBack->pfnInput(pDbgc->pBack, 0));
return rc;
}
/**
* Reads input, parses it and executes commands on '\n'.
*
* @returns VBox status.
* @param pDbgc Debugger console instance data.
* @param fNoExecute Indicates that no commands should actually be executed.
*/
int dbgcProcessInput(PDBGC pDbgc, bool fNoExecute)
{
/*
* We know there's input ready, so let's read it first.
*/
int rc = dbgcInputRead(pDbgc);
if (RT_FAILURE(rc))
return rc;
/*
* Now execute any ready commands.
*/
if (pDbgc->cInputLines)
{
pDbgc->pBack->pfnSetReady(pDbgc->pBack, false);
pDbgc->fReady = false;
rc = dbgcProcessCommands(pDbgc, fNoExecute);
if (RT_SUCCESS(rc) && rc != VWRN_DBGC_CMD_PENDING)
pDbgc->fReady = true;
if ( RT_SUCCESS(rc)
&& pDbgc->iRead == pDbgc->iWrite
&& pDbgc->fReady)
rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "VBoxDbg> ");
if ( RT_SUCCESS(rc)
&& pDbgc->fReady)
pDbgc->pBack->pfnSetReady(pDbgc->pBack, true);
}
else
/* Received nonsense; just skip it. */
pDbgc->iRead = pDbgc->iWrite;
return rc;
}
/**
* Gets the event context identifier string.
* @returns Read only string.
* @param enmCtx The context.
*/
static const char *dbgcGetEventCtx(DBGFEVENTCTX enmCtx)
{
switch (enmCtx)
{
case DBGFEVENTCTX_RAW: return "raw";
case DBGFEVENTCTX_REM: return "rem";
case DBGFEVENTCTX_HWACCL: return "hwaccl";
case DBGFEVENTCTX_HYPER: return "hyper";
case DBGFEVENTCTX_OTHER: return "other";
case DBGFEVENTCTX_INVALID: return "!Invalid Event Ctx!";
default:
AssertMsgFailed(("enmCtx=%d\n", enmCtx));
return "!Unknown Event Ctx!";
}
}
/**
* Processes debugger events.
*
* @returns VBox status.
* @param pDbgc DBGC Instance data.
* @param pEvent Pointer to event data.
*/
static int dbgcProcessEvent(PDBGC pDbgc, PCDBGFEVENT pEvent)
{
/*
* Flush log first.
*/
if (pDbgc->fLog)
{
int rc = dbgcProcessLog(pDbgc);
if (RT_FAILURE(rc))
return rc;
}
/*
* Process the event.
*/
pDbgc->pszScratch = &pDbgc->achInput[0];
pDbgc->iArg = 0;
bool fPrintPrompt = true;
int rc = VINF_SUCCESS;
switch (pEvent->enmType)
{
/*
* The first part is events we have initiated with commands.
*/
case DBGFEVENT_HALT_DONE:
{
rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "\ndbgf event: VM %p is halted! (%s)\n",
pDbgc->pVM, dbgcGetEventCtx(pEvent->enmCtx));
pDbgc->fRegCtxGuest = true; /* we're always in guest context when halted. */
if (RT_SUCCESS(rc))
rc = pDbgc->CmdHlp.pfnExec(&pDbgc->CmdHlp, "r");
break;
}
/*
* The second part is events which can occur at any time.
*/
case DBGFEVENT_FATAL_ERROR:
{
rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "\ndbf event: Fatal error! (%s)\n",
dbgcGetEventCtx(pEvent->enmCtx));
pDbgc->fRegCtxGuest = false; /* fatal errors are always in hypervisor. */
if (RT_SUCCESS(rc))
rc = pDbgc->CmdHlp.pfnExec(&pDbgc->CmdHlp, "r");
break;
}
case DBGFEVENT_BREAKPOINT:
case DBGFEVENT_BREAKPOINT_HYPER:
{
bool fRegCtxGuest = pDbgc->fRegCtxGuest;
pDbgc->fRegCtxGuest = pEvent->enmType == DBGFEVENT_BREAKPOINT;
rc = dbgcBpExec(pDbgc, pEvent->u.Bp.iBp);
switch (rc)
{
case VERR_DBGC_BP_NOT_FOUND:
rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "\ndbgf event: Unknown breakpoint %u! (%s)\n",
pEvent->u.Bp.iBp, dbgcGetEventCtx(pEvent->enmCtx));
break;
case VINF_DBGC_BP_NO_COMMAND:
rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "\ndbgf event: Breakpoint %u! (%s)\n",
pEvent->u.Bp.iBp, dbgcGetEventCtx(pEvent->enmCtx));
break;
case VINF_BUFFER_OVERFLOW:
rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "\ndbgf event: Breakpoint %u! Command too long to execute! (%s)\n",
pEvent->u.Bp.iBp, dbgcGetEventCtx(pEvent->enmCtx));
break;
default:
break;
}
if (RT_SUCCESS(rc) && DBGFR3IsHalted(pDbgc->pVM))
rc = pDbgc->CmdHlp.pfnExec(&pDbgc->CmdHlp, "r");
else
pDbgc->fRegCtxGuest = fRegCtxGuest;
break;
}
case DBGFEVENT_STEPPED:
case DBGFEVENT_STEPPED_HYPER:
{
pDbgc->fRegCtxGuest = pEvent->enmType == DBGFEVENT_STEPPED;
rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "\ndbgf event: Single step! (%s)\n", dbgcGetEventCtx(pEvent->enmCtx));
if (RT_SUCCESS(rc))
rc = pDbgc->CmdHlp.pfnExec(&pDbgc->CmdHlp, "r");
break;
}
case DBGFEVENT_ASSERTION_HYPER:
{
pDbgc->fRegCtxGuest = false;
rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL,
"\ndbgf event: Hypervisor Assertion! (%s)\n"
"%s"
"%s"
"\n",
dbgcGetEventCtx(pEvent->enmCtx),
pEvent->u.Assert.pszMsg1,
pEvent->u.Assert.pszMsg2);
if (RT_SUCCESS(rc))
rc = pDbgc->CmdHlp.pfnExec(&pDbgc->CmdHlp, "r");
break;
}
case DBGFEVENT_DEV_STOP:
{
rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL,
"\n"
"dbgf event: DBGFSTOP (%s)\n"
"File: %s\n"
"Line: %d\n"
"Function: %s\n",
dbgcGetEventCtx(pEvent->enmCtx),
pEvent->u.Src.pszFile,
pEvent->u.Src.uLine,
pEvent->u.Src.pszFunction);
if (RT_SUCCESS(rc) && pEvent->u.Src.pszMessage && *pEvent->u.Src.pszMessage)
rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL,
"Message: %s\n",
pEvent->u.Src.pszMessage);
if (RT_SUCCESS(rc))
rc = pDbgc->CmdHlp.pfnExec(&pDbgc->CmdHlp, "r");
break;
}
case DBGFEVENT_INVALID_COMMAND:
{
rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "\ndbgf/dbgc error: Invalid command event!\n");
break;
}
case DBGFEVENT_TERMINATING:
{
pDbgc->fReady = false;
pDbgc->pBack->pfnSetReady(pDbgc->pBack, false);
pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "\nVM is terminating!\n");
fPrintPrompt = false;
rc = VERR_GENERAL_FAILURE;
break;
}
default:
{
rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "\ndbgf/dbgc error: Unknown event %d!\n", pEvent->enmType);
break;
}
}
/*
* Prompt, anyone?
*/
if (fPrintPrompt && RT_SUCCESS(rc))
{
rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "VBoxDbg> ");
pDbgc->fReady = true;
if (RT_SUCCESS(rc))
pDbgc->pBack->pfnSetReady(pDbgc->pBack, true);
}
return rc;
}
/**
* Prints any log lines from the log buffer.
*
* The caller must not call function this unless pDbgc->fLog is set.
*
* @returns VBox status. (output related)
* @param pDbgc Debugger console instance data.
*/
static int dbgcProcessLog(PDBGC pDbgc)
{
/** @todo */
NOREF(pDbgc);
return 0;
}
/**
* Run the debugger console.
*
* @returns VBox status.
* @param pDbgc Pointer to the debugger console instance data.
*/
int dbgcRun(PDBGC pDbgc)
{
/*
* We're ready for commands now.
*/
pDbgc->fReady = true;
pDbgc->pBack->pfnSetReady(pDbgc->pBack, true);
/*
* Main Debugger Loop.
*
* This loop will either block on waiting for input or on waiting on
* debug events. If we're forwarding the log we cannot wait for long
* before we must flush the log.
*/
int rc = VINF_SUCCESS;
for (;;)
{
if ( pDbgc->pVM
&& DBGFR3CanWait(pDbgc->pVM))
{
/*
* Wait for a debug event.
*/
PCDBGFEVENT pEvent;
rc = DBGFR3EventWait(pDbgc->pVM, pDbgc->fLog ? 1 : 32, &pEvent);
if (RT_SUCCESS(rc))
{
rc = dbgcProcessEvent(pDbgc, pEvent);
if (RT_FAILURE(rc))
break;
}
else if (rc != VERR_TIMEOUT)
break;
/*
* Check for input.
*/
if (pDbgc->pBack->pfnInput(pDbgc->pBack, 0))
{
rc = dbgcProcessInput(pDbgc, false /* fNoExecute */);
if (RT_FAILURE(rc))
break;
}
}
else
{
/*
* Wait for input. If Logging is enabled we'll only wait very briefly.
*/
if (pDbgc->pBack->pfnInput(pDbgc->pBack, pDbgc->fLog ? 1 : 1000))
{
rc = dbgcProcessInput(pDbgc, false /* fNoExecute */);
if (RT_FAILURE(rc))
break;
}
}
/*
* Forward log output.
*/
if (pDbgc->fLog)
{
rc = dbgcProcessLog(pDbgc);
if (RT_FAILURE(rc))
break;
}
}
return rc;
}
/**
* Creates a a new instance.
*
* @returns VBox status code.
* @param ppDbgc Where to store the pointer to the instance data.
* @param pBack Pointer to the backend.
* @param fFlags The flags.
*/
int dbgcCreate(PDBGC *ppDbgc, PDBGCBACK pBack, unsigned fFlags)
{
/*
* Validate input.
*/
AssertPtrReturn(pBack, VERR_INVALID_POINTER);
AssertMsgReturn(!fFlags, ("%#x", fFlags), VERR_INVALID_PARAMETER);
/*
* Allocate and initialize.
*/
PDBGC pDbgc = (PDBGC)RTMemAllocZ(sizeof(*pDbgc));
if (!pDbgc)
return VERR_NO_MEMORY;
dbgcInitCmdHlp(pDbgc);
pDbgc->pBack = pBack;
pDbgc->pVM = NULL;
pDbgc->idCpu = 0;
pDbgc->hDbgAs = DBGF_AS_GLOBAL;
pDbgc->pszEmulation = "CodeView/WinDbg";
pDbgc->paEmulationCmds = &g_aCmdsCodeView[0];
pDbgc->cEmulationCmds = g_cCmdsCodeView;
//pDbgc->fLog = false;
pDbgc->fRegCtxGuest = true;
pDbgc->fRegTerse = true;
//pDbgc->cPagingHierarchyDumps = 0;
//pDbgc->DisasmPos = {0};
//pDbgc->SourcePos = {0};
//pDbgc->DumpPos = {0};
pDbgc->pLastPos = &pDbgc->DisasmPos;
//pDbgc->cbDumpElement = 0;
//pDbgc->cVars = 0;
//pDbgc->paVars = NULL;
//pDbgc->pPlugInHead = NULL;
//pDbgc->pFirstBp = NULL;
//pDbgc->abSearch = {0};
//pDbgc->cbSearch = 0;
pDbgc->cbSearchUnit = 1;
pDbgc->cMaxSearchHits = 1;
//pDbgc->SearchAddr = {0};
//pDbgc->cbSearchRange = 0;
//pDbgc->uInputZero = 0;
//pDbgc->iRead = 0;
//pDbgc->iWrite = 0;
//pDbgc->cInputLines = 0;
//pDbgc->fInputOverflow = false;
pDbgc->fReady = true;
pDbgc->pszScratch = &pDbgc->achScratch[0];
//pDbgc->iArg = 0;
//pDbgc->rcOutput = 0;
//pDbgc->rcCmd = 0;
dbgcEvalInit();
*ppDbgc = pDbgc;
return VINF_SUCCESS;
}
/**
* Destroys a DBGC instance created by dbgcCreate.
*
* @param pDbgc Pointer to the debugger console instance data.
*/
void dbgcDestroy(PDBGC pDbgc)
{
AssertPtr(pDbgc);
/* Disable log hook. */
if (pDbgc->fLog)
{
}
/* Unload all plug-ins. */
dbgcPlugInUnloadAll(pDbgc);
/* Detach from the VM. */
if (pDbgc->pVM)
DBGFR3Detach(pDbgc->pVM);
/* finally, free the instance memory. */
RTMemFree(pDbgc);
}
/**
* Make a console instance.
*
* This will not return until either an 'exit' command is issued or a error code
* indicating connection loss is encountered.
*
* @returns VINF_SUCCESS if console termination caused by the 'exit' command.
* @returns The VBox status code causing the console termination.
*
* @param pVM VM Handle.
* @param pBack Pointer to the backend structure. This must contain
* a full set of function pointers to service the console.
* @param fFlags Reserved, must be zero.
* @remark A forced termination of the console is easiest done by forcing the
* callbacks to return fatal failures.
*/
DBGDECL(int) DBGCCreate(PVM pVM, PDBGCBACK pBack, unsigned fFlags)
{
/*
* Validate input.
*/
AssertPtrNullReturn(pVM, VERR_INVALID_POINTER);
/*
* Allocate and initialize instance data
*/
PDBGC pDbgc;
int rc = dbgcCreate(&pDbgc, pBack, fFlags);
if (RT_FAILURE(rc))
return rc;
/*
* Print welcome message.
*/
rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL,
"Welcome to the VirtualBox Debugger!\n");
/*
* Attach to the specified VM.
*/
if (RT_SUCCESS(rc) && pVM)
{
rc = DBGFR3Attach(pVM);
if (RT_SUCCESS(rc))
{
pDbgc->pVM = pVM;
pDbgc->idCpu = 0;
rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL,
"Current VM is %08x, CPU #%u\n" /** @todo get and print the VM name! */
, pDbgc->pVM, pDbgc->idCpu);
}
else
rc = pDbgc->CmdHlp.pfnVBoxError(&pDbgc->CmdHlp, rc, "When trying to attach to VM %p\n", pDbgc->pVM);
}
/*
* Load plugins.
*/
if (RT_SUCCESS(rc))
{
if (pVM)
dbgcPlugInAutoLoad(pDbgc);
rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "VBoxDbg> ");
}
else
pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "\nDBGCCreate error: %Rrc\n", rc);
/*
* Run the debugger main loop.
*/
if (RT_SUCCESS(rc))
rc = dbgcRun(pDbgc);
/*
* Cleanup console debugger session.
*/
dbgcDestroy(pDbgc);
return rc == VERR_DBGC_QUIT ? VINF_SUCCESS : rc;
}