Skip to content

Commit 39879bd

Browse files
authored
added native debugging section (#1696)
1 parent 0116f9f commit 39879bd

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

CONTRIBUTING.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,3 +243,24 @@ To test integration between debugpy and Visual Studio Code, the latter can be di
243243
## Enabling logging in VS code
244244
See the directions here:
245245
https://github.com/microsoft/debugpy/wiki/Enable-debugger-logs
246+
247+
## Debugging native code (Windows)
248+
249+
To debug the native components of `debugpy`, such as `attach.cpp`, you can use Visual Studio's native debugging feature.
250+
251+
Follow these steps to set up native debugging in Visual Studio:
252+
253+
1. Open Visual Studio and go to `Debug` > `Options` > `Symbols`.
254+
2. Check the option **Search for all module symbols unless excluded**. This ensures that Visual Studio loads the necessary symbols (PDB files) for all modules, including dynamically loaded ones.
255+
3. Click **OK** to close the options dialog.
256+
4. Run your Python script from the command line, for example: `python ./main.py`
257+
5. In Visual Studio, go to `Debug` > `Attach to Process`.
258+
6. From the list of processes, select the appropriate Python process. Be sure to choose the correct process, especially if you're using a virtual environment. You can verify this by checking the command line associated with each process in the **Task Manager**.
259+
7. Under **Attach to**, choose either **Automatic: Native code** or explicitly select **Native** to attach as a native debugger.
260+
8. Click **Attach**.
261+
9. Open the native source file you want to debug, such as `attach.cpp`, and set breakpoints where necessary (e.g., at `DoAttach`).
262+
10. Trigger the loading of the DLL, such as by attaching `debugpy` to the Python process (refer to `Attach: PID` in `debugpy`'s `launch.json` for more details on attaching to the process).
263+
11. Once the DLL is loaded, Visual Studio will automatically load the associated PDB files, and your breakpoints should become active.
264+
12. When the breakpoint is hit, you can debug the native code as you would in any debug session.
265+
266+
If you need to step into the Python code during the debug session, you can download the Python source code from [python.org](https://www.python.org/downloads/source/). Unzip it to a folder, and when Visual Studio prompts for the source location, point it to the folder where you extracted the Python source. Ensure that the Python version matches the interpreter used to run your script (e.g., `python ./main.py`).

0 commit comments

Comments
 (0)