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 len = self
.getHistoryLen()
47 self
.feed_child("set inferior-tty %s\n" % (ttyname
,))
48 self
.waitForPrompt(len)
50 def setBreakpoint(self
, file, lineno
, condition
=None):
51 his
= self
.getHistoryLen()
53 self
.feed_child("break %s:%s\n" % (file, str(lineno
)))
55 self
.feed_child("break %s:%s if %s\n" % \
56 (file, str(lineno
), condition
))
58 rx
= "^Breakpoint |^No |^\(gdb\) "
59 his
, response
= self
.waitForRx(rx
, his
)
63 if response
[0:10] == "Breakpoint":
64 answer
= string
.split(response
)[1].strip()
66 #Wants an answer: "No"
67 if response
[0:14] == "No source file":
68 self
.feed_child("n\n");
70 #Wait again for (gdb)...
71 self
.waitForPrompt(his
)
76 def delBreakpoint(self
, breakpoint
):
77 his
= self
.getHistoryLen()
78 self
.feed_child("del breakpoint %s\n" % (breakpoint
,))
79 self
.waitForPrompt(his
)
81 def getBreakpoints(self
):
82 starthis
= self
.getHistoryLen()
83 self
.feed_child("info breakpoints\n")
84 endhis
, response
= self
.waitForPrompt(starthis
)
86 rxbp
= re
.compile("^\d+\s+breakpoint")
87 rxpos
= re
.compile("^.* at \S+:\d+$")
88 rxcond
= re
.compile("^\tstop only if")
91 bplines
= self
.history
[starthis
+1:endhis
]
94 #Parse the resulting lines
98 if not rxbp
.search(line
):
102 #Get number of breakpoint
103 no
= string
.split(line
)[0]
105 #This line does not contain the file!
106 if not rxpos
.search(line
):
109 pos
= string
.split(line
)[-1]
110 [file,lineno
] = string
.split(pos
,":")
113 if i
+1<len(bplines
) and rxcond
.search(bplines
[i
+1]):
116 cond
= string
.join(string
.split(line
," if ")[1:], " if ")
119 bpnts
+= [[no
, file, lineno
, cond
]]
126 def getExpression(self
, expr
):
128 his
= self
.getHistoryLen()
129 self
.feed_child("print " + expr
+ "\n")
130 his
, response
= self
.waitForPrompt(his
)
131 answer
= self
.history
[his
-1]
133 if len(string
.split(answer
, "=")) == 1:
134 return answer
.strip()
136 split
= string
.split(answer
, "=")
137 return string
.join(split
[1:], "=").strip()
140 def listCodeSnippet(self
):
141 starthis
= self
.getHistoryLen()
142 self
.feed_child("list\n")
143 endhis
, response
= self
.waitForPrompt(starthis
)
145 text
= string
.join(self
.history
[starthis
:endhis
], "\n")
149 def waitForPrompt(self
, his
):
151 return self
.waitForRx(rx
,his
)
154 def testForActivity(self
, his
):
155 """Test whether debugger got active again"""
157 line
= self
.history
[his
]
159 if string
.find(line
, "\x1a\x1a") == 0:
160 tuples
= string
.split(line
[2:], ":")
161 tuples
[1] = int(tuples
[1])
162 return "break", [tuples
[0], int(tuples
[1])]
164 if string
.find(line
, "Program exited") == 0:
165 code
= string
.split(line
)[-1]
169 #Parse the octal number
173 codeno
= codeno
*8 + int(c
)
175 return "exited", codeno
180 def testForInactivity(self
, his
):
181 """Test whether debugger got inactive"""
182 line
= self
.history
[his
]
184 if string
.find(line
, "Starting program:") == 0:
185 prog
= string
.join( string
.split(line
)[1:])
186 return "started", prog
188 if string
.find(line
, "Continuing.") == 0:
189 return "continued", None
191 if string
.find(line
, "\x1a\x1a") == 0:
192 rxcont
= re
.compile("^\(gdb\)\s+(cont|step|next|stepi|nexti)")
194 if rxcont
.search(self
.history
[his
-1]):
195 return "stepped", None
206 if __name__
== "__main__":
209 dbgterm
= GdbTerminal(string
.join(sys
.argv
[1:]))
210 dbgwnd
= DbgTerminal
.DbgWindow(dbgterm
)