15 import ClientIOTerminal
19 class DbgTerminal (vte
.Terminal
):
26 def __init__(self
, clientCmd
):
28 vte
.Terminal
.__init
__(self
)
31 self
.clientCmd
= clientCmd
32 self
.fork_command( self
.getCommand(), self
.getArgv())
34 #Open pseudo-terminal where to-be-debugged process reads/writes to
35 self
.client_ptymaster
, self
.client_ptyslave
= pty
.openpty()
36 self
.setPty(self
.client_ptyslave
)
38 #Set up terminal window and initialize debugger
39 self
.connect("cursor-moved", self
.contents_changed
)
40 self
.connect("child-exited", lambda *w
: gtk
.main_quit())
42 fontdesc
= pango
.FontDescription("monospace 9")
43 self
.set_font(fontdesc
)
47 def contents_changed(self
, term
):
48 c
,r
= term
.get_cursor_position()
51 text
= self
.get_text_range(self
.lastrow
,0,r
,-1,lambda *w
:True)
53 #Remove the incomplete line
54 if self
.getHistoryLen()>0 and (len(self
.history
[-1])==0 or self
.history
[-1]!='\n') :
57 #Get the lines and remove empty lines
58 lines
= string
.split(text
, "\n")
60 #Remove last empty line...
65 self
.history
+= [l
+"\n" for l
in lines
[:-1]]
66 self
.history
+= [lines
[-1]]
70 def waitForNewline(self
):
72 while not self
.lastrow
> r
:
75 def getHistoryLen(self
):
76 return len(self
.history
)
78 def waitForRx(self
, rx
, start
=None):
81 start
= self
.getHistoryLen()
86 for no
in range(start
, self
.getHistoryLen()):
87 line
= self
.history
[no
]
91 start
= self
.getHistoryLen()
96 return self
.getArgv()[0];
99 raise NotImplementedError()
101 def setPty(self
, pty
):
102 raise NotImplementedError()
105 raise NotImplementedError()
107 def setContinue(self
):
108 raise NotImplementedError()
110 def setStepover(self
):
111 raise NotImplementedError()
114 raise NotImplementedError()
117 raise NotImplementedError()
119 def setBreakpoint(self
, file, lineno
, condition
=False):
120 raise NotImplementedError()
122 def delBreakpoint(self
, breakpoint
):
123 raise NotImplementedError()
125 def getExpression(self
, expr
):
126 raise NotImplementedError()
128 def waitForActivation(self
, his
):
129 raise NotImplementedError()
131 def setActive(self
, isactive
):
132 self
.isactive
= isactive
137 def getLastLine(self
):
138 if len(self
.history
) == 0:
141 return self
.history
[-1]
143 def feed_dbg(self
, text
):
144 self
.feed_child(text
)
151 class DbgWindow (gtk
.Window
):
156 def __init__(self
, terminal
):
159 self
.terminal
= terminal
162 gtk
.Window
.__init
__(self
)
163 self
.connect("destroy", lambda *w
: gtk
.main_quit())
165 #Set title and add terminal
166 self
.set_title("Debugger I/O")
167 self
.terminal
.history
= []
168 self
.terminal
.history_length
= 5
169 self
.add(self
.terminal
)
174 def toggleClientIOWindow(self
):
175 if not self
.clientIOWnd
:
176 self
.clientIOWnd
= ClientIOTerminal
.ClientIOWindow(self
, \
177 self
.terminal
.client_ptymaster
)
179 self
.clientIOWnd
.destroy()
180 self
.clientIOWnd
= None
182 def isClientIOWindowExisting(self
):
183 return self
.clientIOWnd
!= None
188 def launchDebugger(wnd
, term
):
190 wnd
.toggleClientIOWindow()
192 term
.setBreakpoint("main.cpp", 15)
194 res
= term
.getExpression("a")
195 print "Result = ", res