diff options
author | Guido van Rossum <guido@python.org> | 1995-02-27 13:13:40 +0000 |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1995-02-27 13:13:40 +0000 |
commit | 3393e709a43b96c933819c5a3832d129f5d36a53 (patch) | |
tree | f7c8210c1bb24b73b2b94e49c52731b84099d769 /Lib/bdb.py | |
parent | a4849aa2c4d5d30cdbe272f339b4cb35feae7829 (diff) | |
download | cpython-3393e709a43b96c933819c5a3832d129f5d36a53.tar.gz |
handle class exceptions; added runeval; made runctx obsolete
Diffstat (limited to 'Lib/bdb.py')
-rw-r--r-- | Lib/bdb.py | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/Lib/bdb.py b/Lib/bdb.py index 0d139d45f4..6d0536db69 100644 --- a/Lib/bdb.py +++ b/Lib/bdb.py @@ -270,36 +270,59 @@ class Bdb: # Basic Debugger # The following two methods can be called by clients to use # a debugger to debug a statement, given as a string. - def run(self, cmd): - import __main__ - dict = __main__.__dict__ - self.runctx(cmd, dict, dict) + def run(self, cmd, globals=None, locals=None): + if globals is None: + import __main__ + globals = __main__.__dict__ + if locals is None: + locals = globals + self.reset() + sys.settrace(self.trace_dispatch) + try: + try: + exec cmd + '\n' in globals, locals + except BdbQuit: + pass + finally: + self.quitting = 1 + sys.settrace(None) - def runctx(self, cmd, globals, locals): + def runeval(self, expr, globals=None, locals=None): + if globals is None: + import __main__ + globals = __main__.__dict__ + if locals is None: + locals = globals self.reset() sys.settrace(self.trace_dispatch) try: try: - exec(cmd + '\n', globals, locals) + return eval(expr + '\n', globals, locals) except BdbQuit: pass finally: self.quitting = 1 sys.settrace(None) + def runctx(self, cmd, globals, locals): + # B/W compatibility + self.run(cmd, globals, locals) + # This method is more useful to debug a single function call. def runcall(self, func, *args): self.reset() sys.settrace(self.trace_dispatch) + res = None try: try: - apply(func, args) + res = apply(func, args) except BdbQuit: pass finally: self.quitting = 1 sys.settrace(None) + return res def set_trace(): |