Debugging mixed Python C++ in VS Code. Can't enter sudo password
After much searching and brain storming I am finally able to debug both Python and CPP code via VS Code. Sequence of steps are as follows:
Install Python C++ Debugger" extension [link]. This extension will remove the pain to manually enter the C++ process id.
Here is my "launch.json" file for reference on how to use this new extension:
{
"version": "0.2.0",
"configurations": [
{
"name": "Python C++ Debug",
"type": "pythoncpp",
"request": "launch",
"pythonLaunchName": "Python: Current File",
"cppConfig": "default (gdb) Attach"
},
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "/home/agaurav/main.py",
"console": "integratedTerminal",
"env": {
"LD_LIBRARY_PATH": "/path/to/lib1:/path/to/lib2"
},
"cwd": "${workspaceRoot}"
}
]}
Finally, set ptrace_scope to 0 so that we allow one process to examine and modify another process. Do this by running this command:
echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope
And done. Now you can set breakpoint at both Python and Cpp
Mixed mode assembly not loading symbol for native C++ pdbs
Mixed-mode debugging can be hit and miss, mostly miss. First check that you've actually have mixed-mode debugging enabled. From a C# project, it is Project + Properties, Debug, Enabled unmanaged code debugging check box. Next, mixed-mode debugging is not enabled for 64-bit processes. If you run on a 64-bit operating system, make sure you force the .exe to run in 32-bit mode. Project + Properties, Build tab, Platform Target = x86.
Next verify where the debugger looked for the .pdb files. From the Debug + Windows + Modules window, right-click the DLL and select "Symbol load information". Final gasp is to use __debugbreak() in the unmanaged code.
UPDATE: Recent versions of VS (starting with VS2012) have a new managed debugging engine that is not compatible enough with the unmanaged debugging engine. Tools > Options > Debugging > General, tick "Use Managed Compatibility Mode". It enables the legacy debugging engine, the one last used in VS2010.
How to attach debugger to step into native (C++) code from a managed (C#) wrapper?
Check the Debug tab on your project's properties page. There should be an "Enable unmanaged code debugging" checkbox. This worked for me when we developed a new .NET UI for our old c++ DLLs.
If your unmanaged DLL is being built from another project (for a while ours were being built using VS6) just make sure you have the DLL's pdb file handy for the debugging.
The other approach is to use the C# exe as the target exe to run from the DLL project, you can then debug your DLL normally.
Debugging Python and C++ in Visual Studio
I faced the same problem and didn't find a solution.
If you want a workaround, try to attach your native code to the python.exe
process:
- Start the debugging of your python script (without native support) and wait on some breakpoint
- Launch your native project in another VisualStudio instance, set needed breakpoint and then go to Debug -> Attach to process, select started python.exe process (you can find it by PID)
- Continue python execution.
It worked for me. Note that you need your native code to be compiled with debug symbols as well.
Happy bug-hunting! =)
How to break in c++ code called from c# interop
As suggested by Kevin Gosse, and detailed in MSFT documentation, just enable mixed-mode debugging:
Enable mixed-mode debugging for a managed calling app
Select the C# or Visual Basic project in Solution Explorer and select the Properties icon, press Alt+Enter, or right-click and choose
Properties.Select the Debug tab, and then select Enable native code debugging.
Close the properties page to save the changes.
Related Topics
How to Highlight The Differences Between Subsequent Lines in a File
How to Have Postgresql Not Collapse Punctuation and Spaces When Collating Using a Language
Finding and Listing Duplicate Words in a Plain Text File
Linux Usb Driver Probe Not Called If Device Already Plugged
Running Docker Without Sudo on Ubuntu 14.04
Error Hh604: Error Running JSON-Rpc Server: Error:0308010C:Digital Envelope Routines::Unsupported
Xmonad: Spawnon Workspace That Had Focus When Spawn Key Was Pressed
How to Play an Audio File from Haskell Code, Cross-Platform
Automated Installation of R-Studio Using Shell Script
Socket Programming Send() Return Value
Using Winscp to Grab a File Through a Tunnel
How to Execute 'X86_64-Conda_Cos6-Linux-Gnu-Gcc': No Such File or Directory (Pysam Installation)
Apt-Update in Azure Nvidia Gives Publickey Error