From ac540e96a915c30034a4fc03ef65b60b8392f664 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 28 Jan 2002 22:18:49 +0200 Subject: Many files: Merge InnoDB-.48 sql/ha_innobase.cc: Merge InnoDB-.48 innobase/include/dict0dict.h: Merge InnoDB-.48 innobase/include/dict0mem.h: Merge InnoDB-.48 innobase/include/mem0dbg.h: Merge InnoDB-.48 innobase/include/mem0mem.h: Merge InnoDB-.48 innobase/include/que0que.h: Merge InnoDB-.48 innobase/include/row0mysql.h: Merge InnoDB-.48 innobase/include/srv0srv.h: Merge InnoDB-.48 innobase/include/trx0sys.h: Merge InnoDB-.48 innobase/include/trx0trx.h: Merge InnoDB-.48 innobase/include/mem0mem.ic: Merge InnoDB-.48 innobase/dict/dict0dict.c: Merge InnoDB-.48 innobase/dict/dict0mem.c: Merge InnoDB-.48 innobase/log/log0recv.c: Merge InnoDB-.48 innobase/mem/mem0dbg.c: Merge InnoDB-.48 innobase/mem/mem0mem.c: Merge InnoDB-.48 innobase/pars/lexyy.c: Merge InnoDB-.48 innobase/que/que0que.c: Merge InnoDB-.48 innobase/rem/rem0rec.c: Merge InnoDB-.48 innobase/row/row0mysql.c: Merge InnoDB-.48 innobase/row/row0sel.c: Merge InnoDB-.48 innobase/srv/srv0srv.c: Merge InnoDB-.48 innobase/sync/sync0arr.c: Merge InnoDB-.48 innobase/trx/trx0sys.c: Merge InnoDB-.48 innobase/trx/trx0trx.c: Merge InnoDB-.48 innobase/trx/trx0undo.c: Merge InnoDB-.48 --- innobase/mem/mem0dbg.c | 94 +++++++++++++++++++++++++++++++++++++++++++++++++- innobase/mem/mem0mem.c | 32 +++++++++-------- 2 files changed, 110 insertions(+), 16 deletions(-) (limited to 'innobase/mem') diff --git a/innobase/mem/mem0dbg.c b/innobase/mem/mem0dbg.c index 0d71708b906..f8f62dffa8b 100644 --- a/innobase/mem/mem0dbg.c +++ b/innobase/mem/mem0dbg.c @@ -808,7 +808,7 @@ mem_validate_no_assert(void) } mutex_exit(&mem_hash_mutex); - + return(error); #else @@ -832,3 +832,95 @@ mem_validate(void) return(TRUE); } + +/**************************************************************** +Tries to find neigboring memory allocation blocks and dumps to stderr +the neighborhood of a given pointer. */ + +void +mem_analyze_corruption( +/*===================*/ + byte* ptr) /* in: pointer to place of possible corruption */ +{ + byte* p; + ulint i; + ulint dist; + + ut_sprintf_buf(srv_fatal_errbuf, ptr - 250, 500); + fprintf(stderr, + "InnoDB: Apparent memory corruption: mem dump %s\n", srv_fatal_errbuf); + + fprintf(stderr, + "InnoDB: Scanning backward trying to find previous allocated mem blocks\n"); + + p = ptr; + dist = 0; + + for (i = 0; i < 10; i++) { + for (;;) { + if (((ulint)p) % 4 == 0) { + + if (*((ulint*)p) == MEM_BLOCK_MAGIC_N) { + fprintf(stderr, + "Mem block at - %lu, file %s, line %lu\n", + dist, p + sizeof(ulint), + *(ulint*)(p + 8 + sizeof(ulint))); + + break; + } + + if (*((ulint*)p) == MEM_FREED_BLOCK_MAGIC_N) { + fprintf(stderr, + "Freed mem block at - %lu, file %s, line %lu\n", + dist, p + sizeof(ulint), + *(ulint*)(p + 8 + sizeof(ulint))); + + break; + } + } + + p--; + dist++; + } + + p--; + dist++; + } + + fprintf(stderr, + "InnoDB: Scanning forward trying to find next allocated mem blocks\n"); + + p = ptr; + dist = 0; + + for (i = 0; i < 10; i++) { + for (;;) { + if (((ulint)p) % 4 == 0) { + + if (*((ulint*)p) == MEM_BLOCK_MAGIC_N) { + fprintf(stderr, + "Mem block at + %lu, file %s, line %lu\n", + dist, p + sizeof(ulint), + *(ulint*)(p + 8 + sizeof(ulint))); + + break; + } + + if (*((ulint*)p) == MEM_FREED_BLOCK_MAGIC_N) { + fprintf(stderr, + "Freed mem block at + %lu, file %s, line %lu\n", + dist, p + sizeof(ulint), + *(ulint*)(p + 8 + sizeof(ulint))); + + break; + } + } + + p++; + dist++; + } + + p++; + dist++; + } +} diff --git a/innobase/mem/mem0mem.c b/innobase/mem/mem0mem.c index 19a2c0d61a7..58fb618e2db 100644 --- a/innobase/mem/mem0mem.c +++ b/innobase/mem/mem0mem.c @@ -14,8 +14,9 @@ Created 6/9/1994 Heikki Tuuri #include "mach0data.h" #include "buf0buf.h" -#include "mem0dbg.c" #include "btr0sea.h" +#include "srv0srv.h" +#include "mem0dbg.c" /* THE MEMORY MANAGEMENT @@ -85,18 +86,12 @@ mem_alloc_func_noninline( /*=====================*/ /* out, own: free storage, NULL if did not succeed */ - ulint n /* in: desired number of bytes */ - #ifdef UNIV_MEM_DEBUG - ,char* file_name, /* in: file name where created */ + ulint n, /* in: desired number of bytes */ + char* file_name, /* in: file name where created */ ulint line /* in: line where created */ - #endif ) { - return(mem_alloc_func(n -#ifdef UNIV_MEM_DEBUG - , file_name, line -#endif - )); + return(mem_alloc_func(n, file_name, line)); } /******************************************************************* @@ -113,8 +108,10 @@ mem_heap_create_block( if init_block is not NULL, its size in bytes */ void* init_block, /* in: init block in fast create, type must be MEM_HEAP_DYNAMIC */ - ulint type) /* in: type of heap: MEM_HEAP_DYNAMIC, or + ulint type, /* in: type of heap: MEM_HEAP_DYNAMIC, or MEM_HEAP_BUFFER possibly ORed to MEM_HEAP_BTR_SEARCH */ + char* file_name,/* in: file name where created */ + ulint line) /* in: line where created */ { mem_block_t* block; ulint len; @@ -164,7 +161,11 @@ mem_heap_create_block( } block->magic_n = MEM_BLOCK_MAGIC_N; - + ut_memcpy(&(block->file_name), file_name + ut_strlen(file_name) - 7, + 7); + block->file_name[7]='\0'; + block->line = line; + mem_block_set_len(block, len); mem_block_set_type(block, type); mem_block_set_free(block, MEM_BLOCK_HEADER_SIZE); @@ -223,8 +224,8 @@ mem_heap_add_block( new_size = n; } - new_block = mem_heap_create_block(heap, new_size, NULL, heap->type); - + new_block = mem_heap_create_block(heap, new_size, NULL, heap->type, + heap->file_name, heap->line); if (new_block == NULL) { return(NULL); @@ -255,7 +256,8 @@ mem_heap_block_free( type = heap->type; len = block->len; init_block = block->init_block; - + block->magic_n = MEM_FREED_BLOCK_MAGIC_N; + #ifdef UNIV_MEM_DEBUG /* In the debug version we set the memory to a random combination of hex 0xDE and 0xAD. */ -- cgit v1.2.1 From 94f7b7f33f785ea6547afc76f51eac569bc80b12 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 29 Jan 2002 22:29:58 +0200 Subject: mem0mem.c: Add more diagnostic code to cath possible memory corruption innobase/mem/mem0mem.c: Add more diagnostic code to cath possible memory corruption --- innobase/mem/mem0mem.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'innobase/mem') diff --git a/innobase/mem/mem0mem.c b/innobase/mem/mem0mem.c index 58fb618e2db..3e0a9c008f3 100644 --- a/innobase/mem/mem0mem.c +++ b/innobase/mem/mem0mem.c @@ -50,7 +50,7 @@ of the blocks stay the same. An exception is, of course, the case where the caller requests a memory buffer whose size is bigger than the threshold. In that case a block big enough must be allocated. - + The heap is physically arranged so that if the current block becomes full, a new block is allocated and always inserted in the chain of blocks as the last block. @@ -119,6 +119,10 @@ mem_heap_create_block( ut_ad((type == MEM_HEAP_DYNAMIC) || (type == MEM_HEAP_BUFFER) || (type == MEM_HEAP_BUFFER + MEM_HEAP_BTR_SEARCH)); + if (heap && heap->magic_n != MEM_BLOCK_MAGIC_N) { + mem_analyze_corruption((byte*)heap); + } + /* In dynamic allocation, calculate the size: block header + data. */ if (init_block != NULL) { @@ -251,6 +255,10 @@ mem_heap_block_free( ulint len; ibool init_block; + if (block->magic_n != MEM_BLOCK_MAGIC_N) { + mem_analyze_corruption((byte*)block); + } + UT_LIST_REMOVE(list, heap->base, block); type = heap->type; -- cgit v1.2.1