All Projects → jart → Disaster

jart / Disaster

Disassemble C/C++ code under cursor in Emacs

disaster.el – Disassemble C/C++ code under cursor in Emacs

Screenshot

Disaster lets you press C-c d to see the compiled assembly code for the C/C++ file you're currently editing. It even jumps to and highlights the line of assembly corresponding to the line beneath your cursor.

It works by creating a .o file using make (if you have a Makefile) or the default system compiler. It then runs that file through objdump to generate the human-readable assembly.

Installation

Make sure to place disaster.el somewhere in the load-path and add the following lines to your .emacs file to enable the C-c d shortcut to invoke disaster:

(add-to-list 'load-path "/PATH/TO/DISASTER")
(require 'disaster)
(define-key c-mode-base-map (kbd "C-c d") 'disaster)

Function Documentation

(disaster &optional FILE LINE)

Shows assembly code for current line of C/C++ file.

Here's the logic path it follows:

  • Is there a Makefile in this directory? Run make bufname.o.
  • Or is there a Makefile in a parent directory? Run make -C .. bufname.o.
  • Or is this a C file? Run cc -g -O3 -c -o bufname.o bufname.c
  • Or is this a C++ file? Run c++ -g -O3 -c -o bufname.o bufname.c
  • If build failed, display errors in compile-mode.
  • Run objdump inside a new window while maintaining focus.
  • Jump to line matching current line.

If FILE and LINE are not specified, the current editing location is used.

(disaster-find-project-root &optional LOOKS FILE)

General-purpose Heuristic to detect bottom directory of project.

This works by scanning parent directories of FILE (using disaster--find-parent-dirs) for certain types of files like a .git/ directory or a Makefile (which is less preferred).

The canonical structure of LOOKS is a list of lists of files to look for in each parent directory where sublists are ordered from highest precedence to lowest. However you may specify LOOKS as a single string or a list of strings for your convenience. If LOOKS is not specified, it'll default to disaster-project-root-files.


Markdown README file generated by make-readme-markdown.el
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].