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")
44 conf.addBreak(bp["file"], bp["lineno"], bp["cond"])
45 conf.store(".pygdb.conf")
47 vim.command("!python %s/pygdb.py %s &\n" % (pygdbdir, clientcmd))
50 def gdbToggleBreakpoint(lineno=None, file=None):
53 #Set lineno and file if not already set
55 lineno = vim.current.window.cursor[0]
57 file = getCurrentFile()
59 #Determine index of breakpoint
60 bpidx = gdbGetBreakpoint( file, lineno )
63 removeBreakpoint(bpidx)
65 addBreakpoint(file, lineno)
68 def setExecutionLine(file, lineno):
73 if file != getCurrentFile():
76 vim.command(":e %s" % file)
78 print "Warning: file '%s' does not exist! (Wrong client command?)" % file
82 vim.command(":%d" % lineno)
89 execsign = gdbNewSignnum()
90 vim.command("sign place %d line=%s name=ExecutionLine file=%s"%(execsign, lineno, file))
93 def delExecutionLine():
98 vim.command("sign unplace %d" % execsign)
102 def addBreakpoint(file, lineno, cond=None):
103 global gdbBps, cmdset
105 #If file is not open, open it
106 if not file in [b.name for b in vim.buffers]:
109 vim.command(":e %s" % file)
111 print "Warning: file '%s' does not exist! (Wrong client command?)" % file
116 #Determine a sign number
117 signnum = gdbNewSignnum()
119 #Create breakpoint and add sign
120 b = {"signnum" : signnum, "lineno" : lineno, "file" : file, "cond" : cond}
124 vim.command("sign place %(signnum)d line=%(lineno)d name=BreakPoint file=%(file)s" % b)
126 vim.command("sign place %(signnum)d line=%(lineno)d name=CondBreakPoint file=%(file)s" % b)
130 def removeBreakpoint(idx):
133 vim.command("sign unplace %(signnum)d" % gdbBps[idx])
137 def gdbBreakpointCond(lineno=None, file=None, cond=None):
140 #Set lineno and file if not already set
142 lineno = vim.current.window.cursor[0]
144 file = getCurrentFile()
146 #Determine index of breakpoint
147 bpidx = gdbGetBreakpoint( file, lineno )
151 gdbBps[bpidx]["cond"] = vim.eval("input('Breakpoint condition: ', '%s')" % gdbBps[bpidx]["cond"])
155 cond = vim.eval("input('Breakpoint condition: ', '')")
157 addBreakpoint(file, lineno, cond)
160 def getCurrentFile():
161 return vim.current.window.buffer.name
171 def gdbGetBreakpoint(file, lineno):
172 for i in range(len(gdbBps)):
173 if [gdbBps[i]["file"], gdbBps[i]["lineno"]] == [file,lineno]:
177 def gdbShowBreakpoints():
181 print "No breakpoints set."
183 print "%d breakpoints set:" % len(gdbBps)
186 if bp["cond"] != None:
187 print "%(file)s:%(lineno)d if %(cond)s" % bp
189 print "%(file)s:%(lineno)d" % bp
194 global clientcmd, cmdset
196 #Not a absolute path --> make one
197 if path[0] != os.sep:
199 #We need the client command to expand the paths...
200 while clientcmd == "" or not cmdset:
201 clientcmd = vim.eval("input('Client commando: ', '%s')" % clientcmd).strip()
204 #Get the dirs where executeable is in
205 relcmd = string.split(clientcmd)[0]
206 abscmd = DbgTerminal.relToAbsPath(getCurrentFile(), relcmd)
207 path = DbgTerminal.relToAbsPath(abscmd, path)
209 assert(path[0] == "/")
215 global clientcmd, gdbBps, cmdset
221 conf = Configuration.Configuration()
222 conf.load(".pygdb.conf")
224 #Remove all breakpoints
228 #Add breakpoints from configuration
229 for bp in conf.breakpoints:
230 bp["file"] = toAbsPath( bp["file"] )
231 addBreakpoint(bp["file"], bp["lineno"], bp["cond"])
233 #Set current execution line
234 if conf.isCurrposSet():
235 file = toAbsPath(conf.currfile)
236 setExecutionLine(file, conf.currlineno)
241 highlight ExecutionLine term=bold ctermbg=DarkGreen ctermfg=Black guibg=LightGreen guifg=Black
242 highlight BreakPoint term=inverse ctermbg=DarkRed ctermfg=Black guibg=LightRed guifg=Black
244 sign define ExecutionLine text==> texthl=ExecutionLine linehl=ExecutionLine
245 sign define BreakPoint text=! texthl=BreakPoint linehl=BreakPoint
246 sign define CondBreakPoint text=? texthl=BreakPoint linehl=BreakPoint
249 command! GDBLaunch :python gdbLaunch()
250 command! GDBToggleBreakpoint :python gdbToggleBreakpoint()
251 command! GDBBreakpointCond :python gdbBreakpointCond()
252 command! GDBShowBreakpoints :python gdbShowBreakpoints()
253 command! GDBLoadConfig :python gdbLoadConfig()
257 function! GDBMapDefaults()
258 nmap <silent> <F5> :GDBLaunch<CR>
259 nmap <silent> <F8> :GDBToggleBreakpoint<CR>
260 nmap <silent> <S-F8> :GDBBreakpointCond<CR>
261 nmap <silent> <F9> :GDBShowBreakpoints<CR>
262 nmap <silent> <S-F9> :GDBLoadConfig<CR>