GDB Failed to set controlling terminal operation not permitted on attached visual studio docker

Viewed 2646

I'm trying to run my program with GDB debugger. When I run it, I get a warning:

GDB: Failed to set controlling terminal: Operation not permitted

That warning appears and disappears very fast in my terminal. I already check some stackoverflow questions, but since I'm running visual studio attached to my docker (remote-container), I'm unable to apply some recommendations.

When I try a brake-point in my code, GDB does not work, and the program executes ignoring GDB.

My lauch.json configuration:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/words",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }

    ]
}

The dockerfile configuration where I'm running my program:

FROM ubuntu:18.04

SHELL ["/bin/bash", "-c"]

RUN apt-get -y update
RUN apt-get install -y Linux-headers-generic build-essential gdb

COPY . /ejercicio
1 Answers

Check that your code has in fact been built with debug. From experience (in Linux) if you don't have any symbols GDB can cause this error during a VS Code session. i.e. Add -g command line option to all compile and link statements.

Related