6 let s:ScriptLocation = expand("<sfile>")
22 #Breakpoint positions: List of dictionaries of form
23 #{"signnum" : , "file" : , "lineno":, "cond" : }
29 global gdbterm, mainctrlwnd, statuswnd, gdbBps, clientcmd, gdbthread
31 clientcmd = vim.eval("input('Client commando: ', '%s')" % clientcmd).strip()
33 if clientcmd.strip()=="":
34 print "No command given!"
37 #Add the breakpoints to the configuration
38 conf = Configuration.Configuration()
39 conf.load(".pygdb.conf")
41 conf.addBreak(bp["file"], bp["lineno"], bp["cond"])
42 conf.store(".pygdb.conf")
44 vim.command("!python %s/pygdb.py %s &\n" % (pygdbdir, clientcmd))
47 def gdbToggleBreakpoint(lineno=None, file=None):
50 #Set lineno and file if not already set
52 lineno = vim.current.window.cursor[0]
54 file = getCurrentFile()
56 #Determine index of breakpoint
57 bpidx = gdbGetBreakpoint( file, lineno )
60 removeBreakpoint(bpidx)
62 addBreakpoint(file, lineno)
65 def addBreakpoint(file, lineno, cond=None):
68 #If file is not open, open it
69 if not file in [b.name for b in vim.buffers]:
72 vim.command(":e %s" % file)
74 print "Warning: file '%s' does not exist! (Wrong client command?)" % file
78 #Determine a sign number
79 signnum = gdbNewSignnum()
81 #Create breakpoint and add sign
82 b = {"signnum" : signnum, "lineno" : lineno, "file" : file, "cond" : cond}
86 vim.command("sign place %(signnum)d line=%(lineno)d name=BreakPoint file=%(file)s" % b)
88 vim.command("sign place %(signnum)d line=%(lineno)d name=CondBreakPoint file=%(file)s" % b)
92 def removeBreakpoint(idx):
95 vim.command("sign unplace %(signnum)d" % gdbBps[idx])
99 def gdbBreakpointCond(lineno=None, file=None, cond=None):
102 #Set lineno and file if not already set
104 lineno = vim.current.window.cursor[0]
106 file = getCurrentFile()
108 #Determine index of breakpoint
109 bpidx = gdbGetBreakpoint( file, lineno )
113 gdbBps[bpidx]["cond"] = vim.eval("input('Breakpoint condition: ', '%s')" % gdbBps[bpidx]["cond"])
117 cond = vim.eval("input('Breakpoint condition: ', '')")
119 addBreakpoint(file, lineno, cond)
122 def getCurrentFile():
123 return vim.current.window.buffer.name
133 def gdbGetBreakpoint(file, lineno):
134 for i in range(len(gdbBps)):
135 if [gdbBps[i]["file"], gdbBps[i]["lineno"]] == [file,lineno]:
139 def gdbShowBreakpoints():
143 print "No breakpoints set."
145 print "%d breakpoints set:" % len(gdbBps)
148 if bp["cond"] != None:
149 print "%(file)s:%(lineno)d if %(cond)s" % bp
151 print "%(file)s:%(lineno)d" % bp
154 def getAbsPath(absfile, relfile):
155 """When an absfile is given and a relfile is given by
156 relative paths relative to absfile, determine the abs
159 #Get directories except for "." parts
160 relsplit = filter(lambda x: x!=".", string.split(relfile, os.sep))
161 #Get the directories of absfile withouth the trailing filename
162 abssplit = string.split(absfile, os.sep)[:-1]
164 #Determine number of ".." and remove them
166 while relsplit[0] == "..":
171 return string.join(abssplit + relsplit, os.sep)
176 global clientcmd, gdbBps
180 conf = Configuration.Configuration()
181 conf.load(".pygdb.conf")
183 #Remove all breakpoints
187 #Add breakpoints from configuration
189 for bp in conf.breakpoints:
193 #Not a absolute path --> make one
194 if file[0] != os.sep:
196 #We need the client command to expand the paths...
197 while clientcmd == "" or not cmdset:
198 clientcmd = vim.eval("input('Client commando: ', '%s')" % clientcmd).strip()
201 #Get the dirs where executeable is in
202 relcmd = string.split(clientcmd)[0]
203 abscmd = getAbsPath(getCurrentFile(), relcmd)
204 bp["file"] = file = getAbsPath(abscmd, file)
206 assert(file[0] == "/")
208 addBreakpoint(bp["file"], bp["lineno"], bp["cond"])
213 highlight BreakPoint term=inverse ctermbg=DarkCyan ctermfg=Black
215 sign define BreakPoint text=! texthl=BreakPoint linehl=BreakPoint
216 sign define CondBreakPoint text=? texthl=BreakPoint linehl=BreakPoint
220 command! GDBLaunch :python gdbLaunch()
221 command! GDBToggleBreakpoint :python gdbToggleBreakpoint()
222 command! GDBBreakpointCond :python gdbBreakpointCond()
223 command! GDBShowBreakpoints :python gdbShowBreakpoints()
224 command! GDBLoadConfig :python gdbLoadConfig()
228 function! GDBMapDefaults()
229 nmap <silent> <F5> :GDBLaunch<CR>
230 nmap <silent> <F8> :GDBToggleBreakpoint<CR>
231 nmap <silent> <S-F8> :GDBBreakpointCond<CR>
232 nmap <silent> <F9> :GDBShowBreakpoints<CR>
233 nmap <silent> <S-F9> :GDBLoadConfig<CR>