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")
75 #Remove the incomplete line
76 self
.history
[-1] += lines
[0]
77 self
.history
+= lines
[1:]
80 def waitForNewline(self
):
81 l
= self
.getHistoryLen()
82 while not self
.getHistoryLen() > l
:
85 def getHistoryLen(self
):
86 return len(self
.history
)
88 def waitForRx(self
, rx
, start
):
92 for no
in range(curr
, self
.getHistoryLen()):
93 line
= self
.history
[no
]
97 #Do not forget the last line
98 curr
= max(start
,self
.getHistoryLen()-1)
102 def getCommand(self
):
103 return self
.getArgv()[0];
106 raise NotImplementedError()
108 def setPty(self
, pty
):
109 raise NotImplementedError()
112 raise NotImplementedError()
114 def setContinue(self
):
115 raise NotImplementedError()
117 def setStepover(self
):
118 raise NotImplementedError()
121 raise NotImplementedError()
124 raise NotImplementedError()
126 def setBreakpoint(self
, file, lineno
, condition
=False):
127 raise NotImplementedError()
129 def delBreakpoint(self
, breakpoint
):
130 raise NotImplementedError()
132 def getExpression(self
, expr
):
133 raise NotImplementedError()
135 def waitForActivation(self
, his
):
136 raise NotImplementedError()
138 def setActive(self
, isactive
):
139 self
.isactive
= isactive
154 class DbgWindow (gtk
.Window
):
159 def __init__(self
, terminal
):
162 self
.terminal
= terminal
165 gtk
.Window
.__init
__(self
)
166 self
.connect("destroy", quitHandler
)
168 #Set title and add terminal
169 self
.set_title("Debugger I/O")
170 self
.terminal
.history
= []
171 self
.terminal
.history_length
= 5
172 self
.add(self
.terminal
)
177 def toggleClientIOWindow(self
):
178 if not self
.clientIOWnd
:
179 self
.clientIOWnd
= ClientIOTerminal
.ClientIOWindow(self
, \
180 self
.terminal
.client_ptymaster
)
182 self
.clientIOWnd
.destroy()
183 self
.clientIOWnd
= None
185 def isClientIOWindowExisting(self
):
186 return self
.clientIOWnd
!= None