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!"
54 #Add the breakpoints to the configuration
55 conf = Configuration.Configuration()
56 conf.load(".pygdb.conf")
59 conf.addBreak(bp["file"], bp["lineno"], bp["cond"])
60 conf.store(".pygdb.conf")
62 vim.command("!python %s/pygdb.py --vim-servername %s %s &\n" % (pygdbdir, vim.eval("v:servername"), clientcmd))
65 def gdbToggleBreakpoint(lineno=None, file=None):
68 #Set lineno and file if not already set
70 lineno = vim.current.window.cursor[0]
72 file = getCurrentFile()
74 #Determine index of breakpoint
75 bpidx = gdbGetBreakpoint( file, lineno )
78 removeBreakpoint(bpidx)
80 addBreakpoint(file, lineno)
83 def setExecutionLine(file, lineno):
88 if file != getCurrentFile():
91 vim.command(":e %s" % file)
93 print "Warning: file '%s' does not exist! (Wrong client command?)" % file
97 vim.command(":%d" % lineno)
104 execsign = gdbNewSignnum()
105 vim.command("sign place %d line=%s name=ExecutionLine file=%s"%(execsign, lineno, file))
108 def delExecutionLine():
113 vim.command("sign unplace %d" % execsign)
117 def addBreakpoint(file, lineno, cond=None):
118 global gdbBps, cmdset
120 #If file is not open, open it
121 if not file in [b.name for b in vim.buffers]:
124 vim.command(":e %s" % file)
126 print "Warning: file '%s' does not exist! (Wrong client command?)" % file
131 #Determine a sign number
132 signnum = gdbNewSignnum()
134 #Create breakpoint and add sign
135 b = {"signnum" : signnum, "lineno" : lineno, "file" : file, "cond" : cond}
139 vim.command("sign place %(signnum)d line=%(lineno)d name=BreakPoint file=%(file)s" % b)
141 vim.command("sign place %(signnum)d line=%(lineno)d name=CondBreakPoint file=%(file)s" % b)
145 def removeBreakpoint(idx):
148 vim.command("sign unplace %(signnum)d" % gdbBps[idx])
152 def gdbBreakpointCond(lineno=None, file=None, cond=None):
155 #Set lineno and file if not already set
157 lineno = vim.current.window.cursor[0]
159 file = getCurrentFile()
161 #Determine index of breakpoint
162 bpidx = gdbGetBreakpoint( file, lineno )
166 gdbBps[bpidx]["cond"] = vim.eval("input('Breakpoint condition: ', '%s')" % gdbBps[bpidx]["cond"])
170 cond = vim.eval("input('Breakpoint condition: ', '')")
172 addBreakpoint(file, lineno, cond)
175 def getCurrentFile():
176 return vim.current.window.buffer.name
186 def gdbGetBreakpoint(file, lineno):
187 for i in range(len(gdbBps)):
188 if [gdbBps[i]["file"], gdbBps[i]["lineno"]] == [file,lineno]:
192 def gdbShowBreakpoints():
196 print "No breakpoints set."
198 print "%d breakpoints set:" % len(gdbBps)
201 if bp["cond"] != None:
202 print "%(file)s:%(lineno)d if %(cond)s" % bp
204 print "%(file)s:%(lineno)d" % bp
209 global clientcmd, cmdset
211 #Not a absolute path --> make one
212 if path[0] != os.sep:
214 #We need the client command to expand the paths...
215 while clientcmd == "" or not cmdset:
216 clientcmd = vim.eval("input('Client commando: ', '%s')" % clientcmd)
218 if clientcmd == None:
220 clientcmd = clientcmd.strip()
224 #Get the dirs where executeable is in
225 relcmd = string.split(clientcmd)[0]
226 abscmd = DbgTerminal.relToAbsPath(getCurrentFile(), relcmd)
227 path = DbgTerminal.relToAbsPath(abscmd, path)
229 assert(path[0] == "/")
235 global clientcmd, gdbBps, cmdset
239 conf = Configuration.Configuration()
240 conf.load(".pygdb.conf")
242 #Remove all breakpoints
246 #Add breakpoints from configuration
247 for bp in conf.breakpoints:
248 bp["file"] = toAbsPath( bp["file"] )
249 addBreakpoint(bp["file"], bp["lineno"], bp["cond"])
251 #Set the command from config
252 if conf.getCommand() != None:
253 clientcmd = conf.getCommand()
255 #Set current execution line
256 if conf.isCurrposSet():
257 file = toAbsPath(conf.currfile)
258 setExecutionLine(file, conf.currlineno)
264 highlight ExecutionLine term=bold ctermbg=DarkGreen ctermfg=Black guibg=LightGreen guifg=Black
265 highlight BreakPoint term=inverse ctermbg=DarkRed ctermfg=Black guibg=LightRed guifg=Black
267 sign define ExecutionLine text==> texthl=ExecutionLine linehl=ExecutionLine
268 sign define BreakPoint text=! texthl=BreakPoint linehl=BreakPoint
269 sign define CondBreakPoint text=? texthl=BreakPoint linehl=BreakPoint
272 command! GDBLaunch :python gdbLaunch()
273 command! GDBToggleBreakpoint :python gdbToggleBreakpoint()
274 command! GDBBreakpointCond :python gdbBreakpointCond()
275 command! GDBShowBreakpoints :python gdbShowBreakpoints()
276 command! GDBLoadConfig :python gdbLoadConfig()
280 function! GDBMapDefaults()
281 nmap <silent> <F5> :GDBLaunch<CR>
282 nmap <silent> <F8> :GDBToggleBreakpoint<CR>
283 nmap <silent> <S-F8> :GDBBreakpointCond<CR>
284 nmap <silent> <F9> :GDBShowBreakpoints<CR>
285 nmap <silent> <S-F9> :GDBLoadConfig<CR>