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
)
33 his
= self
.getHistoryLen()
34 argv
= string
.join(string
.split(self
.clientCmd
)[1:])
35 self
.feed_child("run " + argv
+ "\n")
36 return self
.waitForActivation(his
)
38 def setContinue(self
):
39 his
= self
.getHistoryLen()
40 self
.feed_child("cont\n");
41 return self
.waitForActivation(his
)
43 def setStepover(self
):
44 his
= self
.getHistoryLen()
45 self
.feed_child("next\n");
46 return self
.waitForActivation(his
)
49 his
= self
.getHistoryLen()
50 self
.feed_child("step\n");
51 return self
.waitForActivation(his
)
54 self
.feed_child("quit\n")
56 self
.feed_child("y\n");
58 def setBreakpoint(self
, file, lineno
, condition
=None):
59 his
= self
.getHistoryLen()
61 self
.feed_child("break %s:%s\n" % (file, str(lineno
)))
63 self
.feed_child("break %s:%s if %s\n" % \
64 (file, str(lineno
), condition
))
66 rx
= re
.compile("^Breakpoint |^No |^\(gdb\) ")
67 his
, response
= self
.waitForRx(rx
, his
)
71 if response
[0:10] == "Breakpoint":
72 answer
= string
.split(response
)[1].strip()
74 #Wants an answer: "No"
75 if response
[0:14] == "No source file":
76 self
.feed_child("n\n");
78 #Wait again for (gdb)...
79 self
.waitForActivation(his
)
84 def delBreakpoint(self
, breakpoint
):
85 his
= self
.getHistoryLen()
86 self
.feed_child("del breakpoint %s\n" % (breakpoint
,))
87 self
.waitForActivation(his
)
89 def getBreakpoints(self
):
90 starthis
= self
.getHistoryLen()
91 self
.feed_child("info breakpoints\n")
92 endhis
, response
= self
.__waitForPrompt
(starthis
)
94 rxbp
= re
.compile("^\d+\s+breakpoint")
95 rxpos
= re
.compile("^.* at \S+:\d+$")
96 rxcond
= re
.compile("^\tstop only if")
99 bplines
= self
.history
[starthis
+1:endhis
]
102 #Parse the resulting lines
103 while i
<len(bplines
):
106 if not rxbp
.search(line
):
110 #Get number of breakpoint
111 no
= string
.split(line
)[0]
113 #This line does not contain the file!
114 if not rxpos
.search(line
):
118 pos
= string
.split(line
)[-1]
119 [file,lineno
] = string
.split(pos
,":")
122 if i
+1<len(bplines
) and rxcond
.search(bplines
[i
+1]):
125 pre
,cond
= string
.split(line
,"if")
128 bpnts
+= [[no
, file, lineno
, cond
]]
135 def getExpression(self
, expr
):
137 his
= self
.getHistoryLen()
138 self
.feed_child("print " + expr
+ "\n")
139 his
, response
= self
.__waitForPrompt
(his
)
140 answer
= self
.history
[his
-1]
142 if len(string
.split(answer
, "=")) == 1:
143 return answer
.strip()
145 split
= string
.split(answer
, "=")
146 return string
.join(split
[1:], "=").strip()
149 def waitForActivation(self
, starthis
):
151 self
.setActive(False)
152 endhis
, response
= self
.__waitForPrompt
(starthis
)
155 for his
in reversed(range(starthis
+1,endhis
)):
156 if self
.history
[his
][0:2]=="\x1a\x1a":
157 tuples
= string
.split(self
.history
[his
][2:], ":")
163 def __waitForPrompt(self
, his
):
164 rx
= re
.compile("^\(gdb\) ")
165 return self
.waitForRx(rx
,his
)
170 if __name__
== "__main__":
173 dbgterm
= GdbTerminal(string
.join(sys
.argv
[1:]))
174 dbgwnd
= DbgTerminal
.DbgWindow(dbgterm
)