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

Allow python 3.12 in attach code #1580

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

AdamYoblick
Copy link
Member

Creating this PR so the dll's get generated through github actions. Once they are available as artifacts, I will download them and test locally.

@AdamYoblick AdamYoblick requested a review from a team as a code owner May 7, 2024 23:00
@AdamYoblick
Copy link
Member Author

Downloading windows artifacts from https://github.com/microsoft/debugpy/actions/runs/8993404815?pr=1580 and testing attach scenario locally.

@AdamYoblick
Copy link
Member Author

The attach DOES work now, we got past the "unknown python version" errors. But breakpoints are not getting hit like they were in when using python 3.11.

@int19h - I know debugpy works with python 3.12, but is there anything special I need to do to the attach code for breakpoints to be hit when attaching? This scenario works for 3.11 but not 3.12. Thanks!

@int19h
Copy link
Contributor

int19h commented May 8, 2024

The other place that needs to be updated is here. Without this DLL, it will not be able to set tracing on existing threads.

def _load_python_helper_lib_uncached():
if (not IS_CPYTHON or sys.version_info[:2] > (3, 11)
or hasattr(sys, 'gettotalrefcount') or LOAD_NATIVE_LIB_FLAG in ENV_FALSE_LOWER_VALUES):
pydev_log.info('Helper lib to set tracing to all threads not loaded.')
return None

@int19h
Copy link
Contributor

int19h commented May 8, 2024

But then the DLL itself needs to implement this function for Python 3.12:

#include "py_custom_pyeval_settrace_common.hpp"
#include "py_custom_pyeval_settrace_310.hpp"
#include "py_custom_pyeval_settrace_311.hpp"

void InternalPySetTrace(PyThreadState* curThread, PyObjectHolder* traceFunc, bool isDebug, PythonVersion version)
{
if (PyThreadState_25_27::IsFor(version)) {
InternalPySetTrace_Template<PyThreadState_25_27*>(reinterpret_cast<PyThreadState_25_27*>(curThread), traceFunc, isDebug);
} else if (PyThreadState_30_33::IsFor(version)) {
InternalPySetTrace_Template<PyThreadState_30_33*>(reinterpret_cast<PyThreadState_30_33*>(curThread), traceFunc, isDebug);
} else if (PyThreadState_34_36::IsFor(version)) {
InternalPySetTrace_Template<PyThreadState_34_36*>(reinterpret_cast<PyThreadState_34_36*>(curThread), traceFunc, isDebug);
} else if (PyThreadState_37_38::IsFor(version)) {
InternalPySetTrace_Template<PyThreadState_37_38*>(reinterpret_cast<PyThreadState_37_38*>(curThread), traceFunc, isDebug);
} else if (PyThreadState_39::IsFor(version)) {
InternalPySetTrace_Template<PyThreadState_39*>(reinterpret_cast<PyThreadState_39*>(curThread), traceFunc, isDebug);
} else if (PyThreadState_310::IsFor(version)) {
// 3.10 has other changes on the actual algorithm (use_tracing is per-frame now), so, we have a full new version for it.
InternalPySetTrace_Template310<PyThreadState_310*>(reinterpret_cast<PyThreadState_310*>(curThread), traceFunc, isDebug);
} else if (PyThreadState_311::IsFor(version)) {
InternalPySetTrace_Template311<PyThreadState_311*>(reinterpret_cast<PyThreadState_311*>(curThread), traceFunc, isDebug);
} else {
printf("Unable to set trace to target thread with Python version: %d", version);
}
}

@int19h
Copy link
Contributor

int19h commented May 8, 2024

That is the trickiest part. This is the implementation for Python 3.11, and I believe much of this has changed for 3.12 (e.g. use_tracing doesn't even exist anymore):

https://github.com/microsoft/debugpy/blob/09b5af0bb730e2707ec3bbc14c509523eca116c0/src/debugpy/_vendored/pydevd/pydevd_attach_to_process/common/py_custom_pyeval_settrace_311.hpp

@AdamYoblick AdamYoblick closed this May 9, 2024
@AdamYoblick AdamYoblick reopened this May 9, 2024
@sylvainmouquet
Copy link

we can also add python 3.13?

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

Successfully merging this pull request may close these issues.

None yet

4 participants