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 for cb
in self
.gotActiveCallback
:
79 for cb
in self
.gotInactiveCallback
:
88 def contents_changed(self
, term
):
89 assert( self
.getHistoryLen()>0 )
91 c
,r
= term
.get_cursor_position()
92 text
= self
.get_text_range(self
.lastr
,self
.lastc
,r
,c
-1,lambda *w
:True)
93 self
.lastc
, self
.lastr
= c
,r
95 #Remove annoying \n at the end
96 assert(text
[-1] == "\n")
98 #Get the lines and remove empty lines
99 lines
= string
.split(text
, "\n")
101 #Remove the incomplete line
102 len = max(0,self
.getHistoryLen()-1)
103 self
.history
[-1] += lines
[0]
104 self
.history
+= lines
[1:]
107 #Check if activity status has been changed
108 for i
in range(len, self
.getHistoryLen()):
109 line
= self
.history
[i
]
111 res
= self
.testForActivity(i
)
112 if res
!= None and not self
.isActive():
114 self
.activityChanged
= res
116 res
= self
.testForInactivity(i
)
117 if res
!= None and self
.isActive():
118 self
.setActive(False)
119 self
.activityChanged
= res
123 def waitForNewline(self
):
124 l
= self
.getHistoryLen()
125 while not self
.getHistoryLen() > l
:
128 def getHistoryLen(self
):
129 return len(self
.history
)
131 def waitForRx(self
, rx
, start
):
134 assert( curr
>=start
)
135 for no
in range(curr
, self
.getHistoryLen()):
136 line
= self
.history
[no
]
140 #Do not forget the last line
141 curr
= max(start
,self
.getHistoryLen()-1)
145 def getCommand(self
):
146 return self
.getArgv()[0];
149 raise NotImplementedError()
151 def setPty(self
, pty
):
152 raise NotImplementedError()
155 raise NotImplementedError()
157 def setContinue(self
):
158 raise NotImplementedError()
160 def setStepover(self
):
161 raise NotImplementedError()
164 raise NotImplementedError()
167 raise NotImplementedError()
169 def setBreakpoint(self
, file, lineno
, condition
=False):
170 raise NotImplementedError()
172 def delBreakpoint(self
, breakpoint
):
173 raise NotImplementedError()
175 def getExpression(self
, expr
):
176 raise NotImplementedError()
178 def waitForActivation(self
, his
):
179 raise NotImplementedError()
181 def testForActivity(self
, his
):
182 raise NotImplementedError()
184 def testForInactivity(self
, his
):
185 raise NotImplementedError()
187 def setActive(self
, isactive
):
188 self
.isactive
= isactive
203 class DbgWindow (gtk
.Window
):
208 def __init__(self
, terminal
):
211 self
.terminal
= terminal
214 gtk
.Window
.__init
__(self
)
215 self
.connect("destroy", quitHandler
)
217 #Set title and add terminal
218 self
.set_title("Debugger I/O")
219 self
.terminal
.history
= []
220 self
.terminal
.history_length
= 5
221 self
.add(self
.terminal
)
226 def toggleClientIOWindow(self
):
227 if not self
.clientIOWnd
:
228 self
.clientIOWnd
= ClientIOTerminal
.ClientIOWindow(self
, \
229 self
.terminal
.client_ptymaster
)
231 self
.clientIOWnd
.destroy()
232 self
.clientIOWnd
= None
234 def isClientIOWindowExisting(self
):
235 return self
.clientIOWnd
!= None