Subject: bug#71292: 30.0.50; macOS: .elns have no debug info

From: Gerd Möllmann <[email-masked]>
Date: Fri, 31 May 2024 15:55:43 +0200

On macOS, executables (including .dylibs (=.eln)) never not contain
debug info themselves. Debug info is instead contained in .o files, and
executables reference the .o files used to build them in a debug map.
This can be seen with, e.g.

  dsymutil --dump-debug-map

This means no .o files, no debug info.

libgccjit deletes the .o files if debug > 0, gcc-14 -g does not delete
them, the .o files are kept in some temporary directory.

I found that the following change makes libgccjit behave like gcc:

modified   lisp/emacs-lisp/comp.el
@@ -99,7 +99,7 @@ native-comp-compiler-options
   :version "28.1")

 (defcustom native-comp-driver-options
-  (cond ((eq system-type 'darwin) '("-Wl,-w"))
+  (cond ((eq system-type 'darwin) '("-Wl,-w" "-save-temps=obj"))
         ((eq system-type 'cygwin) '("-Wl,-dynamicbase")))
   "Options passed verbatim to the native compiler's back-end driver.

This does not address the generation of .dSYM bundles. The .o files in
the temp dirs will be deleted at some point by which the debug info of
an executable is lost. This can be prevented by producing a .dSYM
bundle for the executable with

  dsymutil <executable>

and keeping the .dSYM around with the executable. .dSYM bundles can be
loaded in LLDB with

  process symbols add <dsym>.

To produce .dSYMs for native lisp:

  #! /usr/bin/env zsh
  rm -rf native-lisp/**/*.dSYM
  for f in native-lisp/**/*.eln; do
    dsymutil $f
  done

I've made [email-masked] aware of this. Maybe they will change
something in the future.

Example in LLDB with native-comp-debug == 2

  frame #7: 0x000000010350db68 comp-7672a6ed-3a3b5dd7.eln`F636f6d702d2d6c696d706c6966792d626c6f636b_comp__limplify_block_0 + 1632 at comp-7672a6ed-3a3b5dd7.c:101440

and one can look at the C file.