Add tree walking debug function

This commit is contained in:
2025-09-09 16:03:25 -07:00
parent 5064f304ca
commit 4fe4e293ad
3 changed files with 105 additions and 8 deletions

View File

@ -457,6 +457,34 @@ static inline bool refcount_remove_destructor(void *obj, void *key) {
}
// Debug Functions
/**
* Callback used from #refcount_debug_context_walk_tree.
* @param cur The current object in the walk
* @param trail The parent objects, up to the root object
* @return True if the walk should stop, false otherwise
*/
typedef bool (*refcount_debug_walk_callback_t)(void *cur,
const RefcountList *trail,
void *user_data);
bool refcount_debug_context_walk_tree(const RefcountContext *ctx, void *obj,
refcount_debug_walk_callback_t callback,
void *user_data);
/**
* Same as #refcount_debug_context_walk_tree, but only operates on the global
* context.
* @param obj The root object
* @param callback The callback
* @param user_data Extra data to pass to the callback
* @return True if the walk ended early because a callback returned true, false
*/
static inline bool
refcount_debug_walk_tree(void *obj, refcount_debug_walk_callback_t callback,
void *user_data) {
return refcount_debug_context_walk_tree(refcount_default_context, obj,
callback, user_data);
}
uint64_t refcount_debug_context_count_object(const RefcountContext *ctx,
void *obj, void *target);