public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v2] On non-linux systems, don't use native signal numbers
@ 2017-08-18 15:04 Ulf Hermann
  2017-08-19  8:11 ` Mark Wielaard
  0 siblings, 1 reply; 2+ messages in thread
From: Ulf Hermann @ 2017-08-18 15:04 UTC (permalink / raw)
  To: elfutils-devel

We assume core files from linux systems, so we should use the linux
version of the signals when reading them. Other OS might have different
signal numbers.

(v1 was a malformed patch)

Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
---
 src/ChangeLog |  4 ++++
 src/readelf.c | 24 +++++++++++++++++++-----
 2 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index 54ba767e..8aa57051 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,7 @@
+2017-08-18  Ulf Hermann  <ulf.hermann@qt.io>
+
+	* readelf.c: Hardcode the signal numbers for non-linux systems.
+
 2017-07-26  Mark Wielaard  <mark@klomp.org>
 
 	* readelf.c (print_debug_macro_section): Accept either version 4 or
diff --git a/src/readelf.c b/src/readelf.c
index 73be474b..5e2f3fc2 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -57,6 +57,20 @@
 
 #include "../libdw/known-dwarf.h"
 
+#ifdef __linux__
+#define CORE_SIGILL  SIGILL
+#define CORE_SIGBUS  SIGBUS
+#define CORE_SIGFPE  SIGFPE
+#define CORE_SIGSEGV SIGSEGV
+#define CORE_SI_USER SI_USER
+#else
+/* We want the linux version of those as that is what shows up in the core files. */
+#define CORE_SIGILL  4  /* Illegal instruction (ANSI).  */
+#define CORE_SIGBUS  7  /* BUS error (4.2 BSD).  */
+#define CORE_SIGFPE  8  /* Floating-point exception (ANSI).  */
+#define CORE_SIGSEGV 11 /* Segmentation violation (ANSI).  */
+#define CORE_SI_USER 0  /* Sent by kill, sigsend.  */
+#endif
 
 /* Name and version of program.  */
 ARGP_PROGRAM_VERSION_HOOK_DEF = print_version;
@@ -9335,10 +9349,10 @@ handle_siginfo_note (Elf *core, GElf_Word descsz, GElf_Off desc_pos)
   if (si_code > 0)
     switch (si_signo)
       {
-      case SIGILL:
-      case SIGFPE:
-      case SIGSEGV:
-      case SIGBUS:
+      case CORE_SIGILL:
+      case CORE_SIGFPE:
+      case CORE_SIGSEGV:
+      case CORE_SIGBUS:
 	{
 	  uint64_t addr;
 	  if (! buf_read_ulong (core, &ptr, end, &addr))
@@ -9349,7 +9363,7 @@ handle_siginfo_note (Elf *core, GElf_Word descsz, GElf_Off desc_pos)
       default:
 	;
       }
-  else if (si_code == SI_USER)
+  else if (si_code == CORE_SI_USER)
     {
       int pid, uid;
       if (! buf_read_int (core, &ptr, end, &pid)
-- 
2.11.0

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] On non-linux systems, don't use native signal numbers
  2017-08-18 15:04 [PATCH v2] On non-linux systems, don't use native signal numbers Ulf Hermann
@ 2017-08-19  8:11 ` Mark Wielaard
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Wielaard @ 2017-08-19  8:11 UTC (permalink / raw)
  To: Ulf Hermann; +Cc: elfutils-devel

On Fri, Aug 18, 2017 at 05:03:50PM +0200, Ulf Hermann wrote:
> We assume core files from linux systems, so we should use the linux
> version of the signals when reading them. Other OS might have different
> signal numbers.

Thanks, applied.

Note that according to man 7 signal SIGBUS could actually be a different
constant depending on architecture. But that is an existing issue. We might
have to make this code dependent on the EM machine value found in the core
file.

Cheers,

Mark

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-08-19  8:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-18 15:04 [PATCH v2] On non-linux systems, don't use native signal numbers Ulf Hermann
2017-08-19  8:11 ` Mark Wielaard

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 read-only IMAP folder(s) and NNTP newsgroup(s).