kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
From: kristof@sigsegv.be (Kristof Provost)
To: kernelnewbies@lists.kernelnewbies.org
Subject: hook SIGSEGV
Date: Wed, 14 May 2014 14:14:06 +0200	[thread overview]
Message-ID: <20140514121405.GW2613@vega.codepro.be> (raw)
In-Reply-To: <EAF38085-83E5-461D-A31A-A20F5C0980FE@gmail.com>

On 2014-05-10 21:46:01 (+0800), net.study.sea at gmail.com <net.study.sea@gmail.com> wrote:
>      I want to know is it possible to hook SIGSEGV to restart the
>      thread which the signal is sent to,without restart the whole
>      process? And record the place where has caused this signal?
> 
Yes, as others have already pointed out, you can hook SIGSEGV like any
other signal.

You're not going to be able to save the process any more, but you can
still collect some useful information.

I've found it very useful to have a SIGSEGV (and SIGPIPE, SIGABRT,
SIGFPE, SIGILL) handler which logs a backtrace (look at 'man backtrace')
to syslog. Very useful for debugging on targets where core dumps are
impractical.

Others have also pointed out that it might no longer be safe to call
printf() or malloc() there. That's true, but usually it's OK, and if it
turns out that it wasn't ... Well, you were crashing anyway.

Regards,
Kristof

  parent reply	other threads:[~2014-05-14 12:14 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-10 13:46 hook SIGSEGV net.study.sea at gmail.com
2014-05-13 15:29 ` michi1 at michaelblizek.twilightparadox.com
2014-05-13 15:43   ` Sam Dodrill
2014-05-13 16:02   ` Yann Droneaud
2014-05-14 12:14 ` Kristof Provost [this message]
2014-05-14 22:15   ` Max Filippov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140514121405.GW2613@vega.codepro.be \
    --to=kristof@sigsegv.be \
    --cc=kernelnewbies@lists.kernelnewbies.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).