Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

KDevelop debugging warning: Failed to set controlling terminal: Operation not permitted

A while ago I changed my personal operating system to linux and my development enviroment to KDevelop.

However debugging c++ projects is still not working as it should. My KDevelop version is 4.2.2 (I installed it through package management)

Every time I hit the "debug button" the application is starting with the console message warning: GDB: Failed to set controlling terminal: Operation not permitted and debugging functionality is not available.

Any ideas welcome.

(If you need additional information don't hesitate to ask)

like image 342
Mythli Avatar asked Sep 13 '11 19:09

Mythli


Video Answer


1 Answers

I also had this problem, but I use gdb in KDevelop sparsely enough that hadn't bothered me yet. Here's my log of trying to fix it:

Grepping through the GDB 7.3.1 source code reveals that this message is printed when GDB tries to set its master TTY to a newly-created pseudo-tty (see gdb/inflow.c, lines 683-740). In particular, a call to ioctl with request TIOCSCTTY fails with a permissions error.

With this in mind, I took a look at the Linux kernel source code to see what could cause a failure. A bit of searching shows that it will eventually degenerate into a call to tiocsctty(). The comment from tiocsctty that is important here:

/*
 * The process must be a session leader and
 * not have a controlling tty already.
 */

Since the only other reason it can fail with EPERM is if the tty that GDB creates is actually a controlling tty for another process (which seems highly unlikely), I thought it reasonable to assume that GDB is not a session leader. Fair enough, it's launched by KDevelop after all!

So: I tried not launching the GDB session in an external terminal, and it works. Problem narrowed down.

Originally, the external terminal line was set to konsole --noclose --workdir %workdir -e %exe. Changing this to terminator -e %exe made a slight difference: KDevelop warned me that

GDB cannot use the tty* or pty* devices.
Check the settings on /dev/tty* and /dev/pty*
As root you may need to "chmod ug+rw" tty* and pty* devices and/or add the user to the tty group using "usermod -G tty username".

I checked my permissions; my user was part of the tty group and all relevant files were readable and writable.

Grepping through the KDevelop source code reveals how KDevelop actually sets up the terminal. It runs the shell script

tty > FIFO_PATH ; trap "" INT QUIT TSTP ; exec<&-; exec>&-; while :; do sleep 3600;done

and then sets up GDB to use the terminal device it reads from FIFO_PATH. (My name, by the way, not the one that KDevelop uses.) The problem (as best I can tell) is that gdb is not launched as a child of the shell script, and thus cannot use it as its main tty.

I'm not feeling up to patching KDevelop to make this work properly as of yet (or finding what actually caused this to stop working in the first place . . .), so the best I can suggest at the moment is to simply not use an external terminal for debugging purposes.

Good luck! I'll update if I find anything useful.

like image 185
Ethereal Avatar answered Sep 25 '22 15:09

Ethereal