From e075b5a32e8f8f83c3756b7b1fae058137b54d83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Sat, 31 Dec 2005 14:31:31 +0000 Subject: [PATCH] Added some debug helper. Hopefully they give more insight to Stephan's problem (bug #77/#78). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15767 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/system/kernel/cache/block_cache.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/system/kernel/cache/block_cache.cpp b/src/system/kernel/cache/block_cache.cpp index 62e53139aa..45fc2fd807 100644 --- a/src/system/kernel/cache/block_cache.cpp +++ b/src/system/kernel/cache/block_cache.cpp @@ -37,6 +37,9 @@ # define TRACE(x) ; #endif +// This macro is used for fatal situations that are acceptable in a running +// system, like out of memory situations - should only panic for debugging. +#define FATAL(x) panic x struct cache_transaction { cache_transaction(); @@ -238,6 +241,9 @@ block_cache::Free(void *address) return; block_range *range = GetRange(address); + if (range == NULL) + panic("no range for address %p\n", address); + ASSERT(range != NULL); range->Free(this, address); @@ -282,11 +288,14 @@ cached_block * block_cache::NewBlock(off_t blockNumber) { cached_block *block = new cached_block; - if (block == NULL) + if (block == NULL) { + FATAL(("could not allocate block!\n")); return NULL; + } block_range *range = GetFreeRange(); if (range == NULL) { + FATAL(("could not get range!\n")); delete block; return NULL; } @@ -521,6 +530,7 @@ get_cached_block(block_cache *cache, off_t blockNumber, bool &allocated, bool re if (read_pos(cache->fd, blockNumber * blockSize, block->data, blockSize) < blockSize) { cache->FreeBlock(block); + FATAL(("could not read block %Ld\n", blockNumber)); return NULL; } } @@ -593,6 +603,7 @@ get_writable_cached_block(block_cache *cache, off_t blockNumber, off_t base, off // we already have data, so we need to save it block->original = cache->Allocate(); if (block->original == NULL) { + FATAL(("could not allocate original\n")); put_cached_block(cache, block); return NULL; } @@ -604,6 +615,7 @@ get_writable_cached_block(block_cache *cache, off_t blockNumber, off_t base, off block->parent_data = cache->Allocate(); if (block->parent_data == NULL) { // ToDo: maybe we should just continue the current transaction in this case... + FATAL(("could not allocate parent\n")); put_cached_block(cache, block); return NULL; } @@ -635,7 +647,7 @@ write_cached_block(block_cache *cache, cached_block *block, bool deleteTransacti ssize_t written = write_pos(cache->fd, block->block_number * blockSize, data, blockSize); if (written < blockSize) { - dprintf("could not write back block %Ld (%s)\n", block->block_number, strerror(errno)); + FATAL(("could not write back block %Ld (%s)\n", block->block_number, strerror(errno))); return B_IO_ERROR; }