[llvm-objdump] Keep the memory buffer from the dSYM alive when using -g -dsym
authorFrancis Visoiu Mistrih <francisvm@yahoo.com>
Fri, 31 Aug 2018 13:10:54 +0000 (13:10 +0000)
committerFrancis Visoiu Mistrih <francisvm@yahoo.com>
Fri, 31 Aug 2018 13:10:54 +0000 (13:10 +0000)
When using -g and -dsym, llvm-objdump opens the dsym file and keeps the
MachOObjectFile alive, while the memory buffer that the MachOObjectFile
was based on gets destroyed.

Differential Revision: https://reviews.llvm.org/D51365

llvm-svn: 341209

llvm/test/tools/llvm-objdump/X86/macho-disassembly-g-dsym.test [new file with mode: 0644]
llvm/tools/llvm-objdump/MachODump.cpp

diff --git a/llvm/test/tools/llvm-objdump/X86/macho-disassembly-g-dsym.test b/llvm/test/tools/llvm-objdump/X86/macho-disassembly-g-dsym.test
new file mode 100644 (file)
index 0000000..7ed1110
--- /dev/null
@@ -0,0 +1,4 @@
+// RUN: dsymutil -f -oso-prepend-path=%p/../../dsymutil/ %p/../../dsymutil/Inputs/basic.macho.x86_64 -o %t1.dSYM
+// RUN: llvm-objdump -d -g -dsym=%t1.dSYM %p/../../dsymutil/Inputs/basic.macho.x86_64 | FileCheck %s
+
+CHECK: Disassembly of section __TEXT,__text:
index f10f7d0..c8c63ce 100644 (file)
@@ -6947,6 +6947,7 @@ static void DisassembleMachO(StringRef Filename, MachOObjectFile *MachOOF,
 
   std::unique_ptr<DIContext> diContext;
   ObjectFile *DbgObj = MachOOF;
+  std::unique_ptr<MemoryBuffer> DSYMBuf;
   // Try to find debug info and set up the DIContext for it.
   if (UseDbg) {
     // A separate DSym file path was specified, parse it as a macho file,
@@ -6964,6 +6965,8 @@ static void DisassembleMachO(StringRef Filename, MachOObjectFile *MachOOF,
       if (DbgObjCheck.takeError())
         report_error(MachOOF->getFileName(), DbgObjCheck.takeError());
       DbgObj = DbgObjCheck.get().release();
+      // We need to keep the file alive, because we're replacing DbgObj with it.
+      DSYMBuf = std::move(BufOrErr.get());
     }
 
     // Setup the DIContext