14 import ClientIOTerminal
18 class DbgTerminal (vte
.Terminal
):
24 def __init__(self
, clientCmd
):
26 vte
.Terminal
.__init
__(self
)
29 self
.clientCmd
= clientCmd
30 self
.fork_command( self
.getCommand(), self
.getArgv())
32 #Open pseudo-terminal where to-be-debugged process reads/writes to
33 self
.client_ptymaster
, self
.client_ptyslave
= pty
.openpty()
34 self
.setPty(self
.client_ptyslave
)
36 #Set up terminal window and initialize debugger
37 self
.connect("cursor-moved", self
.contents_changed
)
38 self
.connect("child-exited", lambda *w
: gtk
.main_quit())
41 def contents_changed(self
, term
):
42 c
,r
= term
.get_cursor_position()
45 text
= self
.get_text_range(self
.lastrow
,0,r
,-1,lambda *w
:True)
47 #Remove the incomplete line
48 if self
.getHistoryLen()>0 and (len(self
.history
[-1])==0 or self
.history
[-1]!='\n') :
51 #Get the lines and remove empty lines
52 lines
= string
.split(text
, "\n")
54 #Remove last empty line...
59 self
.history
+= [l
+"\n" for l
in lines
[:-1]]
60 self
.history
+= [lines
[-1]]
64 def waitForNewline(self
):
66 while not self
.lastrow
> r
:
69 def getHistoryLen(self
):
70 return len(self
.history
)
72 def waitForRx(self
, rx
, start
=None):
75 start
= self
.getHistoryLen()
80 for no
in range(start
, self
.getHistoryLen()):
81 line
= self
.history
[no
]
85 start
= self
.getHistoryLen()
90 return self
.getArgv()[0];
93 raise NotImplementedError()
95 def setPty(self
, pty
):
96 raise NotImplementedError()
99 raise NotImplementedError()
101 def setContinue(self
):
102 raise NotImplementedError()
104 def setStepover(self
):
105 raise NotImplementedError()
108 raise NotImplementedError()
111 raise NotImplementedError()
113 def setBreakpoint(self
, file, lineno
):
114 raise NotImplementedError()
116 def getExpression(self
, expr
):
117 raise NotImplementedError()
119 def getLastLine(self
):
120 if len(self
.history
) == 0:
123 return self
.history
[-1]
125 def feed_dbg(self
, text
):
126 self
.feed_child(text
)
133 class DbgWindow (gtk
.Window
):
138 def __init__(self
, terminal
):
141 self
.terminal
= terminal
144 gtk
.Window
.__init
__(self
)
145 self
.connect("destroy", lambda *w
: gtk
.main_quit())
147 #Set title and add terminal
148 self
.set_title("Debugger I/O")
149 self
.terminal
.history
= []
150 self
.terminal
.history_length
= 5
151 self
.add(self
.terminal
)
156 def toggleClientIOWindow(self
):
157 if not self
.clientIOWnd
:
158 self
.clientIOWnd
= ClientIOTerminal
.ClientIOWindow(self
, \
159 self
.terminal
.client_ptymaster
)
161 self
.clientIOWnd
.destroy()
162 self
.clientIOWnd
= None
164 def isClientIOWindowExisting(self
):
165 return self
.clientIOWnd
!= None
170 def launchDebugger(wnd
, term
):
172 wnd
.toggleClientIOWindow()
174 term
.setBreakpoint("main.cpp", 15)
176 res
= term
.getExpression("a")
177 print "Result = ", res