summaryrefslogtreecommitdiffstats
path: root/Lib/bdb.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1994-08-01 11:34:53 (GMT)
committerGuido van Rossum <guido@python.org>1994-08-01 11:34:53 (GMT)
commitb6775db241f5fe5e3dc2ca09fc6c9e6164d4b2af (patch)
tree9362939305b2d088b8f19a530c9015d886bc2801 /Lib/bdb.py
parent2979b01ff88ac4c5b316d9bf98edbaaaffac8e24 (diff)
downloadcpython-b6775db241f5fe5e3dc2ca09fc6c9e6164d4b2af.zip
cpython-b6775db241f5fe5e3dc2ca09fc6c9e6164d4b2af.tar.gz
cpython-b6775db241f5fe5e3dc2ca09fc6c9e6164d4b2af.tar.bz2
Merge alpha100 branch back to main trunk
Diffstat (limited to 'Lib/bdb.py')
-rw-r--r--Lib/bdb.py47
1 files changed, 38 insertions, 9 deletions
diff --git a/Lib/bdb.py b/Lib/bdb.py
index 6b3eab9..9b50767 100644
--- a/Lib/bdb.py
+++ b/Lib/bdb.py
@@ -17,6 +17,8 @@ class Bdb: # Basic Debugger
self.breaks = {}
def reset(self):
+ import linecache
+ linecache.checkcache()
self.botframe = None
self.stopframe = None
self.returnframe = None
@@ -134,11 +136,35 @@ class Bdb: # Basic Debugger
self.returnframe = frame
self.quitting = 0
+ def set_trace(self):
+ # Start debugging from here
+ try:
+ 1 + ''
+ except:
+ frame = sys.exc_traceback.tb_frame.f_back
+ self.reset()
+ while frame:
+ frame.f_trace = self.trace_dispatch
+ self.botframe = frame
+ frame = frame.f_back
+ self.set_step()
+ sys.settrace(self.trace_dispatch)
+
def set_continue(self):
# Don't stop except at breakpoints or when finished
self.stopframe = self.botframe
self.returnframe = None
self.quitting = 0
+ if not self.breaks:
+ # no breakpoints; run without debugger overhead
+ sys.settrace(None)
+ try:
+ 1 + '' # raise an exception
+ except:
+ frame = sys.exc_traceback.tb_frame.f_back
+ while frame and frame is not self.botframe:
+ del frame.f_trace
+ frame = frame.f_back
def set_quit(self):
self.stopframe = self.botframe
@@ -177,7 +203,7 @@ class Bdb: # Basic Debugger
return 'There are no breakpoints in that file!'
del self.breaks[filename]
- def clear_all_breaks(self, filename, lineno):
+ def clear_all_breaks(self):
if not self.breaks:
return 'There are no breakpoints!'
self.breaks = {}
@@ -217,11 +243,14 @@ class Bdb: # Basic Debugger
#
def format_stack_entry(self, frame_lineno):
- import codehack, linecache, repr, string
+ import linecache, repr, string
frame, lineno = frame_lineno
filename = frame.f_code.co_filename
s = filename + '(' + `lineno` + ')'
- s = s + codehack.getcodename(frame.f_code)
+ if frame.f_code.co_name:
+ s = s + frame.f_code.co_name
+ else:
+ s = s + "<lambda>"
if frame.f_locals.has_key('__args__'):
args = frame.f_locals['__args__']
if args is not None:
@@ -269,17 +298,19 @@ class Bdb: # Basic Debugger
sys.settrace(None)
+def set_trace():
+ Bdb().set_trace()
+
# -------------------- testing --------------------
class Tdb(Bdb):
def user_call(self, frame, args):
- import codehack
- name = codehack.getcodename(frame.f_code)
+ name = frame.f_code.co_name
if not name: name = '???'
print '+++ call', name, args
def user_line(self, frame):
- import linecache, string, codehack
- name = codehack.getcodename(frame.f_code)
+ import linecache, string
+ name = frame.f_code.co_name
if not name: name = '???'
fn = frame.f_code.co_filename
line = linecache.getline(fn, frame.f_lineno)
@@ -300,7 +331,5 @@ def bar(a):
return a/2
def test():
- import linecache
- linecache.checkcache()
t = Tdb()
t.run('import bdb; bdb.foo(10)')