@@ -1375,17 +1375,17 @@ static uint64_t dumpARMELFData(uint64_t SectionAddr, uint64_t Index,
1375
1375
}
1376
1376
1377
1377
static void dumpELFData (uint64_t SectionAddr, uint64_t Index, uint64_t End,
1378
- ArrayRef<uint8_t > Bytes) {
1378
+ ArrayRef<uint8_t > Bytes, raw_ostream &OS ) {
1379
1379
// print out data up to 8 bytes at a time in hex and ascii
1380
1380
uint8_t AsciiData[9 ] = {' \0 ' };
1381
1381
uint8_t Byte ;
1382
1382
int NumBytes = 0 ;
1383
1383
1384
1384
for (; Index < End; ++Index) {
1385
1385
if (NumBytes == 0 )
1386
- outs () << format (" %8" PRIx64 " :" , SectionAddr + Index);
1386
+ OS << format (" %8" PRIx64 " :" , SectionAddr + Index);
1387
1387
Byte = Bytes.slice (Index)[0 ];
1388
- outs () << format (" %02x" , Byte );
1388
+ OS << format (" %02x" , Byte );
1389
1389
AsciiData[NumBytes] = isPrint (Byte ) ? Byte : ' .' ;
1390
1390
1391
1391
uint8_t IndentOffset = 0 ;
@@ -1400,9 +1400,9 @@ static void dumpELFData(uint64_t SectionAddr, uint64_t Index, uint64_t End,
1400
1400
}
1401
1401
if (NumBytes == 8 ) {
1402
1402
AsciiData[8 ] = ' \0 ' ;
1403
- outs () << std::string (IndentOffset, ' ' ) << " " ;
1404
- outs () << reinterpret_cast <char *>(AsciiData);
1405
- outs () << ' \n ' ;
1403
+ OS << std::string (IndentOffset, ' ' ) << " " ;
1404
+ OS << reinterpret_cast <char *>(AsciiData);
1405
+ OS << ' \n ' ;
1406
1406
NumBytes = 0 ;
1407
1407
}
1408
1408
}
@@ -1666,7 +1666,7 @@ static void
1666
1666
disassembleObject (ObjectFile &Obj, const ObjectFile &DbgObj,
1667
1667
DisassemblerTarget &PrimaryTarget,
1668
1668
std::optional<DisassemblerTarget> &SecondaryTarget,
1669
- SourcePrinter &SP, bool InlineRelocs) {
1669
+ SourcePrinter &SP, bool InlineRelocs, raw_ostream &OS ) {
1670
1670
DisassemblerTarget *DT = &PrimaryTarget;
1671
1671
bool PrimaryIsThumb = false ;
1672
1672
SmallVector<std::pair<uint64_t , uint64_t >, 0 > CHPECodeMap;
@@ -2089,10 +2089,10 @@ disassembleObject(ObjectFile &Obj, const ObjectFile &DbgObj,
2089
2089
2090
2090
if (!PrintedSection) {
2091
2091
PrintedSection = true ;
2092
- outs () << " \n Disassembly of section " ;
2092
+ OS << " \n Disassembly of section " ;
2093
2093
if (!SegmentName.empty ())
2094
- outs () << SegmentName << " ," ;
2095
- outs () << SectionName << " :\n " ;
2094
+ OS << SegmentName << " ," ;
2095
+ OS << SectionName << " :\n " ;
2096
2096
}
2097
2097
2098
2098
bool PrintedLabel = false ;
@@ -2104,22 +2104,22 @@ disassembleObject(ObjectFile &Obj, const ObjectFile &DbgObj,
2104
2104
const StringRef SymbolName = SymNamesHere[i];
2105
2105
2106
2106
if (!PrintedLabel) {
2107
- outs () << ' \n ' ;
2107
+ OS << ' \n ' ;
2108
2108
PrintedLabel = true ;
2109
2109
}
2110
2110
if (LeadingAddr)
2111
- outs () << format (Is64Bits ? " %016" PRIx64 " " : " %08" PRIx64 " " ,
2112
- SectionAddr + Start + VMAAdjustment);
2111
+ OS << format (Is64Bits ? " %016" PRIx64 " " : " %08" PRIx64 " " ,
2112
+ SectionAddr + Start + VMAAdjustment);
2113
2113
if (Obj.isXCOFF () && SymbolDescription) {
2114
- outs () << getXCOFFSymbolDescription (Symbol, SymbolName) << " :\n " ;
2114
+ OS << getXCOFFSymbolDescription (Symbol, SymbolName) << " :\n " ;
2115
2115
} else
2116
- outs () << ' <' << SymbolName << " >:\n " ;
2116
+ OS << ' <' << SymbolName << " >:\n " ;
2117
2117
}
2118
2118
2119
2119
// Don't print raw contents of a virtual section. A virtual section
2120
2120
// doesn't have any contents in the file.
2121
2121
if (Section.isVirtual ()) {
2122
- outs () << " ...\n " ;
2122
+ OS << " ...\n " ;
2123
2123
continue ;
2124
2124
}
2125
2125
@@ -2156,17 +2156,17 @@ disassembleObject(ObjectFile &Obj, const ObjectFile &DbgObj,
2156
2156
do {
2157
2157
StringRef Line;
2158
2158
std::tie (Line, ErrMsg) = ErrMsg.split (' \n ' );
2159
- outs () << DT->Context ->getAsmInfo ()->getCommentString ()
2160
- << " error decoding " << SymNamesHere[SHI] << " : " << Line
2161
- << ' \n ' ;
2159
+ OS << DT->Context ->getAsmInfo ()->getCommentString ()
2160
+ << " error decoding " << SymNamesHere[SHI] << " : " << Line
2161
+ << ' \n ' ;
2162
2162
} while (!ErrMsg.empty ());
2163
2163
2164
2164
if (Size ) {
2165
- outs () << DT->Context ->getAsmInfo ()->getCommentString ()
2166
- << " decoding failed region as bytes\n " ;
2165
+ OS << DT->Context ->getAsmInfo ()->getCommentString ()
2166
+ << " decoding failed region as bytes\n " ;
2167
2167
for (uint64_t I = 0 ; I < Size ; ++I)
2168
- outs () << " \t .byte\t " << format_hex (Bytes[I], 1 , /* Upper=*/ true )
2169
- << ' \n ' ;
2168
+ OS << " \t .byte\t " << format_hex (Bytes[I], 1 , /* Upper=*/ true )
2169
+ << ' \n ' ;
2170
2170
}
2171
2171
}
2172
2172
@@ -2179,13 +2179,13 @@ disassembleObject(ObjectFile &Obj, const ObjectFile &DbgObj,
2179
2179
Start += Size ;
2180
2180
break ;
2181
2181
}
2182
-
2182
+ formatted_raw_ostream FOS (OS);
2183
2183
Index = Start;
2184
2184
if (SectionAddr < StartAddress)
2185
2185
Index = std::max<uint64_t >(Index, StartAddress - SectionAddr);
2186
2186
2187
2187
if (DisassembleAsELFData) {
2188
- dumpELFData (SectionAddr, Index, End, Bytes);
2188
+ dumpELFData (SectionAddr, Index, End, Bytes, FOS );
2189
2189
Index = End;
2190
2190
continue ;
2191
2191
}
@@ -2203,8 +2203,6 @@ disassembleObject(ObjectFile &Obj, const ObjectFile &DbgObj,
2203
2203
Symbols[SI - 1 ].XCOFFSymInfo .StorageMappingClass &&
2204
2204
(*Symbols[SI - 1 ].XCOFFSymInfo .StorageMappingClass == XCOFF::XMC_PR);
2205
2205
2206
- formatted_raw_ostream FOS (outs ());
2207
-
2208
2206
std::unordered_map<uint64_t , std::string> AllLabels;
2209
2207
std::unordered_map<uint64_t , std::vector<BBAddrMapLabel>> BBAddrMapLabels;
2210
2208
if (SymbolizeOperands) {
@@ -2553,7 +2551,8 @@ disassembleObject(ObjectFile &Obj, const ObjectFile &DbgObj,
2553
2551
reportWarning (" failed to disassemble missing symbol " + Sym, FileName);
2554
2552
}
2555
2553
2556
- static void disassembleObject (ObjectFile *Obj, bool InlineRelocs) {
2554
+ static void disassembleObject (ObjectFile *Obj, bool InlineRelocs,
2555
+ raw_ostream &OS) {
2557
2556
// If information useful for showing the disassembly is missing, try to find a
2558
2557
// more complete binary and disassemble that instead.
2559
2558
OwningBinary<Binary> FetchedBinary;
@@ -2679,7 +2678,7 @@ static void disassembleObject(ObjectFile *Obj, bool InlineRelocs) {
2679
2678
" Unrecognized disassembler option: " + Opt);
2680
2679
2681
2680
disassembleObject (*Obj, *DbgObj, PrimaryTarget, SecondaryTarget, SP,
2682
- InlineRelocs);
2681
+ InlineRelocs, OS );
2683
2682
}
2684
2683
2685
2684
void Dumper::printRelocations () {
@@ -3340,7 +3339,7 @@ static void dumpObject(ObjectFile *O, const Archive *A = nullptr,
3340
3339
if (SectionContents)
3341
3340
printSectionContents (O);
3342
3341
if (Disassemble)
3343
- disassembleObject (O, Relocations);
3342
+ disassembleObject (O, Relocations, outs () );
3344
3343
if (UnwindInfo)
3345
3344
printUnwindInfo (O);
3346
3345
0 commit comments