VirtualBox

Ignore:
Timestamp:
Sep 2, 2011 1:14:51 AM (14 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
73809
Message:

More dwarf hacking.

File:
1 edited

Legend:

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

    r38603 r38606  
    4848/** @name Standard DWARF Line Number Opcodes
    4949 * @{ */
    50 #define DW_LNS_extended             UINT8_C(0)
    51 #define DW_LNS_copy                 UINT8_C(1)
    52 #define DW_LNS_advance_pc           UINT8_C(2)
    53 #define DW_LNS_advance_line         UINT8_C(3)
    54 #define DW_LNS_set_file             UINT8_C(4)
    55 #define DW_LNS_set_column           UINT8_C(5)
    56 #define DW_LNS_negate_stmt          UINT8_C(6)
    57 #define DW_LNS_set_basic_block      UINT8_C(7)
    58 #define DW_LNS_const_add_pc         UINT8_C(8)
    59 #define DW_LNS_fixed_advance_pc     UINT8_C(9)
    60 #define DW_LNS_set_prologue_end     UINT8_C(10)
    61 #define DW_LNS_set_epilogue_begin   UINT8_C(11)
    62 #define DW_LNS_set_isa              UINT8_C(12)
     50#define DW_LNS_extended                    UINT8_C(0x00)
     51#define DW_LNS_copy                        UINT8_C(0x01)
     52#define DW_LNS_advance_pc                  UINT8_C(0x02)
     53#define DW_LNS_advance_line                UINT8_C(0x03)
     54#define DW_LNS_set_file                    UINT8_C(0x04)
     55#define DW_LNS_set_column                  UINT8_C(0x05)
     56#define DW_LNS_negate_stmt                 UINT8_C(0x06)
     57#define DW_LNS_set_basic_block             UINT8_C(0x07)
     58#define DW_LNS_const_add_pc                UINT8_C(0x08)
     59#define DW_LNS_fixed_advance_pc            UINT8_C(0x09)
     60#define DW_LNS_set_prologue_end            UINT8_C(0x0a)
     61#define DW_LNS_set_epilogue_begin          UINT8_C(0x0b)
     62#define DW_LNS_set_isa                     UINT8_C(0x0c)
     63#define DW_LNS_what_question_mark          UINT8_C(0x0d)
    6364/** @} */
    6465
     
    138139/** @} */
    139140
     141
     142/** @name DIE Attributes.
     143 * @{ */
     144#define DW_AT_sibling                       UINT16_C(0x0001)
     145#define DW_AT_location                      UINT16_C(0x0002)
     146#define DW_AT_name                          UINT16_C(0x0003)
     147#define DW_AT_ordering                      UINT16_C(0x0009)
     148#define DW_AT_byte_size                     UINT16_C(0x000b)
     149#define DW_AT_bit_offset                    UINT16_C(0x000c)
     150#define DW_AT_bit_size                      UINT16_C(0x000d)
     151#define DW_AT_stmt_list                     UINT16_C(0x0010)
     152#define DW_AT_low_pc                        UINT16_C(0x0011)
     153#define DW_AT_high_pc                       UINT16_C(0x0012)
     154#define DW_AT_language                      UINT16_C(0x0013)
     155#define DW_AT_discr                         UINT16_C(0x0015)
     156#define DW_AT_discr_value                   UINT16_C(0x0016)
     157#define DW_AT_visibility                    UINT16_C(0x0017)
     158#define DW_AT_import                        UINT16_C(0x0018)
     159#define DW_AT_string_length                 UINT16_C(0x0019)
     160#define DW_AT_common_reference              UINT16_C(0x001a)
     161#define DW_AT_comp_dir                      UINT16_C(0x001b)
     162#define DW_AT_const_value                   UINT16_C(0x001c)
     163#define DW_AT_containing_type               UINT16_C(0x001d)
     164#define DW_AT_default_value                 UINT16_C(0x001e)
     165#define DW_AT_inline                        UINT16_C(0x0020)
     166#define DW_AT_is_optional                   UINT16_C(0x0021)
     167#define DW_AT_lower_bound                   UINT16_C(0x0022)
     168#define DW_AT_producer                      UINT16_C(0x0025)
     169#define DW_AT_prototyped                    UINT16_C(0x0027)
     170#define DW_AT_return_addr                   UINT16_C(0x002a)
     171#define DW_AT_start_scope                   UINT16_C(0x002c)
     172#define DW_AT_bit_stride                    UINT16_C(0x002e)
     173#define DW_AT_upper_bound                   UINT16_C(0x002f)
     174#define DW_AT_abstract_origin               UINT16_C(0x0031)
     175#define DW_AT_accessibility                 UINT16_C(0x0032)
     176#define DW_AT_address_class                 UINT16_C(0x0033)
     177#define DW_AT_artificial                    UINT16_C(0x0034)
     178#define DW_AT_base_types                    UINT16_C(0x0035)
     179#define DW_AT_calling_convention            UINT16_C(0x0036)
     180#define DW_AT_count                         UINT16_C(0x0037)
     181#define DW_AT_data_member_location          UINT16_C(0x0038)
     182#define DW_AT_decl_column                   UINT16_C(0x0039)
     183#define DW_AT_decl_file                     UINT16_C(0x003a)
     184#define DW_AT_decl_line                     UINT16_C(0x003b)
     185#define DW_AT_declaration                   UINT16_C(0x003c)
     186#define DW_AT_discr_list                    UINT16_C(0x003d)
     187#define DW_AT_encoding                      UINT16_C(0x003e)
     188#define DW_AT_external                      UINT16_C(0x003f)
     189#define DW_AT_frame_base                    UINT16_C(0x0040)
     190#define DW_AT_friend                        UINT16_C(0x0041)
     191#define DW_AT_identifier_case               UINT16_C(0x0042)
     192#define DW_AT_macro_info                    UINT16_C(0x0043)
     193#define DW_AT_namelist_item                 UINT16_C(0x0044)
     194#define DW_AT_priority                      UINT16_C(0x0045)
     195#define DW_AT_segment                       UINT16_C(0x0046)
     196#define DW_AT_specification                 UINT16_C(0x0047)
     197#define DW_AT_static_link                   UINT16_C(0x0048)
     198#define DW_AT_type                          UINT16_C(0x0049)
     199#define DW_AT_use_location                  UINT16_C(0x004a)
     200#define DW_AT_variable_parameter            UINT16_C(0x004b)
     201#define DW_AT_virtuality                    UINT16_C(0x004c)
     202#define DW_AT_vtable_elem_location          UINT16_C(0x004d)
     203#define DW_AT_allocated                     UINT16_C(0x004e)
     204#define DW_AT_associated                    UINT16_C(0x004f)
     205#define DW_AT_data_location                 UINT16_C(0x0050)
     206#define DW_AT_byte_stride                   UINT16_C(0x0051)
     207#define DW_AT_entry_pc                      UINT16_C(0x0052)
     208#define DW_AT_use_UTF8                      UINT16_C(0x0053)
     209#define DW_AT_extension                     UINT16_C(0x0054)
     210#define DW_AT_ranges                        UINT16_C(0x0055)
     211#define DW_AT_trampoline                    UINT16_C(0x0056)
     212#define DW_AT_call_column                   UINT16_C(0x0057)
     213#define DW_AT_call_file                     UINT16_C(0x0058)
     214#define DW_AT_call_line                     UINT16_C(0x0059)
     215#define DW_AT_description                   UINT16_C(0x005a)
     216#define DW_AT_binary_scale                  UINT16_C(0x005b)
     217#define DW_AT_decimal_scale                 UINT16_C(0x005c)
     218#define DW_AT_small                         UINT16_C(0x005d)
     219#define DW_AT_decimal_sign                  UINT16_C(0x005e)
     220#define DW_AT_digit_count                   UINT16_C(0x005f)
     221#define DW_AT_picture_string                UINT16_C(0x0060)
     222#define DW_AT_mutable                       UINT16_C(0x0061)
     223#define DW_AT_threads_scaled                UINT16_C(0x0062)
     224#define DW_AT_explicit                      UINT16_C(0x0063)
     225#define DW_AT_object_pointer                UINT16_C(0x0064)
     226#define DW_AT_endianity                     UINT16_C(0x0065)
     227#define DW_AT_elemental                     UINT16_C(0x0066)
     228#define DW_AT_pure                          UINT16_C(0x0067)
     229#define DW_AT_recursive                     UINT16_C(0x0068)
     230#define DW_AT_signature                     UINT16_C(0x0069)
     231#define DW_AT_main_subprogram               UINT16_C(0x006a)
     232#define DW_AT_data_bit_offset               UINT16_C(0x006b)
     233#define DW_AT_const_expr                    UINT16_C(0x006c)
     234#define DW_AT_enum_class                    UINT16_C(0x006d)
     235#define DW_AT_linkage_name                  UINT16_C(0x006e)
     236#define DW_AT_lo_user                       UINT16_C(0x2000)
     237#define DW_AT_hi_user                       UINT16_C(0x3fff)
     238/** @} */
     239
     240/** @name DIE Forms.
     241 * @{ */
     242#define DW_FORM_addr                        UINT16_C(0x01)
     243/* What was 0x02? */
     244#define DW_FORM_block2                      UINT16_C(0x03)
     245#define DW_FORM_block4                      UINT16_C(0x04)
     246#define DW_FORM_data2                       UINT16_C(0x05)
     247#define DW_FORM_data4                       UINT16_C(0x06)
     248#define DW_FORM_data8                       UINT16_C(0x07)
     249#define DW_FORM_string                      UINT16_C(0x08)
     250#define DW_FORM_block                       UINT16_C(0x09)
     251#define DW_FORM_block1                      UINT16_C(0x0a)
     252#define DW_FORM_data1                       UINT16_C(0x0b)
     253#define DW_FORM_flag                        UINT16_C(0x0c)
     254#define DW_FORM_sdata                       UINT16_C(0x0d)
     255#define DW_FORM_strp                        UINT16_C(0x0e)
     256#define DW_FORM_udata                       UINT16_C(0x0f)
     257#define DW_FORM_ref_addr                    UINT16_C(0x10)
     258#define DW_FORM_ref1                        UINT16_C(0x11)
     259#define DW_FORM_ref2                        UINT16_C(0x12)
     260#define DW_FORM_ref4                        UINT16_C(0x13)
     261#define DW_FORM_ref8                        UINT16_C(0x14)
     262#define DW_FORM_ref_udata                   UINT16_C(0x15)
     263#define DW_FORM_indirect                    UINT16_C(0x16)
     264#define DW_FORM_sec_offset                  UINT16_C(0x17)
     265#define DW_FORM_exprloc                     UINT16_C(0x18)
     266#define DW_FORM_flag_present                UINT16_C(0x19)
     267#define DW_FORM_ref_sig8                    UINT16_C(0x20)
     268/** @} */
     269
     270
    140271/*******************************************************************************
    141272*   Structures and Typedefs                                                    *
     
    731862static int rtDwarfCursor_SkipLeb128(PRTDWARFCURSOR pCursor)
    732863{
     864    if (RT_FAILURE(pCursor->rc))
     865        return pCursor->rc;
     866
    733867    if (pCursor->cbUnitLeft < 1)
    734868        return pCursor->rc = VERR_DWARF_UNEXPECTED_END;
     
    753887
    754888/**
     889 * Advances the cursor a given number of bytes.
     890 *
     891 * @returns IPRT status code.
     892 * @param   pCursor             The cursor.
     893 * @param   offSkip             The number of bytes to advance.
     894 */
     895static int rtDwarfCursor_SkipBytes(PRTDWARFCURSOR pCursor, uint64_t offSkip)
     896{
     897    if (RT_FAILURE(pCursor->rc))
     898        return pCursor->rc;
     899    if (pCursor->cbUnitLeft < offSkip)
     900        return pCursor->rc = VERR_DWARF_UNEXPECTED_END;
     901
     902    size_t const offSkipSizeT = (size_t)offSkip;
     903    pCursor->cbUnitLeft -= offSkipSizeT;
     904    pCursor->cbLeft     -= offSkipSizeT;
     905    pCursor->pb         += offSkipSizeT;
     906
     907    return VINF_SUCCESS;
     908}
     909
     910
     911/**
    755912 * Reads a zero terminated string, advancing the cursor beyond the terminator.
    756913 *
     
    780937
    781938/**
     939 * Reads a 1, 2, 4 or 8 byte unsgined value.
     940 *
     941 * @returns 64-bit unsigned value.
     942 * @param   pCursor             The cursor.
     943 * @param   cbValue             The value size.
     944 * @param   uErrValue           The error value.
     945 */
     946static uint64_t rtDwarfCursor_GetVarSizedU(PRTDWARFCURSOR pCursor, size_t cbValue, uint64_t uErrValue)
     947{
     948    uint64_t u64Ret;
     949    switch (cbValue)
     950    {
     951        case 1: u64Ret = rtDwarfCursor_GetU8( pCursor, UINT8_MAX); break;
     952        case 2: u64Ret = rtDwarfCursor_GetU16(pCursor, UINT16_MAX); break;
     953        case 4: u64Ret = rtDwarfCursor_GetU32(pCursor, UINT32_MAX); break;
     954        case 8: u64Ret = rtDwarfCursor_GetU64(pCursor, UINT64_MAX); break;
     955        default:
     956            pCursor->rc = VERR_DWARF_BAD_INFO;
     957            return uErrValue;
     958    }
     959    if (RT_FAILURE(pCursor->rc))
     960        return uErrValue;
     961    return u64Ret;
     962}
     963
     964
     965/**
    782966 * Reads an unsigned DWARF half number.
    783967 *
     
    9041088static uint32_t rtDwarfCursor_CalcSectOffsetU32(PRTDWARFCURSOR pCursor)
    9051089{
    906     size_t off = (uint8_t const *)pCursor->pDwarfMod->aSections[pCursor->enmSect].pv - pCursor->pb;
     1090    size_t off = pCursor->pb - (uint8_t const *)pCursor->pDwarfMod->aSections[pCursor->enmSect].pv;
    9071091    uint32_t offRet = (uint32_t)off;
    9081092    if (offRet != off)
     
    9281112    if (offRelative > pCursor->cbUnitLeft)
    9291113    {
     1114        Log(("rtDwarfCursor_CalcPos: bad position %#zx, cbUnitLeft=%#zu\n", offRelative, pCursor->cbUnitLeft));
    9301115        pCursor->rc = VERR_DWARF_BAD_POS;
    9311116        return NULL;
     
    9491134    AssertPtr(pbNewPos);
    9501135    if ((uintptr_t)pbNewPos < (uintptr_t)pCursor->pb)
     1136    {
     1137        Log(("rtDwarfCursor_AdvanceToPos: bad position %p, current %p\n", pbNewPos, pCursor->pb));
    9511138        return pCursor->rc = VERR_DWARF_BAD_POS;
     1139    }
    9521140
    9531141    uintptr_t cbAdj = (uintptr_t)pbNewPos - (uintptr_t)pCursor->pb;
     
    10521240{
    10531241    if (offSect > pThis->aSections[enmSect].cb)
     1242    {
     1243        Log(("rtDwarfCursor_InitWithOffset: offSect=%#x cb=%#x enmSect=%d\n", offSect, pThis->aSections[enmSect].cb, enmSect));
    10541244        return VERR_DWARF_BAD_POS;
     1245    }
    10551246
    10561247    int rc = rtDwarfCursor_Init(pCursor, pThis, enmSect);
     
    11491340 * @returns IPRT status code
    11501341 * @param   pLnState            The line number program state.
    1151  */
    1152 static int rtDwarfLine_AddLine(PRTDWARFLINESTATE pLnState)
     1342 * @param   offOpCode           The opcode offset (for logging
     1343 *                              purposes).
     1344 */
     1345static int rtDwarfLine_AddLine(PRTDWARFLINESTATE pLnState, uint32_t offOpCode)
    11531346{
    11541347    const char *pszFile = pLnState->Regs.iFile < pLnState->cFileNames
     
    11601353    if (RT_SUCCESS(rc))
    11611354    {
    1162         Log2(("rtDwarfLine_AddLine: %x:%08llx (%#llx) %s(%d)\n", iSeg, offSeg, pLnState->Regs.uAddress, pszFile, pLnState->Regs.uLine));
     1355        Log2(("rtDwarfLine_AddLine: %x:%08llx (%#llx) %s(%d) [offOpCode=%08x]\n", iSeg, offSeg, pLnState->Regs.uAddress, pszFile, pLnState->Regs.uLine, offOpCode));
    11631356        rc = RTDbgModLineAdd(pLnState->pDwarfMod->hCnt, pszFile, pLnState->Regs.uLine, iSeg, offSeg, NULL);
    11641357
     
    12141407    while (!rtDwarfCursor_IsAtEndOfUnit(pCursor))
    12151408    {
    1216         uint8_t bOpCode = rtDwarfCursor_GetUByte(pCursor, DW_LNS_extended);
    1217         if (bOpCode > pLnState->Hdr.u8OpcodeBase)
     1409#ifdef LOG_ENABLED
     1410        uint32_t const offOpCode = rtDwarfCursor_CalcSectOffsetU32(pCursor);
     1411#else
     1412        uint32_t const offOpCode = 0;
     1413#endif
     1414        uint8_t        bOpCode   = rtDwarfCursor_GetUByte(pCursor, DW_LNS_extended);
     1415        if (bOpCode >= pLnState->Hdr.u8OpcodeBase)
    12181416        {
    12191417            /*
     
    12331431            pLnState->Regs.uAddress += cAddressDelta;
    12341432            pLnState->Regs.idxOp    += cOpIndexDelta;
    1235             Log2(("DW Special Opcode %#04x: uLine + %d => %u; uAddress + %#llx => %#llx; idxOp + %#llx => %#llx\n",
    1236                   bLogOpCode, cLineDelta, pLnState->Regs.uLine, cAddressDelta, pLnState->Regs.uAddress,
     1433            Log2(("%08x: DW Special Opcode %#04x: uLine + %d => %u; uAddress + %#llx => %#llx; idxOp + %#llx => %#llx\n",
     1434                  offOpCode, bLogOpCode, cLineDelta, pLnState->Regs.uLine, cAddressDelta, pLnState->Regs.uAddress,
    12371435                  cOpIndexDelta, pLnState->Regs.idxOp));
    12381436
    1239             rc = rtDwarfLine_AddLine(pLnState);
     1437            rc = rtDwarfLine_AddLine(pLnState, offOpCode);
    12401438        }
    12411439        else
     
    12471445                 */
    12481446                case DW_LNS_copy:
    1249                     Log2(("DW_LNS_copy\n"));
    1250                     rc = rtDwarfLine_AddLine(pLnState);
     1447                    Log2(("%08x: DW_LNS_copy\n", offOpCode));
     1448                    rc = rtDwarfLine_AddLine(pLnState, offOpCode);
    12511449                    break;
    12521450
     
    12571455                                             * pLnState->Hdr.cbMinInstr;
    12581456                    pLnState->Regs.idxOp    += (pLnState->Regs.idxOp + u64Adv) % pLnState->Hdr.cMaxOpsPerInstr;
    1259                     Log2(("DW_LNS_advance_pc\n"));
     1457                    Log2(("%08x: DW_LNS_advance_pc: u64Adv=%#llx (%lld) )\n", offOpCode, u64Adv, u64Adv));
    12601458                    break;
    12611459                }
     
    12651463                    int32_t cLineDelta = rtDwarfCursor_GetSLeb128AsS32(pCursor, 0);
    12661464                    pLnState->Regs.uLine += cLineDelta;
    1267                     Log2(("DW_LNS_advance_line: uLine + %d => %u\n", cLineDelta, pLnState->Regs.uLine));
     1465                    Log2(("%08x: DW_LNS_advance_line: uLine + %d => %u\n", offOpCode, cLineDelta, pLnState->Regs.uLine));
    12681466                    break;
    12691467                }
     
    12711469                case DW_LNS_set_file:
    12721470                    pLnState->Regs.iFile = rtDwarfCursor_GetULeb128AsU32(pCursor, 0);
    1273                     Log2(("DW_LNS_set_file: iFile=%u\n", pLnState->Regs.iFile));
     1471                    Log2(("%08x: DW_LNS_set_file: iFile=%u\n", offOpCode, pLnState->Regs.iFile));
    12741472                    break;
    12751473
    12761474                case DW_LNS_set_column:
    12771475                    pLnState->Regs.uColumn = rtDwarfCursor_GetULeb128AsU32(pCursor, 0);
    1278                     Log2(("DW_LNS_set_column\n"));
     1476                    Log2(("%08x: DW_LNS_set_column\n", offOpCode));
    12791477                    break;
    12801478
    12811479                case DW_LNS_negate_stmt:
    12821480                    pLnState->Regs.fIsStatement = !pLnState->Regs.fIsStatement;
    1283                     Log2(("DW_LNS_negate_stmt\n"));
     1481                    Log2(("%08x: DW_LNS_negate_stmt\n", offOpCode));
    12841482                    break;
    12851483
    12861484                case DW_LNS_set_basic_block:
    12871485                    pLnState->Regs.fBasicBlock = true;
    1288                     Log2(("DW_LNS_set_basic_block\n"));
     1486                    Log2(("%08x: DW_LNS_set_basic_block\n", offOpCode));
    12891487                    break;
    12901488
     
    12931491                                             * pLnState->Hdr.cbMinInstr;
    12941492                    pLnState->Regs.idxOp    += (pLnState->Regs.idxOp + 255) % pLnState->Hdr.cMaxOpsPerInstr;
    1295                     Log2(("DW_LNS_const_add_pc\n"));
     1493                    Log2(("%08x: DW_LNS_const_add_pc\n", offOpCode));
    12961494                    break;
    12971495
     
    12991497                    pLnState->Regs.uAddress += rtDwarfCursor_GetUHalf(pCursor, 0);
    13001498                    pLnState->Regs.idxOp     = 0;
    1301                     Log2(("DW_LNS_fixed_advance_pc\n"));
     1499                    Log2(("%08x: DW_LNS_fixed_advance_pc\n", offOpCode));
    13021500                    break;
    13031501
    13041502                case DW_LNS_set_prologue_end:
    13051503                    pLnState->Regs.fPrologueEnd = true;
    1306                     Log2(("DW_LNS_set_prologue_end\n"));
     1504                    Log2(("%08x: DW_LNS_set_prologue_end\n", offOpCode));
    13071505                    break;
    13081506
    13091507                case DW_LNS_set_epilogue_begin:
    13101508                    pLnState->Regs.fEpilogueBegin = true;
    1311                     Log2(("DW_LNS_set_epilogue_begin\n"));
     1509                    Log2(("%08x: DW_LNS_set_epilogue_begin\n", offOpCode));
    13121510                    break;
    13131511
    13141512                case DW_LNS_set_isa:
    13151513                    pLnState->Regs.uIsa = rtDwarfCursor_GetULeb128AsU32(pCursor, 0);
    1316                     Log2(("DW_LNS_set_isa %#x\n", pLnState->Regs.uIsa));
     1514                    Log2(("%08x: DW_LNS_set_isa %#x\n", offOpCode, pLnState->Regs.uIsa));
    13171515                    break;
    13181516
     
    13201518                {
    13211519                    unsigned cOpsToSkip = pLnState->Hdr.pacStdOperands[bOpCode - 1];
    1322                     Log2(("rtDwarfLine_RunProgram: Unknown standard opcode %#x, %#x operands\n", bOpCode, cOpsToSkip));
     1520                    Log(("rtDwarfLine_RunProgram: Unknown standard opcode %#x, %#x operands, at %08x.\n", bOpCode, cOpsToSkip, offOpCode));
    13231521                    while (cOpsToSkip-- > 0)
    13241522                        rc = rtDwarfCursor_SkipLeb128(pCursor);
     
    13461544#if 0 /* No need for this, I think. */
    13471545                            pLnState->Regs.fEndSequence = true;
    1348                             rc = rtDwarfLine_AddLine(pLnState);
     1546                            rc = rtDwarfLine_AddLine(pLnState, offOpCode);
    13491547#endif
    13501548                            rtDwarfLine_ResetState(pLnState);
    1351                             Log2(("DW_LNE_end_sequence\n"));
     1549                            Log2(("%08x: DW_LNE_end_sequence\n", offOpCode));
    13521550                            break;
    13531551
    13541552                        case DW_LNE_set_address:
    1355                             switch (cbInstr - 1)
    1356                             {
    1357                                 case 2: pLnState->Regs.uAddress = rtDwarfCursor_GetU16(pCursor, UINT16_MAX); break;
    1358                                 case 4: pLnState->Regs.uAddress = rtDwarfCursor_GetU32(pCursor, UINT32_MAX); break;
    1359                                 case 8: pLnState->Regs.uAddress = rtDwarfCursor_GetU64(pCursor, UINT64_MAX); break;
    1360                                 default:
    1361                                     AssertMsgFailed(("%d\n", cbInstr));
    1362                                     pLnState->Regs.uAddress = rtDwarfCursor_GetNativeUOff(pCursor, UINT64_MAX);
    1363                                     break;
    1364                             }
    1365                             pLnState->Regs.idxOp = 0;
    1366                             Log2(("DW_LNE_set_address: %#llx\n", pLnState->Regs.uAddress));
     1553                            pLnState->Regs.uAddress = rtDwarfCursor_GetVarSizedU(pCursor, cbInstr - 1, UINT64_MAX);
     1554                            pLnState->Regs.idxOp    = 0;
     1555                            Log2(("%08x: DW_LNE_set_address: %#llx\n", offOpCode, pLnState->Regs.uAddress));
    13671556                            break;
    13681557
     
    13731562                            rtDwarfCursor_SkipLeb128(pCursor); /* st_mtime */
    13741563                            rtDwarfCursor_SkipLeb128(pCursor); /* st_size */
    1375                             Log2(("DW_LNE_define_file: {%d}/%s\n", idxInc, pszFilename));
     1564                            Log2(("%08x: DW_LNE_define_file: {%d}/%s\n", offOpCode, idxInc, pszFilename));
    13761565
    13771566                            rc = rtDwarfCursor_AdvanceToPos(pCursor, pbEndOfInstr);
     
    13801569                        }
    13811570
     1571                        /*
     1572                         * Note! Was defined in DWARF 4.  But... Watcom used it
     1573                         *       for setting the segment in DWARF 2, creating
     1574                         *       an incompatibility with the newer standard.
     1575                         */
    13821576                        case DW_LNE_set_descriminator:
    1383                             pLnState->Regs.uDiscriminator = rtDwarfCursor_GetULeb128AsU32(pCursor, UINT32_MAX);
    1384                             Log2(("DW_LNE_set_descriminator: %u\n", pLnState->Regs.uDiscriminator));
     1577                            if (pLnState->Hdr.uVer != 2)
     1578                            {
     1579                                Assert(pLnState->Hdr.uVer >= 4);
     1580                                pLnState->Regs.uDiscriminator = rtDwarfCursor_GetULeb128AsU32(pCursor, UINT32_MAX);
     1581                                Log2(("%08x: DW_LNE_set_descriminator: %u\n", offOpCode, pLnState->Regs.uDiscriminator));
     1582                            }
     1583                            else
     1584                            {
     1585                                uint64_t uSeg = rtDwarfCursor_GetVarSizedU(pCursor, cbInstr - 1, UINT64_MAX);
     1586                                Log2(("%08x: DW_LNE_set_segment: %ll#x - Watcom Extension\n", offOpCode, uSeg));
     1587                                /** @todo make use of this? */
     1588                            }
    13851589                            break;
    13861590
    13871591                        default:
    1388                             Log2(("rtDwarfLine_RunProgram: Unknown extended opcode %#x, length %#x\n", bOpCode, cbInstr));
     1592                            Log(("rtDwarfLine_RunProgram: Unknown extended opcode %#x, length %#x at %08x\n", bOpCode, cbInstr, offOpCode));
    13891593                            break;
    13901594                    }
     
    16591863
    16601864            /* Cache it? */
    1661             if (uCurCode >= pThis->cCachedAbbrevsAlloced)
     1865            if (uCurCode <= pThis->cCachedAbbrevsAlloced)
    16621866            {
    16631867                PRTDWARFABBREV pEntry = &pThis->paCachedAbbrevs[uCurCode - 1];
     
    16871891                uAttr = rtDwarfCursor_GetULeb128AsU32(&Cursor, 0);
    16881892                uForm = rtDwarfCursor_GetULeb128AsU32(&Cursor, 0);
    1689             } while (uAttr != 0 && uForm != 0);
     1893            } while (uAttr != 0);
    16901894            if (RT_FAILURE(Cursor.rc))
    16911895                break;
     
    17341938                uAttr = rtDwarfCursor_GetULeb128AsU32(&Cursor, 0);
    17351939                uForm = rtDwarfCursor_GetULeb128AsU32(&Cursor, 0);
    1736             } while (uAttr != 0 && uForm != 0);
     1940            } while (uAttr != 0);
    17371941            if (RT_FAILURE(Cursor.rc))
    17381942                break;
     
    18942098
    18952099/**
     2100 * Resolves a string section (debug_str) reference.
     2101 *
     2102 * @returns Pointer to the string (inside the string section).
     2103 * @param   pThis               The DWARF instance.
     2104 * @param   pCursor             The cursor.
     2105 * @param   pszErrValue         What to return on failure (@a
     2106 *                              pCursor->rc is set).
     2107 */
     2108static const char *rtDwarfForm_GetStrp(PRTDBGMODDWARF pThis, PRTDWARFCURSOR pCursor, const char *pszErrValue)
     2109{
     2110    uint64_t offDebugStr = rtDwarfCursor_GetUOff(pCursor, UINT64_MAX);
     2111    if (RT_FAILURE(pCursor->rc))
     2112        return pszErrValue;
     2113
     2114    if (offDebugStr >= pThis->aSections[krtDbgModDwarfSect_str].cb)
     2115    {
     2116        /* Ugly: Exploit the cursor status field for reporting errors. */
     2117        pCursor->rc = VERR_DWARF_BAD_INFO;
     2118        return pszErrValue;
     2119    }
     2120
     2121    if (!pThis->aSections[krtDbgModDwarfSect_str].pv)
     2122    {
     2123        int rc = rtDbgModDwarfLoadSection(pThis, krtDbgModDwarfSect_str);
     2124        if (RT_FAILURE(rc))
     2125        {
     2126            /* Ugly: Exploit the cursor status field for reporting errors. */
     2127            pCursor->rc = rc;
     2128            return pszErrValue;
     2129        }
     2130    }
     2131
     2132    return (const char *)pThis->aSections[krtDbgModDwarfSect_str].pv + (size_t)offDebugStr;
     2133}
     2134
     2135static const char *rtDwarfForm_GetString(PRTDBGMODDWARF pThis, PRTDWARFCURSOR pCursor, uint16_t uForm, const char *pszErrValue)
     2136{
     2137    switch (uForm)
     2138    {
     2139        case DW_FORM_string:
     2140            return rtDwarfCursor_GetSZ(pCursor, pszErrValue);
     2141
     2142        case DW_FORM_strp:
     2143            return rtDwarfForm_GetStrp(pThis, pCursor, pszErrValue);
     2144
     2145        default:
     2146            pCursor->rc = VERR_DWARF_UNEXPECTED_FORM;
     2147            return pszErrValue;
     2148    }
     2149}
     2150
     2151
     2152/**
     2153 * Skips a form.
     2154 * @returns IPRT status code
     2155 * @param   pCursor             The cursor.
     2156 * @param   uForm               The form to skip.
     2157 */
     2158static int rtDwarfInfo_SkipForm(PRTDWARFCURSOR pCursor, uint32_t uForm)
     2159{
     2160    switch (uForm)
     2161    {
     2162        case DW_FORM_addr:
     2163            return rtDwarfCursor_SkipBytes(pCursor, pCursor->cbNativeAddr);
     2164
     2165        case DW_FORM_block:
     2166        case DW_FORM_exprloc:
     2167            return rtDwarfCursor_SkipBytes(pCursor, rtDwarfCursor_GetULeb128(pCursor, 0));
     2168
     2169        case DW_FORM_block1:
     2170            return rtDwarfCursor_SkipBytes(pCursor, rtDwarfCursor_GetU8(pCursor, 0));
     2171
     2172        case DW_FORM_block2:
     2173            return rtDwarfCursor_SkipBytes(pCursor, rtDwarfCursor_GetU16(pCursor, 0));
     2174
     2175        case DW_FORM_block4:
     2176            return rtDwarfCursor_SkipBytes(pCursor, rtDwarfCursor_GetU32(pCursor, 0));
     2177
     2178        case DW_FORM_data1:
     2179        case DW_FORM_ref1:
     2180        case DW_FORM_flag:
     2181            return rtDwarfCursor_SkipBytes(pCursor, 1);
     2182
     2183        case DW_FORM_data2:
     2184        case DW_FORM_ref2:
     2185            return rtDwarfCursor_SkipBytes(pCursor, 2);
     2186
     2187        case DW_FORM_data4:
     2188        case DW_FORM_ref4:
     2189            return rtDwarfCursor_SkipBytes(pCursor, 4);
     2190
     2191        case DW_FORM_data8:
     2192        case DW_FORM_ref8:
     2193        case DW_FORM_ref_sig8:
     2194            return rtDwarfCursor_SkipBytes(pCursor, 8);
     2195
     2196        case DW_FORM_udata:
     2197        case DW_FORM_sdata:
     2198        case DW_FORM_ref_udata:
     2199            return rtDwarfCursor_SkipLeb128(pCursor);
     2200
     2201        case DW_FORM_string:
     2202            rtDwarfCursor_GetSZ(pCursor, NULL);
     2203            return pCursor->rc;
     2204
     2205        case DW_FORM_indirect:
     2206            return rtDwarfInfo_SkipForm(pCursor, rtDwarfCursor_GetULeb128AsU32(pCursor, UINT32_MAX));
     2207
     2208        case DW_FORM_strp:
     2209        case DW_FORM_ref_addr:
     2210        case DW_FORM_sec_offset:
     2211            return rtDwarfCursor_SkipBytes(pCursor, pCursor->f64bitDwarf ? 8 : 4);
     2212
     2213        case DW_FORM_flag_present:
     2214            return pCursor->rc; /* no data */
     2215
     2216        default:
     2217            return VERR_DWARF_UNKNOWN_FORM;
     2218    }
     2219}
     2220
     2221
     2222
     2223/**
     2224 * Skips a DIE.
     2225 *
     2226 * @returns IPRT status code.
     2227 * @param   pCursor         The cursor.
     2228 * @param   pAbbrevCursor   The abbreviation cursor.
     2229 */
     2230static int rtDwarfInfo_SkipDie(PRTDWARFCURSOR pCursor, PRTDWARFCURSOR pAbbrevCursor)
     2231{
     2232    for (;;)
     2233    {
     2234        uint32_t uAttr = rtDwarfCursor_GetULeb128AsU32(pAbbrevCursor, 0);
     2235        uint32_t uForm = rtDwarfCursor_GetULeb128AsU32(pAbbrevCursor, 0);
     2236        if (uAttr == 0 && uForm == 0)
     2237            break;
     2238
     2239        int rc = rtDwarfInfo_SkipForm(pCursor, uForm);
     2240        if (RT_FAILURE(rc))
     2241            return rc;
     2242    }
     2243    return RT_FAILURE(pCursor->rc) ? pCursor->rc : pAbbrevCursor->rc;
     2244}
     2245
     2246
     2247/**
    18962248 * Parse a DIE.
    18972249 *
     
    19072259                                PRTDWARFDIESTACK pStack)
    19082260{
    1909     return VERR_NOT_IMPLEMENTED;
     2261    /*
     2262     * Pick out DIEs which tag we find interesting.
     2263     */
     2264    switch (pAbbrev->uTag)
     2265    {
     2266        case DW_TAG_compile_unit:
     2267        case DW_TAG_partial_unit:
     2268            Log((" - DW_TAG_%s_unit:\n", pAbbrev->uTag == DW_TAG_compile_unit ? "compile" : "partial"));
     2269            for (;;)
     2270            {
     2271                uint32_t uAttr = rtDwarfCursor_GetULeb128AsU32(pAbbrevCursor, 0);
     2272                uint32_t uForm = rtDwarfCursor_GetULeb128AsU32(pAbbrevCursor, 0);
     2273                switch (uAttr)
     2274                {
     2275                    case 0:
     2276                        return VINF_SUCCESS;
     2277
     2278                    case DW_AT_name:
     2279                    {
     2280                        const char *pszName = rtDwarfForm_GetString(pThis, pCursor, uForm, "<error>");
     2281                        rtDwarfDieStack_SetName(pStack, pszName);
     2282                        Log4(("%*s   - name=%s\n", pStack->cOnStack*2, "", pszName));
     2283                        break;
     2284                    }
     2285
     2286                    case DW_AT_stmt_list:
     2287                        /** @todo  */
     2288                    default:
     2289                        Log4(("%*s   - attr=%#x form=%#x\n", pStack->cOnStack*2, "", uAttr, uForm));
     2290                        rtDwarfInfo_SkipForm(pCursor, uForm);
     2291                }
     2292                if (RT_FAILURE(pCursor->rc))
     2293                    return pCursor->rc;
     2294            }
     2295            break; /* not reached. */
     2296
     2297        case DW_TAG_subprogram:
     2298            Log((" - DW_TAG_subprogram:\n"));
     2299            for (;;)
     2300            {
     2301                uint32_t uAttr = rtDwarfCursor_GetULeb128AsU32(pAbbrevCursor, 0);
     2302                uint32_t uForm = rtDwarfCursor_GetULeb128AsU32(pAbbrevCursor, 0);
     2303                switch (uAttr)
     2304                {
     2305                    case 0:
     2306                        return VINF_SUCCESS;
     2307
     2308                    case DW_AT_name:
     2309                    {
     2310                        const char *pszName = rtDwarfForm_GetString(pThis, pCursor, uForm, "<error>");
     2311                        rtDwarfDieStack_SetName(pStack, pszName);
     2312                        Log4(("%*s   - name=%s\n", pStack->cOnStack*2, "", pszName));
     2313                        break;
     2314                    }
     2315
     2316                    default:
     2317                        Log4(("%*s   - attr=%#x form=%#x\n", pStack->cOnStack*2, "", uAttr, uForm));
     2318                        rtDwarfInfo_SkipForm(pCursor, uForm);
     2319                }
     2320                if (RT_FAILURE(pCursor->rc))
     2321                    return pCursor->rc;
     2322            }
     2323            break; /* not reached. */
     2324
     2325    }
     2326
     2327    return rtDwarfInfo_SkipDie(pCursor, pAbbrevCursor);
    19102328}
    19112329
     
    19142332static int rtDwarfInfo_LoadUnit(PRTDBGMODDWARF pThis, PRTDWARFCURSOR pCursor)
    19152333{
     2334    Log(("rtDwarfInfo_LoadUnit: %#x\n", rtDwarfCursor_CalcSectOffsetU32(pCursor)));
     2335
    19162336    /*
    19172337     * Read the compilation unit header.
     
    19262346    if (RT_FAILURE(pCursor->rc))
    19272347        return pCursor->rc;
     2348    Log(("   uVer=%d  offAbbrev=%#llx cbNativeAddr=%d\n", uVer, offAbbrev, cbNativeAddr));
    19282349
    19292350    /*
     
    19482369    {
    19492370        uint32_t uAbbrCode = rtDwarfCursor_GetULeb128AsU32(pCursor, UINT32_MAX);
    1950 
    19512371        if (!uAbbrCode)
    19522372        {
     
    19672387                break;
    19682388            }
     2389            Log4((" %*stag=%#x%s\n", Stack.cOnStack * 2, "", pAbbrev->uTag, pAbbrev->fChildren ? " has children" : ""));
    19692390
    19702391            /*
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