Failed to open /dev/tty with vscode debugger
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
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
Can you add
errnoto 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;
}
Just came here to report this -- would be good to see this fixed as this makes debugging TUI apps in vscode quite hard.
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
Came here to report the same thing. It makes TUI apps impossible to debug.
Same issue (with GO debugger)
Having the same issue:
fd = open("/dev/tty", O_RDWR, 0);
fd=-1 errno=6 (No such device or address),
@WardenGnaw
This issue has been closed automatically because it needs more information and has not had recent activity.
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 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?
"console": "integratedTerminal" solution WFM so far
Same problem here.
Workaround "console": "integratedTerminal" no longer supported.
Is there any other workaround?
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"