Skip to content

rnestertsov/goasm-mode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

goasm-mode

An Emacs minor mode for viewing Go compiler assembly output. Generates Plan 9 pseudo-assembly scoped to the current function, with source-line-to-assembly navigation and syntax highlighting.

Features

  • Per-function assembly - Generates assembly output for the Go function at point using go build -gcflags '-S'
  • Source-to-assembly navigation - Jump the assembly view to the instructions corresponding to the current source line
  • Assembly-to-source navigation - Jump from an assembly line back to the corresponding source line
  • Jump-to-address navigation - Follow branch/jump instructions to their target offset, or jump to any byte offset manually
  • Instruction documentation - Inline eldoc hints for assembly instructions, plus d to open full documentation in a browser (x86/ARM/Go pseudo-instructions)
  • Assembly highlighting - Matching assembly lines are highlighted when navigating from source
  • Syntax highlighting - Assembly instructions, registers, hex addresses, and source references are font-locked in the output buffer
  • Auto-recompilation - Moving to a different function and navigating automatically re-generates assembly

Requirements

  • Emacs 27.1+
  • Go compiler (go on PATH)
  • A Go project with a go.mod file

Installation

Manual

Clone the repository and add it to your load path:

(add-to-list 'load-path "/path/to/goasm-mode")
(require 'goasm-mode)

use-package

(use-package goasm-mode
  :load-path "/path/to/goasm-mode"
  :hook (go-mode . goasm-minor-mode))

Usage

Enable the minor mode in a Go buffer:

M-x goasm-minor-mode

Or add it to your go-mode hook:

(add-hook 'go-mode-hook #'goasm-minor-mode)

Key Bindings

In a Go source buffer (goasm-minor-mode):

Key Command Description
C-c ! goasm-show Generate assembly for the function at point
C-c . goasm-goto-line Show assembly for the current source line (compiles automatically if needed)

In the *goasm* assembly buffer:

Key Command Description
l goasm-goto-source Jump to the source line referenced by the current assembly line
d goasm-describe-instruction Open documentation for the instruction on the current line
f goasm-follow-jump Follow the branch/jump instruction on the current line to its target
j goasm-jump-to-address Jump to an assembly line by byte offset (decimal or 0x hex)

Workflow

  1. Open a Go source file and enable goasm-minor-mode
  2. Place your cursor inside a function
  3. Press C-c . to see the assembly for the current line — assembly is compiled automatically on first use and when you move to a different function
  4. Move to other source lines and press C-c . again to jump the assembly view and highlight the matching instructions
  5. In the *goasm* buffer, press l on any assembly line to jump back to the corresponding source line
  6. Hover on any instruction to see a short description via eldoc, or press d to open full documentation in your browser
  7. On a branch/jump instruction (e.g. JMP 16, BGT 8), press f to follow it to its target offset — use C-u C-SPC to jump back
  8. Press j to jump to any byte offset by typing it (decimal or 0x hex)

You can also use C-c ! to explicitly generate assembly without navigating to a specific line.

Customization

Variable Default Description
goasm-go-command "go" Path to the Go executable
goasm-build-flags nil Additional flags passed to go build

Development

Running Tests

make test    # Run the ERT test suite
make lint    # Byte-compile and check for warnings
make clean   # Remove compiled files

License

GPL-3.0. See LICENSE for details.

Author

Roman Nestertsov

About

Emacs minor mode for displaying Go Plan9 Assembly

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors