- moved dumpBlock() into debug.c, renamed it to dump_block() and added it

to kernel-exports.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@18268 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Oliver Tappe 2006-07-25 19:46:36 +00:00
parent 375837b47b
commit b66ae2c9c8
3 changed files with 42 additions and 43 deletions

View File

@ -178,6 +178,9 @@ extern void dprintf(const char *format, ...); /* just like printf */
extern void kprintf(const char *fmt, ...); /* only for debugger cmds */
#endif
extern void dump_block(const char *buffer, int size, const char *prefix);
/* hexdumps given buffer */
extern bool set_dprintf_enabled(bool new_state); /* returns old state */
extern void panic(const char *format, ...);

View File

@ -406,56 +406,15 @@ block_cache::LowMemoryHandler(void *data, int32 level)
// #pragma mark -
#ifdef DEBUG_CHANGED
#define DUMPED_BLOCK_SIZE 16
void
dumpBlock(const char *buffer, int size, const char *prefix)
{
int i;
for (i = 0; i < size;) {
int start = i;
dprintf(prefix);
for (; i < start+DUMPED_BLOCK_SIZE; i++) {
if (!(i % 4))
dprintf(" ");
if (i >= size)
dprintf(" ");
else
dprintf("%02x", *(unsigned char *)(buffer + i));
}
dprintf(" ");
for (i = start; i < start + DUMPED_BLOCK_SIZE; i++) {
if (i < size) {
char c = buffer[i];
if (c < 30)
dprintf(".");
else
dprintf("%c", c);
} else
break;
}
dprintf("\n");
}
}
#endif
static void
put_cached_block(block_cache *cache, cached_block *block)
{
#ifdef DEBUG_CHANGED
if (!block->is_dirty && block->compare != NULL && memcmp(block->current_data, block->compare, cache->block_size)) {
dprintf("new block:\n");
dumpBlock((const char *)block->current_data, 256, " ");
dump_block((const char *)block->current_data, 256, " ");
dprintf("unchanged block:\n");
dumpBlock((const char *)block->compare, 256, " ");
dump_block((const char *)block->compare, 256, " ");
write_cached_block(cache, block);
panic("block_cache: supposed to be clean block was changed!\n");

View File

@ -986,3 +986,40 @@ _user_debug_output(const char *userString)
userString += sizeof(string) - 1;
} while (length >= (ssize_t)sizeof(string));
}
void
dump_block(const char *buffer, int size, const char *prefix)
{
const int DUMPED_BLOCK_SIZE = 16;
int i;
for (i = 0; i < size;) {
int start = i;
dprintf(prefix);
for (; i < start + DUMPED_BLOCK_SIZE; i++) {
if (!(i % 4))
dprintf(" ");
if (i >= size)
dprintf(" ");
else
dprintf("%02x", *(unsigned char *)(buffer + i));
}
dprintf(" ");
for (i = start; i < start + DUMPED_BLOCK_SIZE; i++) {
if (i < size) {
char c = buffer[i];
if (c < 30)
dprintf(".");
else
dprintf("%c", c);
} else
break;
}
dprintf("\n");
}
}