VirtualBox

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


Ignore:
Timestamp:
Aug 25, 2011 2:30:23 PM (13 years ago)
Author:
vboxsync
Message:

iprt: debug info coding...

Location:
trunk/src/VBox/Runtime/common
Files:
3 edited

Legend:

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

    r38515 r38531  
    4444*******************************************************************************/
    4545/**
     46 * DWARF sections.
     47 */
     48typedef enum krtDbgModDwarfSect
     49{
     50    krtDbgModDwarfSect_abbrev = 0,
     51    krtDbgModDwarfSect_aranges,
     52    krtDbgModDwarfSect_frame,
     53    krtDbgModDwarfSect_info,
     54    krtDbgModDwarfSect_inlined,
     55    krtDbgModDwarfSect_line,
     56    krtDbgModDwarfSect_loc,
     57    krtDbgModDwarfSect_macinfo,
     58    krtDbgModDwarfSect_pubnames,
     59    krtDbgModDwarfSect_pubtypes,
     60    krtDbgModDwarfSect_ranges,
     61    krtDbgModDwarfSect_str,
     62    krtDbgModDwarfSect_types,
     63    /** End of valid parts (exclusive). */
     64    krtDbgModDwarfSect_End
     65} krtDbgModDwarfSect;
     66
     67/**
    4668 * The instance data of the DWARF reader.
    4769 */
    4870typedef struct RTDBGMODDWARF
    4971{
    50     /** Pointer to back to the debug info module.  */
     72    /** The debug container containing doing the real work. */
     73    RTDBGMOD            hCnt;
     74    /** Pointer to back to the debug info module (no reference ofc). */
    5175    PRTDBGMODINT        pMod;
    52     /** The number of DWARF sections in the image. */
    53     uint32_t            cSections;
    5476
    5577    /** Total line number count. */
     
    5779    /** Total symbol count. */
    5880    uint32_t            cSymbols;
     81
     82    /** DWARF debug info sections. */
     83    struct
     84    {
     85        /** The file offset of the part. */
     86        RTFOFF          offFile;
     87        /** The size of the part. */
     88        size_t          cb;
     89        /** The memory mapping of the part. */
     90        void const     *pv;
     91        /** Set if present. */
     92        bool            fPresent;
     93    } aSections[krtDbgModDwarfSect_End];
    5994} RTDBGMODDWARF;
    6095/** Pointer to instance data of the DWARF reader. */
     
    6398
    6499
     100/**
     101 * Loads a DWARF section from the image file.
     102 *
     103 * @returns IPRT status code.
     104 * @param   pThis               The DWARF instance.
     105 * @param   enmSect             The section to load.
     106 */
     107static int rtDbgModDwarfLoadSection(PRTDBGMODDWARF pThis, krtDbgModDwarfSect enmSect)
     108{
     109    /*
     110     * Don't load stuff twice.
     111     */
     112    if (pThis->aSections[enmSect].pv)
     113        return VINF_SUCCESS;
     114
     115    /*
     116     * Sections that are not present cannot be loaded, treat them like they
     117     * are empty
     118     */
     119    if (!pThis->aSections[enmSect].fPresent)
     120    {
     121        Assert(pThis->aSections[enmSect].cb);
     122        return VINF_SUCCESS;
     123    }
     124    if (!pThis->aSections[enmSect].cb)
     125        return VINF_SUCCESS;
     126
     127    /*
     128     * Sections must be readable with the current image interface.
     129     */
     130    if (pThis->aSections[enmSect].offFile < 0)
     131        return VERR_OUT_OF_RANGE;
     132
     133    /*
     134     * Do the job.
     135     */
     136    return pThis->pMod->pImgVt->pfnMapPart(pThis->pMod, pThis->aSections[enmSect].offFile, pThis->aSections[enmSect].cb,
     137                                           &pThis->aSections[enmSect].pv);
     138}
     139
     140
     141/**
     142 * Unloads a DWARF section previously mapped by rtDbgModDwarfLoadSection.
     143 *
     144 * @returns IPRT status code.
     145 * @param   pThis               The DWARF instance.
     146 * @param   enmSect             The section to unload.
     147 */
     148static int rtDbgModDwarfUnloadSection(PRTDBGMODDWARF pThis, krtDbgModDwarfSect enmSect)
     149{
     150    if (!pThis->aSections[enmSect].pv)
     151        return VINF_SUCCESS;
     152
     153    return pThis->pMod->pImgVt->pfnUnmapPart(pThis->pMod, pThis->aSections[enmSect].cb, &pThis->aSections[enmSect].pv);
     154}
     155
     156
     157
    65158/** @interface_method_impl{RTDBGMODVTDBG,pfnLineByAddr} */
    66159static DECLCALLBACK(int) rtDbgModDwarf_LineByAddr(PRTDBGMODINT pMod, RTDBGSEGIDX iSeg, RTUINTPTR off,
     
    68161{
    69162    PRTDBGMODDWARF pThis = (PRTDBGMODDWARF)pMod->pvDbgPriv;
    70     return VERR_DBG_NO_LINE_NUMBERS;
     163    return RTDbgModLineByAddr(pThis->hCnt, iSeg, off, poffDisp, pLineInfo);
    71164}
    72165
     
    76169{
    77170    PRTDBGMODDWARF pThis = (PRTDBGMODDWARF)pMod->pvDbgPriv;
    78     return VERR_DBG_NO_LINE_NUMBERS;
     171    return RTDbgModLineByOrdinal(pThis->hCnt, iOrdinal, pLineInfo);
    79172}
    80173
     
    84177{
    85178    PRTDBGMODDWARF pThis = (PRTDBGMODDWARF)pMod->pvDbgPriv;
    86     return pThis->cLines;
     179    return RTDbgModLineCount(pThis->hCnt);
    87180}
    88181
     
    92185                                               uint32_t iSeg, RTUINTPTR off, uint32_t *piOrdinal)
    93186{
    94     return VERR_NOT_SUPPORTED;
     187    PRTDBGMODDWARF pThis = (PRTDBGMODDWARF)pMod->pvDbgPriv;
     188    return RTDbgModLineAdd(pThis->hCnt, pszFile, uLineNo, iSeg, off, piOrdinal);
    95189}
    96190
     
    185279{
    186280    PRTDBGMODDWARF pThis = (PRTDBGMODDWARF)pMod->pvDbgPriv;
     281
     282    for (unsigned iSect = 0; iSect < RT_ELEMENTS(pThis->aSections); iSect++)
     283        if (pThis->aSections[iSect].pv)
     284            pThis->pMod->pImgVt->pfnUnmapPart(pThis->pMod, pThis->aSections[iSect].cb, &pThis->aSections[iSect].pv);
     285
     286    RTDbgModRelease(pThis->hCnt);
    187287    RTMemFree(pThis);
     288
    188289    return VINF_SUCCESS;
    189290}
    190291
    191292
     293static int rtDbgModDwarfExplodeLineNumbers(PRTDBGMODDWARF pThis)
     294{
     295    if (!pThis->aSections[krtDbgModDwarfSect_line].fPresent)
     296        return VINF_SUCCESS;
     297    int rc = rtDbgModDwarfLoadSection(pThis, krtDbgModDwarfSect_line);
     298    if (RT_FAILURE(rc))
     299        return rc;
     300
     301
     302    int rc2 = rtDbgModDwarfUnloadSection(pThis, krtDbgModDwarfSect_line);
     303    return RT_SUCCESS(rc2) || RT_FAILURE(rc) ? rc : rc2;
     304}
     305
     306
     307static int rtDbgModDwarfExtractSymbols(PRTDBGMODDWARF pThis)
     308{
     309    int rc = rtDbgModDwarfLoadSection(pThis, krtDbgModDwarfSect_info);
     310    if (RT_FAILURE(rc))
     311        return rc;
     312
     313
     314    return VERR_NOT_IMPLEMENTED;
     315}
     316
     317
    192318/** @callback_method_impl{FNRTLDRENUMDBG} */
    193 static DECLCALLBACK(int) rtDbgModDwarf_EnumCallback(RTLDRMOD hLdrMod, uint32_t iDbgInfo, RTLDRDBGINFOTYPE enmType,
    194                                                     uint16_t iMajorVer, uint16_t iMinorVer, const char *pszPartNm,
    195                                                     RTFOFF offFile, RTUINTPTR LinkAddress, RTUINTPTR cb,
    196                                                     const char *pszExtFile, void *pvUser)
     319static DECLCALLBACK(int) rtDbgModDwarfEnumCallback(RTLDRMOD hLdrMod, uint32_t iDbgInfo, RTLDRDBGINFOTYPE enmType,
     320                                                   uint16_t iMajorVer, uint16_t iMinorVer, const char *pszPartNm,
     321                                                   RTFOFF offFile, RTUINTPTR LinkAddress, RTUINTPTR cb,
     322                                                   const char *pszExtFile, void *pvUser)
    197323{
    198324    /*
     
    204330        return VINF_SUCCESS;
    205331
     332    /*
     333     * Must have a part name starting with debug_ and possibly prefixed by dots
     334     * or underscores.
     335     */
     336    if (!strncmp(pszPartNm, ".debug_", sizeof(".debug_") - 1))
     337        pszPartNm += sizeof(".debug_") - 1;
     338    else if (!strncmp(pszPartNm, "__debug_", sizeof("__debug_") - 1))
     339        pszPartNm += sizeof("__debug_") - 1;
     340    else
     341        AssertMsgFailedReturn(("%s\n", pszPartNm), VINF_SUCCESS /*ignore*/);
     342
     343    /*
     344     * Figure out which part we're talking about.
     345     */
     346    krtDbgModDwarfSect enmSect;
     347    if (0) { /* dummy */ }
     348#define ELSE_IF_STRCMP_SET(a_Name) else if (!strcmp(pszPartNm, #a_Name))  enmSect = krtDbgModDwarfSect_ ## a_Name
     349    ELSE_IF_STRCMP_SET(abbrev);
     350    ELSE_IF_STRCMP_SET(aranges);
     351    ELSE_IF_STRCMP_SET(frame);
     352    ELSE_IF_STRCMP_SET(info);
     353    ELSE_IF_STRCMP_SET(inlined);
     354    ELSE_IF_STRCMP_SET(line);
     355    ELSE_IF_STRCMP_SET(loc);
     356    ELSE_IF_STRCMP_SET(macinfo);
     357    ELSE_IF_STRCMP_SET(pubnames);
     358    ELSE_IF_STRCMP_SET(pubtypes);
     359    ELSE_IF_STRCMP_SET(ranges);
     360    ELSE_IF_STRCMP_SET(str);
     361    ELSE_IF_STRCMP_SET(types);
     362#undef ELSE_IF_STRCMP_SET
     363    else
     364    {
     365        AssertMsgFailed(("%s\n", pszPartNm));
     366        return VINF_SUCCESS;
     367    }
     368
     369    /*
     370     * Record the section.
     371     */
    206372    PRTDBGMODDWARF pThis = (PRTDBGMODDWARF)pvUser;
    207     pThis->cSections++;
    208     /** @todo detect what and record it  */
     373    AssertMsgReturn(!pThis->aSections[enmSect].fPresent, ("duplicate %s\n", pszPartNm), VINF_SUCCESS /*ignore*/);
     374
     375    pThis->aSections[enmSect].fPresent  = true;
     376    pThis->aSections[enmSect].offFile   = offFile;
     377    pThis->aSections[enmSect].pv        = NULL;
     378    pThis->aSections[enmSect].cb        = (size_t)cb;
     379    if (pThis->aSections[enmSect].cb != cb)
     380        pThis->aSections[enmSect].cb    = ~(size_t)0;
     381
    209382    return VINF_SUCCESS;
    210383}
     
    221394
    222395    /*
    223      * Enumeate the debug info in the module, looking for DWARF bits.
     396     * Enumerate the debug info in the module, looking for DWARF bits.
    224397     */
    225398    PRTDBGMODDWARF pThis = (PRTDBGMODDWARF)RTMemAllocZ(sizeof(*pThis));
     
    228401    pThis->pMod = pMod;
    229402
    230     int rc = pMod->pImgVt->pfnEnumDbgInfo(pMod, rtDbgModDwarf_EnumCallback, pThis);
     403    int rc = pMod->pImgVt->pfnEnumDbgInfo(pMod, rtDbgModDwarfEnumCallback, pThis);
    231404    if (RT_SUCCESS(rc))
    232405    {
    233         if (pThis->cSections)
     406        if (pThis->aSections[krtDbgModDwarfSect_info].fPresent)
    234407        {
    235             pMod->pvDbgPriv = pThis;
    236             return VINF_SUCCESS;
     408            /*
     409             * Extract / explode the data we want (symbols and line numbers)
     410             * storing them in a container module.
     411             */
     412            rc = RTDbgModCreate(&pThis->hCnt, pMod->pszName, 0 /*cbSeg*/, 0 /*fFlags*/);
     413            if (RT_SUCCESS(rc))
     414            {
     415                rc = rtDbgModDwarfExtractSymbols(pThis);
     416                if (RT_SUCCESS(rc))
     417                    rc = rtDbgModDwarfExplodeLineNumbers(pThis);
     418                if (RT_SUCCESS(rc))
     419                {
     420                    pMod->pvDbgPriv = pThis;
     421                    return VINF_SUCCESS;
     422                }
     423
     424                /* bail out. */
     425                RTDbgModRelease(pThis->hCnt);
     426            }
    237427        }
    238 
    239         /* Didn't find any DWARF info, bail out. */
    240         rc = VERR_DBG_NO_MATCHING_INTERPRETER;
     428        else
     429            rc = VERR_DBG_NO_MATCHING_INTERPRETER;
    241430    }
    242431    RTMemFree(pThis);
  • trunk/src/VBox/Runtime/common/dbg/dbgmodldr.cpp

    r38516 r38531  
    110110    /*.pfnClose = */            rtDbgModLdr_Close,
    111111    /*.pfnEnumDbgInfo = */      rtDbgModLdr_EnumDbgInfo,
     112    /*.pfnMapPart = */          NULL /** @todo*/,
     113    /*.pfnUnmapPart = */        NULL /** @todo*/,
    112114
    113115    /*.u32EndMagic = */         RTDBGMODVTIMG_MAGIC
  • trunk/src/VBox/Runtime/common/ldr/ldrkStuff.cpp

    r38515 r38531  
    8686    {
    8787        PFNRT            pfn;
     88        PFNRTLDRENUMDBG  pfnEnumDbgInfo;
    8889        PFNRTLDRENUMSYMS pfnEnumSyms;
    8990        PFNRTLDRIMPORT   pfnGetImport;
     
    9293    const void         *pvBits;
    9394    PRTLDRMODKLDR       pMod;
     95    int                 rc;
    9496} RTLDRMODKLDRARGS, *PRTLDRMODKLDRARGS;
    95 
    96 
    97 /*******************************************************************************
    98 *   Internal Functions                                                         *
    99 *******************************************************************************/
    100 static int rtkldrConvertError(int krc);
    101 static int rtkldrConvertErrorFromIPRT(int rc);
    102 
    103 
    104 static int      rtkldrRdrCreate(  PPKRDR ppRdr, const char *pszFilename);
    105 static int      rtkldrRdrDestroy( PKRDR pRdr);
    106 static int      rtkldrRdrRead(    PKRDR pRdr, void *pvBuf, KSIZE cb, KFOFF off);
    107 static int      rtkldrRdrAllMap(  PKRDR pRdr, const void **ppvBits);
    108 static int      rtkldrRdrAllUnmap(PKRDR pRdr, const void *pvBits);
    109 static KFOFF rtkldrRdrSize(    PKRDR pRdr);
    110 static KFOFF rtkldrRdrTell(    PKRDR pRdr);
    111 static const char * rtkldrRdrName(PKRDR pRdr);
    112 static KIPTR    rtkldrRdrNativeFH(PKRDR pRdr);
    113 static KSIZE    rtkldrRdrPageSize(PKRDR pRdr);
    114 static int      rtkldrRdrMap(     PKRDR pRdr, void **ppvBase, KU32 cSegments, PCKLDRSEG paSegments, KBOOL fFixed);
    115 static int      rtkldrRdrRefresh( PKRDR pRdr, void *pvBase, KU32 cSegments, PCKLDRSEG paSegments);
    116 static int      rtkldrRdrProtect( PKRDR pRdr, void *pvBase, KU32 cSegments, PCKLDRSEG paSegments, KBOOL fUnprotectOrProtect);
    117 static int      rtkldrRdrUnmap(   PKRDR pRdr, void *pvBase, KU32 cSegments, PCKLDRSEG paSegments);
    118 static void     rtkldrRdrDone(    PKRDR pRdr);
    119 
    120 
    121 static DECLCALLBACK(int) rtkldrClose(PRTLDRMODINTERNAL pMod);
    122 static DECLCALLBACK(int) rtkldrDone(PRTLDRMODINTERNAL pMod);
    123 static DECLCALLBACK(int) rtkldrEnumSymbols(PRTLDRMODINTERNAL pMod, unsigned fFlags, const void *pvBits,
    124                                            RTUINTPTR BaseAddress,PFNRTLDRENUMSYMS pfnCallback, void *pvUser);
    125 static int rtkldrEnumSymbolsWrapper(PKLDRMOD pMod, uint32_t iSymbol,
    126                                     const char *pchSymbol, KSIZE cchSymbol, const char *pszVersion,
    127                                     KLDRADDR uValue, uint32_t fKind, void *pvUser);
    128 static DECLCALLBACK(size_t) rtkldrGetImageSize(PRTLDRMODINTERNAL pMod);
    129 static DECLCALLBACK(int) rtkldrGetBits(PRTLDRMODINTERNAL pMod, void *pvBits, RTUINTPTR BaseAddress,
    130                                        PFNRTLDRIMPORT pfnGetImport, void *pvUser);
    131 static DECLCALLBACK(int) rtkldrRelocate(PRTLDRMODINTERNAL pMod, void *pvBits, RTUINTPTR NewBaseAddress,
    132                                         RTUINTPTR OldBaseAddress, PFNRTLDRIMPORT pfnGetImport, void *pvUser);
    133 static int rtkldrGetImportWrapper(PKLDRMOD pMod, uint32_t iImport, uint32_t iSymbol, const char *pchSymbol, KSIZE cchSymbol,
    134                                   const char *pszVersion, PKLDRADDR puValue, uint32_t *pfKind, void *pvUser);
    135 
    136 static DECLCALLBACK(int) rtkldrGetSymbolEx(PRTLDRMODINTERNAL pMod, const void *pvBits, RTUINTPTR BaseAddress,
    137                                            const char *pszSymbol, RTUINTPTR *pValue);
    138 static DECLCALLBACK(int) rtkldr_EnumDbgInfo(PRTLDRMODINTERNAL pMod, const void *pvBits,
    139                                             PFNRTLDRENUMDBG pfnCallback, void *pvUser);
    140 
    14197
    14298
     
    271227
    272228
     229
     230/** @copydoc KLDRRDROPS::pfnCreate
     231 * @remark This is a dummy which isn't used. */
     232static int      rtkldrRdr_Create(  PPKRDR ppRdr, const char *pszFilename)
     233{
     234    AssertReleaseFailed();
     235    return -1;
     236}
     237
     238
     239/** @copydoc KLDRRDROPS::pfnDestroy */
     240static int      rtkldrRdr_Destroy( PKRDR pRdr)
     241{
     242    PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader;
     243    int rc = pReader->pfnDestroy(pReader);
     244    return rtkldrConvertErrorFromIPRT(rc);
     245}
     246
     247
     248/** @copydoc KLDRRDROPS::pfnRead */
     249static int      rtkldrRdr_Read(    PKRDR pRdr, void *pvBuf, KSIZE cb, KFOFF off)
     250{
     251    PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader;
     252    int rc = pReader->pfnRead(pReader, pvBuf, cb, off);
     253    return rtkldrConvertErrorFromIPRT(rc);
     254}
     255
     256
     257/** @copydoc KLDRRDROPS::pfnAllMap */
     258static int      rtkldrRdr_AllMap(  PKRDR pRdr, const void **ppvBits)
     259{
     260    PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader;
     261    int rc = pReader->pfnMap(pReader, ppvBits);
     262    return rtkldrConvertErrorFromIPRT(rc);
     263}
     264
     265
     266/** @copydoc KLDRRDROPS::pfnAllUnmap */
     267static int      rtkldrRdr_AllUnmap(PKRDR pRdr, const void *pvBits)
     268{
     269    PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader;
     270    int rc = pReader->pfnUnmap(pReader, pvBits);
     271    return rtkldrConvertErrorFromIPRT(rc);
     272}
     273
     274
     275/** @copydoc KLDRRDROPS::pfnSize */
     276static KFOFF rtkldrRdr_Size(    PKRDR pRdr)
     277{
     278    PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader;
     279    return (KFOFF)pReader->pfnSize(pReader);
     280}
     281
     282
     283/** @copydoc KLDRRDROPS::pfnTell */
     284static KFOFF rtkldrRdr_Tell(    PKRDR pRdr)
     285{
     286    PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader;
     287    return (KFOFF)pReader->pfnTell(pReader);
     288}
     289
     290
     291/** @copydoc KLDRRDROPS::pfnName */
     292static const char * rtkldrRdr_Name(PKRDR pRdr)
     293{
     294    PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader;
     295    return pReader->pfnLogName(pReader);
     296}
     297
     298
     299/** @copydoc KLDRRDROPS::pfnNativeFH */
     300static KIPTR rtkldrRdr_NativeFH(PKRDR pRdr)
     301{
     302    AssertFailed();
     303    return -1;
     304}
     305
     306
     307/** @copydoc KLDRRDROPS::pfnPageSize */
     308static KSIZE rtkldrRdr_PageSize(PKRDR pRdr)
     309{
     310    return PAGE_SIZE;
     311}
     312
     313
     314/** @copydoc KLDRRDROPS::pfnMap */
     315static int      rtkldrRdr_Map(     PKRDR pRdr, void **ppvBase, KU32 cSegments, PCKLDRSEG paSegments, KBOOL fFixed)
     316{
     317    //PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader;
     318    AssertFailed();
     319    return -1;
     320}
     321
     322
     323/** @copydoc KLDRRDROPS::pfnRefresh */
     324static int      rtkldrRdr_Refresh( PKRDR pRdr, void *pvBase, KU32 cSegments, PCKLDRSEG paSegments)
     325{
     326    //PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader;
     327    AssertFailed();
     328    return -1;
     329}
     330
     331
     332/** @copydoc KLDRRDROPS::pfnProtect */
     333static int      rtkldrRdr_Protect( PKRDR pRdr, void *pvBase, KU32 cSegments, PCKLDRSEG paSegments, KBOOL fUnprotectOrProtect)
     334{
     335    //PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader;
     336    AssertFailed();
     337    return -1;
     338}
     339
     340
     341/** @copydoc KLDRRDROPS::pfnUnmap */
     342static int      rtkldrRdr_Unmap(   PKRDR pRdr, void *pvBase, KU32 cSegments, PCKLDRSEG paSegments)
     343{
     344    //PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader;
     345    AssertFailed();
     346    return -1;
     347}
     348
     349/** @copydoc KLDRRDROPS::pfnDone */
     350static void     rtkldrRdr_Done(    PKRDR pRdr)
     351{
     352    //PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader;
     353}
     354
     355
    273356/**
    274357 * The file reader operations.
     
    280363    /* .pszName = */        "IPRT",
    281364    /* .pNext = */          NULL,
    282     /* .pfnCreate = */      rtkldrRdrCreate,
    283     /* .pfnDestroy = */     rtkldrRdrDestroy,
    284     /* .pfnRead = */        rtkldrRdrRead,
    285     /* .pfnAllMap = */      rtkldrRdrAllMap,
    286     /* .pfnAllUnmap = */    rtkldrRdrAllUnmap,
    287     /* .pfnSize = */        rtkldrRdrSize,
    288     /* .pfnTell = */        rtkldrRdrTell,
    289     /* .pfnName = */        rtkldrRdrName,
    290     /* .pfnNativeFH = */    rtkldrRdrNativeFH,
    291     /* .pfnPageSize = */    rtkldrRdrPageSize,
    292     /* .pfnMap = */         rtkldrRdrMap,
    293     /* .pfnRefresh = */     rtkldrRdrRefresh,
    294     /* .pfnProtect = */     rtkldrRdrProtect,
    295     /* .pfnUnmap =  */      rtkldrRdrUnmap,
    296     /* .pfnDone = */        rtkldrRdrDone,
     365    /* .pfnCreate = */      rtkldrRdr_Create,
     366    /* .pfnDestroy = */     rtkldrRdr_Destroy,
     367    /* .pfnRead = */        rtkldrRdr_Read,
     368    /* .pfnAllMap = */      rtkldrRdr_AllMap,
     369    /* .pfnAllUnmap = */    rtkldrRdr_AllUnmap,
     370    /* .pfnSize = */        rtkldrRdr_Size,
     371    /* .pfnTell = */        rtkldrRdr_Tell,
     372    /* .pfnName = */        rtkldrRdr_Name,
     373    /* .pfnNativeFH = */    rtkldrRdr_NativeFH,
     374    /* .pfnPageSize = */    rtkldrRdr_PageSize,
     375    /* .pfnMap = */         rtkldrRdr_Map,
     376    /* .pfnRefresh = */     rtkldrRdr_Refresh,
     377    /* .pfnProtect = */     rtkldrRdr_Protect,
     378    /* .pfnUnmap =  */      rtkldrRdr_Unmap,
     379    /* .pfnDone = */        rtkldrRdr_Done,
    297380    /* .u32Dummy = */       42
    298381};
    299382
    300383
    301 /** @copydoc KLDRRDROPS::pfnCreate
    302  * @remark This is a dummy which isn't used. */
    303 static int      rtkldrRdrCreate(  PPKRDR ppRdr, const char *pszFilename)
    304 {
    305     AssertReleaseFailed();
    306     return -1;
    307 }
    308 
    309 
    310 /** @copydoc KLDRRDROPS::pfnDestroy */
    311 static int      rtkldrRdrDestroy( PKRDR pRdr)
    312 {
    313     PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader;
    314     int rc = pReader->pfnDestroy(pReader);
    315     return rtkldrConvertErrorFromIPRT(rc);
    316 }
    317 
    318 
    319 /** @copydoc KLDRRDROPS::pfnRead */
    320 static int      rtkldrRdrRead(    PKRDR pRdr, void *pvBuf, KSIZE cb, KFOFF off)
    321 {
    322     PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader;
    323     int rc = pReader->pfnRead(pReader, pvBuf, cb, off);
    324     return rtkldrConvertErrorFromIPRT(rc);
    325 }
    326 
    327 
    328 /** @copydoc KLDRRDROPS::pfnAllMap */
    329 static int      rtkldrRdrAllMap(  PKRDR pRdr, const void **ppvBits)
    330 {
    331     PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader;
    332     int rc = pReader->pfnMap(pReader, ppvBits);
    333     return rtkldrConvertErrorFromIPRT(rc);
    334 }
    335 
    336 
    337 /** @copydoc KLDRRDROPS::pfnAllUnmap */
    338 static int      rtkldrRdrAllUnmap(PKRDR pRdr, const void *pvBits)
    339 {
    340     PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader;
    341     int rc = pReader->pfnUnmap(pReader, pvBits);
    342     return rtkldrConvertErrorFromIPRT(rc);
    343 }
    344 
    345 
    346 /** @copydoc KLDRRDROPS::pfnSize */
    347 static KFOFF rtkldrRdrSize(    PKRDR pRdr)
    348 {
    349     PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader;
    350     return (KFOFF)pReader->pfnSize(pReader);
    351 }
    352 
    353 
    354 /** @copydoc KLDRRDROPS::pfnTell */
    355 static KFOFF rtkldrRdrTell(    PKRDR pRdr)
    356 {
    357     PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader;
    358     return (KFOFF)pReader->pfnTell(pReader);
    359 }
    360 
    361 
    362 /** @copydoc KLDRRDROPS::pfnName */
    363 static const char * rtkldrRdrName(PKRDR pRdr)
    364 {
    365     PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader;
    366     return pReader->pfnLogName(pReader);
    367 }
    368 
    369 
    370 /** @copydoc KLDRRDROPS::pfnNativeFH */
    371 static KIPTR rtkldrRdrNativeFH(PKRDR pRdr)
    372 {
    373     AssertFailed();
    374     return -1;
    375 }
    376 
    377 
    378 /** @copydoc KLDRRDROPS::pfnPageSize */
    379 static KSIZE rtkldrRdrPageSize(PKRDR pRdr)
    380 {
    381     return PAGE_SIZE;
    382 }
    383 
    384 
    385 /** @copydoc KLDRRDROPS::pfnMap */
    386 static int      rtkldrRdrMap(     PKRDR pRdr, void **ppvBase, KU32 cSegments, PCKLDRSEG paSegments, KBOOL fFixed)
    387 {
    388     //PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader;
    389     AssertFailed();
    390     return -1;
    391 }
    392 
    393 
    394 /** @copydoc KLDRRDROPS::pfnRefresh */
    395 static int      rtkldrRdrRefresh( PKRDR pRdr, void *pvBase, KU32 cSegments, PCKLDRSEG paSegments)
    396 {
    397     //PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader;
    398     AssertFailed();
    399     return -1;
    400 }
    401 
    402 
    403 /** @copydoc KLDRRDROPS::pfnProtect */
    404 static int      rtkldrRdrProtect( PKRDR pRdr, void *pvBase, KU32 cSegments, PCKLDRSEG paSegments, KBOOL fUnprotectOrProtect)
    405 {
    406     //PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader;
    407     AssertFailed();
    408     return -1;
    409 }
    410 
    411 
    412 /** @copydoc KLDRRDROPS::pfnUnmap */
    413 static int      rtkldrRdrUnmap(   PKRDR pRdr, void *pvBase, KU32 cSegments, PCKLDRSEG paSegments)
    414 {
    415     //PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader;
    416     AssertFailed();
    417     return -1;
    418 }
    419 
    420 /** @copydoc KLDRRDROPS::pfnDone */
    421 static void     rtkldrRdrDone(    PKRDR pRdr)
    422 {
    423     //PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader;
    424 }
    425 
    426 
    427 
    428 
    429 
    430 
    431 /**
    432  * Operations for a kLdr module.
    433  */
    434 static const RTLDROPS g_rtkldrOps =
    435 {
    436     "kLdr",
    437     rtkldrClose,
    438     NULL,
    439     rtkldrDone,
    440     rtkldrEnumSymbols,
    441     /* ext */
    442     rtkldrGetImageSize,
    443     rtkldrGetBits,
    444     rtkldrRelocate,
    445     rtkldrGetSymbolEx,
    446     rtkldr_EnumDbgInfo,
    447     42
    448 };
     384
    449385
    450386
    451387/** @copydoc RTLDROPS::pfnClose */
    452 static DECLCALLBACK(int) rtkldrClose(PRTLDRMODINTERNAL pMod)
     388static DECLCALLBACK(int) rtkldr_Close(PRTLDRMODINTERNAL pMod)
    453389{
    454390    PKLDRMOD pModkLdr = ((PRTLDRMODKLDR)pMod)->pMod;
     
    459395
    460396/** @copydoc RTLDROPS::pfnDone */
    461 static DECLCALLBACK(int) rtkldrDone(PRTLDRMODINTERNAL pMod)
     397static DECLCALLBACK(int) rtkldr_Done(PRTLDRMODINTERNAL pMod)
    462398{
    463399    PKLDRMOD pModkLdr = ((PRTLDRMODKLDR)pMod)->pMod;
    464400    int rc = kLdrModMostlyDone(pModkLdr);
    465     return rtkldrConvertError(rc);
    466 }
    467 
    468 
    469 /** @copydoc RTLDROPS::pfnEnumSymbols */
    470 static DECLCALLBACK(int) rtkldrEnumSymbols(PRTLDRMODINTERNAL pMod, unsigned fFlags, const void *pvBits, RTUINTPTR BaseAddress,
    471                                            PFNRTLDRENUMSYMS pfnCallback, void *pvUser)
    472 {
    473     PKLDRMOD pModkLdr = ((PRTLDRMODKLDR)pMod)->pMod;
    474     RTLDRMODKLDRARGS Args;
    475     Args.pvUser = pvUser;
    476     Args.u.pfnEnumSyms = pfnCallback;
    477     Args.pMod = (PRTLDRMODKLDR)pMod;
    478     Args.pvBits = pvBits;
    479     int rc = kLdrModEnumSymbols(pModkLdr, pvBits, BaseAddress,
    480                                 fFlags & RTLDR_ENUM_SYMBOL_FLAGS_ALL ? KLDRMOD_ENUM_SYMS_FLAGS_ALL : 0,
    481                                 rtkldrEnumSymbolsWrapper, &Args);
    482401    return rtkldrConvertError(rc);
    483402}
     
    514433
    515434
     435/** @copydoc RTLDROPS::pfnEnumSymbols */
     436static DECLCALLBACK(int) rtkldr_EnumSymbols(PRTLDRMODINTERNAL pMod, unsigned fFlags, const void *pvBits, RTUINTPTR BaseAddress,
     437                                            PFNRTLDRENUMSYMS pfnCallback, void *pvUser)
     438{
     439    PKLDRMOD            pModkLdr = ((PRTLDRMODKLDR)pMod)->pMod;
     440    RTLDRMODKLDRARGS    Args;
     441    Args.pvUser         = pvUser;
     442    Args.u.pfnEnumSyms  = pfnCallback;
     443    Args.pMod           = (PRTLDRMODKLDR)pMod;
     444    Args.pvBits         = pvBits;
     445    Args.rc             = VINF_SUCCESS;
     446    int rc = kLdrModEnumSymbols(pModkLdr, pvBits, BaseAddress,
     447                                fFlags & RTLDR_ENUM_SYMBOL_FLAGS_ALL ? KLDRMOD_ENUM_SYMS_FLAGS_ALL : 0,
     448                                rtkldrEnumSymbolsWrapper, &Args);
     449    if (Args.rc != VINF_SUCCESS)
     450        rc = Args.rc;
     451    else
     452        rc = rtkldrConvertError(rc);
     453    return rc;
     454}
     455
     456
    516457/** @copydoc RTLDROPS::pfnGetImageSize */
    517 static DECLCALLBACK(size_t) rtkldrGetImageSize(PRTLDRMODINTERNAL pMod)
     458static DECLCALLBACK(size_t) rtkldr_GetImageSize(PRTLDRMODINTERNAL pMod)
    518459{
    519460    PKLDRMOD pModkLdr = ((PRTLDRMODKLDR)pMod)->pMod;
    520461    return kLdrModSize(pModkLdr);
    521 }
    522 
    523 
    524 /** @copydoc RTLDROPS::pfnGetBits */
    525 static DECLCALLBACK(int) rtkldrGetBits(PRTLDRMODINTERNAL pMod, void *pvBits, RTUINTPTR BaseAddress,
    526                                        PFNRTLDRIMPORT pfnGetImport, void *pvUser)
    527 {
    528     PKLDRMOD pModkLdr = ((PRTLDRMODKLDR)pMod)->pMod;
    529     RTLDRMODKLDRARGS Args;
    530     Args.pvUser = pvUser;
    531     Args.u.pfnGetImport = pfnGetImport;
    532     Args.pMod = (PRTLDRMODKLDR)pMod;
    533     Args.pvBits = pvBits;
    534     int rc = kLdrModGetBits(pModkLdr, pvBits, BaseAddress, rtkldrGetImportWrapper, &Args);
    535     return rtkldrConvertError(rc);
    536 }
    537 
    538 
    539 /** @copydoc RTLDROPS::pfnRelocate */
    540 static DECLCALLBACK(int) rtkldrRelocate(PRTLDRMODINTERNAL pMod, void *pvBits, RTUINTPTR NewBaseAddress,
    541                                         RTUINTPTR OldBaseAddress, PFNRTLDRIMPORT pfnGetImport, void *pvUser)
    542 {
    543     PKLDRMOD pModkLdr = ((PRTLDRMODKLDR)pMod)->pMod;
    544     RTLDRMODKLDRARGS Args;
    545     Args.pvUser = pvUser;
    546     Args.u.pfnGetImport = pfnGetImport;
    547     Args.pMod = (PRTLDRMODKLDR)pMod;
    548     Args.pvBits = pvBits;
    549     int rc = kLdrModRelocateBits(pModkLdr, pvBits, NewBaseAddress, OldBaseAddress, rtkldrGetImportWrapper, &Args);
    550     return rtkldrConvertError(rc);
    551462}
    552463
     
    597508
    598509
     510/** @copydoc RTLDROPS::pfnGetBits */
     511static DECLCALLBACK(int) rtkldr_GetBits(PRTLDRMODINTERNAL pMod, void *pvBits, RTUINTPTR BaseAddress,
     512                                        PFNRTLDRIMPORT pfnGetImport, void *pvUser)
     513{
     514    PKLDRMOD            pModkLdr = ((PRTLDRMODKLDR)pMod)->pMod;
     515    RTLDRMODKLDRARGS    Args;
     516    Args.pvUser         = pvUser;
     517    Args.u.pfnGetImport = pfnGetImport;
     518    Args.pMod           = (PRTLDRMODKLDR)pMod;
     519    Args.pvBits         = pvBits;
     520    Args.rc             = VINF_SUCCESS;
     521    int rc = kLdrModGetBits(pModkLdr, pvBits, BaseAddress, rtkldrGetImportWrapper, &Args);
     522    if (Args.rc != VINF_SUCCESS)
     523        rc = Args.rc;
     524    else
     525        rc = rtkldrConvertError(rc);
     526    return rc;
     527}
     528
     529
     530/** @copydoc RTLDROPS::pfnRelocate */
     531static DECLCALLBACK(int) rtkldr_Relocate(PRTLDRMODINTERNAL pMod, void *pvBits, RTUINTPTR NewBaseAddress,
     532                                         RTUINTPTR OldBaseAddress, PFNRTLDRIMPORT pfnGetImport, void *pvUser)
     533{
     534    PKLDRMOD            pModkLdr = ((PRTLDRMODKLDR)pMod)->pMod;
     535    RTLDRMODKLDRARGS    Args;
     536    Args.pvUser         = pvUser;
     537    Args.u.pfnGetImport = pfnGetImport;
     538    Args.pMod           = (PRTLDRMODKLDR)pMod;
     539    Args.pvBits         = pvBits;
     540    Args.rc             = VINF_SUCCESS;
     541    int rc = kLdrModRelocateBits(pModkLdr, pvBits, NewBaseAddress, OldBaseAddress, rtkldrGetImportWrapper, &Args);
     542    if (Args.rc != VINF_SUCCESS)
     543        rc = Args.rc;
     544    else
     545        rc = rtkldrConvertError(rc);
     546    return rc;
     547}
     548
    599549
    600550/** @copydoc RTLDROPS::pfnGetSymbolEx */
    601 static DECLCALLBACK(int) rtkldrGetSymbolEx(PRTLDRMODINTERNAL pMod, const void *pvBits, RTUINTPTR BaseAddress,
    602                                            const char *pszSymbol, RTUINTPTR *pValue)
     551static DECLCALLBACK(int) rtkldr_GetSymbolEx(PRTLDRMODINTERNAL pMod, const void *pvBits, RTUINTPTR BaseAddress,
     552                                            const char *pszSymbol, RTUINTPTR *pValue)
    603553{
    604554    PKLDRMOD pModkLdr = ((PRTLDRMODKLDR)pMod)->pMod;
     
    631581
    632582
     583/** @copydoc FNKLDRENUMDBG */
     584static int rtkldrEnumDbgInfoWrapper(PKLDRMOD pMod, KU32 iDbgInfo, KLDRDBGINFOTYPE enmType, KI16 iMajorVer, KI16 iMinorVer,
     585                                    const char *pszPartNm, KLDRFOFF offFile, KLDRADDR LinkAddress, KLDRSIZE cb,
     586                                    const char *pszExtFile, void *pvUser)
     587{
     588    PRTLDRMODKLDRARGS pArgs = (PRTLDRMODKLDRARGS)pvUser;
     589
     590    RTLDRDBGINFOTYPE enmMyType;
     591    switch (enmType)
     592    {
     593        case KLDRDBGINFOTYPE_UNKNOWN:   enmMyType = RTLDRDBGINFOTYPE_UNKNOWN;  break;
     594        case KLDRDBGINFOTYPE_STABS:     enmMyType = RTLDRDBGINFOTYPE_STABS;    break;
     595        case KLDRDBGINFOTYPE_DWARF:     enmMyType = RTLDRDBGINFOTYPE_DWARF;    break;
     596        case KLDRDBGINFOTYPE_CODEVIEW:  enmMyType = RTLDRDBGINFOTYPE_CODEVIEW; break;
     597        case KLDRDBGINFOTYPE_WATCOM:    enmMyType = RTLDRDBGINFOTYPE_WATCOM;   break;
     598        case KLDRDBGINFOTYPE_HLL:       enmMyType = RTLDRDBGINFOTYPE_HLL;      break;
     599        default:
     600            AssertFailed();
     601            enmMyType = RTLDRDBGINFOTYPE_UNKNOWN;
     602            break;
     603    }
     604
     605    int rc = pArgs->u.pfnEnumDbgInfo(&pArgs->pMod->Core, iDbgInfo, enmMyType, iMajorVer, iMinorVer, pszPartNm,
     606                                     offFile, LinkAddress, cb, pszExtFile, pArgs->pvUser);
     607    if (RT_FAILURE(rc))
     608        return rc; /* don't bother converting. */
     609    return 0;
     610}
     611
     612
    633613/** @copydoc RTLDROPS::pfnEnumDbgInfo */
    634614static DECLCALLBACK(int) rtkldr_EnumDbgInfo(PRTLDRMODINTERNAL pMod, const void *pvBits,
    635615                                            PFNRTLDRENUMDBG pfnCallback, void *pvUser)
    636616{
    637     return VERR_NOT_SUPPORTED;
    638 }
     617    PRTLDRMODKLDR       pThis = (PRTLDRMODKLDR)pMod;
     618    RTLDRMODKLDRARGS    Args;
     619    Args.pvUser             = pvUser;
     620    Args.u.pfnEnumDbgInfo   = pfnCallback;
     621    Args.pvBits             = pvBits;
     622    Args.pMod               = pThis;
     623    Args.rc                 = VINF_SUCCESS;
     624    int rc = kLdrModEnumDbgInfo(pThis->pMod, pvBits, rtkldrEnumDbgInfoWrapper, &Args);
     625    if (Args.rc != VINF_SUCCESS)
     626        rc = Args.rc;
     627    return rc;
     628}
     629
     630
     631/**
     632 * Operations for a kLdr module.
     633 */
     634static const RTLDROPS g_rtkldrOps =
     635{
     636    "kLdr",
     637    rtkldr_Close,
     638    NULL,
     639    rtkldr_Done,
     640    rtkldr_EnumSymbols,
     641    /* ext */
     642    rtkldr_GetImageSize,
     643    rtkldr_GetBits,
     644    rtkldr_Relocate,
     645    rtkldr_GetSymbolEx,
     646    rtkldr_EnumDbgInfo,
     647    42
     648};
    639649
    640650
     
    667677    }
    668678
    669     /* Create a rtkldrRdr instance. */
     679    /* Create a rtkldrRdr_ instance. */
    670680    PRTKLDRRDR pRdr = (PRTKLDRRDR)RTMemAllocZ(sizeof(*pRdr));
    671681    if (!pRdr)
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