[SATYR PATCH 2/6] Add sr_frame_cmp and sr_frame_cmp_distance
Martin Milata
mmilata at redhat.com
Fri Jun 14 18:01:08 UTC 2013
Signed-off-by: Martin Milata <mmilata at redhat.com>
---
include/frame.h | 14 ++++++++++++++
lib/core_frame.c | 4 ++++
lib/core_thread.c | 2 +-
lib/gdb_frame.c | 8 ++++++++
lib/gdb_thread.c | 2 +-
lib/generic_frame.c | 18 ++++++++++++++++++
lib/generic_frame.h | 3 +++
lib/generic_thread.h | 4 ++--
lib/java_frame.c | 2 ++
lib/java_thread.c | 2 +-
lib/koops_frame.c | 2 ++
lib/koops_stacktrace.c | 2 +-
lib/python_frame.c | 2 ++
lib/python_stacktrace.c | 2 +-
14 files changed, 60 insertions(+), 7 deletions(-)
diff --git a/include/frame.h b/include/frame.h
index bb23419..9eda374 100644
--- a/include/frame.h
+++ b/include/frame.h
@@ -57,6 +57,20 @@ sr_frame_next(struct sr_frame *frame);
void
sr_frame_append_to_str(struct sr_frame *frame, struct sr_strbuf *strbuf);
+/**
+ * Compares two frames. Returns 0 on equality. Frames of distinct type are
+ * always unequal.
+ */
+int
+sr_frame_cmp(struct sr_frame *t1, struct sr_frame *t2);
+
+/**
+ * Compares two frames for the purpose of thread distance computation. Returns
+ * 0 on equality. Frames of distinct type are always unequal.
+ */
+int
+sr_frame_cmp_distance(struct sr_frame *t1, struct sr_frame *t2);
+
#ifdef __cplusplus
}
#endif
diff --git a/lib/core_frame.c b/lib/core_frame.c
index a2d1ef0..ac3f601 100644
--- a/lib/core_frame.c
+++ b/lib/core_frame.c
@@ -33,6 +33,8 @@ struct frame_methods core_frame_methods =
{
.append_to_str = (append_to_str_fn_t) sr_core_frame_append_to_str,
.next = (next_frame_fn_t) core_next,
+ .cmp = (frame_cmp_fn_t) sr_core_frame_cmp,
+ .cmp_distance = (frame_cmp_fn_t) sr_core_frame_cmp_distance,
};
/* Public functions */
@@ -176,6 +178,8 @@ int
sr_core_frame_cmp_distance(struct sr_core_frame *frame1,
struct sr_core_frame *frame2)
{
+ /* TODO: we should not rely on function name and we definitely should use
+ * build id */
/* Function name. */
int function_name = sr_strcmp0(frame1->function_name,
frame2->function_name);
diff --git a/lib/core_thread.c b/lib/core_thread.c
index 3ebf1d9..e97f806 100644
--- a/lib/core_thread.c
+++ b/lib/core_thread.c
@@ -34,7 +34,7 @@ DEFINE_NEXT_FUNC(core_next, struct sr_thread, struct sr_core_thread)
struct thread_methods core_thread_methods =
{
.frames = (frames_fn_t) core_frames,
- .cmp = (cmp_fn_t) sr_core_thread_cmp,
+ .cmp = (thread_cmp_fn_t) sr_core_thread_cmp,
.frame_count = (frame_count_fn_t) thread_frame_count,
.next = (next_thread_fn_t) core_next,
};
diff --git a/lib/gdb_frame.c b/lib/gdb_frame.c
index e3b30fb..f9e7f41 100644
--- a/lib/gdb_frame.c
+++ b/lib/gdb_frame.c
@@ -32,10 +32,18 @@
DEFINE_NEXT_FUNC(gdb_next, struct sr_frame, struct sr_gdb_frame)
+static int
+frame_cmp_without_number(struct sr_gdb_frame *frame1, struct sr_gdb_frame *frame2)
+{
+ return sr_gdb_frame_cmp(frame1, frame2, false);
+}
+
struct frame_methods gdb_frame_methods =
{
.append_to_str = (append_to_str_fn_t) sr_gdb_frame_append_to_str,
.next = (next_frame_fn_t) gdb_next,
+ .cmp = (frame_cmp_fn_t) frame_cmp_without_number,
+ .cmp_distance = (frame_cmp_fn_t) sr_gdb_frame_cmp_distance,
};
/* Public functions */
diff --git a/lib/gdb_thread.c b/lib/gdb_thread.c
index 21acca3..e1af1f2 100644
--- a/lib/gdb_thread.c
+++ b/lib/gdb_thread.c
@@ -38,7 +38,7 @@ DEFINE_NEXT_FUNC(gdb_next, struct sr_thread, struct sr_gdb_thread)
struct thread_methods gdb_thread_methods =
{
.frames = (frames_fn_t) gdb_frames,
- .cmp = (cmp_fn_t) sr_gdb_thread_cmp,
+ .cmp = (thread_cmp_fn_t) sr_gdb_thread_cmp,
.frame_count = (frame_count_fn_t) thread_frame_count,
.next = (next_thread_fn_t) gdb_next,
};
diff --git a/lib/generic_frame.c b/lib/generic_frame.c
index 9041037..83d399e 100644
--- a/lib/generic_frame.c
+++ b/lib/generic_frame.c
@@ -43,3 +43,21 @@ sr_frame_next(struct sr_frame *frame)
{
return DISPATCH(dtable, frame->type, next)(frame);
}
+
+int
+sr_frame_cmp(struct sr_frame *frame1, struct sr_frame *frame2)
+{
+ if (frame1->type != frame2->type)
+ return frame1->type - frame2->type;
+
+ return DISPATCH(dtable, frame1->type, cmp)(frame1, frame2);
+}
+
+int
+sr_frame_cmp_distance(struct sr_frame *frame1, struct sr_frame *frame2)
+{
+ if (frame1->type != frame2->type)
+ return frame1->type - frame2->type;
+
+ return DISPATCH(dtable, frame1->type, cmp_distance)(frame1, frame2);
+}
diff --git a/lib/generic_frame.h b/lib/generic_frame.h
index 5e28817..138123c 100644
--- a/lib/generic_frame.h
+++ b/lib/generic_frame.h
@@ -22,11 +22,14 @@
typedef void (*append_to_str_fn_t)(struct sr_frame *, struct sr_strbuf *);
typedef struct sr_frame* (*next_frame_fn_t)(struct sr_frame *);
+typedef int (*frame_cmp_fn_t)(struct sr_frame *, struct sr_frame *);
struct frame_methods
{
append_to_str_fn_t append_to_str;
next_frame_fn_t next;
+ frame_cmp_fn_t cmp;
+ frame_cmp_fn_t cmp_distance;
};
extern struct frame_methods core_frame_methods, python_frame_methods,
diff --git a/lib/generic_thread.h b/lib/generic_thread.h
index e1e5f0a..c53f6fe 100644
--- a/lib/generic_thread.h
+++ b/lib/generic_thread.h
@@ -21,14 +21,14 @@
#include "thread.h"
typedef struct sr_frame* (*frames_fn_t)(struct sr_thread*);
-typedef int (*cmp_fn_t)(struct sr_thread*, struct sr_thread*);
+typedef int (*thread_cmp_fn_t)(struct sr_thread*, struct sr_thread*);
typedef int (*frame_count_fn_t)(struct sr_thread*);
typedef struct sr_thread* (*next_thread_fn_t)(struct sr_thread*);
struct thread_methods
{
frames_fn_t frames;
- cmp_fn_t cmp;
+ thread_cmp_fn_t cmp;
frame_count_fn_t frame_count;
next_thread_fn_t next;
};
diff --git a/lib/java_frame.c b/lib/java_frame.c
index fc8ae29..dfe9f86 100644
--- a/lib/java_frame.c
+++ b/lib/java_frame.c
@@ -39,6 +39,8 @@ struct frame_methods java_frame_methods =
{
.append_to_str = (append_to_str_fn_t) sr_java_frame_append_to_str,
.next = (next_frame_fn_t) java_next,
+ .cmp = (frame_cmp_fn_t) sr_java_frame_cmp,
+ .cmp_distance = (frame_cmp_fn_t) sr_java_frame_cmp_distance,
};
/* Public functions */
diff --git a/lib/java_thread.c b/lib/java_thread.c
index ef5f73c..f149f76 100644
--- a/lib/java_thread.c
+++ b/lib/java_thread.c
@@ -38,7 +38,7 @@ DEFINE_NEXT_FUNC(java_next, struct sr_thread, struct sr_java_thread)
struct thread_methods java_thread_methods =
{
.frames = (frames_fn_t) java_frames,
- .cmp = (cmp_fn_t) sr_java_thread_cmp,
+ .cmp = (thread_cmp_fn_t) sr_java_thread_cmp,
.frame_count = (frame_count_fn_t) thread_frame_count,
.next = (next_thread_fn_t) java_next,
};
diff --git a/lib/koops_frame.c b/lib/koops_frame.c
index 76f5027..286bc94 100644
--- a/lib/koops_frame.c
+++ b/lib/koops_frame.c
@@ -36,6 +36,8 @@ struct frame_methods koops_frame_methods =
{
.append_to_str = (append_to_str_fn_t) sr_koops_frame_append_to_str,
.next = (next_frame_fn_t) koops_next,
+ .cmp = (frame_cmp_fn_t) sr_koops_frame_cmp,
+ .cmp_distance = (frame_cmp_fn_t) sr_koops_frame_cmp_distance,
};
/* Public functions */
diff --git a/lib/koops_stacktrace.c b/lib/koops_stacktrace.c
index 16d96a3..f6c4ccb 100644
--- a/lib/koops_stacktrace.c
+++ b/lib/koops_stacktrace.c
@@ -61,7 +61,7 @@ DEFINE_THREAD_FUNC(koops_frames, struct sr_koops_stacktrace)
struct thread_methods koops_thread_methods =
{
.frames = (frames_fn_t) koops_frames,
- .cmp = (cmp_fn_t) NULL,
+ .cmp = (thread_cmp_fn_t) NULL,
.frame_count = (frame_count_fn_t) thread_frame_count,
.next = (next_thread_fn_t) thread_no_next_thread,
};
diff --git a/lib/python_frame.c b/lib/python_frame.c
index 86ecb4e..e3ae238 100644
--- a/lib/python_frame.c
+++ b/lib/python_frame.c
@@ -35,6 +35,8 @@ struct frame_methods python_frame_methods =
{
.append_to_str = (append_to_str_fn_t) sr_python_frame_append_to_str,
.next = (next_frame_fn_t) python_next,
+ .cmp = (frame_cmp_fn_t) sr_python_frame_cmp,
+ .cmp_distance = (frame_cmp_fn_t) sr_python_frame_cmp_distance,
};
/* Public functions */
diff --git a/lib/python_stacktrace.c b/lib/python_stacktrace.c
index 278d175..fbb0807 100644
--- a/lib/python_stacktrace.c
+++ b/lib/python_stacktrace.c
@@ -39,7 +39,7 @@ DEFINE_THREAD_FUNC(python_frames, struct sr_python_stacktrace)
struct thread_methods python_thread_methods =
{
.frames = (frames_fn_t) python_frames,
- .cmp = (cmp_fn_t) NULL,
+ .cmp = (thread_cmp_fn_t) NULL,
.frame_count = (frame_count_fn_t) thread_frame_count,
.next = (next_thread_fn_t) thread_no_next_thread,
};
--
1.7.11.7
More information about the Crash-catcher
mailing list