Skip to content
Snippets Groups Projects
Commit bc0e59f3 authored by Moritz Sichert's avatar Moritz Sichert
Browse files

Initial commit

parents
No related branches found
No related tags found
No related merge requests found
__pycache__/
# vim-gdb
vim-gdb integrates gdb running in `:terminal` into vim.
## Usage
Run the command `:Vimgdb [args]`, for example `:Vimgdb --args /bin/ls -l`. This
will open a new window with gdb. The current window will be used to display the
source files when gdb stops.
#!/bin/bash
export VIMGDB_DIR=$(dirname "$0")
export VIMGDB_SESSION_ID="$1"
shift
exec gdb -x "$VIMGDB_DIR/gdbinit" "$@"
python
import os
import sys
sys.path.insert(0, os.environ['VIMGDB_DIR'])
import vimgdb
end
import json
import os
import gdb
VIM_ESCAPE_SEQ_BEGIN = '\x1b]51;'
VIM_ESCAPE_SEQ_END = '\x07'
VIMGDB_SESSION_ID = os.environ['VIMGDB_SESSION_ID']
def send_vim_command(funcname, *args):
vim_args = ['call', str(funcname), list(args)]
args_str = json.dumps(vim_args)
print(VIM_ESCAPE_SEQ_BEGIN + args_str + VIM_ESCAPE_SEQ_END, end='', flush=True)
def jump_to_current_frame():
try:
frame = gdb.selected_frame()
except gdb.error:
return
if frame.type() != gdb.NORMAL_FRAME:
return
sal = frame.find_sal()
if sal is None or sal.symtab is None:
return
send_vim_command('Tapi_vimgdb_goto', VIMGDB_SESSION_ID, sal.symtab.fullname(), sal.line)
gdb.events.before_prompt.connect(jump_to_current_frame)
highlight VimgdbCurrentLine ctermbg=130 guibg=#FFE568
let s:vimgdb_dir = fnamemodify(resolve(expand('<sfile>:p')), ':h:h')
let s:next_session_id = 0
let s:sessions = {}
function! Tapi_vimgdb_goto(bufnum, arglist)
if len(a:arglist) != 3
return
endif
let session_id = a:arglist[0]
let filename = a:arglist[1]
let line = a:arglist[2]
let session = s:sessions[session_id]
" Go to source window and jump to current line
noautocmd call win_gotoid(session['source_winid'])
execute 'edit' fnameescape(filename)
execute 'normal!' line . 'G'
" Update highlighted line
if session['current_line_matchid'] != -1
call matchdelete(session['current_line_matchid'])
endif
let session['current_line_matchid'] = matchaddpos('VimgdbCurrentLine', [line])
" Switch back to debugger window
noautocmd call win_gotoid(bufwinid(a:bufnum))
endfunction
function! s:close_session(session_id)
if !has_key(s:sessions, a:session_id)
return
endif
let session = s:sessions[a:session_id]
if session['current_line_matchid'] != -1
noautocmd call win_gotoid(session['source_winid'])
call matchdelete(session['current_line_matchid'])
endif
endfunction
function! s:vimgdb(mods, gdb_args)
let session_id = s:next_session_id
let s:next_session_id = s:next_session_id + 1
let s:sessions[session_id] = {'source_winid': win_getid(), 'current_line_matchid': -1}
execute a:mods 'terminal' '++close' s:vimgdb_dir . '/gdb/gdb-wrapper' session_id a:gdb_args
execute 'autocmd BufDelete <buffer> call s:close_session(' . session_id . ')'
endfunction
command! -nargs=+ -complete=shellcmd Vimgdb call s:vimgdb('<mods>', "<args>")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment