abrt  2.1.5
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.0
59 
60 /* abrt-handle-event.c */
61 #define sr_core_stacktrace btp_thread
62 #define sr_core_thread btp_thread
63 
64 enum sr_distance_type
65 {
66  SR_DISTANCE_DAMERAU_LEVENSHTEIN
67 };
68 
69 /* The functions should be static but that generates unused function warnings.
70  * We don't include this header in two compilation units that are then linked
71  * together anyway, so this should work. And this file should be gone soon ...
72  */
73 struct sr_core_stacktrace *
74 sr_core_stacktrace_from_json_text(const char *text,
75  char **error_message)
76 {
77  struct btp_thread *thread = btp_load_core_backtrace(text);
78  if (!thread)
79  {
80  *error_message = xstrdup(
81  "Failed to parse backtrace, considering it not duplicate");
82  return NULL;
83  }
84  return btp_load_core_backtrace(text);
85 }
86 
87 struct sr_core_thread *
88 sr_core_stacktrace_find_crash_thread(struct sr_core_stacktrace *stacktrace)
89 {
90  return stacktrace;
91 }
92 
93 int
94 sr_core_thread_get_frame_count(struct sr_core_thread *thread)
95 {
96  return btp_thread_get_frame_count(thread);
97 }
98 
99 int
100 sr_core_thread_cmp(struct sr_core_thread *thread1,
101  struct sr_core_thread *thread2)
102 {
103  return btp_thread_cmp(thread1, thread2);
104 }
105 
106 float
107 sr_distance_core(enum sr_distance_type distance_type,
108  struct sr_core_thread *thread1,
109  struct sr_core_thread *thread2)
110 {
111  return btp_thread_levenshtein_distance_custom(thread1, thread2, true,
112  btp_core_backtrace_frame_cmp);
113 }
114 
115 void
116 sr_core_stacktrace_free(struct sr_core_stacktrace *stacktrace)
117 {
118  btp_free_core_backtrace(stacktrace);
119 }
120 
121 /* abrt-action-analyze-backtrace.c */
122 #define sr_location btp_location
123 #define sr_gdb_stacktrace btp_backtrace
124 #define sr_gdb_frame btp_frame
125 
126 void
127 sr_location_init(struct sr_location *location)
128 {
129  btp_location_init(location);
130 }
131 
132 struct sr_gdb_stacktrace *
133 sr_gdb_stacktrace_parse(const char **input,
134  struct sr_location *location)
135 {
136  return btp_backtrace_parse(input, location);
137 }
138 
139 char *
140 sr_gdb_stacktrace_get_duplication_hash(struct sr_gdb_stacktrace *stacktrace)
141 {
142  return btp_backtrace_get_duplication_hash(stacktrace);
143 }
144 
145 float
146 sr_gdb_stacktrace_quality_complex(struct sr_gdb_stacktrace *stacktrace)
147 {
148  return btp_backtrace_quality_complex(stacktrace);
149 }
150 
151 struct sr_gdb_frame *
152 sr_gdb_stacktrace_get_crash_frame(struct sr_gdb_stacktrace *stacktrace)
153 {
154  return btp_backtrace_get_crash_frame(stacktrace);
155 }
156 
157 void
158 sr_gdb_frame_free(struct sr_gdb_frame *frame)
159 {
160  btp_frame_free(frame);
161 }
162 
163 void
164 sr_gdb_stacktrace_free(struct sr_gdb_stacktrace *stacktrace)
165 {
166  btp_backtrace_free(stacktrace);
167 }
168 
169 #endif /* USE_SATYR */
170 
171 #endif /* SATYR_COMPAT_H_ */