[3.10] bpo-44461: Check early that a pdb target is valid for execution. (GH-27227) (GH-27399)
Automerge-Triggered-By: GH:jaraco
diff --git a/Lib/pdb.py b/Lib/pdb.py
index 1b4ff54..9432111 100755
--- a/Lib/pdb.py
+++ b/Lib/pdb.py
@@ -1694,6 +1694,14 @@ def main():
print('Error:', mainpyfile, 'does not exist')
sys.exit(1)
+ if run_as_module:
+ import runpy
+ try:
+ runpy._get_module_details(mainpyfile)
+ except Exception:
+ traceback.print_exc()
+ sys.exit(1)
+
sys.argv[:] = args # Hide "pdb.py" and pdb options from argument list
if not run_as_module: