VSCode remote debug raspberry pi with pigpio needs sudo

32 views Asked by At

I have VSCode running on win10 and I'm debugging on a headless raspberry pi in C++. The configuration works when I just use vanilla C++ stuff. But when I need to access the IO with pigpio it needs sudo. If I build the program and then SSH to the pi and execute it with sudo it works. However, if I try to use the IDE to debug it, I get the message that I need sudo access.

initCheckPermitted: 
+---------------------------------------------------------+
|Sorry, you don't have permission to run this program.    |
|Try running as root, e.g. precede the command with sudo. |
+---------------------------------------------------------+

The user I connect with has sudo access, I've tried adding sudo into the launch.json command in front of gdb. That didn't work.

I created a file called remoteDebug in /home/aaronl/lawnmower/src and then put that into miDebuggerPath in launch.json. But it appears that this launch.json file isn't even being used, as this is the command that appears in the terminal...no sudo, no remoteDebug

Terminal output:
Done "/usr/bin/gdb" --interpreter=mi --tty=${DbgTerm} 0<"/tmp/Microsoft-MIEngine-In-tpotth2h.twr" 1>"/tmp/Microsoft-MIEngine-Out-iz5mi0ud.r3l"

File: launch.json

{
"version": "0.2.0",
"configurations": [
{
  "name": "C/C++ Runner: Debug Session",
  "type": "cppdbg",
  "request": "launch",
  "args": [],
  "stopAtEntry": false,
  "externalConsole": false,
  "cwd": "/home/aaronl/lawnmower/src",
  "program": "/home/aaronl/lawnmower/src/build/Debug/outDebug",
  "MIMode": "gdb",
  "miDebuggerPath": "remoteDebug",
  "setupCommands": [
    {
      "description": "Enable pretty-printing for gdb",
      "text": "-enable-pretty-printing",
      "ignoreFailures": true
    }
  ]
}
]
}

File: remoteDebug

sudo /usr/bin/gdb "$@"
1

There are 1 answers

0
Guillius On

I once solved this by logging in as user "root" on my Pi ...
You have to enable this option in the ssh configuration and it does come with some security risks though.