VirtualBox

Changeset 46113 in vbox


Ignore:
Timestamp:
May 15, 2013 10:39:43 PM (12 years ago)
Author:
vboxsync
Message:

Implemented debug module that uses the exported symbols. This will work on all hosts. :-)

Location:
trunk
Files:
6 edited

Legend:

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

    r46083 r46113  
    371371 * @{ */
    372372/** Returns ALL kinds of symbols. The default is to only return public/exported symbols. */
    373 #define RTLDR_ENUM_SYMBOL_FLAGS_ALL    RT_BIT(1)
     373#define RTLDR_ENUM_SYMBOL_FLAGS_ALL     RT_BIT(1)
     374/** Ignore forwarders (for use with RTLDR_ENUM_SYMBOL_FLAGS_ALL). */
     375#define RTLDR_ENUM_SYMBOL_FLAGS_NO_FWD  RT_BIT(2)
    374376/** @} */
    375377
  • trunk/src/VBox/Runtime/common/dbg/dbgmoddeferred.cpp

    r46109 r46113  
    478478
    479479
     480/** @interface_method_impl{RTDBGMODVTIMG,pfnEnumSymbols} */
     481static DECLCALLBACK(int) rtDbgModDeferredImg_EnumSymbols(PRTDBGMODINT pMod, uint32_t fFlags, RTLDRADDR BaseAddress,
     482                                                         PFNRTLDRENUMSYMS pfnCallback, void *pvUser)
     483{
     484    int rc = rtDbgModDeferredDoIt(pMod, false /*fForceRetry*/);
     485    if (RT_SUCCESS(rc))
     486        rc = pMod->pImgVt->pfnEnumSymbols(pMod, fFlags, BaseAddress, pfnCallback, pvUser);
     487    return rc;
     488}
     489
     490
    480491/** @interface_method_impl{RTDBGMODVTIMG,pfnEnumSegments} */
    481492static DECLCALLBACK(int) rtDbgModDeferredImg_EnumSegments(PRTDBGMODINT pMod, PFNRTLDRENUMSEGS pfnCallback, void *pvUser)
     
    523534    /*.pfnEnumDbgInfo = */              rtDbgModDeferredImg_EnumDbgInfo,
    524535    /*.pfnEnumSegments = */             rtDbgModDeferredImg_EnumSegments,
     536    /*.pfnEnumSymbols = */              rtDbgModDeferredImg_EnumSymbols,
    525537    /*.pfnGetLoadedSize = */            rtDbgModDeferredImg_ImageSize,
    526538    /*.pfnLinkAddressToSegOffset = */   rtDbgModDeferredImg_LinkAddressToSegOffset,
  • trunk/src/VBox/Runtime/common/dbg/dbgmodexports.cpp

    r45997 r46113  
    2929*   Header Files                                                               *
    3030*******************************************************************************/
     31#define LOG_GROUP RTLOGGROUP_DBG
    3132#include <iprt/dbg.h>
    3233#include "internal/iprt.h"
    3334
     35#include <iprt/alloca.h>
    3436#include <iprt/assert.h>
    3537#include <iprt/err.h>
     38#include <iprt/log.h>
    3639#include <iprt/string.h>
    3740#include "internal/dbgmod.h"
    3841
    3942
     43/*******************************************************************************
     44*   Structures and Typedefs                                                    *
     45*******************************************************************************/
     46typedef struct RTDBGMODEXPORTARGS
     47{
     48    PRTDBGMODINT    pDbgMod;
     49    RTLDRADDR       uImageBase;
     50} RTDBGMODEXPORTARGS;
     51/** Pointer to an argument package. */
     52typedef RTDBGMODEXPORTARGS *PRTDBGMODEXPORTARGS;
    4053
    4154
     55/** @callback_method_impl{FNRTLDRENUMSYMS,
     56 *  Copies the symbols over into the container.} */
     57static DECLCALLBACK(int) rtDbgModExportsAddSymbolCallback(RTLDRMOD hLdrMod, const char *pszSymbol, unsigned uSymbol,
     58                                                          RTLDRADDR Value, void *pvUser)
     59{
     60    PRTDBGMODEXPORTARGS pArgs = (PRTDBGMODEXPORTARGS)pvUser;
     61    NOREF(hLdrMod);
     62
     63    if (Value >= pArgs->uImageBase)
     64    {
     65        int rc = RTDbgModSymbolAdd(pArgs->pDbgMod, pszSymbol, RTDBGSEGIDX_RVA, Value - pArgs->uImageBase,
     66                                   0 /*cb*/, 0 /* fFlags */, NULL /*piOrdinal*/);
     67        Log(("Symbol #%05u %#018x %s [%Rrc]\n", uSymbol, Value, pszSymbol, rc)); NOREF(rc);
     68    }
     69    else
     70        Log(("Symbol #%05u %#018x %s [SKIPPED - INVALID ADDRESS]\n", uSymbol, Value, pszSymbol));
     71    return VINF_SUCCESS;
     72}
     73
     74
     75/** @callback_method_impl{FNRTLDRENUMSEGS,
     76 *  Copies the segments over into the container.} */
     77static DECLCALLBACK(int) rtDbgModExportsAddSegmentsCallback(RTLDRMOD hLdrMod, PCRTLDRSEG pSeg, void *pvUser)
     78{
     79    PRTDBGMODEXPORTARGS pArgs = (PRTDBGMODEXPORTARGS)pvUser;
     80    Log(("Segment %.*s: LinkAddress=%#llx RVA=%#llx cb=%#llx\n",
     81         pSeg->cchName, pSeg->pchName, (uint64_t)pSeg->LinkAddress, (uint64_t)pSeg->RVA, pSeg->cb));
     82    NOREF(hLdrMod);
     83
     84    /* Find the best base address for the module. */
     85    if (    pSeg->LinkAddress != NIL_RTLDRADDR
     86        &&  (   !pArgs->uImageBase
     87             || pArgs->uImageBase > pSeg->LinkAddress))
     88        pArgs->uImageBase = pSeg->LinkAddress;
     89
     90    /* Make sure the name is terminated before we add it. */
     91    char *pszName = (char *)pSeg->pchName;
     92    if (pszName[pSeg->cchName])
     93    {
     94        pszName = (char *)alloca(pSeg->cchName + 1);
     95        memcpy(pszName, pSeg->pchName, pSeg->cchName);
     96        pszName[pSeg->cchName] = '\0';
     97    }
     98
     99    RTLDRADDR cb = RT_MAX(pSeg->cb, pSeg->cbMapped);
     100    return RTDbgModSegmentAdd(pArgs->pDbgMod, pSeg->RVA, cb, pszName, 0 /*fFlags*/, NULL);
     101}
    42102
    43103
     
    62122     * We simply use a container type for this work.
    63123     */
    64     /// @todo later int rc = rtDbgModContainerCreate(pDbgMod, 0);
    65     int rc = rtDbgModContainerCreate(pDbgMod, cbImage);
     124    int rc = rtDbgModContainerCreate(pDbgMod, 0);
    66125    if (RT_FAILURE(rc))
    67126        return rc;
     127    pDbgMod->fExports = true;
    68128
    69129    /*
    70      * Copy the segments.
     130     * Copy the segments and symbols.
    71131     */
     132    RTDBGMODEXPORTARGS Args;
     133    Args.pDbgMod    = pDbgMod;
     134    Args.uImageBase = 0;
     135    rc = pDbgMod->pImgVt->pfnEnumSegments(pDbgMod, rtDbgModExportsAddSegmentsCallback, &Args);
     136    if (RT_SUCCESS(rc))
     137    {
     138        rc = pDbgMod->pImgVt->pfnEnumSymbols(pDbgMod, RTLDR_ENUM_SYMBOL_FLAGS_ALL | RTLDR_ENUM_SYMBOL_FLAGS_NO_FWD,
     139                                             Args.uImageBase ? Args.uImageBase : 0x10000,
     140                                             rtDbgModExportsAddSymbolCallback, &Args);
     141        if (RT_FAILURE(rc))
     142            Log(("rtDbgModCreateForExports: Error during symbol enum: %Rrc\n", rc));
     143    }
     144    else
     145        Log(("rtDbgModCreateForExports: Error during segment enum: %Rrc\n", rc));
    72146
    73     /*
    74      * Copy the symbols.
    75      */
    76 
    77 
    78     return VINF_SUCCESS;
     147    /* This won't fail. */
     148    if (RT_SUCCESS(rc))
     149        rc = VINF_SUCCESS;
     150    else
     151        rc = -rc; /* Change it into a warning. */
     152    return rc;
    79153}
    80154
  • trunk/src/VBox/Runtime/common/dbg/dbgmodldr.cpp

    r46083 r46113  
    109109
    110110/** @interface_method_impl{RTDBGMODVTIMG,pfnEnumSegments} */
     111static DECLCALLBACK(int) rtDbgModLdr_EnumSymbols(PRTDBGMODINT pMod, uint32_t fFlags, RTLDRADDR BaseAddress,
     112                                                 PFNRTLDRENUMSYMS pfnCallback, void *pvUser)
     113{
     114    PRTDBGMODLDR pThis = (PRTDBGMODLDR)pMod->pvImgPriv;
     115    return RTLdrEnumSymbols(pThis->hLdrMod, fFlags, NULL /*pvBits*/, BaseAddress, pfnCallback, pvUser);
     116}
     117
     118
     119/** @interface_method_impl{RTDBGMODVTIMG,pfnEnumSegments} */
    111120static DECLCALLBACK(int) rtDbgModLdr_EnumSegments(PRTDBGMODINT pMod, PFNRTLDRENUMSEGS pfnCallback, void *pvUser)
    112121{
     
    164173    /*.pfnEnumDbgInfo = */              rtDbgModLdr_EnumDbgInfo,
    165174    /*.pfnEnumSegments = */             rtDbgModLdr_EnumSegments,
     175    /*.pfnEnumSymbols = */              rtDbgModLdr_EnumSymbols,
    166176    /*.pfnGetLoadedSize = */            rtDbgModLdr_GetLoadedSize,
    167177    /*.pfnLinkAddressToSegOffset = */   rtDbgModLdr_LinkAddressToSegOffset,
  • trunk/src/VBox/Runtime/common/ldr/ldrPE.cpp

    r46108 r46113  
    971971            uintptr_t   uRVAExport = paAddress[uOrdinal];
    972972            RTUINTPTR Value;
    973             if (    uRVAExport - (uintptr_t)pModPe->ExportDir.VirtualAddress
    974                 <   pModPe->ExportDir.Size)
    975             {
    976                 /* Resolve forwarder. */
    977                 AssertMsgFailed(("Forwarders are not supported!\n"));
     973            if (  uRVAExport - (uintptr_t)pModPe->ExportDir.VirtualAddress
     974                < pModPe->ExportDir.Size)
     975            {
     976                if (!(fFlags & RTLDR_ENUM_SYMBOL_FLAGS_NO_FWD))
     977                {
     978                    /* Resolve forwarder. */
     979                    AssertMsgFailed(("Forwarders are not supported!\n"));
     980                }
    978981                continue;
    979982            }
  • trunk/src/VBox/Runtime/include/internal/dbgmod.h

    r46101 r46113  
    115115     */
    116116    DECLCALLBACKMEMBER(int, pfnEnumSegments)(PRTDBGMODINT pMod, PFNRTLDRENUMSEGS pfnCallback, void *pvUser);
     117
     118    /**
     119     * Enumerates the symbols exported by the module.
     120     *
     121     * @returns iprt status code, which might have been returned by pfnCallback.
     122     * @param   pMod            Pointer to the module structure.
     123     * @param   fFlags          Flags indicating what to return and such.
     124     * @param   BaseAddress     The image base addressto use when calculating the
     125     *                          symbol values.
     126     * @param   pfnCallback     The callback function which each symbol is to be fed
     127     *                          to.
     128     * @param   pvUser          User argument to pass to the enumerator.
     129     */
     130    DECLCALLBACKMEMBER(int, pfnEnumSymbols)(PRTDBGMODINT pMod, uint32_t fFlags, RTLDRADDR BaseAddress,
     131                                            PFNRTLDRENUMSYMS pfnCallback, void *pvUser);
    117132
    118133    /**
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