From cfcc39662a53b6f7a77c7ec8f05478227c5f137f Mon Sep 17 00:00:00 2001 From: Stefan Huber Date: Mon, 9 Jun 2008 12:01:24 +0200 Subject: [PATCH] - fixing ssh problem - some minor changes - added addBreakpoint function for external usage --- BreakpointsFrame.py | 36 ++++++++++++++++++++++-------------- DbgTerminal.py | 32 ++++++-------------------------- GdbTerminal.py | 28 ++++++++++++++-------------- StatusWindow.py | 9 +++++++-- pygdb.py | 5 ++--- 5 files changed, 51 insertions(+), 59 deletions(-) diff --git a/BreakpointsFrame.py b/BreakpointsFrame.py index 3216de6..9b709b4 100644 --- a/BreakpointsFrame.py +++ b/BreakpointsFrame.py @@ -92,7 +92,8 @@ class BreakpointsFrame (gtk.Frame): bpspec = self.bpEntry.get_text() - rx = re.compile("^[\w\._\-]+:\d+\s*(\sif\s+\S+.*)?$") + bpspec = bpspec.strip() + rx = re.compile("^[\w\._\-]+:\d+(\s+if\s+\S+.*)?$") #Check if format is correct if not rx.search(bpspec): @@ -115,12 +116,16 @@ class BreakpointsFrame (gtk.Frame): pos = ifsplit[0].strip() [file,lineno] = string.split(pos, ":") - pos = self.debugger.setBreakpoint(file, lineno, cond) + self.addBreakpoint(file, lineno, cond) + + + + def addBreakpoint(self, file, lineno, cond=None): - if pos!=None: - iter = self.model.append() - self.model.set(iter, 0, pos) - self.model.set(iter, 1, bpspec) + no = self.debugger.setBreakpoint(file, lineno, cond) + + if no!=None: + self.addBreakpointToList(no, file, lineno, cond) else: dialog = gtk.MessageDialog(None, \ gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, \ @@ -128,10 +133,19 @@ class BreakpointsFrame (gtk.Frame): "Invalid specification!") dialog.run() dialog.destroy() - return + def addBreakpointToList(self, no, file, lineno, cond=None): + iter = self.model.append() + self.model.set(iter, 0, no) + + if cond==None: + self.model.set(iter, 1, "%s:%s" % (str(file), str(lineno))) + else: + self.model.set(iter, 1, "%s:%s if %s" % (str(file), str(lineno), str(cond))) + + def delBtnClicked(self, btn): @@ -169,13 +183,7 @@ class BreakpointsFrame (gtk.Frame): for bp in bpnts: [no, file, lineno, cond] = bp - iter = self.model.append() - self.model.set(iter, 0, no) - - if cond==None: - self.model.set(iter, 1, "%s:%s" % (file, lineno)) - else: - self.model.set(iter, 1, "%s:%s if %s" % (file, lineno, cond)) + self.addBreakpointToList(no, file, lineno, cond) diff --git a/DbgTerminal.py b/DbgTerminal.py index 605c2b7..8cdc932 100644 --- a/DbgTerminal.py +++ b/DbgTerminal.py @@ -29,20 +29,23 @@ class DbgTerminal (vte.Terminal): #Start debugger self.clientCmd = clientCmd - self.fork_command( self.getCommand(), self.getArgv()) - #Open pseudo-terminal where to-be-debugged process reads/writes to self.client_ptymaster, self.client_ptyslave = pty.openpty() - self.setPty(self.client_ptyslave) #Set up terminal window and initialize debugger self.connect("cursor-moved", self.contents_changed) self.connect("child-exited", lambda *w: gtk.main_quit()) + #font description fontdesc = pango.FontDescription("monospace 9") self.set_font(fontdesc) + def initialize(self): + #Launch debugger + self.fork_command( self.getCommand(), self.getArgv()) + self.setPty(self.client_ptyslave) + def contents_changed(self, term): c,r = term.get_cursor_position() @@ -134,15 +137,6 @@ class DbgTerminal (vte.Terminal): def isActive(self): return self.isactive - def getLastLine(self): - if len(self.history) == 0: - return None - - return self.history[-1] - - def feed_dbg(self, text): - self.feed_child(text) - @@ -184,17 +178,3 @@ class DbgWindow (gtk.Window): - -def launchDebugger(wnd, term): - - wnd.toggleClientIOWindow() - - term.setBreakpoint("main.cpp", 15) - term.setRun() - res = term.getExpression("a") - print "Result = ", res - - term.setQuit() - - - diff --git a/GdbTerminal.py b/GdbTerminal.py index 77d21e2..496e7c3 100755 --- a/GdbTerminal.py +++ b/GdbTerminal.py @@ -25,54 +25,55 @@ class GdbTerminal (DbgTerminal.DbgTerminal): def setPty(self, pty): ttyname = os.ttyname(pty) - self.feed_dbg("set inferior-tty %s\n" % (ttyname,)) + self.feed_child("set inferior-tty %s\n" % (ttyname,)) def setRun(self): his = self.getHistoryLen() argv = string.join(string.split(self.clientCmd)[1:]) - self.feed_dbg("run " + argv + "\n") + self.feed_child("run " + argv + "\n") return self.waitForActivation(his) def setContinue(self): his = self.getHistoryLen() - self.feed_dbg("cont\n"); + self.feed_child("cont\n"); return self.waitForActivation(his) def setStepover(self): his = self.getHistoryLen() - self.feed_dbg("next\n"); + self.feed_child("next\n"); return self.waitForActivation(his) def setStepin(self): his = self.getHistoryLen() - self.feed_dbg("step\n"); + self.feed_child("step\n"); return self.waitForActivation(his) def setQuit(self): - self.feed_dbg("quit\n") + self.feed_child("quit\n") self.waitForNewline() - self.feed_dbg("y\n"); + self.feed_child("y\n"); def setBreakpoint(self, file, lineno, condition=None): his = self.getHistoryLen() if condition==None: - self.feed_dbg("break %s:%s\n" % (file, str(lineno))) + self.feed_child("break %s:%s\n" % (file, str(lineno))) else: - self.feed_dbg("break %s:%s if %s\n" % \ + self.feed_child("break %s:%s if %s\n" % \ (file, str(lineno), condition)) rx = re.compile("^Breakpoint |^No|^\(gdb\) ") his, response = self.waitForRx(rx, his) + print his, response if response[0:10] == "Breakpoint": return string.split(response)[1].strip() if response[0:5] == "(gdb)": return None if response[0:14] == "No source file": - self.feed_dbg("n\n"); + self.feed_child("n\n"); return None if response[0:3] == "No ": return None @@ -80,11 +81,11 @@ class GdbTerminal (DbgTerminal.DbgTerminal): return NotImplementedError() def delBreakpoint(self, breakpoint): - self.feed_dbg("del breakpoint %s\n" % (breakpoint,)) + self.feed_child("del breakpoint %s\n" % (breakpoint,)) def getBreakpoints(self): starthis = self.getHistoryLen() - self.feed_dbg("info breakpoints\n") + self.feed_child("info breakpoints\n") rx = re.compile("^\(gdb\) ") endhis, response = self.waitForRx(rx, starthis) @@ -128,7 +129,7 @@ class GdbTerminal (DbgTerminal.DbgTerminal): def getExpression(self, expr): his = self.getHistoryLen() - self.feed_dbg("print " + expr + "\n") + self.feed_child("print " + expr + "\n") rx = re.compile("^\(gdb\) $") his, response = self.waitForRx(rx, his) @@ -163,7 +164,6 @@ if __name__ == "__main__": dbgterm = GdbTerminal(string.join(sys.argv[1:])) dbgwnd = DbgTerminal.DbgWindow(dbgterm) - DbgTerminal.launchDebugger(dbgwnd, dbgterm) gtk.main() diff --git a/StatusWindow.py b/StatusWindow.py index 1eb4862..8614788 100644 --- a/StatusWindow.py +++ b/StatusWindow.py @@ -13,10 +13,10 @@ import BreakpointsFrame class StatusWindow (gtk.Window): - def __init__(self, parent, debugger): + def __init__(self, mainctrlwnd, debugger): gtk.Window.__init__(self) - self.set_screen(parent.get_screen()) + self.set_screen(mainctrlwnd.get_screen()) self.set_border_width(5) self.set_title("Status") @@ -24,6 +24,11 @@ class StatusWindow (gtk.Window): self.connect("destroy", lambda *w: gtk.main_quit()) + #Register callback function for new positions + self.mainctrlwnd = mainctrlwnd + mainctrlwnd.newPosCbs += [self.updateValues] + + vbox = gtk.VBox(False, 5) self.add(vbox) diff --git a/pygdb.py b/pygdb.py index 64c48df..be9ecb0 100755 --- a/pygdb.py +++ b/pygdb.py @@ -19,10 +19,9 @@ def launchDebugger(clientCmd): #Create windows mainCtrlWnd = MainControlWindow.MainControlWindow(dbgterm) statusWnd = StatusWindow.StatusWindow(mainCtrlWnd, dbgterm) + dbgterm.initialize() - #Register callback function for new positions - mainCtrlWnd.newPosCbs += [statusWnd.updateValues] - + print "run" gtk.main() -- 2.30.2