Skip to content

Commit ea1dd9a

Browse files
authored
Fix debugger stepping actions in forked process (#1921)
* Fix debugger stepping actions in forked process Fix the debugger stepping state when debugging a process that has been forked from the main process. The new sys.monitoring mechanism didn't fully clear the thread local storage after a fork leading to a state where the forked child process tracked the wrong thread information and was never updated on the latest continue action. * Add stepping test for forked process * Add line ending back in for cleaner diff * More formatting reversions
1 parent b387710 commit ea1dd9a

File tree

6 files changed

+2424
-2231
lines changed

6 files changed

+2424
-2231
lines changed

CONTRIBUTING.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,21 +108,21 @@ Pydevd (at src/debugpy/_vendored/pydevd) is a subrepo of https://github.com/fabi
108108
In order to update the source, you would:
109109
- git checkout -b "branch name"
110110
- python subrepo.py pull
111-
- git push
111+
- git push
112112
- Fix any debugpy tests that are failing as a result of the pull
113113
- Create a PR from your branch
114114

115115
You might need to regenerate the Cython modules after any changes. This can be done by:
116116

117117
- Install Python latest (3.12 as of this writing)
118-
- pip install cython, django>=1.9, setuptools>=0.9, wheel>0.21, twine
118+
- pip install cython 'django>=1.9' 'setuptools>=0.9' 'wheel>0.21' twine
119119
- On a windows machine:
120120
- set FORCE_PYDEVD_VC_VARS=C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build\vcvars64.bat
121121
- in the pydevd folder: python .\build_tools\build.py
122122

123123
## Pushing pydevd back to PyDev.Debugger
124124

125-
If you've made changes to pydevd (at src/debugpy/_vendored/pydevd), you'll want to push back changes to pydevd so as Fabio makes changes to pydevd we can continue to share updates.
125+
If you've made changes to pydevd (at src/debugpy/_vendored/pydevd), you'll want to push back changes to pydevd so as Fabio makes changes to pydevd we can continue to share updates.
126126

127127
To do this, you would:
128128

@@ -148,13 +148,13 @@ You run all of the tests with (from the root folder):
148148

149149
- python -m pytest -n auto -rfE
150150

151-
That will run all of the tests in parallel and output any failures.
151+
That will run all of the tests in parallel and output any failures.
152152

153153
If you want to just see failures you can do this:
154154

155155
- python -m pytest -n auto -q
156156

157-
That should generate output that just lists the tests which failed.
157+
That should generate output that just lists the tests which failed.
158158

159159
```
160160
=============================================== short test summary info ===============================================
@@ -167,7 +167,7 @@ With that you can then run individual tests like so:
167167

168168
- python -m pytest -n auto tests_python/test_debugger.py::test_path_translation[False]
169169

170-
That will generate a log from the test run.
170+
That will generate a log from the test run.
171171

172172
Logging the test output can be tricky so here's some information on how to debug the tests.
173173

@@ -194,7 +194,7 @@ Make sure if you add this in a module that gets `cythonized`, that you turn off
194194

195195
#### How to use logs to debug failures
196196

197-
Investigating log failures can be done in multiple ways.
197+
Investigating log failures can be done in multiple ways.
198198

199199
If you have an existing test failing, you can investigate it by running the test with the main branch and comparing the results. To do so you would:
200200

@@ -238,7 +238,7 @@ Breakpoint command
238238
0.00s - Received command: CMD_SET_BREAK 111 3 1 python-line C:\Users\rchiodo\source\repos\PyDev.Debugger\tests_python\resources\_debugger_case_remove_breakpoint.py 7 None None None
239239
```
240240

241-
In order to investigate a failure you'd look for the CMDs you expect and then see where the CMDs deviate. At that point you'd add logging around what might have happened next.
241+
In order to investigate a failure you'd look for the CMDs you expect and then see where the CMDs deviate. At that point you'd add logging around what might have happened next.
242242

243243
## Using modified debugpy in Visual Studio Code
244244
To test integration between debugpy and Visual Studio Code, the latter can be directed to use a custom version of debugpy in lieu of the one bundled with the Python extension. This is done by specifying `"debugAdapterPath"` in `launch.json` - it must point at the root directory of the *package*, which is `src/debugpy` inside the repository:
@@ -257,7 +257,7 @@ https://github.com/microsoft/debugpy/wiki/Enable-debugger-logs
257257

258258
## Debugging native code (Windows)
259259

260-
To debug the native components of `debugpy`, such as `attach.cpp`, you can use Visual Studio's native debugging feature.
260+
To debug the native components of `debugpy`, such as `attach.cpp`, you can use Visual Studio's native debugging feature.
261261

262262
Follow these steps to set up native debugging in Visual Studio:
263263

src/debugpy/_vendored/pydevd/_pydevd_sys_monitoring/_pydevd_sys_monitoring.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,16 @@ def enable_code_tracing(thread_ident: Optional[int], code, frame) -> bool:
755755

756756
return _enable_code_tracing(py_db, additional_info, func_code_info, code, frame, False)
757757

758+
# fmt: off
759+
# IFDEF CYTHON
760+
# cpdef reset_thread_local_info():
761+
# ELSE
762+
def reset_thread_local_info():
763+
# ENDIF
764+
# fmt: on
765+
"""Resets the thread local info TLS store for use after a fork()."""
766+
global _thread_local_info
767+
_thread_local_info = threading.local()
758768

759769
# fmt: off
760770
# IFDEF CYTHON

0 commit comments

Comments
 (0)