17 class GdbTerminal (DbgTerminal
.DbgTerminal
):
20 def __init__(self
, clientCmd
, exitcb
=None):
21 DbgTerminal
.DbgTerminal
.__init
__(self
, clientCmd
, exitcb
)
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
)
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
)
69 if response
[0:10] == "Breakpoint":
70 return string
.split(response
)[1].strip()
71 if response
[0:5] == "(gdb)":
73 if response
[0:14] == "No source file":
74 self
.feed_child("n\n");
76 if response
[0:3] == "No ":
79 return NotImplementedError()
81 def delBreakpoint(self
, breakpoint
):
82 self
.feed_child("del breakpoint %s\n" % (breakpoint
,))
84 def getBreakpoints(self
):
85 starthis
= self
.getHistoryLen()
86 self
.feed_child("info breakpoints\n")
88 rx
= re
.compile("^\(gdb\) ")
89 endhis
, response
= self
.waitForRx(rx
, starthis
)
92 rxbp1
= re
.compile("^\d+\s+breakpoint")
93 rxbp2
= re
.compile("^\tstop only if")
96 bplines
= self
.history
[starthis
+1:endhis
]
99 #Parse the resulting lines
100 while i
<len(bplines
):
103 if not rxbp1
.search(line
):
107 splits
= string
.split(line
)
110 [file,lineno
] = string
.split(pos
,":")
113 if i
+1<len(bplines
) and rxbp2
.search(bplines
[i
+1]):
116 pre
,cond
= string
.split(line
,"if")
119 bpnts
+= [[no
, file, lineno
, cond
]]
126 def getExpression(self
, expr
):
128 his
= self
.getHistoryLen()
129 self
.feed_child("print " + expr
+ "\n")
131 rx
= re
.compile("^\(gdb\) $")
132 his
, response
= self
.waitForRx(rx
, his
)
134 answer
= self
.history
[his
-1]
136 if len(string
.split(answer
, "=")) == 1:
137 return answer
.strip()
139 split
= string
.split(answer
, "=")
140 return string
.join(split
[1:], "=").strip()
143 def waitForActivation(self
, his
=None):
145 self
.setActive(False)
146 rx
= re
.compile("^\(gdb\) $")
147 his
, reponse
= self
.waitForRx(rx
,his
)
150 if self
.history
[his
-1][0:2]=="\x1a\x1a":
151 tuples
= string
.split(self
.history
[his
-1][2:], ":")
158 if __name__
== "__main__":
161 dbgterm
= GdbTerminal(string
.join(sys
.argv
[1:]))
162 dbgwnd
= DbgTerminal
.DbgWindow(dbgterm
)