Skip to content

Instantly share code, notes, and snippets.

@ildus
Created March 6, 2017 08:36
Show Gist options
  • Save ildus/882271b11243a0205bbd2a3ff4e4c518 to your computer and use it in GitHub Desktop.
Save ildus/882271b11243a0205bbd2a3ff4e4c518 to your computer and use it in GitHub Desktop.
psql, gdb and vim intergration
function! MakeGdbBreak()
let path = "break ".expand('%').":".line(".")
call writefile([path], "/tmp/gdb_breaks")
echo "Created ".path
endfunction
command! -bar GDBreak call MakeGdbBreak()
nnoremap <leader>b :GDBreak<cr>
#!/usr/bin/env python3
import sys
import subprocess
import re
pid = None
for line in sys.stdin:
m = re.search('\d{1}\d+', line)
if m:
pid = int(m.group(0))
gdb_init = '''set pagination off
handle SIGUSR1 noprint nostop
handle SIGUSR2 noprint nostop
set history filename /tmp/gdb_history
set history save on
set breakpoint pending on
set print elements 0
'''
with open('/tmp/gdb_init', 'w') as f:
f.write(gdb_init)
commands = '''source /tmp/gdb_breaks
attach %s
''' % pid
with open('/tmp/gdb_commands', 'w') as f:
f.write(commands)
#urxvt --hold -e sudo gdb -ix /tmp/gdb_init -x /tmp/gdb_commands --args postgres
subprocess.Popen(['urxvt', '-e', 'sudo', 'gdb', '-ix', '/tmp/gdb_init',
'-x', '/tmp/gdb_commands', '--args', 'postgres'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment