-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprint.c
47 lines (33 loc) · 888 Bytes
/
print.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "Heap.h"
#include <stdio.h>
//
// Dump out all of the entries in the heap
//
void dump_heap(void) {
pHeap_Block_t block = lock_heap();
if (!block) {printf("Lock Failed!\n"); return;}
do {
print_heap_entry(block+1);
} while (block = block->next);
unlock_heap();
}
//
// Print out a block in the heap
//
void print_heap_block(pHeap_Block_t block) {
if (!block) {printf("Invalid Block!\n"); return;}
printf("%-16p: Next: %-16p\tPre: %-16p\tSize: %-18lld\tChecksum:%llu",
block, block->next, block->pre,
(long long) block->size, (unsigned long long) block->checksum
);
if (!valid_block(block)) {printf("\t*INVALID*\n");}
printf("\n");
}
//
// Print out the data returned from malloc, calloc, or realloc
//
void print_heap_entry(void* ptr) {
if (!ptr) {printf("Invalid Pointer!\n");}
pHeap_Block_t block = PTR_BLOCK(ptr);
print_heap_block(block);
}