Changeset 38606 in vbox for trunk/src/VBox/Runtime/common/dbg
- Timestamp:
- Sep 2, 2011 1:14:51 AM (14 years ago)
- svn:sync-xref-src-repo-rev:
- 73809
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/dbg/dbgmoddwarf.cpp
r38603 r38606 48 48 /** @name Standard DWARF Line Number Opcodes 49 49 * @{ */ 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) 63 64 /** @} */ 64 65 … … 138 139 /** @} */ 139 140 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 140 271 /******************************************************************************* 141 272 * Structures and Typedefs * … … 731 862 static int rtDwarfCursor_SkipLeb128(PRTDWARFCURSOR pCursor) 732 863 { 864 if (RT_FAILURE(pCursor->rc)) 865 return pCursor->rc; 866 733 867 if (pCursor->cbUnitLeft < 1) 734 868 return pCursor->rc = VERR_DWARF_UNEXPECTED_END; … … 753 887 754 888 /** 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 */ 895 static 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 /** 755 912 * Reads a zero terminated string, advancing the cursor beyond the terminator. 756 913 * … … 780 937 781 938 /** 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 */ 946 static 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 /** 782 966 * Reads an unsigned DWARF half number. 783 967 * … … 904 1088 static uint32_t rtDwarfCursor_CalcSectOffsetU32(PRTDWARFCURSOR pCursor) 905 1089 { 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; 907 1091 uint32_t offRet = (uint32_t)off; 908 1092 if (offRet != off) … … 928 1112 if (offRelative > pCursor->cbUnitLeft) 929 1113 { 1114 Log(("rtDwarfCursor_CalcPos: bad position %#zx, cbUnitLeft=%#zu\n", offRelative, pCursor->cbUnitLeft)); 930 1115 pCursor->rc = VERR_DWARF_BAD_POS; 931 1116 return NULL; … … 949 1134 AssertPtr(pbNewPos); 950 1135 if ((uintptr_t)pbNewPos < (uintptr_t)pCursor->pb) 1136 { 1137 Log(("rtDwarfCursor_AdvanceToPos: bad position %p, current %p\n", pbNewPos, pCursor->pb)); 951 1138 return pCursor->rc = VERR_DWARF_BAD_POS; 1139 } 952 1140 953 1141 uintptr_t cbAdj = (uintptr_t)pbNewPos - (uintptr_t)pCursor->pb; … … 1052 1240 { 1053 1241 if (offSect > pThis->aSections[enmSect].cb) 1242 { 1243 Log(("rtDwarfCursor_InitWithOffset: offSect=%#x cb=%#x enmSect=%d\n", offSect, pThis->aSections[enmSect].cb, enmSect)); 1054 1244 return VERR_DWARF_BAD_POS; 1245 } 1055 1246 1056 1247 int rc = rtDwarfCursor_Init(pCursor, pThis, enmSect); … … 1149 1340 * @returns IPRT status code 1150 1341 * @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 */ 1345 static int rtDwarfLine_AddLine(PRTDWARFLINESTATE pLnState, uint32_t offOpCode) 1153 1346 { 1154 1347 const char *pszFile = pLnState->Regs.iFile < pLnState->cFileNames … … 1160 1353 if (RT_SUCCESS(rc)) 1161 1354 { 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)); 1163 1356 rc = RTDbgModLineAdd(pLnState->pDwarfMod->hCnt, pszFile, pLnState->Regs.uLine, iSeg, offSeg, NULL); 1164 1357 … … 1214 1407 while (!rtDwarfCursor_IsAtEndOfUnit(pCursor)) 1215 1408 { 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) 1218 1416 { 1219 1417 /* … … 1233 1431 pLnState->Regs.uAddress += cAddressDelta; 1234 1432 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, 1237 1435 cOpIndexDelta, pLnState->Regs.idxOp)); 1238 1436 1239 rc = rtDwarfLine_AddLine(pLnState );1437 rc = rtDwarfLine_AddLine(pLnState, offOpCode); 1240 1438 } 1241 1439 else … … 1247 1445 */ 1248 1446 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); 1251 1449 break; 1252 1450 … … 1257 1455 * pLnState->Hdr.cbMinInstr; 1258 1456 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)); 1260 1458 break; 1261 1459 } … … 1265 1463 int32_t cLineDelta = rtDwarfCursor_GetSLeb128AsS32(pCursor, 0); 1266 1464 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)); 1268 1466 break; 1269 1467 } … … 1271 1469 case DW_LNS_set_file: 1272 1470 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)); 1274 1472 break; 1275 1473 1276 1474 case DW_LNS_set_column: 1277 1475 pLnState->Regs.uColumn = rtDwarfCursor_GetULeb128AsU32(pCursor, 0); 1278 Log2((" DW_LNS_set_column\n"));1476 Log2(("%08x: DW_LNS_set_column\n", offOpCode)); 1279 1477 break; 1280 1478 1281 1479 case DW_LNS_negate_stmt: 1282 1480 pLnState->Regs.fIsStatement = !pLnState->Regs.fIsStatement; 1283 Log2((" DW_LNS_negate_stmt\n"));1481 Log2(("%08x: DW_LNS_negate_stmt\n", offOpCode)); 1284 1482 break; 1285 1483 1286 1484 case DW_LNS_set_basic_block: 1287 1485 pLnState->Regs.fBasicBlock = true; 1288 Log2((" DW_LNS_set_basic_block\n"));1486 Log2(("%08x: DW_LNS_set_basic_block\n", offOpCode)); 1289 1487 break; 1290 1488 … … 1293 1491 * pLnState->Hdr.cbMinInstr; 1294 1492 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)); 1296 1494 break; 1297 1495 … … 1299 1497 pLnState->Regs.uAddress += rtDwarfCursor_GetUHalf(pCursor, 0); 1300 1498 pLnState->Regs.idxOp = 0; 1301 Log2((" DW_LNS_fixed_advance_pc\n"));1499 Log2(("%08x: DW_LNS_fixed_advance_pc\n", offOpCode)); 1302 1500 break; 1303 1501 1304 1502 case DW_LNS_set_prologue_end: 1305 1503 pLnState->Regs.fPrologueEnd = true; 1306 Log2((" DW_LNS_set_prologue_end\n"));1504 Log2(("%08x: DW_LNS_set_prologue_end\n", offOpCode)); 1307 1505 break; 1308 1506 1309 1507 case DW_LNS_set_epilogue_begin: 1310 1508 pLnState->Regs.fEpilogueBegin = true; 1311 Log2((" DW_LNS_set_epilogue_begin\n"));1509 Log2(("%08x: DW_LNS_set_epilogue_begin\n", offOpCode)); 1312 1510 break; 1313 1511 1314 1512 case DW_LNS_set_isa: 1315 1513 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)); 1317 1515 break; 1318 1516 … … 1320 1518 { 1321 1519 unsigned cOpsToSkip = pLnState->Hdr.pacStdOperands[bOpCode - 1]; 1322 Log 2(("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)); 1323 1521 while (cOpsToSkip-- > 0) 1324 1522 rc = rtDwarfCursor_SkipLeb128(pCursor); … … 1346 1544 #if 0 /* No need for this, I think. */ 1347 1545 pLnState->Regs.fEndSequence = true; 1348 rc = rtDwarfLine_AddLine(pLnState );1546 rc = rtDwarfLine_AddLine(pLnState, offOpCode); 1349 1547 #endif 1350 1548 rtDwarfLine_ResetState(pLnState); 1351 Log2((" DW_LNE_end_sequence\n"));1549 Log2(("%08x: DW_LNE_end_sequence\n", offOpCode)); 1352 1550 break; 1353 1551 1354 1552 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)); 1367 1556 break; 1368 1557 … … 1373 1562 rtDwarfCursor_SkipLeb128(pCursor); /* st_mtime */ 1374 1563 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)); 1376 1565 1377 1566 rc = rtDwarfCursor_AdvanceToPos(pCursor, pbEndOfInstr); … … 1380 1569 } 1381 1570 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 */ 1382 1576 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 } 1385 1589 break; 1386 1590 1387 1591 default: 1388 Log 2(("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)); 1389 1593 break; 1390 1594 } … … 1659 1863 1660 1864 /* Cache it? */ 1661 if (uCurCode >= pThis->cCachedAbbrevsAlloced)1865 if (uCurCode <= pThis->cCachedAbbrevsAlloced) 1662 1866 { 1663 1867 PRTDWARFABBREV pEntry = &pThis->paCachedAbbrevs[uCurCode - 1]; … … 1687 1891 uAttr = rtDwarfCursor_GetULeb128AsU32(&Cursor, 0); 1688 1892 uForm = rtDwarfCursor_GetULeb128AsU32(&Cursor, 0); 1689 } while (uAttr != 0 && uForm != 0);1893 } while (uAttr != 0); 1690 1894 if (RT_FAILURE(Cursor.rc)) 1691 1895 break; … … 1734 1938 uAttr = rtDwarfCursor_GetULeb128AsU32(&Cursor, 0); 1735 1939 uForm = rtDwarfCursor_GetULeb128AsU32(&Cursor, 0); 1736 } while (uAttr != 0 && uForm != 0);1940 } while (uAttr != 0); 1737 1941 if (RT_FAILURE(Cursor.rc)) 1738 1942 break; … … 1894 2098 1895 2099 /** 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 */ 2108 static 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 2135 static 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 */ 2158 static 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 */ 2230 static 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 /** 1896 2248 * Parse a DIE. 1897 2249 * … … 1907 2259 PRTDWARFDIESTACK pStack) 1908 2260 { 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); 1910 2328 } 1911 2329 … … 1914 2332 static int rtDwarfInfo_LoadUnit(PRTDBGMODDWARF pThis, PRTDWARFCURSOR pCursor) 1915 2333 { 2334 Log(("rtDwarfInfo_LoadUnit: %#x\n", rtDwarfCursor_CalcSectOffsetU32(pCursor))); 2335 1916 2336 /* 1917 2337 * Read the compilation unit header. … … 1926 2346 if (RT_FAILURE(pCursor->rc)) 1927 2347 return pCursor->rc; 2348 Log((" uVer=%d offAbbrev=%#llx cbNativeAddr=%d\n", uVer, offAbbrev, cbNativeAddr)); 1928 2349 1929 2350 /* … … 1948 2369 { 1949 2370 uint32_t uAbbrCode = rtDwarfCursor_GetULeb128AsU32(pCursor, UINT32_MAX); 1950 1951 2371 if (!uAbbrCode) 1952 2372 { … … 1967 2387 break; 1968 2388 } 2389 Log4((" %*stag=%#x%s\n", Stack.cOnStack * 2, "", pAbbrev->uTag, pAbbrev->fChildren ? " has children" : "")); 1969 2390 1970 2391 /*
Note:
See TracChangeset
for help on using the changeset viewer.