Skip to content

Failed to open /dev/tty with vscode debugger #3351

Open

Description

@0w0miki

In my program, I tried to read /dev/tty. The program cannot open the file with vscode debugger, but the file is successfully opened with gdb command line.

The source code is:

#include <stdio.h>
#include <fcntl.h>

int main(int argc, char const *argv[])
{
    int f = open("/dev/tty", O_RDONLY);
    printf("open tty %d\n",f);
    return 0;
}

The program is then build with g++ -g ./main.cpp.

When I use gdb to debug in vscode, it gives:

open tty -1

However, with command line gdb ./a.out, the file can be open successfully.

(gdb) r
Starting program: /home/miki0w0/c_test/a.out
open tty 3
[Inferior 1 (process 22818) exited normally]
(gdb) q

A same open issue can be found at https://stackoverflow.com/questions/52027368/unable-to-open-dev-ttyusb0-while-debugging-with-visual-studio-code-on-linux.

The vscode debugger works well in other cases. I wounder what causes the difference and how to fix it.

The environment is:

  • OS and Version: Ubuntu 16.04
  • VS Code Version: 1.32.3
  • C/C++ Extension Version: 0.22.1
  • Other extensions you installed (and if the issue persists after disabling them): None

Additional context
My configure file is:
launch.json.txt.

And the log information is included in this file:
debuglog.txt

Activity

  1. changed the title [-]Failed to open /dev/tty with vscode debug [/-] [+]Failed to open /dev/tty with vscode debugger[/+] on Mar 24, 2019
  2. pieandcakes commented on May 2, 2019

    @pieandcakes
    Contributor

    Can you add errno to your printf statement to see what the actual error is? I wonder if it is a permissions issue but would need to know more about why its failing.

    For reference: http://man7.org/linux/man-pages/man3/errno.3.html

  3. added
    more info needed
    on May 2, 2019
  4. 0w0miki commented on May 3, 2019

    @0w0miki
    Author

    Can you add errno to your printf statement to see what the actual error is? I wonder if it is a permissions issue but would need to know more about why its failing.

    For reference: http://man7.org/linux/man-pages/man3/errno.3.html

    I added errno to the code, and the following are the results with VS code debugger and gdb command line.
    Using debugger, the output is:

    errno: 6
    No such device or address
    open tty -1
    

    Using gdb ./a.out, the output is:

    errno: 0
    Success
    open tty 3
    

    The code is modified as

    #include <stdio.h>
    #include <fcntl.h>
    #include <errno.h>
    #include <string.h>
    
    int main(int argc, char const *argv[])
    {
        errno = 0;
        int f = open("/dev/tty", O_RDONLY);
        int errsv = errno;
        printf("errno: %d\n", errsv);
        printf("%s\n",strerror(errsv));
        printf("open tty %d\n",f);
        return 0;
    }
  5. osa1 commented on Sep 16, 2019

    @osa1

    Just came here to report this -- would be good to see this fixed as this makes debugging TUI apps in vscode quite hard.

  6. gerekon commented on Oct 11, 2019

    @gerekon

    I have the same issue, but with opening regular file for writing. Debugging with GDB from command line works well.
    Errno code is "No such file or directory".
    I use Ubuntu 18.04

  7. remicorniere commented on Dec 22, 2019

    @remicorniere

    Came here to report the same thing. It makes TUI apps impossible to debug.

  8. gnojus commented on Feb 8, 2020

    @gnojus

    Same issue (with GO debugger)

  9. goto3k commented on Apr 28, 2020

    @goto3k

    Having the same issue:
    fd = open("/dev/tty", O_RDWR, 0);

    fd=-1
    errno=6 (No such device or address),

  10. pieandcakes commented on Apr 28, 2020

    @pieandcakes
    Contributor
  11. github-actions commented on Dec 9, 2020

    @github-actions

    This issue has been closed automatically because it needs more information and has not had recent activity.

  12. MisterMX commented on Mar 19, 2022

    @MisterMX

    I had the same issue. The reason was the program was not running within a terminal but rather the debug console.

    FIxed it by setting "console": "integratedTerminal" in launch config.

  13. totszwai commented on Feb 8, 2023

    @totszwai

    Max (@MisterMX) your solution no longer exists/work in the latest VSCode, do you know what's the new alternative?

    Pierson Lee (@pieandcakes) Andrew Wang (@WardenGnaw) Can we re-open this?

  14. removed
    more info needed
    on Feb 8, 2023
  15. mbenson commented on Jan 18, 2024

    @mbenson

    "console": "integratedTerminal" solution WFM so far

  16. talraveh1 commented on Dec 17, 2024

    @talraveh1

    Same problem here.

    Workaround "console": "integratedTerminal" no longer supported.

    Is there any other workaround?

  17. dan-frohlich commented on Apr 3, 2025

    @dan-frohlich

    I added this and it got the debugger working. My app expects to be running in a "terminal" or TTY
    I'm running vscode: 1.98.2 on ubuntu

    "console": "integratedTerminal"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions