diff --git a/gdb/.gdbinit.d/init b/gdb/.gdbinit.d/init index 62fa108..ce3539c 100644 --- a/gdb/.gdbinit.d/init +++ b/gdb/.gdbinit.d/init @@ -11,15 +11,3 @@ set mi-async on set non-stop off alias -a it = info threads - -# Adapted to use neovim from https://github.com/cyrus-and/gdb-dashboard/issues/20 -define vo -python -import os -sal = gdb.selected_frame().find_sal() -current_line = sal.line -if current_line != 0: - openInNvim = "nvr +" + str(current_line) + " " + sal.symtab.fullname() - os.system(openInNvim) -end -end diff --git a/gdb/.gdbinit.d/scripts/vo.py b/gdb/.gdbinit.d/scripts/vo.py new file mode 100644 index 0000000..ccf53cd --- /dev/null +++ b/gdb/.gdbinit.d/scripts/vo.py @@ -0,0 +1,21 @@ +# Adapted to use neovim from https://github.com/cyrus-and/gdb-dashboard/issues/20 +# Requires neovim-remote and can only be used from within neovim terminal +import os +import gdb # type: ignore + + +class OpenNvim(gdb.Command): + def __init__(self): + super().__init__("vo", gdb.COMMAND_USER) + + def complete(self, _text, _word): + return gdb.COMPLETE_SYMBOL + + def invoke(self, _args, _from_tty): + sal = gdb.selected_frame().find_sal() + current_line = sal.line + if current_line != 0: + openInNvim = "nvr +" + str(current_line) + " " + sal.symtab.fullname() + os.system(openInNvim) + +OpenNvim()