Vega strike Python Modules doc  0.5.1
Documentation of the " Modules " folder of Vega strike
 All Data Structures Namespaces Files Functions Variables
Bdb Class Reference
Inheritance diagram for Bdb:
Tdb Pdb

Public Member Functions

def __init__
 
def canonic
 
def reset
 
def trace_dispatch
 
def dispatch_line
 
def dispatch_call
 
def dispatch_return
 
def dispatch_exception
 
def stop_here
 
def break_here
 
def do_clear
 
def break_anywhere
 
def user_call
 
def user_line
 
def user_return
 
def user_exception
 
def set_step
 
def set_next
 
def set_return
 
def set_trace
 
def set_continue
 
def set_quit
 
def set_break
 
def clear_break
 
def clear_bpbynumber
 
def clear_all_file_breaks
 
def clear_all_breaks
 
def get_break
 
def get_breaks
 
def get_file_breaks
 
def get_all_breaks
 
def get_stack
 
def format_stack_entry
 
def run
 
def runeval
 
def runctx
 
def runcall
 

Data Fields

 breaks
 
 fncache
 
 botframe
 
 stopframe
 
 returnframe
 
 quitting
 
 currentbp
 

Detailed Description

Generic Python debugger base class.

This class takes care of details of the trace facility;
a derived class should implement user interaction.
The standard debugger class (pdb.Pdb) is an example.

Definition at line 12 of file bdb.py.

Constructor & Destructor Documentation

def __init__ (   self)

Definition at line 21 of file bdb.py.

21 
22  def __init__(self):
23  self.breaks = {}
24  self.fncache = {}

Member Function Documentation

def break_anywhere (   self,
  frame 
)

Definition at line 123 of file bdb.py.

References Bdb.canonic().

124  def break_anywhere(self, frame):
125  return self.breaks.has_key(
126  self.canonic(frame.f_code.co_filename))
def break_here (   self,
  frame 
)

Definition at line 103 of file bdb.py.

References Bdb.breaks, Bdb.canonic(), and bdb.effective().

104  def break_here(self, frame):
105  filename = self.canonic(frame.f_code.co_filename)
106  if not self.breaks.has_key(filename):
107  return 0
108  lineno = frame.f_lineno
109  if not lineno in self.breaks[filename]:
110  return 0
111  # flag says ok to delete temp. bp
112  (bp, flag) = effective(filename, lineno, frame)
113  if bp:
114  self.currentbp = bp.number
115  if (flag and bp.temporary):
116  self.do_clear(str(bp.number))
117  return 1
118  else:
119  return 0
def canonic (   self,
  filename 
)

Definition at line 25 of file bdb.py.

References Bdb.fncache.

25 
26  def canonic(self, filename):
27  if filename == "<" + filename[1:-1] + ">":
28  return filename
29  canonic = self.fncache.get(filename)
30  if not canonic:
31  canonic = os.path.abspath(filename)
32  canonic = os.path.normcase(canonic)
33  self.fncache[filename] = canonic
34  return canonic
def clear_all_breaks (   self)

Definition at line 265 of file bdb.py.

References Bdb.breaks.

266  def clear_all_breaks(self):
267  if not self.breaks:
268  return 'There are no breakpoints'
269  for bp in Breakpoint.bpbynumber:
270  if bp:
271  bp.deleteMe()
272  self.breaks = {}
def clear_all_file_breaks (   self,
  filename 
)

Definition at line 255 of file bdb.py.

References Bdb.breaks, and Bdb.canonic().

256  def clear_all_file_breaks(self, filename):
257  filename = self.canonic(filename)
258  if not self.breaks.has_key(filename):
259  return 'There are no breakpoints in %s' % filename
260  for line in self.breaks[filename]:
261  blist = Breakpoint.bplist[filename, line]
262  for bp in blist:
263  bp.deleteMe()
264  del self.breaks[filename]
def clear_bpbynumber (   self,
  arg 
)

Definition at line 242 of file bdb.py.

References Bdb.clear_break().

243  def clear_bpbynumber(self, arg):
244  try:
245  number = int(arg)
246  except:
247  return 'Non-numeric breakpoint number (%s)' % arg
248  try:
249  bp = Breakpoint.bpbynumber[number]
250  except IndexError:
251  return 'Breakpoint number (%d) out of range' % number
252  if not bp:
253  return 'Breakpoint (%d) already deleted' % number
254  self.clear_break(bp.file, bp.line)
def clear_break (   self,
  filename,
  lineno 
)

Definition at line 226 of file bdb.py.

References Bdb.breaks, and Bdb.canonic().

227  def clear_break(self, filename, lineno):
228  filename = self.canonic(filename)
229  if not self.breaks.has_key(filename):
230  return 'There are no breakpoints in %s' % filename
231  if lineno not in self.breaks[filename]:
232  return 'There is no breakpoint at %s:%d' % (filename,
233  lineno)
234  # If there's only one bp in the list for that file,line
235  # pair, then remove the breaks entry
236  for bp in Breakpoint.bplist[filename, lineno][:]:
237  bp.deleteMe()
238  if not Breakpoint.bplist.has_key((filename, lineno)):
239  self.breaks[filename].remove(lineno)
240  if not self.breaks[filename]:
241  del self.breaks[filename]
def dispatch_call (   self,
  frame,
  arg 
)

Definition at line 63 of file bdb.py.

References Bdb.botframe, Bdb.break_anywhere(), Bdb.quitting, Bdb.stop_here(), Bdb.trace_dispatch(), and Bdb.user_call().

63 
64  def dispatch_call(self, frame, arg):
65  # XXX 'arg' is no longer used
66  if self.botframe is None:
67  # First call of dispatch since reset()
68  self.botframe = frame
69  return self.trace_dispatch
70  if not (self.stop_here(frame) or self.break_anywhere(frame)):
71  # No need to trace this function
72  return # None
73  self.user_call(frame, arg)
74  if self.quitting: raise BdbQuit
75  return self.trace_dispatch
def dispatch_exception (   self,
  frame,
  arg 
)

Definition at line 82 of file bdb.py.

References Bdb.quitting, Bdb.stop_here(), Bdb.trace_dispatch(), and Bdb.user_exception().

82 
83  def dispatch_exception(self, frame, arg):
84  if self.stop_here(frame):
85  self.user_exception(frame, arg)
86  if self.quitting: raise BdbQuit
87  return self.trace_dispatch
def dispatch_line (   self,
  frame 
)

Definition at line 57 of file bdb.py.

References Bdb.break_here(), Bdb.quitting, Bdb.stop_here(), Bdb.trace_dispatch(), and Bdb.user_line().

57 
58  def dispatch_line(self, frame):
59  if self.stop_here(frame) or self.break_here(frame):
60  self.user_line(frame)
61  if self.quitting: raise BdbQuit
62  return self.trace_dispatch
def dispatch_return (   self,
  frame,
  arg 
)

Definition at line 76 of file bdb.py.

References Bdb.quitting, Bdb.returnframe, Bdb.stop_here(), Bdb.trace_dispatch(), and Bdb.user_return().

76 
77  def dispatch_return(self, frame, arg):
78  if self.stop_here(frame) or frame == self.returnframe:
79  self.user_return(frame, arg)
80  if self.quitting: raise BdbQuit
81  return self.trace_dispatch
def do_clear (   self,
  arg 
)

Definition at line 120 of file bdb.py.

121  def do_clear(self, arg):
122  raise NotImplementedError, "subclass of bdb must implement do_clear()"
def format_stack_entry (   self,
  frame_lineno,
  lprefix = ': ' 
)

Definition at line 315 of file bdb.py.

References Bdb.canonic(), linecache.getline(), and repr.repr.

316  def format_stack_entry(self, frame_lineno, lprefix=': '):
317  import linecache, repr
318  frame, lineno = frame_lineno
319  filename = self.canonic(frame.f_code.co_filename)
320  s = filename + '(' + `lineno` + ')'
321  if frame.f_code.co_name:
322  s = s + frame.f_code.co_name
323  else:
324  s = s + "<lambda>"
325  if frame.f_locals.has_key('__args__'):
326  args = frame.f_locals['__args__']
327  else:
328  args = None
329  if args:
330  s = s + repr.repr(args)
331  else:
332  s = s + '()'
333  if frame.f_locals.has_key('__return__'):
334  rv = frame.f_locals['__return__']
335  s = s + '->'
336  s = s + repr.repr(rv)
337  line = linecache.getline(filename, lineno)
338  if line: s = s + lprefix + line.strip()
339  return s
def get_all_breaks (   self)

Definition at line 291 of file bdb.py.

References Bdb.breaks.

292  def get_all_breaks(self):
293  return self.breaks
def get_break (   self,
  filename,
  lineno 
)

Definition at line 273 of file bdb.py.

References Bdb.breaks, and Bdb.canonic().

274  def get_break(self, filename, lineno):
275  filename = self.canonic(filename)
276  return self.breaks.has_key(filename) and \
277  lineno in self.breaks[filename]
def get_breaks (   self,
  filename,
  lineno 
)

Definition at line 278 of file bdb.py.

References Bdb.breaks, and Bdb.canonic().

279  def get_breaks(self, filename, lineno):
280  filename = self.canonic(filename)
281  return self.breaks.has_key(filename) and \
282  lineno in self.breaks[filename] and \
283  Breakpoint.bplist[filename, lineno] or []
def get_file_breaks (   self,
  filename 
)

Definition at line 284 of file bdb.py.

References Bdb.breaks, and Bdb.canonic().

285  def get_file_breaks(self, filename):
286  filename = self.canonic(filename)
287  if self.breaks.has_key(filename):
288  return self.breaks[filename]
289  else:
290  return []
def get_stack (   self,
  f,
  t 
)

Definition at line 297 of file bdb.py.

References Bdb.botframe, and sre_parse.max.

298  def get_stack(self, f, t):
299  stack = []
300  if t and t.tb_frame is f:
301  t = t.tb_next
302  while f is not None:
303  stack.append((f, f.f_lineno))
304  if f is self.botframe:
305  break
306  f = f.f_back
307  stack.reverse()
308  i = max(0, len(stack) - 1)
309  while t is not None:
310  stack.append((t.tb_frame, t.tb_lineno))
311  t = t.tb_next
312  return stack, i
def reset (   self)

Definition at line 35 of file bdb.py.

References linecache.checkcache().

35 
36  def reset(self):
37  import linecache
39  self.botframe = None
40  self.stopframe = None
41  self.returnframe = None
42  self.quitting = 0
def run (   self,
  cmd,
  globals = None,
  locals = None 
)

Definition at line 343 of file bdb.py.

References Bdb.quitting, Bdb.reset(), and Bdb.trace_dispatch().

344  def run(self, cmd, globals=None, locals=None):
345  if globals is None:
346  import __main__
347  globals = __main__.__dict__
348  if locals is None:
349  locals = globals
350  self.reset()
351  sys.settrace(self.trace_dispatch)
352  if not isinstance(cmd, types.CodeType):
353  cmd = cmd+'\n'
354  try:
355  try:
356  exec cmd in globals, locals
357  except BdbQuit:
358  pass
359  finally:
360  self.quitting = 1
361  sys.settrace(None)
def runcall (   self,
  func,
  args 
)

Definition at line 387 of file bdb.py.

References Bdb.quitting, Bdb.reset(), and Bdb.trace_dispatch().

388  def runcall(self, func, *args):
389  self.reset()
390  sys.settrace(self.trace_dispatch)
391  res = None
392  try:
393  try:
394  res = apply(func, args)
395  except BdbQuit:
396  pass
397  finally:
398  self.quitting = 1
399  sys.settrace(None)
400  return res
401 
def runctx (   self,
  cmd,
  globals,
  locals 
)

Definition at line 381 of file bdb.py.

References Bdb.run().

382  def runctx(self, cmd, globals, locals):
383  # B/W compatibility
384  self.run(cmd, globals, locals)
def runeval (   self,
  expr,
  globals = None,
  locals = None 
)

Definition at line 362 of file bdb.py.

References Bdb.quitting, Bdb.reset(), and Bdb.trace_dispatch().

363  def runeval(self, expr, globals=None, locals=None):
364  if globals is None:
365  import __main__
366  globals = __main__.__dict__
367  if locals is None:
368  locals = globals
369  self.reset()
370  sys.settrace(self.trace_dispatch)
371  if not isinstance(expr, types.CodeType):
372  expr = expr+'\n'
373  try:
374  try:
375  return eval(expr, globals, locals)
376  except BdbQuit:
377  pass
378  finally:
379  self.quitting = 1
380  sys.settrace(None)
def set_break (   self,
  filename,
  lineno,
  temporary = 0,
  cond = None 
)

Definition at line 212 of file bdb.py.

References Bdb.breaks, Bdb.canonic(), and linecache.getline().

213  def set_break(self, filename, lineno, temporary=0, cond = None):
214  filename = self.canonic(filename)
215  import linecache # Import as late as possible
216  line = linecache.getline(filename, lineno)
217  if not line:
218  return 'Line %s:%d does not exist' % (filename,
219  lineno)
220  if not self.breaks.has_key(filename):
221  self.breaks[filename] = []
222  list = self.breaks[filename]
223  if not lineno in list:
224  list.append(lineno)
225  bp = Breakpoint(filename, lineno, temporary, cond)
def set_continue (   self)

Definition at line 183 of file bdb.py.

References Bdb.botframe, Bdb.breaks, Bdb.quitting, Bdb.returnframe, and Bdb.stopframe.

184  def set_continue(self):
185  # Don't stop except at breakpoints or when finished
186  self.stopframe = self.botframe
187  self.returnframe = None
188  self.quitting = 0
189  if not self.breaks:
190  # no breakpoints; run without debugger overhead
191  sys.settrace(None)
192  try:
193  1 + '' # raise an exception
194  except:
195  frame = sys.exc_info()[2].tb_frame.f_back
196  while frame and frame is not self.botframe:
197  del frame.f_trace
198  frame = frame.f_back
def set_next (   self,
  frame 
)
Stop on the next line in or below the given frame.

Definition at line 157 of file bdb.py.

References Bdb.quitting, Bdb.returnframe, and Bdb.stopframe.

158  def set_next(self, frame):
159  """Stop on the next line in or below the given frame."""
160  self.stopframe = frame
161  self.returnframe = None
162  self.quitting = 0
def set_quit (   self)

Definition at line 199 of file bdb.py.

References Bdb.botframe, Bdb.quitting, Bdb.returnframe, and Bdb.stopframe.

200  def set_quit(self):
201  self.stopframe = self.botframe
202  self.returnframe = None
203  self.quitting = 1
204  sys.settrace(None)
def set_return (   self,
  frame 
)
Stop when returning from the given frame.

Definition at line 163 of file bdb.py.

References Bdb.quitting, Bdb.returnframe, and Bdb.stopframe.

164  def set_return(self, frame):
165  """Stop when returning from the given frame."""
166  self.stopframe = frame.f_back
167  self.returnframe = frame
168  self.quitting = 0
def set_step (   self)
Stop after one line of code.

Definition at line 151 of file bdb.py.

References Bdb.quitting, Bdb.returnframe, and Bdb.stopframe.

152  def set_step(self):
153  """Stop after one line of code."""
154  self.stopframe = None
155  self.returnframe = None
156  self.quitting = 0
def set_trace (   self)
Start debugging from here.

Definition at line 169 of file bdb.py.

References Bdb.botframe, Bdb.reset(), Bdb.set_step(), and Bdb.trace_dispatch().

170  def set_trace(self):
171  """Start debugging from here."""
172  try:
173  1 + ''
174  except:
175  frame = sys.exc_info()[2].tb_frame.f_back
176  self.reset()
177  while frame:
178  frame.f_trace = self.trace_dispatch
179  self.botframe = frame
180  frame = frame.f_back
181  self.set_step()
182  sys.settrace(self.trace_dispatch)
def stop_here (   self,
  frame 
)

Definition at line 92 of file bdb.py.

References Bdb.botframe, and Bdb.stopframe.

92 
93  def stop_here(self, frame):
94  if self.stopframe is None:
95  return 1
96  if frame is self.stopframe:
97  return 1
98  while frame is not None and frame is not self.stopframe:
99  if frame is self.botframe:
100  return 1
101  frame = frame.f_back
102  return 0
def trace_dispatch (   self,
  frame,
  event,
  arg 
)

Definition at line 43 of file bdb.py.

References Bdb.dispatch_call(), Bdb.dispatch_exception(), Bdb.dispatch_line(), Bdb.dispatch_return(), Bdb.quitting, and Bdb.trace_dispatch().

43 
44  def trace_dispatch(self, frame, event, arg):
45  if self.quitting:
46  return # None
47  if event == 'line':
48  return self.dispatch_line(frame)
49  if event == 'call':
50  return self.dispatch_call(frame, arg)
51  if event == 'return':
52  return self.dispatch_return(frame, arg)
53  if event == 'exception':
54  return self.dispatch_exception(frame, arg)
55  print 'bdb.Bdb.dispatch: unknown debugging event:', `event`
56  return self.trace_dispatch
def user_call (   self,
  frame,
  argument_list 
)
This method is called when there is the remote possibility
that we ever need to stop in this function.

Definition at line 130 of file bdb.py.

131  def user_call(self, frame, argument_list):
132  """This method is called when there is the remote possibility
133  that we ever need to stop in this function."""
134  pass
def user_exception (   self,
  frame,
  exc_type,
  exc_value,
  exc_traceback 
)
This method is called if an exception occurs,
but only if we are to stop at or just below this level.

Definition at line 143 of file bdb.py.

144  def user_exception(self, frame, (exc_type, exc_value, exc_traceback)):
145  """This method is called if an exception occurs,
146  but only if we are to stop at or just below this level."""
147  pass
def user_line (   self,
  frame 
)
This method is called when we stop or break at this line.

Definition at line 135 of file bdb.py.

136  def user_line(self, frame):
137  """This method is called when we stop or break at this line."""
138  pass
def user_return (   self,
  frame,
  return_value 
)
This method is called when a return trap is set here.

Definition at line 139 of file bdb.py.

140  def user_return(self, frame, return_value):
141  """This method is called when a return trap is set here."""
142  pass

Field Documentation

botframe

Definition at line 38 of file bdb.py.

breaks

Definition at line 22 of file bdb.py.

currentbp

Definition at line 113 of file bdb.py.

fncache

Definition at line 23 of file bdb.py.

quitting

Definition at line 41 of file bdb.py.

returnframe

Definition at line 40 of file bdb.py.

stopframe

Definition at line 39 of file bdb.py.


The documentation for this class was generated from the following file: