VirtualBox

Changeset 20355 in vbox for trunk


Ignore:
Timestamp:
Jun 7, 2009 9:11:41 AM (16 years ago)
Author:
vboxsync
Message:

IPRT: some dbgmod bits.

Location:
trunk/src/VBox/Runtime
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/Makefile.kmk

    r20236 r20355  
    202202        common/dbg/dbgas.cpp \
    203203        common/dbg/dbgmod.cpp \
     204        common/dbg/dbgmodcontainer.cpp \
    204205        common/err/errmsg.cpp \
    205206        common/err/RTErrConvertFromErrno.cpp \
  • trunk/src/VBox/Runtime/common/dbg/dbgas.cpp

    r19757 r20355  
    130130*   Defined Constants And Macros                                               *
    131131*******************************************************************************/
    132 /** Validates a context handle and returns rc if not valid. */
     132/** Validates an address space handle and returns rc if not valid. */
    133133#define RTDBGAS_VALID_RETURN_RC(pDbgAs, rc) \
    134134    do { \
     
    337337
    338338/**
    339  * Retains a reference to the address space.
     339 * Retains another reference to the address space.
    340340 *
    341341 * @returns New reference count, UINT32_MAX on invalid handle (asserted).
  • trunk/src/VBox/Runtime/common/dbg/dbgmod.cpp

    r19757 r20355  
    3333*******************************************************************************/
    3434#include <iprt/dbg.h>
     35
    3536#include <iprt/asm.h>
     37#include <iprt/assert.h>
    3638#include <iprt/avl.h>
     39#include <iprt/err.h>
     40#include <iprt/initterm.h>
     41#include <iprt/mem.h>
     42#include <iprt/once.h>
     43#include <iprt/param.h>
     44#include <iprt/semaphore.h>
    3745#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>
    4346#include "internal/dbgmod.h"
    4447#include "internal/magics.h"
    4548
    4649
    47 RTDECL(int)         RTDbgModCreate(PRTDBGMOD phDbgMod, const char *pszName, RTUINTPTR cb, uint32_t fFlags)
    48 {
    49     return VERR_NOT_IMPLEMENTED;
     50/*******************************************************************************
     51*   Structures and Typedefs                                                    *
     52*******************************************************************************/
     53/** Debug info interpreter regisration record. */
     54typedef struct RTDBGMODREGDBG
     55{
     56    /** Pointer to the next record. */
     57    struct RTDBGMODREGDBG  *pNext;
     58    /** Pointer to the virtual function table for the interpreter.  */
     59    PCRTDBGMODVTDBG         pVt;
     60    /** Usage counter.  */
     61    uint32_t volatile       cUsers;
     62} RTDBGMODREGDBG;
     63typedef RTDBGMODREGDBG *PRTDBGMODREGDBG;
     64
     65/** Image interpreter regisration record. */
     66typedef struct RTDBGMODREGIMG
     67{
     68    /** Pointer to the next record. */
     69    struct RTDBGMODREGIMG  *pNext;
     70    /** Pointer to the virtual function table for the interpreter.  */
     71    PCRTDBGMODVTIMG         pVt;
     72    /** Usage counter.  */
     73    uint32_t volatile       cUsers;
     74} RTDBGMODREGIMG;
     75typedef RTDBGMODREGIMG *PRTDBGMODREGIMG;
     76
     77
     78/*******************************************************************************
     79*   Defined Constants And Macros                                               *
     80*******************************************************************************/
     81/** Validates a debug module handle and returns rc if not valid. */
     82#define RTDBGMOD_VALID_RETURN_RC(pDbgMod, rc) \
     83    do { \
     84        AssertPtrReturn((pDbgMod), (rc)); \
     85        AssertReturn((pDbgMod)->u32Magic == RTDBGMOD_MAGIC, (rc)); \
     86        AssertReturn((pDbgMod)->cRefs > 0, (rc)); \
     87    } while (0)
     88
     89/** Locks the debug module. */
     90#define RTDBGMOD_LOCK(pDbgMod) \
     91    do { \
     92        int rcLock = RTCritSectEnter(&(pDbgMod)->CritSect); \
     93        AssertRC(rcLock); \
     94    } while (0)
     95
     96/** Unlocks the debug module. */
     97#define RTDBGMOD_UNLOCK(pDbgMod) \
     98    do { \
     99        int rcLock = RTCritSectLeave(&(pDbgMod)->CritSect); \
     100        AssertRC(rcLock); \
     101    } while (0)
     102
     103
     104/*******************************************************************************
     105*   Global Variables                                                           *
     106*******************************************************************************/
     107/** Init once object for lazy registration of the built-in image and debug
     108 * info interpreters. */
     109static RTONCE           g_rtDbgModOnce = RTONCE_INITIALIZER;
     110/** Read/Write semaphore protecting the list of registered interpreters.  */
     111static RTSEMRW          g_hDbgModRWSem = NIL_RTSEMRW;
     112/** List of registered image interpreters.  */
     113static RTDBGMODREGIMG   g_pImgHead;
     114/** List of registered debug infor interpreters.  */
     115static RTDBGMODREGDBG   g_pDbgHead;
     116
     117
     118
     119/**
     120 * Do-once callback that initializes the read/write semaphore and registers
     121 * the built-in interpreters.
     122 *
     123 * @returns IPRT status code.
     124 * @param   pvUser1     NULL.
     125 * @param   pvUser2     NULL.
     126 */
     127static DECLCALLBACK(int) rtDbgModInitOnce(void *pvUser1, void *pvUser2)
     128{
     129    int rc = RTSemRWCreate(&g_hDbgModRWSem);
     130    AssertRCReturn(rc, rc);
     131
     132    /* Register them. */
     133
     134    return rc;
     135}
     136
     137
     138DECLINLINE(int) rtDbgModLazyInit(void)
     139{
     140    return RTOnce(&g_rtDbgModOnce, rtDbgModInitOnce, NULL, NULL);
     141}
     142
     143
     144RTDECL(int)  RTDbgModCreate(PRTDBGMOD phDbgMod, const char *pszName, RTUINTPTR cb, uint32_t fFlags)
     145{
     146    /*
     147     * Input validation and lazy initialization.
     148     */
     149    AssertPtrReturn(phDbgMod, VERR_INVALID_POINTER);
     150    *phDbgMod = NIL_RTDBGMOD;
     151    AssertPtrReturn(pszName, VERR_INVALID_POINTER);
     152    AssertReturn(*pszName, VERR_INVALID_PARAMETER);
     153    AssertReturn(cb > 0, VERR_INVALID_PARAMETER);
     154    AssertReturn(fFlags == 0, VERR_INVALID_PARAMETER);
     155
     156    int rc = rtDbgModLazyInit();
     157    if (RT_FAILURE(rc))
     158        return rc;
     159
     160    /*
     161     * Allocate a new module instance.
     162     */
     163    PRTDBGMODINT pDbgMod = (PRTDBGMODINT)RTMemAllocZ(sizeof(*pDbgMod));
     164    if (!pDbgMod)
     165        return VERR_NO_MEMORY;
     166    pDbgMod->u32Magic = RTDBGMOD_MAGIC;
     167    pDbgMod->cRefs = 1;
     168    rc = RTCritSectInit(&pDbgMod->CritSect);
     169    if (RT_SUCCESS(rc))
     170    {
     171        pDbgMod->pszName = RTStrDup(pszName);
     172        if (pDbgMod->pszName)
     173        {
     174            pDbgMod->pDbgVt = &g_rtDbgModVtDbgContainer;
     175            rc = pDbgMod->pDbgVt->pfnTryOpen(pDbgMod);
     176            if (RT_SUCCESS(rc))
     177            {
     178                *phDbgMod = pDbgMod;
     179                return rc;
     180            }
     181            RTStrFree(pDbgMod->pszName);
     182        }
     183        RTCritSectDelete(&pDbgMod->CritSect);
     184    }
     185
     186    RTMemFree(pDbgMod);
     187    return rc;
    50188}
    51189
     
    60198}
    61199
    62 RTDECL(int)         RTDbgModDestroy(RTDBGMOD hDbgMod)
    63 {
    64     return VERR_NOT_IMPLEMENTED;
    65 }
    66 
    67 RTDECL(uint32_t)    RTDbgModRetain(RTDBGMOD hDbgMod)
    68 {
    69     return 0;
    70 }
    71 
    72 RTDECL(uint32_t)    RTDbgModRelease(RTDBGMOD hDbgMod)
    73 {
    74     return 0;
    75 }
    76 
     200
     201/**
     202 * Destroys an module after the reference count has reached zero.
     203 *
     204 * @param   pDbgMod     The module instance.
     205 */
     206static void  rtDbgModDestroy(PRTDBGMODINT pDbgMod)
     207{
     208    /*
     209     * Close the debug info interpreter first, then the image interpret.
     210     */
     211    RTCritSectEnter(&pDbgMod->CritSect); /* paranoia  */
     212    if (pDbgMod->pDbgVt)
     213        pDbgMod->pDbgVt->pfnClose(pDbgMod);
     214    if (pDbgMod->pImgVt)
     215        pDbgMod->pImgVt->pfnClose(pDbgMod);
     216
     217    /*
     218     * Free the resources.
     219     */
     220    ASMAtomicWriteU32(&pDbgMod->u32Magic, ~RTDBGMOD_MAGIC);
     221    RTStrFree(pDbgMod->pszName);
     222    RTStrFree(pDbgMod->pszImgFile);
     223    RTStrFree(pDbgMod->pszDbgFile);
     224    RTCritSectLeave(&pDbgMod->CritSect); /* paranoia  */
     225    RTCritSectDelete(&pDbgMod->CritSect);
     226    RTMemFree(pDbgMod);
     227}
     228
     229
     230/**
     231 * Retains another reference to the module.
     232 *
     233 * @returns New reference count, UINT32_MAX on invalid handle (asserted).
     234 *
     235 * @param   hDbgMod         The module handle.
     236 *
     237 * @remarks Will not take any locks.
     238 */
     239RTDECL(uint32_t) RTDbgModRetain(RTDBGMOD hDbgMod)
     240{
     241    PRTDBGMODINT pDbgMod = hDbgMod;
     242    RTDBGMOD_VALID_RETURN_RC(pDbgMod, UINT32_MAX);
     243    return ASMAtomicIncU32(&pDbgMod->cRefs);
     244}
     245
     246
     247/**
     248 * Release a reference to the module.
     249 *
     250 * When the reference count reaches zero, the module is destroyed.
     251 *
     252 * @returns New reference count, UINT32_MAX on invalid handle (asserted).
     253 *
     254 * @param   hDbgMod         The module handle. The NIL handle is quietly ignored
     255 *                          and 0 is returned.
     256 *
     257 * @remarks Will not take any locks.
     258 */
     259RTDECL(uint32_t) RTDbgModRelease(RTDBGMOD hDbgMod)
     260{
     261    if (hDbgMod == NIL_RTDBGMOD)
     262        return 0;
     263    PRTDBGMODINT pDbgMod = hDbgMod;
     264    RTDBGMOD_VALID_RETURN_RC(pDbgMod, UINT32_MAX);
     265
     266    uint32_t cRefs = ASMAtomicDecU32(&pDbgMod->cRefs);
     267    if (!cRefs)
     268        rtDbgModDestroy(pDbgMod);
     269    return cRefs;
     270}
     271
     272
     273/**
     274 * Gets the module name.
     275 *
     276 * @returns Pointer to a read only string containing the name.
     277 *
     278 * @param   hDbgMod             The module handle.
     279 */
    77280RTDECL(const char *) RTDbgModName(RTDBGMOD hDbgMod)
    78281{
    79     return NULL;
    80 }
     282    PRTDBGMODINT pDbgMod = hDbgMod;
     283    RTDBGMOD_VALID_RETURN_RC(pDbgMod, NULL);
     284    return pDbgMod->pszName;
     285}
     286
    81287
    82288RTDECL(RTUINTPTR)   RTDbgModImageSize(RTDBGMOD hDbgMod)
  • trunk/src/VBox/Runtime/include/internal/dbgmod.h

    r19559 r20355  
    2424
    2525#include <iprt/types.h>
     26#include <iprt/critsect.h>
    2627#include "internal/magics.h"
    2728
     
    134135
    135136    /**
     137     * Adds a symbol to the module (optional).
     138     *
     139     * This method is used to implement DBGFR3SymbolAdd.
     140     *
     141     * @returns VBox status code.
     142     * @retval  VERR_NOT_SUPPORTED if the interpreter doesn't support this feature.
     143     *
     144     * @param   pMod        Pointer to the module structure.
     145     * @param   pszSymbol   The symbol name.
     146     * @param   iSeg        The segment number (0-based). RTDBGMOD_SEG_RVA can be used.
     147     * @param   off         The offset into the segment.
     148     * @param   cbSymbol    The area covered by the symbol. 0 is fine.
     149     */
     150    DECLCALLBACKMEMBER(int, pfnSymbolAdd)(PRTDBGMODINT pMod, const char *pszSymbol, uint32_t iSeg, RTGCUINTPTR off, RTUINT cbSymbol);
     151
     152    /**
    136153     * Queries symbol information by symbol name.
    137154     *
     
    185202    DECLCALLBACKMEMBER(int, pfnLineByAddr)(PRTDBGMODINT pMod, uint32_t iSeg, RTGCUINTPTR off, PRTGCINTPTR poffDisp, PRTDBGLINE pLine);
    186203
    187     /**
    188      * Adds a symbol to the module (optional).
    189      *
    190      * This method is used to implement DBGFR3SymbolAdd.
    191      *
    192      * @returns VBox status code.
    193      * @retval  VERR_NOT_SUPPORTED if the interpreter doesn't support this feature.
    194      *
    195      * @param   pMod        Pointer to the module structure.
    196      * @param   pszSymbol   The symbol name.
    197      * @param   iSeg        The segment number (0-based). RTDBGMOD_SEG_RVA can be used.
    198      * @param   off         The offset into the segment.
    199      * @param   cbSymbol    The area covered by the symbol. 0 is fine.
    200      */
    201     DECLCALLBACKMEMBER(int, pfnSymbolAdd)(PRTDBGMODINT pMod, const char *pszSymbol, uint32_t iSeg, RTGCUINTPTR off, RTUINT cbSymbol);
    202 
    203204    /** For catching initialization errors (RTDBGMODVTDBG_MAGIC). */
    204205    uint32_t    u32EndMagic;
     
    214215{
    215216    /** Magic value (RTDBGMOD_MAGIC). */
    216     uint32_t        u32Magic;
    217     /** The number of address spaces this module is currently linked into.
     217    uint32_t            u32Magic;
     218    /** The number of reference there are to this module.
    218219     * This is used to perform automatic cleanup and sharing. */
    219     uint32_t        cLinks;
     220    uint32_t volatile   cRefs;
    220221    /** The module name (short). */
    221     const char     *pszName;
     222    char               *pszName;
    222223    /** The module filename. Can be NULL. */
    223     const char     *pszImgFile;
     224    char               *pszImgFile;
    224225    /** The debug info file (if external). Can be NULL. */
    225     const char     *pszDbgFile;
     226    char               *pszDbgFile;
     227
     228    /** Critical section serializing access to the module. */
     229    RTCRITSECT          CritSect;
    226230
    227231    /** The method table for the executable image interpreter. */
    228     PCRTDBGMODVTIMG pImgVt;
     232    PCRTDBGMODVTIMG     pImgVt;
    229233    /** Pointer to the private data of the executable image interpreter. */
    230     void           *pvImgPriv;
     234    void               *pvImgPriv;
    231235
    232236    /** The method table for the debug info interpreter. */
    233     PCRTDBGMODVTDBG pDbgVt;
     237    PCRTDBGMODVTDBG     pDbgVt;
    234238    /** Pointer to the private data of the debug info interpreter. */
    235     void           *pvDbgPriv;
     239    void               *pvDbgPriv;
    236240
    237241} RTDBGMODINT;
    238 
     242/** Pointer to an debug module structure.  */
     243typedef RTDBGMODINT *PRTDBGMODINT;
     244
     245
     246/** Default symbol container implementation. */
     247extern RTDBGMODVTDBG const g_rtDbgModVtDbgContainer;
    239248
    240249/** @} */
  • trunk/src/VBox/Runtime/r0drv/darwin/semaphore-r0drv-darwin.cpp

    r19922 r20355  
    187187        ASMAtomicIncU32(&pEventInt->cWaking);
    188188        thread_wakeup_prim((event_t)pEventInt, TRUE /* one thread */, THREAD_AWAKENED);
    189         /** @todo this isn't safe. a scheduling interrupt on the other cpu while we're in here
     189                /** @todo this isn't safe. a scheduling interrupt on the other cpu while we're in here
    190190         * could cause the thread to be timed out before we manage to wake it up and the event
    191          * ends up in the wrong state. ditto for posix signals. */
     191         * ends up in the wrong state. ditto for posix signals.
     192                 * Update: check the return code; it will return KERN_NOT_WAITING if no one is around. */
    192193    }
    193194    else
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