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 rxbp1
= re
.compile("^\d+\s+breakpoint")
94 rxbp2
= re
.compile("^\tstop only if")
97 bplines
= self
.history
[starthis
+1:endhis
]
100 #Parse the resulting lines
101 while i
<len(bplines
):
104 if not rxbp1
.search(line
):
108 splits
= string
.split(line
)
111 [file,lineno
] = string
.split(pos
,":")
114 if i
+1<len(bplines
) and rxbp2
.search(bplines
[i
+1]):
117 pre
,cond
= string
.split(line
,"if")
120 bpnts
+= [[no
, file, lineno
, cond
]]
127 def getExpression(self
, expr
):
129 his
= self
.getHistoryLen()
130 self
.feed_child("print " + expr
+ "\n")
132 rx
= re
.compile("^\(gdb\) $")
133 his
, response
= self
.waitForRx(rx
, his
)
135 answer
= self
.history
[his
-1]
137 if len(string
.split(answer
, "=")) == 1:
138 return answer
.strip()
140 split
= string
.split(answer
, "=")
141 return string
.join(split
[1:], "=").strip()
144 def waitForActivation(self
, his
=None):
146 self
.setActive(False)
147 rx
= re
.compile("^\(gdb\) $")
148 his
, reponse
= self
.waitForRx(rx
,his
)
151 if self
.history
[his
-1][0:2]=="\x1a\x1a":
152 tuples
= string
.split(self
.history
[his
-1][2:], ":")
159 if __name__
== "__main__":
162 dbgterm
= GdbTerminal(string
.join(sys
.argv
[1:]))
163 dbgwnd
= DbgTerminal
.DbgWindow(dbgterm
)