77d21e2f6e3fbffab0c3143214bca2ff1dd8db31
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_dbg("set inferior-tty %s\n" % (ttyname
,))
32 his
= self
.getHistoryLen()
33 argv
= string
.join(string
.split(self
.clientCmd
)[1:])
34 self
.feed_dbg("run " + argv
+ "\n")
35 return self
.waitForActivation(his
)
38 def setContinue(self
):
39 his
= self
.getHistoryLen()
40 self
.feed_dbg("cont\n");
41 return self
.waitForActivation(his
)
43 def setStepover(self
):
44 his
= self
.getHistoryLen()
45 self
.feed_dbg("next\n");
46 return self
.waitForActivation(his
)
49 his
= self
.getHistoryLen()
50 self
.feed_dbg("step\n");
51 return self
.waitForActivation(his
)
54 self
.feed_dbg("quit\n")
58 def setBreakpoint(self
, file, lineno
, condition
=None):
59 his
= self
.getHistoryLen()
61 self
.feed_dbg("break %s:%s\n" % (file, str(lineno
)))
63 self
.feed_dbg("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
)
70 if response
[0:10] == "Breakpoint":
71 return string
.split(response
)[1].strip()
72 if response
[0:5] == "(gdb)":
74 if response
[0:14] == "No source file":
77 if response
[0:3] == "No ":
80 return NotImplementedError()
82 def delBreakpoint(self
, breakpoint
):
83 self
.feed_dbg("del breakpoint %s\n" % (breakpoint
,))
85 def getBreakpoints(self
):
86 starthis
= self
.getHistoryLen()
87 self
.feed_dbg("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
):
105 print "Warning GdbTerminal.getBreakpoints at line", line
109 splits
= string
.split(line
)
112 [file,lineno
] = string
.split(pos
,":")
115 if i
+1<len(bplines
) and rxbp2
.search(bplines
[i
+1]):
118 pre
,cond
= string
.split(line
,"if")
121 bpnts
+= [[no
, file, lineno
, cond
]]
128 def getExpression(self
, expr
):
130 his
= self
.getHistoryLen()
131 self
.feed_dbg("print " + expr
+ "\n")
133 rx
= re
.compile("^\(gdb\) $")
134 his
, response
= self
.waitForRx(rx
, his
)
136 answer
= self
.history
[his
-1]
138 if len(string
.split(answer
, "=")) == 1:
139 return answer
.strip()
141 split
= string
.split(answer
, "=")
142 return string
.join(split
[1:], "=").strip()
145 def waitForActivation(self
, his
):
147 self
.setActive(False)
148 rx
= re
.compile("^\(gdb\) $")
149 his
, reponse
= self
.waitForRx(rx
,his
)
152 if self
.history
[his
-1][0:2]=="\x1a\x1a":
153 tuples
= string
.split(self
.history
[his
-1][2:], ":")
160 if __name__
== "__main__":
163 dbgterm
= GdbTerminal(string
.join(sys
.argv
[1:]))
164 dbgwnd
= DbgTerminal
.DbgWindow(dbgterm
)
166 DbgTerminal
.launchDebugger(dbgwnd
, dbgterm
)