17 import ClientIOTerminal
21 class DbgTerminal (vte
.Terminal
):
23 def __init__(self
, clientCmd
):
25 vte
.Terminal
.__init
__(self
)
31 self
.lastc
, self
.lastr
= 0,0
34 self
.clientCmd
= clientCmd
35 #Open pseudo-terminal where to-be-debugged process reads/writes to
36 self
.client_ptymaster
, self
.client_ptyslave
= pty
.openpty()
38 #Set up terminal window and initialize debugger
39 self
.connect("cursor-moved", self
.contents_changed
)
40 self
.connect("child-exited", quitHandler
)
43 fontdesc
= pango
.FontDescription("monospace 9")
44 self
.set_font(fontdesc
)
48 self
.childpid
= self
.fork_command( self
.getCommand(), self
.getArgv())
49 self
.waitForActivation(0)
50 self
.setPty(self
.client_ptyslave
)
54 if self
.childpid
!= None:
56 os
.kill(self
.childpid
, 15);
61 def contents_changed(self
, term
):
62 assert( self
.getHistoryLen()>0 )
64 c
,r
= term
.get_cursor_position()
65 text
= self
.get_text_range(self
.lastr
,self
.lastc
,r
,c
-1,lambda *w
:True)
66 self
.lastc
, self
.lastr
= c
,r
68 #Remove annoying \n at the end
69 assert(text
[-1] == "\n")
72 #Get the lines and remove empty lines
73 lines
= string
.split(text
, "\n")
76 #Remove the incomplete line
77 len = self
.getHistoryLen()
78 self
.history
[-1] += lines
[0]
79 self
.history
+= lines
[1:]
81 for l
in self
.history
[len:]:
85 def waitForNewline(self
):
86 l
= self
.getHistoryLen()
87 while not self
.getHistoryLen() > l
:
90 def getHistoryLen(self
):
91 return len(self
.history
)
93 def waitForRx(self
, rx
, start
):
97 for no
in range(curr
, self
.getHistoryLen()):
98 line
= self
.history
[no
]
102 #Do not forget the last line
103 curr
= max(start
,self
.getHistoryLen()-1)
107 def getCommand(self
):
108 return self
.getArgv()[0];
111 raise NotImplementedError()
113 def setPty(self
, pty
):
114 raise NotImplementedError()
117 raise NotImplementedError()
119 def setContinue(self
):
120 raise NotImplementedError()
122 def setStepover(self
):
123 raise NotImplementedError()
126 raise NotImplementedError()
129 raise NotImplementedError()
131 def setBreakpoint(self
, file, lineno
, condition
=False):
132 raise NotImplementedError()
134 def delBreakpoint(self
, breakpoint
):
135 raise NotImplementedError()
137 def getExpression(self
, expr
):
138 raise NotImplementedError()
140 def waitForActivation(self
, his
):
141 raise NotImplementedError()
143 def setActive(self
, isactive
):
144 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", quitHandler
)
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