Added a frame enumerator to backtrace_t
authorMartin Willi <martin@revosec.ch>
Fri, 29 Apr 2011 11:56:20 +0000 (13:56 +0200)
committerMartin Willi <martin@revosec.ch>
Mon, 16 May 2011 13:22:21 +0000 (15:22 +0200)
src/libstrongswan/utils/backtrace.c
src/libstrongswan/utils/backtrace.h

index f69bd15..cb83d98 100644 (file)
@@ -176,6 +176,44 @@ METHOD(backtrace_t, equals, bool,
        return TRUE;
 }
 
+/**
+ * Frame enumerator
+ */
+typedef struct {
+       /** implements enumerator_t */
+       enumerator_t public;
+       /** reference to backtrace */
+       private_backtrace_t *bt;
+       /** current position */
+       int i;
+} frame_enumerator_t;
+
+METHOD(enumerator_t, frame_enumerate, bool,
+       frame_enumerator_t *this, void **addr)
+{
+       if (this->i < this->bt->frame_count)
+       {
+               *addr = this->bt->frames[this->i++];
+               return TRUE;
+       }
+       return FALSE;
+}
+
+METHOD(backtrace_t, create_frame_enumerator, enumerator_t*,
+       private_backtrace_t *this)
+{
+       frame_enumerator_t *enumerator;
+
+       INIT(enumerator,
+               .public = {
+                       .enumerate = (void*)_frame_enumerate,
+                       .destroy = (void*)free,
+               },
+               .bt = this,
+       );
+       return &enumerator->public;
+}
+
 METHOD(backtrace_t, destroy, void,
        private_backtrace_t *this)
 {
@@ -203,6 +241,7 @@ backtrace_t *backtrace_create(int skip)
                .log = _log_,
                .contains_function = _contains_function,
                .equals = _equals,
+               .create_frame_enumerator = _create_frame_enumerator,
                .destroy = _destroy,
        };
 
index cf4d277..9d59d25 100644 (file)
@@ -56,6 +56,12 @@ struct backtrace_t {
         * @return              TRUE if backtraces are equal
         */
        bool (*equals)(backtrace_t *this, backtrace_t *other);
+       /**
+        * Create an enumerator over the stack frame addresses.
+        *
+        * @return              enumerator_t over void*
+        */
+       enumerator_t* (*create_frame_enumerator)(backtrace_t *this);
 
        /**
         * Destroy a backtrace instance.