summaryrefslogtreecommitdiffstats
path: root/Lib/bdb.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1997-07-11 13:42:50 (GMT)
committerGuido van Rossum <guido@python.org>1997-07-11 13:42:50 (GMT)
commitff02e1ddde1a0f4183b534aa20258792fe9e9b48 (patch)
tree9967661ee3fa98b25058d9571e722526d0e09d70 /Lib/bdb.py
parent65c28b7efb290f5eadf538f14514c9a48bb0f1d7 (diff)
downloadcpython-ff02e1ddde1a0f4183b534aa20258792fe9e9b48.zip
cpython-ff02e1ddde1a0f4183b534aa20258792fe9e9b48.tar.gz
cpython-ff02e1ddde1a0f4183b534aa20258792fe9e9b48.tar.bz2
Support for conditional breakpoints (Jim Fulton).
Diffstat (limited to 'Lib/bdb.py')
-rw-r--r--Lib/bdb.py20
1 files changed, 16 insertions, 4 deletions
diff --git a/Lib/bdb.py b/Lib/bdb.py
index b2c827c..124d19a 100644
--- a/Lib/bdb.py
+++ b/Lib/bdb.py
@@ -16,6 +16,7 @@ class Bdb: # Basic Debugger
def __init__(self):
self.breaks = {}
+ self.cbreaks = {}
def reset(self):
import linecache
@@ -85,11 +86,16 @@ class Bdb: # Basic Debugger
return 0
def break_here(self, frame):
- if not self.breaks.has_key(frame.f_code.co_filename):
+ filename=frame.f_code.co_filename
+ if not self.breaks.has_key(filename):
return 0
- if not frame.f_lineno in \
- self.breaks[frame.f_code.co_filename]:
+ lineno=frame.f_lineno
+ if not lineno in self.breaks[filename]:
return 0
+ if self.cbreaks.has_key((filename, lineno)):
+ cond=self.cbreaks[filename, lineno]
+ return eval(cond, frame.f_globals,
+ frame.f_locals)
return 1
def break_anywhere(self, frame):
@@ -178,7 +184,7 @@ class Bdb: # Basic Debugger
# error message is something went wrong, None if all is well.
# Call self.get_*break*() to see the breakpoints.
- def set_break(self, filename, lineno):
+ def set_break(self, filename, lineno, cond=None):
import linecache # Import as late as possible
line = linecache.getline(filename, lineno)
if not line:
@@ -189,6 +195,7 @@ class Bdb: # Basic Debugger
if lineno in list:
return 'There is already a breakpoint there!'
list.append(lineno)
+ if cond is not None: self.cbreaks[filename, lineno]=cond
def clear_break(self, filename, lineno):
if not self.breaks.has_key(filename):
@@ -198,16 +205,21 @@ class Bdb: # Basic Debugger
self.breaks[filename].remove(lineno)
if not self.breaks[filename]:
del self.breaks[filename]
+ try: del self.cbreaks[filename, lineno]
+ except: pass
def clear_all_file_breaks(self, filename):
if not self.breaks.has_key(filename):
return 'There are no breakpoints in that file!'
del self.breaks[filename]
+ for f,l in self.cbreaks.keys():
+ if f==filename: del self.cbreaks[f,l]
def clear_all_breaks(self):
if not self.breaks:
return 'There are no breakpoints!'
self.breaks = {}
+ self.cbreaks = {}
def get_break(self, filename, lineno):
return self.breaks.has_key(filename) and \