15cb11df2bb233c8c7881db3e2c255cf0de77327
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
,))
31 argv
= string
.join(string
.split(self
.clientCmd
)[1:])
32 self
.feed_child("run " + argv
+ "\n")
34 def setContinue(self
):
35 self
.feed_child("cont\n");
37 def setStepover(self
):
38 self
.feed_child("next\n");
41 self
.feed_child("step\n");
44 self
.feed_child("quit\n")
46 self
.feed_child("y\n");
48 def setBreakpoint(self
, file, lineno
, condition
=None):
49 his
= self
.getHistoryLen()
51 self
.feed_child("break %s:%s\n" % (file, str(lineno
)))
53 self
.feed_child("break %s:%s if %s\n" % \
54 (file, str(lineno
), condition
))
56 rx
= re
.compile("^Breakpoint |^No |^\(gdb\) ")
57 his
, response
= self
.waitForRx(rx
, his
)
61 if response
[0:10] == "Breakpoint":
62 answer
= string
.split(response
)[1].strip()
64 #Wants an answer: "No"
65 if response
[0:14] == "No source file":
66 self
.feed_child("n\n");
68 #Wait again for (gdb)...
69 self
.waitForActivation(his
)
74 def delBreakpoint(self
, breakpoint
):
75 his
= self
.getHistoryLen()
76 self
.feed_child("del breakpoint %s\n" % (breakpoint
,))
77 self
.waitForActivation(his
)
79 def getBreakpoints(self
):
80 starthis
= self
.getHistoryLen()
81 self
.feed_child("info breakpoints\n")
82 endhis
, response
= self
.__waitForPrompt
(starthis
)
84 rxbp
= re
.compile("^\d+\s+breakpoint")
85 rxpos
= re
.compile("^.* at \S+:\d+$")
86 rxcond
= re
.compile("^\tstop only if")
89 bplines
= self
.history
[starthis
+1:endhis
]
92 #Parse the resulting lines
96 if not rxbp
.search(line
):
100 #Get number of breakpoint
101 no
= string
.split(line
)[0]
103 #This line does not contain the file!
104 if not rxpos
.search(line
):
108 pos
= string
.split(line
)[-1]
109 [file,lineno
] = string
.split(pos
,":")
112 if i
+1<len(bplines
) and rxcond
.search(bplines
[i
+1]):
115 pre
,cond
= string
.split(line
,"if")
118 bpnts
+= [[no
, file, lineno
, cond
]]
125 def getExpression(self
, expr
):
127 his
= self
.getHistoryLen()
128 self
.feed_child("print " + expr
+ "\n")
129 his
, response
= self
.__waitForPrompt
(his
)
130 answer
= self
.history
[his
-1]
132 if len(string
.split(answer
, "=")) == 1:
133 return answer
.strip()
135 split
= string
.split(answer
, "=")
136 return string
.join(split
[1:], "=").strip()
139 def waitForActivation(self
, starthis
):
141 self
.setActive(False)
142 endhis
, response
= self
.__waitForPrompt
(starthis
)
145 for his
in reversed(range(starthis
+1,endhis
)):
146 if self
.history
[his
][0:2]=="\x1a\x1a":
147 tuples
= string
.split(self
.history
[his
][2:], ":")
148 return tuples
[0], int(tuples
[1])
153 def __waitForPrompt(self
, his
):
154 rx
= re
.compile("^\(gdb\) ")
155 return self
.waitForRx(rx
,his
)
158 def testForActivity(self
, his
):
159 """Test whether debugger got active again"""
160 rx
= re
.compile("^\(gdb\) ")
162 #Aha! There is a prompt...
163 if rx
.search(self
.history
[his
]):
164 line
= self
.history
[his
-1]
166 if line
[0:2]=="\x1a\x1a":
167 tuples
= string
.split(line
[2:], ":")
168 tuples
[1] = int(tuples
[1])
169 return "break", [tuples
[0], int(tuples
[1])]
171 if string
.find(line
, "Program exited") == 0:
172 code
= string
.split(line
)[-1]
174 return "exited", code
179 def testForInactivity(self
, his
):
180 """Test whether debugger got inactive"""
181 line
= self
.history
[his
]
183 if string
.find(line
, "Starting program:") == 0:
184 prog
= string
.join( string
.split(line
)[1:])
185 return "started", prog
187 if string
.find(line
, "Continuing.") == 0:
188 return "continued", None
190 if string
.find(line
, "\x1a\x1a") == 0:
191 rxcont
= re
.compile("^\(gdb\)\s+(cont|step|next|stepi|nexti)")
193 if rxcont
.search(self
.history
[his
-1]):
194 return "stepped", None
205 if __name__
== "__main__":
208 dbgterm
= GdbTerminal(string
.join(sys
.argv
[1:]))
209 dbgwnd
= DbgTerminal
.DbgWindow(dbgterm
)