8cdc932abfbeda71402a10a1d0ddd985582e9e75
[pygdb.git] / DbgTerminal.py
1 #!/usr/bin/python
2 #shuber, 2008-06-04
3
4 __author__ = "shuber"
5
6
7 import gtk
8 import pango
9 import pty
10 import string
11 import time
12 import threading
13 import vte
14
15 import ClientIOTerminal
16
17
18
19 class DbgTerminal (vte.Terminal):
20
21 isactive = True
22 lastrow = 0
23 history = []
24
25
26 def __init__(self, clientCmd):
27
28 vte.Terminal.__init__(self)
29
30 #Start debugger
31 self.clientCmd = clientCmd
32 #Open pseudo-terminal where to-be-debugged process reads/writes to
33 self.client_ptymaster, self.client_ptyslave = pty.openpty()
34
35 #Set up terminal window and initialize debugger
36 self.connect("cursor-moved", self.contents_changed)
37 self.connect("child-exited", lambda *w: gtk.main_quit())
38
39 #font description
40 fontdesc = pango.FontDescription("monospace 9")
41 self.set_font(fontdesc)
42
43
44 def initialize(self):
45 #Launch debugger
46 self.fork_command( self.getCommand(), self.getArgv())
47 self.setPty(self.client_ptyslave)
48
49
50 def contents_changed(self, term):
51 c,r = term.get_cursor_position()
52
53 if self.lastrow <= r:
54 text = self.get_text_range(self.lastrow,0,r,-1,lambda *w:True)
55
56 #Remove the incomplete line
57 if self.getHistoryLen()>0 and (len(self.history[-1])==0 or self.history[-1]!='\n') :
58 del self.history[-1]
59
60 #Get the lines and remove empty lines
61 lines = string.split(text, "\n")
62
63 #Remove last empty line...
64 if lines[-1] == "":
65 del lines[-1]
66
67 #Add lines to history
68 self.history += [l+"\n" for l in lines[:-1]]
69 self.history += [lines[-1]]
70 self.lastrow = r
71
72
73 def waitForNewline(self):
74 r = self.lastrow
75 while not self.lastrow > r:
76 gtk.main_iteration()
77
78 def getHistoryLen(self):
79 return len(self.history)
80
81 def waitForRx(self, rx, start=None):
82
83 if start == None:
84 start = self.getHistoryLen()
85 if start < 0:
86 start = 0
87
88 while True:
89 for no in range(start, self.getHistoryLen()):
90 line = self.history[no]
91 if rx.search(line):
92 return no, line
93
94 start = self.getHistoryLen()
95 gtk.main_iteration()
96
97
98 def getCommand(self):
99 return self.getArgv()[0];
100
101 def getArgv(self):
102 raise NotImplementedError()
103
104 def setPty(self, pty):
105 raise NotImplementedError()
106
107 def setRun(self):
108 raise NotImplementedError()
109
110 def setContinue(self):
111 raise NotImplementedError()
112
113 def setStepover(self):
114 raise NotImplementedError()
115
116 def setStepin(self):
117 raise NotImplementedError()
118
119 def setQuit(self):
120 raise NotImplementedError()
121
122 def setBreakpoint(self, file, lineno, condition=False):
123 raise NotImplementedError()
124
125 def delBreakpoint(self, breakpoint):
126 raise NotImplementedError()
127
128 def getExpression(self, expr):
129 raise NotImplementedError()
130
131 def waitForActivation(self, his):
132 raise NotImplementedError()
133
134 def setActive(self, isactive):
135 self.isactive = isactive
136
137 def isActive(self):
138 return self.isactive
139
140
141
142
143
144
145 class DbgWindow (gtk.Window):
146
147 clientIOWnd = None
148
149
150 def __init__(self, terminal):
151
152 #Set up some members
153 self.terminal = terminal
154
155 #Set up GTK stuff
156 gtk.Window.__init__(self)
157 self.connect("destroy", lambda *w: gtk.main_quit())
158
159 #Set title and add terminal
160 self.set_title("Debugger I/O")
161 self.terminal.history = []
162 self.terminal.history_length = 5
163 self.add(self.terminal)
164
165 #Show the window
166 self.show_all()
167
168 def toggleClientIOWindow(self):
169 if not self.clientIOWnd:
170 self.clientIOWnd = ClientIOTerminal.ClientIOWindow(self, \
171 self.terminal.client_ptymaster)
172 else:
173 self.clientIOWnd.destroy()
174 self.clientIOWnd = None
175
176 def isClientIOWindowExisting(self):
177 return self.clientIOWnd != None
178
179
180