vscode-cpptools icon indicating copy to clipboard operation
vscode-cpptools copied to clipboard

RedHat/CentOS el7.x86_64 - GDB: Failed to set controlling terminal; Creates a file with name "2"

Open esarver opened this issue 7 years ago • 8 comments

Originally posted by @FranzDeCopenhague in https://github.com/Microsoft/vscode-cpptools/issues/264#issuecomment-352234542

I am also seeing this in CentOS 7.

My launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/build/bin/syshealth",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}/build/bin",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "build"
        }
    ]
}

My c_cpp_properties.json:

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE"
            ],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "c11",
            "cppStandard": "c++11",
            "intelliSenseMode": "clang-x64",
            "compileCommands": "${workspaceRoot}/build/compile_commands.json"
        }
    ],
    "version": 4
}

When I try to launch the debugger, I get a terminal window that appears that says: &"warning: GDB: Failed to set controlling terminal: Operation not permitted\n".

The VSCode debugger is inoperable:

  • Clicking on the pause button produces no results (only restart and stop do)
  • the debug console prints Unable to perform this action because the process is running. no matter what GDB command I send.
  • no variables or symbols appear in the debug pane.

Another interesting symptom is that a file with the name "2" appears in my build/bin directory with the contents -e c 1. This file only appears after I attempt to launch a debugging session.

Running GDB standalone from a separate terminal session doesn't seem to have any problem.

esarver avatar Nov 07 '18 16:11 esarver

If you enable logging, you will see the command we put in a file that we tell VS Code to run. Can you see if that command looks ok?

pieandcakes avatar Nov 07 '18 21:11 pieandcakes

This seems to stem from this line of code although I don't know why that line ends up creating a file. This command is to clear the terminal.

pieandcakes avatar Nov 08 '18 21:11 pieandcakes

I apologize for the delay in getting back to this issue. I wonder if this has anything to do with tcsh not working with all the bash-isms such as redirection in the form 1>&2.

esarver avatar Nov 12 '18 20:11 esarver

On CentOS 7 shell is not a recognized command. The only way the command worked for me was to change it to be

sh -c 'echo -e \\033c 1>&2'

In the file that you referenced, there are several other references to shell that may need to be changed to sh -c '<command>'. I am not sure how portable this is with macOS and other versions of Linux.

From my brief research it doesn't appear that C-shells (such as tcsh) support redirection very well. Unfortunately RHEL and CentOS still default to tcsh. Fortunately, it does appear that /bin/sh still points to bash.

esarver avatar Nov 12 '18 21:11 esarver

@esarver shell isn't a shell console command but rather a command to gdb to run the rest of that command in its default shell.

these commands are sent to gdb which then sends it to the shell. You can test it out by running gdb --interpreter=mi and then running -interpreter-exec console <cmd> where <cmd> is shell echo -e \\033c 1>&2.

pieandcakes avatar Nov 12 '18 21:11 pieandcakes

Ok. Now I understand.

esarver avatar Nov 12 '18 22:11 esarver

@esarver shell isn't a shell console command but rather a command to gdb to run the rest of that command in its default shell.

these commands are sent to gdb which then sends it to the shell. You can test it out by running gdb --interpreter=mi and then running -interpreter-exec console <cmd> where <cmd> is shell echo -e \\033c 1>&2.

my default shell is tcsh in centos 7, execute command(-exec shell echo -e \033c 1>&2) in vscode debug console like this, it do generate a file with name "2" in the current dir image according to gdb doc On GNU and Unix systems, the environment variable SHELL, if it exists, determines which shell to run. and my $SHELL is tcsh image

since redirection like this "1>&2" does not work in tcsh, it seems that the echo command(echo -e \033c 1>&2) need to take into account different kinds of shell redirection syntax.

tarik-jin avatar Sep 14 '22 16:09 tarik-jin

Could anyone help fix this? I'm forced to use tcsh by IT.

zengderui avatar May 08 '24 05:05 zengderui