You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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