admin管理员组

文章数量:1125805

It seems in my environment (Linux On Power) there are issues when I try to run a linux command in gdb. Using less prints the whole file to stdout rather than running less. Vim tells me the output is not a terminal. Spawning a new xterm window in gdb is linked to the gdb process and closes when I close gdb.

gdb version:

: gdb --version
GNU gdb (GDB) Red Hat Enterprise Linux 8.2-19.el8

I tried doing the following: (gdb) !less some_file.txt

Rather than opening the file up in the less process, it just prints the whole file to stdout.

If I use vim in gdb, I get the following message:

(gdb) !vim some_file.txt
Vim: Warning: Output is not to a terminal

But after a couple of seconds, it will open vim up and allow me to navigate through the file.

One final weird thing that hasn't happened before that might be a hint to what is going on. I use xterm. So let's say I open up a new xterm window in gdb: (gdb) !xterm & A new window pops up. Now let's say I quit gdb:

(gdb) q
A debugging session is active.

        Inferior 1 [process 1027212] will be killed.

Quit anyway? (y or n) y

When I hit y, it will stay stuck like that until I either close the new xterm window, or I hit Control-C. If I hit Control-C, gdb terminates, but then the new xterm window closes. So it seems somehow the processes that are being spawned in gdb aren't behaving correctly.

It seems in my environment (Linux On Power) there are issues when I try to run a linux command in gdb. Using less prints the whole file to stdout rather than running less. Vim tells me the output is not a terminal. Spawning a new xterm window in gdb is linked to the gdb process and closes when I close gdb.

gdb version:

: gdb --version
GNU gdb (GDB) Red Hat Enterprise Linux 8.2-19.el8

I tried doing the following: (gdb) !less some_file.txt

Rather than opening the file up in the less process, it just prints the whole file to stdout.

If I use vim in gdb, I get the following message:

(gdb) !vim some_file.txt
Vim: Warning: Output is not to a terminal

But after a couple of seconds, it will open vim up and allow me to navigate through the file.

One final weird thing that hasn't happened before that might be a hint to what is going on. I use xterm. So let's say I open up a new xterm window in gdb: (gdb) !xterm & A new window pops up. Now let's say I quit gdb:

(gdb) q
A debugging session is active.

        Inferior 1 [process 1027212] will be killed.

Quit anyway? (y or n) y

When I hit y, it will stay stuck like that until I either close the new xterm window, or I hit Control-C. If I hit Control-C, gdb terminates, but then the new xterm window closes. So it seems somehow the processes that are being spawned in gdb aren't behaving correctly.

Share Improve this question edited 2 days ago romainl 196k21 gold badges297 silver badges333 bronze badges asked Jan 9 at 3:08 John DemetrosJohn Demetros 111 bronze badge 9
  • What shell are you using? I tried using upstream GDB (not the RH downstream version) 8.2 and 8.2.1, in xterm, with bash as the shell, and I'm unable to reproduce the behaviour you report. Are you able to install a more up to date GDB? 8.2 is ~6 years old now. – Andrew Commented Jan 9 at 8:50
  • @Andrew Unfortunately I'm unable to install a more up to date GDB. I use korn shell. The thing is that it was working fine up until a few months ago. I'm not sure what changed in my environment and was hoping there were others that had had this issue and knew how to resolve it. – John Demetros Commented 2 days ago
  • It sounds like gdb runs shell commands with output going to a pipe rather than the terminal, so less disables its interactive mode. You can see this confirmed in the warning message from vim. – Barmar Commented 2 days ago
  • @Andrew I don't see how this could be related to the shell version. The shell is not in the input/output loop when it runs commands. – Barmar Commented 2 days ago
  • 1 Are you running gdb from an ordinary terminal, or are you in an IDE's console? – Barmar Commented 2 days ago
 |  Show 4 more comments

1 Answer 1

Reset to default 0

Apparently this behavior occurs when piping gdb to a file with tee. I had not noticed it initially because I was calling gdb from a script, obfuscating the pipe to tee. Thanks to @Andrew and @Barmar for helping me sort this out.

本文标签: linuxshell processes spawned in gdb aren39t behaving correctlyStack Overflow