14 import ClientIOTerminal
18 class DbgTerminal (vte
.Terminal
):
25 def __init__(self
, clientCmd
):
27 vte
.Terminal
.__init
__(self
)
30 self
.clientCmd
= clientCmd
31 self
.fork_command( self
.getCommand(), self
.getArgv())
33 #Open pseudo-terminal where to-be-debugged process reads/writes to
34 self
.client_ptymaster
, self
.client_ptyslave
= pty
.openpty()
35 self
.setPty(self
.client_ptyslave
)
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 def contents_changed(self
, term
):
43 c
,r
= term
.get_cursor_position()
46 text
= self
.get_text_range(self
.lastrow
,0,r
,-1,lambda *w
:True)
48 #Remove the incomplete line
49 if self
.getHistoryLen()>0 and (len(self
.history
[-1])==0 or self
.history
[-1]!='\n') :
52 #Get the lines and remove empty lines
53 lines
= string
.split(text
, "\n")
55 #Remove last empty line...
60 self
.history
+= [l
+"\n" for l
in lines
[:-1]]
61 self
.history
+= [lines
[-1]]
65 def waitForNewline(self
):
67 while not self
.lastrow
> r
:
70 def getHistoryLen(self
):
71 return len(self
.history
)
73 def waitForRx(self
, rx
, start
=None):
76 start
= self
.getHistoryLen()
81 for no
in range(start
, self
.getHistoryLen()):
82 line
= self
.history
[no
]
86 start
= self
.getHistoryLen()
91 return self
.getArgv()[0];
94 raise NotImplementedError()
96 def setPty(self
, pty
):
97 raise NotImplementedError()
100 raise NotImplementedError()
102 def setContinue(self
):
103 raise NotImplementedError()
105 def setStepover(self
):
106 raise NotImplementedError()
109 raise NotImplementedError()
112 raise NotImplementedError()
114 def setBreakpoint(self
, file, lineno
):
115 raise NotImplementedError()
117 def getExpression(self
, expr
):
118 raise NotImplementedError()
120 def waitForActivation(self
, his
):
121 raise NotImplementedError()
123 def setActive(self
, isactive
):
124 self
.isactive
= isactive
129 def getLastLine(self
):
130 if len(self
.history
) == 0:
133 return self
.history
[-1]
135 def feed_dbg(self
, text
):
136 self
.feed_child(text
)
143 class DbgWindow (gtk
.Window
):
148 def __init__(self
, terminal
):
151 self
.terminal
= terminal
154 gtk
.Window
.__init
__(self
)
155 self
.connect("destroy", lambda *w
: gtk
.main_quit())
157 #Set title and add terminal
158 self
.set_title("Debugger I/O")
159 self
.terminal
.history
= []
160 self
.terminal
.history_length
= 5
161 self
.add(self
.terminal
)
166 def toggleClientIOWindow(self
):
167 if not self
.clientIOWnd
:
168 self
.clientIOWnd
= ClientIOTerminal
.ClientIOWindow(self
, \
169 self
.terminal
.client_ptymaster
)
171 self
.clientIOWnd
.destroy()
172 self
.clientIOWnd
= None
174 def isClientIOWindowExisting(self
):
175 return self
.clientIOWnd
!= None
180 def launchDebugger(wnd
, term
):
182 wnd
.toggleClientIOWindow()
184 term
.setBreakpoint("main.cpp", 15)
186 res
= term
.getExpression("a")
187 print "Result = ", res