abrt  2.1.4
A tool to inform users about various problems on the running system
satyr-compat.h
1 /*
2  Copyright (C) 2013 RedHat inc.
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License along
15  with this program; if not, write to the Free Software Foundation, Inc.,
16  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18 /*
19  * Compatibility header for transition from btparser to satyr. When the
20  * possibility to compile abrt against btparser is removed, delete this file
21  * and include the relevant satyr headers instead.
22  */
23 #ifndef SATYR_COMPAT_H_
24 #define SATYR_COMPAT_H_
25 
26 #include "config.h"
27 
28 #ifdef USE_SATYR
29 /* Satyr is used, nothing to do, just include everything we may need. */
30 
31 #include <satyr/core_frame.h>
32 #include <satyr/core_stacktrace.h>
33 #include <satyr/core_thread.h>
34 #include <satyr/distance.h>
35 #include <satyr/gdb_frame.h>
36 #include <satyr/gdb_stacktrace.h>
37 #include <satyr/location.h>
38 #include <satyr/metrics.h>
39 #include <satyr/normalize.h>
40 #include <satyr/sha1.h>
41 #include <satyr/utils.h>
42 
43 #define BACKTRACE_DUP_THRESHOLD 0.3
44 
45 #else /* USE_SATYR */
46 /* We use btparser. Wrap the calls to btparser in a satyr-compatible interface. */
47 
48 #include <btparser/frame.h>
49 #include <btparser/thread.h>
50 #include <btparser/normalize.h>
51 #include <btparser/metrics.h>
52 #include <btparser/core-backtrace.h>
53 #include <btparser/backtrace.h>
54 #include <btparser/frame.h>
55 #include <btparser/location.h>
56 #include "libabrt.h" /* xstrdup */
57 
58 #define BACKTRACE_DUP_THRESHOLD 2
59 
60 /* abrt-handle-event.c */
61 #define sr_core_stacktrace btp_thread
62 #define sr_core_thread btp_thread
63 #define sr_thread_get_frame_count btp_thread_get_frame_count
64 
65 enum sr_distance_type
66 {
67  SR_DISTANCE_DAMERAU_LEVENSHTEIN
68 };
69 
70 /* The functions should be static but that generates unused function warnings.
71  * We don't include this header in two compilation units that are then linked
72  * together anyway, so this should work. And this file should be gone soon ...
73  */
74 struct sr_core_stacktrace *
75 sr_core_stacktrace_from_json_text(const char *text,
76  char **error_message)
77 {
78  struct btp_thread *thread = btp_load_core_backtrace(text);
79  if (!thread)
80  {
81  *error_message = xstrdup(
82  "Failed to parse backtrace, considering it not duplicate");
83  return NULL;
84  }
85  return btp_load_core_backtrace(text);
86 }
87 
88 struct sr_core_thread *
89 sr_core_stacktrace_find_crash_thread(struct sr_core_stacktrace *stacktrace)
90 {
91  return stacktrace;
92 }
93 
94 int
95 sr_core_thread_get_frame_count(struct sr_core_thread *thread)
96 {
97  return btp_thread_get_frame_count(thread);
98 }
99 
100 float
101 sr_distance_core(enum sr_distance_type distance_type,
102  struct sr_core_thread *thread1,
103  struct sr_core_thread *thread2)
104 {
105  return btp_thread_levenshtein_distance_custom(thread1, thread2, true,
106  btp_core_backtrace_frame_cmp);
107 }
108 
109 void
110 sr_core_stacktrace_free(struct sr_core_stacktrace *stacktrace)
111 {
112  btp_free_core_backtrace(stacktrace);
113 }
114 
115 /* abrt-action-analyze-backtrace.c */
116 #define sr_location btp_location
117 #define sr_gdb_stacktrace btp_backtrace
118 #define sr_gdb_frame btp_frame
119 
120 void
121 sr_location_init(struct sr_location *location)
122 {
123  btp_location_init(location);
124 }
125 
126 struct sr_gdb_stacktrace *
127 sr_gdb_stacktrace_parse(const char **input,
128  struct sr_location *location)
129 {
130  return btp_backtrace_parse(input, location);
131 }
132 
133 char *
134 sr_gdb_stacktrace_get_duplication_hash(struct sr_gdb_stacktrace *stacktrace)
135 {
136  return btp_backtrace_get_duplication_hash(stacktrace);
137 }
138 
139 float
140 sr_gdb_stacktrace_quality_complex(struct sr_gdb_stacktrace *stacktrace)
141 {
142  return btp_backtrace_quality_complex(stacktrace);
143 }
144 
145 struct sr_gdb_frame *
146 sr_gdb_stacktrace_get_crash_frame(struct sr_gdb_stacktrace *stacktrace)
147 {
148  return btp_backtrace_get_crash_frame(stacktrace);
149 }
150 
151 void
152 sr_gdb_frame_free(struct sr_gdb_frame *frame)
153 {
154  btp_frame_free(frame);
155 }
156 
157 void
158 sr_gdb_stacktrace_free(struct sr_gdb_stacktrace *stacktrace)
159 {
160  btp_backtrace_free(stacktrace);
161 }
162 
163 #endif /* USE_SATYR */
164 
165 #endif /* SATYR_COMPAT_H_ */