18 import ClientIOTerminal
22 class DbgTerminal (vte
.Terminal
):
24 def __init__(self
, clientCmd
):
26 vte
.Terminal
.__init
__(self
)
32 self
.lastc
, self
.lastr
= 0,0
33 self
.gotActiveCallback
= []
34 self
.gotInactiveCallback
= []
35 self
.activityChanged
= None
38 self
.clientCmd
= clientCmd
39 #Open pseudo-terminal where to-be-debugged process reads/writes to
40 self
.client_ptymaster
, self
.client_ptyslave
= pty
.openpty()
42 #Set up terminal window and initialize debugger
43 self
.connect("cursor-moved", self
.contents_changed
)
44 self
.connect("child-exited", quitHandler
)
45 gobject
.timeout_add(50, self
.checkActivityChanged
)
48 fontdesc
= pango
.FontDescription("monospace 9")
49 self
.set_font(fontdesc
)
53 self
.childpid
= self
.fork_command( self
.getCommand(), self
.getArgv())
54 self
.waitForActivation(0)
55 self
.setPty(self
.client_ptyslave
)
59 if self
.childpid
!= None:
61 os
.kill(self
.childpid
, 15);
64 def checkActivityChanged(self
):
69 if self
.activityChanged
!= None:
71 res
= self
.activityChanged
72 self
.activityChanged
= None
76 print "got active: ", res
77 for cb
in self
.gotActiveCallback
:
80 print "got inactive: ", res
81 for cb
in self
.gotInactiveCallback
:
90 def contents_changed(self
, term
):
91 assert( self
.getHistoryLen()>0 )
93 c
,r
= term
.get_cursor_position()
94 text
= self
.get_text_range(self
.lastr
,self
.lastc
,r
,c
-1,lambda *w
:True)
95 self
.lastc
, self
.lastr
= c
,r
97 #Remove annoying \n at the end
98 assert(text
[-1] == "\n")
100 #Get the lines and remove empty lines
101 lines
= string
.split(text
, "\n")
103 #Remove the incomplete line
104 len = max(0,self
.getHistoryLen())
105 self
.history
[-1] += lines
[0]
106 self
.history
+= lines
[1:]
109 #Check if activity status has been changed
110 for i
in range(len, self
.getHistoryLen()):
111 line
= self
.history
[i
]
113 res
= self
.testForInactivity(i
)
115 while self
.activityChanged
!= None:
116 print "wait for pending activity"
119 self
.setActive(False)
120 self
.activityChanged
= res
122 res
= self
.testForActivity(i
)
124 while self
.activityChanged
!= None:
125 print "wait for pending activity"
129 self
.activityChanged
= res
134 def waitForNewline(self
):
135 l
= self
.getHistoryLen()
136 while not self
.getHistoryLen() > l
:
139 def getHistoryLen(self
):
140 return len(self
.history
)
142 def waitForRx(self
, rx
, start
):
145 assert( curr
>=start
)
146 for no
in range(curr
, self
.getHistoryLen()):
147 line
= self
.history
[no
]
151 #Do not forget the last line
152 curr
= max(start
,self
.getHistoryLen()-1)
156 def getCommand(self
):
157 return self
.getArgv()[0];
160 raise NotImplementedError()
162 def setPty(self
, pty
):
163 raise NotImplementedError()
166 raise NotImplementedError()
168 def setContinue(self
):
169 raise NotImplementedError()
171 def setStepover(self
):
172 raise NotImplementedError()
175 raise NotImplementedError()
178 raise NotImplementedError()
180 def setBreakpoint(self
, file, lineno
, condition
=False):
181 raise NotImplementedError()
183 def delBreakpoint(self
, breakpoint
):
184 raise NotImplementedError()
186 def getExpression(self
, expr
):
187 raise NotImplementedError()
189 def waitForActivation(self
, his
):
190 raise NotImplementedError()
192 def testForActivity(self
, his
):
193 raise NotImplementedError()
195 def testForInactivity(self
, his
):
196 raise NotImplementedError()
198 def setActive(self
, isactive
):
199 self
.isactive
= isactive
214 class DbgWindow (gtk
.Window
):
219 def __init__(self
, terminal
):
222 self
.terminal
= terminal
225 gtk
.Window
.__init
__(self
)
226 self
.connect("destroy", quitHandler
)
228 #Set title and add terminal
229 self
.set_title("Debugger I/O")
230 self
.terminal
.history
= []
231 self
.terminal
.history_length
= 5
232 self
.add(self
.terminal
)
237 def toggleClientIOWindow(self
):
238 if not self
.clientIOWnd
:
239 self
.clientIOWnd
= ClientIOTerminal
.ClientIOWindow(self
, \
240 self
.terminal
.client_ptymaster
)
242 self
.clientIOWnd
.destroy()
243 self
.clientIOWnd
= None
245 def isClientIOWindowExisting(self
):
246 return self
.clientIOWnd
!= None