From 648f1bdb4bb69daf905ce13c57eccd327b0bf151 Mon Sep 17 00:00:00 2001 From: Stefan Huber Date: Tue, 10 Jun 2008 18:24:32 +0200 Subject: [PATCH] added a vim load-config feature --- pygdb.vim | 131 ++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 103 insertions(+), 28 deletions(-) diff --git a/pygdb.vim b/pygdb.vim index fe0626f..25b7fe1 100644 --- a/pygdb.vim +++ b/pygdb.vim @@ -28,10 +28,8 @@ clientcmd = "" def gdbLaunch(): global gdbterm, mainctrlwnd, statuswnd, gdbBps, clientcmd, gdbthread - clientcmd = vim.eval("input('Client commando: ', '%s')" % clientcmd).strip() - if clientcmd.strip()=="": print "No command given!" return @@ -58,20 +56,34 @@ def gdbToggleBreakpoint(lineno=None, file=None): #Determine index of breakpoint bpidx = gdbGetBreakpoint( file, lineno ) - #Remove the breakpoint if bpidx != None: - vim.command("sign unplace %(signnum)d" % gdbBps[bpidx]) - del gdbBps[bpidx] - - #Create the breakpoint + removeBreakpoint(bpidx) else: - #Determine a sign number - signnum = gdbNewSignnum() + addBreakpoint(file, lineno) + + +def addBreakpoint(file, lineno, cond=None): + global gdbBps - #Create breakpoint and add sign - b = {"signnum" : signnum, "lineno" : lineno, "file" : file, "cond" : None} + #Determine a sign number + signnum = gdbNewSignnum() + + #Create breakpoint and add sign + b = {"signnum" : signnum, "lineno" : lineno, "file" : file, "cond" : cond} + gdbBps += [b] + + if cond == None: vim.command("sign place %(signnum)d line=%(lineno)d name=BreakPoint file=%(file)s" % b) - gdbBps += [b] + else: + vim.command("sign place %(signnum)d line=%(lineno)d name=CondBreakPoint file=%(file)s" % b) + + + +def removeBreakpoint(idx): + global gdbBps + + vim.command("sign unplace %(signnum)d" % gdbBps[idx]) + del gdbBps[idx] def gdbBreakpointCond(lineno=None, file=None, cond=None): @@ -86,24 +98,15 @@ def gdbBreakpointCond(lineno=None, file=None, cond=None): #Determine index of breakpoint bpidx = gdbGetBreakpoint( file, lineno ) - #Remove the breakpoint + #Alter condition if bpidx != None: - if cond == None: - cond = vim.eval("input('Breakpoint condition: ', '%s')" % gdbBps[bpidx]["cond"]) - gdbBps[bpidx]["cond"] = cond - + gdbBps[bpidx]["cond"] = vim.eval("input('Breakpoint condition: ', '%s')" % gdbBps[bpidx]["cond"]) + #Set new breakpoint else: - #Determine a sign number - signnum = gdbNewSignnum() - #Get condition - if cond == None: - cond = vim.eval("input('Breakpoint condition: ', '')") - - #Create breakpoint and add sign - b = {"signnum" : signnum, "lineno" : lineno, "file" : file, "cond" : cond} - vim.command("sign place %(signnum)d line=%(lineno)d name=CondBreakPoint file=%(file)s" % b) - gdbBps += [b] + cond = vim.eval("input('Breakpoint condition: ', '')") + #Add the breakpoint + addBreakpoint(file, lineno, cond) def getCurrentFile(): @@ -123,6 +126,74 @@ def gdbGetBreakpoint(file, lineno): return i return None +def gdbShowBreakpoints(): + global gdbBps + + if len(gdbBps) == 0: + print "No breakpoints set." + else: + print "%d breakpoints set:" % len(gdbBps) + + for bp in gdbBps: + if bp["cond"] != None: + print "%(file)s:%(lineno)d if %(cond)s" % bp + else: + print "%(file)s:%(lineno)d" % bp + + +def getAbsPath(absfile, relfile): + """When an absfile is given and a relfile is given by + relative paths relative to absfile, determine the abs + path of relfile""" + + #Get directories except for "." parts + relsplit = filter(lambda x: x!=".", string.split(relfile, os.sep)) + #Get the directories of absfile withouth the trailing filename + abssplit = string.split(absfile, os.sep)[:-1] + + #Determine number of ".." and remove them + up=0 + while relsplit[0] == "..": + up += 1 + del relsplit[0] + del abssplit[-1] + + return string.join(abssplit + relsplit, os.sep) + + + +def gdbLoadConfig(): + global clientcmd, gdbBps + + + #Load configuration + conf = Configuration.Configuration() + conf.load(".pygdb.conf") + + #Remove all breakpoints + while len(gdbBps)>0: + removeBreakpoint(0) + + #Add breakpoints from configuration + for bp in conf.breakpoints: + + file = bp["file"] + + #Not a absolute path --> make one + if file[0] != os.sep: + + #We need the client command to expand the paths... + while clientcmd == "": + clientcmd = vim.eval("input('Client commando: ', '%s')" % clientcmd).strip() + + #Get the dirs where executeable is in + relcmd = string.split(clientcmd)[0] + abscmd = getAbsPath(getCurrentFile(), relcmd) + bp["file"] = file = getAbsPath(abscmd, file) + + assert(file[0] == "/") + + addBreakpoint(bp["file"], bp["lineno"], bp["cond"]) >> @@ -137,13 +208,17 @@ sign define CondBreakPoint text=? texthl=BreakPoint linehl=BreakPoint command! GDBLaunch :python gdbLaunch() command! GDBToggleBreakpoint :python gdbToggleBreakpoint() command! GDBBreakpointCond :python gdbBreakpointCond() +command! GDBShowBreakpoints :python gdbShowBreakpoints() +command! GDBLoadConfig :python gdbLoadConfig() function! GDBMapDefaults() nmap :GDBLaunch nmap :GDBToggleBreakpoint - nmap :GDBBreakpointCond + nmap :GDBBreakpointCond + nmap :GDBShowBreakpoints + nmap :GDBLoadConfig endfunction -- 2.30.2