当前位置:网站首页>GDB debugging practice (7) signal processing
GDB debugging practice (7) signal processing
2022-06-21 22:18:00 【Wonderful binary】
List of articles
GDB Sending signal
stay GDB Debugging status , You can enter... At the command number signal Signal name To send a signal to the program .
Input signal Press down tab The signal name is displayed :
(gdb) signal
Display all 152 possibilities? (y or n)
32 SIG108 SIG125 SIG46 SIG63 SIG80 SIG97 SIGIO SIGSTOP
33 SIG109 SIG126 SIG47 SIG64 SIG81 SIG98 SIGKILL SIGSYS
34 SIG110 SIG127 SIG48 SIG65 SIG82 SIG99 SIGLIBRT SIGTERM
EXC_ARITHMETIC SIG111 SIG32 SIG49 SIG66 SIG83 SIGABRT SIGLOST SIGTRAP
EXC_BAD_ACCESS SIG112 SIG33 SIG50 SIG67 SIG84 SIGALRM SIGLWP SIGTSTP
EXC_BAD_INSTRUCTION SIG113 SIG34 SIG51 SIG68 SIG85 SIGBUS SIGMSG SIGTTIN
EXC_BREAKPOINT SIG114 SIG35 SIG52 SIG69 SIG86 SIGCANCEL SIGPHONE SIGTTOU
EXC_EMULATION SIG115 SIG36 SIG53 SIG70 SIG87 SIGCHLD SIGPIPE SIGURG
EXC_SOFTWARE SIG116 SIG37 SIG54 SIG71 SIG88 SIGCONT SIGPOLL SIGUSR1
SIG100 SIG117 SIG38 SIG55 SIG72 SIG89 SIGDANGER SIGPRIO SIGUSR2
SIG101 SIG118 SIG39 SIG56 SIG73 SIG90 SIGEMT SIGPROF SIGVTALRM
SIG102 SIG119 SIG40 SIG57 SIG74 SIG91 SIGFPE SIGPWR SIGWAITING
SIG103 SIG120 SIG41 SIG58 SIG75 SIG92 SIGGRANT SIGQUIT SIGWINCH
SIG104 SIG121 SIG42 SIG59 SIG76 SIG93 SIGHUP SIGRETRACT SIGWIND
SIG105 SIG122 SIG43 SIG60 SIG77 SIG94 SIGILL SIGSAK SIGXCPU
SIG106 SIG123 SIG44 SIG61 SIG78 SIG95 SIGINFO SIGSEGV SIGXFSZ
SIG107 SIG124 SIG45 SIG62 SIG79 SIG96 SIGINT SIGSOUND
GDB Processing signals
background :gdb The default behavior of is to capture the signal , Instead of passing it to the debugger , We can change this behavior through command configuration
stay GDB in handle The command is used to set GDB For signal processing , You can enter help handle Check it out. .
(gdb) help handle
Specify how to handle signals.
Usage: handle SIGNAL [ACTIONS]
Args are signals and actions to apply to those signals.
If no actions are specified, the current settings for the specified signals
will be displayed instead.
Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals
from 1-15 are allowed for compatibility with old versions of GDB.
Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).
The special arg "all" is recognized to mean all signals except those
used by the debugger, typically SIGTRAP and SIGINT.
Recognized actions include "stop", "nostop", "print", "noprint",
"pass", "nopass", "ignore", or "noignore".
Stop means reenter debugger if this signal happens (implies print).
Print means print a message if this signal happens.
Pass means let program see this signal; otherwise program doesn't know.
Ignore is a synonym for nopass and noignore is a synonym for pass.
Pass and Stop may be combined.
Multiple signals may be specified. Signal numbers and signal names
may be interspersed with actions, with the actions being performed for
all signals cumulatively specified.
Summarize the general meaning :
- nostop
When the debugged program receives a signal ,GDB It won't stop the program , But a message will be sent to tell you that you receive this signal . - stop
When the debugged program receives a signal ,GDB Will stop your program . - print
When the debugged program receives a signal ,GDB A message will be displayed . - noprint
When the debugged program receives a signal ,GDB Will not tell you the message of the signal . - pass 、noignore
When the debugged program receives a signal ,GDB Do not process signals . This means ,GDB Will give this signal to the debugged program to process . - nopass、ignore
When the debugged program receives a signal ,GDB The debugged program will not be allowed to process this signal .
above 6 Item Configuration , Actually, it should be divided into 3 A state in which groups can be superimposed on each other . namely :
stop/nostop
print/noprint
pass/nopass
stay GDB Can be used in info signals and info handle To see what signals are being GDB Detection neutralization GDB Treatment of it :
(gdb) info signals
Signal Stop Print Pass to program Description
SIGHUP Yes Yes Yes Hangup
SIGINT Yes Yes No Interrupt
SIGQUIT Yes Yes Yes Quit
SIGILL Yes Yes Yes Illegal instruction
SIGTRAP Yes Yes No Trace/breakpoint trap
SIGABRT Yes Yes Yes Aborted
SIGEMT Yes Yes Yes Emulation trap
SIGFPE Yes Yes Yes Arithmetic exception
SIGKILL Yes Yes Yes Killed
SIGBUS Yes Yes Yes Bus error
SIGSEGV Yes Yes Yes Segmentation fault
SIGSYS Yes Yes Yes Bad system call
SIGPIPE Yes Yes Yes Broken pipe
SIGALRM No No Yes Alarm clock
...
actual combat
#include <signal.h>
#include <stdio.h>
void signalHandle(int para)
{
printf("in signal handle,signal num:%d\n", para);
}
void signalHandle2(int para)
{
printf("in signal handle,signal num:%d\n", para);
exit(0);
}
int main(void)
{
signal(SIGUSR1, signalHandle);
signal(SIGUSR2, signalHandle2);
while(1)
{
printf("press any key to send a signal\n");
getchar();
raise(SIGUSR1);
}
return 0;
}
For better results , Run the program first , then gdb attach To the process , Get into gdb Debug mode
(gdb) c
Continuing.
Program received signal SIGUSR1, User defined signal 1.
0x00007fd1f1ec9337 in raise () from /lib64/libc.so.6
(gdb) c
Continuing.
You can find that when you press enter in the program , The process sent itself SIGUSR1 The signal , also GDB When the signal is captured, stop , We continue to run ,
take GDB Yes SIGUSR1 The signal processing is set to nostop
(gdb) handle SIGUSR1 nostop
Signal Stop Print Pass to program Description
SIGUSR1 No Yes Yes User defined signal 1
(gdb) c
Continuing.
Program received signal SIGUSR1, User defined signal 1
You can see that only , and gdb Won't stop , Next
take GDB Yes SIGUSR1 The signal processing is set to noprint
(gdb) handle SIGUSR1 noprint
Signal Stop Print Pass to program Description
SIGUSR1 No No Yes User defined signal 1
(gdb) c
Continuing
here GDB Neither print nor stop .
边栏推荐
- Use for, while and do while to find the sum of 1-100 circularly
- Self made C compiler
- Thresholdtypes of opencvsharp threshold segmentation threshold function
- 采样器合集
- Worthington trypsin solution
- Luogu p1514 [noip2010 improvement group] water diversion into the city
- I2C【1】-I2C驱动调试读操作异常的bug
- 【深入理解TcaplusDB技术】TcaplusDB构造数据
- 浅学Vector---如何使用常见的接口
- 利用for循环,分别计算1-100中奇数的和、偶数的和【方法一】
猜你喜欢

AWS CloudWatch

【深入理解TcaplusDB技术】TcaplusDB导入数据

Advanced packaging, the beginning of a big cycle -- a symposium on semiconductor equipment

Thoroughly understand the foundation of MySQL: the difference between B tree and b+ tree

TRNA analysis using trnascan se

HiC-Pro | HiC数据处理工具

B2B mall website helps enterprises speed up distribution and build an efficient and intelligent B2B online distribution platform

leetcode刷题:顺丰科技智慧物流校园技术挑战赛

【深入理解TcaplusDB技术】单据受理之表管理

dotter|打点法进行序列两两比较软件
随机推荐
利用while循环,分别计算1-100中奇数的和、偶数的和【方法二】
Mafft|multi sequence alignment tool
HiC-Pro | HiC数据处理工具
I2C【1】-I2C驱动调试读操作异常的bug
利用do while循环,分别计算1-100中奇数的和、偶数的和【方法二】
洛谷P5440 【XR-2】奇迹 题解
Common abbreviations and terms of mitochondrial genome
中衍期货开户可以吗?平台靠谱吗?安全性高吗?
MitoZ|Multi-Kmer mode
MitoZ|Multi-Kmer mode
洛谷P1535 [USACO08MAR]Cow Travelling S 题解
安超云入选《CIOReview》2022年亚太区“十大云计算解决方案提供商”
University of Virginia: ingy Elsayed aly | logic based reward formation in Multi-Agent Reinforcement Learning
Utilisation de la combinaison d'assertions de l'API Stream et de la mise en cache locale pour les requêtes floues (près de 1000 fois plus efficace que MySQL)
Chess and card games
Does the whole house smart home brand "zhiting technology" have an experience center?
001 new construction project based on opencvsharp
处理订单业务多面手,订货管理系统实现企业订货库存统一管理
As we media, why can some people earn more than 10000 yuan a month, but you can only earn a few yuan a month?
使用StreamAPI 断言组合,结合本地缓存做模糊查询(比mysql效率提升近1000倍)