[SATYR PATCHv2 4/9] Add a type member to satyr structures

Martin Milata mmilata at redhat.com
Tue May 28 17:33:41 UTC 2013


All frame/thread/stacktrace structures now contain a report type
constant as its first member. This makes it possible to provide
functions that accepts frames/threads/stacktraces of any type (primitive
form of dynamic typing).

This change is split from the following patch in order to make it more
readable and touch less files.

Signed-off-by: Martin Milata <mmilata at redhat.com>
---
 lib/Makefile.am         |  3 ++-
 lib/core_frame.c        |  1 +
 lib/core_frame.h        |  3 +++
 lib/core_stacktrace.c   |  1 +
 lib/core_stacktrace.h   |  3 +++
 lib/core_thread.c       |  1 +
 lib/core_thread.h       |  3 +++
 lib/gdb_frame.c         |  1 +
 lib/gdb_frame.h         |  3 +++
 lib/gdb_stacktrace.c    |  1 +
 lib/gdb_stacktrace.h    |  3 +++
 lib/gdb_thread.c        |  1 +
 lib/gdb_thread.h        |  3 +++
 lib/java_frame.c        |  1 +
 lib/java_frame.h        |  3 +++
 lib/java_stacktrace.c   |  1 +
 lib/java_stacktrace.h   |  3 +++
 lib/java_thread.c       |  1 +
 lib/java_thread.h       |  3 +++
 lib/koops_frame.c       |  1 +
 lib/koops_frame.h       |  3 +++
 lib/koops_stacktrace.c  |  1 +
 lib/koops_stacktrace.h  |  3 +++
 lib/python_frame.c      |  1 +
 lib/python_frame.h      |  3 +++
 lib/python_stacktrace.c |  2 ++
 lib/python_stacktrace.h |  3 +++
 lib/report.c            |  1 +
 lib/report.h            | 10 +---------
 lib/report_type.h       | 44 ++++++++++++++++++++++++++++++++++++++++++++
 30 files changed, 101 insertions(+), 10 deletions(-)
 create mode 100644 lib/report_type.h

diff --git a/lib/Makefile.am b/lib/Makefile.am
index 8b5ae4a..192b0e1 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -32,7 +32,8 @@ pkginclude_HEADERS = \
 	sha1.h \
 	strbuf.h \
 	unstrip.h \
-	utils.h
+	utils.h \
+	report_type.h
 
 lib_LTLIBRARIES = libsatyr.la
 libsatyr_la_SOURCES = \
diff --git a/lib/core_frame.c b/lib/core_frame.c
index 2335e32..0f9485e 100644
--- a/lib/core_frame.c
+++ b/lib/core_frame.c
@@ -42,6 +42,7 @@ sr_core_frame_init(struct sr_core_frame *frame)
     frame->fingerprint = NULL;
     frame->fingerprint_hashed = false;
     frame->next = NULL;
+    frame->type = SR_REPORT_CORE;
 }
 
 void
diff --git a/lib/core_frame.h b/lib/core_frame.h
index b5f45c7..c7817db 100644
--- a/lib/core_frame.h
+++ b/lib/core_frame.h
@@ -29,6 +29,7 @@
 extern "C" {
 #endif
 
+#include "report_type.h"
 #include <inttypes.h>
 #include <stdbool.h>
 
@@ -41,6 +42,8 @@ struct sr_json_value;
  */
 struct sr_core_frame
 {
+    enum sr_report_type type;
+
     /** Address of the machine code in memory.  This is useful only
      * when build_id is not present for some reason.  For example,
      * this might be a null dereference (address is 0) or calling a
diff --git a/lib/core_stacktrace.c b/lib/core_stacktrace.c
index a19fc36..a97deba 100644
--- a/lib/core_stacktrace.c
+++ b/lib/core_stacktrace.c
@@ -53,6 +53,7 @@ sr_core_stacktrace_init(struct sr_core_stacktrace *stacktrace)
     stacktrace->executable = NULL;
     stacktrace->crash_thread = NULL;
     stacktrace->threads = NULL;
+    stacktrace->type = SR_REPORT_CORE;
 }
 
 void
diff --git a/lib/core_stacktrace.h b/lib/core_stacktrace.h
index 6ee7509..765bdec 100644
--- a/lib/core_stacktrace.h
+++ b/lib/core_stacktrace.h
@@ -29,6 +29,7 @@
 extern "C" {
 #endif
 
+#include "report_type.h"
 #include <inttypes.h>
 
 struct sr_core_thread;
@@ -40,6 +41,8 @@ struct sr_json_value;
  */
 struct sr_core_stacktrace
 {
+    enum sr_report_type type;
+
     /** Signal number. */
     uint16_t signal;
 
diff --git a/lib/core_thread.c b/lib/core_thread.c
index a9fecdb..0a1e627 100644
--- a/lib/core_thread.c
+++ b/lib/core_thread.c
@@ -37,6 +37,7 @@ sr_core_thread_init(struct sr_core_thread *thread)
 {
     thread->frames = NULL;
     thread->next = NULL;
+    thread->type = SR_REPORT_CORE;
 }
 
 void
diff --git a/lib/core_thread.h b/lib/core_thread.h
index 6dc173d..0813105 100644
--- a/lib/core_thread.h
+++ b/lib/core_thread.h
@@ -29,6 +29,7 @@
 extern "C" {
 #endif
 
+#include "report_type.h"
 #include <stdbool.h>
 #include <inttypes.h>
 
@@ -42,6 +43,8 @@ struct sr_json_value;
  */
 struct sr_core_thread
 {
+    enum sr_report_type type;
+
     /** Thread id. */
     int64_t id;
 
diff --git a/lib/gdb_frame.c b/lib/gdb_frame.c
index 70defeb..0ab01d3 100644
--- a/lib/gdb_frame.c
+++ b/lib/gdb_frame.c
@@ -46,6 +46,7 @@ sr_gdb_frame_init(struct sr_gdb_frame *frame)
     frame->address = -1;
     frame->library_name = NULL;
     frame->next = NULL;
+    frame->type = SR_REPORT_GDB;
 }
 
 void
diff --git a/lib/gdb_frame.h b/lib/gdb_frame.h
index a43b40f..756b458 100644
--- a/lib/gdb_frame.h
+++ b/lib/gdb_frame.h
@@ -29,6 +29,7 @@
 extern "C" {
 #endif
 
+#include "report_type.h"
 #include <stdbool.h>
 #include <stdint.h>
 
@@ -43,6 +44,8 @@ struct sr_location;
  */
 struct sr_gdb_frame
 {
+    enum sr_report_type type;
+
     /**
      * A function name or NULL. If it's NULL, signal_handler_called is
      * true.
diff --git a/lib/gdb_stacktrace.c b/lib/gdb_stacktrace.c
index 7dfe37a..11cceb6 100644
--- a/lib/gdb_stacktrace.c
+++ b/lib/gdb_stacktrace.c
@@ -44,6 +44,7 @@ sr_gdb_stacktrace_init(struct sr_gdb_stacktrace *stacktrace)
     stacktrace->threads = NULL;
     stacktrace->crash = NULL;
     stacktrace->libs = NULL;
+    stacktrace->type = SR_REPORT_GDB;
 }
 
 void
diff --git a/lib/gdb_stacktrace.h b/lib/gdb_stacktrace.h
index 889fad4..f7eff36 100644
--- a/lib/gdb_stacktrace.h
+++ b/lib/gdb_stacktrace.h
@@ -30,6 +30,7 @@
 extern "C" {
 #endif
 
+#include "report_type.h"
 #include <stdbool.h>
 
 struct sr_gdb_thread;
@@ -47,6 +48,8 @@ struct sr_location;
  */
 struct sr_gdb_stacktrace
 {
+    enum sr_report_type type;
+
     struct sr_gdb_thread *threads;
 
     /**
diff --git a/lib/gdb_thread.c b/lib/gdb_thread.c
index 1cd3c60..e059cd6 100644
--- a/lib/gdb_thread.c
+++ b/lib/gdb_thread.c
@@ -42,6 +42,7 @@ sr_gdb_thread_init(struct sr_gdb_thread *thread)
     thread->number = -1;
     thread->frames = NULL;
     thread->next = NULL;
+    thread->type = SR_REPORT_GDB;
 }
 
 void
diff --git a/lib/gdb_thread.h b/lib/gdb_thread.h
index 70ae7d3..dca88fe 100644
--- a/lib/gdb_thread.h
+++ b/lib/gdb_thread.h
@@ -29,6 +29,7 @@
 extern "C" {
 #endif
 
+#include "report_type.h"
 #include <stdbool.h>
 #include <stdint.h>
 
@@ -44,6 +45,8 @@ struct sr_gdb_sharedlib;
  */
 struct sr_gdb_thread
 {
+    enum sr_report_type type;
+
     uint32_t number;
 
     /**
diff --git a/lib/java_frame.c b/lib/java_frame.c
index 6296c42..0ae7134 100644
--- a/lib/java_frame.c
+++ b/lib/java_frame.c
@@ -54,6 +54,7 @@ void
 sr_java_frame_init(struct sr_java_frame *frame)
 {
     memset(frame, 0, sizeof(*frame));
+    frame->type = SR_REPORT_JAVA;
 }
 
 void
diff --git a/lib/java_frame.h b/lib/java_frame.h
index 772a5f9..b1be1c9 100644
--- a/lib/java_frame.h
+++ b/lib/java_frame.h
@@ -30,6 +30,7 @@
 extern "C" {
 #endif
 
+#include "report_type.h"
 #include <stdbool.h>
 #include <stdint.h>
 
@@ -38,6 +39,8 @@ struct sr_location;
 
 struct sr_java_frame
 {
+    enum sr_report_type type;
+
     /**
      * FQDN - Fully qualified domain name. Can be NULL.
      *
diff --git a/lib/java_stacktrace.c b/lib/java_stacktrace.c
index 5fce917..fa8af06 100644
--- a/lib/java_stacktrace.c
+++ b/lib/java_stacktrace.c
@@ -41,6 +41,7 @@ void
 sr_java_stacktrace_init(struct sr_java_stacktrace *stacktrace)
 {
     memset(stacktrace, 0, sizeof(*stacktrace));
+    stacktrace->type = SR_REPORT_JAVA;
 }
 
 void
diff --git a/lib/java_stacktrace.h b/lib/java_stacktrace.h
index 373c567..ef16918 100644
--- a/lib/java_stacktrace.h
+++ b/lib/java_stacktrace.h
@@ -33,10 +33,13 @@ extern "C" {
 struct sr_java_thread;
 struct sr_location;
 
+#include "report_type.h"
 #include <stdint.h>
 
 struct sr_java_stacktrace
 {
+    enum sr_report_type type;
+
     /**
      * Threads of stack trace. Always non-NULL.
      */
diff --git a/lib/java_thread.c b/lib/java_thread.c
index 9335585..a8b7e60 100644
--- a/lib/java_thread.c
+++ b/lib/java_thread.c
@@ -43,6 +43,7 @@ sr_java_thread_init(struct sr_java_thread *thread)
     thread->name = NULL;
     thread->frames = NULL;
     thread->next = NULL;
+    thread->type = SR_REPORT_JAVA;
 }
 
 void
diff --git a/lib/java_thread.h b/lib/java_thread.h
index 216fd4a..386989d 100644
--- a/lib/java_thread.h
+++ b/lib/java_thread.h
@@ -30,6 +30,7 @@
 extern "C" {
 #endif
 
+#include "report_type.h"
 #include <stdbool.h>
 #include <stdint.h>
 
@@ -44,6 +45,8 @@ struct sr_location;
  */
 struct sr_java_thread
 {
+    enum sr_report_type type;
+
     /**
      * Thread name. Can be NULL
      */
diff --git a/lib/koops_frame.c b/lib/koops_frame.c
index 8fed0bc..eb1677b 100644
--- a/lib/koops_frame.c
+++ b/lib/koops_frame.c
@@ -40,6 +40,7 @@ void
 sr_koops_frame_init(struct sr_koops_frame *frame)
 {
     memset(frame, 0, sizeof(struct sr_koops_frame));
+    frame->type = SR_REPORT_KERNELOOPS;
 }
 
 void
diff --git a/lib/koops_frame.h b/lib/koops_frame.h
index 733dbcf..269fb73 100644
--- a/lib/koops_frame.h
+++ b/lib/koops_frame.h
@@ -30,6 +30,7 @@
 extern "C" {
 #endif
 
+#include "report_type.h"
 #include <stdbool.h>
 #include <stdint.h>
 
@@ -40,6 +41,8 @@ struct sr_strbuf;
  */
 struct sr_koops_frame
 {
+    enum sr_report_type type;
+
     /**
      * Address of the function in memory.  It is set to 0 when the
      * address is not available.  In such a case, function_name is
diff --git a/lib/koops_stacktrace.c b/lib/koops_stacktrace.c
index 89e3d34..48d4a09 100644
--- a/lib/koops_stacktrace.c
+++ b/lib/koops_stacktrace.c
@@ -40,6 +40,7 @@ void
 sr_koops_stacktrace_init(struct sr_koops_stacktrace *stacktrace)
 {
     memset(stacktrace, 0, sizeof(struct sr_koops_stacktrace));
+    stacktrace->type = SR_REPORT_KERNELOOPS;
 }
 
 void
diff --git a/lib/koops_stacktrace.h b/lib/koops_stacktrace.h
index 54bd0cc..b885d4a 100644
--- a/lib/koops_stacktrace.h
+++ b/lib/koops_stacktrace.h
@@ -30,6 +30,7 @@
 extern "C" {
 #endif
 
+#include "report_type.h"
 #include <stdbool.h>
 #include <inttypes.h>
 
@@ -37,6 +38,8 @@ struct sr_location;
 
 struct sr_koops_stacktrace
 {
+    enum sr_report_type type;
+
     /**
      * @brief Version of the kernel.
      */
diff --git a/lib/python_frame.c b/lib/python_frame.c
index 59f3e88..ecc9f76 100644
--- a/lib/python_frame.c
+++ b/lib/python_frame.c
@@ -39,6 +39,7 @@ void
 sr_python_frame_init(struct sr_python_frame *frame)
 {
     memset(frame, 0, sizeof(struct sr_python_frame));
+    frame->type = SR_REPORT_PYTHON;
 }
 
 void
diff --git a/lib/python_frame.h b/lib/python_frame.h
index fc9be79..a02a6b1 100644
--- a/lib/python_frame.h
+++ b/lib/python_frame.h
@@ -30,6 +30,7 @@
 extern "C" {
 #endif
 
+#include "report_type.h"
 #include <stdbool.h>
 #include <stdint.h>
 
@@ -38,6 +39,8 @@ struct sr_strbuf;
 
 struct sr_python_frame
 {
+    enum sr_report_type type;
+
     bool special_file;
 
     char *file_name;
diff --git a/lib/python_stacktrace.c b/lib/python_stacktrace.c
index 9e0ecba..5544ed2 100644
--- a/lib/python_stacktrace.c
+++ b/lib/python_stacktrace.c
@@ -23,6 +23,7 @@
 #include "utils.h"
 #include "json.h"
 #include "sha1.h"
+#include "report_type.h"
 #include "strbuf.h"
 #include <stdio.h>
 #include <string.h>
@@ -42,6 +43,7 @@ void
 sr_python_stacktrace_init(struct sr_python_stacktrace *stacktrace)
 {
     memset(stacktrace, 0, sizeof(struct sr_python_stacktrace));
+    stacktrace->type = SR_REPORT_PYTHON;
 }
 
 void
diff --git a/lib/python_stacktrace.h b/lib/python_stacktrace.h
index 4c5eb88..d487b45 100644
--- a/lib/python_stacktrace.h
+++ b/lib/python_stacktrace.h
@@ -30,6 +30,7 @@
 extern "C" {
 #endif
 
+#include "report_type.h"
 #include <stdint.h>
 
 struct sr_python_frame;
@@ -37,6 +38,8 @@ struct sr_location;
 
 struct sr_python_stacktrace
 {
+    enum sr_report_type type;
+
     /* Exception class name. */
     char *exception_name;
 
diff --git a/lib/report.c b/lib/report.c
index fae62f2..ce6b3fb 100644
--- a/lib/report.c
+++ b/lib/report.c
@@ -175,6 +175,7 @@ sr_report_to_json(struct sr_report *report)
     {
     default:
     case SR_REPORT_INVALID:
+    case SR_REPORT_GDB: /* gdb ureports are not supported */
         report_type = "invalid";
         reason = "invalid";
         break;
diff --git a/lib/report.h b/lib/report.h
index e9b6f60..634c6e5 100644
--- a/lib/report.h
+++ b/lib/report.h
@@ -24,18 +24,10 @@
 extern "C" {
 #endif
 
+#include "report_type.h"
 #include <inttypes.h>
 #include <stdbool.h>
 
-enum sr_report_type
-{
-    SR_REPORT_INVALID = 0,
-    SR_REPORT_CORE,
-    SR_REPORT_PYTHON,
-    SR_REPORT_KERNELOOPS,
-    SR_REPORT_JAVA
-};
-
 struct sr_report
 {
     uint32_t report_version;
diff --git a/lib/report_type.h b/lib/report_type.h
new file mode 100644
index 0000000..8df81a2
--- /dev/null
+++ b/lib/report_type.h
@@ -0,0 +1,44 @@
+/*
+    report_type.h
+
+    Copyright (C) 2013  Red Hat, Inc.
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License along
+    with this program; if not, write to the Free Software Foundation, Inc.,
+    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+#ifndef SATYR_REPORT_TYPE_H
+#define SATYR_REPORT_TYPE_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+enum sr_report_type
+{
+    SR_REPORT_INVALID = 0,
+    SR_REPORT_CORE,
+    SR_REPORT_PYTHON,
+    SR_REPORT_KERNELOOPS,
+    SR_REPORT_JAVA,
+    SR_REPORT_GDB,
+
+    /* Keep this the last entry. */
+    SR_REPORT_NUM
+};
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
-- 
1.7.11.7



More information about the Crash-catcher mailing list