Added a frame enumerator to backtrace_t
This commit is contained in:
@@ -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,
|
||||
};
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user