@@ -7223,13 +7223,11 @@ static void DisassembleMachO(StringRef Filename, MachOObjectFile *MachOOF,
7223
7223
raw_ostream &DebugOut = nulls ();
7224
7224
#endif
7225
7225
7226
- // Try to find debug info and set up the DIContext for it.
7227
7226
std::unique_ptr<DIContext> diContext;
7228
- std::unique_ptr<Binary> DSYMBinary ;
7227
+ ObjectFile *DbgObj = MachOOF ;
7229
7228
std::unique_ptr<MemoryBuffer> DSYMBuf;
7229
+ // Try to find debug info and set up the DIContext for it.
7230
7230
if (UseDbg) {
7231
- ObjectFile *DbgObj = MachOOF;
7232
-
7233
7231
// A separate DSym file path was specified, parse it as a macho file,
7234
7232
// get the sections and supply it to the section name parsing machinery.
7235
7233
if (!DSYMFile.empty ()) {
@@ -7240,61 +7238,12 @@ static void DisassembleMachO(StringRef Filename, MachOObjectFile *MachOOF,
7240
7238
return ;
7241
7239
}
7242
7240
7241
+ std::unique_ptr<MachOObjectFile> DbgObjCheck = unwrapOrError (
7242
+ ObjectFile::createMachOObjectFile (BufOrErr.get ()->getMemBufferRef ()),
7243
+ DSYMFile.getValue ());
7244
+ DbgObj = DbgObjCheck.release ();
7243
7245
// We need to keep the file alive, because we're replacing DbgObj with it.
7244
7246
DSYMBuf = std::move (BufOrErr.get ());
7245
-
7246
- Expected<std::unique_ptr<Binary>> BinaryOrErr =
7247
- createBinary (DSYMBuf.get ()->getMemBufferRef ());
7248
- if (!BinaryOrErr) {
7249
- report_error (BinaryOrErr.takeError (), DSYMFile);
7250
- return ;
7251
- }
7252
-
7253
- // We need to keep the Binary elive with the buffer
7254
- DSYMBinary = std::move (BinaryOrErr.get ());
7255
-
7256
- if (ObjectFile *O = dyn_cast<ObjectFile>(DSYMBinary.get ())) {
7257
- // this is a Mach-O object file, use it
7258
- if (MachOObjectFile *MachDSYM = dyn_cast<MachOObjectFile>(&*O)) {
7259
- DbgObj = MachDSYM;
7260
- }
7261
- else {
7262
- WithColor::error (errs (), " llvm-objdump" )
7263
- << DSYMFile << " is not a Mach-O file type.\n " ;
7264
- return ;
7265
- }
7266
- }
7267
- else if (auto UB = dyn_cast<MachOUniversalBinary>(DSYMBinary.get ())){
7268
- // this is a Universal Binary, find a Mach-O for this architecture
7269
- uint32_t CPUType, CPUSubType;
7270
- const char *ArchFlag;
7271
- if (MachOOF->is64Bit ()) {
7272
- const MachO::mach_header_64 H_64 = MachOOF->getHeader64 ();
7273
- CPUType = H_64.cputype ;
7274
- CPUSubType = H_64.cpusubtype ;
7275
- } else {
7276
- const MachO::mach_header H = MachOOF->getHeader ();
7277
- CPUType = H.cputype ;
7278
- CPUSubType = H.cpusubtype ;
7279
- }
7280
- Triple T = MachOObjectFile::getArchTriple (CPUType, CPUSubType, nullptr ,
7281
- &ArchFlag);
7282
- Expected<std::unique_ptr<MachOObjectFile>> MachDSYM =
7283
- UB->getObjectForArch (ArchFlag);
7284
- if (!MachDSYM) {
7285
- report_error (MachDSYM.takeError (), DSYMFile);
7286
- return ;
7287
- }
7288
-
7289
- // We need to keep the Binary elive with the buffer
7290
- DbgObj = &*MachDSYM.get ();
7291
- DSYMBinary = std::move (*MachDSYM);
7292
- }
7293
- else {
7294
- WithColor::error (errs (), " llvm-objdump" )
7295
- << DSYMFile << " is not a Mach-O or Universal file type.\n " ;
7296
- return ;
7297
- }
7298
7247
}
7299
7248
7300
7249
// Setup the DIContext
0 commit comments