Re: [RFC/PATCH] Add new internal variable $_signo

Mark Kettenis
2013-06-14T07:49:07Z

> From: Sergio Durigan Junior <sergiodj@redhat.com>
> Date: Thu, 13 Jun 2013 21:37:59 -0300
>
> Hi,
>
> This patch comes from a request at:
>
> <https://bugzilla.redhat.com/show_bug.cgi?id=971849>
>
> Basically, the ABRT project (<https://fedorahosted.org/abrt/wiki>) wants
> to be able to perform some analysis on corefiles (to be implemented as a
> Python GDB module) and for that it needs to be able to inspect the
> signal which killed the program being investigated.
>
> This can be done with recent Linux kernels by inspecting the $_siginfo
> convenience variable (on corefiles, it works by parsing the contents of
> the NT_SIGINFO section, whose support was added by Tom on
> 1b05b77b857f26c59ad5dc6443fc8baa21696440). The NT_SIGINFO section was
> added on the kernel by:
>
> author Denys Vlasenko <vda.linux@googlemail.com> 2012-10-05 00:15:35 (GMT)
> commit 49ae4d4b113be03dc4a2ec5f2a1f573ff0fcddb3 (patch)
>
> (This is Linux 3.7-rc1).
>
> Well, the problem is that for older kernels (or not so old, as can be
> noted by the date), when one tries to access $_siginfo.si_signo from a
> corefile he/she gets:
>
> (gdb) core ./coredump
> [New LWP 2703]
> Core was generated by `/usr/bin/gnote <<skip>>'.
> Program terminated with signal 11, Segmentation fault.
> #0 0x09fa5348 in ?? ()
> (gdb) print $_siginfo.si_signo
> Unable to read siginfo
>
> The signal can obviously be recovered because GDB itself mentioned it
> when saying that it was "signal 11, Segmentation fault", and this is why
> this patch came to life. It basically sets/creates a new internal
> variable called "$_signo" to be used as an alternative to
> $_siginfo.si_signo when this one is unavailable. It's not a complex
> patch per se, but I would certainly like some review because there may
> be other places where we should set the variable as well.
>
> The patch also contains a testcase and an update to the documentation in
> order to mention the new convenience variable.
>
> Comments? OK to apply?

Sounds reasonable to me. Implementation seems sound.

> gdb/ChangeLog:
> 2013-06-13 Denys Vlasenko <dvlasenk@redhat.com>
>
> * corelow.c (core_open): Set internal variable "$_signo".
> * infrun.c (handle_inferior_event): Likewise, for
> TARGET_WAITKIND_SIGNALLED and TARGET_WAITKIND_STOPPED.
>
> gdb/testsuite/ChangeLog:
> 2013-06-13 Sergio Durigan Junior <sergiodj@redhat.com>
>
> * gdb.base/signo.c: New file.
> * gdb.base/signo.exp: Likewise.
>
> gdb/doc/ChangeLog:
> 2013-06-13 Sergio Durigan Junior <sergiodj@redhat.com>
>
> * gdb.texinfo (Convenience Variables): Document "$_signo".