2.3 How do I use a debugger on Emacs?

By default, Emacs is compiled with debugging on, and optimizations enabled. The optimizations may interfere with some types of debugging; the debugger may not show clearly where it is, or may not be able to inspect certain variables. If this is the case, reconfigure with CFLAGS='-O0 -g3'

The file etc/DEBUG contains general debugging hints, as well as specific notes about debugging Emacs.

GDB is the GNU debugger, which can be used to debug Emacs when it has been compiled with GCC. The best results will be obtained if you start gdb from the src directory as gdb ./emacs.exe. This will load the init file .gdbinit1 in that directory, to define some extra commands for working with lisp while debugging, and set up breakpoints to catch abnormal aborts.

A Windows port of GDB is installed with MinGW64-w64 and MSYS2 (‘mingw-w64-<arch>-toolchain’ group) or can be found on MinGW download sites and on some others.


Footnotes

(1)

Latest versions of GDB might refuse to load the init file for security reasons, unless you customize GDB; alternatively, use an explicit source ./gdbinit command after entering GDB.