VirtualBox

Changeset 20756 in vbox for trunk/src/VBox/Runtime/common


Ignore:
Timestamp:
Jun 22, 2009 1:59:33 AM (15 years ago)
Author:
vboxsync
Message:

IPRT: More RTDbg coding - generic container is mostly done now.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/dbg/dbgmodcontainer.cpp

    r20744 r20756  
    7575    /** The segment size. */
    7676    RTUINTPTR                   cb;
     77    /** The segment flags. */
     78    uint32_t                    fFlags;
    7779    /** The segment name. */
    7880    const char                 *pszName;
     
    365367
    366368    pSymbol->AddrCore.Key       = off;
    367     pSymbol->AddrCore.KeyLast   = off + RT_MIN(cb, 1);
     369    pSymbol->AddrCore.KeyLast   = off + RT_MAX(cb, 1);
    368370    pSymbol->OrdinalCore.Key    = pThis->iNextSymbolOrdinal;
    369371    pSymbol->iSeg               = iSeg;
     
    405407    RTMemFree(pSymbol);
    406408    return rc;
     409}
     410
     411
     412/** @copydoc RTDBGMODVTDBG::pfnSegmentByIndex */
     413static DECLCALLBACK(int) rtDbgModContainer_SegmentByIndex(PRTDBGMODINT pMod, RTDBGSEGIDX iSeg, PRTDBGSEGMENT pSegInfo)
     414{
     415    PRTDBGMODCTN pThis = (PRTDBGMODCTN)pMod->pvDbgPriv;
     416    if (iSeg >= pThis->cSegs)
     417        return VERR_DBG_INVALID_SEGMENT_INDEX;
     418    pSegInfo->Address = RTUINTPTR_MAX;
     419    pSegInfo->uRva    = pThis->paSegs[iSeg].off;
     420    pSegInfo->cb      = pThis->paSegs[iSeg].cb;
     421    pSegInfo->fFlags  = pThis->paSegs[iSeg].fFlags;
     422    pSegInfo->iSeg    = iSeg;
     423    strcpy(pSegInfo->szName, pThis->paSegs[iSeg].pszName);
     424    return VINF_SUCCESS;
     425}
     426
     427
     428/** @copydoc RTDBGMODVTDBG::pfnSegmentCount */
     429static DECLCALLBACK(RTDBGSEGIDX) rtDbgModContainer_SegmentCount(PRTDBGMODINT pMod)
     430{
     431    PRTDBGMODCTN pThis = (PRTDBGMODCTN)pMod->pvDbgPriv;
     432    return pThis->cSegs;
     433}
     434
     435
     436/** @copydoc RTDBGMODVTDBG::pfnSegmentAdd */
     437static DECLCALLBACK(int) rtDbgModContainer_SegmentAdd(PRTDBGMODINT pMod, RTUINTPTR uRva, RTUINTPTR cb, const char *pszName, size_t cchName,
     438                                                      uint32_t fFlags, PRTDBGSEGIDX piSeg)
     439{
     440    PRTDBGMODCTN pThis = (PRTDBGMODCTN)pMod->pvDbgPriv;
     441
     442    /*
     443     * Input validation (the bits the caller cannot do).
     444     */
     445    /* Overlapping segments are not yet supported. Will use flags to deal with it if it becomes necessary. */
     446    RTUINTPTR   uRvaLast    = uRva + RT_MAX(cb, 1) - 1;
     447    RTUINTPTR   uRvaLastMax = uRvaLast;
     448    RTDBGSEGIDX iSeg        = pThis->cSegs;
     449    while (iSeg-- > 0)
     450    {
     451        RTUINTPTR uCurRva     = pThis->paSegs[iSeg].off;
     452        RTUINTPTR uCurRvaLast = uCurRva + RT_MAX(pThis->paSegs[iSeg].cb, 1) - 1;
     453        if (   uRva      <= uCurRvaLast
     454            && uRvaLast  >= uCurRva)
     455            AssertMsgFailedReturn(("uRva=%RTptr uRvaLast=%RTptr (cb=%RTptr) \"%s\";\n"
     456                                   "uRva=%RTptr uRvaLast=%RTptr (cb=%RTptr) \"%s\" iSeg=%#x\n",
     457                                   uRva, uRvaLast, cb, pszName,
     458                                   uCurRva, uCurRvaLast, pThis->paSegs[iSeg].cb, pThis->paSegs[iSeg].pszName, iSeg),
     459                                  VERR_DBG_SEGMENT_INDEX_CONFLICT);
     460        if (uRvaLastMax < uCurRvaLast)
     461            uRvaLastMax = uCurRvaLast;
     462    }
     463    /* Strict ordered segment addition at the moment. */
     464    iSeg = pThis->cSegs;
     465    AssertMsgReturn(!piSeg || *piSeg == NIL_RTDBGSEGIDX || *piSeg == iSeg,
     466                    ("iSeg=%#x *piSeg=%#x\n", iSeg, *piSeg),
     467                    VERR_DBG_INVALID_SEGMENT_INDEX);
     468
     469    /*
     470     * Add an entry to the segment table, extending it if necessary.
     471     */
     472    if (!(iSeg % 8))
     473    {
     474        void *pvSegs = RTMemRealloc(pThis->paSegs, sizeof(RTDBGMODCTNSEGMENT) * (iSeg + 8));
     475        if (!pvSegs)
     476            return VERR_NO_MEMORY;
     477        pThis->paSegs = (PRTDBGMODCTNSEGMENT)pvSegs;
     478    }
     479
     480    pThis->paSegs[iSeg].SymAddrTree     = NULL;
     481    pThis->paSegs[iSeg].LineAddrTree    = NULL;
     482    pThis->paSegs[iSeg].off             = uRva;
     483    pThis->paSegs[iSeg].cb              = cb;
     484    pThis->paSegs[iSeg].fFlags          = fFlags;
     485    pThis->paSegs[iSeg].pszName         = RTStrCacheEnterN(g_hDbgModStrCache, pszName, cchName);
     486    if (pThis->paSegs[iSeg].pszName)
     487    {
     488        if (piSeg)
     489            *piSeg = iSeg;
     490        pThis->cSegs++;
     491        pThis->cb = uRvaLastMax + 1;
     492        if (!pThis->cb)
     493            pThis->cb = RTUINTPTR_MAX;
     494        return VINF_SUCCESS;
     495    }
     496    return VERR_NO_MEMORY;
     497}
     498
     499
     500/** @copydoc RTDBGMODVTDBG::pfnRvaToSegOff */
     501static DECLCALLBACK(RTUINTPTR) rtDbgModContainer_ImageSize(PRTDBGMODINT pMod)
     502{
     503    PRTDBGMODCTN pThis = (PRTDBGMODCTN)pMod->pvDbgPriv;
     504    return pThis->cb;
    407505}
    408506
     
    519617{
    520618    /*.u32Magic = */            RTDBGMODVTDBG_MAGIC,
    521     /*.fSupports = */           0, ///@todo iprt/types.h isn't up to date...
     619    /*.fSupports = */           0, /* (Don't call my TryOpen, please.) */
    522620    /*.pszName = */             "container",
    523621    /*.pfnTryOpen = */          rtDbgModContainer_TryOpen,
    524622    /*.pfnClose = */            rtDbgModContainer_Close,
     623
    525624    /*.pfnRvaToSegOff = */      rtDbgModContainer_RvaToSegOff,
    526 
    527     /*.pfnSegmentAdd = */       NULL,//rtDbgModContainer_SegmentAdd,
    528     /*.pfnSegmentCount = */     NULL,//rtDbgModContainer_SegmentCount,
    529     /*.pfnSegmentByIndex = */   NULL,//rtDbgModContainer_SegmentByIndex,
     625    /*.pfnImageSize = */        rtDbgModContainer_ImageSize,
     626
     627    /*.pfnSegmentAdd = */       rtDbgModContainer_SegmentAdd,
     628    /*.pfnSegmentCount = */     rtDbgModContainer_SegmentCount,
     629    /*.pfnSegmentByIndex = */   rtDbgModContainer_SegmentByIndex,
    530630
    531631    /*.pfnSymbolAdd = */        rtDbgModContainer_SymbolAdd,
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