summaryrefslogtreecommitdiffstats
path: root/Lib/pdb.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/pdb.py')
-rwxr-xr-xLib/pdb.py50
1 files changed, 47 insertions, 3 deletions
diff --git a/Lib/pdb.py b/Lib/pdb.py
index fa2e1ec..bb669a0 100755
--- a/Lib/pdb.py
+++ b/Lib/pdb.py
@@ -120,7 +120,10 @@ def find_function(funcname, filename):
try:
fp = tokenize.open(filename)
except OSError:
- return None
+ lines = linecache.getlines(filename)
+ if not lines:
+ return None
+ fp = io.StringIO(''.join(lines))
funcdef = ""
funcstart = None
# consumer of this info expects the first line to be 1
@@ -237,6 +240,44 @@ class _ModuleTarget(_ExecutableTarget):
)
+class _ZipTarget(_ExecutableTarget):
+ def __init__(self, target):
+ import runpy
+
+ self._target = os.path.realpath(target)
+ sys.path.insert(0, self._target)
+ try:
+ _, self._spec, self._code = runpy._get_main_module_details()
+ except ImportError as e:
+ print(f"ImportError: {e}")
+ sys.exit(1)
+ except Exception:
+ traceback.print_exc()
+ sys.exit(1)
+
+ def __repr__(self):
+ return self._target
+
+ @property
+ def filename(self):
+ return self._code.co_filename
+
+ @property
+ def code(self):
+ return self._code
+
+ @property
+ def namespace(self):
+ return dict(
+ __name__='__main__',
+ __file__=os.path.normcase(os.path.abspath(self.filename)),
+ __package__=self._spec.parent,
+ __loader__=self._spec.loader,
+ __spec__=self._spec,
+ __builtins__=__builtins__,
+ )
+
+
class _PdbInteractiveConsole(code.InteractiveConsole):
def __init__(self, ns, message):
self._message = message
@@ -1076,7 +1117,7 @@ class Pdb(bdb.Bdb, cmd.Cmd):
if f:
fname = f
item = parts[1]
- answer = find_function(item, fname)
+ answer = find_function(item, self.canonic(fname))
return answer or failed
def checkline(self, filename, lineno):
@@ -2282,7 +2323,10 @@ def main():
if not opts.args:
parser.error("no module or script to run")
file = opts.args.pop(0)
- target = _ScriptTarget(file)
+ if file.endswith('.pyz'):
+ target = _ZipTarget(file)
+ else:
+ target = _ScriptTarget(file)
sys.argv[:] = [file] + opts.args # Hide "pdb.py" and pdb options from argument list