DBGFDisas.cpp revision 61028bf0d1927cff20200e587be6f306aa331fe2
/* $Id$ */
/** @file
* VMM DBGF - Debugger Facility, Disassembler.
*/
/*
* Copyright (C) 2006-2007 innotek GmbH
*
* 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 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_DBGF
#include "DBGFInternal.h"
/*******************************************************************************
* Internal Functions *
*******************************************************************************/
static DECLCALLBACK(int) dbgfR3DisasInstrRead(RTHCUINTPTR pSrc, uint8_t *pDest, uint32_t size, void *pvUserdata);
/**
* Structure used when disassembling and instructions in DBGF.
* This is used so the reader function can get the stuff it needs.
*/
typedef struct
{
/** The core structure. */
/** The VM handle. */
/** Pointer to the first byte in the segemnt. */
/** Pointer to the byte after the end of the segment. (might have wrapped!) */
/** The size of the segment minus 1. */
/** The guest paging mode. */
/** Pointer to the current page - HC Ptr. */
void const *pvPageHC;
/** Pointer to the current page - GC Ptr. */
/** Pointer to the next instruction (relative to GCPtrSegBase). */
/** The lock information that PGMPhysReleasePageMappingLock needs. */
/** Whether the PageMapLock is valid or not. */
bool fLocked;
/**
* Calls the dissassembler with the proper reader functions and such for disa
*
* @returns VBox status code.
* @param pVM VM handle
* @param pSelInfo The selector info.
* @param enmMode The guest paging mode.
* @param GCPtr The GC pointer (selector offset).
* @param pState The disas CPU state.
*/
static int dbgfR3DisasInstrFirst(PVM pVM, PSELMSELINFO pSelInfo, PGMMODE enmMode, RTGCPTR GCPtr, PDBGFDISASSTATE pState)
{
if (VBOX_SUCCESS(rc))
{
return VINF_SUCCESS;
}
/* cleanup */
{
}
return rc;
}
#if 0
/**
* Calls the dissassembler for disassembling the next instruction.
*
* @returns VBox status code.
* @param pState The disas CPU state.
*/
{
if (VBOX_SUCCESS(rc))
{
return VINF_SUCCESS;
}
return rc;
}
#endif
/**
* Done with the dissassembler state, free associated resources.
*
* @param pState The disas CPU state ++.
*/
{
{
}
}
/**
* Instruction reader.
*
* @returns VBox status code. (Why this is a int32_t and not just an int is also beyond me.)
* @param PtrSrc Address to read from.
* In our case this is relative to the selector pointed to by the 2nd user argument of uDisCpu.
* @param pu8Dst Where to store the bytes.
* @param cbRead Number of bytes to read.
* @param uDisCpu Pointer to the disassembler cpu state. (Why this is a VBOXHUINTPTR is beyond me...)
* In this context it's always pointer to the Core of a DBGFDISASSTATE.
*/
static DECLCALLBACK(int) dbgfR3DisasInstrRead(RTHCUINTPTR PtrSrc, uint8_t *pu8Dst, uint32_t cbRead, void *pvDisCpu)
{
for (;;)
{
/* Need to update the page translation? */
{
int rc = VINF_SUCCESS;
/* translate the address */
{
}
else
{
rc = PGMPhysGCPhys2CCPtrReadOnly(pState->pVM, pState->pvPageGC, &pState->pvPageHC, &pState->PageMapLock);
else
rc = PGMPhysGCPtr2CCPtrReadOnly(pState->pVM, pState->pvPageGC, &pState->pvPageHC, &pState->PageMapLock);
}
if (VBOX_FAILURE(rc))
{
return rc;
}
}
/* check the segemnt limit */
return VERR_OUT_OF_SELECTOR_BOUNDS;
/* calc how much we can read */
/* read and advance */
if (!cbRead)
return VINF_SUCCESS;
}
}
/**
* Copy a string and return pointer to the terminator char in the copy.
*/
{
}
/**
* Disassembles the one instruction according to the specified flags and address.
*
* @returns VBox status code.
* @param pVM VM handle.
* @param Sel The code selector. This used to determin the 32/16 bit ness and
* calculation of the actual instruction address.
* @param GCPtr The code address relative to the base of Sel.
* @param fFlags Flags controlling where to start and how to format.
* A combination of the DBGF_DISAS_FLAGS_* \#defines.
* @param pszOutput Output buffer.
* @param cchOutput Size of the output buffer.
* @param pcbInstr Where to return the size of the instruction.
*/
DBGFR3DECL(int) DBGFR3DisasInstrEx(PVM pVM, RTSEL Sel, RTGCPTR GCPtr, unsigned fFlags, char *pszOutput, uint32_t cchOutput, uint32_t *pcbInstr)
{
/*
* Get the Sel and GCPtr if fFlags requests that.
*/
int rc;
{
else
}
/*
* Read the selector info - assume no stale selectors and nasty stuff like that.
* Since the selector flags in the CPUMCTX structures aren't up to date unless
* we recently visited REM, we'll not search for the selector there.
*/
bool fRealModeAddress = false;
if ( pHiddenSel
{
}
else if ( !(fFlags & DBGF_DISAS_FLAGS_CURRENT_HYPER)
|| enmMode == PGMMODE_REAL) )
{ /* V86 mode or real mode - real mode addressing */
fRealModeAddress = true;
}
else if (Sel == DBGF_SEL_FLAT)
{
}
else
{
if (VBOX_FAILURE(rc))
{
return rc;
}
}
/*
* Disassemble it.
*/
if (VBOX_FAILURE(rc))
{
return rc;
}
/*
* Format it.
*/
char szBuf[512];
/* prefix */
/* the instruction */
char ch;
{
pszFormat++;
}
{
do *psz++ = ' ';
#ifdef DEBUG_bird /* Not sure if Sander want's this because of log size */
#else
while (0);
#endif
pszFormat++;
}
/** @todo implement annotation and symbol lookup! */
int iParam = 1;
for (;;)
{
if (ch == '%')
{
switch (ch)
{
/*
* Relative jump offset.
*/
case 'J':
{
else
{
AssertMsgFailed(("Oops!\n"));
return VERR_GENERAL_FAILURE;
}
{
}
#ifdef DEBUG_bird /* an experiment. */
if ( VBOX_SUCCESS(rc)
{
if (off > 0)
else if (off > 0)
{
case CPUMODE_16BIT:
break;
case CPUMODE_32BIT:
break;
default:
break;
}
}
else
#endif /* DEBUG_bird */
{
{
case CPUMODE_16BIT:
break;
case CPUMODE_32BIT:
break;
default:
break;
}
}
break;
}
case 'A': //direct address
case 'C': //control register
case 'D': //debug register
case 'E': //ModRM specifies parameter
case 'F': //Eflags register
case 'G': //ModRM selects general register
case 'I': //Immediate data
case 'M': //ModRM may only refer to memory
case 'O': //No ModRM byte
case 'P': //ModRM byte selects MMX register
case 'Q': //ModRM byte selects MMX register or memory address
case 'R': //ModRM byte may only refer to a general register
case 'S': //ModRM byte selects a segment register
case 'T': //ModRM byte selects a test register
case 'X': //DS:SI
case 'Y': //ES:DI
switch (iParam)
{
}
pszFormat += 2;
break;
case 'e': //register based on operand size (e.g. %eAX)
*psz++ = 'E';
pszFormat += 4;
break;
default:
break;
}
/* Skip to the next parameter in the format string. */
if (!pszFormat)
break;
pszFormat++;
iParam++;
}
else
{
/* output char, but check for parameter separator first. */
if (ch == ',')
iParam++;
if (!ch)
break;
pszFormat++;
}
#ifdef DEBUG_bird /* Not sure if Sander want's this because of log size */
/* space after commas */
if (ch == ',')
{
pszFormat++;
*psz++ = ' ';
}
#endif
} /* foreach char in pszFormat */
*psz = '\0';
/*
* Print it to the user specified buffer.
*/
if (fFlags & DBGF_DISAS_FLAGS_NO_BYTES)
{
else if (fRealModeAddress)
else if (Sel == DBGF_SEL_FLAT)
else
}
else
{
szBuf);
else if (fRealModeAddress)
szBuf);
else if (Sel == DBGF_SEL_FLAT)
szBuf);
else
szBuf);
}
if (pcbInstr)
return VINF_SUCCESS;
}
/**
* Disassembles an instruction.
* Addresses will be tried resolved to symbols
*
* @returns VBox status code.
* @param pVM VM handle.
* @param Sel The code selector. This used to determin the 32/16 bit ness and
* calculation of the actual instruction address.
* @param GCPtr The code address relative to the base of Sel.
* @param pszOutput Output buffer.
* @param cchOutput Size of the output buffer.
*/
DBGFR3DECL(int) DBGFR3DisasInstr(PVM pVM, RTSEL Sel, RTGCPTR GCPtr, char *pszOutput, uint32_t cchOutput)
{
}
/**
* Disassembles the current guest context instruction.
* All registers and data will be displayed. Addresses will be attempted resolved to symbols.
*
* @returns VBox status code.
* @param pVM VM handle.
* @param pszOutput Output buffer.
* @param cchOutput Size of the output buffer.
*/
{
}
/**
* Disassembles the current guest context instruction and writes it to the log.
* All registers and data will be displayed. Addresses will be attempted resolved to symbols.
*
* @returns VBox status code.
* @param pVM VM handle.
* @param pszPrefix Short prefix string to the dissassembly string. (optional)
*/
{
char szBuf[256];
szBuf[0] = '\0';
if (VBOX_FAILURE(rc))
else
return rc;
}
/**
* Disassembles the specified guest context instruction and writes it to the log.
* Addresses will be attempted resolved to symbols.
*
* @returns VBox status code.
* @param pVM VM handle.
* @param Sel The code selector. This used to determin the 32/16 bit-ness and
* calculation of the actual instruction address.
* @param GCPtr The code address relative to the base of Sel.
*/
{
char szBuf[256];
szBuf[0] = '\0';
if (VBOX_FAILURE(rc))
RTStrPrintf(szBuf, sizeof(szBuf), "DBGFR3DisasInstrLog(, %RTsel, %RGv) failed with rc=%Vrc\n", Sel, GCPtr, rc);
return rc;
}