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]]
27 argv
= string
.join(string
.split(self
.clientCmd
)[1:])
28 self
.feed_child("run " + argv
+ "\n")
30 def setContinue(self
):
31 self
.feed_child("cont\n");
33 def setStepover(self
):
34 self
.feed_child("next\n");
37 self
.feed_child("step\n");
40 self
.feed_child("quit\n")
42 self
.feed_child("y\n");
44 def setPty(self
, pty
):
45 ttyname
= os
.ttyname(pty
)
46 self
.__getAnswerFromCmd
("set inferior-tty %s\n" % (ttyname
,))
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
= "^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
.waitForPrompt(his
)
74 def delBreakpoint(self
, breakpoint
):
75 self
.__getAnswerFromCmd
("del breakpoint %s\n" % (breakpoint
,))
78 def getBreakpoints(self
):
79 bplines
= self
.__getAnswerFromCmd
("info breakpoints\n")
81 rxbp
= re
.compile("^\d+\s+breakpoint")
82 rxpos
= re
.compile("^.* at \S+:\d+$")
83 rxcond
= re
.compile("^\tstop only if")
88 #Parse the resulting lines
92 if not rxbp
.search(line
):
96 #Get number of breakpoint
97 no
= string
.split(line
)[0]
99 #This line does not contain the file!
100 if not rxpos
.search(line
):
103 pos
= string
.split(line
)[-1]
104 [file,lineno
] = string
.split(pos
,":")
107 if i
+1<len(bplines
) and rxcond
.search(bplines
[i
+1]):
110 cond
= string
.join(string
.split(line
," if ")[1:], " if ")
113 bpnts
+= [[no
, file, lineno
, cond
]]
120 def getExpression(self
, expr
):
121 answer
= self
.__getAnswerFromCmd
("print " + expr
+ "\n")
124 if len(string
.split(answer
, "=")) == 1:
125 return answer
.strip()
127 split
= string
.split(answer
, "=")
128 return string
.join(split
[1:], "=").strip()
131 def listCodeSnippet(self
):
132 answ
= self
.__getAnswerFromCmd
("list\n")
133 return string
.join(answ
, "\n")
135 def getBacktrace(self
):
136 answ
= self
.__getAnswerFromCmd
("bt\n")
137 return string
.join(answ
, "\n")
139 def waitForPrompt(self
, his
):
141 return self
.waitForRx(rx
,his
)
143 def __getAnswerFromCmd(self
, cmd
):
144 starthis
= self
.getHistoryLen()
146 endhis
, response
= self
.waitForPrompt(starthis
)
148 return self
.history
[starthis
:endhis
]
151 def testForActivity(self
, his
):
152 """Test whether debugger got active again"""
154 line
= self
.history
[his
]
156 if string
.find(line
, "\x1a\x1a") == 0:
157 tuples
= string
.split(line
[2:], ":")
158 tuples
[1] = int(tuples
[1])
159 return "break", [tuples
[0], int(tuples
[1])]
161 if string
.find(line
, "Program exited") == 0:
162 code
= string
.split(line
)[-1]
166 #Parse the octal number
170 codeno
= codeno
*8 + int(c
)
172 return "exited", codeno
177 def testForInactivity(self
, his
):
178 """Test whether debugger got inactive"""
179 line
= self
.history
[his
]
181 if string
.find(line
, "Starting program:") == 0:
182 prog
= string
.join( string
.split(line
)[1:])
183 return "started", prog
185 if string
.find(line
, "Continuing.") == 0:
186 return "continued", None
188 if string
.find(line
, "\x1a\x1a") == 0:
189 rxcont
= re
.compile("^\(gdb\)\s+(cont|step|next|stepi|nexti)")
191 if rxcont
.search(self
.history
[his
-1]):
192 return "stepped", None
203 if __name__
== "__main__":
206 dbgterm
= GdbTerminal(string
.join(sys
.argv
[1:]))
207 dbgwnd
= DbgTerminal
.DbgWindow(dbgterm
)