VirtualBox

Changeset 64589 in vbox


Ignore:
Timestamp:
Nov 6, 2016 6:07:32 PM (8 years ago)
Author:
vboxsync
Message:

DBGFR3Flow: Iterator API for the branch tables

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/vmm/dbgf.h

    r64586 r64589  
    25082508/** Pointer to a control flow graph iterator. */
    25092509typedef DBGFFLOWIT *PDBGFFLOWIT;
     2510/** A DBGF control flow graph branch table iterator. */
     2511typedef struct DBGFFLOWBRANCHTBLITINT *DBGFFLOWBRANCHTBLIT;
     2512/** Pointer to a control flow graph branch table iterator. */
     2513typedef DBGFFLOWBRANCHTBLIT *PDBGFFLOWBRANCHTBLIT;
    25102514
    25112515/** @name DBGFFLOWBB Flags.
     
    26042608VMMR3DECL(int)               DBGFR3FlowBbQuerySuccessors(DBGFFLOWBB hFlowBb, PDBGFFLOWBB phFlowBbFollow,
    26052609                                                         PDBGFFLOWBB phFlowBbTarget);
    2606 
    26072610VMMR3DECL(uint32_t)          DBGFR3FlowBbGetRefBbCount(DBGFFLOWBB hFlowBb);
    26082611VMMR3DECL(int)               DBGFR3FlowBbGetRefBb(DBGFFLOWBB hFlowBb, PDBGFFLOWBB pahFlowBbRef, uint32_t cRef);
     
    26192622VMMR3DECL(int)               DBGFR3FlowItReset(DBGFFLOWIT hFlowIt);
    26202623
     2624VMMR3DECL(int)               DBGFR3FlowBranchTblItCreate(DBGFFLOW hFlow, DBGFFLOWITORDER enmOrder, PDBGFFLOWBRANCHTBLIT phFlowBranchTblIt);
     2625VMMR3DECL(void)              DBGFR3FlowBranchTblItDestroy(DBGFFLOWBRANCHTBLIT hFlowBranchTblIt);
     2626VMMR3DECL(DBGFFLOWBRANCHTBL) DBGFR3FlowBranchTblItNext(DBGFFLOWBRANCHTBLIT hFlowBranchTblIt);
     2627VMMR3DECL(int)               DBGFR3FlowBranchTblItReset(DBGFFLOWBRANCHTBLIT hFlowBranchTblIt);
     2628
    26212629/** @} */
    26222630
  • trunk/src/VBox/Debugger/testcase/tstDBGCStubs.cpp

    r64586 r64589  
    511511    return VERR_INTERNAL_ERROR;
    512512}
     513VMMR3DECL(int) DBGFR3FlowBranchTblItCreate(DBGFFLOW hFlow, DBGFFLOWITORDER enmOrder, PDBGFFLOWBRANCHTBLIT phFlowBranchTblIt)
     514{
     515    return VERR_INTERNAL_ERROR;
     516}
     517VMMR3DECL(void) DBGFR3FlowBranchTblItDestroy(DBGFFLOWBRANCHTBLIT hFlowBranchTblIt)
     518{
     519}
     520VMMR3DECL(DBGFFLOWBRANCHTBL) DBGFR3FlowBranchTblItNext(DBGFFLOWBRANCHTBLIT hFlowBranchTblIt)
     521{
     522    return NULL;
     523}
     524VMMR3DECL(int) DBGFR3FlowBranchTblItReset(DBGFFLOWBRANCHTBLIT hFlowBranchTblIt)
     525{
     526    return VERR_INTERNAL_ERROR;
     527}
    513528
    514529#include <VBox/vmm/cfgm.h>
  • trunk/src/VBox/VMM/VMMR3/DBGFR3Flow.cpp

    r64588 r64589  
    181181
    182182
     183/**
     184 * Control flow graph branch table iterator state.
     185 */
     186typedef struct DBGFFLOWBRANCHTBLITINT
     187{
     188    /** Pointer to the control flow graph (holding a reference). */
     189    PDBGFFLOWINT             pFlow;
     190    /** Next branch table to return. */
     191    uint32_t                 idxTblNext;
     192    /** Array of branch table pointers sorted by the specified order - variable in size. */
     193    PDBGFFLOWBRANCHTBLINT    apBranchTbl[1];
     194} DBGFFLOWBRANCHTBLITINT;
     195/** Pointer to the internal control flow graph branch table iterator state. */
     196typedef DBGFFLOWBRANCHTBLITINT *PDBGFFLOWBRANCHTBLITINT;
     197
    183198/*********************************************************************************************************************************
    184199*   Internal Functions                                                                                                           *
     
    19641979 *
    19651980 * @returns VBox status code.
    1966  * @param   hFlow                The control flow graph handle.
     1981 * @param   hFlow               The control flow graph handle.
    19671982 * @param   enmOrder            The order in which the basic blocks are enumerated.
    1968  * @param   phFlowIt             Where to store the handle to the iterator on success.
     1983 * @param   phFlowIt            Where to store the handle to the iterator on success.
    19691984 */
    19701985VMMR3DECL(int) DBGFR3FlowItCreate(DBGFFLOW hFlow, DBGFFLOWITORDER enmOrder, PDBGFFLOWIT phFlowIt)
     
    20652080    return VINF_SUCCESS;
    20662081}
     2082
     2083
     2084/**
     2085 * @callback_method_impl{FNRTSORTCMP}
     2086 */
     2087static DECLCALLBACK(int) dbgfR3FlowBranchTblItSortCmp(void const *pvElement1, void const *pvElement2, void *pvUser)
     2088{
     2089    PDBGFFLOWITORDER penmOrder = (PDBGFFLOWITORDER)pvUser;
     2090    PDBGFFLOWBRANCHTBLINT pTbl1 = *(PDBGFFLOWBRANCHTBLINT *)pvElement1;
     2091    PDBGFFLOWBRANCHTBLINT pTbl2 = *(PDBGFFLOWBRANCHTBLINT *)pvElement2;
     2092
     2093    if (dbgfR3FlowAddrEqual(&pTbl1->AddrStart, &pTbl2->AddrStart))
     2094        return 0;
     2095
     2096    if (*penmOrder == DBGFFLOWITORDER_BY_ADDR_LOWEST_FIRST)
     2097    {
     2098        if (dbgfR3FlowAddrLower(&pTbl1->AddrStart, &pTbl2->AddrStart))
     2099            return -1;
     2100        else
     2101            return 1;
     2102    }
     2103    else
     2104    {
     2105        if (dbgfR3FlowAddrLower(&pTbl1->AddrStart, &pTbl2->AddrStart))
     2106            return 1;
     2107        else
     2108            return -1;
     2109    }
     2110}
     2111
     2112
     2113/**
     2114 * Creates a new branch table iterator for the given control flow graph.
     2115 *
     2116 * @returns VBox status code.
     2117 * @param   hFlow               The control flow graph handle.
     2118 * @param   enmOrder            The order in which the basic blocks are enumerated.
     2119 * @param   phFlowBranchTblIt   Where to store the handle to the iterator on success.
     2120 */
     2121VMMR3DECL(int) DBGFR3FlowBranchTblItCreate(DBGFFLOW hFlow, DBGFFLOWITORDER enmOrder,
     2122                                           PDBGFFLOWBRANCHTBLIT phFlowBranchTblIt)
     2123{
     2124    int rc = VINF_SUCCESS;
     2125    PDBGFFLOWINT pFlow = hFlow;
     2126    AssertPtrReturn(pFlow, VERR_INVALID_POINTER);
     2127    AssertPtrReturn(phFlowBranchTblIt, VERR_INVALID_POINTER);
     2128    AssertReturn(enmOrder > DBGFFLOWITORDER_INVALID && enmOrder < DBGFFLOWITORDER_BREADTH_FIRST,
     2129                 VERR_INVALID_PARAMETER);
     2130    AssertReturn(enmOrder < DBGFFLOWITORDER_DEPTH_FRIST, VERR_NOT_SUPPORTED);
     2131
     2132    PDBGFFLOWBRANCHTBLITINT pIt = (PDBGFFLOWBRANCHTBLITINT)RTMemAllocZ(RT_OFFSETOF(DBGFFLOWBRANCHTBLITINT, apBranchTbl[pFlow->cBranchTbls]));
     2133    if (RT_LIKELY(pIt))
     2134    {
     2135        DBGFR3FlowRetain(hFlow);
     2136        pIt->pFlow      = pFlow;
     2137        pIt->idxTblNext = 0;
     2138        /* Fill the list and then sort. */
     2139        PDBGFFLOWBRANCHTBLINT pFlowBranchTbl;
     2140        uint32_t idxTbl = 0;
     2141        RTListForEach(&pFlow->LstBranchTbl, pFlowBranchTbl, DBGFFLOWBRANCHTBLINT, NdBranchTbl)
     2142        {
     2143            DBGFR3FlowBranchTblRetain(pFlowBranchTbl);
     2144            pIt->apBranchTbl[idxTbl++] = pFlowBranchTbl;
     2145        }
     2146
     2147        /* Sort the blocks by address. */
     2148        RTSortShell(&pIt->apBranchTbl[0], pFlow->cBranchTbls, sizeof(PDBGFFLOWBRANCHTBLINT), dbgfR3FlowBranchTblItSortCmp, &enmOrder);
     2149
     2150        *phFlowBranchTblIt = pIt;
     2151    }
     2152    else
     2153        rc = VERR_NO_MEMORY;
     2154
     2155    return rc;
     2156}
     2157
     2158
     2159/**
     2160 * Destroys a given control flow graph branch table iterator.
     2161 *
     2162 * @returns nothing.
     2163 * @param   hFlowBranchTblIt              The control flow graph branch table iterator handle.
     2164 */
     2165VMMR3DECL(void) DBGFR3FlowBranchTblItDestroy(DBGFFLOWBRANCHTBLIT hFlowBranchTblIt)
     2166{
     2167    PDBGFFLOWBRANCHTBLITINT pIt = hFlowBranchTblIt;
     2168    AssertPtrReturnVoid(pIt);
     2169
     2170    for (unsigned i = 0; i < pIt->pFlow->cBranchTbls; i++)
     2171        DBGFR3FlowBranchTblRelease(pIt->apBranchTbl[i]);
     2172
     2173    DBGFR3FlowRelease(pIt->pFlow);
     2174    RTMemFree(pIt);
     2175}
     2176
     2177
     2178/**
     2179 * Returns the next branch table in the iterator or NULL if there is no
     2180 * branch table left.
     2181 *
     2182 * @returns Handle to the next basic block in the iterator or NULL if the end
     2183 *          was reached.
     2184 * @param   hFlowBranchTblIt    The iterator handle.
     2185 *
     2186 * @note If a valid handle is returned it must be release with DBGFR3FlowBranchTblRelease()
     2187 *       when not required anymore.
     2188 */
     2189VMMR3DECL(DBGFFLOWBRANCHTBL) DBGFR3FlowBranchTblItNext(DBGFFLOWBRANCHTBLIT hFlowBranchTblIt)
     2190{
     2191    PDBGFFLOWBRANCHTBLITINT pIt = hFlowBranchTblIt;
     2192    AssertPtrReturn(pIt, NULL);
     2193
     2194    PDBGFFLOWBRANCHTBLINT pTbl = NULL;
     2195    if (pIt->idxTblNext < pIt->pFlow->cBranchTbls)
     2196    {
     2197        pTbl = pIt->apBranchTbl[pIt->idxTblNext++];
     2198        DBGFR3FlowBranchTblRetain(pTbl);
     2199    }
     2200
     2201    return pTbl;
     2202}
     2203
     2204
     2205/**
     2206 * Resets the given iterator to the beginning.
     2207 *
     2208 * @returns VBox status code.
     2209 * @param   hFlowBranchTblIt    The iterator handle.
     2210 */
     2211VMMR3DECL(int) DBGFR3FlowBranchTblItReset(DBGFFLOWBRANCHTBLIT hFlowBranchTblIt)
     2212{
     2213    PDBGFFLOWBRANCHTBLITINT pIt = hFlowBranchTblIt;
     2214    AssertPtrReturn(pIt, VERR_INVALID_HANDLE);
     2215
     2216    pIt->idxTblNext = 0;
     2217    return VINF_SUCCESS;
     2218}
  • trunk/src/VBox/VMM/VMMR3/VMMR3.def

    r64586 r64589  
    162162    DBGFR3FlowItNext
    163163    DBGFR3FlowItReset
     164    DBGFR3FlowBranchTblItCreate
     165    DBGFR3FlowBranchTblItDestroy
     166    DBGFR3FlowBranchTblItNext
     167    DBGFR3FlowBranchTblItReset
    164168    DBGFR3PlugInLoad
    165169    DBGFR3PlugInUnload
Note: See TracChangeset for help on using the changeset viewer.

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