16 import ClientIOTerminal
20 class DbgTerminal (vte
.Terminal
):
28 def __init__(self
, clientCmd
, exitcb
=None):
30 vte
.Terminal
.__init
__(self
)
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", lambda *w
: onChildExited())
47 fontdesc
= pango
.FontDescription("monospace 9")
48 self
.set_font(fontdesc
)
52 self
.childpid
= self
.fork_command( self
.getCommand(), self
.getArgv())
53 self
.setPty(self
.client_ptyslave
)
54 self
.waitForActivation()
58 if self
.childpid
!= None:
59 os
.kill(self
.childpid
, 15);
64 def contents_changed(self
, term
):
65 c
,r
= term
.get_cursor_position()
68 text
= self
.get_text_range(self
.lastrow
,0,r
,-1,lambda *w
:True)
70 #Remove the incomplete line
71 if self
.getHistoryLen()>0 and (len(self
.history
[-1])==0 or self
.history
[-1]!='\n') :
74 #Get the lines and remove empty lines
75 lines
= string
.split(text
, "\n")
77 #Remove last empty line...
82 self
.history
+= [l
+"\n" for l
in lines
[:-1]]
83 self
.history
+= [lines
[-1]]
87 def waitForNewline(self
):
89 while not self
.lastrow
> r
:
92 def getHistoryLen(self
):
93 return len(self
.history
)
95 def waitForRx(self
, rx
, start
=None):
98 start
= self
.getHistoryLen()
103 for no
in range(start
, self
.getHistoryLen()):
104 line
= self
.history
[no
]
108 start
= self
.getHistoryLen()
112 def getCommand(self
):
113 return self
.getArgv()[0];
116 raise NotImplementedError()
118 def setPty(self
, pty
):
119 raise NotImplementedError()
122 raise NotImplementedError()
124 def setContinue(self
):
125 raise NotImplementedError()
127 def setStepover(self
):
128 raise NotImplementedError()
131 raise NotImplementedError()
134 raise NotImplementedError()
136 def setBreakpoint(self
, file, lineno
, condition
=False):
137 raise NotImplementedError()
139 def delBreakpoint(self
, breakpoint
):
140 raise NotImplementedError()
142 def getExpression(self
, expr
):
143 raise NotImplementedError()
145 def waitForActivation(self
, his
):
146 raise NotImplementedError()
148 def setActive(self
, isactive
):
149 self
.isactive
= isactive
159 class DbgWindow (gtk
.Window
):
164 def __init__(self
, terminal
):
167 self
.terminal
= terminal
170 gtk
.Window
.__init
__(self
)
171 self
.connect("destroy", lambda *w
: gtk
.main_quit())
173 #Set title and add terminal
174 self
.set_title("Debugger I/O")
175 self
.terminal
.history
= []
176 self
.terminal
.history_length
= 5
177 self
.add(self
.terminal
)
182 def toggleClientIOWindow(self
):
183 if not self
.clientIOWnd
:
184 self
.clientIOWnd
= ClientIOTerminal
.ClientIOWindow(self
, \
185 self
.terminal
.client_ptymaster
)
187 self
.clientIOWnd
.destroy()
188 self
.clientIOWnd
= None
190 def isClientIOWindowExisting(self
):
191 return self
.clientIOWnd
!= None