X-Git-Url: https://git.sthu.org/?a=blobdiff_plain;f=pygdb.vim;h=9486db462b189d6a0ee6a326f6b82dd4c412ddf5;hb=2021af9ecfafe8d2411720329e0368d573056d68;hp=25b7fe1cada7436637d21f33aa987bfcf2931581;hpb=648f1bdb4bb69daf905ce13c57eccd327b0bf151;p=pygdb.git diff --git a/pygdb.vim b/pygdb.vim index 25b7fe1..9486db4 100644 --- a/pygdb.vim +++ b/pygdb.vim @@ -1,4 +1,11 @@ -"shuber, 2008-06-08 +"pygdb.vim - pygtk interface to gdb in connection with (g)vim +" Maintainer: Stefan Huber + + +if !has('python') + echo "Error: Required vim compiled with +python" + finish +endif if ! exists("g:pygdb") @@ -16,6 +23,7 @@ import threading import vim import Configuration +import DbgTerminal @@ -24,11 +32,20 @@ import Configuration gdbBps = [] signnum = 0 clientcmd = "" +execsign = None def gdbLaunch(): - global gdbterm, mainctrlwnd, statuswnd, gdbBps, clientcmd, gdbthread + global gdbBps, clientcmd, pygdbdir - clientcmd = vim.eval("input('Client commando: ', '%s')" % clientcmd).strip() + clientcmd = vim.eval("input('Client commando: ', '%s')" % clientcmd) + + #Pressed esq? + if clientcmd == None: + clientcmd = "" + return + + #Strip away white space + clientcmd = clientcmd.strip() if clientcmd.strip()=="": print "No command given!" @@ -37,11 +54,12 @@ def gdbLaunch(): #Add the breakpoints to the configuration conf = Configuration.Configuration() conf.load(".pygdb.conf") + conf.breakpoints = [] for bp in gdbBps: conf.addBreak(bp["file"], bp["lineno"], bp["cond"]) conf.store(".pygdb.conf") - vim.command("!python %s/pygdb.py %s &\n" % (pygdbdir, clientcmd)) + vim.command("!python %s/pygdb.py --vim-servername %s %s &\n" % (pygdbdir, vim.eval("v:servername"), clientcmd)) def gdbToggleBreakpoint(lineno=None, file=None): @@ -62,8 +80,53 @@ def gdbToggleBreakpoint(lineno=None, file=None): addBreakpoint(file, lineno) +def setExecutionLine(file, lineno): + global execsign + + + #Open that file! + if file != getCurrentFile(): + try: + os.stat(file) + vim.command(":e %s" % file) + except OSError: + print "Warning: file '%s' does not exist! (Wrong client command?)" % file + return + + #Jump to line + vim.command(":%d" % lineno) + + #Remove old execsign + if execsign != None: + delExecutionLine() + + #Set the sign + execsign = gdbNewSignnum() + vim.command("sign place %d line=%s name=ExecutionLine file=%s"%(execsign, lineno, file)) + + +def delExecutionLine(): + global execsign + + #Remove old execsign + if execsign != None: + vim.command("sign unplace %d" % execsign) + execsign = None + + def addBreakpoint(file, lineno, cond=None): - global gdbBps + global gdbBps, cmdset + + #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 + cmdset = False + return + #Determine a sign number signnum = gdbNewSignnum() @@ -141,29 +204,35 @@ def gdbShowBreakpoints(): 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] +def toAbsPath(path): + global clientcmd, cmdset + + #Not a absolute path --> make one + if path[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) + + if clientcmd == None: + clientcmd = "" + clientcmd = clientcmd.strip() - #Determine number of ".." and remove them - up=0 - while relsplit[0] == "..": - up += 1 - del relsplit[0] - del abssplit[-1] + cmdset = True - return string.join(abssplit + relsplit, os.sep) + #Get the dirs where executeable is in + relcmd = string.split(clientcmd)[0] + abscmd = DbgTerminal.relToAbsPath(getCurrentFile(), relcmd) + path = DbgTerminal.relToAbsPath(abscmd, path) + assert(path[0] == "/") + + return path def gdbLoadConfig(): - global clientcmd, gdbBps + global clientcmd, gdbBps, cmdset #Load configuration @@ -176,35 +245,30 @@ def gdbLoadConfig(): #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] == "/") - + bp["file"] = toAbsPath( bp["file"] ) addBreakpoint(bp["file"], bp["lineno"], bp["cond"]) ->> + #Set the command from config + if conf.getCommand() != None: + clientcmd = conf.getCommand() + + #Set current execution line + if conf.isCurrposSet(): + file = toAbsPath(conf.currfile) + setExecutionLine(file, conf.currlineno) + else: + delExecutionLine() +>> -highlight BreakPoint term=inverse ctermbg=DarkCyan ctermfg=Black +highlight ExecutionLine term=bold ctermbg=DarkGreen ctermfg=Black guibg=LightGreen guifg=Black +highlight BreakPoint term=inverse ctermbg=DarkRed ctermfg=Black guibg=LightRed guifg=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 - command! GDBLaunch :python gdbLaunch() command! GDBToggleBreakpoint :python gdbToggleBreakpoint() command! GDBBreakpointCond :python gdbBreakpointCond()