MCPcopy Index your code
hub / github.com/python/cpython / main

Function main

Lib/pdb.py:3646–3701  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3644 return opts, args
3645
3646def main():
3647 opts, args = parse_args()
3648
3649 if getattr(opts, 'pid', None) is not None:
3650 try:
3651 attach(opts.pid, opts.commands)
3652 except RuntimeError:
3653 print(
3654 f"Cannot attach to pid {opts.pid}, please make sure that the process exists "
3655 "and is using the same Python version."
3656 )
3657 sys.exit(1)
3658 except PermissionError:
3659 exit_with_permission_help_text()
3660 return
3661 elif getattr(opts, 'module', None) is not None:
3662 file = opts.module
3663 target = _ModuleTarget(file)
3664 else:
3665 file = args.pop(0)
3666 if file.endswith('.pyz'):
3667 target = _ZipTarget(file)
3668 else:
3669 target = _ScriptTarget(file)
3670
3671 sys.argv[:] = [file] + args # Hide "pdb.py" and pdb options from argument list
3672
3673 # Note on saving/restoring sys.argv: it's a good idea when sys.argv was
3674 # modified by the script being debugged. It's a bad idea when it was
3675 # changed by the user from the command line. There is a "restart" command
3676 # which allows explicit specification of command line arguments.
3677 pdb = Pdb(mode='cli', backend='monitoring', colorize=True)
3678 pdb.rcLines.extend(opts.commands)
3679 while True:
3680 try:
3681 pdb._run(target)
3682 except Restart:
3683 print("Restarting", target, "with arguments:")
3684 print("\t" + " ".join(sys.argv[1:]))
3685 except SystemExit as e:
3686 # In most cases SystemExit does not warrant a post-mortem session.
3687 print("The program exited via sys.exit(). Exit status:", end=' ')
3688 print(e)
3689 except BaseException as e:
3690 traceback.print_exception(e, colorize=_colorize.can_colorize())
3691 print("Uncaught exception. Entering post mortem debugging")
3692 print("Running 'cont' or 'step' will restart the program")
3693 try:
3694 pdb.interaction(None, e)
3695 except Restart:
3696 print("Restarting", target, "with arguments:")
3697 print("\t" + " ".join(sys.argv[1:]))
3698 continue
3699 if pdb._user_requested_quit:
3700 break
3701 print("The program finished and will be restarted")
3702
3703

Callers

nothing calls this directly

Calls 14

_runMethod · 0.95
interactionMethod · 0.95
attachFunction · 0.85
_ModuleTargetClass · 0.85
_ZipTargetClass · 0.85
_ScriptTargetClass · 0.85
PdbClass · 0.85
parse_argsFunction · 0.70
exitMethod · 0.45
popMethod · 0.45
endswithMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…