X-Git-Url: https://git.sthu.org/?p=pygdb.git;a=blobdiff_plain;f=pygdb.vim;h=fc03b84404d48cf050f4f1116db99c5aeec2c6f2;hp=244e6322a74d3758d349c64ca16b6a5e4b3c2bd7;hb=e25955fe11da68612055397fc0a0e652b9971377;hpb=fd54ea4a2710afa2bd51e2b8600c4577bdfccc0d diff --git a/pygdb.vim b/pygdb.vim index 244e632..fc03b84 100644 --- a/pygdb.vim +++ b/pygdb.vim @@ -9,46 +9,39 @@ let s:ScriptLocation = expand("") python << >> import gtk +import os import string import sys import threading - import vim -#Do not use a ~ for home directory -sys.path.append("/home/shuber/projekte/pygdb/") +import Configuration -import pygdb -import GdbTerminal -import MainControlWindow -import StatusWindow -#Breakpoint positions: List of dictionaries of form {"signnum" : , "file" : , "lineno":, "cond" : } +#Breakpoint positions: List of dictionaries of form +#{"signnum" : , "file" : , "lineno":, "cond" : } gdbBps = [] signnum = 0 clientcmd = "" -gdbterm = None -mainctrlwnd = None -statuswnd = None -gdbthread = None - - - def gdbLaunch(): global gdbterm, mainctrlwnd, statuswnd, gdbBps, clientcmd, gdbthread + clientcmd = vim.eval("input('Client commando: ', '%s')" % clientcmd).strip() - clientcmd = vim.eval("input('Client commando: ', '%s')" % clientcmd) - gdbterm, mainctrlwnd, statuswnd = pygdb.launchDebugger(clientcmd, False) + if clientcmd.strip()=="": + print "No command given!" + return + #Add the breakpoints to the configuration + conf = Configuration.Configuration() + conf.load(".pygdb.conf") for bp in gdbBps: - statuswnd.breakpointsFrame.addBreakpoint(bp["file"], bp["lineno"], bp["cond"]) - - print "Started dbg session." - gtk.main() - print "Finished dbg session." + conf.addBreak(bp["file"], bp["lineno"], bp["cond"]) + conf.store(".pygdb.conf") + + vim.command("!python %s/pygdb.py %s &\n" % (pygdbdir, clientcmd)) def gdbToggleBreakpoint(lineno=None, file=None): @@ -58,25 +51,49 @@ def gdbToggleBreakpoint(lineno=None, file=None): if lineno==None: lineno = vim.current.window.cursor[0] if file==None: - file = vim.current.window.buffer.name + file = getCurrentFile() #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 + + #If file is not open, open it + if not file in [b.name for b in vim.buffers]: + try: + os.stat(file) + vim.command(":e %s" % file) + except OSError: + print "Warning: file '%s' does not exist! (Wrong client command?)" % file + return + + + #Determine a sign number + signnum = gdbNewSignnum() + + #Create breakpoint and add sign + b = {"signnum" : signnum, "lineno" : lineno, "file" : file, "cond" : cond} + gdbBps += [b] - #Create breakpoint and add sign - b = {"signnum" : signnum, "lineno" : lineno, "file" : file, "cond" : None} + 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,29 +103,25 @@ def gdbBreakpointCond(lineno=None, file=None, cond=None): if lineno==None: lineno = vim.current.window.cursor[0] if file==None: - file = vim.current.window.buffer.name + file = getCurrentFile() #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(): + return vim.current.window.buffer.name + def gdbNewSignnum(): @@ -123,14 +136,82 @@ 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 + cmdset = False + 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 == "" or not cmdset: + clientcmd = vim.eval("input('Client commando: ', '%s')" % clientcmd).strip() + cmdset = True + + #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"]) >> -highlight ExecutionLine term=bold ctermbg=DarkGreen ctermfg=White highlight BreakPoint term=inverse ctermbg=DarkCyan ctermfg=Black -sign define ExecutionLine text==> texthl=ExecutionLine linehl=ExecutionLine sign define BreakPoint text=! texthl=BreakPoint linehl=BreakPoint sign define CondBreakPoint text=? texthl=BreakPoint linehl=BreakPoint @@ -139,13 +220,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