diff options
author | Georg Brandl <georg@python.org> | 2010-07-30 18:08:12 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2010-07-30 18:08:12 (GMT) |
commit | 5ed2b5a92ab4f5c4c8ad77ec95a4f7add3083432 (patch) | |
tree | 294ffe4619074d526f2d4d9743d75de0b448c076 | |
parent | e38de851eba7d47d3cf93db2feee0d91e361a3e1 (diff) | |
download | cpython-5ed2b5a92ab4f5c4c8ad77ec95a4f7add3083432.zip cpython-5ed2b5a92ab4f5c4c8ad77ec95a4f7add3083432.tar.gz cpython-5ed2b5a92ab4f5c4c8ad77ec95a4f7add3083432.tar.bz2 |
Fix source finding if the given frame is a module-level frame.
-rwxr-xr-x | Lib/pdb.py | 13 |
1 files changed, 11 insertions, 2 deletions
@@ -105,6 +105,15 @@ def find_function(funcname, filename): fp.close() return answer +def getsourcelines(obj): + lines, lineno = inspect.findsource(obj) + if inspect.isframe(obj) and lineno == 0 and \ + obj.f_globals is obj.f_locals: + # must be a module frame: do not try to cut a block out of it + return lines, 0 + elif inspect.ismodule(obj): + return lines, 0 + return inspect.getblock(lines[lineno:]), lineno+1 # Interaction prompt line will separate file and call info from code # text using value of line_prefix string. A newline and arrow may @@ -1048,7 +1057,7 @@ class Pdb(bdb.Bdb, cmd.Cmd): filename = self.curframe.f_code.co_filename breaklist = self.get_file_breaks(filename) try: - lines, lineno = inspect.getsourcelines(self.curframe) + lines, lineno = getsourcelines(self.curframe) except IOError as err: self.error(err) return @@ -1064,7 +1073,7 @@ class Pdb(bdb.Bdb, cmd.Cmd): except: return try: - lines, lineno = inspect.getsourcelines(obj) + lines, lineno = getsourcelines(obj) except (IOError, TypeError) as err: self.error(err) return |