|
39 | 39 |
|
40 | 40 | #undef DEBUG_TYPE
|
41 | 41 | #define DEBUG_TYPE "bolt"
|
| 42 | +namespace opts { |
| 43 | +extern cl::opt<unsigned> Verbosity; |
| 44 | +} |
42 | 45 | namespace llvm {
|
43 | 46 | namespace bolt {
|
44 | 47 |
|
@@ -105,6 +108,14 @@ uint32_t DIEBuilder::allocDIE(const DWARFUnit &DU, const DWARFDie &DDie,
|
105 | 108 | return DWARFUnitInfo.DIEIDMap[DDieOffset];
|
106 | 109 |
|
107 | 110 | DIE *Die = DIE::get(Alloc, dwarf::Tag(DDie.getTag()));
|
| 111 | + // This handles the case where there is a DIE ref which points to |
| 112 | + // invalid DIE. This prevents assert when IR is written out. |
| 113 | + // Also it makes debugging easier. |
| 114 | + // DIE dump is not very useful. |
| 115 | + // It's nice to know original offset from which this DIE was constructed. |
| 116 | + Die->setOffset(DDie.getOffset()); |
| 117 | + if (opts::Verbosity >= 1) |
| 118 | + getState().DWARFDieAddressesParsed.insert(DDie.getOffset()); |
108 | 119 | const uint32_t DId = DWARFUnitInfo.DieInfoVector.size();
|
109 | 120 | DWARFUnitInfo.DIEIDMap[DDieOffset] = DId;
|
110 | 121 | DWARFUnitInfo.DieInfoVector.emplace_back(
|
@@ -290,10 +301,6 @@ DIE *DIEBuilder::constructDIEFast(DWARFDie &DDie, DWARFUnit &U,
|
290 | 301 | DIEInfo &DieInfo = getDIEInfo(UnitId, *Idx);
|
291 | 302 |
|
292 | 303 | uint64_t Offset = DDie.getOffset();
|
293 |
| - // Just for making debugging easier. |
294 |
| - // DIE dump is not very useful. |
295 |
| - // It's nice to know original offset from which this DIE was constructed. |
296 |
| - DieInfo.Die->setOffset(Offset); |
297 | 304 | uint64_t NextOffset = Offset;
|
298 | 305 | DWARFDataExtractor Data = U.getDebugInfoExtractor();
|
299 | 306 | DWARFDebugInfoEntry DDIEntry;
|
@@ -369,6 +376,7 @@ getUnitForOffset(DIEBuilder &Builder, DWARFContext &DWCtx,
|
369 | 376 |
|
370 | 377 | uint32_t DIEBuilder::computeDIEOffset(const DWARFUnit &CU, DIE &Die,
|
371 | 378 | uint32_t &CurOffset) {
|
| 379 | + getState().DWARFDieAddressesParsed.erase(Die.getOffset()); |
372 | 380 | uint32_t CurSize = 0;
|
373 | 381 | Die.setOffset(CurOffset);
|
374 | 382 | for (DIEValue &Val : Die.values())
|
@@ -421,6 +429,13 @@ void DIEBuilder::finish() {
|
421 | 429 | continue;
|
422 | 430 | computeOffset(*CU, UnitSize);
|
423 | 431 | }
|
| 432 | + if (opts::Verbosity >= 1) { |
| 433 | + if (!getState().DWARFDieAddressesParsed.empty()) |
| 434 | + dbgs() << "Referenced DIE offsets not in .debug_info\n"; |
| 435 | + for (const uint64_t Address : getState().DWARFDieAddressesParsed) { |
| 436 | + dbgs() << Twine::utohexstr(Address) << "\n"; |
| 437 | + } |
| 438 | + } |
424 | 439 | updateReferences();
|
425 | 440 | }
|
426 | 441 |
|
@@ -457,11 +472,20 @@ DWARFDie DIEBuilder::resolveDIEReference(
|
457 | 472 | allocDIE(*RefCU, RefDie, getState().DIEAlloc, *UnitId);
|
458 | 473 | return RefDie;
|
459 | 474 | }
|
| 475 | + errs() << "BOLT-WARNING: [internal-dwarf-error]: invalid referenced DIE " |
| 476 | + "at offset: " |
| 477 | + << Twine::utohexstr(RefOffset) << ".\n"; |
| 478 | + |
| 479 | + } else { |
| 480 | + errs() << "BOLT-WARNING: [internal-dwarf-error]: could not parse " |
| 481 | + "referenced DIE at offset: " |
| 482 | + << Twine::utohexstr(RefOffset) << ".\n"; |
460 | 483 | }
|
| 484 | + } else { |
| 485 | + errs() << "BOLT-WARNING: [internal-dwarf-error]: could not find referenced " |
| 486 | + "CU. Referenced DIE offset: " |
| 487 | + << Twine::utohexstr(RefOffset) << ".\n"; |
461 | 488 | }
|
462 |
| - |
463 |
| - errs() << "BOLT-WARNING: [internal-dwarf-error]: could not find referenced " |
464 |
| - "CU.\n"; |
465 | 489 | return DWARFDie();
|
466 | 490 | }
|
467 | 491 |
|
|
0 commit comments