[Go] gdb ignores signal processing

Source: Internet
Author: User
Tags aliases sigint signal signal handler

Signal (signals)

A signal is a soft interrupt and is a method of handling asynchronous events. In general, the operating system supports many signals. In particular, UNIX, a more important application typically processes signals. UNIX defines a number of signals, such as SIGINT to interrupt the character signal, that is, the CTRL + C signal, Sigbus indicates a hardware failure signal, SIGCHLD indicates the child process status change signal, sigkill means to terminate the program running signal, and so on. Semaphore programming is a very important technology under UNIX.

GDB has the ability to handle any kind of signal when you debug a program, and you can tell GDB which signal to handle. You can ask GDB to stop the running program as soon as it receives the signal you specified for debugging. You can use GDB's handle command to accomplish this function.

Handle
Define a signal processing in GDB. The signal can start with the sig or not start with the sig, you can define a range to process the signal (such as: Sigio-sigkill, the signal processing from the SIGIO signal 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 from running, but it will give you a message telling 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 shows a message.
Noprint
When the program being debugged receives a signal, GDB will not tell you the message that you received 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 debug program to handle.
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 by GDB.


Additionally add:

Processing of signals
The program is network-related and frequently receives sigpipe during debugging, causing GdB to stop. Looking at GDB info, the workaround is simple. Use the handle command to set the default signal processing behavior can be:
   handle SIGPIPE nostop
If you do not want to see the message, you can set up:
   handle SIGPIPE nostop noprint
on it. Other related signals can also be treated similarly. Want to know the current signal status can be used to see info signal .

Startup configuration file
GDB use in the more troublesome thing, is every start, but also to manually knock a command, especially the breakpoint more than the case, this special effect, efficiency. Check it out. GDB INFO,GDB supports automatic reading of a startup script file. Gdbinit, so the startup command that is often entered can be written in the GDB startup directory. Gdbinit. For example
.gdbinit:
   file myapp
   handle SIGPIPE nostop
   break ss.c:100
   break ss.c:200
   run
, GDB is similar to bash, and it supports the source command, which executes another script file. So you can modify the. Gdbinit:
.gdbinit:
   file myapp
   handle SIGPIPE nostop
   source gdb.break
   run
gdb.break:
   break ss.c:100
   break ss.c:200
This modifies the breakpoint configuration, just need to edit the gdb.break. Later, I still need to start gdb separately, do not want to execute the automatic script, and then improved a bit. First, name the. Gdbinit 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 GDB enters the interactive state with 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命令

alias顾名思义就是起别名的意思,在linux里,可以通过alias命令为常用命令设置快捷方式,命令格式如下: alias name=‘command‘ 例如: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, the required aliases are written inside, the difference is that the/ETC/BASHRC set of aliases for all logged-in users, and ~/.BASHRC only for the current user role.

Like what:

Handle SIGUSR2 Nostop

A good post, speaking of GDB in the signal (signal) related debugging skills

Turn from Magic C + + Forum

Http://www.magicunix.com/index_ch.html

http://www.magicunix.com/cgi-bin1/forum_cn/ultimatebb.cgi?ubb=get_topic&f=1&t=000060#000003

Reference:

--------------------------------------------------------------------------------

Original post by Couger:

I wrote an int signal processing function, in the processing function set breakpoint after go, but under the console press CTRL-C after the MC does not enter the processing function, and the program under the console also exits directly, did not give the desired output.

--------------------------------------------------------------------------------

The SIGINT signal was sent after pressing CTRL-C in the console, but the default setting in GDB would result in the information intercepted by GDB and the debug application could not accept the signal.

There are two ways to enable a debugged application to receive a signal:

(1) Change the GDB signal processing settings

For example, the following settings will tell GdB not to stop, print, and pass to the debug target program when receiving SIGINT

=====================================

(GDB) handle SIGINT nostop Print Pass

SIGINT is used by the debugger.

Is sure you want to the change it? (Y or N) y

Signal Stop Print Pass to program Description

SIGINT No Yes Yes Interrupt

(GDB)

=====================================

(2) Send a signal directly to the debugged application using the GDB command

First set a breakpoint at the statement where you want to send the signal, then run the program, and when you stop to the breakpoint, send a signal to the debug target program with GDB's signal command

====================================

(GDB) Signal SIGINT

Continuing with signal SIGINT.

Breakpoint 1, Handler (signal=2) at main.cpp:15

printf ("Signal handler...\n"

;

====================================

;-( However, these two methods are not currently supported MC, so need to wait for the new version of the MC can be easily supported by your debugging situation, hehe. Let's start by manually debugging.

The new version will increase

(1) Signal processing settings for the debugger

(2) Support send Signal command

Debugging Use Cases:

============

/*

* This program was uninterruptable with

* CTRL + C, uses signal handler

*/

#include;

#include;

#include;

/* The signal handler function */

void handler (int signal) {

printf ("Signal handler...\n"

;

Psignal (Signal, "signal:"

;

}/*handler*/

Main () {

/* Registering the handler, catching

SIGINT Signals */

Signal (SIGINT, handler);

/* do nothing */

while (1) {

printf ("running...\n"

;

Sleep (10);

}/*while*/

}/*main*/

============

Change GDB's signal processing settings

============

5.3 Signals

A signal is an asynchronous event, the can happen in a program. The

Operating system defines the possible kinds of signals, and gives each

Kind a name and a number. For example, on Unix SIGINT is the signal a

Program gets if you type an interrupt character (often c-c); SIGSEGV

is the signal a program gets from referencing a place in memory far

Away from all the areas on use; SIGALRM occurs when the alarm clock

Timer goes off (which happens only if your program have requested an

Alarm).

Some signals, including SIGALRM, is a normal part of the functioning

of your program. Others, such as SIGSEGV, indicate errors; These

Signals is fatal (they kill your program immediately) if the program

Have not specified in advance some other handle the signal.

SIGINT does not indicate a error in your program, but it is normally

Fatal so it can carry out the purpose of the interrupt:to kill the

Program.

GDB has the ability-detect any occurrence of a signal in your

Program. You can tell the GDB in advance-what-do-each kind of

Signal.

Normally, GDB is set up-let-the non-erroneous signals like SIGALRM

Be-silently passed to your program (so-as-interfere with their

Role in the program's functioning) but to stop your program immediately

Whenever an error signal happens. You can change these settings with

The handle command.

Info signals

Info handle

Print a table of all the kinds of signals and how GDB have been told to

Handle each one. You can use the signal numbers of all the

Defined types of signals.

Info handle is a alias for info signals.

Handle Signal keywords ...

Change the handles signal signal. Signal can be the number of a

Signal or its name (with or without the "SIG" at the beginning); A list

of signal numbers of the form ' Low-high '; Or the word ' all ', meaning

All the known signals. The keywords say.

The keywords allowed by the handle command can be abbreviated. Their full names is:

Nostop

GDB should not stop your program when this signal happens. It may still

Print a message telling you the signal have come in.

Stop

GDB should stop your program if this signal happens. This implies the Print keyword as well.

Print

GDB should print a message when the this signal happens.

Noprint

GDB should not mention the occurrence of the signal at all. This implies the Nostop keyword as well.

Pass

Noignore

GDB should allow your program to see this signal; Your program can

Handle the signal, or else it may terminate if the signal is fatal and

Not handled. Pass and Noignore are synonyms.

NoPass

Ignore

GDB should not allow your program to see this signal. NoPass and ignore are synonyms.

When a signal stops your program, the signal was not visible to the

program until you continue. Your program sees the signal then, if pass

is in effect for the signal in question at that time. In other words,

After GDB reports a signal, you can use the handle command with pass or

NoPass to control whether your program sees that signal when you

Continue.

The default is set to Nostop, Noprint, pass for non-erroneous signals

such as SIGALRM, Sigwinch and SIGCHLD, and to stop, print, pass for the

Erroneous signals.

You can also with the signal command to prevent your program from seeing

A signal, or cause it to see a signal it normally would don't see, or to

Give it any signal for any time. For example, if your program stopped

Due to some sort of memory reference error, you might store correct

Values into the erroneous variables and continue hoping

execution; But your program would probably terminate immediately as a

Result of the fatal signal once it saw the signal. To prevent this, you

Can continue with ' signal 0 '. See sections Giving your program a signal.

============

Send a signal directly to the debug target program using the GDB Signal command

================

Iii. Generating signals

Using the Singal command, you can generate a signal to the program being debugged. Such as: Interrupt signal CTRL + C. This is very convenient for debugging the program, you can set the breakpoint at any point in the program run, and in this breakpoint with GDB to produce a signal, this precisely in a place to produce a signal very advantageous program debugging.

The syntax is: signal; UNIX's system signals are usually from 1 to 15. So, the value is also in this range.

Unlike the kill command of the shell, the kill command of the system is intercepted by GDB when signaled to the debug program, and a signal issued by the single command is sent directly to the debugged program.

====================

[Go] gdb ignores signal processing

Related Article

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.