Files
Artem Mukhin 52e6ffff25 PY-48037 Merge Attach to process updates from PyDev to support Python 3.10 and 3.11 on Windows
Manually picked from PyDev revision `26864816cbfcf002a99913bcc31ebef48042a4ac`.

Notable changes:

* Inject DLL to Python process fa163ccc2d
* Support for Python 3.10 bdec612183
* Support for Python 3.11 8ab57600de

GitOrigin-RevId: 720414ca39573b3f8b4b9e1b5b72f33eb024ccc1
2023-07-03 19:12:31 +00:00

80 lines
2.4 KiB
Python

import sys
import os
def process_command_line(argv):
setup = {}
setup['port'] = 5678 # Default port for PyDev remote debugger
setup['pid'] = 0
setup['host'] = '127.0.0.1'
setup['protocol'] = ''
setup['debug-mode'] = ''
i = 0
while i < len(argv):
if argv[i] == '--port':
del argv[i]
setup['port'] = int(argv[i])
del argv[i]
elif argv[i] == '--pid':
del argv[i]
setup['pid'] = int(argv[i])
del argv[i]
elif argv[i] == '--host':
del argv[i]
setup['host'] = argv[i]
del argv[i]
elif argv[i] == '--protocol':
del argv[i]
setup['protocol'] = argv[i]
del argv[i]
elif argv[i] == '--debug-mode':
del argv[i]
setup['debug-mode'] = argv[i]
del argv[i]
if not setup['pid']:
sys.stderr.write('Expected --pid to be passed.\n')
sys.exit(1)
return setup
def main(setup):
sys.path.append(os.path.dirname(__file__))
import add_code_to_python_process
show_debug_info_on_target_process = 0
pydevd_dirname = os.path.dirname(os.path.dirname(__file__))
if sys.platform == 'win32':
setup['pythonpath'] = pydevd_dirname.replace('\\', '/')
setup['pythonpath2'] = os.path.dirname(__file__).replace('\\', '/')
python_code = '''import sys;
sys.path.append("%(pythonpath)s");
sys.path.append("%(pythonpath2)s");
import attach_script;
attach_script.attach(port=%(port)s, host="%(host)s", protocol="%(protocol)s", debug_mode="%(debug-mode)s");
'''.replace('\r\n', '').replace('\r', '').replace('\n', '')
else:
setup['pythonpath'] = pydevd_dirname
setup['pythonpath2'] = os.path.dirname(__file__)
# We have to pass it a bit differently for gdb
python_code = '''import sys;
sys.path.append(\\\"%(pythonpath)s\\\");
sys.path.append(\\\"%(pythonpath2)s\\\");
import attach_script;
attach_script.attach(port=%(port)s, host=\\\"%(host)s\\\", protocol=\\\"%(protocol)s\\\", debug_mode=\\\"%(debug-mode)s\\\");
'''.replace('\r\n', '').replace('\r', '').replace('\n', '')
python_code = python_code % setup
add_code_to_python_process.run_python_code(
setup['pid'], python_code, connect_debugger_tracing=True, show_debug_info=show_debug_info_on_target_process)
if __name__ == '__main__':
main(process_command_line(sys.argv[1:]))