Reputation: 1735
Following the instructions in: https://nadiah.org/2020/03/01/example-debug-mixed-python-c-in-visual-studio-code/
I ran into a strange error. In step five it reads:
In the terminal, VS Code will tell you that superuser access is required to attach to a process. Type in Y and enter the root password.
However I can't type 'Y' since an extra line is added when I am asked if I want to continue as a super user. See image:
My launch.json is:
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
},
{
"name": "(gdb) Attach",
"type": "cppdbg",
"request": "attach",
"program": "${workspaceRoot}/venv/bin/python", /* My virtual env */
"processId": "${command:pickProcess}",
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
I tried to launch VS Code as a super user to no avail. Adding sudo to 'MIMode' is not valid either.
I tried the solutions proposed in https://github.com/microsoft/vscode-cpptools/issues/4988 to no avail either.
Help is very much appreciated !
Upvotes: 3
Views: 6371
Reputation: 21
does "(gdb) Attach" or "(cuda-gdb) attach" work yet. "echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope" is not a good solution, this is a security threat.
Upvotes: 0
Reputation: 96
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
Upvotes: 4
Reputation: 1735
I found a workaround using VSCode version 1.42.1. I don't know if other version work too. I hope this helps, but if you have a better solution using the latest version, please let us know by posting your answer. I reported this issue as a bug.
UPDATE: This bug was solved in VSCode version 1.52.1.
Happy coding !
Upvotes: 0