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:
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.