summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1992-01-27 16:59:34 (GMT)
committerGuido van Rossum <guido@python.org>1992-01-27 16:59:34 (GMT)
commitfac6da22ff19cff2c39d0a571442242898ae70d6 (patch)
tree4ae7b84b2ee61232f052c2cac9b25241f56f0211 /Lib
parentd7d8cd44c1bae8f9026474177fa31fa5e0a0da1e (diff)
downloadcpython-fac6da22ff19cff2c39d0a571442242898ae70d6.zip
cpython-fac6da22ff19cff2c39d0a571442242898ae70d6.tar.gz
cpython-fac6da22ff19cff2c39d0a571442242898ae70d6.tar.bz2
Added a method "format_stack_entry" to be used by derived classes.
Forget about the temp file.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/bdb.py37
1 files changed, 22 insertions, 15 deletions
diff --git a/Lib/bdb.py b/Lib/bdb.py
index 693387b..dfc41d9 100644
--- a/Lib/bdb.py
+++ b/Lib/bdb.py
@@ -6,7 +6,6 @@
# and 'wdb', a window-oriented debugger.
# And of course... you can roll your own!
-
import sys
BdbQuit = 'bdb.BdbQuit' # Exception to give up completely
@@ -217,12 +216,32 @@ class Bdb: # Basic Debugger
t = t.tb_next
return stack, i
+ #
+
+ def format_stack_entry(self, (frame, lineno)):
+ import codehack, linecache, repr, string
+ filename = frame.f_code.co_filename
+ s = filename + '(' + `lineno` + ')'
+ s = s + codehack.getcodename(frame.f_code)
+ if frame.f_locals.has_key('__args__'):
+ args = frame.f_locals['__args__']
+ if args is not None:
+ s = s + repr.repr(args)
+ if frame.f_locals.has_key('__return__'):
+ rv = frame.f_locals['__return__']
+ s = s + '->'
+ s = s + repr.repr(rv)
+ line = linecache.getline(filename, lineno)
+ if line: s = s + ': ' + string.strip(line)
+ return s
+
# The following two functions can be called by clients to use
# a debugger to debug a statement, given as a string.
def run(self, cmd):
- modname = self.writetempfile(cmd)
- self.runctx('import ' + modname + '\n', {}, {})
+ import __main__
+ dict = __main__.__dict__
+ self.runctx(cmd, dict, dict)
def runctx(self, cmd, globals, locals):
self.reset()
@@ -237,18 +256,6 @@ class Bdb: # Basic Debugger
del sys.trace
# XXX What to do if the command finishes normally?
- def writetempfile(self, cmd):
- import os
- modname = 'bdb' + `os.getpid()`
- filename = '/tmp/' + modname + '.py'
- f = open(filename, 'w')
- f.write(cmd + '\n')
- f.close()
- import sys
- if sys.modules.has_key(modname): del sys.modules[modname]
- if '/tmp' not in sys.path: sys.path.insert(0, '/tmp')
- return modname
-
# -------------------- testing --------------------