6fec9f3e789f40cff60e62de2561d271ca81164e
17 import ClientIOTerminal
21 class DbgTerminal (vte
.Terminal
):
23 def __init__(self
, clientCmd
):
25 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", quitHandler
)
42 fontdesc
= pango
.FontDescription("monospace 9")
43 self
.set_font(fontdesc
)
47 self
.childpid
= self
.fork_command( self
.getCommand(), self
.getArgv())
48 self
.waitForActivation(0)
49 self
.setPty(self
.client_ptyslave
)
53 if self
.childpid
!= None:
55 os
.kill(self
.childpid
, 15);
60 def contents_changed(self
, term
):
61 assert( self
.getHistoryLen()>0 )
63 c
,r
= term
.get_cursor_position()
64 text
= self
.get_text_range(self
.getHistoryLen()-1,0,r
,-1,lambda *w
:True)
66 #Remove annoying \n at the end
67 assert(text
[-1] == "\n")
70 #Get the lines and remove empty lines
71 lines
= string
.split(text
, "\n")
73 #Remove the incomplete line
75 #Add lines to history. The last line contains no "\n" at the end!
76 self
.history
+= [l
+"\n" for l
in lines
[:-1]]
77 self
.history
+= [lines
[-1]]
79 assert(r
== self
.getHistoryLen()-1)
82 def waitForNewline(self
):
83 l
= self
.getHistoryLen()
84 while not self
.getHistoryLen() > l
:
87 def getHistoryLen(self
):
88 return len(self
.history
)
90 def waitForRx(self
, rx
, start
):
94 for no
in range(curr
, self
.getHistoryLen()):
95 line
= self
.history
[no
]
99 #Do not forget the last line
100 curr
= max(start
,self
.getHistoryLen()-1)
104 def getCommand(self
):
105 return self
.getArgv()[0];
108 raise NotImplementedError()
110 def setPty(self
, pty
):
111 raise NotImplementedError()
114 raise NotImplementedError()
116 def setContinue(self
):
117 raise NotImplementedError()
119 def setStepover(self
):
120 raise NotImplementedError()
123 raise NotImplementedError()
126 raise NotImplementedError()
128 def setBreakpoint(self
, file, lineno
, condition
=False):
129 raise NotImplementedError()
131 def delBreakpoint(self
, breakpoint
):
132 raise NotImplementedError()
134 def getExpression(self
, expr
):
135 raise NotImplementedError()
137 def waitForActivation(self
, his
):
138 raise NotImplementedError()
140 def setActive(self
, isactive
):
141 self
.isactive
= isactive
156 class DbgWindow (gtk
.Window
):
161 def __init__(self
, terminal
):
164 self
.terminal
= terminal
167 gtk
.Window
.__init
__(self
)
168 self
.connect("destroy", quitHandler
)
170 #Set title and add terminal
171 self
.set_title("Debugger I/O")
172 self
.terminal
.history
= []
173 self
.terminal
.history_length
= 5
174 self
.add(self
.terminal
)
179 def toggleClientIOWindow(self
):
180 if not self
.clientIOWnd
:
181 self
.clientIOWnd
= ClientIOTerminal
.ClientIOWindow(self
, \
182 self
.terminal
.client_ptymaster
)
184 self
.clientIOWnd
.destroy()
185 self
.clientIOWnd
= None
187 def isClientIOWindowExisting(self
):
188 return self
.clientIOWnd
!= None