16 import ClientIOTerminal
20 class DbgTerminal (vte
.Terminal
):
22 def __init__(self
, clientCmd
):
24 vte
.Terminal
.__init
__(self
)
33 self
.clientCmd
= clientCmd
34 #Open pseudo-terminal where to-be-debugged process reads/writes to
35 self
.client_ptymaster
, self
.client_ptyslave
= pty
.openpty()
37 #Set up terminal window and initialize debugger
38 self
.connect("cursor-moved", self
.contents_changed
)
39 self
.connect("child-exited", lambda *w
: gtk
.main_quit())
42 fontdesc
= pango
.FontDescription("monospace 9")
43 self
.set_font(fontdesc
)
47 self
.childpid
= self
.fork_command( self
.getCommand(), self
.getArgv())
48 self
.setPty(self
.client_ptyslave
)
49 self
.waitForActivation()
53 if self
.childpid
!= None:
55 os
.kill(self
.childpid
, 15);
60 def contents_changed(self
, term
):
61 c
,r
= term
.get_cursor_position()
64 text
= self
.get_text_range(self
.lastrow
,0,r
,-1,lambda *w
:True)
66 #Remove the incomplete line
67 if self
.getHistoryLen()>0 and (len(self
.history
[-1])==0 or self
.history
[-1]!='\n') :
70 #Get the lines and remove empty lines
71 lines
= string
.split(text
, "\n")
73 #Remove last empty line...
78 self
.history
+= [l
+"\n" for l
in lines
[:-1]]
79 self
.history
+= [lines
[-1]]
83 def waitForNewline(self
):
85 while not self
.lastrow
> r
:
88 def getHistoryLen(self
):
89 return len(self
.history
)
91 def waitForRx(self
, rx
, start
=None):
94 start
= self
.getHistoryLen()
99 for no
in range(start
, self
.getHistoryLen()):
100 line
= self
.history
[no
]
104 start
= self
.getHistoryLen()
108 def getCommand(self
):
109 return self
.getArgv()[0];
112 raise NotImplementedError()
114 def setPty(self
, pty
):
115 raise NotImplementedError()
118 raise NotImplementedError()
120 def setContinue(self
):
121 raise NotImplementedError()
123 def setStepover(self
):
124 raise NotImplementedError()
127 raise NotImplementedError()
130 raise NotImplementedError()
132 def setBreakpoint(self
, file, lineno
, condition
=False):
133 raise NotImplementedError()
135 def delBreakpoint(self
, breakpoint
):
136 raise NotImplementedError()
138 def getExpression(self
, expr
):
139 raise NotImplementedError()
141 def waitForActivation(self
, his
):
142 raise NotImplementedError()
144 def setActive(self
, isactive
):
145 self
.isactive
= isactive
155 class DbgWindow (gtk
.Window
):
160 def __init__(self
, terminal
):
163 self
.terminal
= terminal
166 gtk
.Window
.__init
__(self
)
167 self
.connect("destroy", lambda *w
: gtk
.main_quit())
169 #Set title and add terminal
170 self
.set_title("Debugger I/O")
171 self
.terminal
.history
= []
172 self
.terminal
.history_length
= 5
173 self
.add(self
.terminal
)
178 def toggleClientIOWindow(self
):
179 if not self
.clientIOWnd
:
180 self
.clientIOWnd
= ClientIOTerminal
.ClientIOWindow(self
, \
181 self
.terminal
.client_ptymaster
)
183 self
.clientIOWnd
.destroy()
184 self
.clientIOWnd
= None
186 def isClientIOWindowExisting(self
):
187 return self
.clientIOWnd
!= None