VirtualBox

Changeset 38573 in vbox


Ignore:
Timestamp:
Aug 30, 2011 2:36:20 PM (14 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
73751
Message:

iprt: Read dwarf line numbers.

Location:
trunk
Files:
4 edited

Legend:

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

    r37591 r38573  
    14231423/** No debug module interpreter matching the debug info. */
    14241424#define VERR_DBG_NO_MATCHING_INTERPRETER        (-667)
     1425/** Bad DWARF line number header. */
     1426#define VERR_DWARF_BAD_LINE_NUMBER_HEADER       (-668)
     1427/** Unexpected end of DWARF unit. */
     1428#define VERR_DWARF_UNEXPECTED_END               (-669)
     1429/** DWARF LEB value overflows the decoder type. */
     1430#define VERR_DWARF_LEB_OVERFLOW                 (-670)
     1431/** Bad DWARF extended line number opcode. */
     1432#define VERR_DWARF_BAD_LNE                      (-671)
     1433/** Bad DWARF string. */
     1434#define VERR_DWARF_BAD_STRING                   (-672)
     1435/** Bad DWARF position. */
     1436#define VERR_DWARF_BAD_POS                      (-673)
    14251437/** @} */
    14261438
     
    16401652/** @} */
    16411653
    1642 /** @name RTDvm status codes
     1654/** @name Logger status codes
    16431655 * @{ */
    16441656/** The internal logger revision did not match. */
  • trunk/include/iprt/log.h

    r37818 r38573  
    5353    /** Default logging group. */
    5454    RTLOGGROUP_DEFAULT,
     55    RTLOGGROUP_DBG,
     56    RTLOGGROUP_DBG_DWARF,
    5557    RTLOGGROUP_DIR,
    5658    RTLOGGROUP_FILE,
     
    8284#define RT_LOGGROUP_NAMES \
    8385    "DEFAULT",      \
     86    "RT_DBG",       \
     87    "RT_DBG_DWARF", \
    8488    "RT_DIR",       \
    8589    "RT_FILE",      \
     
    9296    "RT_TIME",      \
    9397    "RT_TIMER",     \
    94     "RT_11", \
    95     "RT_12", \
    9698    "RT_13", \
    9799    "RT_14", \
  • trunk/src/VBox/Runtime/common/dbg/dbgmoddwarf.cpp

    r38558 r38573  
    2929*   Header Files                                                               *
    3030*******************************************************************************/
     31#define LOG_GROUP   RTLOGGROUP_DBG_DWARF
    3132#include <iprt/dbg.h>
    3233#include "internal/iprt.h"
    3334
    3435#include <iprt/asm.h>
     36#include <iprt/ctype.h>
    3537#include <iprt/err.h>
    36 #include <iprt/ctype.h>
     38#include <iprt/log.h>
    3739#include <iprt/mem.h>
    3840#include <iprt/path.h>
    39 #include <iprt/stream.h>
    4041#include <iprt/string.h>
    4142#include "internal/dbgmod.h"
     
    151152
    152153
    153 #define VERR_DWARF_BAD_LINE_NUMBER_HEADER   -55555
    154 #define VERR_DWARF_UNEXPECTED_END           -55554
    155 #define VERR_DWARF_LEB_OVERFLOW             -55553
    156 #define VERR_DWARF_BAD_LNE                  -55552
    157 
    158 
    159154/**
    160155 * Loads a DWARF section from the image file.
     
    455450    /* Sign extend the value. */
    456451    else if (u64Ret & RT_BIT_64(cBits - 1))
    457         u64Ret |= ~RT_BIT_64(cBits - 1);
     452        u64Ret |= ~(RT_BIT_64(cBits - 1) - 1);
    458453
    459454    return (int64_t)u64Ret;
     
    537532    {
    538533        if (!pCursor->cbUnitLeft)
     534        {
     535            pCursor->rc = VERR_DWARF_BAD_STRING;
    539536            return pszErrValue;
     537        }
    540538        pCursor->cbUnitLeft--;
    541539        pCursor->cbLeft--;
     
    609607
    610608
     609/**
     610 * Calculates an absolute cursor position from one relative to the current
     611 * cursor position.
     612 *
     613 * @returns The absolute cursor position.
     614 * @param   pCursor             The cursor.
     615 * @param   offRelative         The relative position.  Must be a positive
     616 *                              offset.
     617 */
     618static uint8_t const *rtDwarfCursor_CalcPos(PRTDWARFCURSOR pCursor, size_t offRelative)
     619{
     620    if (offRelative > pCursor->cbUnitLeft)
     621    {
     622        pCursor->rc = VERR_DWARF_BAD_POS;
     623        return NULL;
     624    }
     625    return pCursor->pb + offRelative;
     626}
     627
     628
     629/**
     630 * Advances the cursor to the given position.
     631 *
     632 * @returns IPRT status code.
     633 * @param   pCursor             The cursor.
     634 * @param   pbNewPos            The new position - returned by
     635 *                              rtDwarfCursor_CalcPos().
     636 */
     637static int rtDwarfCursor_AdvanceToPos(PRTDWARFCURSOR pCursor, uint8_t const *pbNewPos)
     638{
     639    if (RT_FAILURE(pCursor->rc))
     640        return pCursor->rc;
     641    AssertPtr(pbNewPos);
     642    if ((uintptr_t)pbNewPos < (uintptr_t)pCursor->pb)
     643        return pCursor->rc = VERR_DWARF_BAD_POS;
     644
     645    uintptr_t cbAdj = (uintptr_t)pbNewPos - (uintptr_t)pCursor->pb;
     646    if (RT_UNLIKELY(cbAdj > pCursor->cbUnitLeft))
     647    {
     648        AssertFailed();
     649        pCursor->rc = VERR_DWARF_BAD_POS;
     650        cbAdj = pCursor->cbUnitLeft;
     651    }
     652
     653    pCursor->cbUnitLeft -= cbAdj;
     654    pCursor->cbLeft     -= cbAdj;
     655    pCursor->pb         += cbAdj;
     656    return pCursor->rc;
     657}
     658
     659
    611660static bool rtDwarfCursor_IsAtEndOfUnit(PRTDWARFCURSOR pCursor)
    612661{
    613     return pCursor->cbUnitLeft > 0;
     662    return !pCursor->cbUnitLeft;
    614663}
    615664
     
    626675static bool rtDwarfCursor_IsAtEnd(PRTDWARFCURSOR pCursor)
    627676{
    628     return pCursor->cbLeft > 0;
     677    return !pCursor->cbLeft;
    629678}
    630679
     
    819868typedef struct RTDWARFLINESTATE
    820869{
    821     /** Registers */
     870    /** Virtual Line Number Machine Registers. */
    822871    struct
    823872    {
     
    837886    /** @} */
    838887
    839     /** @name Header
    840      * @{ */
    841     uint32_t        uVer;
    842     uint64_t        cbSkipAfterHdr;
    843     uint8_t         cbMinInstr;
    844     uint8_t         cMaxOpsPerInstr;
    845     uint8_t         u8DefIsStmt;
    846     int8_t          s8LineBase;
    847     uint8_t         u8LineRange;
    848     uint8_t         u8OpcodeBase;
    849     uint8_t const  *pacStdOperands;
    850     /** @} */
     888    /** Header. */
     889    struct
     890    {
     891        uint32_t        uVer;
     892        uint64_t        offFirstOpcode;
     893        uint8_t         cbMinInstr;
     894        uint8_t         cMaxOpsPerInstr;
     895        uint8_t         u8DefIsStmt;
     896        int8_t          s8LineBase;
     897        uint8_t         u8LineRange;
     898        uint8_t         u8OpcodeBase;
     899        uint8_t const  *pacStdOperands;
     900    } Hdr;
    851901
    852902    /** @name Include Path Table (0-based)
     
    856906    /** @} */
    857907
    858     /** @name File Name Table (1-based)
     908    /** @name File Name Table (0-based, dummy zero entry)
    859909     * @{ */
    860910    char          **papszFileNames;
     
    901951     * Sanitize the name.
    902952     */
    903     return rtDbgModDwarfStringToUtf8(pLnState->pDwarfMod, &pLnState->papszFileNames[iFileName]);
     953    int rc = rtDbgModDwarfStringToUtf8(pLnState->pDwarfMod, &pLnState->papszFileNames[iFileName]);
     954    Log(("  File #%02u = '%s'\n", iFileName, pLnState->papszFileNames[iFileName]));
     955    return rc;
    904956}
    905957
     
    914966    int rc = rtDbgModDwarfLinkAddressToSegOffset(pLnState->pDwarfMod, pLnState->Regs.uAddress, &iSeg, &offSeg);
    915967    if (RT_SUCCESS(rc))
     968    {
     969        Log2(("rtDwarfLine_StdOp_Copy: %x:%08llx (%#llx) %s(%d)\n", iSeg, offSeg, pLnState->Regs.uAddress, pszFile, pLnState->Regs.uLine));
    916970        rc = RTDbgModLineAdd(pLnState->pDwarfMod->hCnt, pszFile, pLnState->Regs.uLine, iSeg, offSeg, NULL);
     971
     972        /* Ignore address conflicts for now. */
     973        if (rc == VERR_DBG_ADDRESS_CONFLICT)
     974            rc = VINF_SUCCESS;
     975    }
    917976
    918977    pLnState->Regs.fBasicBlock    = false;
     
    936995    pLnState->Regs.uLine            = 1;
    937996    pLnState->Regs.uColumn          = 0;
    938     pLnState->Regs.fIsStatement     = RT_BOOL(pLnState->u8DefIsStmt);
     997    pLnState->Regs.fIsStatement     = RT_BOOL(pLnState->Hdr.u8DefIsStmt);
    939998    pLnState->Regs.fBasicBlock      = false;
    940999    pLnState->Regs.fEndSequence     = false;
     
    9551014static int rtDwarfLine_RunProgram(PRTDWARFLINESTATE pLnState, PRTDWARFCURSOR pCursor)
    9561015{
     1016    LogFlow(("rtDwarfLine_RunProgram: cbUnitLeft=%zu\n", pCursor->cbUnitLeft));
     1017
    9571018    int rc = VINF_SUCCESS;
    9581019    rtDwarfLine_ResetState(pLnState);
    959     do
    960     {
    961         uint8_t bOpCode = rtDwarfCursor_GetUByte(pCursor, 0);
    962         if (bOpCode > pLnState->u8OpcodeBase)
     1020
     1021    while (!rtDwarfCursor_IsAtEndOfUnit(pCursor))
     1022    {
     1023        uint8_t bOpCode = rtDwarfCursor_GetUByte(pCursor, DW_LNS_extended);
     1024        if (bOpCode > pLnState->Hdr.u8OpcodeBase)
    9631025        {
    9641026            /*
    9651027             * Special opcode.
    9661028             */
    967             bOpCode -= pLnState->u8OpcodeBase;
    968             pLnState->Regs.uLine    += bOpCode % pLnState->u8LineRange + (int32_t)pLnState->s8LineBase;
    969             bOpCode /= pLnState->u8LineRange;
    970             pLnState->Regs.uAddress += (pLnState->Regs.idxOp + bOpCode) / pLnState->cMaxOpsPerInstr
    971                                      * pLnState->cbMinInstr;
    972             pLnState->Regs.idxOp    += (pLnState->Regs.idxOp + bOpCode) % pLnState->cMaxOpsPerInstr;
     1029            uint8_t const bLogOpCode = bOpCode; NOREF(bLogOpCode);
     1030            bOpCode -= pLnState->Hdr.u8OpcodeBase;
     1031
     1032            int32_t const cLineDelta = bOpCode % pLnState->Hdr.u8LineRange + (int32_t)pLnState->Hdr.s8LineBase;
     1033            bOpCode /= pLnState->Hdr.u8LineRange;
     1034
     1035            uint64_t uTmp = bOpCode + pLnState->Regs.idxOp + bOpCode;
     1036            uint64_t const cAddressDelta = uTmp / pLnState->Hdr.cMaxOpsPerInstr * pLnState->Hdr.cbMinInstr;
     1037            uint64_t const cOpIndexDelta = uTmp % pLnState->Hdr.cMaxOpsPerInstr;
     1038
     1039            pLnState->Regs.uLine    += cLineDelta;
     1040            pLnState->Regs.uAddress += cAddressDelta;
     1041            pLnState->Regs.idxOp    += cOpIndexDelta;
     1042            Log2(("DW Special Opcode %#04x: uLine + %d => %u; uAddress + %#llx => %#llx; idxOp + %#llx => %#llx\n",
     1043                  bLogOpCode, cLineDelta, pLnState->Regs.uLine, cAddressDelta, pLnState->Regs.uAddress,
     1044                  cOpIndexDelta, pLnState->Regs.idxOp));
    9731045
    9741046            rc = rtDwarfLine_StdOp_Copy(pLnState);
     
    9821054                 */
    9831055                case DW_LNS_copy:
    984                     rtDwarfLine_StdOp_Copy(pLnState);
     1056                    Log2(("DW_LNS_copy\n"));
     1057                    rc = rtDwarfLine_StdOp_Copy(pLnState);
    9851058                    break;
    9861059
     
    9881061                {
    9891062                    uint64_t u64Adv = rtDwarfCursor_GetULeb128(pCursor, 0);
    990                     pLnState->Regs.uAddress += (pLnState->Regs.idxOp + u64Adv) / pLnState->cMaxOpsPerInstr
    991                                              * pLnState->cbMinInstr;
    992                     pLnState->Regs.idxOp    += (pLnState->Regs.idxOp + u64Adv) % pLnState->cMaxOpsPerInstr;
     1063                    pLnState->Regs.uAddress += (pLnState->Regs.idxOp + u64Adv) / pLnState->Hdr.cMaxOpsPerInstr
     1064                                             * pLnState->Hdr.cbMinInstr;
     1065                    pLnState->Regs.idxOp    += (pLnState->Regs.idxOp + u64Adv) % pLnState->Hdr.cMaxOpsPerInstr;
     1066                    Log2(("DW_LNS_advance_pc\n"));
    9931067                    break;
    9941068                }
    9951069
    9961070                case DW_LNS_advance_line:
    997                     pLnState->Regs.uLine += rtDwarfCursor_GetSLeb128AsS32(pCursor, 0);
     1071                {
     1072                    int32_t cLineDelta = rtDwarfCursor_GetSLeb128AsS32(pCursor, 0);
     1073                    pLnState->Regs.uLine += cLineDelta;
     1074                    Log2(("DW_LNS_advance_line: uLine + %d => %u\n", cLineDelta, pLnState->Regs.uLine));
    9981075                    break;
     1076                }
    9991077
    10001078                case DW_LNS_set_file:
    10011079                    pLnState->Regs.iFile = rtDwarfCursor_GetULeb128AsU32(pCursor, 0);
     1080                    Log2(("DW_LNS_set_file: iFile=%u\n", pLnState->Regs.iFile));
    10021081                    break;
    10031082
    10041083                case DW_LNS_set_column:
    10051084                    pLnState->Regs.uColumn = rtDwarfCursor_GetULeb128AsU32(pCursor, 0);
     1085                    Log2(("DW_LNS_set_column\n"));
    10061086                    break;
    10071087
    10081088                case DW_LNS_negate_stmt:
    10091089                    pLnState->Regs.fIsStatement = !pLnState->Regs.fIsStatement;
     1090                    Log2(("DW_LNS_negate_stmt\n"));
    10101091                    break;
    10111092
    10121093                case DW_LNS_set_basic_block:
    10131094                    pLnState->Regs.fBasicBlock = true;
     1095                    Log2(("DW_LNS_set_basic_block\n"));
    10141096                    break;
    10151097
    10161098                case DW_LNS_const_add_pc:
    1017                     pLnState->Regs.uAddress += (pLnState->Regs.idxOp + 255) / pLnState->cMaxOpsPerInstr
    1018                                              * pLnState->cbMinInstr;
    1019                     pLnState->Regs.idxOp    += (pLnState->Regs.idxOp + 255) % pLnState->cMaxOpsPerInstr;
     1099                    pLnState->Regs.uAddress += (pLnState->Regs.idxOp + 255) / pLnState->Hdr.cMaxOpsPerInstr
     1100                                             * pLnState->Hdr.cbMinInstr;
     1101                    pLnState->Regs.idxOp    += (pLnState->Regs.idxOp + 255) % pLnState->Hdr.cMaxOpsPerInstr;
     1102                    Log2(("DW_LNS_const_add_pc\n"));
    10201103                    break;
    10211104
     
    10231106                    pLnState->Regs.uAddress += rtDwarfCursor_GetUHalf(pCursor, 0);
    10241107                    pLnState->Regs.idxOp     = 0;
     1108                    Log2(("DW_LNS_fixed_advance_pc\n"));
    10251109                    break;
    10261110
    10271111                case DW_LNS_set_prologue_end:
    10281112                    pLnState->Regs.fPrologueEnd = true;
     1113                    Log2(("DW_LNS_set_prologue_end\n"));
    10291114                    break;
    10301115
    10311116                case DW_LNS_set_epilogue_begin:
    10321117                    pLnState->Regs.fEpilogueBegin = true;
     1118                    Log2(("DW_LNS_set_epilogue_begin\n"));
    10331119                    break;
    10341120
    10351121                case DW_LNS_set_isa:
    10361122                    pLnState->Regs.uIsa = rtDwarfCursor_GetULeb128AsU32(pCursor, 0);
     1123                    Log2(("DW_LNS_set_isa %#x\n", pLnState->Regs.uIsa));
    10371124                    break;
    10381125
    10391126                default:
    10401127                {
    1041                     unsigned cOpsToSkip = pLnState->pacStdOperands[bOpCode - 1];
     1128                    unsigned cOpsToSkip = pLnState->Hdr.pacStdOperands[bOpCode - 1];
     1129                    Log2(("rtDwarfLine_RunProgram: Unknown standard opcode %#x, %#x operands\n", bOpCode, cOpsToSkip));
    10421130                    while (cOpsToSkip-- > 0)
    10431131                        rc = rtDwarfCursor_SkipLeb128(pCursor);
     
    10501138                case DW_LNS_extended:
    10511139                {
     1140                    /* The instruction has a length prefix. */
    10521141                    uint64_t cbInstr = rtDwarfCursor_GetULeb128(pCursor, UINT64_MAX);
     1142                    if (RT_FAILURE(pCursor->rc))
     1143                        return pCursor->rc;
    10531144                    if (cbInstr > pCursor->cbUnitLeft)
    10541145                        return VERR_DWARF_BAD_LNE;
    1055                     /** @todo continue here. */
     1146                    uint8_t const * const pbEndOfInstr = rtDwarfCursor_CalcPos(pCursor, cbInstr);
     1147
     1148                    /* Get the opcode and deal with it if we know it. */
    10561149                    bOpCode = rtDwarfCursor_GetUByte(pCursor, 0);
    10571150                    switch (bOpCode)
    10581151                    {
    10591152                        case DW_LNE_end_sequence:
     1153#if 0 /* No need for this */
     1154                            pLnState->Regs.fEndSequence = true;
     1155                            rc = rtDwarfLine_StdOp_Copy(pLnState);
     1156#endif
     1157                            rtDwarfLine_ResetState(pLnState);
     1158                            Log2(("DW_LNE_end_sequence\n"));
     1159                            break;
     1160
    10601161                        case DW_LNE_set_address:
     1162                            switch (cbInstr - 1)
     1163                            {
     1164                                case 2: pLnState->Regs.uAddress = rtDwarfCursor_GetU16(pCursor, UINT16_MAX); break;
     1165                                case 4: pLnState->Regs.uAddress = rtDwarfCursor_GetU32(pCursor, UINT32_MAX); break;
     1166                                case 8: pLnState->Regs.uAddress = rtDwarfCursor_GetU64(pCursor, UINT64_MAX); break;
     1167                                default:
     1168                                    AssertMsgFailed(("%d\n", cbInstr));
     1169                                    pLnState->Regs.uAddress = rtDwarfCursor_GetUOff(pCursor, UINT64_MAX);
     1170                                    break;
     1171                            }
     1172                            pLnState->Regs.idxOp = 0;
     1173                            Log2(("DW_LNE_set_address: %#llx\n", pLnState->Regs.uAddress));
     1174                            break;
     1175
    10611176                        case DW_LNE_define_file:
     1177                        {
     1178                            const char *pszFilename = rtDwarfCursor_GetSZ(pCursor, NULL);
     1179                            uint32_t    idxInc      = rtDwarfCursor_GetULeb128AsU32(pCursor, UINT32_MAX);
     1180                            rtDwarfCursor_SkipLeb128(pCursor); /* st_mtime */
     1181                            rtDwarfCursor_SkipLeb128(pCursor); /* st_size */
     1182                            Log2(("DW_LNE_define_file: {%d}/%s\n", idxInc, pszFilename));
     1183
     1184                            rc = rtDwarfCursor_AdvanceToPos(pCursor, pbEndOfInstr);
     1185                            if (RT_SUCCESS(rc))
     1186                                rc = rtDwarfLine_DefineFileName(pLnState, pszFilename, idxInc);
     1187                        }
     1188
    10621189                        case DW_LNE_set_descriminator:
     1190                            pLnState->Regs.uDiscriminator = rtDwarfCursor_GetULeb128AsU32(pCursor, UINT32_MAX);
     1191                            Log2(("DW_LNE_set_descriminator: %u\n", pLnState->Regs.uDiscriminator));
     1192                            break;
     1193
     1194                        default:
     1195                            Log2(("rtDwarfLine_RunProgram: Unknown extended opcode %#x, length %#x\n", bOpCode, cbInstr));
    10631196                            break;
    10641197                    }
     1198
     1199                    /* Advance the cursor to the end of the instruction . */
     1200                    rtDwarfCursor_AdvanceToPos(pCursor, pbEndOfInstr);
    10651201                    break;
    10661202                }
    10671203            }
    10681204        }
    1069     } while (RT_SUCCESS(rc));
     1205
     1206        /*
     1207         * Check the status before looping.
     1208         */
     1209        if (RT_FAILURE(rc))
     1210            return rc;
     1211        if (RT_FAILURE(pCursor->rc))
     1212            return pCursor->rc;
     1213    }
    10701214    return rc;
    10711215}
     
    10811225static int rtDwarfLine_ReadFileNames(PRTDWARFLINESTATE pLnState, PRTDWARFCURSOR pCursor)
    10821226{
     1227    int rc = rtDwarfLine_DefineFileName(pLnState, "/<bad-zero-file-name-entry>", 0);
     1228    if (RT_FAILURE(rc))
     1229        return rc;
     1230
    10831231    for (;;)
    10841232    {
     
    10911239        rtDwarfCursor_SkipLeb128(pCursor); /* st_size */
    10921240
    1093         int rc = rtDwarfLine_DefineFileName(pLnState, psz, idxInc);
     1241        rc = rtDwarfLine_DefineFileName(pLnState, psz, idxInc);
    10941242        if (RT_FAILURE(rc))
    10951243            return rc;
    10961244    }
    1097     return VINF_SUCCESS;
     1245    return pCursor->rc;
    10981246}
    10991247
     
    11181266            pLnState->papszIncPaths = (const char **)pv;
    11191267        }
     1268        Log(("  Path #%02u = '%s'\n", pLnState->cIncPaths, psz));
    11201269        pLnState->papszIncPaths[pLnState->cIncPaths] = psz;
    11211270        pLnState->cIncPaths++;
     
    11261275    }
    11271276
    1128     return VINF_SUCCESS;
     1277    return pCursor->rc;
    11291278}
    11301279
     
    11391288     * Parse the header.
    11401289     */
    1141     LnState.uVer           = rtDwarfCursor_GetUHalf(pCursor, 0);
    1142     if (LnState.uVer >= 2 && LnState.uVer <= 4)
     1290    rtDwarfCursor_GetInitalLength(pCursor);
     1291    LnState.Hdr.uVer           = rtDwarfCursor_GetUHalf(pCursor, 0);
     1292    if (   LnState.Hdr.uVer < 2
     1293        || LnState.Hdr.uVer > 4)
    11431294        return rtDwarfCursor_SkipUnit(pCursor);
    1144     LnState.cbSkipAfterHdr = rtDwarfCursor_GetUOff(pCursor, 0);
    1145     LnState.cbMinInstr     = rtDwarfCursor_GetUByte(pCursor, 0);
    1146     LnState.cMaxOpsPerInstr= rtDwarfCursor_GetUByte(pCursor, 0);
    1147     LnState.u8DefIsStmt    = rtDwarfCursor_GetUByte(pCursor, 0);
    1148     LnState.s8LineBase     = rtDwarfCursor_GetSByte(pCursor, 0);
    1149     LnState.u8LineRange    = rtDwarfCursor_GetUByte(pCursor, 0);
    1150     LnState.u8OpcodeBase   = rtDwarfCursor_GetUByte(pCursor, 0);
    1151     if (!LnState.u8OpcodeBase)
     1295
     1296    LnState.Hdr.offFirstOpcode = rtDwarfCursor_GetUOff(pCursor, 0);
     1297    uint8_t const * const pbFirstOpcode = rtDwarfCursor_CalcPos(pCursor, LnState.Hdr.offFirstOpcode);
     1298
     1299    LnState.Hdr.cbMinInstr     = rtDwarfCursor_GetUByte(pCursor, 0);
     1300    if (LnState.Hdr.uVer >= 4)
     1301        LnState.Hdr.cMaxOpsPerInstr = rtDwarfCursor_GetUByte(pCursor, 0);
     1302    else
     1303        LnState.Hdr.cMaxOpsPerInstr = 1;
     1304    LnState.Hdr.u8DefIsStmt    = rtDwarfCursor_GetUByte(pCursor, 0);
     1305    LnState.Hdr.s8LineBase     = rtDwarfCursor_GetSByte(pCursor, 0);
     1306    LnState.Hdr.u8LineRange    = rtDwarfCursor_GetUByte(pCursor, 0);
     1307    LnState.Hdr.u8OpcodeBase   = rtDwarfCursor_GetUByte(pCursor, 0);
     1308
     1309    if (   !LnState.Hdr.u8OpcodeBase
     1310        || !LnState.Hdr.cMaxOpsPerInstr
     1311        || !LnState.Hdr.u8LineRange
     1312        || LnState.Hdr.u8DefIsStmt > 1)
    11521313        return VERR_DWARF_BAD_LINE_NUMBER_HEADER;
    1153 
    1154     LnState.pacStdOperands = pCursor->pb;
    1155     for (uint8_t iStdOpcode = 1; iStdOpcode < LnState.u8OpcodeBase; iStdOpcode++)
     1314    Log2(("DWARF Line number header:\n"
     1315          "    uVer             %d\n"
     1316          "    offFirstOpcode   %#llx\n"
     1317          "    cbMinInstr       %u\n"
     1318          "    cMaxOpsPerInstr  %u\n"
     1319          "    u8DefIsStmt      %u\n"
     1320          "    s8LineBase       %d\n"
     1321          "    u8LineRange      %u\n"
     1322          "    u8OpcodeBase     %u\n",
     1323          LnState.Hdr.uVer,    LnState.Hdr.offFirstOpcode, LnState.Hdr.cbMinInstr,  LnState.Hdr.cMaxOpsPerInstr,
     1324          LnState.Hdr.u8DefIsStmt, LnState.Hdr.s8LineBase, LnState.Hdr.u8LineRange, LnState.Hdr.u8OpcodeBase));
     1325
     1326    LnState.Hdr.pacStdOperands = pCursor->pb;
     1327    for (uint8_t iStdOpcode = 1; iStdOpcode < LnState.Hdr.u8OpcodeBase; iStdOpcode++)
    11561328        rtDwarfCursor_GetUByte(pCursor, 0);
    11571329
    1158     int rc = rtDwarfLine_ReadIncludePaths(&LnState, pCursor);
     1330    int rc = pCursor->rc;
     1331    if (RT_SUCCESS(rc))
     1332        rc = rtDwarfLine_ReadIncludePaths(&LnState, pCursor);
    11591333    if (RT_SUCCESS(rc))
    11601334        rc = rtDwarfLine_ReadFileNames(&LnState, pCursor);
     
    11631337     * Run the program....
    11641338     */
     1339    if (RT_SUCCESS(rc))
     1340        rc = rtDwarfCursor_AdvanceToPos(pCursor, pbFirstOpcode);
    11651341    if (RT_SUCCESS(rc))
    11661342        rc = rtDwarfLine_RunProgram(&LnState, pCursor);
     
    11981374        return rc;
    11991375
    1200     while (   rtDwarfCursor_IsAtEnd(&Cursor)
     1376    while (   !rtDwarfCursor_IsAtEnd(&Cursor)
    12011377           && RT_SUCCESS(rc))
    12021378        rc = rtDbgModDwarfExplodeLineNumbersForUnit(pThis, &Cursor);
     
    12591435{
    12601436    PRTDBGMODINT pMod = (PRTDBGMODINT)pvUser;
     1437    Log(("Segment %.*s: LinkAddress=%#llx RVA=%#llx cb=%#llx\n",
     1438         pSeg->cchName, pSeg->pchName, (uint64_t)pSeg->LinkAddress, (uint64_t)pSeg->RVA, pSeg->cb));
     1439#if 0
    12611440    return pMod->pDbgVt->pfnSegmentAdd(pMod, pSeg->RVA, pSeg->cb, pSeg->pchName, pSeg->cchName, 0 /*fFlags*/, NULL);
     1441#else
     1442    return pMod->pDbgVt->pfnSegmentAdd(pMod, pSeg->LinkAddress, pSeg->cb, pSeg->pchName, pSeg->cchName, 0 /*fFlags*/, NULL);
     1443#endif
    12621444}
    12631445
  • trunk/src/VBox/Runtime/tools/RTLdrFlt.cpp

    r38547 r38573  
    141141
    142142    PRTSTREAM       pInput   = g_pStdIn;
     143    PRTSTREAM       pOutput  = g_pStdOut;
    143144    bool            fVerbose = false;
    144145
     
    286287                psz += cchAddress;
    287288                if (pszStart != psz)
    288                     RTStrmWrite(g_pStdOut, pszStart, psz - pszStart);
     289                    RTStrmWrite(pOutput, pszStart, psz - pszStart);
    289290                pszStart = psz;
    290291
     
    297298                {
    298299                    if (iSeg != UINT32_MAX)
    299                         RTStrmPrintf(g_pStdOut, "=[%s:%u", RTDbgModName(hDbgMod), iSeg);
     300                        RTStrmPrintf(pOutput, "=[%s:%u", RTDbgModName(hDbgMod), iSeg);
    300301                    else
    301                         RTStrmPrintf(g_pStdOut, "=[%s", RTDbgModName(hDbgMod), iSeg);
     302                        RTStrmPrintf(pOutput, "=[%s", RTDbgModName(hDbgMod), iSeg);
    302303
    303304                    /*
     
    310311                    {
    311312                        if (!offSym)
    312                             RTStrmPrintf(g_pStdOut, "!%s", Symbol.szName);
     313                            RTStrmPrintf(pOutput, "!%s", Symbol.szName);
    313314                        else if (offSym > 0)
    314                             RTStrmPrintf(g_pStdOut, "!%s+%#llx", Symbol.szName, offSym);
     315                            RTStrmPrintf(pOutput, "!%s+%#llx", Symbol.szName, offSym);
    315316                        else
    316                             RTStrmPrintf(g_pStdOut, "!%s-%#llx", Symbol.szName, -offSym);
     317                            RTStrmPrintf(pOutput, "!%s-%#llx", Symbol.szName, -offSym);
    317318                    }
    318319                    else
    319                         RTStrmPrintf(g_pStdOut, "+%#llx", u64Address - uAddr);
     320                        RTStrmPrintf(pOutput, "+%#llx", u64Address - uAddr);
    320321
    321322                    /*
     
    326327                    rc = RTDbgAsLineByAddr(hDbgAs, u64Address, &offLine, &Line);
    327328                    if (RT_SUCCESS(rc))
    328                         RTStrmPrintf(g_pStdOut, " %Rbn(%u)", Line.szFilename, Line.uLineNo);
    329 
    330                     RTStrmPrintf(g_pStdOut, "]");
     329                        RTStrmPrintf(pOutput, " %Rbn(%u)", Line.szFilename, Line.uLineNo);
     330
     331                    RTStrmPrintf(pOutput, "]");
    331332                    RTDbgModRelease(hDbgMod);
    332333                }
     
    337338
    338339        if (pszStart != psz)
    339             RTStrmWrite(g_pStdOut, pszStart, psz - pszStart);
    340         RTStrmPutCh(g_pStdOut, '\n');
     340            RTStrmWrite(pOutput, pszStart, psz - pszStart);
     341        RTStrmPutCh(pOutput, '\n');
    341342
    342343    }
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