VirtualBox

Ignore:
Timestamp:
Jan 24, 2011 5:35:59 PM (14 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
69620
Message:

Debugger console: more cleanup.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Debugger/DBGCCmdHlp.cpp

    r35673 r35694  
    3737
    3838/**
    39  * Command helper for writing text to the debug console.
    40  *
    41  * @returns VBox status.
    42  * @param   pCmdHlp     Pointer to the command callback structure.
    43  * @param   pvBuf       What to write.
    44  * @param   cbBuf       Number of bytes to write.
    45  * @param   pcbWritten  Where to store the number of bytes actually written.
    46  *                      If NULL the entire buffer must be successfully written.
    47  */
    48 static DECLCALLBACK(int) dbgcHlpWrite(PDBGCCMDHLP pCmdHlp, const void *pvBuf, size_t cbBuf, size_t *pcbWritten)
    49 {
    50     PDBGC   pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
    51     return pDbgc->pBack->pfnWrite(pDbgc->pBack, pvBuf, cbBuf, pcbWritten);
    52 }
    53 
    54 
    55 /**
    56  * Command helper for writing formatted text to the debug console.
    57  *
    58  * @returns VBox status.
    59  * @param   pCmdHlp     Pointer to the command callback structure.
    60  * @param   pcb         Where to store the number of bytes written.
    61  * @param   pszFormat   The format string.
    62  *                      This is using the log formatter, so it's format extensions can be used.
    63  * @param   ...         Arguments specified in the format string.
     39 * @interface_method_impl{DBGCCMDHLP,pfnPrintf}
    6440 */
    6541static DECLCALLBACK(int) dbgcHlpPrintf(PDBGCCMDHLP pCmdHlp, size_t *pcbWritten, const char *pszFormat, ...)
     
    7753
    7854/**
    79  * Callback to format non-standard format specifiers.
     55 * Callback to format non-standard format specifiers, employed by dbgcPrintfV
     56 * and others.
    8057 *
    8158 * @returns The number of bytes formatted.
     
    190167
    191168/**
    192  * Output callback.
     169 * Output callback employed by dbgcHlpPrintfV.
    193170 *
    194171 * @returns number of bytes written.
     
    199176static DECLCALLBACK(size_t) dbgcFormatOutput(void *pvArg, const char *pachChars, size_t cbChars)
    200177{
    201     PDBGC   pDbgc = (PDBGC)pvArg;
     178    PDBGC pDbgc = (PDBGC)pvArg;
    202179    if (cbChars)
    203180    {
    204181        int rc = pDbgc->pBack->pfnWrite(pDbgc->pBack, pachChars, cbChars, NULL);
    205         if (RT_FAILURE(rc))
     182        if (RT_SUCCESS(rc))
     183            pDbgc->chLastOutput = pachChars[cbChars - 1];
     184        else
    206185        {
    207186            pDbgc->rcOutput = rc;
     
    216195
    217196/**
    218  * Command helper for writing formatted text to the debug console.
    219  *
    220  * @returns VBox status.
    221  * @param   pCmdHlp     Pointer to the command callback structure.
    222  * @param   pcbWritten  Where to store the number of bytes written.
    223  * @param   pszFormat   The format string.
    224  *                      This is using the log formatter, so it's format extensions can be used.
    225  * @param   args        Arguments specified in the format string.
     197 * @interface_method_impl{DBGCCMDHLP,pfnPrintfV}
    226198 */
    227199static DECLCALLBACK(int) dbgcHlpPrintfV(PDBGCCMDHLP pCmdHlp, size_t *pcbWritten, const char *pszFormat, va_list args)
     
    243215
    244216/**
    245  * Reports an error from a DBGF call.
    246  *
    247  * @returns VBox status code appropriate to return from a command.
    248  * @param   pCmdHlp     Pointer to command helpers.
    249  * @param   rc          The VBox status code returned by a DBGF call.
    250  * @param   pszFormat   Format string for additional messages. Can be NULL.
    251  * @param   ...         Format arguments, optional.
     217 * @interface_method_impl{DBGCCMDHLP,pfnVBoxErrorV}
    252218 */
    253219static DECLCALLBACK(int) dbgcHlpVBoxErrorV(PDBGCCMDHLP pCmdHlp, int rc, const char *pszFormat, va_list args)
     
    271237
    272238/**
    273  * Reports an error from a DBGF call.
    274  *
    275  * @returns VBox status code appropriate to return from a command.
    276  * @param   pCmdHlp     Pointer to command helpers.
    277  * @param   rc          The VBox status code returned by a DBGF call.
    278  * @param   pszFormat   Format string for additional messages. Can be NULL.
    279  * @param   ...         Format arguments, optional.
     239 * @interface_method_impl{DBGCCMDHLP,pfnVBoxError}
    280240 */
    281241static DECLCALLBACK(int) dbgcHlpVBoxError(PDBGCCMDHLP pCmdHlp, int rc, const char *pszFormat, ...)
     
    290250
    291251/**
    292  * Command helper for reading memory specified by a DBGC variable.
    293  *
    294  * @returns VBox status code appropriate to return from a command.
    295  * @param   pCmdHlp     Pointer to the command callback structure.
    296  * @param   pVM         VM handle if GC or physical HC address.
    297  * @param   pvBuffer    Where to store the read data.
    298  * @param   cbRead      Number of bytes to read.
    299  * @param   pVarPointer DBGC variable specifying where to start reading.
    300  * @param   pcbRead     Where to store the number of bytes actually read.
    301  *                      This optional, but it's useful when read GC virtual memory where a
    302  *                      page in the requested range might not be present.
    303  *                      If not specified not-present failure or end of a HC physical page
    304  *                      will cause failure.
     252 * @interface_method_impl{DBGCCMDHLP,pfnMemRead}
    305253 */
    306254static DECLCALLBACK(int) dbgcHlpMemRead(PDBGCCMDHLP pCmdHlp, PVM pVM, void *pvBuffer, size_t cbRead, PCDBGCVAR pVarPointer, size_t *pcbRead)
     
    472420}
    473421
    474 /**
    475  * Command helper for writing memory specified by a DBGC variable.
    476  *
    477  * @returns VBox status code appropriate to return from a command.
    478  * @param   pCmdHlp     Pointer to the command callback structure.
    479  * @param   pVM         VM handle if GC or physical HC address.
    480  * @param   pvBuffer    What to write.
    481  * @param   cbWrite     Number of bytes to write.
    482  * @param   pVarPointer DBGC variable specifying where to start reading.
    483  * @param   pcbWritten  Where to store the number of bytes written.
    484  *                      This is optional. If NULL be aware that some of the buffer
    485  *                      might have been written to the specified address.
     422
     423/**
     424 * @interface_method_impl{DBGCCMDHLP,pfnMemWrite}
    486425 */
    487426static DECLCALLBACK(int) dbgcHlpMemWrite(PDBGCCMDHLP pCmdHlp, PVM pVM, const void *pvBuffer, size_t cbWrite, PCDBGCVAR pVarPointer, size_t *pcbWritten)
     
    618557
    619558/**
    620  * Executes one command expression.
    621  * (Hopefully the parser and functions are fully reentrant.)
    622  *
    623  * @returns VBox status code appropriate to return from a command.
    624  * @param   pCmdHlp     Pointer to the command callback structure.
    625  * @param   pszExpr     The expression. Format string with the format DBGC extensions.
    626  * @param   ...         Format arguments.
     559 * @interface_method_impl{DBGCCMDHLP,pfnHlpExec}
    627560 */
    628561static DECLCALLBACK(int) dbgcHlpExec(PDBGCCMDHLP pCmdHlp, const char *pszExpr, ...)
     
    694627    if (RT_FAILURE(pDbgc->rcOutput))
    695628        return pDbgc->rcOutput;
     629    if (pDbgc->chLastOutput != '\n')
     630        dbgcFormatOutput(pDbgc, "\n", 1);
     631    return VERR_DBGC_COMMAND_FAILED;
     632}
     633
     634
     635/**
     636 * @copydoc DBGCCMDHLP::pfnFailV
     637 */
     638static DECLCALLBACK(int) dbgcHlpFailRcV(PDBGCCMDHLP pCmdHlp, PCDBGCCMD pCmd, int rc, const char *pszFormat, va_list va)
     639{
     640    PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
     641
     642    /*
     643     * Do the formatting and output.
     644     */
     645    pDbgc->rcOutput = VINF_SUCCESS;
     646    RTStrFormat(dbgcFormatOutput, pDbgc, dbgcStringFormatter, pDbgc, "%s: error: ", pCmd->pszCmd);
     647    if (RT_FAILURE(pDbgc->rcOutput))
     648        return pDbgc->rcOutput;
     649    RTStrFormatV(dbgcFormatOutput, pDbgc, dbgcStringFormatter, pDbgc, pszFormat, va);
     650    if (RT_FAILURE(pDbgc->rcOutput))
     651        return pDbgc->rcOutput;
     652    RTStrFormat(dbgcFormatOutput, pDbgc, dbgcStringFormatter, pDbgc, ": %Rrc\n", rc);
     653    if (RT_FAILURE(pDbgc->rcOutput))
     654        return pDbgc->rcOutput;
     655
    696656    return VERR_DBGC_COMMAND_FAILED;
    697657}
     
    778738
    779739/**
    780  * Converts a DBGC variable to a number.
    781  *
    782  * @returns VBox status code.
    783  * @param   pCmdHlp     Pointer to the command callback structure.
    784  * @param   pVar        The variable to convert.
    785  * @param   pu64Number  Where to store the number value.
     740 * @interface_method_impl{DBGCCMDHLP,pfnVarToNumber}
    786741 */
    787742static DECLCALLBACK(int) dbgcHlpVarToNumber(PDBGCCMDHLP pCmdHlp, PCDBGCVAR pVar, uint64_t *pu64Number)
     
    823778
    824779/**
    825  * Converts a DBGC variable to a boolean.
    826  *
    827  * @returns VBox status code.
    828  * @param   pCmdHlp     Pointer to the command callback structure.
    829  * @param   pVar        The variable to convert.
    830  * @param   pf          Where to store the boolean.
     780 * @interface_method_impl{DBGCCMDHLP,pfnVarToBool}
    831781 */
    832782static DECLCALLBACK(int) dbgcHlpVarToBool(PDBGCCMDHLP pCmdHlp, PCDBGCVAR pVar, bool *pf)
     
    12551205
    12561206/**
    1257  * Info helper callback wrapper - print formatted string.
    1258  *
    1259  * @param   pHlp        Pointer to this structure.
    1260  * @param   pszFormat   The format string.
    1261  * @param   ...         Arguments.
     1207 * @interface_method_impl{DBGFINFOHLP,pfnPrintf}
    12621208 */
    12631209static DECLCALLBACK(void) dbgcHlpGetDbgfOutputHlp_Printf(PCDBGFINFOHLP pHlp, const char *pszFormat, ...)
     
    12721218
    12731219/**
    1274  * Info helper callback wrapper - print formatted string.
    1275  *
    1276  * @param   pHlp        Pointer to this structure.
    1277  * @param   pszFormat   The format string.
    1278  * @param   args        Argument list.
     1220 * @interface_method_impl{DBGFINFOHLP,pfnPrintfV}
    12791221 */
    12801222static DECLCALLBACK(void) dbgcHlpGetDbgfOutputHlp_PrintfV(PCDBGFINFOHLP pHlp, const char *pszFormat, va_list args)
     
    13101252void dbgcInitCmdHlp(PDBGC pDbgc)
    13111253{
    1312     pDbgc->CmdHlp.pfnWrite              = dbgcHlpWrite;
     1254    pDbgc->CmdHlp.u32Magic              = DBGCCMDHLP_MAGIC;
    13131255    pDbgc->CmdHlp.pfnPrintfV            = dbgcHlpPrintfV;
    13141256    pDbgc->CmdHlp.pfnPrintf             = dbgcHlpPrintf;
     
    13201262    pDbgc->CmdHlp.pfnExec               = dbgcHlpExec;
    13211263    pDbgc->CmdHlp.pfnFailV              = dbgcHlpFailV;
     1264    pDbgc->CmdHlp.pfnFailRcV            = dbgcHlpFailRcV;
    13221265    pDbgc->CmdHlp.pfnVarToDbgfAddr      = dbgcHlpVarToDbgfAddr;
    13231266    pDbgc->CmdHlp.pfnVarFromDbgfAddr    = dbgcHlpVarFromDbgfAddr;
     
    13271270    pDbgc->CmdHlp.pfnVarConvert         = dbgcHlpVarConvert;
    13281271    pDbgc->CmdHlp.pfnGetDbgfOutputHlp   = dbgcHlpGetDbgfOutputHlp;
    1329 }
    1330 
     1272    pDbgc->CmdHlp.u32EndMarker          = DBGCCMDHLP_MAGIC;
     1273}
     1274
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette