DBGFDisas.cpp revision 99cd1ce586a12bf6b8c6084cbcdebe8fe3553cc2
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * DBGF - Debugger Facility, Disassembler.
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * Copyright (C) 2006-2007 Oracle Corporation
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * available from http://www.virtualbox.org. This file is free software;
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * you can redistribute it and/or modify it under the terms of the GNU
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * General Public License (GPL) as published by the Free Software
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync/*******************************************************************************
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync* Header Files *
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync*******************************************************************************/
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync/*******************************************************************************
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync* Structures and Typedefs *
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync*******************************************************************************/
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * Structure used when disassembling and instructions in DBGF.
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * This is used so the reader function can get the stuff it needs.
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsynctypedef struct
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync /** The core structure. */
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync /** The VM handle. */
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync /** The VMCPU handle. */
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync /** The address space for resolving symbol. */
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync /** Pointer to the first byte in the segment. */
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync /** Pointer to the byte after the end of the segment. (might have wrapped!) */
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync /** The size of the segment minus 1. */
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync /** The guest paging mode. */
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync /** Pointer to the current page - R3 Ptr. */
f486cea04d3045b35f843ddd19eb2de45a9929fevboxsync void const *pvPageR3;
f486cea04d3045b35f843ddd19eb2de45a9929fevboxsync /** Pointer to the current page - GC Ptr. */
f486cea04d3045b35f843ddd19eb2de45a9929fevboxsync /** Pointer to the next instruction (relative to GCPtrSegBase). */
f486cea04d3045b35f843ddd19eb2de45a9929fevboxsync /** The lock information that PGMPhysReleasePageMappingLock needs. */
f486cea04d3045b35f843ddd19eb2de45a9929fevboxsync /** Whether the PageMapLock is valid or not. */
f486cea04d3045b35f843ddd19eb2de45a9929fevboxsync /** 64 bits mode or not. */
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync/*******************************************************************************
f486cea04d3045b35f843ddd19eb2de45a9929fevboxsync* Internal Functions *
f486cea04d3045b35f843ddd19eb2de45a9929fevboxsync*******************************************************************************/
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * Calls the disassembler with the proper reader functions and such for disa
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * @returns VBox status code.
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * @param pVM VM handle
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * @param pVCpu VMCPU handle
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * @param pSelInfo The selector info.
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * @param enmMode The guest paging mode.
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * @param fFlags DBGF_DISAS_FLAGS_XXX.
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * @param GCPtr The GC pointer (selector offset).
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * @param pState The disas CPU state.
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsyncstatic int dbgfR3DisasInstrFirst(PVM pVM, PVMCPU pVCpu, PDBGFSELINFO pSelInfo, PGMMODE enmMode,
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync RTGCPTR GCPtr, uint32_t fFlags, PDBGFDISASSTATE pState)
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync pState->GCPtrSegEnd = pSelInfo->cbLimit + 1 + (RTGCUINTPTR)pSelInfo->GCPtrBase;
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync pState->hAs = pSelInfo->fFlags & DBGFSELINFO_FLAGS_HYPER /** @todo Deal more explicitly with RC in DBGFR3Disas*. */
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync pState->f64Bits = enmMode >= PGMMODE_AMD64 && pSelInfo->u.Raw.Gen.u1Long;
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync /* cleanup */
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync PGMPhysReleasePageMappingLock(pVM, &pState->PageMapLock);
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * Calls the disassembler for disassembling the next instruction.
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * @returns VBox status code.
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * @param pState The disas CPU state.
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsyncstatic int dbgfR3DisasInstrNext(PDBGFDISASSTATE pState)
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync int rc = DISInstr(&pState->Cpu, (void *)pState->GCPtrNext, 0, &cbInstr, NULL);
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * Done with the disassembler state, free associated resources.
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * @param pState The disas CPU state ++.
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsyncstatic void dbgfR3DisasInstrDone(PDBGFDISASSTATE pState)
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync PGMPhysReleasePageMappingLock(pState->pVM, &pState->PageMapLock);
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * @callback_method_impl{FNDISREADBYTES}
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * @remarks @a uSrcAddr is relative to the base address indicated by
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * DBGFDISASSTATE::GCPtrSegBase.
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsyncstatic DECLCALLBACK(int) dbgfR3DisasInstrRead(PDISCPUSTATE pDisState, uint8_t *pbDst, RTUINTPTR uSrcAddr, uint32_t cbToRead)
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync PDBGFDISASSTATE pState = (PDBGFDISASSTATE)pDisState;
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync RTGCUINTPTR GCPtr = uSrcAddr + pState->GCPtrSegBase;
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync /* Need to update the page translation? */
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync || (GCPtr >> PAGE_SHIFT) != (pState->pvPageGC >> PAGE_SHIFT))
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync /* translate the address */
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync if (MMHyperIsInsideArea(pState->pVM, pState->pvPageGC))
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync pState->pvPageR3 = MMHyperRCToR3(pState->pVM, (RTRCPTR)pState->pvPageGC);
a98ffaaf4c29cf148cb52f094fe3c42fd4cdcc57vboxsync PGMPhysReleasePageMappingLock(pState->pVM, &pState->PageMapLock);
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync rc = PGMPhysGCPhys2CCPtrReadOnly(pState->pVM, pState->pvPageGC, &pState->pvPageR3, &pState->PageMapLock);
a98ffaaf4c29cf148cb52f094fe3c42fd4cdcc57vboxsync rc = PGMPhysGCPtr2CCPtrReadOnly(pState->pVCpu, pState->pvPageGC, &pState->pvPageR3, &pState->PageMapLock);
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync /* check the segment limit */
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync if (!pState->f64Bits && uSrcAddr > pState->cbSegLimit)
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync /* calc how much we can read */
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync uint32_t cb = PAGE_SIZE - (GCPtr & PAGE_OFFSET_MASK);
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync /* read and advance */
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync memcpy(pbDst, (char *)pState->pvPageR3 + (GCPtr & PAGE_OFFSET_MASK), cb);
a98ffaaf4c29cf148cb52f094fe3c42fd4cdcc57vboxsync * @copydoc FNDISGETSYMBOL
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsyncstatic DECLCALLBACK(int) dbgfR3DisasGetSymbol(PCDISCPUSTATE pCpu, uint32_t u32Sel, RTUINTPTR uAddress, char *pszBuf, size_t cchBuf, RTINTPTR *poff, void *pvUser)
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync rc = DBGFR3AddrFromSelInfoOff(pState->pVM, &Addr, pSelInfo, uAddress);
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync rc = DBGFR3AsSymbolByAddr(pState->pVM, pState->hAs, &Addr, &off, &Sym, NULL /*phMod*/);
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync rc = VERR_SYMBOL_NOT_FOUND; /** @todo implement this */
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * Disassembles the one instruction according to the specified flags and
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * address, internal worker executing on the EMT of the specified virtual CPU.
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * @returns VBox status code.
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * @param pVM The VM handle.
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * @param pVCpu The virtual CPU handle.
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * @param Sel The code selector. This used to determine the 32/16 bit ness and
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * calculation of the actual instruction address.
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * @param pGCPtr Pointer to the variable holding the code address
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * relative to the base of Sel.
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * @param fFlags Flags controlling where to start and how to format.
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * A combination of the DBGF_DISAS_FLAGS_* \#defines.
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * @param pszOutput Output buffer.
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * @param cbOutput Size of the output buffer.
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * @param pcbInstr Where to return the size of the instruction.
732da7aa8afe6d7a7afd51b07888b2ef48d22a31vboxsyncdbgfR3DisasInstrExOnVCpu(PVM pVM, PVMCPU pVCpu, RTSEL Sel, PRTGCPTR pGCPtr, uint32_t fFlags,
732da7aa8afe6d7a7afd51b07888b2ef48d22a31vboxsync char *pszOutput, uint32_t cbOutput, uint32_t *pcbInstr)
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * Get the Sel and GCPtr if fFlags requests that.
a98ffaaf4c29cf148cb52f094fe3c42fd4cdcc57vboxsync if (fFlags & (DBGF_DISAS_FLAGS_CURRENT_GUEST | DBGF_DISAS_FLAGS_CURRENT_HYPER))
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * Read the selector info - assume no stale selectors and nasty stuff like that.
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * Since the selector flags in the CPUMCTX structures aren't up to date unless
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * we recently visited REM, we'll not search for the selector there.
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync && ( (fFlags & DBGF_DISAS_FLAGS_HID_SEL_REGS_VALID)
a98ffaaf4c29cf148cb52f094fe3c42fd4cdcc57vboxsync : enmMode != PGMMODE_REAL && (!pCtxCore || !pCtxCore->eflags.Bits.u1VM)
a98ffaaf4c29cf148cb52f094fe3c42fd4cdcc57vboxsync SelInfo.u.Raw.Gen.u1Present = pHiddenSel->Attr.n.u1Present;
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync SelInfo.u.Raw.Gen.u1Granularity = pHiddenSel->Attr.n.u1Granularity;;
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync SelInfo.u.Raw.Gen.u1DefBig = pHiddenSel->Attr.n.u1DefBig;
f486cea04d3045b35f843ddd19eb2de45a9929fevboxsync SelInfo.u.Raw.Gen.u1Long = pHiddenSel->Attr.n.u1Long;
f486cea04d3045b35f843ddd19eb2de45a9929fevboxsync SelInfo.u.Raw.Gen.u1DescType = pHiddenSel->Attr.n.u1DescType;
f486cea04d3045b35f843ddd19eb2de45a9929fevboxsync SelInfo.u.Raw.Gen.u4Type = pHiddenSel->Attr.n.u4Type;
f486cea04d3045b35f843ddd19eb2de45a9929fevboxsync fRealModeAddress = !!(SelInfo.fFlags & DBGFSELINFO_FLAGS_REAL_MODE);
f486cea04d3045b35f843ddd19eb2de45a9929fevboxsync if ( (fFlags & DBGF_DISAS_FLAGS_HID_SEL_REGS_VALID)
f486cea04d3045b35f843ddd19eb2de45a9929fevboxsync { /* Assume the current CS defines the execution mode. */
f486cea04d3045b35f843ddd19eb2de45a9929fevboxsync SelInfo.u.Raw.Gen.u1Present = pHiddenSel->Attr.n.u1Present;
f486cea04d3045b35f843ddd19eb2de45a9929fevboxsync SelInfo.u.Raw.Gen.u1Granularity = pHiddenSel->Attr.n.u1Granularity;;
f486cea04d3045b35f843ddd19eb2de45a9929fevboxsync SelInfo.u.Raw.Gen.u1DefBig = pHiddenSel->Attr.n.u1DefBig;
f486cea04d3045b35f843ddd19eb2de45a9929fevboxsync SelInfo.u.Raw.Gen.u1Long = pHiddenSel->Attr.n.u1Long;
f486cea04d3045b35f843ddd19eb2de45a9929fevboxsync SelInfo.u.Raw.Gen.u1DescType = pHiddenSel->Attr.n.u1DescType;
f486cea04d3045b35f843ddd19eb2de45a9929fevboxsync SelInfo.u.Raw.Gen.u4Type = pHiddenSel->Attr.n.u4Type;
f486cea04d3045b35f843ddd19eb2de45a9929fevboxsync else if ( !(fFlags & DBGF_DISAS_FLAGS_CURRENT_HYPER)
f486cea04d3045b35f843ddd19eb2de45a9929fevboxsync || (fFlags & DBGF_DISAS_FLAGS_MODE_MASK) == DBGF_DISAS_FLAGS_16BIT_REAL_MODE
f486cea04d3045b35f843ddd19eb2de45a9929fevboxsync { /* V86 mode or real mode - real mode addressing */
f486cea04d3045b35f843ddd19eb2de45a9929fevboxsync rc = SELMR3GetSelectorInfo(pVM, pVCpu, Sel, &SelInfo);
f486cea04d3045b35f843ddd19eb2de45a9929fevboxsync RTStrPrintf(pszOutput, cbOutput, "Sel=%04x -> %Rrc\n", Sel, rc);
f486cea04d3045b35f843ddd19eb2de45a9929fevboxsync * Disassemble it.
f486cea04d3045b35f843ddd19eb2de45a9929fevboxsync rc = dbgfR3DisasInstrFirst(pVM, pVCpu, &SelInfo, enmMode, GCPtr, fFlags, &State);
f486cea04d3045b35f843ddd19eb2de45a9929fevboxsync RTStrPrintf(pszOutput, cbOutput, "Disas -> %Rrc\n", rc);
f486cea04d3045b35f843ddd19eb2de45a9929fevboxsync * Format it.
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync fFlags & DBGF_DISAS_FLAGS_NO_SYMBOLS ? NULL : dbgfR3DisasGetSymbol,
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * Print it to the user specified buffer.
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync RTStrPrintf(pszOutput, cbOutput, "%04x:%04x %s", Sel, (unsigned)GCPtr, szBuf);
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync RTStrPrintf(pszOutput, cbOutput, "%RGv %s", GCPtr, szBuf);
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync RTStrPrintf(pszOutput, cbOutput, "%08RX32 %s", (uint32_t)GCPtr, szBuf);
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync RTStrPrintf(pszOutput, cbOutput, "%04x:%RGv %s", Sel, GCPtr, szBuf);
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync RTStrPrintf(pszOutput, cbOutput, "%04x:%08RX32 %s", Sel, (uint32_t)GCPtr, szBuf);
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync rc = dbgfR3DisasInstrRead(&State.Cpu, pau8Bits, GCPtr, cbBits);
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync cbBits, pau8Bits, cbBits < 8 ? (8 - cbBits) * 3 : 0, "",
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync RTStrPrintf(pszOutput, cbOutput, "%04x:%04x %.*Rhxs%*s %s",
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync cbBits, pau8Bits, cbBits < 8 ? (8 - cbBits) * 3 : 0, "",
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync RTStrPrintf(pszOutput, cbOutput, "%RGv %.*Rhxs%*s %s",
f486cea04d3045b35f843ddd19eb2de45a9929fevboxsync cbBits, pau8Bits, cbBits < 8 ? (8 - cbBits) * 3 : 0, "",
f486cea04d3045b35f843ddd19eb2de45a9929fevboxsync RTStrPrintf(pszOutput, cbOutput, "%08RX32 %.*Rhxs%*s %s",
a98ffaaf4c29cf148cb52f094fe3c42fd4cdcc57vboxsync cbBits, pau8Bits, cbBits < 8 ? (8 - cbBits) * 3 : 0, "",
f486cea04d3045b35f843ddd19eb2de45a9929fevboxsync RTStrPrintf(pszOutput, cbOutput, "%04x:%RGv %.*Rhxs%*s %s",
f486cea04d3045b35f843ddd19eb2de45a9929fevboxsync cbBits, pau8Bits, cbBits < 8 ? (8 - cbBits) * 3 : 0, "",
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync RTStrPrintf(pszOutput, cbOutput, "%04x:%08RX32 %.*Rhxs%*s %s",
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync cbBits, pau8Bits, cbBits < 8 ? (8 - cbBits) * 3 : 0, "",
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * Disassembles the one instruction according to the specified flags and address.
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * @returns VBox status code.
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * @param pVM VM handle.
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * @param idCpu The ID of virtual CPU.
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * @param Sel The code selector. This used to determine the 32/16 bit ness and
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * calculation of the actual instruction address.
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * @param GCPtr The code address relative to the base of Sel.
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * @param fFlags Flags controlling where to start and how to format.
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * A combination of the DBGF_DISAS_FLAGS_* \#defines.
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * @param pszOutput Output buffer. This will always be properly
f486cea04d3045b35f843ddd19eb2de45a9929fevboxsync * terminated if @a cbOutput is greater than zero.
f486cea04d3045b35f843ddd19eb2de45a9929fevboxsync * @param cbOutput Size of the output buffer.
f486cea04d3045b35f843ddd19eb2de45a9929fevboxsync * @param pcbInstr Where to return the size of the instruction.
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * @remarks May have to switch to the EMT of the virtual CPU in order to do
f486cea04d3045b35f843ddd19eb2de45a9929fevboxsync * address conversion.
f486cea04d3045b35f843ddd19eb2de45a9929fevboxsyncVMMR3DECL(int) DBGFR3DisasInstrEx(PVM pVM, VMCPUID idCpu, RTSEL Sel, RTGCPTR GCPtr, uint32_t fFlags,
f486cea04d3045b35f843ddd19eb2de45a9929fevboxsync char *pszOutput, uint32_t cbOutput, uint32_t *pcbInstr)
f486cea04d3045b35f843ddd19eb2de45a9929fevboxsync AssertReturn(cbOutput > 0, VERR_INVALID_PARAMETER);
f486cea04d3045b35f843ddd19eb2de45a9929fevboxsync VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE);
f486cea04d3045b35f843ddd19eb2de45a9929fevboxsync AssertReturn(idCpu < pVM->cCpus, VERR_INVALID_CPU_ID);
f486cea04d3045b35f843ddd19eb2de45a9929fevboxsync AssertReturn(!(fFlags & ~DBGF_DISAS_FLAGS_VALID_MASK), VERR_INVALID_PARAMETER);
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync AssertReturn((fFlags & DBGF_DISAS_FLAGS_MODE_MASK) <= DBGF_DISAS_FLAGS_64BIT_MODE, VERR_INVALID_PARAMETER);
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * Optimize the common case where we're called on the EMT of idCpu since
a98ffaaf4c29cf148cb52f094fe3c42fd4cdcc57vboxsync * we're using this all the time when logging.
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync rc = dbgfR3DisasInstrExOnVCpu(pVM, pVCpu, Sel, &GCPtr, fFlags, pszOutput, cbOutput, pcbInstr);
f486cea04d3045b35f843ddd19eb2de45a9929fevboxsync rc = VMR3ReqPriorityCallWait(pVM, idCpu, (PFNRT)dbgfR3DisasInstrExOnVCpu, 8,
f486cea04d3045b35f843ddd19eb2de45a9929fevboxsync pVM, VMMGetCpuById(pVM, idCpu), Sel, &GCPtr, fFlags, pszOutput, cbOutput, pcbInstr);
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * Disassembles the current guest context instruction.
a98ffaaf4c29cf148cb52f094fe3c42fd4cdcc57vboxsync * All registers and data will be displayed. Addresses will be attempted resolved to symbols.
a98ffaaf4c29cf148cb52f094fe3c42fd4cdcc57vboxsync * @returns VBox status code.
a98ffaaf4c29cf148cb52f094fe3c42fd4cdcc57vboxsync * @param pVCpu VMCPU handle.
a98ffaaf4c29cf148cb52f094fe3c42fd4cdcc57vboxsync * @param pszOutput Output buffer. This will always be properly
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * terminated if @a cbOutput is greater than zero.
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * @param cbOutput Size of the output buffer.
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsyncVMMR3DECL(int) DBGFR3DisasInstrCurrent(PVMCPU pVCpu, char *pszOutput, uint32_t cbOutput)
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync AssertReturn(cbOutput > 0, VERR_INVALID_PARAMETER);
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync return DBGFR3DisasInstrEx(pVCpu->pVMR3, pVCpu->idCpu, 0, 0,
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync DBGF_DISAS_FLAGS_CURRENT_GUEST | DBGF_DISAS_FLAGS_DEFAULT_MODE,
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * Disassembles the current guest context instruction and writes it to the log.
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * All registers and data will be displayed. Addresses will be attempted resolved to symbols.
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * @returns VBox status code.
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * @param pVCpu VMCPU handle.
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * @param pszPrefix Short prefix string to the disassembly string. (optional)
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsyncVMMR3DECL(int) DBGFR3DisasInstrCurrentLogInternal(PVMCPU pVCpu, const char *pszPrefix)
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync int rc = DBGFR3DisasInstrCurrent(pVCpu, &szBuf[0], sizeof(szBuf));
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync RTStrPrintf(szBuf, sizeof(szBuf), "DBGFR3DisasInstrCurrentLog failed with rc=%Rrc\n", rc);
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync RTLogPrintf("%s-CPU%d: %s\n", pszPrefix, pVCpu->idCpu, szBuf);
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * Disassembles the specified guest context instruction and writes it to the log.
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * Addresses will be attempted resolved to symbols.
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * @returns VBox status code.
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * @param pVM VM handle.
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * @param pVCpu The virtual CPU handle, defaults to CPU 0 if NULL.
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * @param Sel The code selector. This used to determine the 32/16 bit-ness and
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync * calculation of the actual instruction address.
a98ffaaf4c29cf148cb52f094fe3c42fd4cdcc57vboxsync * @param GCPtr The code address relative to the base of Sel.
a98ffaaf4c29cf148cb52f094fe3c42fd4cdcc57vboxsyncVMMR3DECL(int) DBGFR3DisasInstrLogInternal(PVMCPU pVCpu, RTSEL Sel, RTGCPTR GCPtr)
a98ffaaf4c29cf148cb52f094fe3c42fd4cdcc57vboxsync int rc = DBGFR3DisasInstrEx(pVCpu->pVMR3, pVCpu->idCpu, Sel, GCPtr, DBGF_DISAS_FLAGS_DEFAULT_MODE,
e2a4ff87ea2e2e95350793b5fccb143c1819fadcvboxsync RTStrPrintf(szBuf, sizeof(szBuf), "DBGFR3DisasInstrLog(, %RTsel, %RGv) failed with rc=%Rrc\n", Sel, GCPtr, rc);