17 class DbgWindow (gtk
.Window
):
25 def __init__(self
, clientCmd
):
28 self
.clientCmd
= clientCmd
31 gtk
.Window
.__init
__(self
)
32 self
.connect("destroy", lambda *w
: gtk
.main_quit())
34 #Set title and add terminal
35 self
.set_title("Debugger I/O")
36 self
.terminal
= vte
.Terminal()
37 self
.terminal
.history
= []
38 self
.terminal
.history_length
= 5
39 self
.add(self
.terminal
)
41 #Set up terminal window and initialize debugger
42 self
.terminal
.connect("child-exited", lambda *w
: gtk
.main_quit())
43 self
.terminal
.connect("cursor-moved", self
.contents_changed
)
50 def _initializeDbg(self
):
53 self
.terminal
.fork_command( self
.getDbgCommand(), self
.getDbgArgv())
55 #Open pseudo-terminal where to-be-debugged process reads/writes to
56 self
.client_ptymaster
, self
.client_ptyslave
= pty
.openpty()
57 self
.setDbgPty(self
.client_ptyslave
)
60 def contents_changed(self
, term
):
61 c
,r
= term
.get_cursor_position()
64 text
= self
.terminal
.get_text_range(self
.lastrow
,0,r
-1,-1,lambda *w
:True)
65 self
.history
+= string
.split(text
, "\n")
68 def waitForDbgNewline(self
):
70 while not self
.lastrow
> r
:
73 def waitForDbgRx(self
, rx
):
75 start
= len(self
.history
)
78 for line
in self
.history
[start
:]:
83 def getDbgCommand(self
):
84 return self
.getDbgArgv()[0];
87 raise NotImplementedError()
89 def setDbgPty(self
, pty
):
90 raise NotImplementedError()
93 raise NotImplementedError()
96 raise NotImplementedError()
98 def setDbgContinue(self
):
99 raise NotImplementedError()
101 def setDbgBreakpoint(self
, file, lineno
):
102 raise NotImplementedError()
104 def getDbgExpression(self
, expr
):
105 raise NotImplementedError()
107 def getDbgLastLine(self
):
108 if len(self
.history
) == 0:
111 return self
.history
[-1]
113 def feed_dbg(self
, text
):
114 self
.terminal
.feed_child(text
)
117 def showClientIOWindow(self
):
118 if not self
.clientIOWnd
:
119 self
.clientIOWnd
= ClientIOWindow
.ClientIOWindow(self
, self
.client_ptymaster
)
124 def launchDebugger(wnd
):
126 wnd
.showClientIOWindow()
128 wnd
.setDbgBreakpoint("main.cpp", 15)
130 res
= wnd
.getDbgExpression("a")
131 print "Result = ", res