Commit 172f5e28 authored by Sergei Golubchik's avatar Sergei Golubchik

add safemalloc back

... but differently

client/mysqltest.cc:
  my_safe_print_str() don't append \n anymore
dbug/dbug.c:
  restore safemalloc as a part of dbug suite
dbug/user.r:
  restore 'S' flag documentation
include/my_dbug.h:
  restore safemalloc as a part of dbug suite
include/my_sys.h:
  move valgrind defines to a dedicated header
mysys/my_malloc.c:
  use new safemalloc
mysys/stacktrace.c:
  don't append \n. let the calller do it, if needed
sql/mysqld.cc:
  my_safe_print_str() don't append \n anymore
parent 02b82326
...@@ -8173,14 +8173,17 @@ static void dump_backtrace(void) ...@@ -8173,14 +8173,17 @@ static void dump_backtrace(void)
fprintf(stderr, "read_command_buf (%p): ", read_command_buf); fprintf(stderr, "read_command_buf (%p): ", read_command_buf);
my_safe_print_str(read_command_buf, sizeof(read_command_buf)); my_safe_print_str(read_command_buf, sizeof(read_command_buf));
fputc('\n', stderr);
if (conn) if (conn)
{ {
fprintf(stderr, "conn->name (%p): ", conn->name); fprintf(stderr, "conn->name (%p): ", conn->name);
my_safe_print_str(conn->name, conn->name_len); my_safe_print_str(conn->name, conn->name_len);
fputc('\n', stderr);
#ifdef EMBEDDED_LIBRARY #ifdef EMBEDDED_LIBRARY
fprintf(stderr, "conn->cur_query (%p): ", conn->cur_query); fprintf(stderr, "conn->cur_query (%p): ", conn->cur_query);
my_safe_print_str(conn->cur_query, conn->cur_query_len); my_safe_print_str(conn->cur_query, conn->cur_query_len);
fputc('\n', stderr);
#endif #endif
} }
fputs("Attempting backtrace...\n", stderr); fputs("Attempting backtrace...\n", stderr);
......
This diff is collapsed.
...@@ -988,6 +988,14 @@ Most useful with ...@@ -988,6 +988,14 @@ Most useful with
.B DBUG_PUSH .B DBUG_PUSH
macros used to temporarily alter the macros used to temporarily alter the
debugger state. debugger state.
.LI S
When compiled with
.I safemalloc
this flag invokes "sanity" memory checks (for overwrites/underwrites)
on each
.B DBUG_ENTER
and
.B DBUG_RETURN.
.LI t[,N] .LI t[,N]
Enable function control flow tracing. Enable function control flow tracing.
The maximum nesting depth is specified by N, and defaults to The maximum nesting depth is specified by N, and defaults to
......
...@@ -66,6 +66,9 @@ extern void _db_unlock_file_(void); ...@@ -66,6 +66,9 @@ extern void _db_unlock_file_(void);
extern FILE *_db_fp_(void); extern FILE *_db_fp_(void);
extern void _db_flush_(); extern void _db_flush_();
extern const char* _db_get_func_(void); extern const char* _db_get_func_(void);
extern void *_db_malloc_(size_t size);
extern void *_db_realloc_(void *ptr, size_t size);
extern void _db_free_(void *ptr);
#define DBUG_ENTER(a) struct _db_stack_frame_ _db_stack_frame_; \ #define DBUG_ENTER(a) struct _db_stack_frame_ _db_stack_frame_; \
_db_enter_ (a,__FILE__,__LINE__,&_db_stack_frame_) _db_enter_ (a,__FILE__,__LINE__,&_db_stack_frame_)
...@@ -98,6 +101,10 @@ extern const char* _db_get_func_(void); ...@@ -98,6 +101,10 @@ extern const char* _db_get_func_(void);
#define DBUG_EXPLAIN_INITIAL(buf,len) _db_explain_init_((buf),(len)) #define DBUG_EXPLAIN_INITIAL(buf,len) _db_explain_init_((buf),(len))
#define DEBUGGER_OFF do { _dbug_on_= 0; } while(0) #define DEBUGGER_OFF do { _dbug_on_= 0; } while(0)
#define DEBUGGER_ON do { _dbug_on_= 1; } while(0) #define DEBUGGER_ON do { _dbug_on_= 1; } while(0)
#define DBUG_MALLOC(SIZE) _db_malloc_(SIZE)
#define DBUG_REALLOC(PTR,SIZE) _db_realloc_(PTR,SIZE)
#define DBUG_FREE(PTR) _db_free_(PTR)
#ifndef __WIN__ #ifndef __WIN__
#define DBUG_ABORT() (_db_flush_(), abort()) #define DBUG_ABORT() (_db_flush_(), abort())
#else #else
...@@ -163,6 +170,9 @@ extern void _db_suicide_(); ...@@ -163,6 +170,9 @@ extern void _db_suicide_();
#define DBUG_EXPLAIN_INITIAL(buf,len) #define DBUG_EXPLAIN_INITIAL(buf,len)
#define DEBUGGER_OFF do { } while(0) #define DEBUGGER_OFF do { } while(0)
#define DEBUGGER_ON do { } while(0) #define DEBUGGER_ON do { } while(0)
#define DBUG_MALLOC(SIZE) malloc(SIZE)
#define DBUG_REALLOC(PTR,SIZE) realloc(PTR,SIZE)
#define DBUG_FREE(PTR) free(PTR)
#define DBUG_ABORT() do { } while(0) #define DBUG_ABORT() do { } while(0)
#define DBUG_CRASH_ENTER(func) #define DBUG_CRASH_ENTER(func)
#define DBUG_CRASH_RETURN(val) do { return(val); } while(0) #define DBUG_CRASH_RETURN(val) do { return(val); } while(0)
......
...@@ -28,24 +28,7 @@ typedef struct my_aio_result { ...@@ -28,24 +28,7 @@ typedef struct my_aio_result {
} my_aio_result; } my_aio_result;
#endif #endif
#ifdef HAVE_valgrind #include <my_valgrind.h>
#define IF_VALGRIND(A,B) A
#else
#define IF_VALGRIND(A,B) B
#endif
#if defined(HAVE_valgrind) && defined(HAVE_VALGRIND_MEMCHECK_H)
# include <valgrind/memcheck.h>
# define MEM_UNDEFINED(a,len) VALGRIND_MAKE_MEM_UNDEFINED(a,len)
# define MEM_NOACCESS(a,len) VALGRIND_MAKE_MEM_NOACCESS(a,len)
# define MEM_CHECK_ADDRESSABLE(a,len) VALGRIND_CHECK_MEM_IS_ADDRESSABLE(a,len)
# define MEM_CHECK_DEFINED(a,len) VALGRIND_CHECK_MEM_IS_DEFINED(a,len)
#else /* HAVE_VALGRIND */
# define MEM_UNDEFINED(a,len) ((void) 0)
# define MEM_NOACCESS(a,len) ((void) 0)
# define MEM_CHECK_ADDRESSABLE(a,len) ((void) 0)
# define MEM_CHECK_DEFINED(a,len) ((void) 0)
#endif /* HAVE_VALGRIND */
#include <my_pthread.h> #include <my_pthread.h>
...@@ -168,12 +151,6 @@ extern void *my_memdup(const void *from,size_t length,myf MyFlags); ...@@ -168,12 +151,6 @@ extern void *my_memdup(const void *from,size_t length,myf MyFlags);
extern char *my_strdup(const char *from,myf MyFlags); extern char *my_strdup(const char *from,myf MyFlags);
extern char *my_strndup(const char *from, size_t length, extern char *my_strndup(const char *from, size_t length,
myf MyFlags); myf MyFlags);
#ifdef SAFEMALLOC
#define TRASH(A,B) do { bfill(A, B, 0x8F); MEM_UNDEFINED(A, B); } while (0)
#else
#define TRASH(A,B) do{MEM_CHECK_ADDRESSABLE(A,B);MEM_UNDEFINED(A,B);} while (0)
#endif
#if defined(ENABLED_DEBUG_SYNC) #if defined(ENABLED_DEBUG_SYNC)
extern void (*debug_sync_C_callback_ptr)(const char *, size_t); extern void (*debug_sync_C_callback_ptr)(const char *, size_t);
#define DEBUG_SYNC_C(_sync_point_name_) do { \ #define DEBUG_SYNC_C(_sync_point_name_) do { \
......
/* Copyright (C) 2010 Monty Program Ab
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/* Some defines to make it easier to use valgrind */
#ifdef HAVE_valgrind
#define IF_VALGRIND(A,B) A
#else
#define IF_VALGRIND(A,B) B
#endif
#if defined(HAVE_valgrind) && defined(HAVE_VALGRIND_MEMCHECK_H)
# include <valgrind/memcheck.h>
# define MEM_UNDEFINED(a,len) VALGRIND_MAKE_MEM_UNDEFINED(a,len)
# define MEM_NOACCESS(a,len) VALGRIND_MAKE_MEM_NOACCESS(a,len)
# define MEM_CHECK_ADDRESSABLE(a,len) VALGRIND_CHECK_MEM_IS_ADDRESSABLE(a,len)
# define MEM_CHECK_DEFINED(a,len) VALGRIND_CHECK_MEM_IS_DEFINED(a,len)
#else /* HAVE_VALGRIND */
# define MEM_UNDEFINED(a,len) ((void) 0)
# define MEM_NOACCESS(a,len) ((void) 0)
# define MEM_CHECK_ADDRESSABLE(a,len) ((void) 0)
# define MEM_CHECK_DEFINED(a,len) ((void) 0)
#endif /* HAVE_VALGRIND */
#ifndef DBUG_OFF
#define TRASH_FILL(A,B,C) do { bfill(A, B, C); MEM_UNDEFINED(A, B); } while (0)
#else
#define TRASH_FILL(A,B,C) do{ MEM_CHECK_ADDRESSABLE(A,B);MEM_UNDEFINED(A,B);} while (0)
#endif
#define TRASH_ALLOC(A,B) TRASH_FILL(A,B,0xA5)
#define TRASH_FREE(A,B) TRASH_FILL(A,B,0x8F)
#define TRASH(A,B) TRASH_FREE(A,B)
...@@ -3421,7 +3421,6 @@ sub mysql_install_db { ...@@ -3421,7 +3421,6 @@ sub mysql_install_db {
mtr_add_arg($args, "--loose-skip-ndbcluster"); mtr_add_arg($args, "--loose-skip-ndbcluster");
mtr_add_arg($args, "--loose-skip-aria"); mtr_add_arg($args, "--loose-skip-aria");
mtr_add_arg($args, "--disable-sync-frm"); mtr_add_arg($args, "--disable-sync-frm");
mtr_add_arg($args, "--loose-disable-debug");
mtr_add_arg($args, "--tmpdir=%s", "$opt_vardir/tmp/"); mtr_add_arg($args, "--tmpdir=%s", "$opt_vardir/tmp/");
mtr_add_arg($args, "--core-file"); mtr_add_arg($args, "--core-file");
......
...@@ -235,6 +235,7 @@ void *alloc_root(MEM_ROOT *mem_root, size_t length) ...@@ -235,6 +235,7 @@ void *alloc_root(MEM_ROOT *mem_root, size_t length)
mem_root->used= next; mem_root->used= next;
mem_root->first_block_usage= 0; mem_root->first_block_usage= 0;
} }
TRASH_ALLOC(point, length);
DBUG_PRINT("exit",("ptr: 0x%lx", (ulong) point)); DBUG_PRINT("exit",("ptr: 0x%lx", (ulong) point));
DBUG_RETURN((void*) point); DBUG_RETURN((void*) point);
#endif #endif
......
...@@ -35,10 +35,10 @@ void *my_malloc(size_t size, myf my_flags) ...@@ -35,10 +35,10 @@ void *my_malloc(size_t size, myf my_flags)
if (!size) if (!size)
size=1; size=1;
point= malloc(size); point= DBUG_MALLOC(size);
DBUG_EXECUTE_IF("simulate_out_of_memory", DBUG_EXECUTE_IF("simulate_out_of_memory",
{ {
free(point); my_free(point);
point= NULL; point= NULL;
}); });
...@@ -81,7 +81,7 @@ void *my_realloc(void *oldpoint, size_t size, myf my_flags) ...@@ -81,7 +81,7 @@ void *my_realloc(void *oldpoint, size_t size, myf my_flags)
DBUG_ASSERT(size > 0); DBUG_ASSERT(size > 0);
if (!oldpoint && (my_flags & MY_ALLOW_ZERO_PTR)) if (!oldpoint && (my_flags & MY_ALLOW_ZERO_PTR))
DBUG_RETURN(my_malloc(size, my_flags)); DBUG_RETURN(my_malloc(size, my_flags));
if ((point= realloc(oldpoint, size)) == NULL) if ((point= DBUG_REALLOC(oldpoint, size)) == NULL)
{ {
if (my_flags & MY_FREE_ON_ERROR) if (my_flags & MY_FREE_ON_ERROR)
my_free(oldpoint); my_free(oldpoint);
...@@ -107,7 +107,7 @@ void my_free(void *ptr) ...@@ -107,7 +107,7 @@ void my_free(void *ptr)
{ {
DBUG_ENTER("my_free"); DBUG_ENTER("my_free");
DBUG_PRINT("my",("ptr: %p", ptr)); DBUG_PRINT("my",("ptr: %p", ptr));
free(ptr); DBUG_FREE(ptr);
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
......
...@@ -117,12 +117,8 @@ static int safe_print_str(const char *addr, int max_len) ...@@ -117,12 +117,8 @@ static int safe_print_str(const char *addr, int max_len)
break; break;
} }
/* Output a new line if something was printed. */
if (total != (size_t) max_len)
fputc('\n', stderr);
if (nbytes == -1) if (nbytes == -1)
fprintf(stderr, "Can't read from address %p: %m.\n", addr); fprintf(stderr, "Can't read from address %p: %m.", addr);
close(fd); close(fd);
...@@ -144,13 +140,12 @@ void my_safe_print_str(const char* val, int max_len) ...@@ -144,13 +140,12 @@ void my_safe_print_str(const char* val, int max_len)
if (!PTR_SANE(val)) if (!PTR_SANE(val))
{ {
fprintf(stderr, "is an invalid pointer\n"); fprintf(stderr, "is an invalid pointer");
return; return;
} }
for (; max_len && PTR_SANE(val) && *val; --max_len) for (; max_len && PTR_SANE(val) && *val; --max_len)
fputc(*val++, stderr); fputc(*val++, stderr);
fputc('\n', stderr);
} }
#if defined(HAVE_PRINTSTACK) #if defined(HAVE_PRINTSTACK)
...@@ -704,11 +699,11 @@ void my_safe_print_str(const char *val, int len) ...@@ -704,11 +699,11 @@ void my_safe_print_str(const char *val, int len)
{ {
__try __try
{ {
fprintf(stderr, "%.*s\n", len, val); fprintf(stderr, "%.*s", len, val);
} }
__except(EXCEPTION_EXECUTE_HANDLER) __except(EXCEPTION_EXECUTE_HANDLER)
{ {
fprintf(stderr, "is an invalid string pointer\n"); fprintf(stderr, "is an invalid string pointer");
} }
} }
#endif /*__WIN__*/ #endif /*__WIN__*/
...@@ -2610,7 +2610,7 @@ the thread stack. Please read http://dev.mysql.com/doc/mysql/en/linux.html\n\n", ...@@ -2610,7 +2610,7 @@ the thread stack. Please read http://dev.mysql.com/doc/mysql/en/linux.html\n\n",
"Some pointers may be invalid and cause the dump to abort.\n"); "Some pointers may be invalid and cause the dump to abort.\n");
fprintf(stderr, "Query (%p): ", thd->query()); fprintf(stderr, "Query (%p): ", thd->query());
my_safe_print_str(thd->query(), min(1024, thd->query_length())); my_safe_print_str(thd->query(), min(1024, thd->query_length()));
fprintf(stderr, "Connection ID (thread ID): %lu\n", (ulong) thd->thread_id); fprintf(stderr, "\nConnection ID (thread ID): %lu\n", (ulong) thd->thread_id);
fprintf(stderr, "Status: %s\n", kreason); fprintf(stderr, "Status: %s\n", kreason);
fputc('\n', stderr); fputc('\n', stderr);
} }
......
...@@ -7653,9 +7653,7 @@ static void translog_force_current_buffer_to_finish() ...@@ -7653,9 +7653,7 @@ static void translog_force_current_buffer_to_finish()
we can not copy it and will not overwrite later we can not copy it and will not overwrite later
*/ */
new_buffer->skipped_data= current_page_fill; new_buffer->skipped_data= current_page_fill;
#ifndef DBUG_OFF TRASH_ALLOC(new_buffer->buffer, current_page_fill);
memset(new_buffer->buffer, 0xa5, current_page_fill);
#endif
DBUG_ASSERT(new_buffer->skipped_data < TRANSLOG_PAGE_SIZE); DBUG_ASSERT(new_buffer->skipped_data < TRANSLOG_PAGE_SIZE);
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment