January 31, 2024

Using breakpoints in C

An easy shortcut to get a breakpoint in gdb going is by using global assembly labels.

int fun(int a, int b) {
    // do something

    asm("b:");
    // or
    asm("b: nop");

    // return something
}

The label does nothing, but it means that once gdb is open, you can simply do:

(gdb) b b

Original idea from:

In case the above does not work, please try:

Neovim shortcut

vim.api.nvim_create_autocmd({"BufNewFile", "BufRead"}, {
  group = vim.api.nvim_create_augroup("UserCAutoCommands", {clear=true}),
  pattern = '*.c',
  command = [[
    noremap <F1> :normal oasm("b: nop");<ESC> |
    noremap <F2> :g/^.*asm("b: nop").*/d<CR>
  ]]
})