Browse Source

Added find_raw_block_owner() in debug functions

Ioannis Koutras 13 years ago
parent
commit
c3fa58507c
2 changed files with 31 additions and 0 deletions
  1. 3 0
      private-include/debug.h
  2. 28 0
      src/debug.c

+ 3 - 0
private-include/debug.h

@@ -27,7 +27,10 @@
 #include "dmm_config.h"
 
 #include "dmmlib/allocator.h"
+#include "dmmlib/raw_block.h"
 
 void get_raw_blocks(allocator_t *allocator);
 
+raw_block_header_t *find_raw_block_owner(void *ptr);
+
 #endif /* DEBUG_H */

+ 28 - 0
src/debug.c

@@ -25,6 +25,8 @@
 #include "debug.h"
 
 #include "trace.h"
+#include <stdbool.h>
+#include "dmmlib/dmmlib.h"
 
 /** Gets the number of raw blocks that are currently managed by an allocator.
  *
@@ -48,3 +50,29 @@ void get_raw_blocks(allocator_t *allocator) {
     TRACE_1("dmmlib - there are %d raw blocks\n", counter);
 
 }
+
+/** Tries to find the raw block owner of a memory allocation.
+ *
+ * @param ptr The pointer of the memory allocation.
+ */
+raw_block_header_t *find_raw_block_owner(void *ptr) {
+    raw_block_header_t *current_raw_block;
+    bool found;
+
+    for(current_raw_block = systemallocator.raw_block_head;
+            current_raw_block != NULL;
+            current_raw_block = current_raw_block->next_raw_block) {
+        if(((char *)ptr > (char *)current_raw_block) &&
+                ((char *)ptr < (char *)current_raw_block +
+                 current_raw_block->size)) {
+            found = true;
+            break;
+        }
+    }
+
+    if(found) {
+        return current_raw_block;
+    } else {
+        return NULL;
+    }
+}