def _process_debug_options(self, opts): """Process the launch arguments to configure the debugger.""" if opts.get('MULTIPROCESS', False): if not options.multiprocess: options.multiprocess = True multiproc.listen_for_subprocesses() self.start_subprocess_notifier()
def setup_connection(): opts = ptvsd.options pydevd.apply_debugger_options({ 'server': not opts.client, 'client': opts.host, 'port': opts.port, 'multiprocess': opts.multiprocess, }) if opts.multiprocess: listen_for_subprocesses() # We need to set up sys.argv[0] before invoking attach() or enable_attach(), # because they use it to report the 'process' event. Thus, we can't rely on # run_path() and run_module() doing that, even though they will eventually. if opts.target_kind == 'code': sys.argv[0] = '-c' elif opts.target_kind == 'file': sys.argv[0] = opts.target elif opts.target_kind == 'module': # Add current directory to path, like Python itself does for -m. This must # be in place before trying to use find_spec below to resolve submodules. sys.path.insert(0, '') # We want to do the same thing that run_module() would do here, without # actually invoking it. On Python 3, it's exposed as a public API, but # on Python 2, we have to invoke a private function in runpy for this. # Either way, if it fails to resolve for any reason, just leave argv as is. try: if sys.version_info >= (3,): from importlib.util import find_spec spec = find_spec(opts.target) if spec is not None: sys.argv[0] = spec.origin else: _, _, _, sys.argv[0] = runpy._get_module_details(opts.target) except Exception: ptvsd.log.exception('Error determining module path for sys.argv') else: assert False ptvsd.log.debug('sys.argv after patching: {0!r}', sys.argv) addr = (opts.host, opts.port) global daemon if opts.no_debug: daemon = ptvsd.runner.Daemon() if not daemon.wait_for_launch(addr): return elif opts.client: daemon = ptvsd._remote.attach(addr) else: daemon = ptvsd._remote.enable_attach(addr) if opts.wait: ptvsd.wait_for_attach()
def setup_connection(): opts = ptvsd.options pydevd.apply_debugger_options({ 'server': not opts.client, 'client': opts.host, 'port': opts.port, 'multiprocess': opts.multiprocess, }) if opts.multiprocess: listen_for_subprocesses() # We need to set up sys.argv[0] before invoking attach() or enable_attach(), # because they use it to report the 'process' event. Thus, we can't rely on # run_path() and run_module() doing that, even though they will eventually. if opts.target_kind == 'code': sys.argv[0] = '-c' elif opts.target_kind == 'file': sys.argv[0] = opts.target elif opts.target_kind == 'module': # Add current directory to path, like Python itself does for -m. This must # be in place before trying to use find_spec below to resolve submodules. sys.path.insert(0, '') # We want to do the same thing that run_module() would do here, without # actually invoking it. On Python 3, it's exposed as a public API, but # on Python 2, we have to invoke a private function in runpy for this. # Either way, if it fails to resolve for any reason, just leave argv as is. try: if sys.version_info >= (3,): from importlib.util import find_spec spec = find_spec(opts.target) if spec is not None: sys.argv[0] = spec.origin else: _, _, _, sys.argv[0] = runpy._get_module_details(opts.target) except Exception: ptvsd.log.exception('Error determining module path for sys.argv') else: assert False ptvsd.log.debug('sys.argv after patching: {0!r}', sys.argv) addr = (opts.host, opts.port) global daemon if opts.no_debug: daemon = ptvsd.runner.Daemon() if not daemon.wait_for_launch(addr): return elif opts.client: daemon = ptvsd._remote.attach(addr) else: daemon = ptvsd._remote.enable_attach(addr) if opts.wait: ptvsd.wait_for_attach()
def _parse_args(prog, argv): parser = argparse.ArgumentParser(prog=prog) parser.add_argument('--nodebug', action='store_true') parser.add_argument('--client', action='store_true') parser.add_argument('--host', required=True) parser.add_argument('--port', type=int, required=True) def port_range(arg): arg = tuple(int(s) for s in arg.split('-')) if len(arg) != 2: raise ValueError return arg parser.add_argument('--multiprocess', action='store_true') parser.add_argument('--subprocess-of', type=int, help=argparse.SUPPRESS) parser.add_argument('--subprocess-notify', type=int, help=argparse.SUPPRESS) target = parser.add_mutually_exclusive_group(required=True) target.add_argument('-m', dest='module') target.add_argument('-c', dest='code') target.add_argument('--pid', type=int) target.add_argument('filename', nargs='?') parser.add_argument('--single-session', action='store_true') parser.add_argument('--wait', action='store_true') parser.add_argument('-V', '--version', action='version') parser.version = __version__ args = parser.parse_args(argv) ns = vars(args) options.host = ns.pop('host', None) options.port = ns.pop('port') options.client = ns.pop('client') args.address = (Address.as_client if options.client else Address.as_server)(options.host, options.port) # noqa if ns['multiprocess']: options.multiprocess = True multiproc.listen_for_subprocesses() options.subprocess_of = ns.pop('subprocess_of') options.subprocess_notify = ns.pop('subprocess_notify') pid = ns.pop('pid') module = ns.pop('module') filename = ns.pop('filename') code = ns.pop('code') if pid is not None: args.name = pid args.kind = 'pid' elif module is not None: args.name = module args.kind = 'module' elif code is not None: options.code = code args.name = 'ptvsd.run_code' args.kind = 'module' else: args.name = filename args.kind = 'script' return args
def _parse_args(prog, argv): parser = argparse.ArgumentParser(prog=prog) parser.add_argument('--nodebug', action='store_true') parser.add_argument('--client', action='store_true') parser.add_argument('--host', required=True) parser.add_argument('--port', type=int, required=True) def port_range(arg): arg = tuple(int(s) for s in arg.split('-')) if len(arg) != 2: raise ValueError return arg parser.add_argument('--multiprocess', action='store_true') parser.add_argument('--subprocess-of', type=int, help=argparse.SUPPRESS) parser.add_argument('--subprocess-notify', type=int, help=argparse.SUPPRESS) target = parser.add_mutually_exclusive_group(required=True) target.add_argument('-m', dest='module') target.add_argument('-c', dest='code') target.add_argument('--pid', type=int) target.add_argument('filename', nargs='?') parser.add_argument('--single-session', action='store_true') parser.add_argument('--wait', action='store_true') parser.add_argument('-V', '--version', action='version') parser.version = __version__ args = parser.parse_args(argv) ns = vars(args) options.host = ns.pop('host', None) options.port = ns.pop('port') options.client = ns.pop('client') args.address = (Address.as_client if options.client else Address.as_server)(options.host, options.port) # noqa if ns['multiprocess']: options.multiprocess = True multiproc.listen_for_subprocesses() options.subprocess_of = ns.pop('subprocess_of') options.subprocess_notify = ns.pop('subprocess_notify') pid = ns.pop('pid') module = ns.pop('module') filename = ns.pop('filename') code = ns.pop('code') if pid is not None: args.name = pid args.kind = 'pid' elif module is not None: args.name = module args.kind = 'module' elif code is not None: options.code = code args.name = 'ptvsd.run_code' args.kind = 'module' else: args.name = filename args.kind = 'script' return args