[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r8443 - in flightrecorder/src: include libflightrecorder
From: |
gnunet |
Subject: |
[GNUnet-SVN] r8443 - in flightrecorder/src: include libflightrecorder |
Date: |
Fri, 1 May 2009 15:17:23 -0600 |
Author: durner
Date: 2009-05-01 15:17:23 -0600 (Fri, 01 May 2009)
New Revision: 8443
Modified:
flightrecorder/src/include/flightrecorder.h
flightrecorder/src/libflightrecorder/stack_trace.c
Log:
fr_st_cmp(), -dup(), -free()
Modified: flightrecorder/src/include/flightrecorder.h
===================================================================
--- flightrecorder/src/include/flightrecorder.h 2009-05-01 20:25:13 UTC (rev
8442)
+++ flightrecorder/src/include/flightrecorder.h 2009-05-01 21:17:23 UTC (rev
8443)
@@ -43,6 +43,7 @@
typedef int (*StackTraceIterator)(struct StackTraceEntry *entry);
typedef enum {FR_OPT_RECORD_STACK_TRACE} FR_Option;
+typedef enum {FR_DUP_STACK, FR_DUP_INFO} FR_StackTrace_Duplication_Type;
void *fr_malloc (size_t n);
void *fr_calloc (size_t n, size_t s);
@@ -126,6 +127,28 @@
*/
void fr_st_iterate(struct StackTrace *trace, StackTraceIterator iter);
+/**
+ * @brief Compare two stack traces
+ * @param trace1 first stack trace
+ * @param trace2 second trace
+ * @return 1 if equal, 0 otherwise
+ */
+int fr_st_cmp(struct StackTrace *trace1, struct StackTrace *trace2);
+
+/**
+ * @brief Duplicate a stack trace
+ * @param trace stack trace to duplicate
+ * @param type mode of duplication
+ * @return new stack trace
+ */
+struct StackTrace *fr_st_dup(struct StackTrace *trace,
FR_StackTrace_Duplication_Type type);
+
+/**
+ * @brief Release a stack trace
+ * @param trace stack trace to release
+ */
+void fr_st_free(struct StackTrace *trace);
+
/* --- Stack traces - C/S API --- */
/**
Modified: flightrecorder/src/libflightrecorder/stack_trace.c
===================================================================
--- flightrecorder/src/libflightrecorder/stack_trace.c 2009-05-01 20:25:13 UTC
(rev 8442)
+++ flightrecorder/src/libflightrecorder/stack_trace.c 2009-05-01 21:17:23 UTC
(rev 8443)
@@ -202,3 +202,112 @@
entry--;
}
}
+
+/**
+ * @brief Compare two stack traces
+ * @param trace1 first stack trace
+ * @param trace2 second trace
+ * @return 1 if equal, 0 otherwise
+ */
+int fr_st_cmp(struct StackTrace *trace1, struct StackTrace *trace2)
+{
+ unsigned int cur, len;
+
+ len = trace1->depth;
+
+ if (len != trace2->depth)
+ return 0;
+
+ for (cur = 0; cur < len; cur++)
+ {
+ struct StackTraceEntry entry1, entry2;
+
+ entry1 = trace1->entries[cur];
+ entry2 = trace2->entries[cur];
+
+ if (strcmp(entry1->file, entry2->file) != 0 || entry1->line !=
entry2->line)
+ return 0;
+ }
+
+ return 1;
+}
+
+/**
+ * @brief Duplicate a stack trace
+ * @param trace stack trace to duplicate
+ * @param type mode of duplication
+ * @return new stack trace
+ */
+struct StackTrace *fr_st_dup(struct StackTrace *trace,
FR_StackTrace_Duplication_Type type)
+{
+ struct StackTrace *ret;
+ struct StackTraceEntry *src_entry, *dst_entry;
+ unsigned int entry_idx;
+
+ ret = (struct StackTrace *) malloc(sizeof(struct StackTrace));
+ memset(ret, sizeof(struct StackTrace), 0);
+ ret->depth = trace->depth;
+ ret->tid = trace->tid;
+ ret->entries = (struct StackTraceEntries *) malloc(sizeof(struct
StackTraceEntry) * ret->depth);
+ memset(ret->entries, sizeof(struct StackTraceEntries) * ret->depth);
+
+ src_entry = trace->entries;
+ dst_entry = ret->entries;
+ for (entry_idx = trace->depth; entry_idx > 0; entry_idx--)
+ {
+ dst_entry->file = strdup(src_entry->file);
+ dst_entry->line = src_entry->line;
+ if (src_entry->function)
+ dst_entry->function = strdup(src_entry->function);
+
+ if (type == FR_DUP_INFO)
+ {
+ unsigned int info_idx;
+ char **src_info, **dst_info;
+
+ dst_entry->info_count = src_entry->info_count;
+ src_info = src_entry->infos;
+ dst_info = dst_entry->infos;
+ for (info_idx = src_entry->info_count; info_idx > 0; info_idx--)
+ {
+ *dst_info = strdup(*src_info);
+ dst_info++;
+ src_info++;
+ }
+ }
+
+ src_entry++;
+ dst_entry++;
+ }
+
+ return ret;
+}
+
+/**
+ * @brief Release a stack trace
+ * @param trace stack trace to release
+ */
+void fr_st_free(struct StackTrace *trace)
+{
+ struct StackTraceEntry *entry;
+ unsigned int entry_idx;
+ unsigned int info_idx;
+ char **info;
+
+ entry = trace->entries;
+ for (entry_idx = trace->depth; entry_idx > 0; entry_idx--)
+ {
+ free(entry->file);
+ if (entry->function)
+ free(entry->function);
+
+ info = entry->infos;
+ for (info_idx = entry->info_count; info_idx > 0; info_idx--)
+ {
+ free(*src_info);
+ info++;
+ }
+
+ entry++;
+ }
+}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r8443 - in flightrecorder/src: include libflightrecorder,
gnunet <=