microsoft / vscode-python

Python extension for Visual Studio Code
https://aka.ms/pvsc-marketplace
MIT License
4.28k stars 1.17k forks source link

Cannot attach to a process for debugging #21673

Open chance-sematic opened 1 year ago

chance-sematic commented 1 year ago

Type: Bug

Behaviour

Seeing the logs in output when attaching python debugger to a process:

Expected vs. Actual

Debugger can attach to a process successfully.

Steps to reproduce:

Using the following launch config to attach debugger to a proces: { "name": "Python: Attach using Process Id", "type": "python", "request": "attach", "processId": "${command:pickProcess}", "justMyCode": true },

Diagnostic data

Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

``` Attaching to PID: 17645 (elapsed: 1.01s). Attaching to PID: 17645 (elapsed: 2.01s). Attach to PID failed. --- Starting attach to pid: 17645 --- (lldb) process attach --pid 17645 Process 17645 stopped * thread `#1`, queue = 'com.apple.main-thread', stop reason = signal SIGSTOP frame #0: 0x000000019b5c4a00 libsystem_kernel.dylib`__select + 8 libsystem_kernel.dylib`: -> 0x19b5c4a00 <+8>: b.lo 0x19b5c4a20 ; <+40> 0x19b5c4a04 <+12>: pacibsp 0x19b5c4a08 <+16>: stp x29, x30, [sp, #-0x10]! 0x19b5c4a0c <+20>: mov x29, sp Target 0: (python3.8) stopped. Executable module set to "/private/var/tmp/_bazel_user1/c02f1d320b442821a596168a522c3417/external/python3_8_aarch64-apple-darwin/bin/python3.8". Architecture set to: arm64e-apple-macosx-. (lldb) command script import "/Users/user1/.vscode/extensions/ms-python.python-2023.6.1/pythonFiles/lib/python/debugpy/_vendored/pydevd/pydevd_attach_to_process/linux_and_mac/lldb_prepare.py" (lldb) load_lib_and_attach "/Users/user1/.vscode/extensions/ms-python.python-2023.6.1/pythonFiles/lib/python/debugpy/_vendored/pydevd/pydevd_attach_to_process/attach_x86_64.dylib" 0 "import codecs;import json;import sys;decode = lambda s: codecs.utf_8_decode(bytearray(s))[0] if s is not None else None;script_dir = decode([47, 85, 115, 101, 114, 115, 47, 97, 110, 99, 104, 47, 46, 118, 115, 99, 111, 100, 101, 47, 101, 120, 116, 101, 110, 115, 105, 111, 110, 115, 47, 109, 115, 45, 112, 121, 116, 104, 111, 110, 46, 112, 121, 116, 104, 111, 110, 45, 50, 48, 50, 51, 46, 54, 46, 49, 47, 112, 121, 116, 104, 111, 110, 70, 105, 108, 101, 115, 47, 108, 105, 98, 47, 112, 121, 116, 104, 111, 110, 47, 100, 101, 98, 117, 103, 112, 121, 47, 97, 100, 97, 112, 116, 101, 114, 47, 46, 46, 47, 46, 46, 47, 100, 101, 98, 117, 103, 112, 121, 47, 46, 46, 47, 100, 101, 98, 117, 103, 112, 121, 47, 115, 101, 114, 118, 101, 114]);setup = json.loads(decode([123, 34, 109, 111, 100, 101, 34, 58, 32, 34, 99, 111, 110, 110, 101, 99, 116, 34, 44, 32, 34, 97, 100, 100, 114, 101, 115, 115, 34, 58, 32, 91, 34, 49, 50, 55, 46, 48, 46, 48, 46, 49, 34, 44, 32, 53, 53, 50, 57, 52, 93, 44, 32, 34, 119, 97, 105, 116, 95, 102, 111, 114, 95, 99, 108, 105, 101, 110, 116, 34, 58, 32, 102, 97, 108, 115, 101, 44, 32, 34, 108, 111, 103, 95, 116, 111, 34, 58, 32, 110, 117, 108, 108, 44, 32, 34, 97, 100, 97, 112, 116, 101, 114, 95, 97, 99, 99, 101, 115, 115, 95, 116, 111, 107, 101, 110, 34, 58, 32, 34, 49, 55, 97, 49, 48, 98, 97, 48, 53, 100, 101, 97, 99, 49, 51, 97, 98, 56, 53, 54, 98, 52, 55, 51, 52, 57, 49, 98, 49, 100, 98, 52, 53, 49, 49, 102, 52, 56, 54, 100, 101, 102, 50, 102, 49, 56, 57, 50, 56, 50, 53, 57, 51, 52, 102, 56, 57, 54, 49, 97, 97, 98, 98, 52, 34, 125]));sys.path.insert(0, script_dir);import attach_pid_injected;del sys.path[0];attach_pid_injected.attach(setup);" 0 /Users/user1/.vscode/extensions/ms-python.python-2023.6.1/pythonFiles/lib/python/debugpy/_vendored/pydevd/pydevd_attach_to_process/attach_x86_64.dylib success import codecs;import json;import sys;decode = lambda s: codecs.utf_8_decode(bytearray(s))[0] if s is not None else None;script_dir = decode([47, 85, 115, 101, 114, 115, 47, 97, 110, 99, 104, 47, 46, 118, 115, 99, 111, 100, 101, 47, 101, 120, 116, 101, 110, 115, 105, 111, 110, 115, 47, 109, 115, 45, 112, 121, 116, 104, 111, 110, 46, 112, 121, 116, 104, 111, 110, 45, 50, 48, 50, 51, 46, 54, 46, 49, 47, 112, 121, 116, 104, 111, 110, 70, 105, 108, 101, 115, 47, 108, 105, 98, 47, 112, 121, 116, 104, 111, 110, 47, 100, 101, 98, 117, 103, 112, 121, 47, 97, 100, 97, 112, 116, 101, 114, 47, 46, 46, 47, 46, 46, 47, 100, 101, 98, 117, 103, 112, 121, 47, 46, 46, 47, 100, 101, 98, 117, 103, 112, 121, 47, 115, 101, 114, 118, 101, 114]);setup = json.loads(decode([123, 34, 109, 111, 100, 101, 34, 58, 32, 34, 99, 111, 110, 110, 101, 99, 116, 34, 44, 32, 34, 97, 100, 100, 114, 101, 115, 115, 34, 58, 32, 91, 34, 49, 50, 55, 46, 48, 46, 48, 46, 49, 34, 44, 32, 53, 53, 50, 57, 52, 93, 44, 32, 34, 119, 97, 105, 116, 95, 102, 111, 114, 95, 99, 108, 105, 101, 110, 116, 34, 58, 32, 102, 97, 108, 115, 101, 44, 32, 34, 108, 111, 103, 95, 116, 111, 34, 58, 32, 110, 117, 108, 108, 44, 32, 34, 97, 100, 97, 112, 116, 101, 114, 95, 97, 99, 99, 101, 115, 115, 95, 116, 111, 107, 101, 110, 34, 58, 32, 34, 49, 55, 97, 49, 48, 98, 97, 48, 53, 100, 101, 97, 99, 49, 51, 97, 98, 56, 53, 54, 98, 52, 55, 51, 52, 57, 49, 98, 49, 100, 98, 52, 53, 49, 49, 102, 52, 56, 54, 100, 101, 102, 50, 102, 49, 56, 57, 50, 56, 50, 53, 57, 51, 52, 102, 56, 57, 54, 49, 97, 97, 98, 98, 52, 34, 125]));sys.path.insert(0, script_dir);import attach_pid_injected;del sys.path[0];attach_pid_injected.attach(setup); error: expression failed to parse: error: :1:6: use of undeclared identifier 'DoAttach' (int)DoAttach(0, "import codecs;import json;import sys;decode = lambda s: codecs.utf_8_decode(bytearray(s))[0] if s is not None else None;script_dir = decode([47, 85, 115, 101, 114, 115, 47, 97, 110, 99, 104, 47, 46, 118, 115, 99, 111, 100, 101, 47, 101, 120, 116, 101, 110, 115, 105, 111, 110, 115, 47, 109, 115, 45, 112, 121, 116, 104, 111, 110, 46, 112, 121, 116, 104, 111, 110, 45, 50, 48, 50, 51, 46, 54, 46, 49, 47, 112, 121, 116, 104, 111, 110, 70, 105, 108, 101, 115, 47, 108, 105, 98, 47, 112, 121, 116, 104, 111, 110, 47, 100, 101, 98, 117, 103, 112, 121, 47, 97, 100, 97, 112, 116, 101, 114, 47, 46, 46, 47, 46, 46, 47, 100, 101, 98, 117, 103, 112, 121, 47, 46, 46, 47, 100, 101, 98, 117, 103, 112, 121, 47, 115, 101, 114, 118, 101, 114]);setup = json.loads(decode([123, 34, 109, 111, 100, 101, 34, 58, 32, 34, 99, 111, 110, 110, 101, 99, 116, 34, 44, 32, 34, 97, 100, 100, 114, 101, 115, 115, 34, 58, 32, 91, 34, 49, 50, 55, 46, 48, 46, 48, 46, 49, 34, 44, 32, 53, 53, 50, 57, 52, 93, 44, 32, 34, 119, 97, 105, 116, 95, 102, 111, 114, 95, 99, 108, 105, 101, 110, 116, 34, 58, 32, 102, 97, 108, 115, 101, 44, 32, 34, 108, 111, 103, 95, 116, 111, 34, 58, 32, 110, 117, 108, 108, 44, 32, 34, 97, 100, 97, 112, 116, 101, 114, 95, 97, 99, 99, 101, 115, 115, 95, 116, 111, 107, 101, 110, 34, 58, 32, 34, 49, 55, 97, 49, 48, 98, 97, 48, 53, 100, 101, 97, 99, 49, 51, 97, 98, 56, 53, 54, 98, 52, 55, 51, 52, 57, 49, 98, 49, 100, 98, 52, 53, 49, 49, 102, 52, 56, 54, 100, 101, 102, 50, 102, 49, 56, 57, 50, 56, 50, 53, 57, 51, 52, 102, 56, 57, 54, 49, 97, 97, 98, 98, 52, 34, 125]));sys.path.insert(0, script_dir);import attach_pid_injected;del sys.path[0];attach_pid_injected.attach(setup);", 0); ^ (lldb) process detach Process 17645 detached (lldb) script import os; os._exit(1) E+00002.137: Code injection into PID=17645 failed: Traceback (most recent call last): File "/Users/user1/.vscode/extensions/ms-python.python-2023.6.1/pythonFiles/lib/python/debugpy/adapter/../../debugpy/../debugpy/server/cli.py", line 391, in attach_to_pid add_code_to_python_process.run_python_code( File "/Users/user1/.vscode/extensions/ms-python.python-2023.6.1/pythonFiles/lib/python/debugpy/_vendored/pydevd/pydevd_attach_to_process/add_code_to_python_process.py", line 528, in run_python_code_mac subprocess.check_call(' '.join(cmd), shell=True, env=env) File "/Users/user1/.pyenv/versions/3.8.15/lib/python3.8/subprocess.py", line 364, in check_call raise CalledProcessError(retcode, cmd) subprocess.CalledProcessError: Command 'lldb --no-lldbinit --script-language Python -o 'process attach --pid 17645' -o 'command script import "/Users/user1/.vscode/extensions/ms-python.python-2023.6.1/pythonFiles/lib/python/debugpy/_vendored/pydevd/pydevd_attach_to_process/linux_and_mac/lldb_prepare.py"' -o 'load_lib_and_attach "/Users/user1/.vscode/extensions/ms-python.python-2023.6.1/pythonFiles/lib/python/debugpy/_vendored/pydevd/pydevd_attach_to_process/attach_x86_64.dylib" 0 "import codecs;import json;import sys;decode = lambda s: codecs.utf_8_decode(bytearray(s))[0] if s is not None else None;script_dir = decode([47, 85, 115, 101, 114, 115, 47, 97, 110, 99, 104, 47, 46, 118, 115, 99, 111, 100, 101, 47, 101, 120, 116, 101, 110, 115, 105, 111, 110, 115, 47, 109, 115, 45, 112, 121, 116, 104, 111, 110, 46, 112, 121, 116, 104, 111, 110, 45, 50, 48, 50, 51, 46, 54, 46, 49, 47, 112, 121, 116, 104, 111, 110, 70, 105, 108, 101, 115, 47, 108, 105, 98, 47, 112, 121, 116, 104, 111, 110, 47, 100, 101, 98, 117, 103, 112, 121, 47, 97, 100, 97, 112, 116, 101, 114, 47, 46, 46, 47, 46, 46, 47, 100, 101, 98, 117, 103, 112, 121, 47, 46, 46, 47, 100, 101, 98, 117, 103, 112, 121, 47, 115, 101, 114, 118, 101, 114]);setup = json.loads(decode([123, 34, 109, 111, 100, 101, 34, 58, 32, 34, 99, 111, 110, 110, 101, 99, 116, 34, 44, 32, 34, 97, 100, 100, 114, 101, 115, 115, 34, 58, 32, 91, 34, 49, 50, 55, 46, 48, 46, 48, 46, 49, 34, 44, 32, 53, 53, 50, 57, 52, 93, 44, 32, 34, 119, 97, 105, 116, 95, 102, 111, 114, 95, 99, 108, 105, 101, 110, 116, 34, 58, 32, 102, 97, 108, 115, 101, 44, 32, 34, 108, 111, 103, 95, 116, 111, 34, 58, 32, 110, 117, 108, 108, 44, 32, 34, 97, 100, 97, 112, 116, 101, 114, 95, 97, 99, 99, 101, 115, 115, 95, 116, 111, 107, 101, 110, 34, 58, 32, 34, 49, 55, 97, 49, 48, 98, 97, 48, 53, 100, 101, 97, 99, 49, 51, 97, 98, 56, 53, 54, 98, 52, 55, 51, 52, 57, 49, 98, 49, 100, 98, 52, 53, 49, 49, 102, 52, 56, 54, 100, 101, 102, 50, 102, 49, 56, 57, 50, 56, 50, 53, 57, 51, 52, 102, 56, 57, 54, 49, 97, 97, 98, 98, 52, 34, 125]));sys.path.insert(0, script_dir);import attach_pid_injected;del sys.path[0];attach_pid_injected.attach(setup);" 0' -o 'process detach' -o 'script import os; os._exit(1)'' returned non-zero exit status 1. Stack where logged: File "/Users/user1/.pyenv/versions/3.8.15/lib/python3.8/runpy.py", line 194, in _run_module_as_main return _run_code(code, main_globals, None, File "/Users/user1/.pyenv/versions/3.8.15/lib/python3.8/runpy.py", line 87, in _run_code exec(code, run_globals) File "/Users/user1/.vscode/extensions/ms-python.python-2023.6.1/pythonFiles/lib/python/debugpy/adapter/../../debugpy/__main__.py", line 39, in cli.main() File "/Users/user1/.vscode/extensions/ms-python.python-2023.6.1/pythonFiles/lib/python/debugpy/adapter/../../debugpy/../debugpy/server/cli.py", line 430, in main run() File "/Users/user1/.vscode/extensions/ms-python.python-2023.6.1/pythonFiles/lib/python/debugpy/adapter/../../debugpy/../debugpy/server/cli.py", line 398, in attach_to_pid log.reraise_exception("Code injection into PID={0} failed:", pid) File "/Users/user1/.vscode/extensions/ms-python.python-2023.6.1/pythonFiles/lib/python/debugpy/adapter/../../debugpy/../debugpy/common/log.py", line 222, in reraise_exception _exception(format_string, *args, **kwargs) Traceback (most recent call last): File "/Users/user1/.pyenv/versions/3.8.15/lib/python3.8/runpy.py", line 194, in _run_module_as_main return _run_code(code, main_globals, None, File "/Users/user1/.pyenv/versions/3.8.15/lib/python3.8/runpy.py", line 87, in _run_code exec(code, run_globals) File "/Users/user1/.vscode/extensions/ms-python.python-2023.6.1/pythonFiles/lib/python/debugpy/adapter/../../debugpy/__main__.py", line 39, in cli.main() File "/Users/user1/.vscode/extensions/ms-python.python-2023.6.1/pythonFiles/lib/python/debugpy/adapter/../../debugpy/../debugpy/server/cli.py", line 430, in main run() File "/Users/user1/.vscode/extensions/ms-python.python-2023.6.1/pythonFiles/lib/python/debugpy/adapter/../../debugpy/../debugpy/server/cli.py", line 398, in attach_to_pid log.reraise_exception("Code injection into PID={0} failed:", pid) File "/Users/user1/.vscode/extensions/ms-python.python-2023.6.1/pythonFiles/lib/python/debugpy/adapter/../../debugpy/../debugpy/server/cli.py", line 391, in attach_to_pid add_code_to_python_process.run_python_code( File "/Users/user1/.vscode/extensions/ms-python.python-2023.6.1/pythonFiles/lib/python/debugpy/_vendored/pydevd/pydevd_attach_to_process/add_code_to_python_process.py", line 528, in run_python_code_mac subprocess.check_call(' '.join(cmd), shell=True, env=env) File "/Users/user1/.pyenv/versions/3.8.15/lib/python3.8/subprocess.py", line 364, in check_call raise CalledProcessError(retcode, cmd) subprocess.CalledProcessError: Command 'lldb --no-lldbinit --script-language Python -o 'process attach --pid 17645' -o 'command script import "/Users/user1/.vscode/extensions/ms-python.python-2023.6.1/pythonFiles/lib/python/debugpy/_vendored/pydevd/pydevd_attach_to_process/linux_and_mac/lldb_prepare.py"' -o 'load_lib_and_attach "/Users/user1/.vscode/extensions/ms-python.python-2023.6.1/pythonFiles/lib/python/debugpy/_vendored/pydevd/pydevd_attach_to_process/attach_x86_64.dylib" 0 "import codecs;import json;import sys;decode = lambda s: codecs.utf_8_decode(bytearray(s))[0] if s is not None else None;script_dir = decode([47, 85, 115, 101, 114, 115, 47, 97, 110, 99, 104, 47, 46, 118, 115, 99, 111, 100, 101, 47, 101, 120, 116, 101, 110, 115, 105, 111, 110, 115, 47, 109, 115, 45, 112, 121, 116, 104, 111, 110, 46, 112, 121, 116, 104, 111, 110, 45, 50, 48, 50, 51, 46, 54, 46, 49, 47, 112, 121, 116, 104, 111, 110, 70, 105, 108, 101, 115, 47, 108, 105, 98, 47, 112, 121, 116, 104, 111, 110, 47, 100, 101, 98, 117, 103, 112, 121, 47, 97, 100, 97, 112, 116, 101, 114, 47, 46, 46, 47, 46, 46, 47, 100, 101, 98, 117, 103, 112, 121, 47, 46, 46, 47, 100, 101, 98, 117, 103, 112, 121, 47, 115, 101, 114, 118, 101, 114]);setup = json.loads(decode([123, 34, 109, 111, 100, 101, 34, 58, 32, 34, 99, 111, 110, 110, 101, 99, 116, 34, 44, 32, 34, 97, 100, 100, 114, 101, 115, 115, 34, 58, 32, 91, 34, 49, 50, 55, 46, 48, 46, 48, 46, 49, 34, 44, 32, 53, 53, 50, 57, 52, 93, 44, 32, 34, 119, 97, 105, 116, 95, 102, 111, 114, 95, 99, 108, 105, 101, 110, 116, 34, 58, 32, 102, 97, 108, 115, 101, 44, 32, 34, 108, 111, 103, 95, 116, 111, 34, 58, 32, 110, 117, 108, 108, 44, 32, 34, 97, 100, 97, 112, 116, 101, 114, 95, 97, 99, 99, 101, 115, 115, 95, 116, 111, 107, 101, 110, 34, 58, 32, 34, 49, 55, 97, 49, 48, 98, 97, 48, 53, 100, 101, 97, 99, 49, 51, 97, 98, 56, 53, 54, 98, 52, 55, 51, 52, 57, 49, 98, 49, 100, 98, 52, 53, 49, 49, 102, 52, 56, 54, 100, 101, 102, 50, 102, 49, 56, 57, 50, 56, 50, 53, 57, 51, 52, 102, 56, 57, 54, 49, 97, 97, 98, 98, 52, 34, 125]));sys.path.insert(0, script_dir);import attach_pid_injected;del sys.path[0];attach_pid_injected.attach(setup);" 0' -o 'process detach' -o 'script import os; os._exit(1)'' returned non-zero exit status 1. Using /Users/user1/.vscode/extensions/ms-python.python-2023.6.1/pythonFiles/lib/python/debugpy/_vendored/pydevd/pydevd_attach_to_process/attach_x86_64.dylib in arch: arm64. Running: lldb --no-lldbinit --script-language Python -o 'process attach --pid 17645' -o 'command script import "/Users/user1/.vscode/extensions/ms-python.python-2023.6.1/pythonFiles/lib/python/debugpy/_vendored/pydevd/pydevd_attach_to_process/linux_and_mac/lldb_prepare.py"' -o 'load_lib_and_attach "/Users/user1/.vscode/extensions/ms-python.python-2023.6.1/pythonFiles/lib/python/debugpy/_vendored/pydevd/pydevd_attach_to_process/attach_x86_64.dylib" 0 "import codecs;import json;import sys;decode = lambda s: codecs.utf_8_decode(bytearray(s))[0] if s is not None else None;script_dir = decode([47, 85, 115, 101, 114, 115, 47, 97, 110, 99, 104, 47, 46, 118, 115, 99, 111, 100, 101, 47, 101, 120, 116, 101, 110, 115, 105, 111, 110, 115, 47, 109, 115, 45, 112, 121, 116, 104, 111, 110, 46, 112, 121, 116, 104, 111, 110, 45, 50, 48, 50, 51, 46, 54, 46, 49, 47, 112, 121, 116, 104, 111, 110, 70, 105, 108, 101, 115, 47, 108, 105, 98, 47, 112, 121, 116, 104, 111, 110, 47, 100, 101, 98, 117, 103, 112, 121, 47, 97, 100, 97, 112, 116, 101, 114, 47, 46, 46, 47, 46, 46, 47, 100, 101, 98, 117, 103, 112, 121, 47, 46, 46, 47, 100, 101, 98, 117, 103, 112, 121, 47, 115, 101, 114, 118, 101, 114]);setup = json.loads(decode([123, 34, 109, 111, 100, 101, 34, 58, 32, 34, 99, 111, 110, 110, 101, 99, 116, 34, 44, 32, 34, 97, 100, 100, 114, 101, 115, 115, 34, 58, 32, 91, 34, 49, 50, 55, 46, 48, 46, 48, 46, 49, 34, 44, 32, 53, 53, 50, 57, 52, 93, 44, 32, 34, 119, 97, 105, 116, 95, 102, 111, 114, 95, 99, 108, 105, 101, 110, 116, 34, 58, 32, 102, 97, 108, 115, 101, 44, 32, 34, 108, 111, 103, 95, 116, 111, 34, 58, 32, 110, 117, 108, 108, 44, 32, 34, 97, 100, 97, 112, 116, 101, 114, 95, 97, 99, 99, 101, 115, 115, 95, 116, 111, 107, 101, 110, 34, 58, 32, 34, 49, 55, 97, 49, 48, 98, 97, 48, 53, 100, 101, 97, 99, 49, 51, 97, 98, 56, 53, 54, 98, 52, 55, 51, 52, 57, 49, 98, 49, 100, 98, 52, 53, 49, 49, 102, 52, 56, 54, 100, 101, 102, 50, 102, 49, 56, 57, 50, 56, 50, 53, 57, 51, 52, 102, 56, 57, 54, 49, 97, 97, 98, 98, 52, 34, 125]));sys.path.insert(0, script_dir);import attach_pid_injected;del sys.path[0];attach_pid_injected.attach(setup);" 0' -o 'process detach' -o 'script import os; os._exit(1)' ```

User Settings

``` languageServer: "Pylance" ```

Extension version: 2023.13.12011006 VS Code version: Code 1.80.1 (Universal) (74f6148eb9ea00507ec113ec51c489d6ffb4b771, 2023-07-12T17:20:23.298Z) OS version: Darwin arm64 22.2.0 Modes:

System Info |Item|Value| |---|---| |CPUs|Apple M1 Pro (10 x 24)| |GPU Status|2d_canvas: enabled
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
metal: disabled_off
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled| |Load (avg)|2, 3, 3| |Memory (System)|16.00GB (0.06GB free)| |Process Argv|--crash-reporter-id e14f8157-0715-41f2-a3b5-a9aba91adcab| |Screen Reader|no| |VM|0%|
A/B Experiments ``` vsliv368cf:30146710 vsreu685:30147344 python383cf:30185419 vspor879:30202332 vspor708:30202333 vspor363:30204092 vslsvsres303:30308271 vserr242cf:30382550 pythontb:30283811 vsjup518:30340749 pythonptprofiler:30281270 vsdfh931:30280409 vshan820:30294714 vstes263cf:30335440 vscoreces:30445986 vscod805cf:30301675 binariesv615:30325510 bridge0708:30335490 bridge0723:30353136 vsaa593:30376534 pythonvs932:30410667 vsclangdc:30486549 c4g48928:30535728 dsvsc012cf:30540253 pynewext54:30695312 azure-dev_surveyonecf:30548226 vsccc:30610678 2e4cg342:30602488 f6dab269:30613381 a9j8j154:30646983 showlangstatbar:30737416 vsctsb:30748421 03d35959:30757346 57b77579:30736110 pythonfmttext:30731395 pythoncmvfstrcf:30756944 fixshowwlkth:30771522 hideindicator:30785051 pythongtdpath:30769146 i26e3531:30792625 pythonnosm12tcf:30779713 pythonidxpt:30784022 pythonnocebcf:30776496 e537b577:30786199 dsvsc013:30795093 dsvsc014cf:30791936 ```
DotNetRussell commented 1 year ago

I'm also seeing this while attempting to attach to a subprocess of a python application

E+00000.387: Code injection into PID=1078601 failed:

Traceback (most recent call last):
               File "/home/kali/.vscode-oss/extensions/ms-python.python-2023.4.1-universal/pythonFiles/lib/python/debugpy/adapter/../../debugpy/../debugpy/server/cli.py", line 391, in attach_to_pid
                 add_code_to_python_process.run_python_code(
               File "/home/kali/.vscode-oss/extensions/ms-python.python-2023.4.1-universal/pythonFiles/lib/python/debugpy/_vendored/pydevd/pydevd_attach_to_process/add_code_to_python_process.py", line 471, in run_python_code_linux
                 subprocess.check_call(' '.join(cmd), shell=True, env=env)
               File "/usr/lib/python3.11/subprocess.py", line 413, in check_call
                 raise CalledProcessError(retcode, cmd)
             subprocess.CalledProcessError: Command 'gdb --nw --nh --nx --pid 1078601 --batch --eval-command='set scheduler-locking off'

This is with the latest stable build of Kali

microboym commented 1 year ago

same problem.

microboym commented 1 year ago

The extension use lldb as the debugger as default. Considering that it might a problem with lldb, I've attempted to install gdb on my machine, but I got this

brew installl gdb
...
gdb: The x86_64 architecture is required for this software.
Error: gdb: An unsatisfied requirement failed this build.

Sincerely hoping for help.

chance-sematic commented 1 year ago

To quickly unblock, one can try this ( add this to the main file of your Python program, remove after debugging and before committing)

import ptvsd
ptvsd.enable_attach(address=('localhost', 5724), redirect_output=True)
print('Now is a good time to attach your debugger: Run: Python: Attach')
ptvsd.wait_for_attach()
chance-sematic commented 1 year ago

@DotNetRussell Your output shows "CalledProcessError", can you check whether the root cause is also

import codecs;import json;import sys;decode = lambda s: codecs.utf_8_decode(bytearray(s))[0] if s is not None else None;script_dir = decode([47, 85, 115, 101, 114, 115, 47, 97, 110, 99, 104, 47, 46, 118, 115, 99, 111, 100, 101, 47, 101, 120, 116, 101, 110, 115, 105, 111, 110, 115, 47, 109, 115, 45, 112, 121, 116, 104, 111, 110, 46, 112, 121, 116, 104, 111, 110, 45, 50, 48, 50, 51, 46, 54, 46, 49, 47, 112, 121, 116, 104, 111, 110, 70, 105, 108, 101, 115, 47, 108, 105, 98, 47, 112, 121, 116, 104, 111, 110, 47, 100, 101, 98, 117, 103, 112, 121, 47, 97, 100, 97, 112, 116, 101, 114, 47, 46, 46, 47, 46, 46, 47, 100, 101, 98, 117, 103, 112, 121, 47, 46, 46, 47, 100, 101, 98, 117, 103, 112, 121, 47, 115, 101, 114, 118, 101, 114]);setup = json.loads(decode([123, 34, 109, 111, 100, 101, 34, 58, 32, 34, 99, 111, 110, 110, 101, 99, 116, 34, 44, 32, 34, 97, 100, 100, 114, 101, 115, 115, 34, 58, 32, 91, 34, 49, 50, 55, 46, 48, 46, 48, 46, 49, 34, 44, 32, 53, 53, 50, 57, 52, 93, 44, 32, 34, 119, 97, 105, 116, 95, 102, 111, 114, 95, 99, 108, 105, 101, 110, 116, 34, 58, 32, 102, 97, 108, 115, 101, 44, 32, 34, 108, 111, 103, 95, 116, 111, 34, 58, 32, 110, 117, 108, 108, 44, 32, 34, 97, 100, 97, 112, 116, 101, 114, 95, 97, 99, 99, 101, 115, 115, 95, 116, 111, 107, 101, 110, 34, 58, 32, 34, 49, 55, 97, 49, 48, 98, 97, 48, 53, 100, 101, 97, 99, 49, 51, 97, 98, 56, 53, 54, 98, 52, 55, 51, 52, 57, 49, 98, 49, 100, 98, 52, 53, 49, 49, 102, 52, 56, 54, 100, 101, 102, 50, 102, 49, 56, 57, 50, 56, 50, 53, 57, 51, 52, 102, 56, 57, 54, 49, 97, 97, 98, 98, 52, 34, 125]));sys.path.insert(0, script_dir);import attach_pid_injected;del sys.path[0];attach_pid_injected.attach(setup);
error: expression failed to parse:
error: <user expression 1>:1:6: use of undeclared identifier 'DoAttach'

This could help the maintainers confirm that it is indeed the same issue.

(I am just helping out and clarify, I am not the one to fix it)

microboym commented 1 year ago

@DotNetRussell Your output shows "CalledProcessError", can you check whether the root cause is also

import codecs;import json;import sys;decode = lambda s: codecs.utf_8_decode(bytearray(s))[0] if s is not None else None;script_dir = decode([47, 85, 115, 101, 114, 115, 47, 97, 110, 99, 104, 47, 46, 118, 115, 99, 111, 100, 101, 47, 101, 120, 116, 101, 110, 115, 105, 111, 110, 115, 47, 109, 115, 45, 112, 121, 116, 104, 111, 110, 46, 112, 121, 116, 104, 111, 110, 45, 50, 48, 50, 51, 46, 54, 46, 49, 47, 112, 121, 116, 104, 111, 110, 70, 105, 108, 101, 115, 47, 108, 105, 98, 47, 112, 121, 116, 104, 111, 110, 47, 100, 101, 98, 117, 103, 112, 121, 47, 97, 100, 97, 112, 116, 101, 114, 47, 46, 46, 47, 46, 46, 47, 100, 101, 98, 117, 103, 112, 121, 47, 46, 46, 47, 100, 101, 98, 117, 103, 112, 121, 47, 115, 101, 114, 118, 101, 114]);setup = json.loads(decode([123, 34, 109, 111, 100, 101, 34, 58, 32, 34, 99, 111, 110, 110, 101, 99, 116, 34, 44, 32, 34, 97, 100, 100, 114, 101, 115, 115, 34, 58, 32, 91, 34, 49, 50, 55, 46, 48, 46, 48, 46, 49, 34, 44, 32, 53, 53, 50, 57, 52, 93, 44, 32, 34, 119, 97, 105, 116, 95, 102, 111, 114, 95, 99, 108, 105, 101, 110, 116, 34, 58, 32, 102, 97, 108, 115, 101, 44, 32, 34, 108, 111, 103, 95, 116, 111, 34, 58, 32, 110, 117, 108, 108, 44, 32, 34, 97, 100, 97, 112, 116, 101, 114, 95, 97, 99, 99, 101, 115, 115, 95, 116, 111, 107, 101, 110, 34, 58, 32, 34, 49, 55, 97, 49, 48, 98, 97, 48, 53, 100, 101, 97, 99, 49, 51, 97, 98, 56, 53, 54, 98, 52, 55, 51, 52, 57, 49, 98, 49, 100, 98, 52, 53, 49, 49, 102, 52, 56, 54, 100, 101, 102, 50, 102, 49, 56, 57, 50, 56, 50, 53, 57, 51, 52, 102, 56, 57, 54, 49, 97, 97, 98, 98, 52, 34, 125]));sys.path.insert(0, script_dir);import attach_pid_injected;del sys.path[0];attach_pid_injected.attach(setup);
error: expression failed to parse:
error: <user expression 1>:1:6: use of undeclared identifier 'DoAttach'

This could help the maintainers confirm that it is indeed the same issue.

My output seems to show the same cause.

jgen1 commented 3 months ago

I am also seeing this issue, has there been a resolution?

Stiliyan92 commented 3 months ago

Same issue for me on Mac M1 with Visual Studio Code (1.89.1 (Universal)) sys.path.insert(0, script_dir);import attach_pid_injected;del sys.path[0];attach_pid_injected.attach(setup); error: error: <user expression 1>:1:6: use of undeclared identifier 'DoAttach'

Unusualmay commented 3 months ago

I have encountered this problem as well. How can I solve it? subprocess.CalledProcessError: Command 'lldb --no-lldbinit --script-language Python -o 'process attach --pid 23513' -o 'command script import "/Users/may/Applications/PyCharm Professional Edition.app/Contents/plugins/python/helpers/pydev/pydevd_attach_to_process/linux_and_mac/lldb_prepare.py"' -o 'load_lib_and_attach "/Users/may/Applications/PyCharm Professional Edition.app/Contents/plugins/python/helpers/pydev/pydevd_attach_to_process/attach.dylib" 0 "import sys;sys.path.append(\"/Users/may/Applications/PyCharm Professional Edition.app/Contents/plugins/python/helpers/pydev\");sys.path.append(\"/Users/may/Applications/PyCharm Professional Edition.app/Contents/plugins/python/helpers/pydev/pydevd_attach_to_process\");import attach_script;attach_script.attach(port=58981, host=\"127.0.0.1\", protocol=\"\", debug_mode=\"\");" 0' -o 'process detach' -o 'script import os; os._exit(1)'' returned non-zero exit status 1.