Changeset 4251 in vbox
- Timestamp:
- Aug 20, 2007 11:53:15 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Debugger/DBGConsole.cpp
r4215 r4251 461 461 static DECLCALLBACK(int) dbgcCmdShowVars(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult); 462 462 static DECLCALLBACK(int) dbgcCmdHarakiri(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult); 463 static DECLCALLBACK(int) dbgcCmdEcho(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult); 464 static DECLCALLBACK(int) dbgcCmdRunScript(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult); 463 465 464 466 static DECLCALLBACK(int) dbgcOpMinus(PDBGC pDbgc, PCDBGCVAR pArg, PDBGCVAR pResult); … … 813 815 { "dt", 0, 1, &g_aArgDumpTSS[0], ELEMENTS(g_aArgDumpTSS), NULL, 0, dbgcCmdDumpTSS, "[tss|tss:ign|addr]", "Dump the task state segment (TSS)." }, 814 816 { "dw", 0, 1, &g_aArgDumpMem[0], ELEMENTS(g_aArgDumpMem), NULL, 0, dbgcCmdDumpMem, "[addr]", "Dump memory in words." }, 817 { "echo", 1, ~0, &g_aArgMultiStr[0], ELEMENTS(g_aArgMultiStr), NULL, 0, dbgcCmdEcho, "<str1> [str2..[strN]]", "Displays the strings separated by one blank space and the last one followed by a newline." }, 815 818 { "exit", 0, 0, NULL, 0, NULL, 0, dbgcCmdQuit, "", "Exits the debugger." }, 816 819 { "format", 1, 1, &g_aArgAny[0], ELEMENTS(g_aArgAny), NULL, 0, dbgcCmdFormat, "", "Evaluates an expression and formats it." }, … … 834 837 { "rh", 0, 2, &g_aArgReg[0], ELEMENTS(g_aArgReg), NULL, 0, dbgcCmdRegHyper, "[reg [newval]]", "Show or set register(s) - hypervisor reg set." }, 835 838 { "rt", 0, 0, NULL, 0, NULL, 0, dbgcCmdRegTerse, "", "Toggles terse / verbose register info." }, 839 { "runscript", 1, 1, &g_aArgFilename[0], ELEMENTS(g_aArgFilename), NULL, 0, dbgcCmdRunScript, "<filename>", "Runs the command listed in the script. Lines starting with '#' (after removing blanks) are comment. blank lines are ignored. Stops on failure." }, 836 840 { "s", 0, 1, &g_aArgSource[0], ELEMENTS(g_aArgSource), NULL, 0, dbgcCmdSource, "[addr]", "Source." }, 837 841 { "set", 2, 2, &g_aArgSet[0], ELEMENTS(g_aArgSet), NULL, 0, dbgcCmdSet, "<var> <value>", "Sets a global variable." }, … … 3564 3568 return rc4; 3565 3569 } 3570 3571 3572 /** 3573 * The 'echo' command. 3574 * 3575 * @returns VBox status. 3576 * @param pCmd Pointer to the command descriptor (as registered). 3577 * @param pCmdHlp Pointer to command helper functions. 3578 * @param pVM Pointer to the current VM (if any). 3579 * @param paArgs Pointer to (readonly) array of arguments. 3580 * @param cArgs Number of arguments in the array. 3581 */ 3582 static DECLCALLBACK(int) dbgcCmdEcho(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult) 3583 { 3584 /* 3585 * Loop thru the arguments and print them with one space between. 3586 */ 3587 int rc = 0; 3588 for (unsigned i = 0; i < cArgs; i++) 3589 { 3590 if (paArgs[i].enmType == DBGCVAR_TYPE_STRING) 3591 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, i ? " %s" : "%s", paArgs[i].u.pszString); 3592 else 3593 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, i ? " <parser error>" : "<parser error>"); 3594 if (VBOX_FAILURE(rc)) 3595 return rc; 3596 } 3597 NOREF(pCmd); NOREF(pResult); NOREF(pVM); 3598 return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "\n"); 3599 } 3600 3601 3602 /** 3603 * The 'echo' command. 3604 * 3605 * @returns VBox status. 3606 * @param pCmd Pointer to the command descriptor (as registered). 3607 * @param pCmdHlp Pointer to command helper functions. 3608 * @param pVM Pointer to the current VM (if any). 3609 * @param paArgs Pointer to (readonly) array of arguments. 3610 * @param cArgs Number of arguments in the array. 3611 */ 3612 static DECLCALLBACK(int) dbgcCmdRunScript(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult) 3613 { 3614 /* check that the parser did what it's supposed to do. */ 3615 if ( cArgs != 1 3616 || paArgs[0].enmType != DBGCVAR_TYPE_STRING) 3617 return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "parser error\n"); 3618 3619 /* 3620 * Try open the script. 3621 */ 3622 const char *pszFilename = paArgs[0].u.pszString; 3623 FILE *pFile = fopen(pszFilename, "r"); 3624 if (!pFile) 3625 return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "Failed to open '%s'.\n", pszFilename); 3626 3627 /* 3628 * Execute it line by line. 3629 */ 3630 int rc = 0; 3631 unsigned iLine = 0; 3632 char szLine[8192]; 3633 while (fgets(szLine, sizeof(szLine), pFile)) 3634 { 3635 /* check that the line isn't too long. */ 3636 char *pszEnd = strchr(szLine, '\0'); 3637 if (pszEnd == &szLine[sizeof(szLine) - 1]) 3638 { 3639 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "runscript error: Line #%u is too long\n", iLine); 3640 break; 3641 } 3642 iLine++; 3643 3644 /* strip leading blanks and check for comment / blank line. */ 3645 char *psz = RTStrStripL(szLine); 3646 if ( *psz == '\0' 3647 || *psz == '\n' 3648 || *psz == '#') 3649 continue; 3650 3651 /* strip trailing blanks and check for empty line (\r case). */ 3652 while ( pszEnd > psz 3653 && isspace(pszEnd[-1])) /* isspace includes \n and \r normally. */ 3654 *++pszEnd = '\0'; 3655 3656 /** @todo check for Control-C / Cancel at this point... */ 3657 3658 /* 3659 * Execute the command. 3660 * 3661 * This is a bit wasteful with scratch space btw., can fix it later. 3662 * The whole return code crap should be fixed too, so that it's possible 3663 * to know whether a command succeeded (VBOX_SUCCESS()) or failed, and 3664 * more importantly why it failed. 3665 */ 3666 rc = pCmdHlp->pfnExec(pCmdHlp, "%s", szLine); 3667 if (VBOX_FAILURE(rc)) 3668 { 3669 if (rc == VERR_BUFFER_OVERFLOW) 3670 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "runscript error: Line #%u is too long (exec overflowed)\n", iLine); 3671 break; 3672 } 3673 if (rc == VWRN_DBGC_CMD_PENDING) 3674 { 3675 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "runscript error: VWRN_DBGC_CMD_PENDING on line #%u, script terminated\n", iLine); 3676 break; 3677 } 3678 } 3679 3680 fclose(pFile); 3681 3682 NOREF(pCmd); NOREF(pResult); NOREF(pVM); 3683 return rc; 3684 } 3685 3566 3686 3567 3687
Note:
See TracChangeset
for help on using the changeset viewer.