Ignore signal processing in GDB

Source: Internet
Author: User
Tags aliases
Signal (signals)

A signal is a soft interrupt and is a way to handle asynchronous events. In general, the operating system supports many signals. Unix in particular, more important applications typically handle signals. UNIX defines a number of signals, such as SIGINT that interrupt character signals, that is, CTRL + C signals, Sigbus signals for hardware failures, SIGCHLD state change signals, Sigkill signals to terminate the program's operation, and so on. Signal programming is a very important technology under UNIX.

GDB has the ability to process any kind of signal when you debug the program, and you can tell GDB which signal to process. You can request GDB to receive the signal you have specified, and immediately stop the running program for you to debug. You can use GDB's handle command to accomplish this function.

Handle
Define a signal processing in GDB. A signal may begin with a sig or not at a sig, and can be used to define a range (e.g. Sigio-sigkill) that handles signals from Sigio to SIGKILL, including Sigio, Sigiot,sigkill three signals. You can also use the keyword all to indicate that you want to process all the signals. Once the program being debugged receives the signal, the running program is immediately stopped by GDB for debugging. It can be one or more of the following keywords.

Nostop
When the program being debugged receives a signal, GDB does not stop the program, but it will make a message that tells you to receive the signal.
Stop
When the program being debugged receives a signal, GDB stops your program.
Print
When the program being debugged receives a signal, GDB displays a message.
Noprint
When the program that is being debugged receives a signal, GDB does not tell you the message that you receive the signal.
Pass
Noignore
When the program being debugged receives a signal, GDB does not process the signal. This means that GDB will give this signal to the debugger to process it.
NoPass
Ignore
When the program being debugged receives a signal, GDB does not let the debugger process the signal.


Info signals
Info handle
See what signals are being detected in GDB.
Additionally added:

Processing of signals
The program is related to the network, during debugging often received sigpipe, causing GDB to stop. After looking at GDB info, the solution is simple. Use the handle command to set the processing behavior of the default signal:
Handle Sigpipe Nostop
If you don't want to see the message, you can set it this way:
Handle Sigpipe nostop Noprint
It's OK. Other related signals can also be treated similarly. To understand the current signal state you can use the Info signal view.

Start configuration file
GDB in the use of the more troublesome things, that is, every time to start, but also manually hit a command, especially more breakpoints, this special effects, efficiency. Check it out. GDB INFO,GDB supports the automatic reading of a startup script file. Gdbinit, so often enter the startup command, can be written in the GDB startup directory. Gdbinit. Like what
. Gdbinit:
File MyApp
Handle Sigpipe Nostop
Break ss.c:100
Break ss.c:200
Run
GDB, like Bash, also supports the source command, which executes another script file. So you can modify it. Gdbinit:
. Gdbinit:
File MyApp
Handle Sigpipe Nostop
SOURCE Gdb.break
Run
Gdb.break:
Break ss.c:100
Break ss.c:200
This modification of the breakpoint configuration, only need to edit the gdb.break on it. Later, I still need to start gdb separately, do not want to perform automatic script, and then improved again. First, name the. Gdbinit as Gdb.init, and then define a shell alias:
$ alias. gdb= "Gdb-x gdb.init"

This way, if you need to use an automatic script, use the. gdb command, or use GDB to enter the interactive state of GDB. This configuration can be a simple command to start debugging, the overall efficiency can be improved a lot.

Note: Transfer from http://blog.scaner.i.thu.cn/index.php/2006/04/15/gdb-tips-1/

Annotations

1alias command

Alias is the meaning of aliases, in Linux, you can use the alias command to set shortcuts for common commands, the command format is as follows: Alias Name= ' command ' For example: Alias del= ' RM '

To show that the system already has an alias, use alias or alias-p directly

If you need to set a more command alias, you can directly modify the/ETC/BASHRC or ~/.BASHRC, you will need to write the alias to the inside, the difference is that the/ETC/BASHRC set of aliases for all logged-in users, and ~/.BASHRC only for the current user role.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.