[llvm] [llvm-objdump] Fix --source with --macho flag (PR #163810)

Daniel Rodríguez Troitiño via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 17 16:29:45 PDT 2025


================
@@ -7415,18 +7416,24 @@ static void DisassembleMachO(StringRef Filename, MachOObjectFile *MachOOF,
   std::unique_ptr<DIContext> diContext;
   std::unique_ptr<Binary> DSYMBinary;
   std::unique_ptr<MemoryBuffer> DSYMBuf;
-  if (UseDbg) {
-    // If 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 (const ObjectFile *DbgObj =
-            getMachODSymObject(MachOOF, Filename, DSYMBinary, DSYMBuf)) {
+  const ObjectFile *DbgObj = MachOOF;
+  if (UseDbg || PrintSource || PrintLines) {
+    // Look for debug info in external dSYM file or embedded in the object.
+    // getMachODSymObject returns MachOOF by default if no external dSYM found.
+    const ObjectFile *DSym =
+        getMachODSymObject(MachOOF, Filename, DSYMBinary, DSYMBuf);
+    if (!DSym)
+      return;
+    DbgObj = DSym;
+    if (UseDbg) {
----------------
drodriguez wrote:

Should `PrintLines` also be checked here?

The docs for `--line-numbers` say "When disassembling, display source line numbers.", while the docs for `-g` say "Print line information from debug info if available". It seems to be the same thing, except that `-g` is exclusive for the Mach-O parser. Probably they were both introduced without knowledge of each other.

https://github.com/llvm/llvm-project/pull/163810


More information about the llvm-commits mailing list