VirtualBox

Ignore:
Timestamp:
May 15, 2009 11:37:31 PM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
47378
Message:

VMM,IPRT,DBGC: Debug address spaces.

Location:
trunk/src/VBox/Runtime/common/dbg
Files:
2 edited

Legend:

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

    r19566 r19757  
    3535#include <iprt/asm.h>
    3636#include <iprt/avl.h>
     37#include <iprt/assert.h>
     38#include <iprt/err.h>
     39#include <iprt/mem.h>
     40#include <iprt/param.h>
    3741#include <iprt/string.h>
    38 
    39 #include <iprt/mem.h>
    40 #include <iprt/err.h>
    41 #include <iprt/assert.h>
    42 #include <iprt/param.h>
    43 //#include "internal/dbg.h"
     42#include <iprt/semaphore.h>
    4443#include "internal/magics.h"
    4544
     
    102101    /** Magic value (RTDBGAS_MAGIC). */
    103102    uint32_t            u32Magic;
     103    /** The number of reference to this address space. */
     104    uint32_t volatile   cRefs;
     105    /** Handle of the read-write lock. */
     106    RTSEMRW             hLock;
    104107    /** Number of modules in the module address space. */
    105108    uint32_t            cModules;
     
    132135        AssertPtrReturn((pDbgAs), (rc)); \
    133136        AssertReturn((pDbgAs)->u32Magic == RTDBGAS_MAGIC, (rc)); \
     137        AssertReturn((pDbgAs)->cRefs > 0, (rc)); \
     138    } while (0)
     139
     140/** Locks the address space for reading. */
     141#define RTDBGAS_LOCK_READ(pDbgAs) \
     142    do { \
     143        int rcLock = RTSemRWRequestRead((pDbgAs)->hLock, RT_INDEFINITE_WAIT); \
     144        AssertRC(rcLock); \
     145    } while (0)
     146
     147/** Unlocks the address space after reading. */
     148#define RTDBGAS_UNLOCK_READ(pDbgAs) \
     149    do { \
     150        int rcLock = RTSemRWReleaseRead((pDbgAs)->hLock); \
     151        AssertRC(rcLock); \
     152    } while (0)
     153
     154/** Locks the address space for writing. */
     155#define RTDBGAS_LOCK_WRITE(pDbgAs) \
     156    do { \
     157        int rcLock = RTSemRWRequestWrite((pDbgAs)->hLock, RT_INDEFINITE_WAIT); \
     158        AssertRC(rcLock); \
     159    } while (0)
     160
     161/** Unlocks the address space after writing. */
     162#define RTDBGAS_UNLOCK_WRITE(pDbgAs) \
     163    do { \
     164        int rcLock = RTSemRWReleaseWrite((pDbgAs)->hLock); \
     165        AssertRC(rcLock); \
    134166    } while (0)
    135167
     
    139171*******************************************************************************/
    140172static void rtDbgAsModuleUnlinkMod(PRTDBGASINT pDbgAs, PRTDBGASMOD pMod);
     173static void rtDbgAsModuleUnlinkByMap(PRTDBGASINT pDbgAs, PRTDBGASMAP pMap);
    141174
    142175
     
    170203    /* initalize it. */
    171204    pDbgAs->u32Magic    = RTDBGAS_MAGIC;
     205    pDbgAs->cRefs       = 1;
     206    pDbgAs->hLock       = NIL_RTSEMRW;
    172207    pDbgAs->cModules    = 0;
    173208    pDbgAs->paModules   = NULL;
     
    178213    pDbgAs->LastAddr    = LastAddr;
    179214    memcpy(pDbgAs->szName, pszName, cchName + 1);
    180 
    181     *phDbgAs = pDbgAs;
    182     return VINF_SUCCESS;
     215    int rc = RTSemRWCreate(&pDbgAs->hLock);
     216    if (RT_SUCCESS(rc))
     217    {
     218        *phDbgAs = pDbgAs;
     219        return VINF_SUCCESS;
     220    }
     221
     222    pDbgAs->u32Magic = 0;
     223    RTMemFree(pDbgAs);
     224    return rc;
    183225}
    184226
     
    269311 * reference counting.
    270312 *
    271  * @returns IPRT status code.
    272  *
    273  * @param   hDbgAs          The address space handle. A NIL handle will
    274  *                          be quietly ignored.
    275  */
    276 RTDECL(int) RTDbgAsDestroy(RTDBGAS hDbgAs)
    277 {
    278     /*
    279      * Validate input.
    280      */
    281     if (hDbgAs == NIL_RTDBGAS)
    282         return VINF_SUCCESS;
    283     PRTDBGASINT pDbgAs = hDbgAs;
    284     RTDBGAS_VALID_RETURN_RC(pDbgAs, VERR_INVALID_HANDLE);
    285 
     313 * @param   pDbgAs          The address space instance to be destroyed.
     314 */
     315static void rtDbgAsDestroy(PRTDBGASINT pDbgAs)
     316{
    286317    /*
    287318     * Mark the address space invalid and release all the modules.
     
    302333
    303334    RTMemFree(pDbgAs);
    304 
    305     return VINF_SUCCESS;
     335}
     336
     337
     338/**
     339 * Retains a reference to the address space.
     340 *
     341 * @returns New reference count, UINT32_MAX on invalid handle (asserted).
     342 *
     343 * @param   hDbgAs          The address space handle.
     344 *
     345 * @remarks Will not take any locks.
     346 */
     347RTDECL(uint32_t) RTDbgAsRetain(RTDBGAS hDbgAs)
     348{
     349    PRTDBGASINT pDbgAs = hDbgAs;
     350    RTDBGAS_VALID_RETURN_RC(pDbgAs, UINT32_MAX);
     351    return ASMAtomicIncU32(&pDbgAs->cRefs);
     352}
     353
     354
     355/**
     356 * Release a reference to the address space.
     357 *
     358 * When the reference count reaches zero, the address space is destroyed.
     359 * That means unlinking all the modules it currently contains, potentially
     360 * causing some or all of them to be destroyed as they are managed by
     361 * reference counting.
     362 *
     363 * @returns New reference count, UINT32_MAX on invalid handle (asserted).
     364 *
     365 * @param   hDbgAs          The address space handle. The NIL handle is quietly
     366 *                          ignored and 0 is returned.
     367 *
     368 * @remarks Will not take any locks.
     369 */
     370RTDECL(uint32_t) RTDbgAsRelease(RTDBGAS hDbgAs)
     371{
     372    if (hDbgAs == NIL_RTDBGAS)
     373        return 0;
     374    PRTDBGASINT pDbgAs = hDbgAs;
     375    RTDBGAS_VALID_RETURN_RC(pDbgAs, UINT32_MAX);
     376
     377    uint32_t cRefs = ASMAtomicDecU32(&pDbgAs->cRefs);
     378    if (!cRefs)
     379        rtDbgAsDestroy(pDbgAs);
     380    return cRefs;
    306381}
    307382
     
    314389 *
    315390 * @param   hDbgAs          The address space handle.
     391 *
     392 * @remarks Will not take any locks.
    316393 */
    317394RTDECL(const char *) RTDbgAsName(RTDBGAS hDbgAs)
     
    330407 *
    331408 * @param   hDbgAs          The address space handle.
     409 *
     410 * @remarks Will not take any locks.
    332411 */
    333412RTDECL(RTUINTPTR) RTDbgAsFirstAddr(RTDBGAS hDbgAs)
     
    346425 *
    347426 * @param   hDbgAs          The address space handle.
     427 *
     428 * @remarks Will not take any locks.
    348429 */
    349430RTDECL(RTUINTPTR) RTDbgAsLastAddr(RTDBGAS hDbgAs)
     
    363444 *
    364445 * @param   hDbgAs          The address space handle.
    365  */
    366 RTDECL(uint32_t)    RTDbgAsModuleCount(RTDBGAS hDbgAs)
     446 *
     447 * @remarks Will not take any locks.
     448 */
     449RTDECL(uint32_t) RTDbgAsModuleCount(RTDBGAS hDbgAs)
    367450{
    368451    PRTDBGASINT pDbgAs = hDbgAs;
     
    382465 * @param   cb              The size of what we're linking.
    383466 * @param   pszName         The name of the module.
     467 * @param   fFlags          See RTDBGASLINK_FLAGS_*.
     468 *
     469 * @remarks The caller must have locked the address space for writing.
    384470 */
    385471int rtDbgAsModuleLinkCommon(PRTDBGASINT pDbgAs, RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg,
    386                             RTUINTPTR Addr, RTUINTPTR cb, const char *pszName)
     472                            RTUINTPTR Addr, RTUINTPTR cb, const char *pszName, uint32_t fFlags)
    387473{
    388474    /*
    389475     * Check that the requested space is undisputed.
    390476     */
    391    PRTDBGASMAP pAdjMod = (PRTDBGASMAP)RTAvlrUIntPtrGetBestFit(&pDbgAs->MapTree, Addr, false /* fAbove */);
    392    if (     pAdjMod
    393        &&   pAdjMod->Core.KeyLast >= Addr)
    394        return VERR_ADDRESS_CONFLICT;
    395    pAdjMod = (PRTDBGASMAP)RTAvlrUIntPtrGetBestFit(&pDbgAs->MapTree, Addr, true /* fAbove */);
    396    if (     pAdjMod
    397        &&   pAdjMod->Core.Key >= Addr + cb - 1)
    398        return VERR_ADDRESS_CONFLICT;
     477    for (;;)
     478    {
     479        PRTDBGASMAP pAdjMod = (PRTDBGASMAP)RTAvlrUIntPtrGetBestFit(&pDbgAs->MapTree, Addr, false /* fAbove */);
     480        if (     pAdjMod
     481            &&   pAdjMod->Core.KeyLast >= Addr)
     482        {
     483            if (!(fFlags & RTDBGASLINK_FLAGS_REPLACE))
     484                return VERR_ADDRESS_CONFLICT;
     485            rtDbgAsModuleUnlinkByMap(pDbgAs, pAdjMod);
     486            continue;
     487        }
     488        pAdjMod = (PRTDBGASMAP)RTAvlrUIntPtrGetBestFit(&pDbgAs->MapTree, Addr, true /* fAbove */);
     489        if (     pAdjMod
     490            &&   pAdjMod->Core.Key >= Addr + cb - 1)
     491        {
     492            if (!(fFlags & RTDBGASLINK_FLAGS_REPLACE))
     493                return VERR_ADDRESS_CONFLICT;
     494            rtDbgAsModuleUnlinkByMap(pDbgAs, pAdjMod);
     495            continue;
     496        }
     497        break;
     498    }
    399499
    400500    /*
     
    491591
    492592
    493 
    494 
    495593/**
    496594 * Links a module into the address space at the give address.
     
    506604 * @param   hDbgMod         The module handle of the module to be linked in.
    507605 * @param   ImageAddr       The address to link the module at.
    508  */
    509 RTDECL(int) RTDbgAsModuleLink(RTDBGAS hDbgAs, RTDBGMOD hDbgMod, RTUINTPTR ImageAddr)
     606 * @param   fFlags          See RTDBGASLINK_FLAGS_*.
     607 */
     608RTDECL(int) RTDbgAsModuleLink(RTDBGAS hDbgAs, RTDBGMOD hDbgMod, RTUINTPTR ImageAddr, uint32_t fFlags)
    510609{
    511610    /*
     
    526625        ||  ImageAddr + cb - 1  < ImageAddr)
    527626        return VERR_OUT_OF_RANGE;
     627    AssertReturn(!(fFlags & ~RTDBGASLINK_FLAGS_VALID_MASK), VERR_INVALID_PARAMETER);
    528628
    529629    /*
    530630     * Invoke worker common with RTDbgAsModuleLinkSeg.
    531631     */
    532     return rtDbgAsModuleLinkCommon(pDbgAs, hDbgMod, NIL_RTDBGSEGIDX, ImageAddr, cb, pszName);
     632    RTDBGAS_LOCK_WRITE(pDbgAs);
     633    int rc = rtDbgAsModuleLinkCommon(pDbgAs, hDbgMod, NIL_RTDBGSEGIDX, ImageAddr, cb, pszName, fFlags);
     634    RTDBGAS_UNLOCK_WRITE(pDbgAs);
     635    return rc;
    533636}
    534637
     
    549652 *                          linked in.
    550653 * @param   SegAddr         The address to link the segment at.
    551  */
    552 RTDECL(int) RTDbgAsModuleLinkSeg(RTDBGAS hDbgAs, RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg, RTUINTPTR SegAddr)
     654 * @param   fFlags          See RTDBGASLINK_FLAGS_*.
     655 */
     656RTDECL(int) RTDbgAsModuleLinkSeg(RTDBGAS hDbgAs, RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg, RTUINTPTR SegAddr, uint32_t fFlags)
    553657{
    554658    /*
     
    569673        ||  SegAddr + cb - 1  < SegAddr)
    570674        return VERR_OUT_OF_RANGE;
     675    AssertReturn(!(fFlags & ~RTDBGASLINK_FLAGS_VALID_MASK), VERR_INVALID_PARAMETER);
    571676
    572677    /*
    573678     * Invoke worker common with RTDbgAsModuleLinkSeg.
    574679     */
    575     return rtDbgAsModuleLinkCommon(pDbgAs, hDbgMod, iSeg, SegAddr, cb, pszName);
     680    RTDBGAS_LOCK_WRITE(pDbgAs);
     681    int rc = rtDbgAsModuleLinkCommon(pDbgAs, hDbgMod, iSeg, SegAddr, cb, pszName, fFlags);
     682    RTDBGAS_UNLOCK_WRITE(pDbgAs);
     683    return rc;
    576684}
    577685
     
    582690 * @param   pDbgAs          Pointer to the address space instance data.
    583691 * @param   pMod            The module to unlink.
     692 *
     693 * @remarks The caller must have locked the address space for writing.
    584694 */
    585695static void rtDbgAsModuleUnlinkMod(PRTDBGASINT pDbgAs, PRTDBGASMOD pMod)
     
    636746 * @param   pDbgAs          Pointer to the address space instance data.
    637747 * @param   pMap            The map to unlink and free.
     748 *
     749 * @remarks The caller must have locked the address space for writing.
    638750 */
    639751static void rtDbgAsModuleUnlinkMap(PRTDBGASINT pDbgAs, PRTDBGASMAP pMap)
     
    669781
    670782/**
    671  * Unlinks all the mappings of a module from the address space.
    672  *
    673  * @returns IPRT status code.
    674  * @retval  VERR_NOT_FOUND if the module wasn't found.
    675  *
    676  * @param   hDbgAs          The address space handle.
    677  * @param   hDbgMod         The module handle of the module to be unlinked.
    678  */
    679 RTDECL(int) RTDbgAsModuleUnlink(RTDBGAS hDbgAs, RTDBGMOD hDbgMod)
    680 {
    681     /*
    682      * Validate input.
    683      */
    684     PRTDBGASINT pDbgAs = hDbgAs;
    685     RTDBGAS_VALID_RETURN_RC(pDbgAs, VERR_INVALID_HANDLE);
    686     if (hDbgMod == NIL_RTDBGMOD)
    687         return VINF_SUCCESS;
    688 
    689     PRTDBGASMOD pMod = (PRTDBGASMOD)RTAvlPVGet(&pDbgAs->ModTree, hDbgMod);
    690     if (!pMod)
    691         return VERR_NOT_FOUND;
    692 
    693     /*
    694      * Unmap all but
    695      */
    696     while (pMod->pMapHead)
    697         rtDbgAsModuleUnlinkMap(pDbgAs, pMod->pMapHead);
    698     rtDbgAsModuleUnlinkMod(pDbgAs, pMod);
    699     return VINF_SUCCESS;
    700 }
    701 
    702 
    703 /**
    704  * Unlinks the mapping at the specified address.
    705  *
    706  * @returns IPRT status code.
    707  * @retval  VERR_NOT_FOUND if no module or segment is mapped at that address.
    708  *
    709  * @param   hDbgAs          The address space handle.
    710  * @param   Addr            The address within the mapping to be unlinked.
    711  */
    712 RTDECL(int) RTDbgAsModuleUnlinkByAddr(RTDBGAS hDbgAs, RTUINTPTR Addr)
    713 {
    714     /*
    715      * Validate input.
    716      */
    717     PRTDBGASINT pDbgAs = hDbgAs;
    718     RTDBGAS_VALID_RETURN_RC(pDbgAs, VERR_INVALID_HANDLE);
    719     PRTDBGASMAP pMap = (PRTDBGASMAP)RTAvlrUIntPtrRangeGet(&pDbgAs->MapTree, Addr);
    720     if (pMap)
    721         return VERR_NOT_FOUND;
    722 
     783 * Worker for RTDbgAsModuleUnlinkByAddr and rtDbgAsModuleLinkCommon that
     784 * unlinks a single mapping and releases the module if it's the last one.
     785 *
     786 * @param   pDbgAs      The address space instance.
     787 * @param   pMap        The mapping to unlink.
     788 *
     789 * @remarks The caller must have locked the address space for writing.
     790 */
     791static void rtDbgAsModuleUnlinkByMap(PRTDBGASINT pDbgAs, PRTDBGASMAP pMap)
     792{
    723793    /*
    724794     * Unlink it from the address space.
     
    729799    if (!pMod->pMapHead)
    730800        rtDbgAsModuleUnlinkMod(pDbgAs, pMod);
     801}
     802
     803
     804/**
     805 * Unlinks all the mappings of a module from the address space.
     806 *
     807 * @returns IPRT status code.
     808 * @retval  VERR_NOT_FOUND if the module wasn't found.
     809 *
     810 * @param   hDbgAs          The address space handle.
     811 * @param   hDbgMod         The module handle of the module to be unlinked.
     812 */
     813RTDECL(int) RTDbgAsModuleUnlink(RTDBGAS hDbgAs, RTDBGMOD hDbgMod)
     814{
     815    /*
     816     * Validate input.
     817     */
     818    PRTDBGASINT pDbgAs = hDbgAs;
     819    RTDBGAS_VALID_RETURN_RC(pDbgAs, VERR_INVALID_HANDLE);
     820    if (hDbgMod == NIL_RTDBGMOD)
     821        return VINF_SUCCESS;
     822
     823    RTDBGAS_LOCK_WRITE(pDbgAs);
     824    PRTDBGASMOD pMod = (PRTDBGASMOD)RTAvlPVGet(&pDbgAs->ModTree, hDbgMod);
     825    if (!pMod)
     826    {
     827        RTDBGAS_UNLOCK_WRITE(pDbgAs);
     828        return VERR_NOT_FOUND;
     829    }
     830
     831    /*
     832     * Unmap all everything and release the module.
     833     */
     834    while (pMod->pMapHead)
     835        rtDbgAsModuleUnlinkMap(pDbgAs, pMod->pMapHead);
     836    rtDbgAsModuleUnlinkMod(pDbgAs, pMod);
     837
     838    RTDBGAS_UNLOCK_WRITE(pDbgAs);
     839    return VINF_SUCCESS;
     840}
     841
     842
     843/**
     844 * Unlinks the mapping at the specified address.
     845 *
     846 * @returns IPRT status code.
     847 * @retval  VERR_NOT_FOUND if no module or segment is mapped at that address.
     848 *
     849 * @param   hDbgAs          The address space handle.
     850 * @param   Addr            The address within the mapping to be unlinked.
     851 */
     852RTDECL(int) RTDbgAsModuleUnlinkByAddr(RTDBGAS hDbgAs, RTUINTPTR Addr)
     853{
     854    /*
     855     * Validate input.
     856     */
     857    PRTDBGASINT pDbgAs = hDbgAs;
     858    RTDBGAS_VALID_RETURN_RC(pDbgAs, VERR_INVALID_HANDLE);
     859
     860    RTDBGAS_LOCK_WRITE(pDbgAs);
     861    PRTDBGASMAP pMap = (PRTDBGASMAP)RTAvlrUIntPtrRangeGet(&pDbgAs->MapTree, Addr);
     862    if (pMap)
     863    {
     864        RTDBGAS_UNLOCK_WRITE(pDbgAs);
     865        return VERR_NOT_FOUND;
     866    }
     867
     868    /*
     869     * Hand it to
     870     */
     871    rtDbgAsModuleUnlinkByMap(pDbgAs, pMap);
     872
     873    RTDBGAS_UNLOCK_WRITE(pDbgAs);
    731874    return VINF_SUCCESS;
    732875}
     
    754897    PRTDBGASINT pDbgAs = hDbgAs;
    755898    RTDBGAS_VALID_RETURN_RC(pDbgAs, NIL_RTDBGMOD);
     899
     900    RTDBGAS_LOCK_READ(pDbgAs);
    756901    if (iModule >= pDbgAs->cModules)
     902    {
     903        RTDBGAS_UNLOCK_READ(pDbgAs);
    757904        return NIL_RTDBGMOD;
     905    }
    758906
    759907    /*
     
    762910    RTDBGMOD hMod = (RTDBGMOD)pDbgAs->paModules[iModule].Core.Key;
    763911    RTDbgModRetain(hMod);
     912
     913    RTDBGAS_UNLOCK_READ(pDbgAs);
    764914    return hMod;
    765915}
     
    789939    PRTDBGASINT pDbgAs = hDbgAs;
    790940    RTDBGAS_VALID_RETURN_RC(pDbgAs, VERR_INVALID_HANDLE);
     941
     942    RTDBGAS_LOCK_READ(pDbgAs);
    791943    PRTDBGASMAP pMap = (PRTDBGASMAP)RTAvlrUIntPtrRangeGet(&pDbgAs->MapTree, Addr);
    792944    if (pMap)
     945    {
     946        RTDBGAS_UNLOCK_READ(pDbgAs);
    793947        return VERR_NOT_FOUND;
     948    }
    794949
    795950    /*
     
    806961    if (piSeg)
    807962        *piSeg = pMap->iSeg;
     963
     964    RTDBGAS_UNLOCK_READ(pDbgAs);
    808965    return VINF_SUCCESS;
    809966}
     
    832989    RTDBGAS_VALID_RETURN_RC(pDbgAs, VERR_INVALID_HANDLE);
    833990    AssertPtrReturn(phMod, VERR_INVALID_POINTER);
     991
     992    RTDBGAS_LOCK_READ(pDbgAs);
    834993    PRTDBGASNAME pName = (PRTDBGASNAME)RTStrSpaceGet(&pDbgAs->NameSpace, pszName);
    835994    if (!pName)
     995    {
     996        RTDBGAS_UNLOCK_READ(pDbgAs);
    836997        return VERR_NOT_FOUND;
     998    }
    837999
    8381000    PRTDBGASMOD pMod = pName->pHead;
     
    8411003        pMod = pMod->pNextName;
    8421004        if (!pMod)
     1005        {
     1006            RTDBGAS_UNLOCK_READ(pDbgAs);
    8431007            return VERR_OUT_OF_RANGE;
     1008        }
    8441009    }
    8451010
     
    8501015    RTDbgModRetain(hMod);
    8511016    *phMod = hMod;
     1017
     1018    RTDBGAS_UNLOCK_READ(pDbgAs);
    8521019    return VINF_SUCCESS;
     1020}
     1021
     1022
     1023/**
     1024 * Internal worker that looks up and retains a module.
     1025 *
     1026 * @returns Module handle, NIL_RTDBGMOD if not found.
     1027 * @param   pDbgAs          The address space instance data.
     1028 * @param   Addr            Address within the module.
     1029 * @param   piSeg           where to return the segment index.
     1030 * @param   poffSeg         Where to return the segment offset.
     1031 */
     1032DECLINLINE(RTDBGMOD) rtDbgAsModuleByAddr(PRTDBGASINT pDbgAs, RTUINTPTR Addr, PRTDBGSEGIDX piSeg, PRTUINTPTR poffSeg)
     1033{
     1034    RTDBGMOD hMod = NIL_RTDBGMOD;
     1035
     1036    RTDBGAS_LOCK_READ(pDbgAs);
     1037    PRTDBGASMAP pMap = (PRTDBGASMAP)RTAvlrUIntPtrRangeGet(&pDbgAs->MapTree, Addr);
     1038    if (pMap)
     1039    {
     1040        hMod = (RTDBGMOD)pMap->pMod->Core.Key;
     1041        RTDbgModRetain(hMod);
     1042        *piSeg = pMap->iSeg;
     1043        *poffSeg = Addr - pMap->Core.Key;
     1044    }
     1045    RTDBGAS_UNLOCK_READ(pDbgAs);
     1046
     1047    return hMod;
    8531048}
    8541049
     
    8691064{
    8701065    /*
    871      * Validate input.
     1066    * Validate input and resolve the address.
    8721067     */
    8731068    PRTDBGASINT pDbgAs = hDbgAs;
    8741069    RTDBGAS_VALID_RETURN_RC(pDbgAs, VERR_INVALID_HANDLE);
    875     PRTDBGASMAP pMap = (PRTDBGASMAP)RTAvlrUIntPtrRangeGet(&pDbgAs->MapTree, Addr);
    876     if (pMap)
     1070
     1071    RTDBGSEGIDX iSeg;
     1072    RTUINTPTR offSeg;
     1073    RTDBGMOD hMod = rtDbgAsModuleByAddr(pDbgAs, Addr, &iSeg, &offSeg);
     1074    if (hMod == NIL_RTDBGMOD)
    8771075        return VERR_NOT_FOUND;
    8781076
     
    8801078     * Forward the call.
    8811079     */
    882     RTDBGMOD hMod = (RTDBGMOD)pMap->pMod->Core.Key;
    883     return RTDbgModSymbolAdd(hMod, pszSymbol, pMap->iSeg, Addr - pMap->Core.Key, cb);
     1080    int rc = RTDbgModSymbolAdd(hMod, pszSymbol, iSeg, offSeg, cb);
     1081    RTDbgModRelease(hMod);
     1082    return rc;
    8841083}
    8851084
     
    9011100{
    9021101    /*
    903      * Validate input.
     1102     * Validate input and resolve the address.
    9041103     */
    9051104    PRTDBGASINT pDbgAs = hDbgAs;
    9061105    RTDBGAS_VALID_RETURN_RC(pDbgAs, VERR_INVALID_HANDLE);
    907     PRTDBGASMAP pMap = (PRTDBGASMAP)RTAvlrUIntPtrRangeGet(&pDbgAs->MapTree, Addr);
    908     if (pMap)
     1106
     1107    RTDBGSEGIDX iSeg;
     1108    RTUINTPTR offSeg;
     1109    RTDBGMOD hMod = rtDbgAsModuleByAddr(pDbgAs, Addr, &iSeg, &offSeg);
     1110    if (hMod == NIL_RTDBGMOD)
    9091111        return VERR_NOT_FOUND;
    9101112
     
    9121114     * Forward the call.
    9131115     */
    914     RTDBGMOD hMod = (RTDBGMOD)pMap->pMod->Core.Key;
    915     return RTDbgModSymbolByAddr(hMod, pMap->iSeg, Addr - pMap->Core.Key, poffDisp, pSymbol);
     1116    int rc = RTDbgModSymbolByAddr(hMod, iSeg, offSeg, poffDisp, pSymbol);
     1117    RTDbgModRelease(hMod);
     1118    return rc;
    9161119}
    9171120
     
    9341137{
    9351138    /*
    936      * Validate input.
     1139     * Validate input and resolve the address.
    9371140     */
    9381141    PRTDBGASINT pDbgAs = hDbgAs;
    9391142    RTDBGAS_VALID_RETURN_RC(pDbgAs, VERR_INVALID_HANDLE);
    940     PRTDBGASMAP pMap = (PRTDBGASMAP)RTAvlrUIntPtrRangeGet(&pDbgAs->MapTree, Addr);
    941     if (pMap)
     1143
     1144    RTDBGSEGIDX iSeg;
     1145    RTUINTPTR offSeg;
     1146    RTDBGMOD hMod = rtDbgAsModuleByAddr(pDbgAs, Addr, &iSeg, &offSeg);
     1147    if (hMod == NIL_RTDBGMOD)
    9421148        return VERR_NOT_FOUND;
    9431149
     
    9451151     * Forward the call.
    9461152     */
    947     RTDBGMOD hMod = (RTDBGMOD)pMap->pMod->Core.Key;
    948     return RTDbgModSymbolByAddrA(hMod, pMap->iSeg, Addr - pMap->Core.Key, poffDisp, ppSymbol);
     1153    int rc = RTDbgModSymbolByAddrA(hMod, iSeg, offSeg, poffDisp, ppSymbol);
     1154    RTDbgModRelease(hMod);
     1155    return rc;
     1156}
     1157
     1158
     1159/**
     1160 * Creates a snapshot of the module table on the temporary heap.
     1161 *
     1162 * The caller must release all the module handles before freeing the table
     1163 * using RTMemTmpFree.
     1164 *
     1165 * @returns Module table snaphot.
     1166 * @param   pDbgAs          The address space instance data.
     1167 * @param   pcModules       Where to return the number of modules.
     1168 */
     1169DECLINLINE(PRTDBGMOD) rtDbgAsSnapshotModuleTable(PRTDBGASINT pDbgAs, uint32_t *pcModules)
     1170{
     1171    RTDBGAS_LOCK_READ(pDbgAs);
     1172
     1173    uint32_t iMod = *pcModules = pDbgAs->cModules;
     1174    PRTDBGMOD paModules = (PRTDBGMOD)RTMemTmpAlloc(sizeof(paModules[0]) * RT_MAX(iMod, 1));
     1175    if (paModules)
     1176    {
     1177        while (iMod-- > 0)
     1178        {
     1179            RTDBGMOD hMod = paModules[iMod];
     1180            paModules[iMod] = hMod;
     1181            RTDbgModRetain(hMod);
     1182        }
     1183    }
     1184
     1185    RTDBGAS_UNLOCK_READ(pDbgAs);
     1186    return paModules;
    9491187}
    9501188
     
    9731211     * Iterate the modules, looking for the symbol.
    9741212     */
    975     for (uint32_t i = 0; i < pDbgAs->cModules; i++)
    976     {
    977         RTDBGMOD hMod = (RTDBGMOD)pDbgAs->paModules[i].Core.Key;
    978         int rc = RTDbgModSymbolByName(hMod, pszSymbol, pSymbol);
     1213    uint32_t cModules;
     1214    PRTDBGMOD paModules = rtDbgAsSnapshotModuleTable(pDbgAs, &cModules);
     1215    if (!paModules)
     1216        return VERR_NO_TMP_MEMORY;
     1217
     1218    for (uint32_t i = 0; i < cModules; i++)
     1219    {
     1220        int rc = RTDbgModSymbolByName(paModules[i], pszSymbol, pSymbol);
     1221        RTDbgModRelease(paModules[i]);
    9791222        if (RT_SUCCESS(rc))
     1223        {
     1224            for (i = i + 1; i < cModules; i++)
     1225                RTDbgModRelease(paModules[i]);
     1226            RTMemTmpFree(paModules);
    9801227            return rc;
    981     }
     1228        }
     1229    }
     1230
     1231    RTMemTmpFree(paModules);
    9821232    return VERR_SYMBOL_NOT_FOUND;
    9831233}
     
    10091259     * Iterate the modules, looking for the symbol.
    10101260     */
    1011     for (uint32_t i = 0; i < pDbgAs->cModules; i++)
    1012     {
    1013         RTDBGMOD hMod = (RTDBGMOD)pDbgAs->paModules[i].Core.Key;
    1014         int rc = RTDbgModSymbolByNameA(hMod, pszSymbol, ppSymbol);
     1261    uint32_t cModules;
     1262    PRTDBGMOD paModules = rtDbgAsSnapshotModuleTable(pDbgAs, &cModules);
     1263    if (!paModules)
     1264        return VERR_NO_TMP_MEMORY;
     1265
     1266    for (uint32_t i = 0; i < cModules; i++)
     1267    {
     1268        int rc = RTDbgModSymbolByNameA(paModules[i], pszSymbol, ppSymbol);
     1269        RTDbgModRelease(paModules[i]);
    10151270        if (RT_SUCCESS(rc))
     1271        {
     1272            for (i = i + 1; i < cModules; i++)
     1273                RTDbgModRelease(paModules[i]);
     1274            RTMemTmpFree(paModules);
    10161275            return rc;
    1017     }
     1276        }
     1277    }
     1278
     1279    RTMemTmpFree(paModules);
    10181280    return VERR_SYMBOL_NOT_FOUND;
    10191281}
     
    10361298{
    10371299    /*
    1038      * Validate input.
     1300     * Validate input and resolve the address.
    10391301     */
    10401302    PRTDBGASINT pDbgAs = hDbgAs;
    10411303    RTDBGAS_VALID_RETURN_RC(pDbgAs, VERR_INVALID_HANDLE);
    1042     PRTDBGASMAP pMap = (PRTDBGASMAP)RTAvlrUIntPtrRangeGet(&pDbgAs->MapTree, Addr);
    1043     if (pMap)
     1304
     1305    RTDBGSEGIDX iSeg;
     1306    RTUINTPTR offSeg;
     1307    RTDBGMOD hMod = rtDbgAsModuleByAddr(pDbgAs, Addr, &iSeg, &offSeg);
     1308    if (hMod == NIL_RTDBGMOD)
    10441309        return VERR_NOT_FOUND;
    10451310
     
    10471312     * Forward the call.
    10481313     */
    1049     RTDBGMOD hMod = (RTDBGMOD)pMap->pMod->Core.Key;
    1050     return RTDbgModLineByAddr(hMod, pMap->iSeg, Addr - pMap->Core.Key, poffDisp, pLine);
     1314    int rc = RTDbgModLineByAddr(hMod, iSeg, offSeg, poffDisp, pLine);
     1315    RTDbgModRelease(hMod);
     1316    return rc;
    10511317}
    10521318
     
    10691335{
    10701336    /*
    1071      * Validate input.
     1337     * Validate input and resolve the address.
    10721338     */
    10731339    PRTDBGASINT pDbgAs = hDbgAs;
    10741340    RTDBGAS_VALID_RETURN_RC(pDbgAs, VERR_INVALID_HANDLE);
    1075     PRTDBGASMAP pMap = (PRTDBGASMAP)RTAvlrUIntPtrRangeGet(&pDbgAs->MapTree, Addr);
    1076     if (pMap)
     1341
     1342    RTDBGSEGIDX iSeg;
     1343    RTUINTPTR offSeg;
     1344    RTDBGMOD hMod = rtDbgAsModuleByAddr(pDbgAs, Addr, &iSeg, &offSeg);
     1345    if (hMod == NIL_RTDBGMOD)
    10771346        return VERR_NOT_FOUND;
    10781347
     
    10801349     * Forward the call.
    10811350     */
    1082     RTDBGMOD hMod = (RTDBGMOD)pMap->pMod->Core.Key;
    1083     return RTDbgModLineByAddrA(hMod, pMap->iSeg, Addr - pMap->Core.Key, poffDisp, ppLine);
    1084 }
    1085 
     1351    int rc = RTDbgModLineByAddrA(hMod, iSeg, offSeg, poffDisp, ppLine);
     1352    RTDbgModRelease(hMod);
     1353    return rc;
     1354}
     1355
  • trunk/src/VBox/Runtime/common/dbg/dbgmod.cpp

    r19566 r19757  
    4545
    4646
    47 RTDECL(int)         RTDbgModCreate(PRTDBGMOD phDbgMod, const char *pszName, const char *pszImgFile, const char *pszDbgFile)
     47RTDECL(int)         RTDbgModCreate(PRTDBGMOD phDbgMod, const char *pszName, RTUINTPTR cb, uint32_t fFlags)
     48{
     49    return VERR_NOT_IMPLEMENTED;
     50}
     51
     52RTDECL(int)         RTDbgModCreateFromImage(PRTDBGMOD phDbgMod, const char *pszFilename, const char *pszName, uint32_t fFlags)
     53{
     54    return VERR_NOT_IMPLEMENTED;
     55}
     56
     57RTDECL(int)         RTDbgModCreateFromMap(PRTDBGMOD phDbgMod, const char *pszFilename, const char *pszName, RTUINTPTR uSubtrahend, uint32_t fFlags)
    4858{
    4959    return VERR_NOT_IMPLEMENTED;
Note: See TracChangeset for help on using the changeset viewer.

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