VirtualBox

Changeset 84694 in vbox


Ignore:
Timestamp:
Jun 5, 2020 12:55:11 PM (4 years ago)
Author:
vboxsync
Message:

Debugger/DBGCGdbRemoteStub: Track registered trace points to allow removal later on, bugref:5217

File:
1 edited

Legend:

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

    r84691 r84694  
    2727#include <iprt/cdefs.h>
    2828#include <iprt/err.h>
     29#include <iprt/list.h>
    2930#include <iprt/mem.h>
    3031#include <iprt/string.h>
     
    9596    GDBSTUBRECVSTATE_32BIT_HACK = 0x7fffffff
    9697} GDBSTUBRECVSTATE;
     98
     99
     100/**
     101 * A tracepoint descriptor.
     102 */
     103typedef struct GDBSTUBTP
     104{
     105    /** List node for the list of tracepoints. */
     106    RTLISTNODE                  NdTps;
     107    /** The breakpoint number from the DBGF API. */
     108    uint32_t                    iBp;
     109    /** The tracepoint type for identification. */
     110    GDBSTUBTPTYPE               enmTpType;
     111    /** The tracepoint address for identification. */
     112    uint64_t                    GdbTgtAddr;
     113    /** The tracepoint kind for identification. */
     114    uint64_t                    uKind;
     115} GDBSTUBTP;
     116/** Pointer to a tracepoint. */
     117typedef GDBSTUBTP *PGDBSTUBTP;
    97118
    98119
     
    128149    /** Flag whether was something was output using the 'O' packet since it was reset last. */
    129150    bool                        fOutput;
     151    /** List of registered trace points.
     152     * GDB removes breakpoints/watchpoints using the parameters they were
     153     * registered with while we only use the BP number form DBGF internally.
     154     * Means we have to track all registration so we can remove them later on. */
     155    RTLISTANCHOR                LstTps;
    130156} GDBSTUBCTX;
    131157/** Pointer to the GDB stub context data. */
     
    224250*   Internal Functions                                                                                                           *
    225251*********************************************************************************************************************************/
     252
     253
     254/**
     255 * Tries to find a trace point with the given parameters in the list of registered trace points.
     256 *
     257 * @returns Pointer to the trace point registration record if found or NULL if none was found.
     258 * @param   pThis               The GDB stub context.
     259 * @param   enmTpType           The trace point type.
     260 * @param   GdbTgtAddr          Target address given by GDB.
     261 * @param   uKind               Trace point kind.
     262 */
     263static PGDBSTUBTP dbgcGdbStubTpFind(PGDBSTUBCTX pThis, GDBSTUBTPTYPE enmTpType, uint64_t GdbTgtAddr, uint64_t uKind)
     264{
     265    PGDBSTUBTP pTpCur = NULL;
     266    RTListForEach(&pThis->LstTps, pTpCur, GDBSTUBTP, NdTps)
     267    {
     268        if (   pTpCur->enmTpType == enmTpType
     269            && pTpCur->GdbTgtAddr == GdbTgtAddr
     270            && pTpCur->uKind == uKind)
     271            return pTpCur;
     272    }
     273
     274    return NULL;
     275}
     276
     277
     278/**
     279 * Registers a new trace point.
     280 *
     281 * @returns VBox status code.
     282 * @param   pThis               The GDB stub context.
     283 * @param   enmTpType           The trace point type.
     284 * @param   GdbTgtAddr          Target address given by GDB.
     285 * @param   uKind               Trace point kind.
     286 * @param   iBp                 The internal DBGF breakpoint ID this trace point was registered with.
     287 */
     288static int dbgcGdbStubTpRegister(PGDBSTUBCTX pThis, GDBSTUBTPTYPE enmTpType, uint64_t GdbTgtAddr, uint64_t uKind, uint32_t iBp)
     289{
     290    int rc = VERR_ALREADY_EXISTS;
     291
     292    /* Can't register a tracepoint with the same parameters twice or we can't decide whom to remove later on. */
     293    PGDBSTUBTP pTp = dbgcGdbStubTpFind(pThis, enmTpType, GdbTgtAddr, uKind);
     294    if (!pTp)
     295    {
     296        pTp = (PGDBSTUBTP)RTMemAllocZ(sizeof(*pTp));
     297        if (pTp)
     298        {
     299            pTp->enmTpType  = enmTpType;
     300            pTp->GdbTgtAddr = GdbTgtAddr;
     301            pTp->uKind      = uKind;
     302            pTp->iBp        = iBp;
     303            RTListAppend(&pThis->LstTps, &pTp->NdTps);
     304            rc = VINF_SUCCESS;
     305        }
     306        else
     307            rc = VERR_NO_MEMORY;
     308    }
     309
     310    return rc;
     311}
     312
     313
     314/**
     315 * Deregisters the given trace point (needs to be unregistered from DBGF by the caller before).
     316 *
     317 * @returns nothing.
     318 * @param   pTp                 The trace point to deregister.
     319 */
     320static void dbgcGdbStubTpDeregister(PGDBSTUBTP pTp)
     321{
     322    RTListNodeRemove(&pTp->NdTps);
     323    RTMemFree(pTp);
     324}
     325
    226326
    227327/**
     
    16061706                        rc = dbgcBpAdd(&pThis->Dbgc, iBp, NULL /*pszCmd*/);
    16071707                        if (RT_SUCCESS(rc))
    1608                             rc = dbgcGdbStubCtxReplySendOk(pThis);
    1609                         else
     1708                        {
     1709                            rc = dbgcGdbStubTpRegister(pThis, enmTpType, GdbTgtTpAddr, uKind, iBp);
     1710                            if (RT_SUCCESS(rc))
     1711                                rc = dbgcGdbStubCtxReplySendOk(pThis);
     1712                            else
     1713                                dbgcBpDelete(&pThis->Dbgc, iBp);
     1714                        }
     1715
     1716                        if (RT_FAILURE(rc))
    16101717                        {
    16111718                            DBGFR3BpClear(pThis->Dbgc.pUVM, iBp);
     
    16291736                if (RT_SUCCESS(rc))
    16301737                {
    1631                     DBGFADDRESS BpAddr;
    1632                     DBGFR3AddrFromFlat(pThis->Dbgc.pUVM, &BpAddr, GdbTgtTpAddr);
    1633 
    1634                     uint32_t iBp = 0; /** @todo Need to keep track which breakpoint number belongs to which breakpoint. */
    1635                     int rc2 = DBGFR3BpClear(pThis->Dbgc.pUVM, iBp);
    1636                     if (RT_SUCCESS(rc2) || rc2 == VERR_DBGF_BP_NOT_FOUND)
    1637                         dbgcBpDelete(&pThis->Dbgc, iBp);
    1638 
    1639                     if (RT_SUCCESS(rc2))
    1640                         rc = dbgcGdbStubCtxReplySendOk(pThis);
     1738                    PGDBSTUBTP pTp = dbgcGdbStubTpFind(pThis, enmTpType, GdbTgtTpAddr, uKind);
     1739                    if (pTp)
     1740                    {
     1741                        int rc2 = DBGFR3BpClear(pThis->Dbgc.pUVM, pTp->iBp);
     1742                        if (RT_SUCCESS(rc2) || rc2 == VERR_DBGF_BP_NOT_FOUND)
     1743                            dbgcBpDelete(&pThis->Dbgc, pTp->iBp);
     1744
     1745                        if (RT_SUCCESS(rc2))
     1746                        {
     1747                            dbgcGdbStubTpDeregister(pTp);
     1748                            rc = dbgcGdbStubCtxReplySendOk(pThis);
     1749                        }
     1750                        else
     1751                            rc = dbgcGdbStubCtxReplySendErrSts(pThis, rc);
     1752                    }
    16411753                    else
    1642                         rc = dbgcGdbStubCtxReplySendErrSts(pThis, rc);
     1754                        rc = dbgcGdbStubCtxReplySendErrSts(pThis, VERR_NOT_FOUND);
    16431755                }
    16441756                else
     
    23202432    pThis->fExtendedMode   = false;
    23212433    pThis->fOutput         = false;
     2434    RTListInit(&pThis->LstTps);
    23222435    dbgcGdbStubCtxReset(pThis);
    23232436
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