I'm using GDB to debug a program, and I want to direct its output to a different terminal than the one where GDB is running. Here's what I've been doing:
- Open a second terminal, check its device name using
tty, and get something like/dev/pts/14. - In my GDB session, I use the command
tty /dev/pts/14to set the output to that terminal. - Then I issue the
runcommand in GDB to start the program.
This setup does correctly direct the output to terminal 2, but the problem is that the first line on terminal 2 always says:
warning: GDB: Failed to set controlling terminal: Operation not permitted
I tried running GDB as root using sudo but encountered the same warning. Here's a simplified representation of my process:
# Terminal 2:
$ tty
/dev/pts/14
# Terminal 1:
$ gdb ./some-program
(gdb) tty /dev/pts/14
(gdb) run
Would anyone be able to explain what's causing this warning and how I could resolve or suppress it? What does GDB attempt to do when setting the controlling terminal, and why is it failing?
Note: Same things happens on a classic tty like /dev/tty3