Quantcast
Viewing all articles
Browse latest Browse all 4

How to handle SIGTSTP with GDB

Problem

I use Ctrl+Z regularly at the shell to temporarily stop a program and then continue its running using the fg command. However, doing the same in GDB does not work as expected:

  • I press Ctrl+Z. GDB catches it and prints out a message saying SIGTSTP has been received.
  • Typing continue does not continue the execution of the program. The program keeps getting stopped again and prints this message:

(gdb) c
Continuing.

Program received signal SIGTSTP, Stopped (user).
[Switching to Thread 0x7fffe7e28700 (LWP 1492)]
0x00007ffff5b5112d in poll () at ../sysdeps/unix/syscall-template.S:81
81  T_PSEUDO (SYSCALL_SYMBOL, SYSCALL_NAME, SYSCALL_NARGS)

Solution

To view the signals handled by GDB and how they are handled:

(gdb) info signals
  • To view how a specific signal, say SIGTSTP is handled:
(gdb) info signal SIGTSTP
Signal        Stop  Print   Pass to program Description
SIGTSTP       Yes   Yes Yes     Stopped (user)
  • We can see that by default, this signal is passed to the program. By not passing it to the program, just like what a shell does, our problem is solved. To do this, use the handle command:
(gdb) handle SIGTSTP nopass
  • Type continue now and the program continues from where it was stopped.

Tried with: GDB 7.7.1 and Ubuntu 14.04


Tagged: gdb, signal, sigtstp Image may be NSFW.
Clik here to view.
Image may be NSFW.
Clik here to view.

Viewing all articles
Browse latest Browse all 4

Trending Articles