Skip to content

CLRN/gdb-disasm.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

69 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

What it is

It's a neovim plugin for interactively displaying the assembly for your source code. Some alternatives are

Why

The alternatives work with godbolt and have to essentially compile your source code to get the assembly output. This has many complications in case your code has dependencies or a nontrivial build set-up. This plugin works by disassembling the actual binary you have compiled on your environment with your build system.

Features

  • Display assembly inline using virtual text
  • Display assembly in a separate window with highlighting
  • Navigate to function calls under the cursor

Demos

Inline assembly display and toggle

inline asm

ASM in a separate window with highlighting

window asm

Auto update on the build

update asm

Jump to calls under cursor

jump to call

Diff

diff asm

Configuration

Example using cmake-tools and lazy.

  {
    "CLRN/gdb-disasm.nvim",
    config = function()
      local disasm = require "gdbdisasm"
      disasm.setup {}

      local status, cmake = pcall(require, "cmake-tools")
      if not status then
        return
      end

      local target = cmake.get_build_target()
      if target then
        disasm.set_binary_path(cmake.get_build_target_path(target))
      end

      vim.keymap.set("n", "<leader>dai", disasm.toggle_inline_disasm, { desc = "Toggle disassembly" })
      vim.keymap.set("n", "<leader>das", disasm.save_current_state, { desc = "Save current session state" })
      vim.keymap.set("n", "<leader>dal", disasm.load_saved_state, { desc = "Load saved session" })
      vim.keymap.set("n", "<leader>dar", disasm.remove_saved_state, { desc = "Remove saved session" })
      vim.keymap.set("n", "<leader>dac", disasm.resolve_calls_under_the_cursor, { desc = "Jump to a call" })
      vim.keymap.set("n", "<leader>daw", disasm.new_window_disasm, { desc = "Disassemble to new window" })
      vim.keymap.set("n", "<leader>daq", disasm.stop, { desc = "Clean disassembly and quit GDB" })
    end,
  }

You could also add mappings similar to the below to automate target path selection and auto reloading

    -- builds a cmake target and calls assembly update in the callback
    ["<leader>cb"] = {
      function()
        require("cmake-tools").build({}, function()
          require("gdbdisasm").update_asm_display()
        end)
      end,
      "Build target",
    },

    -- selects cmake target and updates the binary path
    ["<leader>ctb"] = {
      function()
        local cmake = require "cmake-tools"
        cmake.select_build_target(function()
          vim.cmd "redrawstatus"

          local target = cmake.get_build_target()
          if target then
            require("gdbdisasm").set_binary_path(cmake.get_build_target_path(target))
          end
        end)
      end,
      "Select build target",
    },

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published