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 #Determine a sign number
69 signnum = gdbNewSignnum()
71 #Create breakpoint and add sign
72 b = {"signnum" : signnum, "lineno" : lineno, "file" : file, "cond" : cond}
76 vim.command("sign place %(signnum)d line=%(lineno)d name=BreakPoint file=%(file)s" % b)
78 vim.command("sign place %(signnum)d line=%(lineno)d name=CondBreakPoint file=%(file)s" % b)
82 def removeBreakpoint(idx):
85 vim.command("sign unplace %(signnum)d" % gdbBps[idx])
89 def gdbBreakpointCond(lineno=None, file=None, cond=None):
92 #Set lineno and file if not already set
94 lineno = vim.current.window.cursor[0]
96 file = getCurrentFile()
98 #Determine index of breakpoint
99 bpidx = gdbGetBreakpoint( file, lineno )
103 gdbBps[bpidx]["cond"] = vim.eval("input('Breakpoint condition: ', '%s')" % gdbBps[bpidx]["cond"])
107 cond = vim.eval("input('Breakpoint condition: ', '')")
109 addBreakpoint(file, lineno, cond)
112 def getCurrentFile():
113 return vim.current.window.buffer.name
123 def gdbGetBreakpoint(file, lineno):
124 for i in range(len(gdbBps)):
125 if [gdbBps[i]["file"], gdbBps[i]["lineno"]] == [file,lineno]:
129 def gdbShowBreakpoints():
133 print "No breakpoints set."
135 print "%d breakpoints set:" % len(gdbBps)
138 if bp["cond"] != None:
139 print "%(file)s:%(lineno)d if %(cond)s" % bp
141 print "%(file)s:%(lineno)d" % bp
144 def getAbsPath(absfile, relfile):
145 """When an absfile is given and a relfile is given by
146 relative paths relative to absfile, determine the abs
149 #Get directories except for "." parts
150 relsplit = filter(lambda x: x!=".", string.split(relfile, os.sep))
151 #Get the directories of absfile withouth the trailing filename
152 abssplit = string.split(absfile, os.sep)[:-1]
154 #Determine number of ".." and remove them
156 while relsplit[0] == "..":
161 return string.join(abssplit + relsplit, os.sep)
166 global clientcmd, gdbBps
170 conf = Configuration.Configuration()
171 conf.load(".pygdb.conf")
173 #Remove all breakpoints
177 #Add breakpoints from configuration
178 for bp in conf.breakpoints:
182 #Not a absolute path --> make one
183 if file[0] != os.sep:
185 #We need the client command to expand the paths...
186 while clientcmd == "":
187 clientcmd = vim.eval("input('Client commando: ', '%s')" % clientcmd).strip()
189 #Get the dirs where executeable is in
190 relcmd = string.split(clientcmd)[0]
191 abscmd = getAbsPath(getCurrentFile(), relcmd)
192 bp["file"] = file = getAbsPath(abscmd, file)
194 assert(file[0] == "/")
196 addBreakpoint(bp["file"], bp["lineno"], bp["cond"])
201 highlight BreakPoint term=inverse ctermbg=DarkCyan ctermfg=Black
203 sign define BreakPoint text=! texthl=BreakPoint linehl=BreakPoint
204 sign define CondBreakPoint text=? texthl=BreakPoint linehl=BreakPoint
208 command! GDBLaunch :python gdbLaunch()
209 command! GDBToggleBreakpoint :python gdbToggleBreakpoint()
210 command! GDBBreakpointCond :python gdbBreakpointCond()
211 command! GDBShowBreakpoints :python gdbShowBreakpoints()
212 command! GDBLoadConfig :python gdbLoadConfig()
216 function! GDBMapDefaults()
217 nmap <silent> <F5> :GDBLaunch<CR>
218 nmap <silent> <F8> :GDBToggleBreakpoint<CR>
219 nmap <silent> <S-F8> :GDBBreakpointCond<CR>
220 nmap <silent> <F9> :GDBShowBreakpoints<CR>
221 nmap <silent> <S-F9> :GDBLoadConfig<CR>