From b77bffb004c6b6d8d97f3a32d2373f0376d5cc70 Mon Sep 17 00:00:00 2001 From: Timo Kokkonen Date: Sat, 24 Apr 2010 13:48:12 +0300 Subject: [PATCH] quadtree.c: Improve debuggin capabilities -Flush out prints immedeatly. This will ensure prints get out even though execution is halted to a breakpoint. -Add some extra debug messages Signed-off-by: Timo Kokkonen --- quadtree.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/quadtree.c b/quadtree.c index a914f66..de59a2f 100644 --- a/quadtree.c +++ b/quadtree.c @@ -21,14 +21,22 @@ static void validate_subtree(const struct quadtree *node) long int children; children = 0; + if (!node) { + printf("Attempted to validate a null pointer\n"); + fflush(stdout); + trap(); + } + for (i = 0; i < 4; i++) { if (!node->child[i]) continue; if (node->child[i]->parent != node) { - printf("%s:%d Fatal! Tree inconsistency detected " - "at child %d in node %p\n", - __func__, __LINE__, i, node); + printf("%s:%d Fatal! Tree inconsistency detected at " + "child %d %p in node %p, incorrent parent %p\n", + __func__, __LINE__, i, node->child[i], node, + node->child[i]->parent); + fflush(stdout); trap(); } @@ -37,6 +45,7 @@ static void validate_subtree(const struct quadtree *node) printf("%s:%d Fatal! Tree loop detected " "at child %d in node %p\n", __func__, __LINE__, i, node); + fflush(stdout); trap(); } } @@ -56,6 +65,7 @@ static void validate_subtree(const struct quadtree *node) printf("%s:%d Tree statistics inconsistency detected! " "child count mismatch. Expected %ld, got %ld\n", __func__, __LINE__, children, node->children); + fflush(stdout); trap(); } @@ -78,6 +88,7 @@ static void validate_subtree(const struct quadtree *node) printf("%s:%d Tree statistics inconsistency detected! " "child depth mismatch.", __func__, __LINE__); + fflush(stdout); trap(); } } @@ -131,6 +142,11 @@ struct quadtree *quadtree_add(struct quadtree *parent, struct quadtree *new, parent->child[ret] = new; new->parent = parent; + if (debug) { + printf("adding node %p to parent %p\n", new, parent); + fflush(stdout); + } + quadtree_recalculate_parent_stats(new, ops); validate_tree(new); @@ -187,6 +203,11 @@ struct quadtree *quadtree_del(struct quadtree *node, struct quadtree *parent = 0; int i; + if (debug) { + printf("Deleting node %p under parent %p\n", + node, node->parent); + fflush(stdout); + } /* * We are deleting the root node. This means we have to select * a new root node and reconstruct the entire tree under it -- 2.45.0