VirtualBox

Changeset 5731

Show
Ignore:
Timestamp:
11/13/07 23:42:00 (1 year ago)
Author:
vboxsync
Message:

Implemented some search commands in the debugger.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/include/VBox/dbg.h

    r5605 r5731  
    6666    DBGCVAR_CAT_STRING, 
    6767    /** Symbol. */ 
    68     DBGCVAR_CAT_SYMBOL 
     68    DBGCVAR_CAT_SYMBOL, 
     69    /** Option. */ 
     70    DBGCVAR_CAT_OPTION, 
     71    /** Option + string. */ 
     72    DBGCVAR_CAT_OPTION_STRING, 
     73    /** Option + number. */ 
     74    DBGCVAR_CAT_OPTION_NUMBER 
    6975} DBGCVARCAT; 
    7076 
     
    203209 
    204210 
    205 /**  
     211/** 
    206212 * Macro for initializing a DBGC variable with defaults. 
    207213 * The result is an unknown variable type without any range. 
  • trunk/include/VBox/dbgf.h

    r5667 r5731  
    15161516#endif 
    15171517 
     1518 
     1519/** 
     1520 * Scan guest memory for an exact byte string. 
     1521 * 
     1522 * @returns VBox status codes: 
     1523 * @retval  VINF_SUCCESS and *pGCPtrHit on success. 
     1524 * @retval  VERR_DBGF_MEM_NOT_FOUND if not found. 
     1525 * @retval  VERR_INVALID_POINTER if any of the pointer arguments are invalid. 
     1526 * @retval  VERR_INVALID_ARGUMENT if any other arguments are invalid. 
     1527 * 
     1528 * @param   pVM         The VM handle. 
     1529 * @param   pAddress    Where to store the mixed address. 
     1530 * @param   cbRange     The number of bytes to scan. 
     1531 * @param   pabNeedle   What to search for - exact search. 
     1532 * @param   cbNeedle    Size of the search byte string. 
     1533 * @param   pHitAddress Where to put the address of the first hit. 
     1534 * 
     1535 * @thread  Any thread. 
     1536 */ 
     1537DBGFR3DECL(int) DBGFR3MemScan(PVM pVM, PCDBGFADDRESS pAddress, RTGCUINTPTR cbRange, const uint8_t *pabNeedle, size_t cbNeedle, PDBGFADDRESS pHitAddress); 
     1538 
    15181539/** @} */ 
    15191540 
  • trunk/src/VBox/Debugger/DBGCCmdHlp.cpp

    r5686 r5731  
    270270        default: 
    271271            rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: %Vrc: %s", rc, pszFormat ? " " : "\n"); 
    272             if (VBOX_SUCCESS(rc) && pszFormat) 
     272            if (RT_SUCCESS(rc) && pszFormat) 
    273273                rc = pCmdHlp->pfnPrintfV(pCmdHlp, NULL, pszFormat, args); 
     274            if (RT_SUCCESS(rc)) 
     275                rc = VERR_DBGC_COMMAND_FAILED; 
    274276            break; 
    275277    } 
  • trunk/src/VBox/Debugger/DBGCCmdWorkers.cpp

    r5686 r5731  
    5353 
    5454/** @todo move me!*/ 
     55void dbgcVarInit(PDBGCVAR pVar) 
     56{ 
     57    if (pVar) 
     58    { 
     59        memset(pVar, 0, sizeof(*pVar)); 
     60        AssertCompile(DBGCVAR_TYPE_UNKNOWN == 0); 
     61        AssertCompile(DBGCVAR_RANGE_NONE == 0); 
     62    } 
     63} 
     64 
     65 
     66/** @todo move me!*/ 
    5567void dbgcVarSetGCFlat(PDBGCVAR pVar, RTGCPTR GCFlat) 
    5668{ 
     
    5870    { 
    5971        pVar->enmType  = DBGCVAR_TYPE_GC_FLAT; 
     72        memset(&pVar->u, 0, sizeof(pVar->u)); 
    6073        pVar->u.GCFlat = GCFlat; 
    6174        pVar->enmRangeType = DBGCVAR_RANGE_NONE; 
     
    7184    { 
    7285        pVar->enmType  = DBGCVAR_TYPE_GC_FLAT; 
     86        memset(&pVar->u, 0, sizeof(pVar->u)); 
    7387        pVar->u.GCFlat = GCFlat; 
    7488        pVar->enmRangeType = DBGCVAR_RANGE_BYTES; 
    7589        pVar->u64Range  = cb; 
     90    } 
     91} 
     92 
     93 
     94/** @todo move me!*/ 
     95void dbgcVarSetU64(PDBGCVAR pVar, uint64_t u64) 
     96{ 
     97    if (pVar) 
     98    { 
     99        pVar->enmType  = DBGCVAR_TYPE_NUMBER; 
     100        memset(&pVar->u, 0, sizeof(pVar->u)); 
     101        pVar->u.u64Number = u64; 
     102        pVar->enmRangeType = DBGCVAR_RANGE_NONE; 
     103        pVar->u64Range  = 0; 
    76104    } 
    77105} 
     
    95123} 
    96124 
     125/** @todo move me!*/ 
     126void dbgcVarSetDbgfAddr(PDBGCVAR pVar, PCDBGFADDRESS pAddress) 
     127{ 
     128    if (pVar) 
     129    { 
     130        memset(&pVar->u, 0, sizeof(pVar->u)); 
     131 
     132        Assert(!pAddress || DBGFADDRESS_IS_VALID(pAddress)); 
     133        if (pAddress && DBGFADDRESS_IS_VALID(pAddress)) 
     134        { 
     135            switch (pAddress->fFlags & DBGFADDRESS_FLAGS_TYPE_MASK) 
     136            { 
     137                case DBGFADDRESS_FLAGS_FAR16: 
     138                case DBGFADDRESS_FLAGS_FAR32: 
     139                case DBGFADDRESS_FLAGS_FAR64: 
     140                    pVar->enmType = DBGCVAR_TYPE_GC_FAR; 
     141                    pVar->u.GCFar.off = pAddress->off; 
     142                    pVar->u.GCFar.sel = pAddress->Sel; 
     143                    break; 
     144 
     145                case DBGFADDRESS_FLAGS_FLAT: 
     146                    pVar->enmType = DBGCVAR_TYPE_GC_FLAT; 
     147                    pVar->u.GCFlat = pAddress->FlatPtr; 
     148                    break; 
     149 
     150                case DBGFADDRESS_FLAGS_PHYS: 
     151                    pVar->enmType = DBGCVAR_TYPE_GC_PHYS; 
     152                    pVar->u.GCPhys = pAddress->FlatPtr; 
     153                    break; 
     154 
     155                default: 
     156                    AssertFailed(); 
     157                    pVar->enmType = DBGCVAR_TYPE_UNKNOWN; 
     158                    break; 
     159            } 
     160        } 
     161        else 
     162            pVar->enmType = DBGCVAR_TYPE_UNKNOWN; 
     163        pVar->enmRangeType = DBGCVAR_RANGE_NONE; 
     164        pVar->u64Range = 0; 
     165    } 
     166} 
     167 
    97168 
    98169/** @todo move me!*/ 
     
    141212        case DBGCVAR_TYPE_GC_FAR: 
    142213            return DBGFR3AddrFromSelOff(pDbgc->pVM, pAddress, pVar->u.GCFar.sel, pVar->u.GCFar.sel); 
     214 
     215        case DBGCVAR_TYPE_GC_PHYS: 
     216            DBGFR3AddrFromPhys(pDbgc->pVM, pAddress, pVar->u.GCPhys); 
     217            return VINF_SUCCESS; 
    143218 
    144219        case DBGCVAR_TYPE_STRING: 
     
    152227        } 
    153228 
    154         case DBGCVAR_TYPE_GC_PHYS: 
    155229        case DBGCVAR_TYPE_HC_FLAT: 
    156230        case DBGCVAR_TYPE_HC_FAR: 
  • trunk/src/VBox/Debugger/DBGCEmulateCodeView.cpp

    r5671 r5731  
    6868static DECLCALLBACK(int) dbgcCmdRegTerse(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult); 
    6969static DECLCALLBACK(int) dbgcCmdSearchMem(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult); 
     70static DECLCALLBACK(int) dbgcCmdSearchMemType(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult); 
    7071static DECLCALLBACK(int) dbgcCmdStack(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult); 
    7172static DECLCALLBACK(int) dbgcCmdTrace(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult); 
     
    229230/** 's' arguments. */ 
    230231static const DBGCVARDESC    g_aArgSearchMem[] = 
     232{ 
     233    /* cTimesMin,   cTimesMax,  enmCategory,            fFlags,                         pszName,        pszDescription */ 
     234    {  0,           1,          DBGCVAR_CAT_OPTION,     0,                              "-b",           "Byte string." }, 
     235    {  0,           1,          DBGCVAR_CAT_OPTION,     0,                              "-w",           "Word string." }, 
     236    {  0,           1,          DBGCVAR_CAT_OPTION,     0,                              "-d",           "DWord string." }, 
     237    {  0,           1,          DBGCVAR_CAT_OPTION,     0,                              "-q",           "QWord string." }, 
     238    {  0,           1,          DBGCVAR_CAT_OPTION,     0,                              "-a",           "ASCII string." }, 
     239    {  0,           1,          DBGCVAR_CAT_OPTION,     0,                              "-u",           "Unicode string." }, 
     240    {  0,           1,          DBGCVAR_CAT_OPTION_NUMBER, 0,                           "-n <Hits>",    "Maximum number of hits." }, 
     241    {  0,           1,          DBGCVAR_CAT_GC_POINTER, 0,                              "range",        "Register to show or set." }, 
     242    {  0,           ~0,         DBGCVAR_CAT_ANY,        0,                              "pattern",      "Pattern to search for." }, 
     243}; 
     244 
     245 
     246/** 's?' arguments. */ 
     247static const DBGCVARDESC    g_aArgSearchMemType[] = 
    231248{ 
    232249    /* cTimesMin,   cTimesMax,  enmCategory,            fFlags,                         pszName,        pszDescription */ 
     
    294311    { "rh",         0,        2,        &g_aArgReg[0],      RT_ELEMENTS(g_aArgReg),        NULL,               0,       dbgcCmdRegHyper,    "[reg [newval]]",       "Show or set register(s) - hypervisor reg set." }, 
    295312    { "rt",         0,        0,        NULL,               0,                             NULL,               0,       dbgcCmdRegTerse,    "",                     "Toggles terse / verbose register info." }, 
    296     //{ "s",          2,       ~0,        &g_aArgSearchMem[0],RT_ELEMENTS(g_aArgSearchMem),  NULL,               0,       dbgcCmdSearchMem,   "<range> <pattern>",    "Continue last search." }, 
    297     { "sa",         2,       ~0,        &g_aArgSearchMem[0],RT_ELEMENTS(g_aArgSearchMem),  NULL,               0,       dbgcCmdSearchMem,   "<range> <pattern>",    "Search memory for an ascii string." }, 
    298     { "sb",         2,       ~0,        &g_aArgSearchMem[0],RT_ELEMENTS(g_aArgSearchMem),  NULL,               0,       dbgcCmdSearchMem,   "<range> <pattern>",    "Search memory for one or more bytes." }, 
    299     { "sd",         2,       ~0,        &g_aArgSearchMem[0],RT_ELEMENTS(g_aArgSearchMem),  NULL,               0,       dbgcCmdSearchMem,   "<range> <pattern>",    "Search memory for one or more double words." }, 
    300     { "sq",         2,       ~0,        &g_aArgSearchMem[0],RT_ELEMENTS(g_aArgSearchMem),  NULL,               0,       dbgcCmdSearchMem,   "<range> <pattern>",    "Search memory for one or more quad words." }, 
    301     { "su",         2,       ~0,        &g_aArgSearchMem[0],RT_ELEMENTS(g_aArgSearchMem),  NULL,               0,       dbgcCmdSearchMem,   "<range> <pattern>",    "Search memory for an unicode string." }, 
    302     { "sw",         2,       ~0,        &g_aArgSearchMem[0],RT_ELEMENTS(g_aArgSearchMem),  NULL,               0,       dbgcCmdSearchMem,   "<range> <pattern>",    "Search memory for one or more words." }, 
     313    { "s",          0,       ~0,        &g_aArgSearchMem[0], RT_ELEMENTS(g_aArgSearchMem),  NULL,              0,       dbgcCmdSearchMem,   "[options] <range> <pattern>",  "Continue last search." }, 
     314    { "sa",         2,       ~0,        &g_aArgSearchMemType[0], RT_ELEMENTS(g_aArgSearchMemType),  NULL,      0,       dbgcCmdSearchMemType,   "<range> <pattern>",    "Search memory for an ascii string." }, 
     315    { "sb",         2,       ~0,        &g_aArgSearchMemType[0], RT_ELEMENTS(g_aArgSearchMemType),  NULL,      0,       dbgcCmdSearchMemType,   "<range> <pattern>",    "Search memory for one or more bytes." }, 
     316    { "sd",         2,       ~0,        &g_aArgSearchMemType[0], RT_ELEMENTS(g_aArgSearchMemType),  NULL,      0,       dbgcCmdSearchMemType,   "<range> <pattern>",    "Search memory for one or more double words." }, 
     317    { "sq",         2,       ~0,        &g_aArgSearchMemType[0], RT_ELEMENTS(g_aArgSearchMemType),  NULL,      0,       dbgcCmdSearchMemType,   "<range> <pattern>",    "Search memory for one or more quad words." }, 
     318    { "su",         2,       ~0,        &g_aArgSearchMemType[0], RT_ELEMENTS(g_aArgSearchMemType),  NULL,      0,       dbgcCmdSearchMemType,   "<range> <pattern>",    "Search memory for an unicode string." }, 
     319    { "sw",         2,       ~0,        &g_aArgSearchMemType[0], RT_ELEMENTS(g_aArgSearchMemType),  NULL,      0,       dbgcCmdSearchMemType,   "<range> <pattern>",    "Search memory for one or more words." }, 
    303320    { "t",          0,        0,        NULL,               0,                             NULL,               0,       dbgcCmdTrace,       "",                     "Instruction trace (step into)." }, 
    304321    { "u",          0,        1,        &g_aArgUnassemble[0],RT_ELEMENTS(g_aArgUnassemble),NULL,               0,       dbgcCmdUnassemble,  "[addr]",               "Unassemble." }, 
     
    28092826 
    28102827/** 
     2828 * Converts one or more variables into a byte buffer for a 
     2829 * given unit size. 
     2830 * 
     2831 * @returns VBox status codes: 
     2832 * @retval  VERR_TOO_MUCH_DATA if the buffer is too small, bitched. 
     2833 * @retval  VERR_INTERNAL_ERROR on bad variable type, bitched. 
     2834 * @retval  VINF_SUCCESS on success. 
     2835 * 
     2836 * @param   pvBuf   The buffer to convert into. 
     2837 * @param   pcbBuf  The buffer size on input. The size of the result on output. 
     2838 * @param   cbUnit  The unit size to apply when converting. 
     2839 * @param   paVars  The array of variables to convert. 
     2840 * @param   cVars   The number of variables. 
     2841 */ 
     2842int dbgcVarsToBytes(PDBGCCMDHLP pCmdHlp, void *pvBuf, uint32_t *pcbBuf, size_t cbUnit, PCDBGCVAR paVars, unsigned cVars) 
     2843{ 
     2844    union 
     2845    { 
     2846        uint8_t *pu8; 
     2847        uint16_t *pu16; 
     2848        uint32_t *pu32; 
     2849        uint64_t *pu64; 
     2850    } u, uEnd; 
     2851    u.pu8 = (uint8_t *)pvBuf; 
     2852    uEnd.pu8 = u.pu8 + *pcbBuf; 
     2853 
     2854    unsigned i; 
     2855    for (i = 0; i < cVars && u.pu8 < uEnd.pu8; i++) 
     2856    { 
     2857        switch (paVars[i].enmType) 
     2858        { 
     2859            case DBGCVAR_TYPE_GC_FAR: 
     2860            case DBGCVAR_TYPE_HC_FAR: 
     2861            case DBGCVAR_TYPE_GC_FLAT: 
     2862            case DBGCVAR_TYPE_GC_PHYS: 
     2863            case DBGCVAR_TYPE_HC_FLAT: 
     2864            case DBGCVAR_TYPE_HC_PHYS: 
     2865            case DBGCVAR_TYPE_NUMBER: 
     2866            { 
     2867                uint64_t u64 = paVars[i].u.u64Number; 
     2868                switch (cbUnit) 
     2869                { 
     2870                    case 1: 
     2871                        do 
     2872                        { 
     2873                            *u.pu8++ = u64; 
     2874                            u64 >>= 8; 
     2875                        } while (u64); 
     2876                        break; 
     2877                    case 2: 
     2878                        do 
     2879                        { 
     2880                            *u.pu16++ = u64; 
     2881                            u64 >>= 16; 
     2882                        } while (u64); 
     2883                        break; 
     2884                    case 4: 
     2885                        *u.pu32++ = u64; 
     2886                        u64 >>= 32; 
     2887                        if (u64) 
     2888                            *u.pu32++ = u64; 
     2889                        break; 
     2890                    case 8: 
     2891                        *u.pu64++ = u64; 
     2892                        break; 
     2893                } 
     2894                break; 
     2895            } 
     2896 
     2897            case DBGCVAR_TYPE_STRING: 
     2898            case DBGCVAR_TYPE_SYMBOL: 
     2899            { 
     2900                const char *psz = paVars[i].u.pszString; 
     2901                size_t cbString = strlen(psz); 
     2902                if (cbString > (uintptr_t)(uEnd.pu8 - u.pu8)) 
     2903                    cbString = uEnd.pu8 - u.pu8; 
     2904 
     2905                size_t cbCopy = cbString & ~(cbUnit - 1); 
     2906                memcpy(u.pu8, psz, cbCopy); 
     2907                u.pu8 += cbCopy; 
     2908                psz += cbCopy; 
     2909 
     2910                size_t cbReminder = cbString & (cbUnit - 1); 
     2911                if (cbReminder) 
     2912                { 
     2913                    memcpy(u.pu8, psz, cbString & (cbUnit - 1)); 
     2914                    memset(u.pu8 + cbReminder, 0, cbUnit - cbReminder); 
     2915                    u.pu8 += cbUnit; 
     2916                } 
     2917                break; 
     2918            } 
     2919 
     2920            default: 
     2921                *pcbBuf = u.pu8 - (uint8_t *)pvBuf; 
     2922                pCmdHlp->pfnVBoxError(pCmdHlp, VERR_INTERNAL_ERROR, 
     2923                                      "i=%d enmType=%d\n", i, paVars[i].enmType); 
     2924                return VERR_INTERNAL_ERROR; 
     2925        } 
     2926    } 
     2927    *pcbBuf = u.pu8 - (uint8_t *)pvBuf; 
     2928    if (i != cVars) 
     2929    { 
     2930        pCmdHlp->pfnVBoxError(pCmdHlp, VERR_TOO_MUCH_DATA, "Max %d bytes.\n", uEnd.pu8 - (uint8_t *)pvBuf); 
     2931        return VERR_TOO_MUCH_DATA; 
     2932    } 
     2933    return VINF_SUCCESS; 
     2934} 
     2935 
     2936 
     2937/** 
     2938 * Executes the search. 
     2939 * 
     2940 * @returns VBox status code. 
     2941 * @param   pCmdHlp     The command helpers. 
     2942 * @param   pVM         The VM handle. 
     2943 * @param   pAddress    The address to start searching from. (undefined on output) 
     2944 * @param   cbRange     The address range to search. Must not wrap. 
     2945 * @param   pabBytes    The byte pattern to search for. 
     2946 * @param   cbBytes     The size of the pattern. 
     2947 * @param   cbUnit      The search unit. 
     2948 * @param   cMaxHits    The max number of hits. 
     2949 * @param   pResult     Where to store the result if it's a function invocation. 
     2950 */ 
     2951static int dbgcCmdWorkerSearchMemDoIt(PDBGCCMDHLP pCmdHlp, PVM pVM, PDBGFADDRESS pAddress, RTGCUINTPTR cbRange, 
     2952                                      const uint8_t *pabBytes, uint32_t cbBytes, 
     2953                                      uint32_t cbUnit, uint64_t cMaxHits, PDBGCVAR pResult) 
     2954{ 
     2955    /* 
     2956     * Do the search. 
     2957     */ 
     2958    uint64_t cHits = 0; 
     2959    for (;;) 
     2960    { 
     2961        /* search */ 
     2962        DBGFADDRESS HitAddress; 
     2963        int rc = DBGFR3MemScan(pVM, pAddress, cbRange, pabBytes, cbBytes, &HitAddress); 
     2964        if (RT_FAILURE(rc)) 
     2965        { 
     2966            if (rc != VERR_DBGF_MEM_NOT_FOUND) 
     2967                return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "DBGFR3MemScan\n"); 
     2968 
     2969            /* update the current address so we can save it (later). */ 
     2970            pAddress->off += cbRange; 
     2971            pAddress->FlatPtr += cbRange; 
     2972            cbRange = 0; 
     2973            break; 
     2974        } 
     2975 
     2976        /* report result */ 
     2977        DBGCVAR VarCur; 
     2978        dbgcVarInit(&VarCur); 
     2979        dbgcVarSetDbgfAddr(&VarCur, &HitAddress); 
     2980        if (!pResult) 
     2981            pCmdHlp->pfnExec(pCmdHlp, "db %DV LB 10", &VarCur); 
     2982        else 
     2983            dbgcVarSetDbgfAddr(pResult, &HitAddress); 
     2984 
     2985        /* advance */ 
     2986        cbRange -= HitAddress.FlatPtr - pAddress->FlatPtr; 
     2987        *pAddress = HitAddress; 
     2988        pAddress->FlatPtr += cbBytes; 
     2989        pAddress->off += cbBytes; 
     2990        if (cbRange <= cbBytes) 
     2991        { 
     2992            cbRange = 0; 
     2993            break; 
     2994        } 
     2995        cbRange -= cbBytes; 
     2996 
     2997        if (++cHits >= cMaxHits) 
     2998        { 
     2999            /// @todo save the search. 
     3000            break; 
     3001        } 
     3002    } 
     3003 
     3004    /* 
     3005     * Save the search so we can resume it... 
     3006     */ 
     3007    PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp); 
     3008    if (pDbgc->abSearch != pabBytes) 
     3009    { 
     3010        memcpy(pDbgc->abSearch, pabBytes, cbBytes); 
     3011        pDbgc->cbSearch = cbBytes; 
     3012        pDbgc->cbSearchUnit = cbUnit; 
     3013    } 
     3014    pDbgc->cMaxSearchHits = cMaxHits; 
     3015    pDbgc->SearchAddr = *pAddress; 
     3016    pDbgc->cbSearchRange = cbRange; 
     3017 
     3018    return cHits ? VINF_SUCCESS : VERR_DBGC_COMMAND_FAILED; 
     3019} 
     3020 
     3021 
     3022/** 
     3023 * Resumes the previous search. 
     3024 * 
     3025 * @returns VBox status code. 
     3026 * @param   pCmdHlp     Pointer to the command helper functions. 
     3027 * @param   pVM         Pointer to the current VM (if any). 
     3028 * @param   pResult     Where to store the result of a function invocation. 
     3029 */ 
     3030static int dbgcCmdWorkerSearchMemResume(PDBGCCMDHLP pCmdHlp, PVM pVM, PDBGCVAR pResult) 
     3031{ 
     3032    PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp); 
     3033 
     3034    /* 
     3035     * Make sure there is a previous command. 
     3036     */ 
     3037    if (!pDbgc->cbSearch) 
     3038    { 
     3039        pCmdHlp->pfnPrintf(pCmdHlp, NULL, "Error: No previous search\n"); 
     3040        return VERR_DBGC_COMMAND_FAILED; 
     3041    } 
     3042 
     3043    /* 
     3044     * Make range and address adjustments. 
     3045     */ 
     3046    DBGFADDRESS Address = pDbgc->SearchAddr; 
     3047    if (Address.FlatPtr == ~(RTGCUINTPTR)0) 
     3048    { 
     3049        Address.FlatPtr -= Address.off; 
     3050        Address.off = 0; 
     3051    } 
     3052 
     3053    RTGCUINTPTR cbRange = pDbgc->cbSearchRange; 
     3054    if (!cbRange) 
     3055        cbRange = ~(RTGCUINTPTR)0; 
     3056    if (Address.FlatPtr + cbRange < pDbgc->SearchAddr.FlatPtr) 
     3057        cbRange = ~(RTGCUINTPTR)0 - pDbgc->SearchAddr.FlatPtr + !!pDbgc->SearchAddr.FlatPtr; 
     3058 
     3059    return dbgcCmdWorkerSearchMemDoIt(pCmdHlp, pVM, &Address, cbRange, pDbgc->abSearch, pDbgc->cbSearch, 
     3060                                      pDbgc->cbSearchUnit, pDbgc->cMaxSearchHits, pResult); 
     3061} 
     3062 
     3063 
     3064/** 
     3065 * Search memory, worker for the 's' and 's?' functions. 
     3066 * 
     3067 * @returns VBox status. 
     3068 * @param   pCmdHlp     Pointer to the command helper functions. 
     3069 * @param   pVM         Pointer to the current VM (if any). 
     3070 * @param   pAddress    Where to start searching. If no range, search till end of address space. 
     3071 * @param   cMaxHits    The maximum number of hits. 
     3072 * @param   chType      The search type. 
     3073 * @param   paPatArgs   The pattern variable array. 
     3074 * @param   cPatArgs    Number of pattern variables. 
     3075 * @param   pResult     Where to store the result of a function invocation. 
     3076 */ 
     3077static int dbgcCmdWorkerSearchMem(PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR pAddress, uint64_t cMaxHits, char chType, 
     3078                                  PCDBGCVAR paPatArgs, unsigned cPatArgs, PDBGCVAR pResult) 
     3079{ 
     3080    dbgcVarSetGCFlat(pResult, 0); 
     3081 
     3082    /* 
     3083     * Convert the search pattern into bytes and DBGFR3MemScan can deal with. 
     3084     */ 
     3085    uint32_t cbUnit; 
     3086    switch (chType) 
     3087    { 
     3088        case 'a': 
     3089        case 'b':   cbUnit = 1; break; 
     3090        case 'u': 
     3091        case 'w':   cbUnit = 2; break; 
     3092        case 'd':   cbUnit = 4; break; 
     3093        case 'q':   cbUnit = 8; break; 
     3094        default: 
     3095            return pCmdHlp->pfnVBoxError(pCmdHlp, VERR_INVALID_PARAMETER, "chType=%c\n", chType); 
     3096    } 
     3097    uint8_t abBytes[RT_SIZEOFMEMB(DBGC, abSearch)]; 
     3098    uint32_t cbBytes = sizeof(abBytes); 
     3099    int rc = dbgcVarsToBytes(pCmdHlp, abBytes, &cbBytes, cbUnit, paPatArgs, cPatArgs); 
     3100    if (RT_FAILURE(rc)) 
     3101        return VERR_DBGC_COMMAND_FAILED; 
     3102 
     3103    /* 
     3104     * Make DBGF address and fix the range. 
     3105     */ 
     3106    DBGFADDRESS Address; 
     3107    rc = pCmdHlp->pfnVarToDbgfAddr(pCmdHlp, pAddress, &Address); 
     3108    if (RT_FAILURE(rc)) 
     3109        return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "VarToDbgfAddr(,%Dv,)\n", pAddress); 
     3110 
     3111    RTGCUINTPTR cbRange; 
     3112    switch (pAddress->enmRangeType) 
     3113    { 
     3114        case DBGCVAR_RANGE_BYTES: 
     3115            cbRange = pAddress->u64Range; 
     3116            if (cbRange != pAddress->u64Range) 
     3117                cbRange = ~(RTGCUINTPTR)0; 
     3118            break; 
     3119 
     3120        case DBGCVAR_RANGE_ELEMENTS: 
     3121            cbRange = (RTGCUINTPTR)(pAddress->u64Range * cbUnit); 
     3122            if (    cbRange != pAddress->u64Range * cbUnit 
     3123                ||  cbRange < pAddress->u64Range) 
     3124                cbRange = ~(RTGCUINTPTR)0; 
     3125            break; 
     3126 
     3127        default: 
     3128            cbRange = ~(RTGCUINTPTR)0; 
     3129            break; 
     3130    } 
     3131    if (Address.FlatPtr + cbRange < Address.FlatPtr) 
     3132        cbRange = ~(RTGCUINTPTR)0 - Address.FlatPtr + !!Address.FlatPtr; 
     3133 
     3134    /* 
     3135     * Ok, do it. 
     3136     */ 
     3137    return dbgcCmdWorkerSearchMemDoIt(pCmdHlp, pVM, &Address, cbRange, abBytes, cbBytes, cbUnit, cMaxHits, pResult); 
     3138} 
     3139 
     3140 
     3141/** 
    28113142 * The 's' command. 
    28123143 * 
     
    28213152{ 
    28223153    /* check that the parser did what it's supposed to do. */ 
    2823     if (    cArgs != 1 
    2824         ||  paArgs[0].enmType != DBGCVAR_TYPE_STRING) 
     3154    //if (    cArgs <= 2 
     3155    //    &&  paArgs[0].enmType != DBGCVAR_TYPE_STRING) 
     3156    //    return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "parser error\n"); 
     3157 
     3158    /* 
     3159     * Repeate previous search? 
     3160     */ 
     3161    if (cArgs == 0) 
     3162        return dbgcCmdWorkerSearchMemResume(pCmdHlp, pVM, pResult); 
     3163 
     3164    /* 
     3165     * Parse arguments. 
     3166     */ 
     3167 
     3168    return -1; 
     3169
     3170 
     3171 
     3172/** 
     3173 * The 's?' command. 
     3174 * 
     3175 * @returns VBox status. 
     3176 * @param   pCmd        Pointer to the command descriptor (as registered). 
     3177 * @param   pCmdHlp     Pointer to command helper functions. 
     3178 * @param   pVM         Pointer to the current VM (if any). 
     3179 * @param   paArgs      Pointer to (readonly) array of arguments. 
     3180 * @param   cArgs       Number of arguments in the array. 
     3181 */ 
     3182static DECLCALLBACK(int) dbgcCmdSearchMemType(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult) 
     3183
     3184    /* check that the parser did what it's supposed to do. */ 
     3185    if (    cArgs < 2 
     3186        ||  !DBGCVAR_ISGCPOINTER(paArgs[0].enmType)) 
    28253187        return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "parser error\n"); 
    2826     return -1
     3188    return dbgcCmdWorkerSearchMem(pCmdHlp, pVM, &paArgs[0], pResult ? 1 : 80, pCmd->pszCmd[1], paArgs + 1, cArgs - 1, pResult)
    28273189} 
    28283190 
  • trunk/src/VBox/Debugger/DBGCInternal.h

    r5686 r5731  
    6464#define VERR_DBGC_BP_EXISTS                     (-12004) 
    6565#define VINF_DBGC_BP_NO_COMMAND                 12005 
     66#define VERR_DBGC_COMMAND_FAILED                (-12006) 
    6667 
    6768 
     
    159160    /** The list of breakpoints. (singly linked) */ 
    160161    PDBGCBP             pFirstBp; 
     162 
     163    /** Save search pattern. */ 
     164    uint8_t             abSearch[256]; 
     165    /** The length of the search pattern. */ 
     166    uint32_t            cbSearch; 
     167    /** The search unit */ 
     168    uint32_t            cbSearchUnit; 
     169    /** The max hits. */ 
     170    uint64_t            cMaxSearchHits; 
     171    /** The address to resume searching from. */ 
     172    DBGFADDRESS         SearchAddr; 
     173    /** What's left of the original search range. */ 
     174    RTGCUINTPTR         cbSearchRange; 
    161175 
    162176    /** @name Parsing and Execution 
     
    337351int     dbgcBpExec(PDBGC pDbgc, RTUINT iBp); 
    338352 
     353void    dbgcVarInit(PDBGCVAR pVar); 
    339354void    dbgcVarSetGCFlat(PDBGCVAR pVar, RTGCPTR GCFlat); 
    340355void    dbgcVarSetGCFlatByteRange(PDBGCVAR pVar, RTGCPTR GCFlat, uint64_t cb); 
     356void    dbgcVarSetU64(PDBGCVAR pVar, uint64_t u64); 
    341357void    dbgcVarSetVar(PDBGCVAR pVar, PCDBGCVAR pVar2); 
     358void    dbgcVarSetDbgfAddr(PDBGCVAR pVar, PCDBGFADDRESS pAddress); 
    342359void    dbgcVarSetNoRange(PDBGCVAR pVar); 
    343360void    dbgcVarSetByteRange(PDBGCVAR pVar, uint64_t cb); 
  • trunk/src/VBox/Debugger/DBGConsole.cpp

    r5686 r5731  
    12601260            rc = pCmd->pfnHandler(pCmd, &pDbgc->CmdHlp, pDbgc->pVM, &pDbgc->aArgs[0], cArgs, NULL); 
    12611261        pDbgc->rcCmd = rc; 
     1262        if (rc == VERR_DBGC_COMMAND_FAILED) 
     1263            rc = VINF_SUCCESS; 
    12621264    } 
    12631265    else 
     
    13431345                rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, 
    13441346                    "Error: Cannot get symbol, it's set only (argument %d).\n", cArgs); 
     1347                break; 
     1348 
     1349            case VERR_DBGC_COMMAND_FAILED: 
     1350                rc = VINF_SUCCESS; 
    13451351                break; 
    13461352 
     
    13551361         */ 
    13561362        if (rc >= VERR_PARSE_FIRST && rc < VERR_PARSE_LAST) 
    1357             rc = 0
     1363            rc = VINF_SUCCESS
    13581364    } 
    13591365 
     
    19411947    //pDbgc->paVars           = NULL; 
    19421948    //pDbgc->pFirstBp         = NULL; 
     1949    //pDbgc->abSearch         = {0}; 
     1950    //pDbgc->cbSearch         = 0; 
     1951    pDbgc->cbSearchUnit       = 1; 
     1952    pDbgc->cMaxSearchHits     = 1; 
     1953    //pDbgc->SearchAddr       = {0}; 
     1954    //pDbgc->cbSearchRange    = 0; 
     1955 
    19431956    //pDbgc->uInputZero       = 0; 
    19441957    //pDbgc->iRead            = 0; 
  • trunk/src/VBox/Debugger/testcase/tstDBGCStubs.cpp

    r5685 r5731  
    275275    return VERR_INTERNAL_ERROR; 
    276276} 
    277  
     277DBGFR3DECL(int) DBGFR3MemScan(PVM pVM, PCDBGFADDRESS pAddress, RTGCUINTPTR cbRange, const uint8_t *pabNeedle, size_t cbNeedle, PDBGFADDRESS pHitAddress) 
     278
     279    return VERR_INTERNAL_ERROR; 
     280
     281DBGFR3DECL(void) DBGFR3AddrFromPhys(PVM pVM, PDBGFADDRESS pAddress, RTGCPHYS PhysAddr) 
     282
     283
  • trunk/src/VBox/VMM/DBGFMem.cpp

    r5667 r5731  
    8484 * Scan guest memory for an exact byte string. 
    8585 * 
    86  * @returns VBox status code. 
     86 * @returns VBox status codes: 
     87 * @retval  VINF_SUCCESS and *pGCPtrHit on success. 
     88 * @retval  VERR_DBGF_MEM_NOT_FOUND if not found. 
     89 * @retval  VERR_INVALID_POINTER if any of the pointer arguments are invalid. 
     90 * @retval  VERR_INVALID_ARGUMENT if any other arguments are invalid. 
     91 * 
    8792 * @param   pVM         The VM handle. 
    8893 * @param   pAddress    Where to store the mixed address. 
  • trunk/src/VBox/VMM/PGMDbg.cpp

    r5667 r5731  
    264264            break; 
    265265        cb = pbEnd - pb; 
    266         if (cb <= cbNeedle) 
     266        if (cb >= cbNeedle) 
    267267        { 
    268268            /* match? */ 
     
    325325    if (!cbNeedle) 
    326326        return VERR_INVALID_PARAMETER; 
    327     if (cbRange > MAX_NEEDLE_SIZE) 
     327    if (cbNeedle > MAX_NEEDLE_SIZE) 
    328328        return VERR_INVALID_PARAMETER; 
    329329 
     
    370370            { 
    371371                PPGMPAGE pPage = &pRam->aPages[iPage]; 
    372                 if (    !PGM_PAGE_IS_ZERO(pPage) 
    373                     &&  !PGM_PAGE_IS_MMIO(pPage)) 
     372                if (    /** @todo !PGM_PAGE_IS_ZERO(pPage) 
     373                    &&*/  !PGM_PAGE_IS_MMIO(pPage)) 
    374374                { 
    375375                    void const *pvPage; 
     
    437437    if (!cbNeedle) 
    438438        return VERR_INVALID_PARAMETER; 
    439     if (cbRange > MAX_NEEDLE_SIZE) 
     439    if (cbNeedle > MAX_NEEDLE_SIZE) 
    440440        return VERR_INVALID_PARAMETER; 
    441441 
     
    456456    while (cPages-- > 0) 
    457457    { 
    458         uint64_t fFlags; 
    459458        RTGCPHYS GCPhys; 
    460         int rc = PGMGstGetPage(pVM, GCPtr, &fFlags, &GCPhys); 
     459        int rc = PGMPhysGCPtr2GCPhys(pVM, GCPtr, &GCPhys); 
    461460        if (RT_SUCCESS(rc)) 
    462461        { 
    463462            PPGMPAGE pPage = pgmPhysGetPage(&pVM->pgm.s, GCPhys); 
    464463            if (    pPage 
    465                 &&  !PGM_PAGE_IS_ZERO(pPage) 
     464///@todo                 &&  !PGM_PAGE_IS_ZERO(pPage) 
    466465                &&  !PGM_PAGE_IS_MMIO(pPage)) 
    467466            { 
    468467                void const *pvPage; 
    469468                PGMPAGEMAPLOCK Lock; 
    470                 rc = PGMPhysGCPhys2CCPtrReadOnly(pVM, GCPtr & ~(RTGCUINTPTR)PAGE_OFFSET_MASK, &pvPage, &Lock); 
     469                rc = PGMPhysGCPhys2CCPtrReadOnly(pVM, GCPhys & ~(RTGCUINTPTR)PAGE_OFFSET_MASK, &pvPage, &Lock); 
    471470                if (RT_SUCCESS(rc)) 
    472471                { 

© 2008 Sun Microsystems, Inc.
ContactPrivacy policy