mm_
mm_

Reputation: 1735

Debugging mixed Python C++ in VS Code. Can't enter sudo password

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:

source /.../venv/bin/activate appears in an unexpected place

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

Answers (3)

Huynh harry
Huynh harry

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

gaurav
gaurav

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:

  1. Install Python C++ Debugger" extension [link]. This extension will remove the pain to manually enter the C++ process id.

  2. 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}"
        }
    ]
    

    }

  3. 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

mm_
mm_

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

Related Questions