// RUN: FileCheck --input-file %t0 %s
CHECK: Disassembly of section __TEXT,__text:
+
+// RUN: llvm-objdump -m -d -g -dsym %p/Inputs/hello-macho-fat.dwarf %p/Inputs/hello-macho-fat | FileCheck -check-prefix MACHO_DSYM %s
+// RUN: llvm-objdump -m -d -g -dsym %p/Inputs/hello-macho-fat.dwarf %p/Inputs/hello-macho-thin | FileCheck -check-prefix MACHO_DSYM %s
+// RUN: llvm-objdump -m -d -g -dsym %p/Inputs/hello-macho-thin.dwarf %p/Inputs/hello-macho-thin | FileCheck -check-prefix MACHO_DSYM %s
+
+MACHO_DSYM: (__TEXT,__text) section
+
+// RUN: llvm-objdump -m -d -g -dsym %p/../Inputs/libbogus11.a %p/../../dsymutil/Inputs/basic.macho.x86_64 2>&1 | FileCheck -check-prefix BAD_INPUT %s
+
+BAD_INPUT: is not a Mach-O or Universal file type.
+
+// RUN: not llvm-objdump -m -d -g -dsym %p/Inputs %p/Inputs/hello-macho-thin 2>&1 | FileCheck -check-prefix DIRECTORY %s
+
+DIRECTORY: Is a directory
raw_ostream &DebugOut = nulls();
#endif
+ // Try to find debug info and set up the DIContext for it.
std::unique_ptr<DIContext> diContext;
- ObjectFile *DbgObj = MachOOF;
+ std::unique_ptr<Binary> DSYMBinary;
std::unique_ptr<MemoryBuffer> DSYMBuf;
- // Try to find debug info and set up the DIContext for it.
if (UseDbg) {
+ ObjectFile *DbgObj = MachOOF;
+
// A separate DSym file path was specified, parse it as a macho file,
// get the sections and supply it to the section name parsing machinery.
if (!DSYMFile.empty()) {
return;
}
- std::unique_ptr<MachOObjectFile> DbgObjCheck = unwrapOrError(
- ObjectFile::createMachOObjectFile(BufOrErr.get()->getMemBufferRef()),
- DSYMFile.getValue());
- DbgObj = DbgObjCheck.release();
// We need to keep the file alive, because we're replacing DbgObj with it.
DSYMBuf = std::move(BufOrErr.get());
+
+ Expected<std::unique_ptr<Binary>> BinaryOrErr =
+ createBinary(DSYMBuf.get()->getMemBufferRef());
+ if (!BinaryOrErr) {
+ report_error(BinaryOrErr.takeError(), DSYMFile);
+ return;
+ }
+
+ // We need to keep the Binary elive with the buffer
+ DSYMBinary = std::move(BinaryOrErr.get());
+
+ if (ObjectFile *O = dyn_cast<ObjectFile>(DSYMBinary.get())) {
+ // this is a Mach-O object file, use it
+ if (MachOObjectFile *MachDSYM = dyn_cast<MachOObjectFile>(&*O)) {
+ DbgObj = MachDSYM;
+ }
+ else {
+ WithColor::error(errs(), "llvm-objdump")
+ << DSYMFile << " is not a Mach-O file type.\n";
+ return;
+ }
+ }
+ else if (auto UB = dyn_cast<MachOUniversalBinary>(DSYMBinary.get())){
+ // this is a Universal Binary, find a Mach-O for this architecture
+ uint32_t CPUType, CPUSubType;
+ const char *ArchFlag;
+ if (MachOOF->is64Bit()) {
+ const MachO::mach_header_64 H_64 = MachOOF->getHeader64();
+ CPUType = H_64.cputype;
+ CPUSubType = H_64.cpusubtype;
+ } else {
+ const MachO::mach_header H = MachOOF->getHeader();
+ CPUType = H.cputype;
+ CPUSubType = H.cpusubtype;
+ }
+ Triple T = MachOObjectFile::getArchTriple(CPUType, CPUSubType, nullptr,
+ &ArchFlag);
+ Expected<std::unique_ptr<MachOObjectFile>> MachDSYM =
+ UB->getObjectForArch(ArchFlag);
+ if (!MachDSYM) {
+ report_error(MachDSYM.takeError(), DSYMFile);
+ return;
+ }
+
+ // We need to keep the Binary elive with the buffer
+ DbgObj = &*MachDSYM.get();
+ DSYMBinary = std::move(*MachDSYM);
+ }
+ else {
+ WithColor::error(errs(), "llvm-objdump")
+ << DSYMFile << " is not a Mach-O or Universal file type.\n";
+ return;
+ }
}
// Setup the DIContext