VirtualBox

Changeset 20799 in vbox for trunk


Ignore:
Timestamp:
Jun 22, 2009 10:36:56 PM (15 years ago)
Author:
vboxsync
Message:

IPRT: More RTDbgMod code.

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/dbg.h

    r20744 r20799  
    575575 * @{
    576576 */
    577 RTDECL(int)         RTDbgModCreate(PRTDBGMOD phDbgMod, const char *pszName, RTUINTPTR cb, uint32_t fFlags);
     577
     578/**
     579 * Creates a module based on the default debug info container.
     580 *
     581 * This can be used to manually load a module and its symbol. The primary user
     582 * group is the debug info interpreters, which use this API to create an
     583 * efficient debug info container behind the scenes and forward all queries to
     584 * it once the info has been loaded.
     585 *
     586 * @returns IPRT status code.
     587 *
     588 * @param   phDbgMod        Where to return the module handle.
     589 * @param   pszName         The name of the module (mandatory).
     590 * @param   cbSeg           The size of initial segment. If zero, segments will
     591 *                          have to be added manually using RTDbgModSegmentAdd.
     592 * @param   fFlags          Flags reserved for future extensions, MBZ for now.
     593 */
     594RTDECL(int)         RTDbgModCreate(PRTDBGMOD phDbgMod, const char *pszName, RTUINTPTR cbSeg, uint32_t fFlags);
     595
    578596RTDECL(int)         RTDbgModCreateDeferred(PRTDBGMOD phDbgMod, const char *pszFilename, const char *pszName, RTUINTPTR cb, uint32_t fFlags);
    579597RTDECL(int)         RTDbgModCreateFromImage(PRTDBGMOD phDbgMod, const char *pszFilename, const char *pszName, uint32_t fFlags);
    580598RTDECL(int)         RTDbgModCreateFromMap(PRTDBGMOD phDbgMod, const char *pszFilename, const char *pszName, RTUINTPTR uSubtrahend, uint32_t fFlags);
     599
     600
     601/**
     602 * Retains another reference to the module.
     603 *
     604 * @returns New reference count, UINT32_MAX on invalid handle (asserted).
     605 *
     606 * @param   hDbgMod         The module handle.
     607 *
     608 * @remarks Will not take any locks.
     609 */
    581610RTDECL(uint32_t)    RTDbgModRetain(RTDBGMOD hDbgMod);
     611
     612/**
     613 * Release a reference to the module.
     614 *
     615 * When the reference count reaches zero, the module is destroyed.
     616 *
     617 * @returns New reference count, UINT32_MAX on invalid handle (asserted).
     618 *
     619 * @param   hDbgMod         The module handle. The NIL handle is quietly ignored
     620 *                          and 0 is returned.
     621 *
     622 * @remarks Will not take any locks.
     623 */
    582624RTDECL(uint32_t)    RTDbgModRelease(RTDBGMOD hDbgMod);
     625
     626/**
     627 * Gets the module name.
     628 *
     629 * @returns Pointer to a read only string containing the name.
     630 *
     631 * @param   hDbgMod         The module handle.
     632 */
    583633RTDECL(const char *) RTDbgModName(RTDBGMOD hDbgMod);
     634
     635/**
     636 * Converts an image relative address to a segment:offset address.
     637 *
     638 * @returns Segment index on success.
     639 *          NIL_RTDBGSEGIDX is returned if the module handle or the RVA are
     640 *          invalid.
     641 *
     642 * @param   hDbgMod         The module handle.
     643 * @param   uRva            The image relative address to convert.
     644 * @param   poffSeg         Where to return the segment offset. Optional.
     645 */
     646RTDECL(RTDBGSEGIDX) RTDbgModRvaToSegOff(RTDBGMOD hDbgMod, RTUINTPTR uRva, PRTUINTPTR poffSeg);
     647
     648/**
     649 * Image size when mapped if segments are mapped adjecently.
     650 *
     651 * For ELF, PE, and Mach-O images this is (usually) a natural query, for LX and
     652 * NE and such it's a bit odder and the answer may not make much sense for them.
     653 *
     654 * @returns Image mapped size.
     655 *          UINTPTR_MAX is returned if the handle is invalid.
     656 *
     657 * @param   hDbgMod         The module handle.
     658 */
    584659RTDECL(RTUINTPTR)   RTDbgModImageSize(RTDBGMOD hDbgMod);
    585660
    586 RTDECL(int)         RTDbgModSegmentAdd(RTDBGMOD hDbgMod, RTUINTPTR uRva, RTUINTPTR cb, const char *pszName, size_t cchName, uint32_t fFlags, PRTDBGSEGIDX piSeg);
     661
     662/**
     663 * Adds a segment to the module. Optional feature.
     664 *
     665 * This method is intended used for manually constructing debug info for a
     666 * module. The main usage is from other debug info interpreters that want to
     667 * avoid writing a debug info database and instead uses the standard container
     668 * behind the scenes.
     669 *
     670 * @returns IPRT status code.
     671 * @retval  VERR_NOT_SUPPORTED if this feature isn't support by the debug info
     672 *          interpreter. This is a common return code.
     673 * @retval  VERR_INVALID_HANDLE if hDbgMod is invalid.
     674 * @retval  VERR_DBG_ADDRESS_WRAP if uRva+cb wraps around.
     675 * @retval  VERR_DBG_SEGMENT_NAME_OUT_OF_RANGE if pszName is too short or long.
     676 * @retval  VERR_INVALID_PARAMETER if fFlags contains undefined flags.
     677 * @retval  VERR_DBG_SPECIAL_SEGMENT if *piSeg is a special segment.
     678 * @retval  VERR_DBG_INVALID_SEGMENT_INDEX if *piSeg doesn't meet expectations.
     679 *
     680 * @param   hDbgMod             The module handle.
     681 * @param   uRva                The image relative address of the segment.
     682 * @param   cb                  The size of the segment.
     683 * @param   pszName             The segment name. Does not normally need to be
     684 *                              unique, although this is somewhat up to the
     685 *                              debug interpreter to decide.
     686 * @param   fFlags              Segment flags. Reserved for future used, MBZ.
     687 * @param   piSeg               The segment index or NIL_RTDBGSEGIDX on input.
     688 *                              The assigned segment index on successful return.
     689 *                              Optional.
     690 */
     691RTDECL(int)         RTDbgModSegmentAdd(RTDBGMOD hDbgMod, RTUINTPTR uRva, RTUINTPTR cb, const char *pszName,
     692                                       uint32_t fFlags, PRTDBGSEGIDX piSeg);
     693
     694/**
     695 * Gets the number of segments in the module.
     696 *
     697 * This is can be used to determin the range which can be passed to
     698 * RTDbgModSegmentByIndex and derivates.
     699 *
     700 * @returns The segment relative address.
     701 *          NIL_RTDBGSEGIDX if the handle is invalid.
     702 *
     703 * @param   hDbgMod         The module handle.
     704 */
    587705RTDECL(RTDBGSEGIDX) RTDbgModSegmentCount(RTDBGMOD hDbgMod);
     706
     707/**
     708 * Query information about a segment.
     709 *
     710 * This can be used together with RTDbgModSegmentCount to enumerate segments.
     711 * The index starts a 0 and stops one below RTDbgModSegmentCount.
     712 *
     713 * @returns IPRT status code.
     714 * @retval  VERR_DBG_INVALID_SEGMENT_INDEX if iSeg is too high.
     715 * @retval  VERR_DBG_SPECIAL_SEGMENT if iSeg indicates a special segment.
     716 * @retval  VERR_INVALID_HANDLE if hDbgMod is invalid.
     717 *
     718 * @param   hDbgMod         The module handle.
     719 * @param   iSeg            The segment index. No special segments.
     720 * @param   pSegInfo        Where to return the segment info. The
     721 *                          RTDBGSEGMENT::Address member will be set to
     722 *                          RTUINTPTR_MAX or the load address used at link time.
     723 */
    588724RTDECL(int)         RTDbgModSegmentByIndex(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg, PRTDBGSEGMENT pSegInfo);
     725
     726/**
     727 * Gets the size of a segment.
     728 *
     729 * This is a just a wrapper around RTDbgModSegmentByIndex.
     730 *
     731 * @returns The segment size.
     732 *          UINTPTR_MAX is returned if either the handle and segment index are
     733 *          invalid.
     734 *
     735 * @param   hDbgMod         The module handle.
     736 * @param   iSeg            The segment index. RTDBGSEGIDX_ABS is not allowed.
     737 *                          If RTDBGSEGIDX_RVA is used, the functions returns
     738 *                          the same value as RTDbgModImageSize.
     739 */
    589740RTDECL(RTUINTPTR)   RTDbgModSegmentSize(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg);
     741
     742/**
     743 * Gets the image relative address of a segment.
     744 *
     745 * This is a just a wrapper around RTDbgModSegmentByIndex.
     746 *
     747 * @returns The segment relative address.
     748 *          UINTPTR_MAX is returned if either the handle and segment index are
     749 *          invalid.
     750 *
     751 * @param   hDbgMod         The module handle.
     752 * @param   iSeg            The segment index. No special segment indexes
     753 *                          allowed (asserted).
     754 */
    590755RTDECL(RTUINTPTR)   RTDbgModSegmentRva(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg);
    591756
  • trunk/include/iprt/err.h

    r20756 r20799  
    952952/** Invalid image relative virtual address. */
    953953#define VERR_DBG_INVALID_RVA                    (-655)
     954/** Invalid image relative virtual address. */
     955#define VERR_DBG_SPECIAL_SEGMENT                (-656)
    954956/** Address conflict within a module/segment.
    955957 * Attempted to add a segment, symbol or line number that fully or partially
    956958 * overlaps with an existing one. */
    957 #define VERR_DBG_ADDRESS_CONFLICT               (-656)
     959#define VERR_DBG_ADDRESS_CONFLICT               (-657)
    958960/** Duplicate symbol within the module.
    959961 * Attempted to add a symbol which name already exists within the module.  */
    960 #define VERR_DBG_DUPLICATE_SYMBOL               (-657)
     962#define VERR_DBG_DUPLICATE_SYMBOL               (-658)
    961963/** The segment index specified when adding a new segment is already in use. */
    962 #define VERR_DBG_SEGMENT_INDEX_CONFLICT         (-658)
     964#define VERR_DBG_SEGMENT_INDEX_CONFLICT         (-659)
    963965/** No line number was found for the specified address/ordinal/whatever. */
    964 #define VERR_DBG_LINE_NOT_FOUND                 (-659)
     966#define VERR_DBG_LINE_NOT_FOUND                 (-660)
    965967/** The length of the symbol name is out of range.
    966968 * This means it is an empty string or that it's greater or equal to
    967969 * RTDBG_SYMBOL_NAME_LENGTH. */
    968 #define VERR_DBG_SYMBOL_NAME_OUT_OF_RANGE       (-660)
     970#define VERR_DBG_SYMBOL_NAME_OUT_OF_RANGE       (-661)
    969971/** The length of the file name is out of range.
    970972 * This means it is an empty string or that it's greater or equal to
    971973 * RTDBG_FILE_NAME_LENGTH. */
    972 #define VERR_DBG_FILE_NAME_OUT_OF_RANGE         (-661)
     974#define VERR_DBG_FILE_NAME_OUT_OF_RANGE         (-662)
     975/** The length of the segment name is out of range.
     976 * This means it is an empty string or that it is greater or equal to
     977 * RTDBG_SEGMENT_NAME_LENGTH. */
     978#define VERR_DBG_SEGMENT_NAME_OUT_OF_RANGE      (-663)
     979/** The specified address range wraps around. */
     980#define VERR_DBG_ADDRESS_WRAP                   (-664)
    973981/** @} */
    974982
  • trunk/src/VBox/Runtime/common/dbg/dbgmod.cpp

    r20744 r20799  
    196196 * Creates a module based on the default debug info container.
    197197 *
    198  * This can be used to manually load a module and its symbol.
     198 * This can be used to manually load a module and its symbol. The primary user
     199 * group is the debug info interpreters, which use this API to create an
     200 * efficient debug info container behind the scenes and forward all queries to
     201 * it once the info has been loaded.
    199202 *
    200203 * @returns IPRT status code.
     
    202205 * @param   phDbgMod        Where to return the module handle.
    203206 * @param   pszName         The name of the module (mandatory).
    204  * @param   cb              The size of the module. Must be greater than zero.
     207 * @param   cbSeg           The size of initial segment. If zero, segments will
     208 *                          have to be added manually using RTDbgModSegmentAdd.
    205209 * @param   fFlags          Flags reserved for future extensions, MBZ for now.
    206210 */
    207 RTDECL(int)  RTDbgModCreate(PRTDBGMOD phDbgMod, const char *pszName, RTUINTPTR cb, uint32_t fFlags)
     211RTDECL(int) RTDbgModCreate(PRTDBGMOD phDbgMod, const char *pszName, RTUINTPTR cbSeg, uint32_t fFlags)
    208212{
    209213    /*
     
    214218    AssertPtrReturn(pszName, VERR_INVALID_POINTER);
    215219    AssertReturn(*pszName, VERR_INVALID_PARAMETER);
    216     AssertReturn(cb > 0, VERR_INVALID_PARAMETER);
    217220    AssertReturn(fFlags == 0, VERR_INVALID_PARAMETER);
    218221
     
    232235    if (RT_SUCCESS(rc))
    233236    {
    234         pDbgMod->pszName = RTStrDup(pszName);
     237        pDbgMod->pszName = RTStrCacheEnter(g_hDbgModStrCache, pszName);
    235238        if (pDbgMod->pszName)
    236239        {
    237             rc = rtDbgModContainerCreate(pDbgMod, cb);
     240            rc = rtDbgModContainerCreate(pDbgMod, cbSeg);
    238241            if (RT_SUCCESS(rc))
    239242            {
     
    241244                return rc;
    242245            }
    243             RTStrFree(pDbgMod->pszName);
     246            RTStrCacheRelease(g_hDbgModStrCache, pDbgMod->pszName);
    244247        }
    245248        RTCritSectDelete(&pDbgMod->CritSect);
     
    273276 * @param   pDbgMod     The module instance.
    274277 */
    275 static void  rtDbgModDestroy(PRTDBGMODINT pDbgMod)
     278static void rtDbgModDestroy(PRTDBGMODINT pDbgMod)
    276279{
    277280    /*
     
    298301     */
    299302    ASMAtomicWriteU32(&pDbgMod->u32Magic, ~RTDBGMOD_MAGIC);
    300     RTStrFree(pDbgMod->pszName);
    301     RTStrFree(pDbgMod->pszImgFile);
    302     RTStrFree(pDbgMod->pszDbgFile);
     303    RTStrCacheRelease(g_hDbgModStrCache, pDbgMod->pszName);
     304    RTStrCacheRelease(g_hDbgModStrCache, pDbgMod->pszImgFile);
     305    RTStrCacheRelease(g_hDbgModStrCache, pDbgMod->pszDbgFile);
    303306    RTCritSectLeave(&pDbgMod->CritSect); /* paranoia  */
    304307    RTCritSectDelete(&pDbgMod->CritSect);
     
    355358 * @returns Pointer to a read only string containing the name.
    356359 *
    357  * @param   hDbgMod             The module handle.
     360 * @param   hDbgMod         The module handle.
    358361 */
    359362RTDECL(const char *) RTDbgModName(RTDBGMOD hDbgMod)
     
    365368
    366369
    367 RTDECL(RTUINTPTR)   RTDbgModImageSize(RTDBGMOD hDbgMod)
    368 {
    369     return 1;
    370 }
    371 
    372 RTDECL(RTUINTPTR)   RTDbgModSegmentSize(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg)
    373 {
    374     return 1;
    375 }
    376 
    377 RTDECL(RTUINTPTR)   RTDbgModSegmentRva(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg)
    378 {
    379     return 0;
    380 }
    381 
     370/**
     371 * Converts an image relative address to a segment:offset address.
     372 *
     373 * @returns Segment index on success.
     374 *          NIL_RTDBGSEGIDX is returned if the module handle or the RVA are
     375 *          invalid.
     376 *
     377 * @param   hDbgMod         The module handle.
     378 * @param   uRva            The image relative address to convert.
     379 * @param   poffSeg         Where to return the segment offset. Optional.
     380 */
     381RTDECL(RTDBGSEGIDX) RTDbgModRvaToSegOff(RTDBGMOD hDbgMod, RTUINTPTR uRva, PRTUINTPTR poffSeg)
     382{
     383    PRTDBGMODINT pDbgMod = hDbgMod;
     384    RTDBGMOD_VALID_RETURN_RC(pDbgMod, NIL_RTDBGSEGIDX);
     385    RTDBGMOD_LOCK(pDbgMod);
     386
     387    RTDBGSEGIDX iSeg = pDbgMod->pDbgVt->pfnRvaToSegOff(pDbgMod, uRva, poffSeg);
     388
     389    RTDBGMOD_UNLOCK(pDbgMod);
     390    return iSeg;
     391}
     392
     393
     394/**
     395 * Image size when mapped if segments are mapped adjecently.
     396 *
     397 * For ELF, PE, and Mach-O images this is (usually) a natural query, for LX and
     398 * NE and such it's a bit odder and the answer may not make much sense for them.
     399 *
     400 * @returns Image mapped size.
     401 *          UINTPTR_MAX is returned if the handle is invalid.
     402 *
     403 * @param   hDbgMod         The module handle.
     404 */
     405RTDECL(RTUINTPTR) RTDbgModImageSize(RTDBGMOD hDbgMod)
     406{
     407    PRTDBGMODINT pDbgMod = hDbgMod;
     408    RTDBGMOD_VALID_RETURN_RC(pDbgMod, UINTPTR_MAX);
     409    RTDBGMOD_LOCK(pDbgMod);
     410
     411    RTUINTPTR cbImage = pDbgMod->pDbgVt->pfnImageSize(pDbgMod);
     412
     413    RTDBGMOD_UNLOCK(pDbgMod);
     414    return cbImage;
     415}
     416
     417
     418/**
     419 * Adds a segment to the module. Optional feature.
     420 *
     421 * This method is intended used for manually constructing debug info for a
     422 * module. The main usage is from other debug info interpreters that want to
     423 * avoid writing a debug info database and instead uses the standard container
     424 * behind the scenes.
     425 *
     426 * @returns IPRT status code.
     427 * @retval  VERR_NOT_SUPPORTED if this feature isn't support by the debug info
     428 *          interpreter. This is a common return code.
     429 * @retval  VERR_INVALID_HANDLE if hDbgMod is invalid.
     430 * @retval  VERR_DBG_ADDRESS_WRAP if uRva+cb wraps around.
     431 * @retval  VERR_DBG_SEGMENT_NAME_OUT_OF_RANGE if pszName is too short or long.
     432 * @retval  VERR_INVALID_PARAMETER if fFlags contains undefined flags.
     433 * @retval  VERR_DBG_SPECIAL_SEGMENT if *piSeg is a special segment.
     434 * @retval  VERR_DBG_INVALID_SEGMENT_INDEX if *piSeg doesn't meet expectations.
     435 *
     436 * @param   hDbgMod             The module handle.
     437 * @param   uRva                The image relative address of the segment.
     438 * @param   cb                  The size of the segment.
     439 * @param   pszName             The segment name. Does not normally need to be
     440 *                              unique, although this is somewhat up to the
     441 *                              debug interpreter to decide.
     442 * @param   fFlags              Segment flags. Reserved for future used, MBZ.
     443 * @param   piSeg               The segment index or NIL_RTDBGSEGIDX on input.
     444 *                              The assigned segment index on successful return.
     445 *                              Optional.
     446 */
     447RTDECL(int) RTDbgModSegmentAdd(RTDBGMOD hDbgMod, RTUINTPTR uRva, RTUINTPTR cb, const char *pszName,
     448                               uint32_t fFlags, PRTDBGSEGIDX piSeg)
     449{
     450    /*
     451     * Validate input.
     452     */
     453    PRTDBGMODINT pDbgMod = hDbgMod;
     454    RTDBGMOD_VALID_RETURN_RC(pDbgMod, VERR_INVALID_HANDLE);
     455    AssertMsgReturn(uRva + cb >= uRva, ("uRva=%RTptr cb=%RTptr\n", uRva, cb), VERR_DBG_ADDRESS_WRAP);
     456    AssertPtr(*pszName);
     457    size_t cchName = strlen(pszName);
     458    AssertReturn(cchName > 0, VERR_DBG_SEGMENT_NAME_OUT_OF_RANGE);
     459    AssertReturn(cchName < RTDBG_SEGMENT_NAME_LENGTH, VERR_DBG_SEGMENT_NAME_OUT_OF_RANGE);
     460    AssertMsgReturn(!fFlags, ("%#x\n", fFlags), VERR_INVALID_PARAMETER);
     461    AssertPtrNull(piSeg);
     462    AssertMsgReturn(!piSeg || *piSeg == NIL_RTDBGSEGIDX || *piSeg <= RTDBGSEGIDX_LAST, ("%#x\n", *piSeg), VERR_DBG_SPECIAL_SEGMENT);
     463
     464    /*
     465     * Do the deed.
     466     */
     467    RTDBGMOD_LOCK(pDbgMod);
     468    int rc = pDbgMod->pDbgVt->pfnSegmentAdd(pDbgMod, uRva, cb, pszName, cchName, fFlags, piSeg);
     469    RTDBGMOD_UNLOCK(pDbgMod);
     470
     471    return rc;
     472
     473}
     474
     475
     476/**
     477 * Gets the number of segments in the module.
     478 *
     479 * This is can be used to determin the range which can be passed to
     480 * RTDbgModSegmentByIndex and derivates.
     481 *
     482 * @returns The segment relative address.
     483 *          NIL_RTDBGSEGIDX if the handle is invalid.
     484 *
     485 * @param   hDbgMod         The module handle.
     486 */
    382487RTDECL(RTDBGSEGIDX) RTDbgModSegmentCount(RTDBGMOD hDbgMod)
    383488{
    384     return 1;
    385 }
     489    PRTDBGMODINT pDbgMod = hDbgMod;
     490    RTDBGMOD_VALID_RETURN_RC(pDbgMod, NIL_RTDBGSEGIDX);
     491    RTDBGMOD_LOCK(pDbgMod);
     492
     493    RTDBGSEGIDX cSegs = pDbgMod->pDbgVt->pfnSegmentCount(pDbgMod);
     494
     495    RTDBGMOD_UNLOCK(pDbgMod);
     496    return cSegs;
     497}
     498
     499
     500/**
     501 * Query information about a segment.
     502 *
     503 * This can be used together with RTDbgModSegmentCount to enumerate segments.
     504 * The index starts a 0 and stops one below RTDbgModSegmentCount.
     505 *
     506 * @returns IPRT status code.
     507 * @retval  VERR_DBG_INVALID_SEGMENT_INDEX if iSeg is too high.
     508 * @retval  VERR_DBG_SPECIAL_SEGMENT if iSeg indicates a special segment.
     509 * @retval  VERR_INVALID_HANDLE if hDbgMod is invalid.
     510 *
     511 * @param   hDbgMod         The module handle.
     512 * @param   iSeg            The segment index. No special segments.
     513 * @param   pSegInfo        Where to return the segment info. The
     514 *                          RTDBGSEGMENT::Address member will be set to
     515 *                          RTUINTPTR_MAX or the load address used at link time.
     516 */
     517RTDECL(int) RTDbgModSegmentByIndex(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg, PRTDBGSEGMENT pSegInfo)
     518{
     519    AssertMsgReturn(iSeg <= RTDBGSEGIDX_LAST, ("%#x\n", iSeg), VERR_DBG_SPECIAL_SEGMENT);
     520    PRTDBGMODINT pDbgMod = hDbgMod;
     521    RTDBGMOD_VALID_RETURN_RC(pDbgMod, VERR_INVALID_HANDLE);
     522    RTDBGMOD_LOCK(pDbgMod);
     523
     524    int rc = pDbgMod->pDbgVt->pfnSegmentByIndex(pDbgMod, iSeg, pSegInfo);
     525
     526    RTDBGMOD_UNLOCK(pDbgMod);
     527    return RT_SUCCESS(rc);
     528}
     529
     530
     531/**
     532 * Gets the size of a segment.
     533 *
     534 * This is a just a wrapper around RTDbgModSegmentByIndex.
     535 *
     536 * @returns The segment size.
     537 *          UINTPTR_MAX is returned if either the handle and segment index are
     538 *          invalid.
     539 *
     540 * @param   hDbgMod         The module handle.
     541 * @param   iSeg            The segment index. RTDBGSEGIDX_ABS is not allowed.
     542 *                          If RTDBGSEGIDX_RVA is used, the functions returns
     543 *                          the same value as RTDbgModImageSize.
     544 */
     545RTDECL(RTUINTPTR) RTDbgModSegmentSize(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg)
     546{
     547    if (iSeg == RTDBGSEGIDX_RVA)
     548        return RTDbgModImageSize(hDbgMod);
     549    RTDBGSEGMENT SegInfo;
     550    int rc = RTDbgModSegmentByIndex(hDbgMod, iSeg, &SegInfo);
     551    return RT_SUCCESS(rc) ? SegInfo.cb : RTUINTPTR_MAX;
     552}
     553
     554
     555/**
     556 * Gets the image relative address of a segment.
     557 *
     558 * This is a just a wrapper around RTDbgModSegmentByIndex.
     559 *
     560 * @returns The segment relative address.
     561 *          UINTPTR_MAX is returned if either the handle and segment index are
     562 *          invalid.
     563 *
     564 * @param   hDbgMod         The module handle.
     565 * @param   iSeg            The segment index. No special segment indexes
     566 *                          allowed (asserted).
     567 */
     568RTDECL(RTUINTPTR) RTDbgModSegmentRva(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg)
     569{
     570    RTDBGSEGMENT SegInfo;
     571    int rc = RTDbgModSegmentByIndex(hDbgMod, iSeg, &SegInfo);
     572    return RT_SUCCESS(rc) ? SegInfo.uRva : RTUINTPTR_MAX;
     573}
     574
     575
    386576
    387577
  • trunk/src/VBox/Runtime/common/dbg/dbgmodcontainer.cpp

    r20756 r20799  
    594594        pThis->paSegs[iSeg].pszName = NULL;
    595595    }
     596
    596597    RTAvlrUIntPtrDestroy(&pThis->AbsAddrTree, rtDbgModContainer_DestroyTreeNode, NULL);
    597598    pThis->Names = NULL;
     
    599600    RTMemFree(pThis->paSegs);
    600601    pThis->paSegs = NULL;
     602
    601603    RTMemFree(pThis);
    602604
     
    650652 * @returns IPRT status code.
    651653 * @param   pMod        The module instance.
    652  * @param   cb          The module size.
     654 * @param   cbSeg       The size of the initial segment. 0 if segments are to be
     655 *                      created manually later on.
    653656 */
    654 int rtDbgModContainerCreate(PRTDBGMODINT pMod, RTUINTPTR cb)
     657int rtDbgModContainerCreate(PRTDBGMODINT pMod, RTUINTPTR cbSeg)
    655658{
    656659    PRTDBGMODCTN pThis = (PRTDBGMODCTN)RTMemAlloc(sizeof(*pThis));
     
    664667    pThis->paSegs = NULL;
    665668    pThis->cSegs = 0;
    666     pThis->cb = cb; /** @todo the module size stuff doesn't quite make sense yet. Need to look at segments first, I guess. */
     669    pThis->cb = 0;
    667670    pThis->iNextSymbolOrdinal = 0;
    668671    pThis->iNextLineOrdinal = 0;
     
    670673    pMod->pDbgVt = &g_rtDbgModVtDbgContainer;
    671674    pMod->pvDbgPriv = pThis;
     675
     676    /*
     677     * Add the initial segment.
     678     */
     679    if (cbSeg)
     680    {
     681        int rc = rtDbgModContainer_SegmentAdd(pMod, 0, cbSeg, "default", sizeof("default") - 1, 0, NULL);
     682        if (RT_FAILURE(rc))
     683        {
     684            RTMemFree(pThis);
     685            pMod->pDbgVt = NULL;
     686            pMod->pvDbgPriv = NULL;
     687            return rc;
     688        }
     689    }
     690
    672691    return VINF_SUCCESS;
    673692}
  • trunk/src/VBox/Runtime/include/internal/dbgmod.h

    r20756 r20799  
    374374    uint32_t volatile   cRefs;
    375375    /** The module name (short). */
    376     char               *pszName;
     376    char const         *pszName;
    377377    /** The module filename. Can be NULL. */
    378     char               *pszImgFile;
     378    char const         *pszImgFile;
    379379    /** The debug info file (if external). Can be NULL. */
    380     char               *pszDbgFile;
     380    char const         *pszDbgFile;
    381381
    382382    /** Critical section serializing access to the module. */
     
    401401
    402402
    403 int rtDbgModContainerCreate(PRTDBGMODINT pMod, RTUINTPTR cb);
     403int rtDbgModContainerCreate(PRTDBGMODINT pMod, RTUINTPTR cbSeg);
    404404
    405405/** @} */
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