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 self
.feed_child("set inferior-tty %s\n" % (ttyname
,))
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
)
37 def setContinue(self
):
38 his
= self
.getHistoryLen()
39 self
.feed_child("cont\n");
40 return self
.waitForActivation(his
)
42 def setStepover(self
):
43 his
= self
.getHistoryLen()
44 self
.feed_child("next\n");
45 return self
.waitForActivation(his
)
48 his
= self
.getHistoryLen()
49 self
.feed_child("step\n");
50 return self
.waitForActivation(his
)
53 self
.feed_child("quit\n")
55 self
.feed_child("y\n");
57 def setBreakpoint(self
, file, lineno
, condition
=None):
58 his
= self
.getHistoryLen()
60 self
.feed_child("break %s:%s\n" % (file, str(lineno
)))
62 self
.feed_child("break %s:%s if %s\n" % \
63 (file, str(lineno
), condition
))
65 rx
= re
.compile("^Breakpoint |^No |^\(gdb\) ")
66 his
, response
= self
.waitForRx(rx
, his
)
68 if response
[0:10] == "Breakpoint":
69 return string
.split(response
)[1].strip()
71 if response
[0:14] == "No source file":
72 self
.feed_child("n\n");
76 if response
[0:5] != "(gdb)":
77 his
, response
= self
.waitForRx(rx
,his
)
82 def delBreakpoint(self
, breakpoint
):
83 self
.feed_child("del breakpoint %s\n" % (breakpoint
,))
85 def getBreakpoints(self
):
86 starthis
= self
.getHistoryLen()
87 self
.feed_child("info breakpoints\n")
89 rx
= re
.compile("^\(gdb\) ")
90 endhis
, response
= self
.waitForRx(rx
, starthis
)
93 rxbp
= re
.compile("^\d+\s+breakpoint")
94 rxpos
= re
.compile("^.* at \S+:\d+$")
95 rxcond
= re
.compile("^\tstop only if")
98 bplines
= self
.history
[starthis
+1:endhis
]
101 #Parse the resulting lines
102 while i
<len(bplines
):
105 if not rxbp
.search(line
):
109 #Get number of breakpoint
110 no
= string
.split(line
)[0]
112 #This line does not contain the file!
113 if not rxpos
.search(line
):
117 pos
= string
.split(line
)[-1]
118 [file,lineno
] = string
.split(pos
,":")
121 if i
+1<len(bplines
) and rxcond
.search(bplines
[i
+1]):
124 pre
,cond
= string
.split(line
,"if")
127 bpnts
+= [[no
, file, lineno
, cond
]]
134 def getExpression(self
, expr
):
136 his
= self
.getHistoryLen()
137 self
.feed_child("print " + expr
+ "\n")
139 rx
= re
.compile("^\(gdb\) $")
140 his
, response
= self
.waitForRx(rx
, his
)
142 answer
= self
.history
[his
-1]
144 if len(string
.split(answer
, "=")) == 1:
145 return answer
.strip()
147 split
= string
.split(answer
, "=")
148 return string
.join(split
[1:], "=").strip()
151 def waitForActivation(self
, starthis
=None):
154 starthis
= self
.getHistoryLen()
156 self
.setActive(False)
157 rx
= re
.compile("^\(gdb\) $")
158 endhis
, reponse
= 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
)