[llvm] r341209 - [llvm-objdump] Keep the memory buffer from the dSYM alive when using -g -dsym

Francis Visoiu Mistrih via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 31 06:10:54 PDT 2018


Author: thegameg
Date: Fri Aug 31 06:10:54 2018
New Revision: 341209

URL: http://llvm.org/viewvc/llvm-project?rev=341209&view=rev
Log:
[llvm-objdump] Keep the memory buffer from the dSYM alive when using -g -dsym

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

Added:
    llvm/trunk/test/tools/llvm-objdump/X86/macho-disassembly-g-dsym.test
Modified:
    llvm/trunk/tools/llvm-objdump/MachODump.cpp

Added: llvm/trunk/test/tools/llvm-objdump/X86/macho-disassembly-g-dsym.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objdump/X86/macho-disassembly-g-dsym.test?rev=341209&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-objdump/X86/macho-disassembly-g-dsym.test (added)
+++ llvm/trunk/test/tools/llvm-objdump/X86/macho-disassembly-g-dsym.test Fri Aug 31 06:10:54 2018
@@ -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:

Modified: llvm/trunk/tools/llvm-objdump/MachODump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objdump/MachODump.cpp?rev=341209&r1=341208&r2=341209&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objdump/MachODump.cpp (original)
+++ llvm/trunk/tools/llvm-objdump/MachODump.cpp Fri Aug 31 06:10:54 2018
@@ -6947,6 +6947,7 @@ static void DisassembleMachO(StringRef F
 
   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 F
       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




More information about the llvm-commits mailing list