• Stars
    star
    287
  • Rank 139,373 (Top 3 %)
  • Language
    Emacs Lisp
  • Created about 11 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Disassemble C/C++ code under cursor in Emacs

Emacs Logo

disaster.el

Disassemble C, C++ or Fortran code under cursor


License GPLv2 MELPA

Screenshot of a C example

Screenshot of a Fortran example

Disaster lets you press C-c d to see the compiled assembly code for the C, C++ or Fortran 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 cmake (if you have a compile_commands.json file) 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, then you should be able to run M-x disaster. If you want, you add the following lines to your .emacs file to register the C-c d shortcut for invoking disaster:

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

Doom Emacs

For Doom Emacs users, you can add this snippet to your packages.el.

(package! disaster
  :recipe (:host github :repo "jart/disaster"))

And this to your config.el:

(use-package! disaster
  :commands (disaster)
  :init
  ;; If you prefer viewing assembly code in `nasm-mode` instead of `asm-mode`
  (setq disaster-assembly-mode 'nasm-mode)

  (map! :localleader
        :map (c++-mode-map c-mode-map fortran-mode-map)
        :desc "Disaster" "d" #'disaster))

Customization Documentation

disaster-make-flags

Command line options to pass to make if a Makefile is found.

disaster-assembly-mode

Which mode to use to view assembly code.

disaster-cc

The command for your C compiler.

disaster-cxx

The command for your C++ compiler.

disaster-fortran

The command for your Fortran compiler.

disaster-cflags

Command line options to use when compiling C.

disaster-cxxflags

Command line options to use when compiling C++.!

disaster-fortranflags

Command line options to use when compiling Fortran.

disaster-objdump

The command name and flags for running objdump.

disaster-buffer-compiler

Buffer name to use for assembler output.

disaster-buffer-assembly

Buffer name to use for objdump assembly output.

disaster-project-root-files

List of lists of files that may indicate software project root directory. Sublist are ordered from highest to lowest precedence.

disaster-c-regexp

Regexp for C source files.

disaster-cpp-regexp

Regexp for C++ source files.

disaster-fortran-regexp

Regexp for Fortran source files.

Function and Macro Documentation

(disaster-create-compile-command-make MAKE-ROOT CWD REL-OBJ OBJ-FILEPROJ-ROOT REL-FILE FILE)

Create compile command for a Make-based project. MAKE-ROOT: path to build root, CWD: path to current source file, REL-OBJ: path to object file (relative to project root), OBJ-FILE: full path to object file (build root!) PROJ-ROOT: path to project root, REL-FILE FILE.

(disaster-create-compile-command-cmake MAKE-ROOT CWD REL-OBJ OBJ-FILEPROJ-ROOT REL-FILE)

Create compile command for a CMake-based project. MAKE-ROOT: path to build root, CWD: path to current source file, REL-OBJ: path to object file (relative to project root), OBJ-FILE: full path to object file (build root!) PROJ-ROOT: path to project root, REL-FILE FILE.

(disaster-get-object-file-path-cmake COMPILE-CMD)

Get the .o object file name from a full COMPILE-CMD.

(disaster-create-compile-command USE-CMAKE MAKE-ROOT CWD REL-OBJOBJ-FILE PROJ-ROOT REL-FILE FILE)

Create the actual compile command. USE-CMAKE: non NIL to use CMake, NIL to use Make or default compiler options, MAKE-ROOT: path to build root, CWD: path to current source file, REL-OBJ: path to object file (relative to project root), OBJ-FILE: full path to object file (build root!) PROJ-ROOT: path to project root, REL-FILE FILE.

(disaster &optional FILE LINE)

Show assembly code for current line of C/C++ file. Here's the logic path it follows:

  • Is there a complile_commands.json in this directory? Get the object file name for the current file, and run it associated command.
  • 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 -c -o bufname.o bufname.c
  • Or is this a C++ file? Run c++ -g -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. First, this will try to use (vc-root-dir) to guess the project root directory, and falls back to manual check wich works by scanning parent directories of FILE (using disaster--find-parent-dirs) for certain types of files like a .projectile file 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.

(disaster-find-build-root USE-CMAKE PROJECT-ROOT)

Find the root of build directory. USE-CMAKE: non nil to use CMake's compile_commands.json, PROJECT-ROOT: root directory of the project.


Markdown README file generated by make-readme-markdown.el

More Repositories

1

cosmopolitan

build-once run-anywhere c library
C
15,150
star
2

blink

tiniest x86-64-linux emulator
C
6,710
star
3

sectorlisp

Bootstrapping LISP in a Boot Sector
C
1,147
star
4

hiptext

Turn images into text better than caca/aalib
C++
749
star
5

gosip

Public Switched Telecommunications Network Unleashed
Go
429
star
6

bestline

ANSI Standard X3.64 Teletypewriter Command Session Library
C
349
star
7

fabulous

Print images, colors, and stylish text to the terminal with Python
Python
340
star
8

landlock-make

Sandboxing for GNU Make has never been easier
C++
178
star
9

redisbayes

Naïve Bayesian Text Classifier on Redis
Python
114
star
10

occupywallst

Stomping out capitalism, one line of code at a time
JavaScript
94
star
11

pledge

OpenBSD APIs ported to Linux userspace using SECCOMP BPF and Landlock LSM
C
80
star
12

jtckdint

C23 Checked Arithmetic
C++
61
star
13

asterisk-voicechanger

Asterisk module for adjusting pitch of voices
C
31
star
14

spandsp

C
28
star
15

tokenbucket

Atomic SWAR Token Buckets
C
27
star
16

poemy2

poemy (a poetry generator) rewritten in C++
C++
24
star
17

django-bone

Generates Django Project Skeletons Simply and Properly
JavaScript
23
star
18

swatpd

Stolen WiFi Aggregate Tunneling Protocol Dæmon (RAID your internet connections!)
C
18
star
19

zsh

Zsh patched to support Actually Portable Executables git://git.code.sf.net/p/zsh/code (upstream pending)
C
15
star
20

sofia-sip

Forked for features and packaging
C
14
star
21

blink-isystem

C++
11
star
22

includeme

Automatic C/C++ '#include' and 'using' in Emacs (WORK IN PROGRESS)
Emacs Lisp
10
star
23

justinemacs

My emacs25 text editor configuration
Emacs Lisp
9
star
24

timespan

Check if timestamp falls within specific boundaries
Python
7
star
25

js2-closure

Automatic goog.require for Closure
Emacs Lisp
5
star
26

sparkles

A decision making tool (defunct, incomplete)
JavaScript
5
star
27

web_library_example

Bootstrap Web Apps for ML Visualization
HTML
5
star
28

emacs-copilot

Large language model code completion for Emacs
Emacs Lisp
5
star
29

poemy

Poetry Generator (DEPRECATED: See poemy2)
JavaScript
4
star
30

asterisk-parrot

Annoying robot that repeats what you say on the phone
C
4
star
31

jart.github.io

4
star
32

tensorflow-makefile

C++
3
star
33

libc-test

C
3
star
34

chessy

A happy toy chess engine, just for fun :) If you want a proper chess engine, check out Stockfish.
C++
3
star
35

long-s.org

Vintage Engliſh Tranſlator
CoffeeScript
2
star
36

freeswitch

Open Source Telecommunications Platform (Unofficial Fork)
C
2
star
37

verobject

Version controlled object database on Redis
Python
1
star