燮pressing的段错误信号 [英] Suppressing the segfault signal

查看:150
本文介绍了燮pressing的段错误信号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我分析一组,在某些测试它们可能会终止段错误越野车项目。被记录在段错误事件的/ var / log / syslog的

例如下面的代码片段返回分段故障,它被记录下来。

 #!/斌/庆典
    。/测试

我的问题是如何燮preSS的内存设计缺陷,使得它的的出现在系统日志中。我试图陷阱捕捉到下面的脚本信号:

 #!/斌/庆典
 设置-bm
 陷阱回声发生了一些事情'{} 1..64
 。/测试

返回的是:

 分段故障
 发生了一些事

所以,它捕获该段错误,但段错误是的还是的记录。

 内核:[81615.373989]测试[319]:段错误在0 IP 00007f6b9436d614
 SP 00007ffe33fb77f8错误6 libc-2.19.so [7f6b942e1000 + 1bb000]


解决方案

我们可以共进晚餐preSS日志信息系统范围内的随e。克

 回声0 GT;的/ proc / SYS /调试/异常痕迹

- 亦见


我们可以共进晚餐preSS日志消息为一个单一的过程,如果我们在 <运行code> ptrace的() 控制,如在调试器。这个程序这是否:

exe.c

 的#include&LT; SYS / wait.h&GT;
#包括LT&; SYS / ptrace.h&GT;主(INT ARGC,CHAR * ARGS [])
{
    将为pid_t PID;
    如果(* ++参数)
    如果(PID =叉())
    {
        INT状态;
        而(等待(安培;状态)0)
        {
            如果(!WIFSTOPPED(状态))
                返回WIFSIGNALED(状态)? 128 + WTERMSIG(状态)
                                           :WEXITSTATUS(状态);
            INT信号= WSTOPSIG(状态);
            如果(信号== SIGTRAP)信号= 0;
            ptrace函数(PTRACE_CONT,PID,0,信号);
        }
        PERROR(等待);
    }
    其他
    {
        的ptrace(PTRACE_TRACEME,0,0,0);
        execvp(*指定参数时,参数);
        PERROR(*参数);
    }
    返回1;
}

这就是所谓的与错误的程序作为它的参数,你的情况

  exe文件./test

- 那么的退出状态 exe文件通常是测试的退出状态,但如果测试是由信号终止的 N 的(11的分段故障的),它是128+的 N

我写了这个之后,我意识到,我们还可以使用 strace的为宗旨,E。克

  strace的-enone ./test

I am analyzing a set of buggy programs that under some test they may terminate with segfault. The segfault event is logged in /var/log/syslog.

For example the following snippet returns Segmentation fault and it is logged.

    #!/bin/bash
    ./test

My question is how to suppress the segfault such that it does NOT appear in the system log. I tried trap to capture the signal in the following script:

 #!/bin/bash
 set -bm
 trap "echo 'something happened'" {1..64}
 ./test

It returns:

 Segmentation fault
 something happened

So, it does traps the segfault but the segfault is still logged.

 kernel: [81615.373989] test[319]: segfault at 0 ip 00007f6b9436d614 
 sp 00007ffe33fb77f8 error 6 in libc-2.19.so[7f6b942e1000+1bb000]

解决方案

We can suppress the log message system-wide with e. g.

echo 0 >/proc/sys/debug/exception-trace

- see also


We can suppress the log message for a single process if we run it under ptrace() control, as in a debugger. This program does that:

exe.c

#include <sys/wait.h>
#include <sys/ptrace.h>

main(int argc, char *args[])
{
    pid_t pid;
    if (*++args)
    if (pid = fork())
    {
        int status;
        while (wait(&status) > 0)
        {
            if (!WIFSTOPPED(status))
                return WIFSIGNALED(status) ? 128+WTERMSIG(status)
                                           : WEXITSTATUS(status);
            int signal = WSTOPSIG(status);
            if (signal == SIGTRAP) signal = 0;
            ptrace(PTRACE_CONT, pid, 0, signal);
        }
        perror("wait");
    }
    else
    {
        ptrace(PTRACE_TRACEME, 0, 0, 0);
        execvp(*args, args);
        perror(*args);
    }
    return 1;
}

It is called with the buggy program as its argument, in your case

exe ./test

- then the exit status of exe normally is the exit status of test, but if test was terminated by signal n (11 for Segmentation fault), it is 128+n.

After I wrote this, I realized that we can also use strace for the purpose, e. g.

strace -enone ./test

这篇关于燮pressing的段错误信号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆