Skip to content

Attaching to process "fails", but debugging works #46

Open

Description

Testing #35 on macOS and Python 3.11.4

  1. Run python3
  2. Attach to that process
  3. Output in the debug console indicates attaching failed. However, vscode is still in a "debugging" state and breakpoints work
image

Terminal contents:

Attaching to PID: 67825 (elapsed: 1.01s).
Attaching to PID: 67825 (elapsed: 2.01s).
Attach to PID failed.
--- Starting attach to pid: 67825 ---
0.00s - Debugger warning: It seems that frozen modules are being used, which may
0.00s - make the debugger miss breakpoints. Please pass -Xfrozen_modules=off
0.00s - to python to disable frozen modules.
0.00s - Note: Debugging will proceed. Set PYDEVD_DISABLE_FILE_VALIDATION=1 to disable this validation.
(lldb) process attach --pid 67825
Process 67825 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
    frame #0: 0x00007ff80e98729e libsystem_kernel.dylib`poll + 10
libsystem_kernel.dylib`poll:
->  0x7ff80e98729e <+10>: jae    0x7ff80e9872a8            ; <+20>
    0x7ff80e9872a0 <+12>: movq   %rax, %rdi
    0x7ff80e9872a3 <+15>: jmp    0x7ff80e9819e4            ; cerror
    0x7ff80e9872a8 <+20>: retq   
Target 0: (Python) stopped.
Executable module set to "/usr/local/Cellar/python@3.11/3.11.4/Frameworks/Python.framework/Versions/3.11/Resources/Python.app/Contents/MacOS/Python".
Architecture set to: x86_64h-apple-macosx-.
(lldb) command script import "/Users/connor/.vscode-insiders/extensions/ms-python.debugpy-2023.1.11741008/bundled/libs/debugpy/_vendored/pydevd/pydevd_attach_to_process/linux_and_mac/lldb_prepare.py"
(lldb) load_lib_and_attach "/Users/connor/.vscode-insiders/extensions/ms-python.debugpy-2023.1.11741008/bundled/libs/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, 99, 111, 110, 110, 111, 114, 47, 46, 118, 115, 99, 111, 100, 101, 45, 105, 110, 115, 105, 100, 101, 114, 115, 47, 101, 120, 116, 101, 110, 115, 105, 111, 110, 115, 47, 109, 115, 45, 112, 121, 116, 104, 111, 110, 46, 100, 101, 98, 117, 103, 112, 121, 45, 50, 48, 50, 51, 46, 49, 46, 49, 49, 55, 52, 49, 48, 48, 56, 47, 98, 117, 110, 100, 108, 101, 100, 47, 108, 105, 98, 115, 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, 54, 52, 49, 52, 48, 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, 56, 97, 51, 100, 53, 98, 101, 98, 50, 53, 57, 52, 97, 55, 99, 98, 55, 98, 101, 49, 99, 99, 53, 102, 57, 50, 57, 48, 52, 48, 48, 55, 50, 100, 52, 98, 101, 100, 54, 101, 49, 50, 52, 98, 49, 102, 49, 50, 48, 56, 57, 56, 100, 51, 54, 54, 50, 52, 57, 56, 55, 99, 48, 57, 34, 125]));sys.path.insert(0, script_dir);import attach_pid_injected;del sys.path[0];attach_pid_injected.attach(setup);" 0
/Users/connor/.vscode-insiders/extensions/ms-python.debugpy-2023.1.11741008/bundled/libs/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, 99, 111, 110, 110, 111, 114, 47, 46, 118, 115, 99, 111, 100, 101, 45, 105, 110, 115, 105, 100, 101, 114, 115, 47, 101, 120, 116, 101, 110, 115, 105, 111, 110, 115, 47, 109, 115, 45, 112, 121, 116, 104, 111, 110, 46, 100, 101, 98, 117, 103, 112, 121, 45, 50, 48, 50, 51, 46, 49, 46, 49, 49, 55, 52, 49, 48, 48, 56, 47, 98, 117, 110, 100, 108, 101, 100, 47, 108, 105, 98, 115, 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, 54, 52, 49, 52, 48, 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, 56, 97, 51, 100, 53, 98, 101, 98, 50, 53, 57, 52, 97, 55, 99, 98, 55, 98, 101, 49, 99, 99, 53, 102, 57, 50, 57, 48, 52, 48, 48, 55, 50, 100, 52, 98, 101, 100, 54, 101, 49, 50, 52, 98, 49, 102, 49, 50, 48, 56, 57, 56, 100, 51, 54, 54, 50, 52, 57, 56, 55, 99, 48, 57, 34, 125]));sys.path.insert(0, script_dir);import attach_pid_injected;del sys.path[0];attach_pid_injected.attach(setup);
success
(lldb) process detach
Process 67825 detached
(lldb) script import os; os._exit(1)
E+00002.414: Code injection into PID=67825 failed:
             
             Traceback (most recent call last):
               File "/Users/connor/.vscode-insiders/extensions/ms-python.debugpy-2023.1.11741008/bundled/libs/debugpy/adapter/../../debugpy/../debugpy/server/cli.py", line 391, in attach_to_pid
                 add_code_to_python_process.run_python_code(
               File "/Users/connor/.vscode-insiders/extensions/ms-python.debugpy-2023.1.11741008/bundled/libs/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 "/usr/local/Cellar/python@3.11/3.11.4/Frameworks/Python.framework/Versions/3.11/lib/python3.11/subprocess.py", line 413, in check_call
                 raise CalledProcessError(retcode, cmd)
             subprocess.CalledProcessError: Command 'lldb --no-lldbinit --script-language Python -o 'process attach --pid 67825' -o 'command script import "/Users/connor/.vscode-insiders/extensions/ms-python.debugpy-2023.1.11741008/bundled/libs/debugpy/_vendored/pydevd/pydevd_attach_to_process/linux_and_mac/lldb_prepare.py"' -o 'load_lib_and_attach "/Users/connor/.vscode-insiders/extensions/ms-python.debugpy-2023.1.11741008/bundled/libs/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, 99, 111, 110, 110, 111, 114, 47, 46, 118, 115, 99, 111, 100, 101, 45, 105, 110, 115, 105, 100, 101, 114, 115, 47, 101, 120, 116, 101, 110, 115, 105, 111, 110, 115, 47, 109, 115, 45, 112, 121, 116, 104, 111, 110, 46, 100, 101, 98, 117, 103, 112, 121, 45, 50, 48, 50, 51, 46, 49, 46, 49, 49, 55, 52, 49, 48, 48, 56, 47, 98, 117, 110, 100, 108, 101, 100, 47, 108, 105, 98, 115, 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, 54, 52, 49, 52, 48, 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, 56, 97, 51, 100, 53, 98, 101, 98, 50, 53, 57, 52, 97, 55, 99, 98, 55, 98, 101, 49, 99, 99, 53, 102, 57, 50, 57, 48, 52, 48, 48, 55, 50, 100, 52, 98, 101, 100, 54, 101, 49, 50, 52, 98, 49, 102, 49, 50, 48, 56, 57, 56, 100, 51, 54, 54, 50, 52, 57, 56, 55, 99, 48, 57, 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 "<frozen runpy>", line 198, in _run_module_as_main
               File "<frozen runpy>", line 88, in _run_code
               File "/Users/connor/.vscode-insiders/extensions/ms-python.debugpy-2023.1.11741008/bundled/libs/debugpy/adapter/../../debugpy/__main__.py", line 39, in <module>
                 cli.main()
               File "/Users/connor/.vscode-insiders/extensions/ms-python.debugpy-2023.1.11741008/bundled/libs/debugpy/adapter/../../debugpy/../debugpy/server/cli.py", line 430, in main
                 run()
               File "/Users/connor/.vscode-insiders/extensions/ms-python.debugpy-2023.1.11741008/bundled/libs/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/connor/.vscode-insiders/extensions/ms-python.debugpy-2023.1.11741008/bundled/libs/debugpy/adapter/../../debugpy/../debugpy/common/log.py", line 222, in reraise_exception
                 _exception(format_string, *args, **kwargs)
             

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/Users/connor/.vscode-insiders/extensions/ms-python.debugpy-2023.1.11741008/bundled/libs/debugpy/adapter/../../debugpy/__main__.py", line 39, in <module>
    cli.main()
  File "/Users/connor/.vscode-insiders/extensions/ms-python.debugpy-2023.1.11741008/bundled/libs/debugpy/adapter/../../debugpy/../debugpy/server/cli.py", line 430, in main
    run()
  File "/Users/connor/.vscode-insiders/extensions/ms-python.debugpy-2023.1.11741008/bundled/libs/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/connor/.vscode-insiders/extensions/ms-python.debugpy-2023.1.11741008/bundled/libs/debugpy/adapter/../../debugpy/../debugpy/server/cli.py", line 391, in attach_to_pid
    add_code_to_python_process.run_python_code(
  File "/Users/connor/.vscode-insiders/extensions/ms-python.debugpy-2023.1.11741008/bundled/libs/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 "/usr/local/Cellar/python@3.11/3.11.4/Frameworks/Python.framework/Versions/3.11/lib/python3.11/subprocess.py", line 413, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command 'lldb --no-lldbinit --script-language Python -o 'process attach --pid 67825' -o 'command script import "/Users/connor/.vscode-insiders/extensions/ms-python.debugpy-2023.1.11741008/bundled/libs/debugpy/_vendored/pydevd/pydevd_attach_to_process/linux_and_mac/lldb_prepare.py"' -o 'load_lib_and_attach "/Users/connor/.vscode-insiders/extensions/ms-python.debugpy-2023.1.11741008/bundled/libs/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, 99, 111, 110, 110, 111, 114, 47, 46, 118, 115, 99, 111, 100, 101, 45, 105, 110, 115, 105, 100, 101, 114, 115, 47, 101, 120, 116, 101, 110, 115, 105, 111, 110, 115, 47, 109, 115, 45, 112, 121, 116, 104, 111, 110, 46, 100, 101, 98, 117, 103, 112, 121, 45, 50, 48, 50, 51, 46, 49, 46, 49, 49, 55, 52, 49, 48, 48, 56, 47, 98, 117, 110, 100, 108, 101, 100, 47, 108, 105, 98, 115, 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, 54, 52, 49, 52, 48, 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, 56, 97, 51, 100, 53, 98, 101, 98, 50, 53, 57, 52, 97, 55, 99, 98, 55, 98, 101, 49, 99, 99, 53, 102, 57, 50, 57, 48, 52, 48, 48, 55, 50, 100, 52, 98, 101, 100, 54, 101, 49, 50, 52, 98, 49, 102, 49, 50, 48, 56, 57, 56, 100, 51, 54, 54, 50, 52, 57, 56, 55, 99, 48, 57, 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.
Running: lldb --no-lldbinit --script-language Python -o 'process attach --pid 67825' -o 'command script import "/Users/connor/.vscode-insiders/extensions/ms-python.debugpy-2023.1.11741008/bundled/libs/debugpy/_vendored/pydevd/pydevd_attach_to_process/linux_and_mac/lldb_prepare.py"' -o 'load_lib_and_attach "/Users/connor/.vscode-insiders/extensions/ms-python.debugpy-2023.1.11741008/bundled/libs/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, 99, 111, 110, 110, 111, 114, 47, 46, 118, 115, 99, 111, 100, 101, 45, 105, 110, 115, 105, 100, 101, 114, 115, 47, 101, 120, 116, 101, 110, 115, 105, 111, 110, 115, 47, 109, 115, 45, 112, 121, 116, 104, 111, 110, 46, 100, 101, 98, 117, 103, 112, 121, 45, 50, 48, 50, 51, 46, 49, 46, 49, 49, 55, 52, 49, 48, 48, 56, 47, 98, 117, 110, 100, 108, 101, 100, 47, 108, 105, 98, 115, 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, 54, 52, 49, 52, 48, 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, 56, 97, 51, 100, 53, 98, 101, 98, 50, 53, 57, 52, 97, 55, 99, 98, 55, 98, 101, 49, 99, 99, 53, 102, 57, 50, 57, 48, 52, 48, 48, 55, 50, 100, 52, 98, 101, 100, 54, 101, 49, 50, 52, 98, 49, 102, 49, 50, 48, 56, 57, 56, 100, 51, 54, 54, 50, 52, 57, 56, 55, 99, 48, 57, 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)'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

bugIssue identified by VS Code Team member as probable bugneeds PRReady to be worked on

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions