new feature: selecting on breakpoint sets entry-ctrl-text
[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 def setContinue(self):
38 his = self.getHistoryLen()
39 self.feed_child("cont\n");
40 return self.waitForActivation(his)
41
42 def setStepover(self):
43 his = self.getHistoryLen()
44 self.feed_child("next\n");
45 return self.waitForActivation(his)
46
47 def setStepin(self):
48 his = self.getHistoryLen()
49 self.feed_child("step\n");
50 return self.waitForActivation(his)
51
52 def setQuit(self):
53 self.feed_child("quit\n")
54 self.waitForNewline()
55 self.feed_child("y\n");
56
57 def setBreakpoint(self, file, lineno, condition=None):
58 his = self.getHistoryLen()
59 if condition==None:
60 self.feed_child("break %s:%s\n" % (file, str(lineno)))
61 else:
62 self.feed_child("break %s:%s if %s\n" % \
63 (file, str(lineno), condition))
64
65 rx = re.compile("^Breakpoint |^No |^\(gdb\) ")
66 his, response = self.waitForRx(rx, his)
67
68 if response[0:10] == "Breakpoint":
69 return string.split(response)[1].strip()
70
71 if response[0:14] == "No source file":
72 self.feed_child("n\n");
73 return None
74
75 #Wait again for gdb
76 if response[0:5] != "(gdb)":
77 his, response = self.waitForRx(rx,his)
78
79 return None
80
81
82 def delBreakpoint(self, breakpoint):
83 self.feed_child("del breakpoint %s\n" % (breakpoint,))
84
85 def getBreakpoints(self):
86 starthis = self.getHistoryLen()
87 self.feed_child("info breakpoints\n")
88
89 rx = re.compile("^\(gdb\) ")
90 endhis, response = self.waitForRx(rx, starthis)
91
92
93 rxbp1 = re.compile("^\d+\s+breakpoint")
94 rxbp2 = re.compile("^\tstop only if")
95
96 bpnts = []
97 bplines = self.history[starthis+1:endhis]
98 i = 0
99
100 #Parse the resulting lines
101 while i<len(bplines):
102 line = bplines[i]
103
104 if not rxbp1.search(line):
105 i += 1
106 continue
107
108 splits = string.split(line)
109 no = splits[0]
110 pos = splits[-1]
111 [file,lineno] = string.split(pos,":")
112 cond = None
113
114 if i+1<len(bplines) and rxbp2.search(bplines[i+1]):
115 i +=1
116 line = bplines[i]
117 pre,cond = string.split(line,"if")
118 cond = cond.strip()
119
120 bpnts += [[no, file, lineno, cond]]
121 i += 1
122
123 return bpnts
124
125
126
127 def getExpression(self, expr):
128
129 his = self.getHistoryLen()
130 self.feed_child("print " + expr + "\n")
131
132 rx = re.compile("^\(gdb\) $")
133 his, response = self.waitForRx(rx, his)
134
135 answer = self.history[his-1]
136
137 if len(string.split(answer, "=")) == 1:
138 return answer.strip()
139
140 split = string.split(answer, "=")
141 return string.join(split[1:], "=").strip()
142
143
144 def waitForActivation(self, his=None):
145
146 self.setActive(False)
147 rx = re.compile("^\(gdb\) $")
148 his, reponse = self.waitForRx(rx,his)
149 self.setActive(True)
150
151 if self.history[his-1][0:2]=="\x1a\x1a":
152 tuples = string.split(self.history[his-1][2:], ":")
153 return tuples[0:2]
154
155 return None
156
157
158
159 if __name__ == "__main__":
160
161
162 dbgterm = GdbTerminal(string.join(sys.argv[1:]))
163 dbgwnd = DbgTerminal.DbgWindow(dbgterm)
164
165 gtk.main()
166
167
168
169