6 let s:ScriptLocation = expand("<sfile>")
23 #Breakpoint positions: List of dictionaries of form
24 #{"signnum" : , "file" : , "lineno":, "cond" : }
31 global gdbterm, mainctrlwnd, statuswnd, gdbBps, clientcmd, gdbthread
33 clientcmd = vim.eval("input('Client commando: ', '%s')" % clientcmd).strip()
35 if clientcmd.strip()=="":
36 print "No command given!"
39 #Add the breakpoints to the configuration
40 conf = Configuration.Configuration()
41 conf.load(".pygdb.conf")
43 conf.addBreak(bp["file"], bp["lineno"], bp["cond"])
44 conf.store(".pygdb.conf")
46 vim.command("!python %s/pygdb.py %s &\n" % (pygdbdir, clientcmd))
49 def gdbToggleBreakpoint(lineno=None, file=None):
52 #Set lineno and file if not already set
54 lineno = vim.current.window.cursor[0]
56 file = getCurrentFile()
58 #Determine index of breakpoint
59 bpidx = gdbGetBreakpoint( file, lineno )
62 removeBreakpoint(bpidx)
64 addBreakpoint(file, lineno)
67 def setExecutionLine(file, lineno):
72 if file != getCurrentFile():
75 vim.command(":e %s" % file)
77 print "Warning: file '%s' does not exist! (Wrong client command?)" % file
81 vim.command(":%d" % lineno)
88 execsign = gdbNewSignnum()
89 vim.command("sign place %d line=%s name=ExecutionLine file=%s"%(execsign, lineno, file))
92 def delExecutionLine():
97 vim.command("sign unplace %d" % execsign)
101 def addBreakpoint(file, lineno, cond=None):
102 global gdbBps, cmdset
104 #If file is not open, open it
105 if not file in [b.name for b in vim.buffers]:
108 vim.command(":e %s" % file)
110 print "Warning: file '%s' does not exist! (Wrong client command?)" % file
115 #Determine a sign number
116 signnum = gdbNewSignnum()
118 #Create breakpoint and add sign
119 b = {"signnum" : signnum, "lineno" : lineno, "file" : file, "cond" : cond}
123 vim.command("sign place %(signnum)d line=%(lineno)d name=BreakPoint file=%(file)s" % b)
125 vim.command("sign place %(signnum)d line=%(lineno)d name=CondBreakPoint file=%(file)s" % b)
129 def removeBreakpoint(idx):
132 vim.command("sign unplace %(signnum)d" % gdbBps[idx])
136 def gdbBreakpointCond(lineno=None, file=None, cond=None):
139 #Set lineno and file if not already set
141 lineno = vim.current.window.cursor[0]
143 file = getCurrentFile()
145 #Determine index of breakpoint
146 bpidx = gdbGetBreakpoint( file, lineno )
150 gdbBps[bpidx]["cond"] = vim.eval("input('Breakpoint condition: ', '%s')" % gdbBps[bpidx]["cond"])
154 cond = vim.eval("input('Breakpoint condition: ', '')")
156 addBreakpoint(file, lineno, cond)
159 def getCurrentFile():
160 return vim.current.window.buffer.name
170 def gdbGetBreakpoint(file, lineno):
171 for i in range(len(gdbBps)):
172 if [gdbBps[i]["file"], gdbBps[i]["lineno"]] == [file,lineno]:
176 def gdbShowBreakpoints():
180 print "No breakpoints set."
182 print "%d breakpoints set:" % len(gdbBps)
185 if bp["cond"] != None:
186 print "%(file)s:%(lineno)d if %(cond)s" % bp
188 print "%(file)s:%(lineno)d" % bp
193 global clientcmd, cmdset
195 #Not a absolute path --> make one
196 if path[0] != os.sep:
198 #We need the client command to expand the paths...
199 while clientcmd == "" or not cmdset:
200 clientcmd = vim.eval("input('Client commando: ', '%s')" % clientcmd).strip()
203 #Get the dirs where executeable is in
204 relcmd = string.split(clientcmd)[0]
205 abscmd = DbgTerminal.relToAbsPath(getCurrentFile(), relcmd)
206 path = DbgTerminal.relToAbsPath(abscmd, path)
208 assert(path[0] == "/")
214 global clientcmd, gdbBps, cmdset
220 conf = Configuration.Configuration()
221 conf.load(".pygdb.conf")
223 #Remove all breakpoints
227 #Add breakpoints from configuration
228 for bp in conf.breakpoints:
229 bp["file"] = toAbsPath( bp["file"] )
230 addBreakpoint(bp["file"], bp["lineno"], bp["cond"])
232 #Set current execution line
233 if conf.isCurrposSet():
234 file = toAbsPath(conf.currfile)
235 setExecutionLine(file, conf.currlineno)
240 highlight ExecutionLine term=bold ctermbg=DarkGreen ctermfg=Black guibg=LightGreen guifg=Black
241 highlight BreakPoint term=inverse ctermbg=DarkRed ctermfg=Black guibg=LightRed guifg=Black
243 sign define ExecutionLine text==> texthl=ExecutionLine linehl=ExecutionLine
244 sign define BreakPoint text=! texthl=BreakPoint linehl=BreakPoint
245 sign define CondBreakPoint text=? texthl=BreakPoint linehl=BreakPoint
248 command! GDBLaunch :python gdbLaunch()
249 command! GDBToggleBreakpoint :python gdbToggleBreakpoint()
250 command! GDBBreakpointCond :python gdbBreakpointCond()
251 command! GDBShowBreakpoints :python gdbShowBreakpoints()
252 command! GDBLoadConfig :python gdbLoadConfig()
256 function! GDBMapDefaults()
257 nmap <silent> <F5> :GDBLaunch<CR>
258 nmap <silent> <F8> :GDBToggleBreakpoint<CR>
259 nmap <silent> <S-F8> :GDBBreakpointCond<CR>
260 nmap <silent> <F9> :GDBShowBreakpoints<CR>
261 nmap <silent> <S-F9> :GDBLoadConfig<CR>