I have a Python project setup in VS Code. The Python project calls a C++ library, which I'd like to debug.
Normally...
Normally, I'd debug as follows:
- Set a breakpoint in a test within the Python project in VS Code (version 1.70.3). Note: I am using
pytest. - Debug the Python test via Test Explorer in VS Code. Wait until execution pauses on the breakpoint set above.
- In Visual Studio Professional 2019, set a breakpoint in the C++ source code.
- In Visual Studio Professional 2019, click the Debug -> Attach to process.
- Leave Connection type set to Default.
- Leave Connection target set to my local machine name.
- Choose Native code for the Attach to: prompt as I only wish to debug my C++ sources.
- Type "python" in the search box.
- Select the python.exe to attach to.
The problem...
The problem is that the last step shows more than one Python process (usually 3), all of which have been started by VS Code. Only one of them is the one I'm looking for (and will hit my C++ breakpoints), but I'm left to trial and error trying to find out which PID I'm after. VS Code does not tell me the relevant PID to attach to, and Visual Studio offers no additional details about the processes.
Workaround...
If I open up Process Explorer (from the Command Palette in VS Code), I am able to see the command line command that started the process as well as the process tree. From there, I'm able to guess the appropriate PID to attach to (i.e. the one where the --adapter-access-token option was supplied on the command line).
Is there an easier way to determine the PID to attach to?
Thanks!