6 let s:ScriptLocation = expand("<sfile>")
22 #Breakpoint positions: List of dictionaries of form
23 #{"signnum" : , "file" : , "lineno":, "cond" : }
30 global gdbterm, mainctrlwnd, statuswnd, gdbBps, clientcmd, gdbthread
32 clientcmd = vim.eval("input('Client commando: ', '%s')" % clientcmd).strip()
34 if clientcmd.strip()=="":
35 print "No command given!"
38 #Add the breakpoints to the configuration
39 conf = Configuration.Configuration()
40 conf.load(".pygdb.conf")
42 conf.addBreak(bp["file"], bp["lineno"], bp["cond"])
43 conf.store(".pygdb.conf")
45 vim.command("!python %s/pygdb.py %s &\n" % (pygdbdir, clientcmd))
48 def gdbToggleBreakpoint(lineno=None, file=None):
51 #Set lineno and file if not already set
53 lineno = vim.current.window.cursor[0]
55 file = getCurrentFile()
57 #Determine index of breakpoint
58 bpidx = gdbGetBreakpoint( file, lineno )
61 removeBreakpoint(bpidx)
63 addBreakpoint(file, lineno)
66 def setExecutionLine(file, lineno):
71 if file != getCurrentFile():
74 vim.command(":e %s" % file)
76 print "Warning: file '%s' does not exist! (Wrong client command?)" % file
80 vim.command(":%d" % lineno)
87 execsign = gdbNewSignnum()
88 vim.command("sign place %d line=%s name=ExecutionLine file=%s"%(execsign, lineno, file))
91 def delExecutionLine():
96 vim.command("sign unplace %d" % execsign)
100 def addBreakpoint(file, lineno, cond=None):
101 global gdbBps, cmdset
103 #If file is not open, open it
104 if not file in [b.name for b in vim.buffers]:
107 vim.command(":e %s" % file)
109 print "Warning: file '%s' does not exist! (Wrong client command?)" % file
114 #Determine a sign number
115 signnum = gdbNewSignnum()
117 #Create breakpoint and add sign
118 b = {"signnum" : signnum, "lineno" : lineno, "file" : file, "cond" : cond}
122 vim.command("sign place %(signnum)d line=%(lineno)d name=BreakPoint file=%(file)s" % b)
124 vim.command("sign place %(signnum)d line=%(lineno)d name=CondBreakPoint file=%(file)s" % b)
128 def removeBreakpoint(idx):
131 vim.command("sign unplace %(signnum)d" % gdbBps[idx])
135 def gdbBreakpointCond(lineno=None, file=None, cond=None):
138 #Set lineno and file if not already set
140 lineno = vim.current.window.cursor[0]
142 file = getCurrentFile()
144 #Determine index of breakpoint
145 bpidx = gdbGetBreakpoint( file, lineno )
149 gdbBps[bpidx]["cond"] = vim.eval("input('Breakpoint condition: ', '%s')" % gdbBps[bpidx]["cond"])
153 cond = vim.eval("input('Breakpoint condition: ', '')")
155 addBreakpoint(file, lineno, cond)
158 def getCurrentFile():
159 return vim.current.window.buffer.name
169 def gdbGetBreakpoint(file, lineno):
170 for i in range(len(gdbBps)):
171 if [gdbBps[i]["file"], gdbBps[i]["lineno"]] == [file,lineno]:
175 def gdbShowBreakpoints():
179 print "No breakpoints set."
181 print "%d breakpoints set:" % len(gdbBps)
184 if bp["cond"] != None:
185 print "%(file)s:%(lineno)d if %(cond)s" % bp
187 print "%(file)s:%(lineno)d" % bp
190 def getAbsPath(absfile, relfile):
191 """When an absfile is given and a relfile is given by
192 relative paths relative to absfile, determine the abs
195 #Get directories except for "." parts
196 relsplit = filter(lambda x: x!=".", string.split(relfile, os.sep))
197 #Get the directories of absfile withouth the trailing filename
198 abssplit = string.split(absfile, os.sep)[:-1]
200 #Determine number of ".." and remove them
202 while relsplit[0] == "..":
207 return string.join(abssplit + relsplit, os.sep)
210 #Change to absolute path
212 global clientcmd, cmdset
214 #Not a absolute path --> make one
215 if path[0] != os.sep:
217 #We need the client command to expand the paths...
218 while clientcmd == "" or not cmdset:
219 clientcmd = vim.eval("input('Client commando: ', '%s')" % clientcmd).strip()
222 #Get the dirs where executeable is in
223 relcmd = string.split(clientcmd)[0]
224 abscmd = getAbsPath(getCurrentFile(), relcmd)
225 path = getAbsPath(abscmd, path)
227 assert(path[0] == "/")
233 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 current execution line
252 if conf.isCurrposSet():
253 file = toAbsPath(conf.currfile)
254 setExecutionLine(file, conf.currlineno)
259 highlight ExecutionLine term=bold ctermbg=DarkGreen ctermfg=Black guibg=LightGreen guifg=Black
260 highlight BreakPoint term=inverse ctermbg=DarkRed ctermfg=Black guibg=LightRed guifg=Black
262 sign define ExecutionLine text==> texthl=ExecutionLine linehl=ExecutionLine
263 sign define BreakPoint text=! texthl=BreakPoint linehl=BreakPoint
264 sign define CondBreakPoint text=? texthl=BreakPoint linehl=BreakPoint
267 command! GDBLaunch :python gdbLaunch()
268 command! GDBToggleBreakpoint :python gdbToggleBreakpoint()
269 command! GDBBreakpointCond :python gdbBreakpointCond()
270 command! GDBShowBreakpoints :python gdbShowBreakpoints()
271 command! GDBLoadConfig :python gdbLoadConfig()
275 function! GDBMapDefaults()
276 nmap <silent> <F5> :GDBLaunch<CR>
277 nmap <silent> <F8> :GDBToggleBreakpoint<CR>
278 nmap <silent> <S-F8> :GDBBreakpointCond<CR>
279 nmap <silent> <F9> :GDBShowBreakpoints<CR>
280 nmap <silent> <S-F9> :GDBLoadConfig<CR>