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
40 clientcmd = vim.eval("input('Client commando: ', '%s')" % clientcmd).strip()
42 if clientcmd.strip()=="":
43 print "No command given!"
46 #Add the breakpoints to the configuration
47 conf = Configuration.Configuration()
48 conf.load(".pygdb.conf")
51 conf.addBreak(bp["file"], bp["lineno"], bp["cond"])
52 conf.store(".pygdb.conf")
54 vim.command("!python %s/pygdb.py --vim-servername %s %s &\n" % (pygdbdir, vim.eval("v:servername"), clientcmd))
57 def gdbToggleBreakpoint(lineno=None, file=None):
60 #Set lineno and file if not already set
62 lineno = vim.current.window.cursor[0]
64 file = getCurrentFile()
66 #Determine index of breakpoint
67 bpidx = gdbGetBreakpoint( file, lineno )
70 removeBreakpoint(bpidx)
72 addBreakpoint(file, lineno)
75 def setExecutionLine(file, lineno):
80 if file != getCurrentFile():
83 vim.command(":e %s" % file)
85 print "Warning: file '%s' does not exist! (Wrong client command?)" % file
89 vim.command(":%d" % lineno)
96 execsign = gdbNewSignnum()
97 vim.command("sign place %d line=%s name=ExecutionLine file=%s"%(execsign, lineno, file))
100 def delExecutionLine():
105 vim.command("sign unplace %d" % execsign)
109 def addBreakpoint(file, lineno, cond=None):
110 global gdbBps, cmdset
112 #If file is not open, open it
113 if not file in [b.name for b in vim.buffers]:
116 vim.command(":e %s" % file)
118 print "Warning: file '%s' does not exist! (Wrong client command?)" % file
123 #Determine a sign number
124 signnum = gdbNewSignnum()
126 #Create breakpoint and add sign
127 b = {"signnum" : signnum, "lineno" : lineno, "file" : file, "cond" : cond}
131 vim.command("sign place %(signnum)d line=%(lineno)d name=BreakPoint file=%(file)s" % b)
133 vim.command("sign place %(signnum)d line=%(lineno)d name=CondBreakPoint file=%(file)s" % b)
137 def removeBreakpoint(idx):
140 vim.command("sign unplace %(signnum)d" % gdbBps[idx])
144 def gdbBreakpointCond(lineno=None, file=None, cond=None):
147 #Set lineno and file if not already set
149 lineno = vim.current.window.cursor[0]
151 file = getCurrentFile()
153 #Determine index of breakpoint
154 bpidx = gdbGetBreakpoint( file, lineno )
158 gdbBps[bpidx]["cond"] = vim.eval("input('Breakpoint condition: ', '%s')" % gdbBps[bpidx]["cond"])
162 cond = vim.eval("input('Breakpoint condition: ', '')")
164 addBreakpoint(file, lineno, cond)
167 def getCurrentFile():
168 return vim.current.window.buffer.name
178 def gdbGetBreakpoint(file, lineno):
179 for i in range(len(gdbBps)):
180 if [gdbBps[i]["file"], gdbBps[i]["lineno"]] == [file,lineno]:
184 def gdbShowBreakpoints():
188 print "No breakpoints set."
190 print "%d breakpoints set:" % len(gdbBps)
193 if bp["cond"] != None:
194 print "%(file)s:%(lineno)d if %(cond)s" % bp
196 print "%(file)s:%(lineno)d" % bp
201 global clientcmd, cmdset
203 #Not a absolute path --> make one
204 if path[0] != os.sep:
206 #We need the client command to expand the paths...
207 while clientcmd == "" or not cmdset:
208 clientcmd = vim.eval("input('Client commando: ', '%s')" % clientcmd).strip()
211 #Get the dirs where executeable is in
212 relcmd = string.split(clientcmd)[0]
213 abscmd = DbgTerminal.relToAbsPath(getCurrentFile(), relcmd)
214 path = DbgTerminal.relToAbsPath(abscmd, path)
216 assert(path[0] == "/")
222 global clientcmd, gdbBps, cmdset
226 conf = Configuration.Configuration()
227 conf.load(".pygdb.conf")
229 #Remove all breakpoints
233 #Add breakpoints from configuration
234 for bp in conf.breakpoints:
235 bp["file"] = toAbsPath( bp["file"] )
236 addBreakpoint(bp["file"], bp["lineno"], bp["cond"])
238 #Set the command from config
239 if conf.getCommand() != None:
240 clientcmd = conf.getCommand()
242 #Set current execution line
243 if conf.isCurrposSet():
244 file = toAbsPath(conf.currfile)
245 setExecutionLine(file, conf.currlineno)
251 highlight ExecutionLine term=bold ctermbg=DarkGreen ctermfg=Black guibg=LightGreen guifg=Black
252 highlight BreakPoint term=inverse ctermbg=DarkRed ctermfg=Black guibg=LightRed guifg=Black
254 sign define ExecutionLine text==> texthl=ExecutionLine linehl=ExecutionLine
255 sign define BreakPoint text=! texthl=BreakPoint linehl=BreakPoint
256 sign define CondBreakPoint text=? texthl=BreakPoint linehl=BreakPoint
259 command! GDBLaunch :python gdbLaunch()
260 command! GDBToggleBreakpoint :python gdbToggleBreakpoint()
261 command! GDBBreakpointCond :python gdbBreakpointCond()
262 command! GDBShowBreakpoints :python gdbShowBreakpoints()
263 command! GDBLoadConfig :python gdbLoadConfig()
267 function! GDBMapDefaults()
268 nmap <silent> <F5> :GDBLaunch<CR>
269 nmap <silent> <F8> :GDBToggleBreakpoint<CR>
270 nmap <silent> <S-F8> :GDBBreakpointCond<CR>
271 nmap <silent> <F9> :GDBShowBreakpoints<CR>
272 nmap <silent> <S-F9> :GDBLoadConfig<CR>