Browse Source

More debug info

Cameron Weinfurt 5 months ago
parent
commit
5a87521bf3
3 changed files with 27 additions and 20 deletions
  1. 1
    0
      .gitignore
  2. 1
    1
      Makefile
  3. 25
    19
      tree_alloc.c

+ 1
- 0
.gitignore View File

@@ -1,3 +1,4 @@
1 1
 *.o
2 2
 the_alloc
3 3
 vgcore*
4
+debug_log.txt

+ 1
- 1
Makefile View File

@@ -7,7 +7,7 @@ OUT_NAME = the_alloc
7 7
 dev: CFLAGS= $(COMMON_FLAGS) -g -D UNIT_TESTS -D DEBUG=1
8 8
 dev: $(OUT_NAME)
9 9
 	rm -f vgcore.*
10
-	valgrind ./$(OUT_NAME)
10
+	valgrind ./$(OUT_NAME) 2&> debug_log.txt 
11 11
 
12 12
 release: CFLAGS= $(COMMON_FLAGS) -O2
13 13
 release: clean $(OUT_NAME)

+ 25
- 19
tree_alloc.c View File

@@ -250,6 +250,8 @@ void insert_singleton(TreeAlloc **root_ptr, TreeAlloc *to_insert) {
250 250
 void insert_right(TreeAlloc** root_ptr, TreeAlloc* to_insert, TreeAlloc* after) {
251 251
 #ifdef DEBUG
252 252
 	printf("=== PRE-INSERT-RIGHT ===\n");
253
+	printf("===== INSERTING =====\n");
254
+	debug_print_tree(0, to_insert);
253 255
 	printf("===== CURRENT TREE =====\n");
254 256
 	debug_print_tree(0, *root_ptr);
255 257
 	printf("===== END OF TREES =====\n");
@@ -273,6 +275,8 @@ void insert_right(TreeAlloc** root_ptr, TreeAlloc* to_insert, TreeAlloc* after)
273 275
 void insert_left(TreeAlloc** root_ptr, TreeAlloc* to_insert, TreeAlloc* before) {
274 276
 #ifdef DEBUG
275 277
 	printf("=== PRE-INSERT-LEFT ====\n");
278
+	printf("===== INSERTING =====\n");
279
+	debug_print_tree(0, to_insert);
276 280
 	printf("===== CURRENT TREE =====\n");
277 281
 	debug_print_tree(0, *root_ptr);
278 282
 	printf("===== END OF TREES =====\n");
@@ -348,42 +352,44 @@ void repair_after_remove(TreeAlloc **root_ptr, TreeAlloc *node) {
348 352
 	}
349 353
 }
350 354
 
351
-void remove_node(TreeAlloc **root_ptr, TreeAlloc *node) {
355
+void remove_node(TreeAlloc **root_ptr, TreeAlloc *to_remove) {
352 356
 	char do_repair = 0;
353 357
 #ifdef DEBUG
354 358
 	printf("====== PRE-REMOVE ======\n");
359
+	printf("===== REMOVING =====\n");
360
+	debug_print_tree(0, to_remove);
355 361
 	printf("===== CURRENT TREE =====\n");
356 362
 	debug_print_tree(0, *root_ptr);
357 363
 	printf("===== END OF TREES =====\n");
358 364
 #endif
359 365
 	TreeAlloc *replace;
360
-	TreeAlloc *parent = node->parent;
361
-	if (!node->left) {
362
-		replace = node->right;
363
-		do_repair = node->color == COLOR_BLACK;
364
-		replace_node(root_ptr, node, replace);
365
-	} else if (!node->right) {
366
-		replace = node->left;
367
-		do_repair = node->color == COLOR_BLACK;
368
-		replace_node(root_ptr, node, replace);
366
+	TreeAlloc *parent = to_remove->parent;
367
+	if (!to_remove->left) {
368
+		replace = to_remove->right;
369
+		do_repair = to_remove->color == COLOR_BLACK;
370
+		replace_node(root_ptr, to_remove, replace);
371
+	} else if (!to_remove->right) {
372
+		replace = to_remove->left;
373
+		do_repair = to_remove->color == COLOR_BLACK;
374
+		replace_node(root_ptr, to_remove, replace);
369 375
 	} else {
370
-		TreeAlloc *tmp = node->right;
376
+		TreeAlloc *tmp = to_remove->right;
371 377
 		while (tmp->left) tmp = tmp->left;
372 378
 		replace = tmp->right;
373 379
 		do_repair = tmp->color == COLOR_BLACK;
374
-		if (tmp != node->right) {
380
+		if (tmp != to_remove->right) {
375 381
 			replace_node(root_ptr, tmp, replace);
376
-			tmp->right = node->right;
377
-			node->right->parent = tmp;
382
+			tmp->right = to_remove->right;
383
+			to_remove->right->parent = tmp;
378 384
 		}
379
-		replace_node(root_ptr, node, tmp);
380
-		tmp->color = node->color;
381
-		tmp->left = node->left;
382
-		node->left->parent = tmp;
385
+		replace_node(root_ptr, to_remove, tmp);
386
+		tmp->color = to_remove->color;
387
+		tmp->left = to_remove->left;
388
+		to_remove->left->parent = tmp;
383 389
 	}
384 390
 
385 391
 	// Make sure that it doesn't have any tree pointers it shouldn't have.
386
-	node->parent = node->left = node->right = NULL;
392
+	to_remove->parent = to_remove->left = to_remove->right = NULL;
387 393
 
388 394
 	if (replace && replace->parent == NULL) {
389 395
 #ifdef DEBUG

Loading…
Cancel
Save