VirtualBox

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


Ignore:
Timestamp:
Aug 26, 2011 2:34:49 PM (14 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
73710
Message:

dwarf hacking in progress...

File:
1 edited

Legend:

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

    r38547 r38554  
    3232#include "internal/iprt.h"
    3333
     34#include <iprt/asm.h>
    3435#include <iprt/err.h>
    3536#include <iprt/ctype.h>
     
    9192typedef RTDBGMODDWARF *PRTDBGMODDWARF;
    9293
     94/**
     95 * Section reader instance.
     96 */
     97typedef struct RTDWARFSECTRDR
     98{
     99    /** The DWARF debug info reader instance. */
     100    PRTDBGMODDWARF          pDwarfMod;
     101    /** The section we're reading.  */
     102    krtDbgModDwarfSect      enmSect;
     103    /** The current position. */
     104    uint8_t const          *pb;
     105    /** The number of bytes left to read. */
     106    size_t                  cbLeft;
     107    /** Set if this is 64-bit DWARF, clear if 32-bit. */
     108    bool                    f64bit;
     109    /** Set if the format endian is native, clear if endian needs to be
     110     * inverted. */
     111    bool                    fNativEndian;
     112} RTDWARFSECTRDR;
     113/** Pointer to a DWARF section reader. */
     114typedef RTDWARFSECTRDR *PRTDWARFSECTRDR;
     115
    93116
    94117
     
    146169        return VINF_SUCCESS;
    147170
    148     int rc =  pThis->pMod->pImgVt->pfnUnmapPart(pThis->pMod, pThis->aSections[enmSect].cb, &pThis->aSections[enmSect].pv);
     171    int rc = pThis->pMod->pImgVt->pfnUnmapPart(pThis->pMod, pThis->aSections[enmSect].cb, &pThis->aSections[enmSect].pv);
    149172    AssertRC(rc);
    150173    return rc;
    151174}
    152175
     176
     177/**
     178 * Corrects the endianness of a 32-bit unsigned value.
     179 *
     180 * @returns The corrected value.
     181 *
     182 * @param   pThis       The DWARF instance.
     183 * @param   pu32        The variable to correct.
     184 */
     185DECLINLINE(uint32_t) rtDbgModDwarfEndianU32(PRTDBGMODDWARF pThis, uint32_t *pu32)
     186{
     187    return *pu32;
     188}
     189
     190
     191/**
     192 * Corrects the endianness of a 64-bit unsigned value.
     193 *
     194 * @returns The corrected value.
     195 *
     196 * @param   pThis       The DWARF instance.
     197 * @param   pu64        The variable to correct.
     198 */
     199DECLINLINE(uint64_t) rtDbgModDwarfEndianU64(PRTDBGMODDWARF pThis, uint64_t *pu64)
     200{
     201    return *pu64;
     202}
     203
     204
     205static uint8_t rtDwarfSectRdrGetU8(PRTDWARFSECTRDR pSectRdr, uint8_t uErrValue)
     206{
     207    if (pSectRdr->cbLeft < 1)
     208    {
     209        pSectRdr->pb    += pSectRdr->cbLeft;
     210        pSectRdr->cbLeft = 0;
     211        return uErrValue;
     212    }
     213
     214    uint8_t u8 = pSectRdr->pb[0];
     215    pSectRdr->pb      += 1;
     216    pSectRdr->cbLeft  -= 1;
     217    return u8;
     218}
     219
     220
     221static uint16_t rtDwarfSectRdrGetU16(PRTDWARFSECTRDR pSectRdr, uint16_t uErrValue)
     222{
     223    if (pSectRdr->cbLeft < 2)
     224    {
     225        pSectRdr->pb    += pSectRdr->cbLeft;
     226        pSectRdr->cbLeft = 0;
     227        return uErrValue;
     228    }
     229
     230    uint16_t u16 = RT_MAKE_U16(pSectRdr->pb[0], pSectRdr->pb[1]);
     231    pSectRdr->pb      += 2;
     232    pSectRdr->cbLeft  -= 2;
     233    if (!pSectRdr->fNativEndian)
     234        u16 = RT_BSWAP_U16(u16);
     235    return u16;
     236}
     237
     238
     239static uint32_t rtDwarfSectRdrGetU32(PRTDWARFSECTRDR pSectRdr, uint32_t uErrValue)
     240{
     241    if (pSectRdr->cbLeft < 4)
     242    {
     243        pSectRdr->pb    += pSectRdr->cbLeft;
     244        pSectRdr->cbLeft = 0;
     245        return uErrValue;
     246    }
     247
     248    uint32_t u32 = RT_MAKE_U32_FROM_U8(pSectRdr->pb[0], pSectRdr->pb[1], pSectRdr->pb[2], pSectRdr->pb[3]);
     249    pSectRdr->pb      += 4;
     250    pSectRdr->cbLeft  -= 4;
     251    if (!pSectRdr->fNativEndian)
     252        u32 = RT_BSWAP_U32(u32);
     253    return u32;
     254}
     255
     256
     257static uint64_t rtDwarfSectRdrGetU64(PRTDWARFSECTRDR pSectRdr, uint64_t uErrValue)
     258{
     259    if (pSectRdr->cbLeft < 8)
     260    {
     261        pSectRdr->pb    += pSectRdr->cbLeft;
     262        pSectRdr->cbLeft = uErrValue;
     263        return 0;
     264    }
     265
     266    uint64_t u64 = RT_MAKE_U64_FROM_U8(pSectRdr->pb[0], pSectRdr->pb[1], pSectRdr->pb[2], pSectRdr->pb[3],
     267                                       pSectRdr->pb[4], pSectRdr->pb[5], pSectRdr->pb[6], pSectRdr->pb[7]);
     268    pSectRdr->pb      += 8;
     269    pSectRdr->cbLeft  -= 8;
     270    if (!pSectRdr->fNativEndian)
     271        u64 = RT_BSWAP_U64(u64);
     272    return u64;
     273}
     274
     275
     276static uint16_t rtDwarfSectRdrGetUHalf(PRTDWARFSECTRDR pSectRdr, uint16_t uErrValue)
     277{
     278    return rtDwarfSectRdrGetU16(pSectRdr, uErrValue);
     279}
     280
     281
     282static uint8_t rtDwarfSectRdrGetUByte(PRTDWARFSECTRDR pSectRdr, uint8_t uErrValue)
     283{
     284    return rtDwarfSectRdrGetU8(pSectRdr, uErrValue);
     285}
     286
     287
     288static int8_t rtDwarfSectRdrGetSByte(PRTDWARFSECTRDR pSectRdr, int8_t iErrValue)
     289{
     290    return (int8_t)rtDwarfSectRdrGetU8(pSectRdr, (uint8_t)iErrValue);
     291}
     292
     293
     294static uint64_t rtDwarfSectRdrGetUOff(PRTDWARFSECTRDR pSectRdr, uint64_t uErrValue)
     295{
     296    if (pSectRdr->f64bit)
     297        return rtDwarfSectRdrGetU64(pSectRdr, uErrValue);
     298    return rtDwarfSectRdrGetU32(pSectRdr, (uint32_t)uErrValue);
     299}
     300
     301
     302/**
     303 * Initialize a section reader.
     304 *
     305 * @returns IPRT status code.
     306 * @param   pSectRdr            The section reader.
     307 * @param   pThis               The dwarf module.
     308 * @param   enmSect             .
     309 */
     310static int rtDwarfSectRdrInit(PRTDWARFSECTRDR pSectRdr, PRTDBGMODDWARF pThis, krtDbgModDwarfSect enmSect)
     311{
     312    int rc = rtDbgModDwarfLoadSection(pThis, enmSect);
     313    if (RT_FAILURE(rc))
     314        return rc;
     315
     316    pSectRdr->pDwarfMod    = pThis;
     317    pSectRdr->enmSect      = enmSect;
     318    pSectRdr->pb           = (uint8_t const *)pThis->aSections[krtDbgModDwarfSect_line].pv;
     319    pSectRdr->cbLeft       = pThis->aSections[krtDbgModDwarfSect_line].cb;
     320    pSectRdr->fNativEndian = true; /** @todo endian */
     321    pSectRdr->f64bit       = false;
     322
     323    /*
     324     * Read the initial length.
     325     */
     326    uint64_t cbUnit = rtDwarfSectRdrGetU32(pSectRdr, 0);
     327    if (cbUnit == UINT32_C(0xffffffff))
     328    {
     329        pSectRdr->f64bit = true;
     330        cbUnit = rtDwarfSectRdrGetU64(pSectRdr, 0);
     331    }
     332    if (cbUnit < pSectRdr->cbLeft)
     333        pSectRdr->cbLeft = (size_t)cbUnit;
     334
     335    return VINF_SUCCESS;
     336}
     337
     338
     339/**
     340 * Deletes a section reader initialized by rtDwarfSectRdrInit.
     341 *
     342 * @param   pSectRdr            The section reader.
     343 */
     344static void rtDwarfSectRdrDelete(PRTDWARFSECTRDR pSectRdr)
     345{
     346    rtDbgModDwarfUnloadSection(pSectRdr->pDwarfMod, pSectRdr->enmSect);
     347
     348    /* ... and a drop of poison. */
     349    pSectRdr->pb = NULL;
     350    pSectRdr->cbLeft = ~(size_t)0;
     351    pSectRdr->enmSect = krtDbgModDwarfSect_End;
     352}
    153353
    154354
     
    301501static int rtDbgModDwarfExplodeLineNumbers(PRTDBGMODDWARF pThis)
    302502{
    303     int rc = rtDbgModDwarfLoadSection(pThis, krtDbgModDwarfSect_line);
     503    if (!pThis->aSections[krtDbgModDwarfSect_line].fPresent)
     504        return VINF_SUCCESS;
     505
     506    RTDWARFSECTRDR SectRdr;
     507    int rc = rtDwarfSectRdrInit(&SectRdr, pThis, krtDbgModDwarfSect_line);
    304508    if (RT_FAILURE(rc))
    305509        return rc;
    306510
    307 #if 0 /** @todo  */
    308     size_t          cbLeft = pThis->aSections[krtDbgModDwarfSect_line].cb;
    309     uint8_t const  *pb     = (uint8_t const *)pThis->aSections[krtDbgModDwarfSect_line].pv;
    310     while (cbLeft > 0)
    311     {
    312 
    313     }
    314 #endif
    315 
    316     rtDbgModDwarfUnloadSection(pThis, krtDbgModDwarfSect_line);
     511    /*
     512     * Parse the header.
     513     */
     514    uint32_t const uVer           = rtDwarfSectRdrGetUHalf(&SectRdr, 0);
     515    uint64_t const cbSkipAfterHdr = rtDwarfSectRdrGetUOff(&SectRdr, 0);
     516    uint8_t  const cbMinInstr     = rtDwarfSectRdrGetUByte(&SectRdr, 0);
     517    uint8_t  const cbMaxInstr     = rtDwarfSectRdrGetUByte(&SectRdr, 0);
     518    uint8_t  const fDefIsStmt     = rtDwarfSectRdrGetUByte(&SectRdr, 0);
     519    int8_t   const i8LineBase     = rtDwarfSectRdrGetSByte(&SectRdr, 0);
     520    uint8_t  const u8LineRange    = rtDwarfSectRdrGetUByte(&SectRdr, 0);
     521    uint8_t  const u8OpcodeBase   = rtDwarfSectRdrGetUByte(&SectRdr, 0);
     522    /*...*/
     523
     524    if (uVer >= 2 && uVer <= 4)
     525    {
     526        /*
     527         * Run the program....
     528         */
     529
     530    }
     531
     532    rtDwarfSectRdrDelete(&SectRdr);
    317533    return rc;
    318534}
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