7c282360501232a26a97acedbceeec10b286e50e
17 class GdbTerminal (DbgTerminal
.DbgTerminal
):
20 def __init__(self
, clientCmd
):
21 DbgTerminal
.DbgTerminal
.__init
__(self
, clientCmd
)
24 return ["gdb", "--fullname", string
.split(self
.clientCmd
)[0]]
26 def setPty(self
, pty
):
27 ttyname
= os
.ttyname(pty
)
28 his
= self
.getHistoryLen()
29 self
.feed_child("set inferior-tty %s\n" % (ttyname
,))
30 self
.waitForActivation(his
)
34 his
= self
.getHistoryLen()
35 argv
= string
.join(string
.split(self
.clientCmd
)[1:])
36 self
.feed_child("run " + argv
+ "\n")
37 return self
.waitForActivation(his
)
39 def setContinue(self
):
40 his
= self
.getHistoryLen()
41 self
.feed_child("cont\n");
42 return self
.waitForActivation(his
)
44 def setStepover(self
):
45 his
= self
.getHistoryLen()
46 self
.feed_child("next\n");
47 return self
.waitForActivation(his
)
50 his
= self
.getHistoryLen()
51 self
.feed_child("step\n");
52 return self
.waitForActivation(his
)
55 self
.feed_child("quit\n")
57 self
.feed_child("y\n");
59 def setBreakpoint(self
, file, lineno
, condition
=None):
60 his
= self
.getHistoryLen()
62 self
.feed_child("break %s:%s\n" % (file, str(lineno
)))
64 self
.feed_child("break %s:%s if %s\n" % \
65 (file, str(lineno
), condition
))
67 rx
= re
.compile("^Breakpoint |^No |^\(gdb\) ")
68 his
, response
= self
.waitForRx(rx
, his
)
72 if response
[0:10] == "Breakpoint":
73 answer
= string
.split(response
)[1].strip()
75 #Wants an answer: "No"
76 if response
[0:14] == "No source file":
77 self
.feed_child("n\n");
79 #Wait again for (gdb)...
80 self
.waitForActivation(his
)
85 def delBreakpoint(self
, breakpoint
):
86 self
.feed_child("del breakpoint %s\n" % (breakpoint
,))
88 def getBreakpoints(self
):
89 starthis
= self
.getHistoryLen()
90 self
.feed_child("info breakpoints\n")
92 rx
= re
.compile("^\(gdb\) ")
93 endhis
, response
= self
.waitForRx(rx
, starthis
)
96 rxbp
= re
.compile("^\d+\s+breakpoint")
97 rxpos
= re
.compile("^.* at \S+:\d+$")
98 rxcond
= re
.compile("^\tstop only if")
101 bplines
= self
.history
[starthis
+1:endhis
]
104 #Parse the resulting lines
105 while i
<len(bplines
):
108 if not rxbp
.search(line
):
112 #Get number of breakpoint
113 no
= string
.split(line
)[0]
115 #This line does not contain the file!
116 if not rxpos
.search(line
):
120 pos
= string
.split(line
)[-1]
121 [file,lineno
] = string
.split(pos
,":")
124 if i
+1<len(bplines
) and rxcond
.search(bplines
[i
+1]):
127 pre
,cond
= string
.split(line
,"if")
130 bpnts
+= [[no
, file, lineno
, cond
]]
137 def getExpression(self
, expr
):
139 his
= self
.getHistoryLen()
140 self
.feed_child("print " + expr
+ "\n")
142 rx
= re
.compile("^\(gdb\)")
143 his
, response
= self
.waitForRx(rx
, his
)
145 answer
= self
.history
[his
-1]
147 if len(string
.split(answer
, "=")) == 1:
148 return answer
.strip()
150 split
= string
.split(answer
, "=")
151 return string
.join(split
[1:], "=").strip()
154 def waitForActivation(self
, starthis
):
156 self
.setActive(False)
157 rx
= re
.compile("^\(gdb\)")
158 endhis
, response
= self
.waitForRx(rx
,starthis
)
161 for his
in reversed(range(starthis
+1,endhis
)):
162 if self
.history
[his
][0:2]=="\x1a\x1a":
163 tuples
= string
.split(self
.history
[his
][2:], ":")
170 if __name__
== "__main__":
173 dbgterm
= GdbTerminal(string
.join(sys
.argv
[1:]))
174 dbgwnd
= DbgTerminal
.DbgWindow(dbgterm
)