DBGCCmdHlp.cpp revision 6ffa2eb79bdf1b3299aacf589ece7b124ec34dc7
248c89033c87fed7229aa29bbbc4f4698fb13687vboxsync * DBGC - Debugger Console, Command Helpers.
248c89033c87fed7229aa29bbbc4f4698fb13687vboxsync * Copyright (C) 2006-2011 Oracle Corporation
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * available from http://www.virtualbox.org. This file is free software;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * you can redistribute it and/or modify it under the terms of the GNU
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * General Public License (GPL) as published by the Free Software
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync/*******************************************************************************
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync* Header Files *
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync*******************************************************************************/
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync * Command helper for writing text to the debug console.
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync * @returns VBox status.
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync * @param pCmdHlp Pointer to the command callback structure.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param pvBuf What to write.
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync * @param cbBuf Number of bytes to write.
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync * @param pcbWritten Where to store the number of bytes actually written.
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync * If NULL the entire buffer must be successfully written.
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsyncstatic DECLCALLBACK(int) dbgcHlpWrite(PDBGCCMDHLP pCmdHlp, const void *pvBuf, size_t cbBuf, size_t *pcbWritten)
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync return pDbgc->pBack->pfnWrite(pDbgc->pBack, pvBuf, cbBuf, pcbWritten);
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync * Command helper for writing formatted text to the debug console.
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync * @returns VBox status.
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync * @param pCmdHlp Pointer to the command callback structure.
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync * @param pcb Where to store the number of bytes written.
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync * @param pszFormat The format string.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * This is using the log formatter, so it's format extensions can be used.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param ... Arguments specified in the format string.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncstatic DECLCALLBACK(int) dbgcHlpPrintf(PDBGCCMDHLP pCmdHlp, size_t *pcbWritten, const char *pszFormat, ...)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Do the formatting and output.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync int rc = pCmdHlp->pfnPrintfV(pCmdHlp, pcbWritten, pszFormat, args);
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync * Callback to format non-standard format specifiers.
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync * @returns The number of bytes formatted.
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync * @param pvArg Formatter argument.
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync * @param pfnOutput Pointer to output function.
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync * @param pvArgOutput Argument for the output function.
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync * @param ppszFormat Pointer to the format string pointer. Advance this till the char
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync * after the format specifier.
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync * @param pArgs Pointer to the argument list. Use this to fetch the arguments.
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync * @param cchWidth Format Width. -1 if not specified.
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync * @param cchPrecision Format Precision. -1 if not specified.
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync * @param fFlags Flags (RTSTR_NTFS_*).
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync * @param chArgSize The argument size specifier, 'l' or 'L'.
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsyncstatic DECLCALLBACK(size_t) dbgcStringFormatter(void *pvArg, PFNRTSTROUTPUT pfnOutput, void *pvArgOutput,
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync const char **ppszFormat, va_list *pArgs, int cchWidth,
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync NOREF(cchWidth); NOREF(cchPrecision); NOREF(fFlags); NOREF(chArgSize); NOREF(pvArg);
ffb50166c9adb4ae583b914d405197035cf890advboxsync * Print variable without range.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * The argument is a const pointer to the variable.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, "%%%RGv", pVar->u.GCFlat);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, "%04x:%08x", pVar->u.GCFar.sel, pVar->u.GCFar.off);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, "%%%%%RGp", pVar->u.GCPhys);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, "%%#%RHv", (uintptr_t)pVar->u.pvHCFlat);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, "#%%%%%RHp", pVar->u.HCPhys);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return pfnOutput(pvArgOutput, pVar->u.pszString, (size_t)pVar->u64Range);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, "%llx", pVar->u.u64Number);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Print variable with range.
248c89033c87fed7229aa29bbbc4f4698fb13687vboxsync * The argument is a const pointer to the variable.
b4d7b4dbcc45b8bde7502aa129440d92d7ffd038vboxsync RTStrPrintf(szRange, sizeof(szRange), " L %llx", pVar->u64Range);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync RTStrPrintf(szRange, sizeof(szRange), " LB %llx", pVar->u64Range);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync return RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, "%%%RGv%s", pVar->u.GCFlat, szRange);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync return RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, "%04x:%08x%s", pVar->u.GCFar.sel, pVar->u.GCFar.off, szRange);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync return RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, "%%%%%RGp%s", pVar->u.GCPhys, szRange);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync return RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, "%%#%RHv%s", (uintptr_t)pVar->u.pvHCFlat, szRange);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync return RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, "#%%%%%RHp%s", pVar->u.HCPhys, szRange);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync return pfnOutput(pvArgOutput, pVar->u.pszString, (size_t)pVar->u64Range);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync return RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, "%llx%s", pVar->u.u64Number, szRange);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync AssertMsgFailed(("Invalid format type '%s'!\n", **ppszFormat));
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * Output callback.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * @returns number of bytes written.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * @param pvArg User argument.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * @param pachChars Pointer to an array of utf-8 characters.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * @param cbChars Number of bytes in the character array pointed to by pachChars.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsyncstatic DECLCALLBACK(size_t) dbgcFormatOutput(void *pvArg, const char *pachChars, size_t cbChars)
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync int rc = pDbgc->pBack->pfnWrite(pDbgc->pBack, pachChars, cbChars, NULL);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * Command helper for writing formatted text to the debug console.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @returns VBox status.
11b175175a0ed424b8e8354acda681ad0adde0f8vboxsync * @param pCmdHlp Pointer to the command callback structure.
11b175175a0ed424b8e8354acda681ad0adde0f8vboxsync * @param pcbWritten Where to store the number of bytes written.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param pszFormat The format string.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * This is using the log formatter, so it's format extensions can be used.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param args Arguments specified in the format string.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncstatic DECLCALLBACK(int) dbgcHlpPrintfV(PDBGCCMDHLP pCmdHlp, size_t *pcbWritten, const char *pszFormat, va_list args)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Do the formatting and output.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync size_t cb = RTStrFormatV(dbgcFormatOutput, pDbgc, dbgcStringFormatter, pDbgc, pszFormat, args);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Reports an error from a DBGF call.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @returns VBox status code appropriate to return from a command.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param pCmdHlp Pointer to command helpers.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param rc The VBox status code returned by a DBGF call.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param pszFormat Format string for additional messages. Can be NULL.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param ... Format arguments, optional.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncstatic DECLCALLBACK(int) dbgcHlpVBoxErrorV(PDBGCCMDHLP pCmdHlp, int rc, const char *pszFormat, va_list args)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: %Rrc: %s", rc, pszFormat ? " " : "\n");
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = pCmdHlp->pfnPrintfV(pCmdHlp, NULL, pszFormat, args);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Reports an error from a DBGF call.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @returns VBox status code appropriate to return from a command.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param pCmdHlp Pointer to command helpers.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param rc The VBox status code returned by a DBGF call.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param pszFormat Format string for additional messages. Can be NULL.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param ... Format arguments, optional.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncstatic DECLCALLBACK(int) dbgcHlpVBoxError(PDBGCCMDHLP pCmdHlp, int rc, const char *pszFormat, ...)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync int rcRet = pCmdHlp->pfnVBoxErrorV(pCmdHlp, rc, pszFormat, args);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Command helper for reading memory specified by a DBGC variable.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @returns VBox status code appropriate to return from a command.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param pCmdHlp Pointer to the command callback structure.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param pVM VM handle if GC or physical HC address.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param pvBuffer Where to store the read data.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param cbRead Number of bytes to read.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param pVarPointer DBGC variable specifying where to start reading.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param pcbRead Where to store the number of bytes actually read.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * This optional, but it's useful when read GC virtual memory where a
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * page in the requested range might not be present.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * If not specified not-present failure or end of a HC physical page
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * will cause failure.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncstatic DECLCALLBACK(int) dbgcHlpMemRead(PDBGCCMDHLP pCmdHlp, PVM pVM, void *pvBuffer, size_t cbRead, PCDBGCVAR pVarPointer, size_t *pcbRead)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Dummy check.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Convert Far addresses getting size and the correct base address.
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * Getting and checking the size is what makes this messy and slow.
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync /* Use DBGFR3AddrFromSelOff for the conversion. */
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync rc = DBGFR3AddrFromSelOff(pDbgc->pVM, pDbgc->idCpu, &Address, Var.u.GCFar.sel, Var.u.GCFar.off);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync /* don't bother with flat selectors (for now). */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = DBGFR3SelQueryInfo(pDbgc->pVM, pDbgc->idCpu, Address.Sel,
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync DBGFSELQI_FLAGS_DT_GUEST | DBGFSELQI_FLAGS_DT_ADJ_64BIT_MODE, &SelInfo);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync cb = (SelInfo.u.Raw.Gen.u1Granularity ? UINT32_C(0xffffffff) : UINT32_C(0xffff)) - Address.off;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Copy page by page.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Calc read size.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case DBGCVAR_TYPE_GC_FLAT: cb = RT_MIN(cb, PAGE_SIZE - (Var.u.GCFlat & PAGE_OFFSET_MASK)); break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case DBGCVAR_TYPE_GC_PHYS: cb = RT_MIN(cb, PAGE_SIZE - (Var.u.GCPhys & PAGE_OFFSET_MASK)); break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case DBGCVAR_TYPE_HC_FLAT: cb = RT_MIN(cb, PAGE_SIZE - ((uintptr_t)Var.u.pvHCFlat & PAGE_OFFSET_MASK)); break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case DBGCVAR_TYPE_HC_PHYS: cb = RT_MIN(cb, PAGE_SIZE - ((size_t)Var.u.HCPhys & PAGE_OFFSET_MASK)); break; /* size_t: MSC has braindead loss of data warnings! */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync default: break;
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * Perform read.
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync /** @todo protect this!!! */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Check for failure.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = DBGCCmdHlpEval(pCmdHlp, &Var, "%DV + %d", &Var, cb);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Command helper for writing memory specified by a DBGC variable.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @returns VBox status code appropriate to return from a command.
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * @param pCmdHlp Pointer to the command callback structure.
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * @param pVM VM handle if GC or physical HC address.
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * @param pvBuffer What to write.
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * @param cbWrite Number of bytes to write.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param pVarPointer DBGC variable specifying where to start reading.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param pcbWritten Where to store the number of bytes written.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * This is optional. If NULL be aware that some of the buffer
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * might have been written to the specified address.
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsyncstatic DECLCALLBACK(int) dbgcHlpMemWrite(PDBGCCMDHLP pCmdHlp, PVM pVM, const void *pvBuffer, size_t cbWrite, PCDBGCVAR pVarPointer, size_t *pcbWritten)
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * Dummy check.
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * Convert Far addresses getting size and the correct base address.
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * Getting and checking the size is what makes this messy and slow.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* Use DBGFR3AddrFromSelOff for the conversion. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = DBGFR3AddrFromSelOff(pDbgc->pVM, pDbgc->idCpu, &Address, Var.u.GCFar.sel, Var.u.GCFar.off);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* don't bother with flat selectors (for now). */
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync rc = DBGFR3SelQueryInfo(pDbgc->pVM, pDbgc->idCpu, Address.Sel,
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync DBGFSELQI_FLAGS_DT_GUEST | DBGFSELQI_FLAGS_DT_ADJ_64BIT_MODE, &SelInfo);
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync cb = (SelInfo.u.Raw.Gen.u1Granularity ? UINT32_C(0xffffffff) : UINT32_C(0xffff)) - Address.off;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* fall thru */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Copy HC memory page by page.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* convert to flat address */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* calc size. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync cbChunk -= (uintptr_t)Var.u.pvHCFlat & PAGE_OFFSET_MASK;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /** @todo protect this!!! */
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync /* advance */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync Var.u.pvHCFlat = (uint8_t *)Var.u.pvHCFlat + cbChunk;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Executes one command expression.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * (Hopefully the parser and functions are fully reentrant.)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @returns VBox status code appropriate to return from a command.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param pCmdHlp Pointer to the command callback structure.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param pszExpr The expression. Format string with the format DBGC extensions.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param ... Format arguments.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncstatic DECLCALLBACK(int) dbgcHlpExec(PDBGCCMDHLP pCmdHlp, const char *pszExpr, ...)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* Save the scratch state. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Format the expression.
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync size_t cbScratch = sizeof(pDbgc->achScratch) - (pDbgc->pszScratch - &pDbgc->achScratch[0]);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync size_t cb = RTStrPrintfExV(dbgcStringFormatter, pDbgc, pDbgc->pszScratch, cbScratch, pszExpr, args);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * Execute the command.
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * We save and restore the arg index and scratch buffer pointer.
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync int rc = dbgcEvalCommand(pDbgc, pszScratch, cb, false /* fNoExecute */);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync /* Restore the scratch state. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @copydoc DBGCCMDHLP::pfnEvalV
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncstatic DECLCALLBACK(int) dbgcHlpEvalV(PDBGCCMDHLP pCmdHlp, PDBGCVAR pResult, const char *pszExpr, va_list va)
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * Format the expression.
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync size_t cb = RTStrPrintfExV(dbgcStringFormatter, pDbgc, szExprFormatted, sizeof(szExprFormatted), pszExpr, va);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync /* ignore overflows. */
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync return dbgcEvalSub(pDbgc, &szExprFormatted[0], cb, pResult);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * @copydoc DBGCCMDHLP::pfnFailV
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsyncstatic DECLCALLBACK(int) dbgcHlpFailV(PDBGCCMDHLP pCmdHlp, PCDBGCCMD pCmd, const char *pszFormat, va_list va)
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * Do the formatting and output.
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync RTStrFormat(dbgcFormatOutput, pDbgc, dbgcStringFormatter, pDbgc, "%s: error: ", pCmd->pszCmd);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync RTStrFormatV(dbgcFormatOutput, pDbgc, dbgcStringFormatter, pDbgc, pszFormat, va);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Converts a DBGC variable to a DBGF address structure.
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * @returns VBox status code.
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * @param pCmdHlp Pointer to the command callback structure.
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsync * @param pVar The variable to convert.
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * @param pAddress The target address.
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsyncstatic DECLCALLBACK(int) dbgcHlpVarToDbgfAddr(PDBGCCMDHLP pCmdHlp, PCDBGCVAR pVar, PDBGFADDRESS pAddress)
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * Converts a DBGC variable to a number.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @returns VBox status code.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param pCmdHlp Pointer to the command callback structure.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param pVar The variable to convert.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param pu64Number Where to store the number value.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncstatic DECLCALLBACK(int) dbgcHlpVarToNumber(PDBGCCMDHLP pCmdHlp, PCDBGCVAR pVar, uint64_t *pu64Number)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VERR_PARSE_INCORRECT_ARG_TYPE; /** @todo better error code! */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Converts a DBGC variable to a boolean.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @returns VBox status code.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param pCmdHlp Pointer to the command callback structure.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param pVar The variable to convert.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param pf Where to store the boolean.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncstatic DECLCALLBACK(int) dbgcHlpVarToBool(PDBGCCMDHLP pCmdHlp, PCDBGCVAR pVar, bool *pf)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /** @todo add strcasecmp / stricmp wrappers to iprt/string.h. */
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync return VERR_PARSE_INCORRECT_ARG_TYPE; /** @todo better error code! */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @interface_method_impl{DBGCCMDHLP,pfnVarGetRange}
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncstatic DECLCALLBACK(int) dbgcHlpVarGetRange(PDBGCCMDHLP pCmdHlp, PCDBGCVAR pVar, uint64_t cbElement, uint64_t cbDefault,
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync/** @todo implement this properly, strings/symbols are not resolved now. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @interface_method_impl{DBGCCMDHLP,pfnVarConvert}
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncstatic DECLCALLBACK(int) dbgcHlpVarConvert(PDBGCCMDHLP pCmdHlp, PCDBGCVAR pInVar, DBGCVARTYPE enmToType, bool fConvSyms,
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync DBGCVAR const InVar = *pInVar; /* if pInVar == pResult */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync PCDBGCVAR pArg = &InVar; /* lazy bird, clean up later */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync DBGFR3AddrFromFlat(pDbgc->pVM, &Address, pArg->u.GCFlat),
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = DBGFR3AddrToVolatileR3Ptr(pDbgc->pVM, pDbgc->idCpu,
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync DBGFR3AddrFromFlat(pDbgc->pVM, &Address, pArg->u.GCFlat),
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync false /*fReadOnly */,
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = DBGFR3AddrToHostPhys(pDbgc->pVM, pDbgc->idCpu,
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync DBGFR3AddrFromFlat(pDbgc->pVM, &Address, pArg->u.GCFlat),
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync rc = DBGFR3AddrFromSelOff(pDbgc->pVM, pDbgc->idCpu, &Address, pArg->u.GCFar.sel, pArg->u.GCFar.off);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = DBGFR3AddrFromSelOff(pDbgc->pVM, pDbgc->idCpu, &Address, pArg->u.GCFar.sel, pArg->u.GCFar.off);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync rc = DBGFR3AddrToPhys(pDbgc->pVM, pDbgc->idCpu, &Address, &pResult->u.GCPhys);
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsync rc = DBGFR3AddrFromSelOff(pDbgc->pVM, pDbgc->idCpu, &Address, pArg->u.GCFar.sel, pArg->u.GCFar.off);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync rc = DBGFR3AddrToVolatileR3Ptr(pDbgc->pVM, pDbgc->idCpu, &Address,
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = DBGFR3AddrFromSelOff(pDbgc->pVM, pDbgc->idCpu, &Address, pArg->u.GCFar.sel, pArg->u.GCFar.off);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = DBGFR3AddrToHostPhys(pDbgc->pVM, pDbgc->idCpu, &Address, &pResult->u.GCPhys);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync //rc = MMR3PhysGCPhys2GCVirtEx(pDbgc->pVM, pResult->u.GCPhys, ..., &pResult->u.GCFlat); - yea, sure.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = DBGFR3AddrToVolatileR3Ptr(pDbgc->pVM, pDbgc->idCpu,
d3b1b01528fe21777281edf167f8deca06f86e39vboxsync DBGFR3AddrFromPhys(pDbgc->pVM, &Address, pArg->u.GCPhys),
d3b1b01528fe21777281edf167f8deca06f86e39vboxsync false /*fReadOnly */,
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync rc = DBGFR3AddrToHostPhys(pDbgc->pVM, pDbgc->idCpu,
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync DBGFR3AddrFromPhys(pDbgc->pVM, &Address, pArg->u.GCPhys),
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = PGMR3DbgR3Ptr2GCPhys(pDbgc->pVM, pArg->u.pvHCFlat, &pResult->u.GCPhys);
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync /** @todo more memory types! */
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync rc = PGMR3DbgR3Ptr2HCPhys(pDbgc->pVM, pArg->u.pvHCFlat, &pResult->u.HCPhys);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /** @todo more memory types! */
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync pResult->u.u64Number = (uintptr_t)InVar.u.pvHCFlat;
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync rc = PGMR3DbgHCPhys2GCPhys(pDbgc->pVM, pArg->u.HCPhys, &pResult->u.GCPhys);
0c80e8c5ac4249337af378ff41c60033c9fff59fvboxsync pResult->u.pvHCFlat = (void *)(uintptr_t)InVar.u.u64Number;
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync rc = dbgcSymbolGet(pDbgc, InVar.u.pszString, enmToType, pResult);
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync AssertMsgFailed(("f=%d t=%d\n", InVar.enmType, enmToType));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Info helper callback wrapper - print formatted string.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param pHlp Pointer to this structure.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param pszFormat The format string.
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync * @param ... Arguments.
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsyncstatic DECLCALLBACK(void) dbgcHlpGetDbgfOutputHlp_Printf(PCDBGFINFOHLP pHlp, const char *pszFormat, ...)
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync PDBGC pDbgc = RT_FROM_MEMBER(pHlp, DBGC, DbgfOutputHlp);
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync pDbgc->CmdHlp.pfnPrintfV(&pDbgc->CmdHlp, NULL, pszFormat, va);
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync * Info helper callback wrapper - print formatted string.
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync * @param pHlp Pointer to this structure.
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync * @param pszFormat The format string.
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync * @param args Argument list.
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsyncstatic DECLCALLBACK(void) dbgcHlpGetDbgfOutputHlp_PrintfV(PCDBGFINFOHLP pHlp, const char *pszFormat, va_list args)
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync PDBGC pDbgc = RT_FROM_MEMBER(pHlp, DBGC, DbgfOutputHlp);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync pDbgc->CmdHlp.pfnPrintfV(&pDbgc->CmdHlp, NULL, pszFormat, args);
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync * @interface_method_impl{DBGCCMDHLP,pfnGetDbgfOutputHlp}
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsyncstatic DECLCALLBACK(PCDBGFINFOHLP) dbgcHlpGetDbgfOutputHlp(PDBGCCMDHLP pCmdHlp)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* Lazy init */
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync pDbgc->DbgfOutputHlp.pfnPrintf = dbgcHlpGetDbgfOutputHlp_Printf;
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync pDbgc->DbgfOutputHlp.pfnPrintfV = dbgcHlpGetDbgfOutputHlp_PrintfV;
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * Initializes the Command Helpers for a DBGC instance.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * @param pDbgc Pointer to the DBGC instance.
ffb50166c9adb4ae583b914d405197035cf890advboxsync pDbgc->CmdHlp.pfnVarToDbgfAddr = dbgcHlpVarToDbgfAddr;