Re: catch SIGSEGV in the demangler

Pedro Alves
2013-01-18T16:59:33Z

On 01/18/2013 04:31 PM, Tom Tromey wrote:
>>>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:
>
> Pedro> The original idea was to do return instead of raise:
> Pedro> +static void
> Pedro> +handle_segv (int sig)
> Pedro> +{
> Pedro> + struct gdb_exception except;
> Pedro> +
> Pedro> + if (!in_demangler)
> Pedro> + {
> Pedro> + signal (sig, SIG_DFL);
> Pedro> + return;
> Pedro> + }
>
> This works fine, but has the effect of causing gdb to ignore an explicit
> 'kill -SEGV'. I had to hack "maint dump-me" to really see it work.

Yeah, you're not supposed to send synchronous signals
asynchronously. :-)

We can detect that using sigaction/SA_SIGINFO, and
then look at si_code, e.g.:

void
handler (int signo, siginfo_t *info)
{
if (expecting_segv)
{
signal (SIGSEGV, SIG_DFL);

if (info->si_code == SI_USER)
raise (signo);
else
return;
}
}

Doesn't cover all si_codes, but should work
fine in practice.

--
Pedro Alves