Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to start debugger - undefined symbol: AttachDebuggerTracing #669

Closed
rohancme opened this issue Jul 22, 2021 · 11 comments
Closed

Unable to start debugger - undefined symbol: AttachDebuggerTracing #669

rohancme opened this issue Jul 22, 2021 · 11 comments

Comments

@rohancme
Copy link

Environment data

  • debugpy version: 1.4.0
  • OS and version: Mac OS Big Sur 11.3.1 on a Macbook Air M1
  • Python version (& distribution if applicable, e.g. Anaconda): Python 3.9.6
  • Using VS Code or Visual Studio: VS Code

Actual behavior

python -m debugpy --listen 5678 ./main.py
Traceback (most recent call last):
  File "/opt/homebrew/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/opt/homebrew/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/Users/rohan/code/DeepFryer/deepfryer/lib/python3.9/site-packages/debugpy/__main__.py", line 45, in <module>
    cli.main()
  File "/Users/rohan/code/DeepFryer/deepfryer/lib/python3.9/site-packages/debugpy/server/cli.py", line 444, in main
    run()
  File "/Users/rohan/code/DeepFryer/deepfryer/lib/python3.9/site-packages/debugpy/server/cli.py", line 267, in run_file
    start_debugging(target)
  File "/Users/rohan/code/DeepFryer/deepfryer/lib/python3.9/site-packages/debugpy/server/cli.py", line 255, in start_debugging
    debugpy.listen(options.address)
  File "/Users/rohan/code/DeepFryer/deepfryer/lib/python3.9/site-packages/debugpy/__init__.py", line 113, in listen
    return api.listen(address)
  File "/Users/rohan/code/DeepFryer/deepfryer/lib/python3.9/site-packages/debugpy/server/api.py", line 143, in debug
    log.reraise_exception("{0}() failed:", func.__name__, level="info")
  File "/Users/rohan/code/DeepFryer/deepfryer/lib/python3.9/site-packages/debugpy/server/api.py", line 141, in debug
    return func(address, settrace_kwargs, **kwargs)
  File "/Users/rohan/code/DeepFryer/deepfryer/lib/python3.9/site-packages/debugpy/server/api.py", line 261, in listen
    _settrace(
  File "/Users/rohan/code/DeepFryer/deepfryer/lib/python3.9/site-packages/debugpy/server/api.py", line 47, in _settrace
    return pydevd.settrace(*args, **kwargs)
  File "/Users/rohan/code/DeepFryer/deepfryer/lib/python3.9/site-packages/debugpy/_vendored/pydevd/pydevd.py", line 2696, in settrace
    _locked_settrace(
  File "/Users/rohan/code/DeepFryer/deepfryer/lib/python3.9/site-packages/debugpy/_vendored/pydevd/pydevd.py", line 2819, in _locked_settrace
    py_db.enable_tracing(py_db.trace_dispatch, apply_to_all_threads=True)
  File "/Users/rohan/code/DeepFryer/deepfryer/lib/python3.9/site-packages/debugpy/_vendored/pydevd/pydevd.py", line 1039, in enable_tracing
    pydevd_tracing.SetTrace(thread_trace_func)
  File "/Users/rohan/code/DeepFryer/deepfryer/lib/python3.9/site-packages/debugpy/_vendored/pydevd/pydevd_tracing.py", line 83, in SetTrace
    if set_trace_to_threads(tracing_func, thread_idents=[thread.get_ident()], create_dummy_thread=False) == 0:
  File "/Users/rohan/code/DeepFryer/deepfryer/lib/python3.9/site-packages/debugpy/_vendored/pydevd/pydevd_tracing.py", line 349, in set_trace_to_threads
    result = lib.AttachDebuggerTracing(
  File "/opt/homebrew/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ctypes/__init__.py", line 387, in __getattr__
    func = self.__getitem__(name)
  File "/opt/homebrew/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ctypes/__init__.py", line 392, in __getitem__
    func = self._FuncPtr((name_or_ordinal, self))
AttributeError: dlsym(RTLD_DEFAULT, AttachDebuggerTracing): symbol not found

Expected behavior

The debug server starts running

Steps to reproduce:

  1. pip install debugpy
  2. python -m debugpy --listen 5678 ./main.py

Is this a known issue with the M1 architecture? I am able to get this running successfully on an older macbook pro

@E5presso
Copy link

E5presso commented Jul 22, 2021

This is an new issues on debugpy 1.4.0 (which is released on today 22 JUL) so you need to rollback to debugpy 1.3.0

@Clifford-Yen
Copy link

I can confirm I also got the same error when I tried to run and debug Python scripts in VS Code. However, I did not install debugpy before (there is no such library in my pip3 list). Is there any way to roll back the built-in (I guess?) debugpy in VS Code? Or I should pip3 install 1.3.0 so that VS Code would use 1.3.0 instead of its built-in debugpy? Thanks for any help.

@karthiknadig
Copy link
Member

@Clifford-Yen You can get the previous version by going to older version of the extension:
image

@Clifford-Yen
Copy link

Thanks @karthiknadig. I actually also checked it in the extension, but debugpy is also not there. That's why I am so confused.

@martijnvwezel
Copy link

This issue occurs on different setups. See #670 for example

@fabioz
Copy link
Collaborator

fabioz commented Jul 22, 2021

As a note, I believe that setting an environment variable such as:

PYDEVD_LOAD_NATIVE_LIB=0

should make the debugging work again (without downgrading).

I still haven't been able to reproduce it myself (so, if someone with that issue can report back if that works it'd be nice...).

@martijnvwezel
Copy link

I have added the following line to the .bashrc on the remote host.
export PYDEVD_LOAD_NATIVE_LIB=0
Restarted the whole VSCode, so it needs to make a new connection and now debugging works with the latest version of de debugger.

@fabioz
Copy link
Collaborator

fabioz commented Jul 22, 2021

Great... Can you also provide the logging for when the error happens?

It's possible to collect that information by setting the following environment variables:

PYDEVD_DEBUG_FILE=</path_to/pydevd.log>
PYDEVD_DEBUG=1

(replacing the </path_to/pydevd.log> to a proper path in your machine)

@martijnvwezel
Copy link

The log files stays somehow empty. Here what the terminal shows:


sending cmd (http_json) -->           CMD_RETURN {"type": "response", "request_seq": 9, "success": true, "command": "setFunctionBreakpoints", "body": {"breakpoints": []}, "seq": 20, "pydevd_cmd_id": 502}

Process SetExceptionBreakpointsRequest: {
    "arguments": {
        "filters": [
            "uncaught"
        ]
    },
    "command": "setExceptionBreakpoints",
    "seq": 10,
    "type": "request"
}

Exceptions to hook on terminate: {'BaseException': <_pydevd_bundle.pydevd_breakpoints.ExceptionBreakpoint object at 0x7f8e9388d0>}.
sending cmd (http_json) -->           CMD_RETURN {"type": "response", "request_seq": 10, "success": true, "command": "setExceptionBreakpoints", "seq": 22, "pydevd_cmd_id": 502}

Process ConfigurationDoneRequest: {
    "arguments": {},
    "command": "configurationDone",
    "seq": 11,
    "type": "request"
}

sending cmd (http_json) -->           CMD_RETURN {"type": "response", "request_seq": 11, "success": true, "command": "configurationDone", "seq": 24, "pydevd_cmd_id": 502}

sending cmd (http_json) -->    CMD_THREAD_CREATE {"type": "event", "event": "thread", "body": {"reason": "started", "threadId": 1}, "seq": 26, "pydevd_cmd_id": 103}

Unable to set trace to all threads in arch: %s (did not find a %s lib in %s). - (('aarch64', 'attach_aarch64.so', '/home/avos/.vscode-server/extensions/ms-python.python-2021.7.1053846006/pythonFiles/lib/python/debugpy/_vendored/pydevd/pydevd_attach_to_process'),)
Successfully Loaded helper lib to set tracing to all threads.
Process ThreadsRequest: {
    "command": "threads",
    "seq": 12,
    "type": "request"
}

sending cmd (http_json) -->           CMD_RETURN {"type": "response", "request_seq": 12, "success": true, "command": "threads", "body": {"threads": [{"id": 1, "name": "MainThread"}]}, "seq": 28, "pydevd_cmd_id": 502}

Traceback (most recent call last):
  File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/avos/.vscode-server/extensions/ms-python.python-2021.7.1053846006/pythonFiles/lib/python/debugpy/__main__.py", line 45, in <module>
    cli.main()
  File "/home/avos/.vscode-server/extensions/ms-python.python-2021.7.1053846006/pythonFiles/lib/python/debugpy/../debugpy/server/cli.py", line 444, in main
    run()
  File "/home/avos/.vscode-server/extensions/ms-python.python-2021.7.1053846006/pythonFiles/lib/python/debugpy/../debugpy/server/cli.py", line 267, in run_file
    start_debugging(target)
  File "/home/avos/.vscode-server/extensions/ms-python.python-2021.7.1053846006/pythonFiles/lib/python/debugpy/../debugpy/server/cli.py", line 257, in start_debugging
    debugpy.connect(options.address, access_token=options.adapter_access_token)
  File "/home/avos/.vscode-server/extensions/ms-python.python-2021.7.1053846006/pythonFiles/lib/python/debugpy/../debugpy/common/compat.py", line 208, in kwonly_f
    return f(*args, **kwargs)
  File "/home/avos/.vscode-server/extensions/ms-python.python-2021.7.1053846006/pythonFiles/lib/python/debugpy/../debugpy/__init__.py", line 135, in connect
    return api.connect(address, access_token=access_token)
  File "/home/avos/.vscode-server/extensions/ms-python.python-2021.7.1053846006/pythonFiles/lib/python/debugpy/../debugpy/server/api.py", line 143, in debug
    log.reraise_exception("{0}() failed:", func.__name__, level="info")
  File "/home/avos/.vscode-server/extensions/ms-python.python-2021.7.1053846006/pythonFiles/lib/python/debugpy/../debugpy/server/api.py", line 141, in debug
    return func(address, settrace_kwargs, **kwargs)
  File "/home/avos/.vscode-server/extensions/ms-python.python-2021.7.1053846006/pythonFiles/lib/python/debugpy/../debugpy/server/api.py", line 276, in connect
    _settrace(host=host, port=port, client_access_token=access_token, **settrace_kwargs)
  File "/home/avos/.vscode-server/extensions/ms-python.python-2021.7.1053846006/pythonFiles/lib/python/debugpy/../debugpy/server/api.py", line 47, in _settrace
    return pydevd.settrace(*args, **kwargs)
  File "/home/avos/.vscode-server/extensions/ms-python.python-2021.7.1053846006/pythonFiles/lib/python/debugpy/_vendored/pydevd/pydevd.py", line 2712, in settrace
    notify_stdin=notify_stdin,
  File "/home/avos/.vscode-server/extensions/ms-python.python-2021.7.1053846006/pythonFiles/lib/python/debugpy/_vendored/pydevd/pydevd.py", line 2819, in _locked_settrace
    py_db.enable_tracing(py_db.trace_dispatch, apply_to_all_threads=True)
  File "/home/avos/.vscode-server/extensions/ms-python.python-2021.7.1053846006/pythonFiles/lib/python/debugpy/_vendored/pydevd/pydevd.py", line 1039, in enable_tracing
    pydevd_tracing.SetTrace(thread_trace_func)
  File "/home/avos/.vscode-server/extensions/ms-python.python-2021.7.1053846006/pythonFiles/lib/python/debugpy/_vendored/pydevd/pydevd_tracing.py", line 83, in SetTrace
    if set_trace_to_threads(tracing_func, thread_idents=[thread.get_ident()], create_dummy_thread=False) == 0:
  File "/home/avos/.vscode-server/extensions/ms-python.python-2021.7.1053846006/pythonFiles/lib/python/debugpy/_vendored/pydevd/pydevd_tracing.py", line 349, in set_trace_to_threads
    result = lib.AttachDebuggerTracing(
  File "/usr/lib/python3.6/ctypes/__init__.py", line 361, in __getattr__
    func = self.__getitem__(name)
  File "/usr/lib/python3.6/ctypes/__init__.py", line 366, in __getitem__
    func = self._FuncPtr((name_or_ordinal, self))
AttributeError: /usr/bin/python3: undefined symbol: AttachDebuggerTracing
pydevd.CheckAliveThread received kill signal
No threads alive, finishing debug session

@fabioz
Copy link
Collaborator

fabioz commented Jul 22, 2021

The issue is that on unsupported platforms (such as aarch64/arm) it ended up doing a LoadLibrary(None) and then didn't actually find the AttachDebuggerTracing function.

@fabioz
Copy link
Collaborator

fabioz commented Jul 22, 2021

This has been fixed in the master version.

Locally you have 2 choices until it's featured in an official release:

  1. Set an environment variable as:

PYDEVD_LOAD_NATIVE_LIB=0

Which will make it so that the native library is not loaded (the fix makes this happen automatically instead of failing in platforms where the library is not available).

  1. Compile the required library for your architecture yourself based on the way it's currently compiled.

The library name format is: attach_<arch>.<extension> (note that arch == platform.machine() and extension == .so/.dll.dylib depending onthe platform) and it must be placed in:

debugpy/_vendored/pydevd/pydevd_attach_to_process

The files below may be used as a basis (flags may differ based on your platform, but in general they should be pretty close).

Windows:
https://github.com/microsoft/debugpy/blob/main/src/debugpy/_vendored/pydevd/pydevd_attach_to_process/windows/compile_windows.bat

Linux:
https://github.com/microsoft/debugpy/blob/main/src/debugpy/_vendored/pydevd/pydevd_attach_to_process/linux_and_mac/compile_linux.sh

Mac:
https://github.com/microsoft/debugpy/blob/main/src/debugpy/_vendored/pydevd/pydevd_attach_to_process/linux_and_mac/compile_mac.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants