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
):
110 pos
= string
.split(line
)[-1]
111 [file,lineno
] = string
.split(pos
,":")
114 if i
+1<len(bplines
) and rxcond
.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")
131 his
, response
= self
.waitForPrompt(his
)
132 answer
= self
.history
[his
-1]
134 if len(string
.split(answer
, "=")) == 1:
135 return answer
.strip()
137 split
= string
.split(answer
, "=")
138 return string
.join(split
[1:], "=").strip()
141 def listCodeSnippet(self
):
142 starthis
= self
.getHistoryLen()
143 self
.feed_child("list\n")
144 endhis
, response
= self
.waitForPrompt(starthis
)
146 text
= string
.join(self
.history
[starthis
:endhis
], "\n")
150 def waitForPrompt(self
, his
):
152 return self
.waitForRx(rx
,his
)
155 def testForActivity(self
, his
):
156 """Test whether debugger got active again"""
158 line
= self
.history
[his
]
160 if string
.find(line
, "\x1a\x1a") == 0:
161 tuples
= string
.split(line
[2:], ":")
162 tuples
[1] = int(tuples
[1])
163 return "break", [tuples
[0], int(tuples
[1])]
165 if string
.find(line
, "Program exited") == 0:
166 code
= string
.split(line
)[-1]
170 #Parse the octal number
174 codeno
= codeno
*8 + int(c
)
176 return "exited", codeno
181 def testForInactivity(self
, his
):
182 """Test whether debugger got inactive"""
183 line
= self
.history
[his
]
185 if string
.find(line
, "Starting program:") == 0:
186 prog
= string
.join( string
.split(line
)[1:])
187 return "started", prog
189 if string
.find(line
, "Continuing.") == 0:
190 return "continued", None
192 if string
.find(line
, "\x1a\x1a") == 0:
193 rxcont
= re
.compile("^\(gdb\)\s+(cont|step|next|stepi|nexti)")
195 if rxcont
.search(self
.history
[his
-1]):
196 return "stepped", None
207 if __name__
== "__main__":
210 dbgterm
= GdbTerminal(string
.join(sys
.argv
[1:]))
211 dbgwnd
= DbgTerminal
.DbgWindow(dbgterm
)