19 import ClientIOTerminal
23 class DbgTerminal (vte
.Terminal
):
25 def __init__(self
, clientCmd
):
27 vte
.Terminal
.__init
__(self
)
33 self
.lastc
, self
.lastr
= 0,0
34 self
.gotActiveCallback
= []
35 self
.gotInactiveCallback
= []
36 self
.activityChanged
= None
39 self
.clientCmd
= clientCmd
40 #Open pseudo-terminal where to-be-debugged process reads/writes to
41 self
.client_ptymaster
, self
.client_ptyslave
= pty
.openpty()
43 #Set up terminal window and initialize debugger
44 self
.connect("cursor-moved", self
.contents_changed
)
45 self
.connect("child-exited", quitHandler
)
46 gobject
.timeout_add(50, self
.checkActivityChanged
)
49 fontdesc
= pango
.FontDescription("monospace 9")
50 self
.set_font(fontdesc
)
54 self
.childpid
= self
.fork_command( self
.getCommand(), self
.getArgv())
56 self
.setPty(self
.client_ptyslave
)
60 if self
.childpid
!= None:
62 os
.kill(self
.childpid
, 15);
65 def getClientExecuteable(self
):
66 return string
.split(self
.clientCmd
)[0]
69 def toAbsPath(self
, path
):
70 """convert path to an absolute path relative to the client
71 executable we debug."""
74 pwd
= os
.getcwd() + "/"
77 client
= self
.getClientExecuteable()
78 client
= relToAbsPath(pwd
, client
)
80 return relToAbsPath(client
, path
)
83 def checkActivityChanged(self
):
88 if self
.activityChanged
!= None:
90 res
= self
.activityChanged
91 self
.activityChanged
= None
95 print "got active: ", res
96 for cb
in self
.gotActiveCallback
:
99 print "got inactive: ", res
100 for cb
in self
.gotInactiveCallback
:
109 def contents_changed(self
, term
):
110 assert( self
.getHistoryLen()>0 )
112 c
,r
= term
.get_cursor_position()
113 text
= self
.get_text_range(self
.lastr
,0,r
,c
,lambda *w
:True)
114 self
.lastc
, self
.lastr
= c
,r
116 #Remove annoying \n at the end
117 assert(text
[-1] == "\n")
120 #Get the lines and remove empty lines
121 lines
= string
.split(text
, "\n")
123 #Remove the incomplete line
124 len = max(0,self
.getHistoryLen())
125 self
.history
[-1] = lines
[0]
126 self
.history
+= lines
[1:]
129 #Check if activity status has been changed
130 for i
in range(len, self
.getHistoryLen()):
131 line
= self
.history
[i
]
133 res
= self
.testForInactivity(i
)
135 while self
.activityChanged
!= None:
136 print "wait for pending activity"
139 self
.setActive(False)
140 self
.activityChanged
= res
142 res
= self
.testForActivity(i
)
144 while self
.activityChanged
!= None:
145 print "wait for pending activity"
149 self
.activityChanged
= res
154 def waitForNewline(self
):
155 l
= self
.getHistoryLen()
156 while not self
.getHistoryLen() > l
:
159 def getHistoryLen(self
):
160 return len(self
.history
)
162 def waitForRx(self
, pat
, start
):
167 assert( curr
>=start
)
168 for no
in range(curr
, self
.getHistoryLen()):
169 line
= self
.history
[no
]
173 #Do not forget the last line
174 curr
= max(start
,self
.getHistoryLen()-1)
175 lr
, lc
= self
.lastr
, self
.lastc
177 while (self
.lastr
, self
.lastc
) == (lr
,lc
):
181 def getCommand(self
):
182 return self
.getArgv()[0];
185 raise NotImplementedError()
187 def setPty(self
, pty
):
188 raise NotImplementedError()
191 raise NotImplementedError()
193 def setContinue(self
):
194 raise NotImplementedError()
196 def setStepover(self
):
197 raise NotImplementedError()
200 raise NotImplementedError()
203 raise NotImplementedError()
205 def setBreakpoint(self
, file, lineno
, condition
=False):
206 raise NotImplementedError()
208 def delBreakpoint(self
, breakpoint
):
209 raise NotImplementedError()
211 def getExpression(self
, expr
):
212 raise NotImplementedError()
214 def listCodeSnippet(self
):
215 raise NotImplementedError()
217 def waitForPrompt(self
, his
):
218 raise NotImplementedError()
220 def testForActivity(self
, his
):
221 raise NotImplementedError()
223 def testForInactivity(self
, his
):
224 raise NotImplementedError()
226 def setActive(self
, isactive
):
227 self
.isactive
= isactive
241 def relToAbsPath(absfile
, relfile
):
242 """When an absfile is given and a relfile is given by
243 relative paths relative to absfile, determine the abs
246 #Get directories except for "." parts
247 relsplit
= filter(lambda x
: x
!=".", string
.split(relfile
, os
.sep
))
248 #Get the directories of absfile withouth the trailing filename
249 abssplit
= string
.split(absfile
, os
.sep
)[:-1]
251 #Determine number of ".." and remove them
253 while relsplit
[0] == "..":
258 return string
.join(abssplit
+ relsplit
, os
.sep
)
261 class DbgWindow (gtk
.Window
):
266 def __init__(self
, terminal
):
269 self
.terminal
= terminal
272 gtk
.Window
.__init
__(self
)
273 self
.connect("destroy", quitHandler
)
275 #Set title and add terminal
276 self
.set_title("Debugger I/O")
277 self
.terminal
.history
= []
278 self
.terminal
.history_length
= 5
279 self
.add(self
.terminal
)
284 def toggleClientIOWindow(self
):
285 if not self
.clientIOWnd
:
286 self
.clientIOWnd
= ClientIOTerminal
.ClientIOWindow(self
, \
287 self
.terminal
.client_ptymaster
)
289 self
.clientIOWnd
.destroy()
290 self
.clientIOWnd
= None
292 def isClientIOWindowExisting(self
):
293 return self
.clientIOWnd
!= None