1 "pygdb.vim - pygtk interface to gdb in connection with (g)vim
2 " Maintainer: Stefan Huber <shuber@cosy.sbg.ac.at>
6 echo "Error: Required vim compiled with +python"
10 if ! exists("g:pygdb")
13 let s:ScriptLocation = expand("<sfile>")
30 #Breakpoint positions: List of dictionaries of form
31 #{"signnum" : , "file" : , "lineno":, "cond" : }
38 global gdbBps, clientcmd, pygdbdir
40 clientcmd = vim.eval("input('Client commando: ', '%s')" % clientcmd)
47 #Strip away white space
48 clientcmd = clientcmd.strip()
50 if clientcmd.strip()=="":
51 print "No command given!"
56 vim.command("!python %s/pygdb.py --vim-servername %s %s &\n" % (pygdbdir, vim.eval("v:servername"), clientcmd))
59 def gdbToggleBreakpoint(lineno=None, file=None):
62 #Set lineno and file if not already set
64 lineno = vim.current.window.cursor[0]
66 file = getCurrentFile()
68 #Determine index of breakpoint
69 bpidx = gdbGetBreakpoint( file, lineno )
72 removeBreakpoint(bpidx)
74 addBreakpoint(file, lineno)
77 def setExecutionLine(file, lineno):
82 if file != getCurrentFile():
85 vim.command(":e %s" % file)
87 print "Warning: file '%s' does not exist! (Wrong client command?)" % file
91 vim.command(":%d" % lineno)
98 execsign = gdbNewSignnum()
99 vim.command("sign place %d line=%s name=ExecutionLine file=%s"%(execsign, lineno, file))
102 def delExecutionLine():
107 vim.command("sign unplace %d" % execsign)
111 def addBreakpoint(file, lineno, cond=None):
112 global gdbBps, cmdset
114 #If file is not open, open it
115 if not file in [b.name for b in vim.buffers]:
118 vim.command(":e %s" % file)
120 print "Warning: file '%s' does not exist! (Wrong client command?)" % file
125 #Determine a sign number
126 signnum = gdbNewSignnum()
128 #Create breakpoint and add sign
129 b = {"signnum" : signnum, "lineno" : lineno, "file" : file, "cond" : cond}
133 vim.command("sign place %(signnum)d line=%(lineno)d name=BreakPoint file=%(file)s" % b)
135 vim.command("sign place %(signnum)d line=%(lineno)d name=CondBreakPoint file=%(file)s" % b)
139 def removeBreakpoint(idx):
142 vim.command("sign unplace %(signnum)d" % gdbBps[idx])
146 def gdbBreakpointCond(lineno=None, file=None, cond=None):
149 #Set lineno and file if not already set
151 lineno = vim.current.window.cursor[0]
153 file = getCurrentFile()
155 #Determine index of breakpoint
156 bpidx = gdbGetBreakpoint( file, lineno )
160 gdbBps[bpidx]["cond"] = vim.eval("input('Breakpoint condition: ', '%s')" % gdbBps[bpidx]["cond"])
164 cond = vim.eval("input('Breakpoint condition: ', '')")
166 addBreakpoint(file, lineno, cond)
169 def getCurrentFile():
170 return vim.current.window.buffer.name
180 def gdbGetBreakpoint(file, lineno):
181 for i in range(len(gdbBps)):
182 if [gdbBps[i]["file"], gdbBps[i]["lineno"]] == [file,lineno]:
186 def gdbShowBreakpoints():
190 print "No breakpoints set."
192 print "%d breakpoints set:" % len(gdbBps)
195 if bp["cond"] != None:
196 print "%(file)s:%(lineno)d if %(cond)s" % bp
198 print "%(file)s:%(lineno)d" % bp
203 global clientcmd, cmdset
205 #Not a absolute path --> make one
206 if path[0] != os.sep:
208 #We need the client command to expand the paths...
209 while clientcmd == "" or not cmdset:
210 clientcmd = vim.eval("input('Client commando: ', '%s')" % clientcmd)
212 if clientcmd == None:
214 clientcmd = clientcmd.strip()
218 #Get the dirs where executeable is in
219 relcmd = string.split(clientcmd)[0]
220 abscmd = DbgTerminal.relToAbsPath(getCurrentFile(), relcmd)
221 path = DbgTerminal.relToAbsPath(abscmd, path)
223 assert(path[0] == "/")
229 global clientcmd, gdbBps, cmdset
233 conf = Configuration.Configuration()
234 conf.load(".pygdb.conf")
236 #Remove all breakpoints
240 #Add breakpoints from configuration
241 for bp in conf.breakpoints:
242 bp["file"] = toAbsPath( bp["file"] )
243 addBreakpoint(bp["file"], bp["lineno"], bp["cond"])
245 #Set the command from config
246 if conf.getCommand() != None:
247 clientcmd = conf.getCommand()
249 #Set current execution line
250 if conf.isCurrposSet():
251 file = toAbsPath(conf.currfile)
252 setExecutionLine(file, conf.currlineno)
257 def gdbWriteConfig():
259 #Add the breakpoints to the configuration
260 conf = Configuration.Configuration()
261 conf.load(".pygdb.conf")
262 conf.breakpoints = []
264 conf.addBreak(bp["file"], bp["lineno"], bp["cond"])
265 conf.store(".pygdb.conf")
270 highlight ExecutionLine term=bold ctermbg=DarkGreen ctermfg=Black guibg=LightGreen guifg=Black
271 highlight BreakPoint term=inverse ctermbg=DarkRed ctermfg=Black guibg=LightRed guifg=Black
273 sign define ExecutionLine text==> texthl=ExecutionLine linehl=ExecutionLine
274 sign define BreakPoint text=! texthl=BreakPoint linehl=BreakPoint
275 sign define CondBreakPoint text=? texthl=BreakPoint linehl=BreakPoint
278 command! GDBLaunch :python gdbLaunch()
279 command! GDBToggleBreakpoint :python gdbToggleBreakpoint()
280 command! GDBBreakpointCond :python gdbBreakpointCond()
281 command! GDBShowBreakpoints :python gdbShowBreakpoints()
282 command! GDBLoadConfig :python gdbLoadConfig()
286 function! GDBMapDefaults()
287 nmap <silent> <F5> :GDBLaunch<CR>
288 nmap <silent> <F8> :GDBToggleBreakpoint<CR>
289 nmap <silent> <S-F8> :GDBBreakpointCond<CR>
290 nmap <silent> <F9> :GDBShowBreakpoints<CR>
291 nmap <silent> <S-F9> :GDBLoadConfig<CR>