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

Failed to open /dev/tty with vscode debugger

Open 0w0miki opened this issue 7 years ago • 14 comments

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

0w0miki avatar Mar 24 '19 06:03 0w0miki

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

pieandcakes avatar May 02 '19 22:05 pieandcakes

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;
}

0w0miki avatar May 03 '19 14:05 0w0miki

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

osa1 avatar Sep 16 '19 19:09 osa1

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

gerekon avatar Oct 11 '19 11:10 gerekon

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

remicorniere avatar Dec 22 '19 22:12 remicorniere

Same issue (with GO debugger)

gnojus avatar Feb 08 '20 19:02 gnojus

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

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

goto3k avatar Apr 28 '20 16:04 goto3k

@WardenGnaw

pieandcakes avatar Apr 28 '20 17:04 pieandcakes

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

github-actions[bot] avatar Dec 09 '20 00:12 github-actions[bot]

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.

MisterMX avatar Mar 19 '22 16:03 MisterMX

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

@pieandcakes @WardenGnaw Can we re-open this?

totszwai avatar Feb 08 '23 01:02 totszwai

"console": "integratedTerminal" solution WFM so far

mbenson avatar Jan 18 '24 19:01 mbenson

Same problem here.

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

Is there any other workaround?

talraveh1 avatar Dec 17 '24 23:12 talraveh1

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"

dan-frohlich avatar Apr 03 '25 22:04 dan-frohlich