DBGCEmulateCodeView.cpp revision 57309798090cfa322b646a5cca662f2567c7e0d2
/* $Id$ */
/** @file
* DBGC - Debugger Console, CodeView / WinDbg Emulation.
*/
/*
* Copyright (C) 2006-2011 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define LOG_GROUP LOG_GROUP_DBGC
#include <stdlib.h>
#include <stdio.h>
#include "DBGCInternal.h"
/*******************************************************************************
* Internal Functions *
*******************************************************************************/
static DECLCALLBACK(int) dbgcCmdBrkAccess(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs);
static DECLCALLBACK(int) dbgcCmdBrkClear(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs);
static DECLCALLBACK(int) dbgcCmdBrkDisable(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs);
static DECLCALLBACK(int) dbgcCmdBrkEnable(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs);
static DECLCALLBACK(int) dbgcCmdBrkList(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs);
static DECLCALLBACK(int) dbgcCmdBrkSet(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs);
static DECLCALLBACK(int) dbgcCmdBrkREM(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs);
static DECLCALLBACK(int) dbgcCmdDumpMem(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs);
static DECLCALLBACK(int) dbgcCmdDumpDT(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs);
static DECLCALLBACK(int) dbgcCmdDumpIDT(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs);
static DECLCALLBACK(int) dbgcCmdDumpPageDir(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs);
static DECLCALLBACK(int) dbgcCmdDumpPageDirBoth(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs);
static DECLCALLBACK(int) dbgcCmdDumpPageHierarchy(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs);
static DECLCALLBACK(int) dbgcCmdDumpPageTable(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs);
static DECLCALLBACK(int) dbgcCmdDumpPageTableBoth(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs);
static DECLCALLBACK(int) dbgcCmdDumpTSS(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs);
static DECLCALLBACK(int) dbgcCmdEditMem(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs);
static DECLCALLBACK(int) dbgcCmdGo(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs);
static DECLCALLBACK(int) dbgcCmdListModules(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs);
static DECLCALLBACK(int) dbgcCmdListNear(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs);
static DECLCALLBACK(int) dbgcCmdListSource(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs);
static DECLCALLBACK(int) dbgcCmdMemoryInfo(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs);
static DECLCALLBACK(int) dbgcCmdReg(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs);
static DECLCALLBACK(int) dbgcCmdRegGuest(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs);
static DECLCALLBACK(int) dbgcCmdRegHyper(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs);
static DECLCALLBACK(int) dbgcCmdRegTerse(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs);
static DECLCALLBACK(int) dbgcCmdSearchMem(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs);
static DECLCALLBACK(int) dbgcCmdSearchMemType(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs);
static DECLCALLBACK(int) dbgcCmdStack(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs);
static DECLCALLBACK(int) dbgcCmdTrace(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs);
static DECLCALLBACK(int) dbgcCmdUnassemble(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs);
/*******************************************************************************
* Global Variables *
*******************************************************************************/
/** 'ba' arguments. */
static const DBGCVARDESC g_aArgBrkAcc[] =
{
/* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
{ 1, 1, DBGCVAR_CAT_STRING, 0, "access", "The access type: x=execute, rw=read/write (alias r), w=write, i=not implemented." },
{ 1, 1, DBGCVAR_CAT_NUMBER, 0, "size", "The access size: 1, 2, 4, or 8. 'x' access requires 1, and 8 requires amd64 long mode." },
{ 0, 1, DBGCVAR_CAT_NUMBER, 0, "passes", "The number of passes before we trigger the breakpoint. (0 is default)" },
{ 0, 1, DBGCVAR_CAT_NUMBER, DBGCVD_FLAGS_DEP_PREV, "max passes", "The number of passes after which we stop triggering the breakpoint. (~0 is default)" },
{ 0, 1, DBGCVAR_CAT_STRING, 0, "cmds", "String of commands to be executed when the breakpoint is hit. Quote it!" },
};
/** 'bc', 'bd', 'be' arguments. */
static const DBGCVARDESC g_aArgBrks[] =
{
/* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
};
/** 'bp' arguments. */
static const DBGCVARDESC g_aArgBrkSet[] =
{
/* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
{ 0, 1, DBGCVAR_CAT_NUMBER, 0, "passes", "The number of passes before we trigger the breakpoint. (0 is default)" },
{ 0, 1, DBGCVAR_CAT_NUMBER, DBGCVD_FLAGS_DEP_PREV, "max passes", "The number of passes after which we stop triggering the breakpoint. (~0 is default)" },
{ 0, 1, DBGCVAR_CAT_STRING, 0, "cmds", "String of commands to be executed when the breakpoint is hit. Quote it!" },
};
/** 'br' arguments. */
static const DBGCVARDESC g_aArgBrkREM[] =
{
/* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
{ 0, 1, DBGCVAR_CAT_NUMBER, 0, "passes", "The number of passes before we trigger the breakpoint. (0 is default)" },
{ 0, 1, DBGCVAR_CAT_NUMBER, DBGCVD_FLAGS_DEP_PREV, "max passes", "The number of passes after which we stop triggering the breakpoint. (~0 is default)" },
{ 0, 1, DBGCVAR_CAT_STRING, 0, "cmds", "String of commands to be executed when the breakpoint is hit. Quote it!" },
};
/** 'd?' arguments. */
static const DBGCVARDESC g_aArgDumpMem[] =
{
/* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
};
/** 'dg', 'dga', 'dl', 'dla' arguments. */
static const DBGCVARDESC g_aArgDumpDT[] =
{
/* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
};
/** 'di', 'dia' arguments. */
static const DBGCVARDESC g_aArgDumpIDT[] =
{
/* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
};
/** 'dpd*' arguments. */
static const DBGCVARDESC g_aArgDumpPD[] =
{
/* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
{ 0, 1, DBGCVAR_CAT_POINTER, 0, "address", "Address which page directory entry to start dumping from. Range is applied to the page directory." },
};
/** 'dpda' arguments. */
static const DBGCVARDESC g_aArgDumpPDAddr[] =
{
/* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
{ 0, 1, DBGCVAR_CAT_POINTER, 0, "address", "Address of the page directory entry to start dumping from." },
};
/** 'dph*' arguments. */
static const DBGCVARDESC g_aArgDumpPH[] =
{
/* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
{ 0, 1, DBGCVAR_CAT_GC_POINTER, 0, "address", "Where in the address space to start dumping and for how long (range). The default address/range will be used if omitted." },
{ 0, 1, DBGCVAR_CAT_NUMBER, DBGCVD_FLAGS_DEP_PREV, "cr3", "The CR3 value to use. The current CR3 of the context will be used if omitted." },
{ 0, 1, DBGCVAR_CAT_STRING, DBGCVD_FLAGS_DEP_PREV, "mode", "The paging mode: legacy, pse, pae, long, ept. Append '-np' for nested paging and '-nx' for no-execute. The current mode will be used if omitted." },
};
/** 'dpt?' arguments. */
static const DBGCVARDESC g_aArgDumpPT[] =
{
/* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
{ 1, 1, DBGCVAR_CAT_POINTER, 0, "address", "Address which page directory entry to start dumping from." },
};
/** 'dpta' arguments. */
static const DBGCVARDESC g_aArgDumpPTAddr[] =
{
/* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
{ 1, 1, DBGCVAR_CAT_POINTER, 0, "address", "Address of the page table entry to start dumping from." },
};
/** 'dt' arguments. */
static const DBGCVARDESC g_aArgDumpTSS[] =
{
/* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
{ 0, 1, DBGCVAR_CAT_POINTER, 0, "tss:ign|addr", "TSS address. If the selector is a TSS selector, the offset will be ignored." }
};
/** 'e?' arguments. */
static const DBGCVARDESC g_aArgEditMem[] =
{
/* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
};
/** 'lm' arguments. */
static const DBGCVARDESC g_aArgListMods[] =
{
/* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
};
/** 'ln' arguments. */
static const DBGCVARDESC g_aArgListNear[] =
{
/* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
};
/** 'ls' arguments. */
static const DBGCVARDESC g_aArgListSource[] =
{
/* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
};
/** 'm' argument. */
static const DBGCVARDESC g_aArgMemoryInfo[] =
{
/* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
};
/** 'r' arguments. */
static const DBGCVARDESC g_aArgReg[] =
{
/* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
};
/** 's' arguments. */
static const DBGCVARDESC g_aArgSearchMem[] =
{
/* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
};
/** 's?' arguments. */
static const DBGCVARDESC g_aArgSearchMemType[] =
{
/* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
};
/** 'u' arguments. */
static const DBGCVARDESC g_aArgUnassemble[] =
{
/* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
};
/** Command descriptors for the CodeView / WinDbg emulation.
* The emulation isn't attempting to be identical, only somewhat similar.
*/
const DBGCCMD g_aCmdsCodeView[] =
{
/* pszCmd, cArgsMin, cArgsMax, paArgDescs, cArgDescs, fFlags, pfnHandler pszSyntax, ....pszDescription */
{ "ba", 3, 6, &g_aArgBrkAcc[0], RT_ELEMENTS(g_aArgBrkAcc), 0, dbgcCmdBrkAccess, "<access> <size> <address> [passes [max passes]] [cmds]",
"Sets a data access breakpoint." },
{ "bc", 1, ~0, &g_aArgBrks[0], RT_ELEMENTS(g_aArgBrks), 0, dbgcCmdBrkClear, "all | <bp#> [bp# []]", "Enabled a set of breakpoints." },
{ "bd", 1, ~0, &g_aArgBrks[0], RT_ELEMENTS(g_aArgBrks), 0, dbgcCmdBrkDisable, "all | <bp#> [bp# []]", "Disables a set of breakpoints." },
{ "be", 1, ~0, &g_aArgBrks[0], RT_ELEMENTS(g_aArgBrks), 0, dbgcCmdBrkEnable, "all | <bp#> [bp# []]", "Enabled a set of breakpoints." },
{ "bp", 1, 4, &g_aArgBrkSet[0], RT_ELEMENTS(g_aArgBrkSet), 0, dbgcCmdBrkSet, "<address> [passes [max passes]] [cmds]",
"Sets a breakpoint (int 3)." },
{ "br", 1, 4, &g_aArgBrkREM[0], RT_ELEMENTS(g_aArgBrkREM), 0, dbgcCmdBrkREM, "<address> [passes [max passes]] [cmds]",
"Sets a recompiler specific breakpoint." },
{ "d", 0, 1, &g_aArgDumpMem[0], RT_ELEMENTS(g_aArgDumpMem), 0, dbgcCmdDumpMem, "[addr]", "Dump memory using last element size." },
{ "da", 0, 1, &g_aArgDumpMem[0], RT_ELEMENTS(g_aArgDumpMem), 0, dbgcCmdDumpMem, "[addr]", "Dump memory as ascii string." },
{ "db", 0, 1, &g_aArgDumpMem[0], RT_ELEMENTS(g_aArgDumpMem), 0, dbgcCmdDumpMem, "[addr]", "Dump memory in bytes." },
{ "dd", 0, 1, &g_aArgDumpMem[0], RT_ELEMENTS(g_aArgDumpMem), 0, dbgcCmdDumpMem, "[addr]", "Dump memory in double words." },
{ "da", 0, 1, &g_aArgDumpMem[0], RT_ELEMENTS(g_aArgDumpMem), 0, dbgcCmdDumpMem, "[addr]", "Dump memory as ascii string." },
{ "dg", 0, ~0, &g_aArgDumpDT[0], RT_ELEMENTS(g_aArgDumpDT), 0, dbgcCmdDumpDT, "[sel [..]]", "Dump the global descriptor table (GDT)." },
{ "dga", 0, ~0, &g_aArgDumpDT[0], RT_ELEMENTS(g_aArgDumpDT), 0, dbgcCmdDumpDT, "[sel [..]]", "Dump the global descriptor table (GDT) including not-present entries." },
{ "di", 0, ~0, &g_aArgDumpIDT[0], RT_ELEMENTS(g_aArgDumpIDT), 0, dbgcCmdDumpIDT, "[int [..]]", "Dump the interrupt descriptor table (IDT)." },
{ "dia", 0, ~0, &g_aArgDumpIDT[0], RT_ELEMENTS(g_aArgDumpIDT), 0, dbgcCmdDumpIDT, "[int [..]]", "Dump the interrupt descriptor table (IDT) including not-present entries." },
{ "dl", 0, ~0, &g_aArgDumpDT[0], RT_ELEMENTS(g_aArgDumpDT), 0, dbgcCmdDumpDT, "[sel [..]]", "Dump the local descriptor table (LDT)." },
{ "dla", 0, ~0, &g_aArgDumpDT[0], RT_ELEMENTS(g_aArgDumpDT), 0, dbgcCmdDumpDT, "[sel [..]]", "Dump the local descriptor table (LDT) including not-present entries." },
{ "dpd", 0, 1, &g_aArgDumpPD[0], RT_ELEMENTS(g_aArgDumpPD), 0, dbgcCmdDumpPageDir, "[addr] [index]", "Dumps page directory entries of the default context." },
{ "dpda", 0, 1, &g_aArgDumpPDAddr[0],RT_ELEMENTS(g_aArgDumpPDAddr), 0, dbgcCmdDumpPageDir, "[addr]", "Dumps specified page directory." },
{ "dpdb", 1, 1, &g_aArgDumpPD[0], RT_ELEMENTS(g_aArgDumpPD), 0, dbgcCmdDumpPageDirBoth, "[addr] [index]", "Dumps page directory entries of the guest and the hypervisor. " },
{ "dpdg", 0, 1, &g_aArgDumpPD[0], RT_ELEMENTS(g_aArgDumpPD), 0, dbgcCmdDumpPageDir, "[addr] [index]", "Dumps page directory entries of the guest." },
{ "dpdh", 0, 1, &g_aArgDumpPD[0], RT_ELEMENTS(g_aArgDumpPD), 0, dbgcCmdDumpPageDir, "[addr] [index]", "Dumps page directory entries of the hypervisor. " },
{ "dph", 0, 3, &g_aArgDumpPH[0], RT_ELEMENTS(g_aArgDumpPH), 0, dbgcCmdDumpPageHierarchy, "[addr [cr3 [mode]]", "Dumps the paging hierarchy at for specfied address range. Default context." },
{ "dphg", 0, 3, &g_aArgDumpPH[0], RT_ELEMENTS(g_aArgDumpPH), 0, dbgcCmdDumpPageHierarchy, "[addr [cr3 [mode]]", "Dumps the paging hierarchy at for specfied address range. Guest context." },
{ "dphh", 0, 3, &g_aArgDumpPH[0], RT_ELEMENTS(g_aArgDumpPH), 0, dbgcCmdDumpPageHierarchy, "[addr [cr3 [mode]]", "Dumps the paging hierarchy at for specfied address range. Hypervisor context." },
{ "dpt", 1, 1, &g_aArgDumpPT[0], RT_ELEMENTS(g_aArgDumpPT), 0, dbgcCmdDumpPageTable,"<addr>", "Dumps page table entries of the default context." },
{ "dpta", 1, 1, &g_aArgDumpPTAddr[0],RT_ELEMENTS(g_aArgDumpPTAddr), 0, dbgcCmdDumpPageTable,"<addr>", "Dumps specified page table." },
{ "dptb", 1, 1, &g_aArgDumpPT[0], RT_ELEMENTS(g_aArgDumpPT), 0, dbgcCmdDumpPageTableBoth,"<addr>", "Dumps page table entries of the guest and the hypervisor." },
{ "dptg", 1, 1, &g_aArgDumpPT[0], RT_ELEMENTS(g_aArgDumpPT), 0, dbgcCmdDumpPageTable,"<addr>", "Dumps page table entries of the guest." },
{ "dpth", 1, 1, &g_aArgDumpPT[0], RT_ELEMENTS(g_aArgDumpPT), 0, dbgcCmdDumpPageTable,"<addr>", "Dumps page table entries of the hypervisor." },
{ "dq", 0, 1, &g_aArgDumpMem[0], RT_ELEMENTS(g_aArgDumpMem), 0, dbgcCmdDumpMem, "[addr]", "Dump memory in quad words." },
{ "dt", 0, 1, &g_aArgDumpTSS[0], RT_ELEMENTS(g_aArgDumpTSS), 0, dbgcCmdDumpTSS, "[tss|tss:ign|addr]", "Dump the task state segment (TSS)." },
{ "dt16", 0, 1, &g_aArgDumpTSS[0], RT_ELEMENTS(g_aArgDumpTSS), 0, dbgcCmdDumpTSS, "[tss|tss:ign|addr]", "Dump the 16-bit task state segment (TSS)." },
{ "dt32", 0, 1, &g_aArgDumpTSS[0], RT_ELEMENTS(g_aArgDumpTSS), 0, dbgcCmdDumpTSS, "[tss|tss:ign|addr]", "Dump the 32-bit task state segment (TSS)." },
{ "dt64", 0, 1, &g_aArgDumpTSS[0], RT_ELEMENTS(g_aArgDumpTSS), 0, dbgcCmdDumpTSS, "[tss|tss:ign|addr]", "Dump the 64-bit task state segment (TSS)." },
{ "dw", 0, 1, &g_aArgDumpMem[0], RT_ELEMENTS(g_aArgDumpMem), 0, dbgcCmdDumpMem, "[addr]", "Dump memory in words." },
/** @todo add 'e', 'ea str', 'eza str', 'eu str' and 'ezu str'. See also
* dbgcCmdSearchMem and its dbgcVarsToBytes usage. */
{ "eb", 2, 2, &g_aArgEditMem[0], RT_ELEMENTS(g_aArgEditMem), 0, dbgcCmdEditMem, "<addr> <value>", "Write a 1-byte value to memory." },
{ "ew", 2, 2, &g_aArgEditMem[0], RT_ELEMENTS(g_aArgEditMem), 0, dbgcCmdEditMem, "<addr> <value>", "Write a 2-byte value to memory." },
{ "ed", 2, 2, &g_aArgEditMem[0], RT_ELEMENTS(g_aArgEditMem), 0, dbgcCmdEditMem, "<addr> <value>", "Write a 4-byte value to memory." },
{ "eq", 2, 2, &g_aArgEditMem[0], RT_ELEMENTS(g_aArgEditMem), 0, dbgcCmdEditMem, "<addr> <value>", "Write a 8-byte value to memory." },
{ "lm", 0, ~0, &g_aArgListMods[0], RT_ELEMENTS(g_aArgListMods), 0, dbgcCmdListModules, "[module [..]]", "List modules." },
{ "lmo", 0, ~0, &g_aArgListMods[0], RT_ELEMENTS(g_aArgListMods), 0, dbgcCmdListModules, "[module [..]]", "List modules and their segments." },
{ "ln", 0, ~0, &g_aArgListNear[0], RT_ELEMENTS(g_aArgListNear), 0, dbgcCmdListNear, "[addr/sym [..]]", "List symbols near to the address. Default address is CS:EIP." },
{ "ls", 0, 1, &g_aArgListSource[0],RT_ELEMENTS(g_aArgListSource), 0, dbgcCmdListSource, "[addr]", "Source." },
{ "m", 1, 1, &g_aArgMemoryInfo[0],RT_ELEMENTS(g_aArgMemoryInfo), 0, dbgcCmdMemoryInfo, "<addr>", "Display information about that piece of memory." },
{ "r", 0, 2, &g_aArgReg[0], RT_ELEMENTS(g_aArgReg), 0, dbgcCmdReg, "[reg [newval]]", "Show or set register(s) - active reg set." },
{ "rg", 0, 2, &g_aArgReg[0], RT_ELEMENTS(g_aArgReg), 0, dbgcCmdRegGuest, "[reg [newval]]", "Show or set register(s) - guest reg set." },
{ "rh", 0, 2, &g_aArgReg[0], RT_ELEMENTS(g_aArgReg), 0, dbgcCmdRegHyper, "[reg [newval]]", "Show or set register(s) - hypervisor reg set." },
{ "s", 0, ~0, &g_aArgSearchMem[0], RT_ELEMENTS(g_aArgSearchMem), 0, dbgcCmdSearchMem, "[options] <range> <pattern>", "Continue last search." },
{ "sa", 2, ~0, &g_aArgSearchMemType[0], RT_ELEMENTS(g_aArgSearchMemType),0, dbgcCmdSearchMemType, "<range> <pattern>", "Search memory for an ascii string." },
{ "sb", 2, ~0, &g_aArgSearchMemType[0], RT_ELEMENTS(g_aArgSearchMemType),0, dbgcCmdSearchMemType, "<range> <pattern>", "Search memory for one or more bytes." },
{ "sd", 2, ~0, &g_aArgSearchMemType[0], RT_ELEMENTS(g_aArgSearchMemType),0, dbgcCmdSearchMemType, "<range> <pattern>", "Search memory for one or more double words." },
{ "sq", 2, ~0, &g_aArgSearchMemType[0], RT_ELEMENTS(g_aArgSearchMemType),0, dbgcCmdSearchMemType, "<range> <pattern>", "Search memory for one or more quad words." },
{ "su", 2, ~0, &g_aArgSearchMemType[0], RT_ELEMENTS(g_aArgSearchMemType),0, dbgcCmdSearchMemType, "<range> <pattern>", "Search memory for an unicode string." },
{ "sw", 2, ~0, &g_aArgSearchMemType[0], RT_ELEMENTS(g_aArgSearchMemType),0, dbgcCmdSearchMemType, "<range> <pattern>", "Search memory for one or more words." },
{ "u", 0, 1, &g_aArgUnassemble[0],RT_ELEMENTS(g_aArgUnassemble), 0, dbgcCmdUnassemble, "[addr]", "Unassemble." },
{ "u64", 0, 1, &g_aArgUnassemble[0],RT_ELEMENTS(g_aArgUnassemble), 0, dbgcCmdUnassemble, "[addr]", "Unassemble 64-bit code." },
{ "u32", 0, 1, &g_aArgUnassemble[0],RT_ELEMENTS(g_aArgUnassemble), 0, dbgcCmdUnassemble, "[addr]", "Unassemble 32-bit code." },
{ "u16", 0, 1, &g_aArgUnassemble[0],RT_ELEMENTS(g_aArgUnassemble), 0, dbgcCmdUnassemble, "[addr]", "Unassemble 16-bit code." },
{ "uv86", 0, 1, &g_aArgUnassemble[0],RT_ELEMENTS(g_aArgUnassemble), 0, dbgcCmdUnassemble, "[addr]", "Unassemble 16-bit code with v8086/real mode addressing." },
};
/**
* The 'go' command.
*
* @returns VBox status.
* @param pCmd Pointer to the command descriptor (as registered).
* @param pCmdHlp Pointer to command helper functions.
* @param pVM Pointer to the current VM (if any).
* @param paArgs Pointer to (readonly) array of arguments.
* @param cArgs Number of arguments in the array.
*/
static DECLCALLBACK(int) dbgcCmdGo(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs)
{
/*
* Check if the VM is halted or not before trying to resume it.
*/
if (!DBGFR3IsHalted(pVM))
if (RT_FAILURE(rc))
return VINF_SUCCESS;
}
/**
* The 'ba' command.
*
* @returns VBox status.
* @param pCmd Pointer to the command descriptor (as registered).
* @param pCmdHlp Pointer to command helper functions.
* @param pVM Pointer to the current VM (if any).
* @param paArgs Pointer to (readonly) array of arguments.
* @param cArgs Number of arguments in the array.
*/
static DECLCALLBACK(int) dbgcCmdBrkAccess(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs)
{
/*
* Interpret access type.
*/
return DBGCCmdHlpFail(pCmdHlp, pCmd, "Invalid access type '%s' for '%s'. Valid types are 'e', 'r', 'w' and 'i'",
{
}
/*
* Validate size.
*/
return DBGCCmdHlpFail(pCmdHlp, pCmd, "Invalid access size %RX64 for '%s'. 'x' access type requires size 1!",
{
case 1:
case 2:
case 4:
break;
/*case 8: - later*/
default:
}
/*
* Convert the pointer to a DBGF address.
*/
if (RT_FAILURE(rc))
/*
* Pick out the optional arguments.
*/
uint64_t iHitTrigger = 0;
uint64_t iHitDisable = ~0;
unsigned iArg = 3;
{
iArg++;
{
iArg++;
}
}
{
iArg++;
}
/*
* Try set the breakpoint.
*/
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
if (rc == VERR_DBGC_BP_EXISTS)
{
if (RT_SUCCESS(rc))
}
}
return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "Failed to set access breakpoint at %RGv", Address.FlatPtr);
}
/**
* The 'bc' command.
*
* @returns VBox status.
* @param pCmd Pointer to the command descriptor (as registered).
* @param pCmdHlp Pointer to command helper functions.
* @param pVM Pointer to the current VM (if any).
* @param paArgs Pointer to (readonly) array of arguments.
* @param cArgs Number of arguments in the array.
*/
static DECLCALLBACK(int) dbgcCmdBrkClear(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs)
{
/*
* Enumerate the arguments.
*/
int rc = VINF_SUCCESS;
{
{
/* one */
{
if (RT_FAILURE(rc2))
}
else
}
{
/* all */
while (pBp)
{
if (RT_FAILURE(rc2))
}
}
else
}
return rc;
}
/**
* The 'bd' command.
*
* @returns VBox status.
* @param pCmd Pointer to the command descriptor (as registered).
* @param pCmdHlp Pointer to command helper functions.
* @param pVM Pointer to the current VM (if any).
* @param paArgs Pointer to (readonly) array of arguments.
* @param cArgs Number of arguments in the array.
*/
static DECLCALLBACK(int) dbgcCmdBrkDisable(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs)
{
/*
* Enumerate the arguments.
*/
int rc = VINF_SUCCESS;
{
{
/* one */
{
if (RT_FAILURE(rc))
}
else
}
{
/* all */
{
if (RT_FAILURE(rc2))
}
}
else
}
return rc;
}
/**
* The 'be' command.
*
* @returns VBox status.
* @param pCmd Pointer to the command descriptor (as registered).
* @param pCmdHlp Pointer to command helper functions.
* @param pVM Pointer to the current VM (if any).
* @param paArgs Pointer to (readonly) array of arguments.
* @param cArgs Number of arguments in the array.
*/
static DECLCALLBACK(int) dbgcCmdBrkEnable(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs)
{
/*
* Enumerate the arguments.
*/
int rc = VINF_SUCCESS;
{
{
/* one */
{
if (RT_FAILURE(rc))
}
else
}
{
/* all */
{
if (RT_FAILURE(rc2))
}
}
else
}
return rc;
}
/**
* Breakpoint enumeration callback function.
*
* @returns VBox status code. Any failure will stop the enumeration.
* @param pVM The VM handle.
* @param pvUser The user argument.
* @param pBp Pointer to the breakpoint information. (readonly)
*/
{
/*
* BP type and size.
*/
char chType;
char cb = 1;
{
case DBGFBPTYPE_INT3:
chType = 'p';
break;
case DBGFBPTYPE_REG:
{
default: chType = '?'; break;
}
break;
case DBGFBPTYPE_REM:
chType = 'r';
break;
default:
chType = '?';
break;
}
else
/*
* Try resolve the address.
*/
int rc = DBGFR3AsSymbolByAddr(pVM, pDbgc->hDbgAs, DBGFR3AddrFromFlat(pVM, &Addr, pBp->GCPtr), &off, &Sym, NULL);
if (RT_SUCCESS(rc))
{
if (!off)
else if (off > 0)
else
}
/*
* The commands.
*/
if (pDbgcBp)
{
else
}
else
return VINF_SUCCESS;
}
/**
* The 'bl' command.
*
* @returns VBox status.
* @param pCmd Pointer to the command descriptor (as registered).
* @param pCmdHlp Pointer to command helper functions.
* @param pVM Pointer to the current VM (if any).
* @param paArgs Pointer to (readonly) array of arguments.
* @param cArgs Number of arguments in the array.
*/
static DECLCALLBACK(int) dbgcCmdBrkList(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR /*paArgs*/, unsigned cArgs)
{
/*
* Enumerate the breakpoints.
*/
if (RT_FAILURE(rc))
return rc;
}
/**
* The 'bp' command.
*
* @returns VBox status.
* @param pCmd Pointer to the command descriptor (as registered).
* @param pCmdHlp Pointer to command helper functions.
* @param pVM Pointer to the current VM (if any).
* @param paArgs Pointer to (readonly) array of arguments.
* @param cArgs Number of arguments in the array.
*/
static DECLCALLBACK(int) dbgcCmdBrkSet(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs)
{
/*
* Convert the pointer to a DBGF address.
*/
if (RT_FAILURE(rc))
/*
* Pick out the optional arguments.
*/
uint64_t iHitTrigger = 0;
uint64_t iHitDisable = ~0;
unsigned iArg = 1;
{
iArg++;
{
iArg++;
}
}
{
iArg++;
}
/*
* Try set the breakpoint.
*/
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
if (rc == VERR_DBGC_BP_EXISTS)
{
if (RT_SUCCESS(rc))
}
}
}
/**
* The 'br' command.
*
* @returns VBox status.
* @param pCmd Pointer to the command descriptor (as registered).
* @param pCmdHlp Pointer to command helper functions.
* @param pVM Pointer to the current VM (if any).
* @param paArgs Pointer to (readonly) array of arguments.
* @param cArgs Number of arguments in the array.
*/
static DECLCALLBACK(int) dbgcCmdBrkREM(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs)
{
/*
* Convert the pointer to a DBGF address.
*/
if (RT_FAILURE(rc))
/*
* Pick out the optional arguments.
*/
uint64_t iHitTrigger = 0;
uint64_t iHitDisable = ~0;
unsigned iArg = 1;
{
iArg++;
{
iArg++;
}
}
{
iArg++;
}
/*
* Try set the breakpoint.
*/
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
if (rc == VERR_DBGC_BP_EXISTS)
{
if (RT_SUCCESS(rc))
}
}
return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "Failed to set REM breakpoint at %RGv", Address.FlatPtr);
}
/**
* The 'u' command.
*
* @returns VBox status.
* @param pCmd Pointer to the command descriptor (as registered).
* @param pCmdHlp Pointer to command helper functions.
* @param pVM Pointer to the current VM (if any).
* @param paArgs Pointer to (readonly) array of arguments.
* @param cArgs Number of arguments in the array.
*/
static DECLCALLBACK(int) dbgcCmdUnassemble(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs)
{
/*
* Validate input.
*/
DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, cArgs == 0 || DBGCVAR_ISPOINTER(paArgs[0].enmType));
/*
* Check the desired mode.
*/
unsigned fFlags = DBGF_DISAS_FLAGS_NO_ADDRESS;
{
default: AssertFailed();
}
/*
* Find address.
*/
if (!cArgs)
{
{
/** @todo Batch query CS, RIP & CPU mode. */
if ( pDbgc->fRegCtxGuest
{
}
else
{
pDbgc->SourcePos.u.GCFar.off = pDbgc->fRegCtxGuest ? CPUMGetGuestEIP(pVCpu) : CPUMGetHyperEIP(pVCpu);
}
if (pDbgc->fRegCtxGuest)
else
}
}
else
/*
* Range.
*/
{
case DBGCVAR_RANGE_NONE:
break;
case DBGCVAR_RANGE_ELEMENTS:
break;
case DBGCVAR_RANGE_BYTES:
break;
default:
}
/*
* Convert physical and host addresses to guest addresses.
*/
int rc;
{
case DBGCVAR_TYPE_GC_FLAT:
case DBGCVAR_TYPE_GC_FAR:
break;
case DBGCVAR_TYPE_GC_PHYS:
case DBGCVAR_TYPE_HC_FLAT:
case DBGCVAR_TYPE_HC_PHYS:
{
if (RT_FAILURE(rc))
break;
}
default: AssertFailed(); break;
}
/*
* Print address.
* todo: Change to list near.
*/
#if 0
if (RT_FAILURE(rc))
return rc;
#endif
/*
* Do the disassembling.
*/
unsigned cTries = 32;
if (iRangeLeft == 0) /* kludge for 'r'. */
iRangeLeft = -1;
for (;;)
{
/*
* Disassemble the instruction.
*/
char szDis[256];
else
rc = DBGFR3DisasInstrEx(pVM, pDbgc->idCpu, pDbgc->DisasmPos.u.GCFar.sel, pDbgc->DisasmPos.u.GCFar.off, fFlags,
if (RT_SUCCESS(rc))
{
/* print it */
if (RT_FAILURE(rc))
return rc;
}
else
{
/* bitch. */
if (RT_FAILURE(rc))
return rc;
if (cTries-- > 0)
cbInstr = 1;
}
/* advance */
if (iRangeLeft < 0) /* 'r' */
break;
iRangeLeft--;
else
iRangeLeft -= cbInstr;
if (RT_FAILURE(rc))
return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "DBGCCmdHlpEval(,,'(%Dv) + %x')", &pDbgc->DisasmPos, cbInstr);
if (iRangeLeft <= 0)
break;
}
return VINF_SUCCESS;
}
/**
* The 'ls' command.
*
* @returns VBox status.
* @param pCmd Pointer to the command descriptor (as registered).
* @param pCmdHlp Pointer to command helper functions.
* @param pVM Pointer to the current VM (if any).
* @param paArgs Pointer to (readonly) array of arguments.
* @param cArgs Number of arguments in the array.
*/
static DECLCALLBACK(int) dbgcCmdListSource(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs)
{
/*
* Validate input.
*/
if ( cArgs > 1
return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "internal error: The parser doesn't do its job properly yet.. It might help to use the '%%' operator.\n");
/*
* Find address.
*/
if (!cArgs)
{
{
pDbgc->SourcePos.u.GCFar.off = pDbgc->fRegCtxGuest ? CPUMGetGuestEIP(pVCpu) : CPUMGetHyperEIP(pVCpu);
}
}
else
/*
* Ensure the source address is flat GC.
*/
{
case DBGCVAR_TYPE_GC_FLAT:
break;
case DBGCVAR_TYPE_GC_PHYS:
case DBGCVAR_TYPE_GC_FAR:
case DBGCVAR_TYPE_HC_FLAT:
case DBGCVAR_TYPE_HC_PHYS:
{
if (RT_FAILURE(rc))
break;
}
default: AssertFailed(); break;
}
/*
* Range.
*/
{
case DBGCVAR_RANGE_NONE:
break;
case DBGCVAR_RANGE_ELEMENTS:
break;
case DBGCVAR_RANGE_BYTES:
break;
default:
return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "internal error: Unknown range type %d.\n", pDbgc->SourcePos.enmRangeType);
}
/*
* Do the disassembling.
*/
bool fFirst = 1;
if (iRangeLeft == 0) /* kludge for 'r'. */
iRangeLeft = -1;
for (;;)
{
/*
* Get line info.
*/
if (RT_FAILURE(rc))
return VINF_SUCCESS;
unsigned cLines = 0;
{
/*
* Print filenamename
*/
fFirst = true;
if (fFirst)
{
if (RT_FAILURE(rc))
return rc;
}
/*
* Try open the file and read the line.
*/
if (phFile)
{
/* Skip ahead to the desired line. */
char szLine[4096];
if (cBefore > 7)
cBefore = 0;
while (cLeft > 0)
{
szLine[0] = '\0';
break;
cLeft--;
}
if (!cLeft)
{
/* print the before lines */
for (;;)
{
while (cch > 0 && (szLine[cch - 1] == '\r' || szLine[cch - 1] == '\n' || RT_C_IS_SPACE(szLine[cch - 1])) )
if (cBefore-- <= 0)
break;
szLine[0] = '\0';
cLines++;
}
/* print the actual line */
}
if (RT_FAILURE(rc))
return rc;
fFirst = false;
}
else
return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "Warning: couldn't open source file '%s'\n", Line.szFilename);
}
/*
* Advance
*/
if (iRangeLeft < 0) /* 'r' */
break;
iRangeLeft -= cLines;
else
iRangeLeft -= 1;
if (RT_FAILURE(rc))
if (iRangeLeft <= 0)
break;
}
return 0;
}
/**
* The 'r' command.
*
* @returns VBox status.
* @param pCmd Pointer to the command descriptor (as registered).
* @param pCmdHlp Pointer to command helper functions.
* @param pVM Pointer to the current VM (if any).
* @param paArgs Pointer to (readonly) array of arguments.
* @param cArgs Number of arguments in the array.
*/
static DECLCALLBACK(int) dbgcCmdReg(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs)
{
if (!pDbgc->fRegCtxGuest)
}
/**
* Common worker for the dbgcCmdReg*() commands.
*
* @returns VBox status.
* @param pCmd Pointer to the command descriptor (as registered).
* @param pCmdHlp Pointer to command helper functions.
* @param pVM Pointer to the current VM (if any).
* @param paArgs Pointer to (readonly) array of arguments.
* @param cArgs Number of arguments in the array.
* @param pszPrefix The symbol prefix.
*/
static DECLCALLBACK(int) dbgcCmdRegCommon(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs,
const char *pszPrefix)
{
return DBGCCmdHlpPrintf(pCmdHlp, "internal error: The parser doesn't do its job properly yet.. Try drop the '@' or/and quote the register name\n");
/*
* Parse the register name and kind.
*/
if (*pszReg == '@')
pszReg++;
if (*pszPrefix)
if (*pszReg == '.')
{
pszReg++;
}
/*
* Query the register type & value (the setter needs the type).
*/
if (RT_FAILURE(rc))
{
if (rc == VERR_DBGF_REGISTER_NOT_FOUND)
}
if (cArgs == 1)
{
/*
* Show the register.
*/
char szValue[160];
if (RT_SUCCESS(rc))
else
}
else if (cArgs == 2)
{
/*
* Modify the register.
*/
return DBGCCmdHlpPrintf(pCmdHlp, "internal error: The parser doesn't do its job properly on the 2nd argument yet...\n");
if (enmType != DBGFREGVALTYPE_DTR)
{
}
else
{
}
if (RT_SUCCESS(rc))
{
if (RT_FAILURE(rc))
}
else
}
else
{
}
return rc;
}
/**
* The 'rg', 'rg64' and 'rg32' commands.
*
* @returns VBox status.
* @param pCmd Pointer to the command descriptor (as registered).
* @param pCmdHlp Pointer to command helper functions.
* @param pVM Pointer to the current VM (if any).
* @param paArgs Pointer to (readonly) array of arguments.
* @param cArgs Number of arguments in the array.
*/
static DECLCALLBACK(int) dbgcCmdRegGuest(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs)
{
/*
* Show all registers our selves.
*/
if (cArgs == 0)
{
char szDisAndRegs[8192];
int rc;
{
if (f64BitMode)
"u %016VR{rip} L 0\n"
"rax=%016VR{rax} rbx=%016VR{rbx} rcx=%016VR{rcx} rdx=%016VR{rdx}\n"
"rsi=%016VR{rsi} rdi=%016VR{rdi} r8 =%016VR{r8} r9 =%016VR{r9}\n"
"r10=%016VR{r10} r11=%016VR{r11} r12=%016VR{r12} r13=%016VR{r13}\n"
"r14=%016VR{r14} r15=%016VR{r15} %VRF{rflags}\n"
"rip=%016VR{rip} rsp=%016VR{rsp} rbp=%016VR{rbp}\n"
"cs=%04VR{cs} ds=%04VR{ds} es=%04VR{es} fs=%04VR{fs} gs=%04VR{gs} ss=%04VR{ss} rflags=%08VR{rflags}\n");
else
"u %04VR{cs}:%08VR{eip} L 0\n"
"eax=%08VR{eax} ebx=%08VR{ebx} ecx=%08VR{ecx} edx=%08VR{edx} esi=%08VR{esi} edi=%08VR{edi}\n"
"eip=%08VR{eip} esp=%08VR{esp} ebp=%08VR{ebp} %VRF{eflags}\n"
"cs=%04VR{cs} ds=%04VR{ds} es=%04VR{es} fs=%04VR{fs} gs=%04VR{gs} ss=%04VR{ss} eflags=%08VR{eflags}\n");
}
else
{
if (f64BitMode)
"u %016VR{rip} L 0\n"
"rax=%016VR{rax} rbx=%016VR{rbx} rcx=%016VR{rcx} rdx=%016VR{rdx}\n"
"rsi=%016VR{rsi} rdi=%016VR{rdi} r8 =%016VR{r8} r9 =%016VR{r9}\n"
"r10=%016VR{r10} r11=%016VR{r11} r12=%016VR{r12} r13=%016VR{r13}\n"
"r14=%016VR{r14} r15=%016VR{r15} %VRF{rflags}\n"
"rip=%016VR{rip} rsp=%016VR{rsp} rbp=%016VR{rbp}\n"
"cs={%04VR{cs} base=%016VR{cs_base} limit=%08VR{cs_lim} flags=%04VR{cs_attr}} cr0=%016VR{cr0}\n"
"ds={%04VR{ds} base=%016VR{ds_base} limit=%08VR{ds_lim} flags=%04VR{ds_attr}} cr2=%016VR{cr2}\n"
"es={%04VR{es} base=%016VR{es_base} limit=%08VR{es_lim} flags=%04VR{es_attr}} cr3=%016VR{cr3}\n"
"fs={%04VR{fs} base=%016VR{fs_base} limit=%08VR{fs_lim} flags=%04VR{fs_attr}} cr4=%016VR{cr4}\n"
"gs={%04VR{gs} base=%016VR{gs_base} limit=%08VR{gs_lim} flags=%04VR{gs_attr}} cr8=%016VR{cr8}\n"
"ss={%04VR{ss} base=%016VR{ss_base} limit=%08VR{ss_lim} flags=%04VR{ss_attr}}\n"
"dr0=%016VR{dr0} dr1=%016VR{dr1} dr2=%016VR{dr2} dr3=%016VR{dr3}\n"
"dr6=%016VR{dr6} dr7=%016VR{dr7}\n"
"gdtr=%016VR{gdtr_base}:%04VR{gdtr_lim} idtr=%016VR{idtr_base}:%04VR{idtr_lim} rflags=%08VR{rflags}\n"
"ldtr={%04VR{ldtr} base=%016VR{ldtr_base} limit=%08VR{ldtr_lim} flags=%08VR{ldtr_attr}}\n"
"tr ={%04VR{tr} base=%016VR{tr_base} limit=%08VR{tr_lim} flags=%08VR{tr_attr}}\n"
" sysenter={cs=%04VR{sysenter_cs} eip=%08VR{sysenter_eip} esp=%08VR{sysenter_esp}}\n"
" efer=%016VR{efer}\n"
" pat=%016VR{pat}\n"
" sf_mask=%016VR{sf_mask}\n"
"krnl_gs_base=%016VR{krnl_gs_base}\n"
" lstar=%016VR{lstar}\n"
" star=%016VR{star} cstar=%016VR{cstar}\n"
"fcw=%04VR{fcw} fsw=%04VR{fsw} ftw=%04VR{ftw} mxcsr=%04VR{mxcsr} mxcsr_mask=%04VR{mxcsr_mask}\n"
);
else
"u %04VR{cs}:%08VR{eip} L 0\n"
"eax=%08VR{eax} ebx=%08VR{ebx} ecx=%08VR{ecx} edx=%08VR{edx} esi=%08VR{esi} edi=%08VR{edi}\n"
"eip=%08VR{eip} esp=%08VR{esp} ebp=%08VR{ebp} %VRF{eflags}\n"
"cs={%04VR{cs} base=%08VR{cs_base} limit=%08VR{cs_lim} flags=%04VR{cs_attr}} dr0=%08VR{dr0} dr1=%08VR{dr1}\n"
"ds={%04VR{ds} base=%08VR{ds_base} limit=%08VR{ds_lim} flags=%04VR{ds_attr}} dr2=%08VR{dr2} dr3=%08VR{dr3}\n"
"es={%04VR{es} base=%08VR{es_base} limit=%08VR{es_lim} flags=%04VR{es_attr}} dr6=%08VR{dr6} dr7=%08VR{dr7}\n"
"fs={%04VR{fs} base=%08VR{fs_base} limit=%08VR{fs_lim} flags=%04VR{fs_attr}} cr0=%08VR{cr0} cr2=%08VR{cr2}\n"
"gs={%04VR{gs} base=%08VR{gs_base} limit=%08VR{gs_lim} flags=%04VR{gs_attr}} cr3=%08VR{cr3} cr4=%08VR{cr4}\n"
"ss={%04VR{ss} base=%08VR{ss_base} limit=%08VR{ss_lim} flags=%04VR{ss_attr}} cr8=%08VR{cr8}\n"
"gdtr=%08VR{gdtr_base}:%04VR{gdtr_lim} idtr=%08VR{idtr_base}:%04VR{idtr_lim} eflags=%08VR{eflags}\n"
"ldtr={%04VR{ldtr} base=%08VR{ldtr_base} limit=%08VR{ldtr_lim} flags=%04VR{ldtr_attr}}\n"
"tr ={%04VR{tr} base=%08VR{tr_base} limit=%08VR{tr_lim} flags=%04VR{tr_attr}}\n"
"sysenter={cs=%04VR{sysenter_cs} eip=%08VR{sysenter_eip} esp=%08VR{sysenter_esp}}\n"
"fcw=%04VR{fcw} fsw=%04VR{fsw} ftw=%04VR{ftw} mxcsr=%04VR{mxcsr} mxcsr_mask=%04VR{mxcsr_mask}\n"
);
}
if (RT_FAILURE(rc))
*pszRegs++ = '\0';
/*
* Disassemble one instruction at cs:[r|e]ip.
*/
}
}
/**
* The 'rh' command.
*
* @returns VBox status.
* @param pCmd Pointer to the command descriptor (as registered).
* @param pCmdHlp Pointer to command helper functions.
* @param pVM Pointer to the current VM (if any).
* @param paArgs Pointer to (readonly) array of arguments.
* @param cArgs Number of arguments in the array.
*/
static DECLCALLBACK(int) dbgcCmdRegHyper(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs)
{
/*
* Show all registers our selves.
*/
if (cArgs == 0)
{
char szDisAndRegs[8192];
int rc;
"u %VR{cs}:%VR{eip} L 0\n"
".eax=%08VR{eax} .ebx=%08VR{ebx} .ecx=%08VR{ecx} .edx=%08VR{edx} .esi=%08VR{esi} .edi=%08VR{edi}\n"
".eip=%08VR{eip} .esp=%08VR{esp} .ebp=%08VR{ebp} .%VRF{eflags}\n"
".cs=%04VR{cs} .ds=%04VR{ds} .es=%04VR{es} .fs=%04VR{fs} .gs=%04VR{gs} .ss=%04VR{ss} .eflags=%08VR{eflags}\n");
else
"u %04VR{cs}:%08VR{eip} L 0\n"
".eax=%08VR{eax} .ebx=%08VR{ebx} .ecx=%08VR{ecx} .edx=%08VR{edx} .esi=%08VR{esi} .edi=%08VR{edi}\n"
".eip=%08VR{eip} .esp=%08VR{esp} .ebp=%08VR{ebp} .%VRF{eflags}\n"
".cs={%04VR{cs} base=%08VR{cs_base} limit=%08VR{cs_lim} flags=%04VR{cs_attr}} .dr0=%08VR{dr0} .dr1=%08VR{dr1}\n"
".ds={%04VR{ds} base=%08VR{ds_base} limit=%08VR{ds_lim} flags=%04VR{ds_attr}} .dr2=%08VR{dr2} .dr3=%08VR{dr3}\n"
".es={%04VR{es} base=%08VR{es_base} limit=%08VR{es_lim} flags=%04VR{es_attr}} .dr6=%08VR{dr6} .dr6=%08VR{dr6}\n"
".fs={%04VR{fs} base=%08VR{fs_base} limit=%08VR{fs_lim} flags=%04VR{fs_attr}} .cr3=%016VR{cr3}\n"
".gs={%04VR{gs} base=%08VR{gs_base} limit=%08VR{gs_lim} flags=%04VR{gs_attr}}\n"
".ss={%04VR{ss} base=%08VR{ss_base} limit=%08VR{ss_lim} flags=%04VR{ss_attr}}\n"
".gdtr=%08VR{gdtr_base}:%04VR{gdtr_lim} .idtr=%08VR{idtr_base}:%04VR{idtr_lim} .eflags=%08VR{eflags}\n"
".ldtr={%04VR{ldtr} base=%08VR{ldtr_base} limit=%08VR{ldtr_lim} flags=%04VR{ldtr_attr}}\n"
".tr ={%04VR{tr} base=%08VR{tr_base} limit=%08VR{tr_lim} flags=%04VR{tr_attr}}\n"
);
if (RT_FAILURE(rc))
*pszRegs++ = '\0';
/*
* Disassemble one instruction at cs:[r|e]ip.
*/
}
}
/**
* The 'rt' command.
*
* @returns VBox status.
* @param pCmd Pointer to the command descriptor (as registered).
* @param pCmdHlp Pointer to command helper functions.
* @param pVM Pointer to the current VM (if any).
* @param paArgs Pointer to (readonly) array of arguments.
* @param cArgs Number of arguments in the array.
*/
static DECLCALLBACK(int) dbgcCmdRegTerse(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs)
{
return pCmdHlp->pfnPrintf(pCmdHlp, NULL, pDbgc->fRegTerse ? "info: Terse register info.\n" : "info: Verbose register info.\n");
}
/**
* The 't' command.
*
* @returns VBox status.
* @param pCmd Pointer to the command descriptor (as registered).
* @param pCmdHlp Pointer to command helper functions.
* @param pVM Pointer to the current VM (if any).
* @param paArgs Pointer to (readonly) array of arguments.
* @param cArgs Number of arguments in the array.
*/
static DECLCALLBACK(int) dbgcCmdTrace(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs)
{
if (RT_SUCCESS(rc))
else
rc = pDbgc->CmdHlp.pfnVBoxError(&pDbgc->CmdHlp, rc, "When trying to single step VM %p\n", pDbgc->pVM);
return rc;
}
/**
* The 'k', 'kg' and 'kh' commands.
*
* @returns VBox status.
* @param pCmd Pointer to the command descriptor (as registered).
* @param pCmdHlp Pointer to command helper functions.
* @param pVM Pointer to the current VM (if any).
* @param paArgs Pointer to (readonly) array of arguments.
* @param cArgs Number of arguments in the array.
*/
static DECLCALLBACK(int) dbgcCmdStack(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs)
{
/*
* Figure which context we're called for and start walking that stack.
*/
int rc;
rc = DBGFR3StackWalkBegin(pVM, pDbgc->idCpu, fGuest ? DBGFCODETYPE_GUEST : DBGFCODETYPE_HYPER, &pFirstFrame);
if (RT_FAILURE(rc))
/*
* Print header.
* 12345678 12345678 0023:87654321 12345678 87654321 12345678 87654321 symbol
*/
{
uint32_t const fCurBitFlags = pFrame->fFlags & (DBGFSTACKFRAME_FLAGS_16BIT | DBGFSTACKFRAME_FLAGS_32BIT | DBGFSTACKFRAME_FLAGS_64BIT);
{
if (fCurBitFlags != fBitFlags)
pCmdHlp->pfnPrintf(pCmdHlp, NULL, "SS:BP Ret SS:BP Ret CS:EIP Arg0 Arg1 Arg2 Arg3 CS:EIP / Symbol [line]\n");
rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%04RX16:%04RX16 %04RX16:%04RX16 %04RX32:%08RX32 %08RX32 %08RX32 %08RX32 %08RX32",
}
else if (fCurBitFlags & DBGFSTACKFRAME_FLAGS_32BIT)
{
if (fCurBitFlags != fBitFlags)
pCmdHlp->pfnPrintf(pCmdHlp, NULL, "EBP Ret EBP Ret CS:EIP Arg0 Arg1 Arg2 Arg3 CS:EIP / Symbol [line]\n");
rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%08RX32 %08RX32 %04RX32:%08RX32 %08RX32 %08RX32 %08RX32 %08RX32",
}
else if (fCurBitFlags & DBGFSTACKFRAME_FLAGS_64BIT)
{
if (fCurBitFlags != fBitFlags)
}
if (RT_FAILURE(rc))
break;
? " %RTsel:%016RGv"
? " %RTsel:%08RGv"
: " %RTsel:%04RGv"
else
{
RTGCINTPTR offDisp = pFrame->AddrPC.FlatPtr - pFrame->pSymPC->Value; /** @todo this isn't 100% correct for segmented stuff. */
if (offDisp > 0)
else if (offDisp < 0)
else
}
rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, " [%s @ 0i%d]", pFrame->pLinePC->szFilename, pFrame->pLinePC->uLineNo);
if (RT_SUCCESS(rc))
if (RT_FAILURE(rc))
break;
}
return rc;
}
static int dbgcCmdDumpDTWorker64(PDBGCCMDHLP pCmdHlp, PCX86DESC64 pDesc, unsigned iEntry, bool fHyper, bool *pfDblEntry)
{
/* GUEST64 */
int rc;
{
static const char * const s_apszTypes[] =
{
"DataRO", /* 0 Read-Only */
"DataRO", /* 1 Read-Only - Accessed */
"DownRO", /* 4 Expand-down, Read-Only */
"DownRO", /* 5 Expand-down, Read-Only - Accessed */
"CodeEO", /* 8 Execute-Only */
"CodeEO", /* 9 Execute-Only - Accessed */
"ConfE0", /* C Conforming, Execute-Only */
"ConfE0", /* D Conforming, Execute-Only - Accessed */
};
cbLimit <<= PAGE_SHIFT;
rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%04x %s Bas=%08x Lim=%08x DPL=%d %s %s %s %s AVL=%d L=%d%s\n",
}
else
{
static const char * const s_apszTypes[] =
{
"Ill-0 ", /* 0 0000 Reserved (Illegal) */
"Ill-1 ", /* 1 0001 Available 16-bit TSS */
"LDT ", /* 2 0010 LDT */
"Ill-3 ", /* 3 0011 Busy 16-bit TSS */
"Ill-4 ", /* 4 0100 16-bit Call Gate */
"Ill-5 ", /* 5 0101 Task Gate */
"Ill-6 ", /* 6 0110 16-bit Interrupt Gate */
"Ill-7 ", /* 7 0111 16-bit Trap Gate */
"Ill-8 ", /* 8 1000 Reserved (Illegal) */
"Tss64A", /* 9 1001 Available 32-bit TSS */
"Ill-A ", /* A 1010 Reserved (Illegal) */
"Tss64B", /* B 1011 Busy 32-bit TSS */
"Call64", /* C 1100 32-bit Call Gate */
"Ill-D ", /* D 1101 Reserved (Illegal) */
"Int64 ", /* E 1110 32-bit Interrupt Gate */
"Trap64" /* F 1111 32-bit Trap Gate */
};
{
/* raw */
break;
case X86_SEL_TYPE_SYS_LDT:
{
rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%04x %s Bas=%016RX64 Lim=%08x DPL=%d %s %s %s %sAVL=%d R=%d%s\n",
pszHyper);
if (pfDblEntry)
*pfDblEntry = true;
break;
}
{
if (pfDblEntry)
*pfDblEntry = true;
break;
}
{
if (pfDblEntry)
*pfDblEntry = true;
break;
}
/* impossible, just it's necessary to keep gcc happy. */
default:
return VINF_SUCCESS;
}
}
return VINF_SUCCESS;
}
/**
* Worker function that displays one descriptor entry (GDT, LDT, IDT).
*
* @returns pfnPrintf status code.
* @param pCmdHlp The DBGC command helpers.
* @param pDesc The descriptor to display.
* @param iEntry The descriptor entry number.
* @param fHyper Whether the selector belongs to the hypervisor or not.
*/
static int dbgcCmdDumpDTWorker32(PDBGCCMDHLP pCmdHlp, PCX86DESC pDesc, unsigned iEntry, bool fHyper)
{
int rc;
{
static const char * const s_apszTypes[] =
{
"DataRO", /* 0 Read-Only */
"DataRO", /* 1 Read-Only - Accessed */
"DownRO", /* 4 Expand-down, Read-Only */
"DownRO", /* 5 Expand-down, Read-Only - Accessed */
"CodeEO", /* 8 Execute-Only */
"CodeEO", /* 9 Execute-Only - Accessed */
"ConfE0", /* C Conforming, Execute-Only */
"ConfE0", /* D Conforming, Execute-Only - Accessed */
};
cbLimit <<= PAGE_SHIFT;
rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%04x %s Bas=%08x Lim=%08x DPL=%d %s %s %s %s AVL=%d L=%d%s\n",
}
else
{
static const char * const s_apszTypes[] =
{
"Ill-0 ", /* 0 0000 Reserved (Illegal) */
"Tss16A", /* 1 0001 Available 16-bit TSS */
"LDT ", /* 2 0010 LDT */
"Tss16B", /* 3 0011 Busy 16-bit TSS */
"Call16", /* 4 0100 16-bit Call Gate */
"TaskG ", /* 5 0101 Task Gate */
"Int16 ", /* 6 0110 16-bit Interrupt Gate */
"Trap16", /* 7 0111 16-bit Trap Gate */
"Ill-8 ", /* 8 1000 Reserved (Illegal) */
"Tss32A", /* 9 1001 Available 32-bit TSS */
"Ill-A ", /* A 1010 Reserved (Illegal) */
"Tss32B", /* B 1011 Busy 32-bit TSS */
"Call32", /* C 1100 32-bit Call Gate */
"Ill-D ", /* D 1101 Reserved (Illegal) */
"Int32 ", /* E 1110 32-bit Interrupt Gate */
"Trap32" /* F 1111 32-bit Trap Gate */
};
{
/* raw */
break;
case X86_SEL_TYPE_SYS_LDT:
{
cbLimit <<= PAGE_SHIFT;
rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%04x %s Bas=%08x Lim=%08x DPL=%d %s %s %s %s AVL=%d R=%d%s\n",
pszHyper);
break;
}
{
break;
}
{
break;
}
{
break;
}
/* impossible, just it's necessary to keep gcc happy. */
default:
return VINF_SUCCESS;
}
}
return rc;
}
/**
* The 'dg', 'dga', 'dl' and 'dla' commands.
*
* @returns VBox status.
* @param pCmd Pointer to the command descriptor (as registered).
* @param pCmdHlp Pointer to command helper functions.
* @param pVM Pointer to the current VM (if any).
* @param paArgs Pointer to (readonly) array of arguments.
* @param cArgs Number of arguments in the array.
*/
static DECLCALLBACK(int) dbgcCmdDumpDT(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs)
{
/*
* Validate input.
*/
if (!pVM)
/*
* Get the CPU mode, check which command variation this is
* and fix a default parameter if needed.
*/
if (!cArgs)
{
cArgs = 1;
}
/*
* Process the arguments.
*/
for (unsigned i = 0; i < cArgs; i++)
{
/*
* Retrieve the selector value from the argument.
* The parser may confuse pointers and numbers if more than one
* argument is given, that that into account.
*/
/* check that what we got makes sense as we don't trust the parser yet. */
return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: arg #%u isn't of number or pointer type but %d.\n", i, paArgs[i].enmType);
unsigned cSels = 1;
{
case DBGCVAR_TYPE_NUMBER:
break;
}
{
/*
* Dump the specified range.
*/
while ( cSels-- > 0
{
if (RT_SUCCESS(rc))
{
else if ( fAll
|| fSingle
{
if (enmMode == CPUMMODE_PROTECTED)
rc = dbgcCmdDumpDTWorker32(pCmdHlp, &SelInfo.u.Raw, Sel, !!(SelInfo.fFlags & DBGFSELINFO_FLAGS_HYPER));
else
{
bool fDblSkip = false;
rc = dbgcCmdDumpDTWorker64(pCmdHlp, &SelInfo.u.Raw64, Sel, !!(SelInfo.fFlags & DBGFSELINFO_FLAGS_HYPER), &fDblSkip);
if (fDblSkip)
Sel += 4;
}
}
}
else
{
if (!fAll)
return rc;
}
if (RT_FAILURE(rc))
return rc;
/* next */
Sel += 8;
}
}
else
}
return VINF_SUCCESS;
}
/**
* The 'di' and 'dia' commands.
*
* @returns VBox status.
* @param pCmd Pointer to the command descriptor (as registered).
* @param pCmdHlp Pointer to command helper functions.
* @param pVM Pointer to the current VM (if any).
* @param paArgs Pointer to (readonly) array of arguments.
* @param cArgs Number of arguments in the array.
*/
static DECLCALLBACK(int) dbgcCmdDumpIDT(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs)
{
/*
* Validate input.
*/
if (!pVM)
/*
* Establish some stuff like the current IDTR and CPU mode,
* and fix a default parameter.
*/
unsigned cbEntry;
switch (enmMode)
{
default:
}
if (!cArgs)
{
cArgs = 1;
}
/*
* Process the arguments.
*/
for (unsigned i = 0; i < cArgs; i++)
{
/* check that what we got makes sense as we don't trust the parser yet. */
return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: arg #%u isn't of number type but %d.\n", i, paArgs[i].enmType);
{
: 1;
while ( cInts-- > 0
&& iInt < 256)
{
/*
* Try read it.
*/
union
{
} u;
{
return VINF_SUCCESS;
}
if (RT_FAILURE(rc))
/*
* Display it.
*/
switch (enmMode)
{
case CPUMMODE_REAL:
/** @todo resolve 16:16 IDTE to a symbol */
break;
case CPUMMODE_PROTECTED:
break;
case CPUMMODE_LONG:
break;
default: break; /* to shut up gcc */
}
if (RT_FAILURE(rc))
return rc;
/* next */
iInt++;
}
}
else
pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: %llx is out of bounds (max 256)\n", paArgs[i].u.u64Number);
}
return VINF_SUCCESS;
}
/**
* The 'da', 'dq', 'dd', 'dw' and 'db' commands.
*
* @returns VBox status.
* @param pCmd Pointer to the command descriptor (as registered).
* @param pCmdHlp Pointer to command helper functions.
* @param pVM Pointer to the current VM (if any).
* @param paArgs Pointer to (readonly) array of arguments.
* @param cArgs Number of arguments in the array.
*/
static DECLCALLBACK(int) dbgcCmdDumpMem(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs)
{
/*
* Validate input.
*/
if ( cArgs > 1
return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "internal error: The parser doesn't do its job properly yet.. It might help to use the '%%' operator.\n");
if (!pVM)
/*
* Figure out the element size.
*/
unsigned cbElement;
bool fAscii = false;
{
default:
case 'a':
cbElement = 1;
fAscii = true;
break;
case '\0':
if (!cbElement)
cbElement = 1;
break;
}
/*
* Find address.
*/
if (!cArgs)
else
/*
* Range.
*/
{
case DBGCVAR_RANGE_NONE:
break;
case DBGCVAR_RANGE_ELEMENTS:
return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: Too many elements requested. Max is 2048 elements.\n");
break;
case DBGCVAR_RANGE_BYTES:
break;
default:
return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "internal error: Unknown range type %d.\n", pDbgc->DumpPos.enmRangeType);
}
/*
* Do the dumping.
*/
for (;;)
{
/*
* Read memory.
*/
char achBuffer[16];
if (RT_FAILURE(rc))
{
}
/*
* Display it.
*/
if (!fAscii)
{
unsigned i;
{
const char *pszSpace = " ";
pszSpace = "-";
switch (cbElement)
{
case 8: pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%s%016llx", pszSpace, *(uint64_t *)&achBuffer[i]); break;
}
}
/* chars column */
{
while (i++ < sizeof(achBuffer))
{
else
}
}
}
else
{
/*
* We print up to the first zero and stop there.
* Only printables + '\t' and '\n' are printed.
*/
if (!u8Prev)
unsigned i;
for (i = 0; i < cb; i++)
{
if ( u8 < 127
|| u8 == '\t'
|| u8 == '\n'))
else if (!u8)
break;
else
}
if (u8 == '\0')
}
/*
* Advance
*/
if (RT_FAILURE(rc))
if (cbLeft <= 0)
break;
}
return VINF_SUCCESS;
}
/**
* Best guess at which paging mode currently applies to the guest
* paging structures.
*
* This have to come up with a decent answer even when the guest
* is in non-paged protected mode or real mode.
*
* @returns cr3.
* @param pDbgc The DBGC instance.
* @param pfPAE Where to store the page address extension indicator.
* @param pfLME Where to store the long mode enabled indicator.
* @param pfPSE Where to store the page size extension indicator.
* @param pfPGE Where to store the page global enabled indicator.
* @param pfNXE Where to store the no-execution enabled indicator.
*/
static RTGCPHYS dbgcGetGuestPageMode(PDBGC pDbgc, bool *pfPAE, bool *pfLME, bool *pfPSE, bool *pfPGE, bool *pfNXE)
{
if (cr4 & X86_CR4_PAE)
{
*pfPSE = true;
*pfPAE = true;
}
else
*pfPAE = false;
*pfNXE = false; /* GUEST64 GUESTNX */
return CPUMGetGuestCR3(pVCpu);
}
/**
* Determine the shadow paging mode.
*
* @returns cr3.
* @param pDbgc The DBGC instance.
* @param pfPAE Where to store the page address extension indicator.
* @param pfLME Where to store the long mode enabled indicator.
* @param pfPSE Where to store the page size extension indicator.
* @param pfPGE Where to store the page global enabled indicator.
* @param pfNXE Where to store the no-execution enabled indicator.
*/
static RTHCPHYS dbgcGetShadowPageMode(PDBGC pDbgc, bool *pfPAE, bool *pfLME, bool *pfPSE, bool *pfPGE, bool *pfNXE)
{
*pfPSE = true;
*pfPGE = false;
switch (PGMGetShadowMode(pVCpu))
{
default:
case PGMMODE_32_BIT:
break;
case PGMMODE_PAE:
*pfPAE = true;
break;
case PGMMODE_PAE_NX:
*pfLME = false;
break;
case PGMMODE_AMD64:
*pfNXE = false;
break;
case PGMMODE_AMD64_NX:
break;
}
return PGMGetHyperCR3(pVCpu);
}
/**
* The 'dpd', 'dpda', 'dpdb', 'dpdg' and 'dpdh' commands.
*
* @returns VBox status.
* @param pCmd Pointer to the command descriptor (as registered).
* @param pCmdHlp Pointer to command helper functions.
* @param pVM Pointer to the current VM (if any).
* @param paArgs Pointer to (readonly) array of arguments.
* @param cArgs Number of arguments in the array.
*/
static DECLCALLBACK(int) dbgcCmdDumpPageDir(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs)
{
/*
* Validate input.
*/
if ( cArgs > 1
|| (cArgs == 1 && pCmd->pszCmd[3] != 'a' && !(paArgs[0].enmType == DBGCVAR_TYPE_NUMBER || DBGCVAR_ISPOINTER(paArgs[0].enmType)))
)
return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "internal error: The parser doesn't do its job properly yet.. It might help to use the '%%' operator.\n");
if (!pVM)
/*
* Guest or shadow page directories? Get the paging parameters.
*/
/*
* Setup default argument if none was specified.
* Fix address / index confusion.
*/
if (!cArgs)
{
{
return DBGCCmdHlpPrintf(pCmdHlp, "Default argument for 'dpda' hasn't been fully implemented yet. Try with an address or use one of the other commands.\n");
if (fGuest)
else
}
else
paArgs = &VarDefault;
cArgs = 1;
}
{
VarDefault = paArgs[0];
{
if (fPAE)
}
paArgs = &VarDefault;
}
/*
* Locate the PDE to start displaying at.
*
* The 'dpda' command takes the address of a PDE, while the others are guest
* virtual address which PDEs should be displayed. So, 'dpda' is rather simple
* while the others require us to do all the tedious walking thru the paging
* hierarchy to find the intended PDE.
*/
unsigned iEntry = ~0U; /* The page directory index. ~0U for 'dpta'. */
unsigned cEntries; /* The number of entries to display. */
unsigned cEntriesMax; /* The max number of entries to display. */
int rc;
{
VarPDEAddr = paArgs[0];
switch (VarPDEAddr.enmRangeType)
{
default: cEntries = 10; break;
}
}
else
{
/*
* Determine the range.
*/
switch (paArgs[0].enmRangeType)
{
default: cEntries = 10; break;
}
/*
* Normalize the input address, it must be a flat GC address.
*/
if (RT_FAILURE(rc))
{
}
if (fPAE)
else
/*
* Do the paging walk until we get to the page directory.
*/
if (fGuest)
else
if (fLME)
{
/* Page Map Level 4 Lookup. */
/* Check if it's a valid address first? */
VarCur.u.u64Number += (((uint64_t)VarGCPtr.u.GCFlat >> X86_PML4_SHIFT) & X86_PML4_MASK) * sizeof(X86PML4E);
if (RT_FAILURE(rc))
return DBGCCmdHlpPrintf(pCmdHlp, "Page directory pointer table is not present for %Dv.\n", &VarGCPtr);
}
if (fPAE)
{
/* Page directory pointer table. */
if (RT_FAILURE(rc))
VarPDEAddr = VarCur;
}
else
{
/* 32-bit legacy - CR3 == page directory. */
VarPDEAddr = VarCur;
}
}
/* adjust cEntries */
/*
* The display loop.
*/
&VarPDEAddr, iEntry);
do
{
/*
* Read.
*/
Pde.u = 0;
if (RT_FAILURE(rc))
/*
* Display.
*/
if (iEntry != ~0U)
{
iEntry++;
}
? "%016llx big phys=%016llx %s %s %s %s %s avl=%02x %s %s %s %s %s"
: "%08llx big phys=%08llx %s %s %s %s %s avl=%02x %s %s %s %s %s",
Pde.u,
Pde.u & X86_PDE_PAE_PG_MASK,
Pde.b.u3Available,
else
? "%016llx 4kb phys=%016llx %s %s %s %s %s avl=%02x %s %s %s %s"
: "%08llx 4kb phys=%08llx %s %s %s %s %s avl=%02x %s %s %s %s",
Pde.u,
Pde.u & X86_PDE_PAE_PG_MASK,
Pde.n.u3Available,
if (RT_FAILURE(rc))
return rc;
/*
* Advance.
*/
if (iEntry != ~0U)
} while (cEntries-- > 0);
return VINF_SUCCESS;
}
/**
* The 'dpdb' command.
*
* @returns VBox status.
* @param pCmd Pointer to the command descriptor (as registered).
* @param pCmdHlp Pointer to command helper functions.
* @param pVM Pointer to the current VM (if any).
* @param paArgs Pointer to (readonly) array of arguments.
* @param cArgs Number of arguments in the array.
*/
static DECLCALLBACK(int) dbgcCmdDumpPageDirBoth(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs)
{
if (!pVM)
if (RT_FAILURE(rc1))
return rc1;
return rc2;
}
/**
* The 'dph*' commands and main part of 'm'.
*
* @returns VBox status.
* @param pCmd Pointer to the command descriptor (as registered).
* @param pCmdHlp Pointer to command helper functions.
* @param pVM Pointer to the current VM (if any).
* @param paArgs Pointer to (readonly) array of arguments.
* @param cArgs Number of arguments in the array.
*/
static DECLCALLBACK(int) dbgcCmdDumpPageHierarchy(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs)
{
if (!pVM)
/*
* Figure the context and base flags.
*/
else
AssertFailed();
if (pDbgc->cPagingHierarchyDumps == 0)
/*
* Get the range.
*/
if (RT_FAILURE(rc))
if (RT_FAILURE(rc))
else if (!cbRange)
else
/*
* Do we have a CR3?
*/
if (cArgs > 1)
{
if ((fFlags & (DBGFPGDMP_FLAGS_GUEST | DBGFPGDMP_FLAGS_SHADOW)) == (DBGFPGDMP_FLAGS_GUEST | DBGFPGDMP_FLAGS_SHADOW))
return DBGCCmdHlpFail(pCmdHlp, pCmd, "No CR3 or mode arguments when dumping both context, please.");
}
else
/*
* Do we have a mode?
*/
if (cArgs > 2)
{
static const struct MODETOFLAGS
{
const char *pszName;
} s_aModeToFlags[] =
{
{ "ept", DBGFPGDMP_FLAGS_EPT },
{ "legacy", 0 },
{ "legacy-np", DBGFPGDMP_FLAGS_NP },
{ "pse", DBGFPGDMP_FLAGS_PSE },
{ "pae-nx-np", DBGFPGDMP_FLAGS_PSE | DBGFPGDMP_FLAGS_PAE | DBGFPGDMP_FLAGS_NXE | DBGFPGDMP_FLAGS_NP },
{ "long-np", DBGFPGDMP_FLAGS_PSE | DBGFPGDMP_FLAGS_PAE | DBGFPGDMP_FLAGS_LME | DBGFPGDMP_FLAGS_NP },
{ "long-nx", DBGFPGDMP_FLAGS_PSE | DBGFPGDMP_FLAGS_PAE | DBGFPGDMP_FLAGS_LME | DBGFPGDMP_FLAGS_NXE },
{ "long-nx-np", DBGFPGDMP_FLAGS_PSE | DBGFPGDMP_FLAGS_PAE | DBGFPGDMP_FLAGS_LME | DBGFPGDMP_FLAGS_NXE | DBGFPGDMP_FLAGS_NP }
};
int i = RT_ELEMENTS(s_aModeToFlags);
while (i-- > 0)
{
break;
}
if (i < 0)
}
else
/*
* Call the worker.
*/
if (RT_FAILURE(rc))
return VINF_SUCCESS;
}
/**
* The 'dpg*' commands.
*
* @returns VBox status.
* @param pCmd Pointer to the command descriptor (as registered).
* @param pCmdHlp Pointer to command helper functions.
* @param pVM Pointer to the current VM (if any).
* @param paArgs Pointer to (readonly) array of arguments.
* @param cArgs Number of arguments in the array.
*/
static DECLCALLBACK(int) dbgcCmdDumpPageTable(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs)
{
/*
* Validate input.
*/
if ( cArgs != 1
|| (pCmd->pszCmd[3] != 'a' && !(paArgs[0].enmType == DBGCVAR_TYPE_NUMBER || DBGCVAR_ISPOINTER(paArgs[0].enmType)))
)
return DBGCCmdHlpPrintf(pCmdHlp, "internal error: The parser doesn't do its job properly yet.. It might help to use the '%%' operator.\n");
if (!pVM)
/*
* Guest or shadow page tables? Get the paging parameters.
*/
/*
* Locate the PTE to start displaying at.
*
* The 'dpta' command takes the address of a PTE, while the others are guest
* virtual address which PTEs should be displayed. So, 'pdta' is rather simple
* while the others require us to do all the tedious walking thru the paging
* hierarchy to find the intended PTE.
*/
unsigned iEntry = ~0U; /* The page table index. ~0U for 'dpta'. */
unsigned cEntries; /* The number of entries to display. */
unsigned cEntriesMax; /* The max number of entries to display. */
int rc;
{
VarPTEAddr = paArgs[0];
switch (VarPTEAddr.enmRangeType)
{
default: cEntries = 10; break;
}
}
else
{
/*
* Determine the range.
*/
switch (paArgs[0].enmRangeType)
{
default: cEntries = 10; break;
}
/*
* Normalize the input address, it must be a flat GC address.
*/
if (RT_FAILURE(rc))
{
}
/*
* Do the paging walk until we get to the page table.
*/
if (fGuest)
else
if (fLME)
{
/* Page Map Level 4 Lookup. */
/* Check if it's a valid address first? */
VarCur.u.u64Number += (((uint64_t)VarGCPtr.u.GCFlat >> X86_PML4_SHIFT) & X86_PML4_MASK) * sizeof(X86PML4E);
if (RT_FAILURE(rc))
return DBGCCmdHlpPrintf(pCmdHlp, "Page directory pointer table is not present for %Dv.\n", &VarGCPtr);
}
if (fPAE)
{
/* Page directory pointer table. */
if (RT_FAILURE(rc))
/* Page directory (PAE). */
if (RT_FAILURE(rc))
VarPTEAddr = VarCur;
}
else
{
/* Page directory (legacy). */
if (RT_FAILURE(rc))
VarPTEAddr = VarCur;
}
}
/* adjust cEntries */
/*
* The display loop.
*/
do
{
/*
* Read.
*/
Pte.u = 0;
if (RT_FAILURE(rc))
/*
* Display.
*/
if (iEntry != ~0U)
{
iEntry++;
}
? "%016llx 4kb phys=%016llx %s %s %s %s %s avl=%02x %s %s %s %s %s"
: "%08llx 4kb phys=%08llx %s %s %s %s %s avl=%02x %s %s %s %s %s",
Pte.u,
Pte.u & X86_PTE_PAE_PG_MASK,
Pte.n.u3Available,
);
if (RT_FAILURE(rc))
return rc;
/*
* Advance.
*/
if (iEntry != ~0U)
} while (cEntries-- > 0);
return VINF_SUCCESS;
}
/**
* The 'dptb' command.
*
* @returns VBox status.
* @param pCmd Pointer to the command descriptor (as registered).
* @param pCmdHlp Pointer to command helper functions.
* @param pVM Pointer to the current VM (if any).
* @param paArgs Pointer to (readonly) array of arguments.
* @param cArgs Number of arguments in the array.
*/
static DECLCALLBACK(int) dbgcCmdDumpPageTableBoth(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs)
{
if (!pVM)
if (RT_FAILURE(rc1))
return rc1;
return rc2;
}
/**
* The 'dt' command.
*
* @returns VBox status.
* @param pCmd Pointer to the command descriptor (as registered).
* @param pCmdHlp Pointer to command helper functions.
* @param pVM Pointer to the current VM (if any).
* @param paArgs Pointer to (readonly) array of arguments.
* @param cArgs Number of arguments in the array.
*/
static DECLCALLBACK(int) dbgcCmdDumpTSS(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs)
{
int rc;
if (!pVM)
if ( cArgs > 1
return DBGCCmdHlpFail(pCmdHlp, pCmd, "internal error: The parser doesn't do its job properly yet...\n");
/*
* Check if the command indicates the type.
*/
enmTssType = kTss16;
enmTssType = kTss32;
enmTssType = kTss64;
/*
* We can get a TSS selector (number), a far pointer using a TSS selector, or some kind of TSS pointer.
*/
if (cArgs == 0)
{
/** @todo consider querying the hidden bits instead (missing API). */
if (RT_FAILURE(rc))
}
{
else
{
{
}
}
}
else
VarTssAddr = paArgs[0];
/*
* Deal with TSS:ign by means of the GDT.
*/
{
rc = DBGFR3SelQueryInfo(pVM, pDbgc->idCpu, VarTssAddr.u.GCFar.sel, DBGFSELQI_FLAGS_DT_GUEST, &SelInfo);
if (RT_FAILURE(rc))
return DBGCCmdHlpFail(pCmdHlp, pCmd, "%04x is not a TSS selector. (!sys)\n", VarTssAddr.u.GCFar.sel);
{
if (enmTssType == kTssToBeDetermined)
enmTssType = kTss16;
break;
case X86_SEL_TYPE_SYS_386_TSS_BUSY: /* AMD64 too */
if (enmTssType == kTssToBeDetermined)
break;
default:
}
}
/*
* Determine the TSS type if none is currently given.
*/
if (enmTssType == kTssToBeDetermined)
{
if ( VarTssAddr.u64Range > 0
enmTssType = kTss16;
else
{
if ( RT_FAILURE(rc)
|| !(uEfer & MSR_K6_EFER_LMA) )
enmTssType = kTss32;
else
enmTssType = kTss64;
}
}
/*
* ASSUMES max TSS size is 64 KB.
*/
switch (enmTssType)
{
case kTss16:
break;
case kTss32:
break;
case kTss64:
break;
default:
}
uint32_t cbTss = VarTssAddr.enmRangeType == DBGCVAR_RANGE_BYTES ? (uint32_t)VarTssAddr.u64Range : 0;
if (cbTss == 0)
return DBGCCmdHlpFail(pCmdHlp, pCmd, "Minimum TSS size is %u bytes, you specified %llu (%llx) bytes.\n",
/*
* Read the TSS into a temporary buffer.
*/
if (RT_FAILURE(rc))
return DBGCCmdHlpFail(pCmdHlp, pCmd, "Failed to read essential parts of the TSS (read %zu, min %zu).\n",
/*
* Format the TSS.
*/
switch (enmTssType)
{
case kTss16:
{
if (SelTss != UINT32_MAX)
else
"ax=%04x bx=%04x cx=%04x dx=%04x si=%04x di=%04x\n"
"ip=%04x sp=%04x bp=%04x\n"
"cs=%04x ss=%04x ds=%04x es=%04x flags=%04x\n"
"ss:sp0=%04x:%04x ss:sp1=%04x:%04x ss:sp2=%04x:%04x\n"
"prev=%04x ldtr=%04x\n"
,
offIoBitmap = 0;
break;
}
case kTss32:
{
if (SelTss != UINT32_MAX)
else
"eax=%08x bx=%08x ecx=%08x edx=%08x esi=%08x edi=%08x\n"
"eip=%08x esp=%08x ebp=%08x\n"
"cs=%04x ss=%04x ds=%04x es=%04x fs=%04x gs=%04x eflags=%08x\n"
"ss:esp0=%04x:%08x ss:esp1=%04x:%08x ss:esp2=%04x:%08x\n"
"prev=%04x ldtr=%04x cr3=%08x debug=%u iomap=%04x\n"
,
break;
}
case kTss64:
{
if (SelTss != UINT32_MAX)
else
"rsp0=%016RX16 rsp1=%016RX16 rsp2=%016RX16\n"
"ist1=%016RX16 ist2=%016RX16\n"
"ist3=%016RX16 ist4=%016RX16\n"
"ist5=%016RX16 ist6=%016RX16\n"
"ist7=%016RX16 iomap=%04x\n"
,
break;
}
default:
}
/*
* Dump the interrupt redirection bitmap.
*/
if (enmTssType != kTss16)
{
if ( offIoBitmap > cbTssMin
{
{
for (uint32_t i = 0; i < 256; i++)
{
{
DBGCCmdHlpPrintf(pCmdHlp, "%02x-%02x %s\n", iStart, i - 1, fPrev ? "Protected mode" : "Redirected");
iStart = i;
}
}
if (iStart != 255)
}
else
DBGCCmdHlpPrintf(pCmdHlp, "Invalid interrupt redirection bitmap size: %u (%#x), expected 32 bytes.\n",
}
else if (offIoBitmap > 0)
else
}
/*
* Dump the I/O bitmap if present.
*/
if (enmTssType != kTss16)
{
if (offIoBitmap < cbTss)
{
{
{
cLine++;
iStart = i;
}
}
}
else if (offIoBitmap > 0)
else
}
return VINF_SUCCESS;
}
/**
* The 'm' command.
*
* @returns VBox status.
* @param pCmd Pointer to the command descriptor (as registered).
* @param pCmdHlp Pointer to command helper functions.
* @param pVM Pointer to the current VM (if any).
* @param paArgs Pointer to (readonly) array of arguments.
* @param cArgs Number of arguments in the array.
*/
static DECLCALLBACK(int) dbgcCmdMemoryInfo(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs)
{
if (!pVM)
}
/**
* Converts one or more variables into a byte buffer for a
* given unit size.
*
* @returns VBox status codes:
* @retval VERR_TOO_MUCH_DATA if the buffer is too small, bitched.
* @retval VERR_INTERNAL_ERROR on bad variable type, bitched.
* @retval VINF_SUCCESS on success.
*
* @param pvBuf The buffer to convert into.
* @param pcbBuf The buffer size on input. The size of the result on output.
* @param cbUnit The unit size to apply when converting.
* The high bit is used to indicate unicode string.
* @param paVars The array of variables to convert.
* @param cVars The number of variables.
*/
int dbgcVarsToBytes(PDBGCCMDHLP pCmdHlp, void *pvBuf, uint32_t *pcbBuf, size_t cbUnit, PCDBGCVAR paVars, unsigned cVars)
{
union
{
} u, uEnd;
unsigned i;
{
{
case DBGCVAR_TYPE_GC_FAR:
case DBGCVAR_TYPE_GC_FLAT:
case DBGCVAR_TYPE_GC_PHYS:
case DBGCVAR_TYPE_HC_FLAT:
case DBGCVAR_TYPE_HC_PHYS:
case DBGCVAR_TYPE_NUMBER:
{
switch (cbUnit & 0x1f)
{
case 1:
do
{
u64 >>= 8;
} while (u64);
break;
case 2:
do
{
u64 >>= 16;
} while (u64);
break;
case 4:
u64 >>= 32;
if (u64)
break;
case 8:
break;
}
break;
}
case DBGCVAR_TYPE_STRING:
case DBGCVAR_TYPE_SYMBOL:
{
{
/* Explode char to unit. */
{
return VERR_TOO_MUCH_DATA;
}
while (*psz)
{
switch (cbUnit & 0x1f)
{
}
psz++;
}
}
else
{
/* Raw copy with zero padding if the size isn't aligned. */
{
return VERR_TOO_MUCH_DATA;
}
if (cbReminder)
{
}
}
break;
}
default:
return VERR_INTERNAL_ERROR;
}
}
if (i != cVars)
{
return VERR_TOO_MUCH_DATA;
}
return VINF_SUCCESS;
}
/**
* The 'eb', 'ew', 'ed' and 'eq' commands.
*
* @returns VBox status.
* @param pCmd Pointer to the command descriptor (as registered).
* @param pCmdHlp Pointer to command helper functions.
* @param pVM Pointer to the current VM (if any).
* @param paArgs Pointer to (readonly) array of arguments.
* @param cArgs Number of arguments in the array.
*/
static DECLCALLBACK(int) dbgcCmdEditMem(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs)
{
unsigned iArg;
/*
* Validate input.
*/
if ( cArgs < 2
return DBGCCmdHlpFail(pCmdHlp, pCmd, "internal error: The parser doesn't do its job properly yet... It might help to use the '%%' operator.\n");
return DBGCCmdHlpFail(pCmdHlp, pCmd, "internal error: The parser doesn't do its job properly yet: Arg #%u is not a number.\n", iArg);
if (!pVM)
/*
* Figure out the element size.
*/
unsigned cbElement;
{
default:
}
/*
* Do setting.
*/
for (iArg = 1;;)
{
if (RT_FAILURE(rc))
/* advance. */
iArg++;
break;
if (RT_FAILURE(rc))
}
return VINF_SUCCESS;
}
/**
* Executes the search.
*
* @returns VBox status code.
* @param pCmdHlp The command helpers.
* @param pVM The VM handle.
* @param pAddress The address to start searching from. (undefined on output)
* @param cbRange The address range to search. Must not wrap.
* @param pabBytes The byte pattern to search for.
* @param cbBytes The size of the pattern.
* @param cbUnit The search unit.
* @param cMaxHits The max number of hits.
* @param pResult Where to store the result if it's a function invocation.
*/
static int dbgcCmdWorkerSearchMemDoIt(PDBGCCMDHLP pCmdHlp, PVM pVM, PDBGFADDRESS pAddress, RTGCUINTPTR cbRange,
{
/*
* Do the search.
*/
for (;;)
{
/* search */
if (RT_FAILURE(rc))
{
if (rc != VERR_DBGF_MEM_NOT_FOUND)
/* update the current address so we can save it (later). */
cbRange = 0;
break;
}
/* report result */
if (RT_FAILURE(rc))
if (!pResult)
else
/* advance */
*pAddress = HitAddress;
{
cbRange = 0;
break;
}
{
/// @todo save the search.
break;
}
}
/*
* Save the search so we can resume it...
*/
{
}
}
/**
* Resumes the previous search.
*
* @returns VBox status code.
* @param pCmdHlp Pointer to the command helper functions.
* @param pVM Pointer to the current VM (if any).
* @param pResult Where to store the result of a function invocation.
*/
{
/*
* Make sure there is a previous command.
*/
{
return VERR_DBGC_COMMAND_FAILED;
}
/*
* Make range and address adjustments.
*/
{
}
if (!cbRange)
cbRange = ~(RTGCUINTPTR)0;
return dbgcCmdWorkerSearchMemDoIt(pCmdHlp, pVM, &Address, cbRange, pDbgc->abSearch, pDbgc->cbSearch,
}
/**
* Search memory, worker for the 's' and 's?' functions.
*
* @returns VBox status.
* @param pCmdHlp Pointer to the command helper functions.
* @param pVM Pointer to the current VM (if any).
* @param pAddress Where to start searching. If no range, search till end of address space.
* @param cMaxHits The maximum number of hits.
* @param chType The search type.
* @param paPatArgs The pattern variable array.
* @param cPatArgs Number of pattern variables.
* @param pResult Where to store the result of a function invocation.
*/
static int dbgcCmdWorkerSearchMem(PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR pAddress, uint64_t cMaxHits, char chType,
{
/*
* Convert the search pattern into bytes and DBGFR3MemScan can deal with.
*/
switch (chType)
{
case 'a':
default:
}
if (RT_FAILURE(rc))
return VERR_DBGC_COMMAND_FAILED;
/*
* Make DBGF address and fix the range.
*/
if (RT_FAILURE(rc))
switch (pAddress->enmRangeType)
{
case DBGCVAR_RANGE_BYTES:
cbRange = ~(RTGCUINTPTR)0;
break;
case DBGCVAR_RANGE_ELEMENTS:
cbRange = ~(RTGCUINTPTR)0;
break;
default:
cbRange = ~(RTGCUINTPTR)0;
break;
}
/*
* Ok, do it.
*/
return dbgcCmdWorkerSearchMemDoIt(pCmdHlp, pVM, &Address, cbRange, abBytes, cbBytes, cbUnit, cMaxHits, pResult);
}
/**
* The 's' command.
*
* @returns VBox status.
* @param pCmd Pointer to the command descriptor (as registered).
* @param pCmdHlp Pointer to command helper functions.
* @param pVM Pointer to the current VM (if any).
* @param paArgs Pointer to (readonly) array of arguments.
* @param cArgs Number of arguments in the array.
*/
static DECLCALLBACK(int) dbgcCmdSearchMem(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs)
{
/* check that the parser did what it's supposed to do. */
//if ( cArgs <= 2
// && paArgs[0].enmType != DBGCVAR_TYPE_STRING)
// return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "parser error\n");
/*
* Repeat previous search?
*/
if (cArgs == 0)
/*
* Parse arguments.
*/
return -1;
}
/**
* The 's?' command.
*
* @returns VBox status.
* @param pCmd Pointer to the command descriptor (as registered).
* @param pCmdHlp Pointer to command helper functions.
* @param pVM Pointer to the current VM (if any).
* @param paArgs Pointer to (readonly) array of arguments.
* @param cArgs Number of arguments in the array.
*/
static DECLCALLBACK(int) dbgcCmdSearchMemType(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs)
{
/* check that the parser did what it's supposed to do. */
if ( cArgs < 2
return dbgcCmdWorkerSearchMem(pCmdHlp, pVM, &paArgs[0], 25, pCmd->pszCmd[1], paArgs + 1, cArgs - 1, NULL);
}
/**
* List near symbol.
*
* @returns VBox status code.
* @param pCmdHlp Pointer to command helper functions.
* @param pVM Pointer to the current VM (if any).
* @param pArg Pointer to the address or symbol to lookup.
*/
{
int rc;
{
/*
* Lookup the symbol address.
*/
if (RT_FAILURE(rc))
}
else
{
/*
* Convert it to a flat GC address and lookup that address.
*/
if (RT_FAILURE(rc))
rc = DBGFR3AsSymbolByAddr(pVM, pDbgc->hDbgAs, DBGFR3AddrFromFlat(pVM, &Addr, AddrVar.u.GCFlat), &offDisp, &Symbol, NULL);
if (RT_FAILURE(rc))
if (!offDisp)
else if (offDisp > 0)
else
else
}
return rc;
}
/**
* The 'ln' (listnear) command.
*
* @returns VBox status.
* @param pCmd Pointer to the command descriptor (as registered).
* @param pCmdHlp Pointer to command helper functions.
* @param pVM Pointer to the current VM (if any).
* @param paArgs Pointer to (readonly) array of arguments.
* @param cArgs Number of arguments in the array.
*/
static DECLCALLBACK(int) dbgcCmdListNear(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs)
{
if (!cArgs)
{
/*
* Current cs:eip symbol.
*/
if (RT_FAILURE(rc))
}
/** @todo Fix the darn parser, it's resolving symbols specified as arguments before we get in here. */
/*
* Iterate arguments.
*/
{
if (RT_FAILURE(rc))
return rc;
}
return VINF_SUCCESS;
}
/**
* Matches the module patters against a module name.
*
* @returns true if matching, otherwise false.
* @param pszName The module name.
* @param paArgs The module pattern argument list.
* @param cArgs Number of arguments.
*/
{
return true;
return false;
}
/**
* The 'ln' (listnear) command.
*
* @returns VBox status.
* @param pCmd Pointer to the command descriptor (as registered).
* @param pCmdHlp Pointer to command helper functions.
* @param pVM Pointer to the current VM (if any).
* @param paArgs Pointer to (readonly) array of arguments.
* @param cArgs Number of arguments in the array.
*/
static DECLCALLBACK(int) dbgcCmdListModules(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs)
{
/*
* Iterate the modules in the current address space and print info about
* those matching the input.
*/
{
if (hMod != NIL_RTDBGMOD)
{
if ( cArgs == 0
{
/*
* Find the mapping with the lower address, preferring a full
* image mapping, for the main line.
*/
if (RT_SUCCESS(rc))
{
bool fFull = false;
&& ( !fFull
if (fMappings)
{
/* sort by address first - not very efficient. */
{
}
/* print */
/** @todo RTDbgModSegmentName(hMod, aMappings[iMap].iSeg)*/ "noname");
else
}
}
else
/** @todo missing address space API for enumerating the mappings. */
}
}
}
return VINF_SUCCESS;
}