From 4a3d2e780899602237cdf09aa30c3ad48b01c342 Mon Sep 17 00:00:00 2001 From: Michael Lotz Date: Tue, 21 Jun 2011 20:25:49 +0000 Subject: [PATCH] Make the heap debug functions available when USE_SLAB_ALLOCATOR_FOR_MALLOC is enabled as well. As this heap implementation is still used for the port heap (as it handles B_NO_LOCK areas) those are still useful. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@42278 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/system/kernel/heap.cpp | 42 +++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/src/system/kernel/heap.cpp b/src/system/kernel/heap.cpp index 7a8f270454..0ef551c6d7 100644 --- a/src/system/kernel/heap.cpp +++ b/src/system/kernel/heap.cpp @@ -305,9 +305,6 @@ get_caller() #endif -#if !USE_SLAB_ALLOCATOR_FOR_MALLOC - - static void dump_page(heap_page *page) { @@ -379,12 +376,14 @@ dump_allocator(heap_allocator *heap, bool areas, bool bins) static int dump_heap_list(int argc, char **argv) { +#if !USE_SLAB_ALLOCATOR_FOR_MALLOC if (argc == 2 && strcmp(argv[1], "grow") == 0) { // only dump dedicated grow heap info kprintf("dedicated grow heap:\n"); dump_allocator(sGrowHeap, true, true); return 0; } +#endif bool stats = false; int i = 1; @@ -401,9 +400,13 @@ dump_heap_list(int argc, char **argv) } if (heapAddress == 0) { +#if !USE_SLAB_ALLOCATOR_FOR_MALLOC // dump default kernel heaps for (uint32 i = 0; i < sHeapCount; i++) dump_allocator(sHeaps[i], !stats, !stats); +#else + print_debugger_command_usage(argv[0]); +#endif } else { // dump specified heap dump_allocator((heap_allocator*)(addr_t)heapAddress, !stats, !stats); @@ -431,10 +434,22 @@ dump_allocations(int argc, char **argv) size_t totalSize = 0; uint32 totalCount = 0; +#if !USE_SLAB_ALLOCATOR_FOR_MALLOC for (uint32 heapIndex = 0; heapIndex < sHeapCount; heapIndex++) { heap_allocator *heap = sHeaps[heapIndex]; if (heapAddress != 0) heap = (heap_allocator *)(addr_t)heapAddress; +#else + while (true) { + heap_allocator *heap = (heap_allocator *)(addr_t)heapAddress; + if (heap == NULL) { + print_debugger_command_usage(argv[0]); + return 0; + } +#endif +#if 0 + } +#endif // go through all the pages in all the areas heap_area *area = heap->all_areas; @@ -824,8 +839,6 @@ dump_allocations_per_caller(int argc, char **argv) #endif // KERNEL_HEAP_LEAK_CHECK -#endif // !USE_SLAB_ALLOCATOR_FOR_MALLOC - #if PARANOID_HEAP_VALIDATION static void @@ -2054,7 +2067,7 @@ heap_init(addr_t base, size_t size) "argument, only allocations matching the team ID, thread ID, caller\n" "address or allocated address given in the second argument are printed.\n" "If the optional argument \"stats\" is specified, only the allocation\n" - "counts and no individual allocations are printed\n", 0); + "counts and no individual allocations are printed.\n", 0); add_debugger_command_etc("allocations_per_caller", &dump_allocations_per_caller, "Dump current heap allocations summed up per caller", @@ -2189,7 +2202,22 @@ heap_init_post_thread() resume_thread(sHeapGrowThread); -#endif // !USE_SLAB_ALLOCATOR_FOR_MALLOC +#else // !USE_SLAB_ALLOCATOR_FOR_MALLOC + + // set up some debug commands + add_debugger_command_etc("heap", &dump_heap_list, + "Dump infos about a specific heap", + "[\"stats\"] \n" + "Dump infos about the specified kernel heap. If \"stats\" is given\n" + "as the argument, currently only the heap count is printed.\n", 0); +#if !KERNEL_HEAP_LEAK_CHECK + add_debugger_command_etc("allocations", &dump_allocations, + "Dump current heap allocations", + "[\"stats\"] \n" + "If the optional argument \"stats\" is specified, only the allocation\n" + "counts and no individual allocations are printed.\n", 0); +#endif // KERNEL_HEAP_LEAK_CHECK +#endif // USE_SLAB_ALLOCATOR_FOR_MALLOC // run the deferred deleter roughly once a second if (register_kernel_daemon(deferred_deleter, NULL, 10) != B_OK)