backtrace: add a clone() method
This commit is contained in:
@@ -52,6 +52,11 @@ struct private_backtrace_t {
|
||||
void *frames[];
|
||||
};
|
||||
|
||||
/**
|
||||
* Forward declaration of method getter
|
||||
*/
|
||||
static backtrace_t get_methods();
|
||||
|
||||
/**
|
||||
* Write a format string with arguments to a FILE line, if it is NULL to DBG
|
||||
*/
|
||||
@@ -531,6 +536,21 @@ METHOD(backtrace_t, create_frame_enumerator, enumerator_t*,
|
||||
return &enumerator->public;
|
||||
}
|
||||
|
||||
METHOD(backtrace_t, clone, backtrace_t*,
|
||||
private_backtrace_t *this)
|
||||
{
|
||||
private_backtrace_t *clone;
|
||||
|
||||
clone = malloc(sizeof(private_backtrace_t) +
|
||||
this->frame_count * sizeof(void*));
|
||||
memcpy(clone->frames, this->frames, this->frame_count * sizeof(void*));
|
||||
clone->frame_count = this->frame_count;
|
||||
|
||||
clone->public = get_methods();
|
||||
|
||||
return &clone->public;
|
||||
}
|
||||
|
||||
METHOD(backtrace_t, destroy, void,
|
||||
private_backtrace_t *this)
|
||||
{
|
||||
@@ -564,6 +584,21 @@ static inline int backtrace_unwind(void **frames, int count)
|
||||
}
|
||||
#endif /* HAVE_UNWIND */
|
||||
|
||||
/**
|
||||
* Get implementation methods of backtrace_t
|
||||
*/
|
||||
static backtrace_t get_methods()
|
||||
{
|
||||
return (backtrace_t) {
|
||||
.log = _log_,
|
||||
.contains_function = _contains_function,
|
||||
.equals = _equals,
|
||||
.clone = _clone,
|
||||
.create_frame_enumerator = _create_frame_enumerator,
|
||||
.destroy = _destroy,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* See header
|
||||
*/
|
||||
@@ -583,13 +618,7 @@ backtrace_t *backtrace_create(int skip)
|
||||
memcpy(this->frames, frames + skip, frame_count * sizeof(void*));
|
||||
this->frame_count = frame_count;
|
||||
|
||||
this->public = (backtrace_t) {
|
||||
.log = _log_,
|
||||
.contains_function = _contains_function,
|
||||
.equals = _equals,
|
||||
.create_frame_enumerator = _create_frame_enumerator,
|
||||
.destroy = _destroy,
|
||||
};
|
||||
this->public = get_methods();
|
||||
|
||||
return &this->public;
|
||||
}
|
||||
|
||||
@@ -59,6 +59,14 @@ struct backtrace_t {
|
||||
* @return TRUE if backtraces are equal
|
||||
*/
|
||||
bool (*equals)(backtrace_t *this, backtrace_t *other);
|
||||
|
||||
/**
|
||||
* Create a copy of this backtrace.
|
||||
*
|
||||
* @return cloned copy
|
||||
*/
|
||||
backtrace_t* (*clone)(backtrace_t *this);
|
||||
|
||||
/**
|
||||
* Create an enumerator over the stack frame addresses.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user