adding first vim code+
[pygdb.git] / GdbTerminal.py
1 #!/usr/bin/python
2 #shuber, 2008-06-04
3
4 __author__ = "shuber"
5
6
7 import gtk
8 import os
9 import re
10 import string
11 import sys
12 import time
13
14 import DbgTerminal
15
16
17 class GdbTerminal (DbgTerminal.DbgTerminal):
18
19
20 def __init__(self, clientCmd):
21 DbgTerminal.DbgTerminal.__init__(self, clientCmd)
22
23 def getArgv(self):
24 return ["gdb", "--fullname", string.split(self.clientCmd)[0]]
25
26 def setPty(self, pty):
27 ttyname = os.ttyname(pty)
28 self.feed_child("set inferior-tty %s\n" % (ttyname,))
29
30 def setRun(self):
31
32 his = self.getHistoryLen()
33 argv = string.join(string.split(self.clientCmd)[1:])
34 self.feed_child("run " + argv + "\n")
35 return self.waitForActivation(his)
36
37
38 def setContinue(self):
39 his = self.getHistoryLen()
40 self.feed_child("cont\n");
41 return self.waitForActivation(his)
42
43 def setStepover(self):
44 his = self.getHistoryLen()
45 self.feed_child("next\n");
46 return self.waitForActivation(his)
47
48 def setStepin(self):
49 his = self.getHistoryLen()
50 self.feed_child("step\n");
51 return self.waitForActivation(his)
52
53 def setQuit(self):
54 self.feed_child("quit\n")
55 self.waitForNewline()
56 self.feed_child("y\n");
57
58 def setBreakpoint(self, file, lineno, condition=None):
59 his = self.getHistoryLen()
60 if condition==None:
61 self.feed_child("break %s:%s\n" % (file, str(lineno)))
62 else:
63 self.feed_child("break %s:%s if %s\n" % \
64 (file, str(lineno), condition))
65
66 rx = re.compile("^Breakpoint |^No|^\(gdb\) ")
67 his, response = self.waitForRx(rx, his)
68
69 print his, response
70
71 if response[0:10] == "Breakpoint":
72 return string.split(response)[1].strip()
73 if response[0:5] == "(gdb)":
74 return None
75 if response[0:14] == "No source file":
76 self.feed_child("n\n");
77 return None
78 if response[0:3] == "No ":
79 return None
80
81 return NotImplementedError()
82
83 def delBreakpoint(self, breakpoint):
84 self.feed_child("del breakpoint %s\n" % (breakpoint,))
85
86 def getBreakpoints(self):
87 starthis = self.getHistoryLen()
88 self.feed_child("info breakpoints\n")
89
90 rx = re.compile("^\(gdb\) ")
91 endhis, response = self.waitForRx(rx, starthis)
92
93
94 rxbp1 = re.compile("^\d+\s+breakpoint")
95 rxbp2 = re.compile("^\tstop only if")
96
97 bpnts = []
98 bplines = self.history[starthis+1:endhis]
99 i = 0
100
101 #Parse the resulting lines
102 while i<len(bplines):
103 line = bplines[i]
104
105 if not rxbp1.search(line):
106 i += 1
107 continue
108
109 splits = string.split(line)
110 no = splits[0]
111 pos = splits[-1]
112 [file,lineno] = string.split(pos,":")
113 cond = None
114
115 if i+1<len(bplines) and rxbp2.search(bplines[i+1]):
116 i +=1
117 line = bplines[i]
118 pre,cond = string.split(line,"if")
119 cond = cond.strip()
120
121 bpnts += [[no, file, lineno, cond]]
122 i += 1
123
124 return bpnts
125
126
127
128 def getExpression(self, expr):
129
130 his = self.getHistoryLen()
131 self.feed_child("print " + expr + "\n")
132
133 rx = re.compile("^\(gdb\) $")
134 his, response = self.waitForRx(rx, his)
135
136 answer = self.history[his-1]
137
138 if len(string.split(answer, "=")) == 1:
139 return answer.strip()
140
141 split = string.split(answer, "=")
142 return string.join(split[1:], "=").strip()
143
144
145 def waitForActivation(self, his=None):
146
147 self.setActive(False)
148 rx = re.compile("^\(gdb\) $")
149 his, reponse = self.waitForRx(rx,his)
150 self.setActive(True)
151
152 if self.history[his-1][0:2]=="\x1a\x1a":
153 tuples = string.split(self.history[his-1][2:], ":")
154 return tuples[0:2]
155
156 return None
157
158
159
160 if __name__ == "__main__":
161
162
163 dbgterm = GdbTerminal(string.join(sys.argv[1:]))
164 dbgwnd = DbgTerminal.DbgWindow(dbgterm)
165
166 gtk.main()
167
168
169
170