@@ -491,11 +491,27 @@ void BinaryFunction::print(raw_ostream &OS, std::string Annotation) {
491491 // Offset of the instruction in function.
492492 uint64_t Offset = 0 ;
493493
494+ auto printConstantIslandInRange = [&](uint64_t Offset, uint64_t Size) {
495+ std::optional<uint64_t > IslandOffset =
496+ getIslandInRange (Offset, Offset + Size);
497+
498+ if (!IslandOffset)
499+ return ;
500+
501+ const size_t IslandSize = getSizeOfDataInCodeAt (*IslandOffset);
502+ BC.printData (OS, BC.extractData (getAddress () + *IslandOffset, IslandSize),
503+ *IslandOffset);
504+ };
505+
494506 if (BasicBlocks.empty () && !Instructions.empty ()) {
495507 // Print before CFG was built.
508+ uint64_t PrevOffset = 0 ;
496509 for (const std::pair<const uint32_t , MCInst> &II : Instructions) {
497510 Offset = II.first ;
498511
512+ // Print any constant islands inbeetween the instructions.
513+ printConstantIslandInRange (PrevOffset, Offset);
514+
499515 // Print label if exists at this offset.
500516 auto LI = Labels.find (Offset);
501517 if (LI != Labels.end ()) {
@@ -506,7 +522,12 @@ void BinaryFunction::print(raw_ostream &OS, std::string Annotation) {
506522 }
507523
508524 BC.printInstruction (OS, II.second , Offset, this );
525+
526+ PrevOffset = Offset;
509527 }
528+
529+ // Print any data at the end of the function.
530+ printConstantIslandInRange (PrevOffset, getMaxSize ());
510531 }
511532
512533 StringRef SplitPointMsg = " " ;
@@ -1048,6 +1069,19 @@ size_t BinaryFunction::getSizeOfDataInCodeAt(uint64_t Offset) const {
10481069 return getSize () - Offset;
10491070}
10501071
1072+ std::optional<uint64_t >
1073+ BinaryFunction::getIslandInRange (uint64_t StartOffset,
1074+ uint64_t EndOffset) const {
1075+ if (!Islands)
1076+ return std::nullopt ;
1077+
1078+ auto Iter = llvm::lower_bound (Islands->DataOffsets , StartOffset);
1079+ if (Iter != Islands->DataOffsets .end () && *Iter < EndOffset)
1080+ return *Iter;
1081+
1082+ return std::nullopt ;
1083+ }
1084+
10511085bool BinaryFunction::isZeroPaddingAt (uint64_t Offset) const {
10521086 ArrayRef<uint8_t > FunctionData = *getData ();
10531087 uint64_t EndOfCode = getSize ();
0 commit comments