How to setup VS Code for debugging C/C++ code using GDB and Remote Development Extension Pack?

47 Views Asked by At

I am trying to debug C++ code on a Jenkins server over SSH in VS Code. But it is not working, it works fine locally. For example, I create a simple C program, test.c:

#include <stdio.h>
int main() {
    int a = 2;
    int b = 3;
    int sum = a + b;
    printf("sum = %d\n", sum);
    return 0;
}

and compile it with debugging symbols:

gcc -g -O0 test.c -o my_test

Then, in VS Code I create this configuration within launch.json

{
    "name": "Testing GDB locally",
    "type": "cppdbg",
    "request": "launch",
    "program": "${workspaceFolder}/my_test",
    "args": [],
    "stopAtEntry": true,
    "cwd": "${workspaceFolder}",
    "environment": [],
    "externalConsole": false,
    "MIMode": "gdb",
    "setupCommands": [
        {
            "description": "Enable pretty-printing for gdb",
            "text": "-enable-pretty-printing",
            "ignoreFailures": true
        }
    ]
}

This works fine, but when I try to transfer the same procedure to the Jenkins server using SSH and the remote development extension, the debugging process just hangs.

I have installed Visual Studio Code Remote Development Extension Pack and set it up with SSH to a Jenkins server

Then, I installed the following extensions on the remote:

I use the following configuration in launch.json:

{
    "name": "Simple C program",
    "type": "cppdbg",
    "request": "launch",
    "cwd": "${workspaceFolder}",
    "program": "${workspaceFolder}/my_test",
    "args": [],
    "stopAtEntry": true,
    "MIMode": "gdb",
    "miDebuggerPath": "/usr/bin/gdb",
    "launchCompleteCommand": "None",
    "logging": {
        "trace": true,
        "traceResponse": true,
        "engineLogging": true
    },
},  

When I press F5 to start debugging, I get the following output in the debugger console: https://pastebin.com/t4QVu2g0. The VS Code terminal is empty, and the debugging toolbar buttons for "Continue", "Step over", "Step into", "Step out", are all grayed out. The only thing I can do is click the "Stop" button ("Pause" does not work).

0

There are 0 best solutions below