Commit 139e8afc authored by Monty's avatar Monty

Re-enable 'S' for --debug (sf_sanity checking for each call)

- Fixed also a wrong comment and a wrong argument to printf
parent 1464f480
...@@ -128,7 +128,6 @@ ...@@ -128,7 +128,6 @@
#define SANITY_CHECK_ON (1U << 12) /* Check memory on every DBUG_ENTER/RETURN */ #define SANITY_CHECK_ON (1U << 12) /* Check memory on every DBUG_ENTER/RETURN */
#define TRACE_ON (1U << 31) /* Trace enabled. MUST be the highest bit!*/ #define TRACE_ON (1U << 31) /* Trace enabled. MUST be the highest bit!*/
#define sf_sanity() (0)
#define TRACING (cs->stack->flags & TRACE_ON) #define TRACING (cs->stack->flags & TRACE_ON)
#define DEBUGGING (cs->stack->flags & DEBUG_ON) #define DEBUGGING (cs->stack->flags & DEBUG_ON)
...@@ -272,6 +271,11 @@ static void PushState(CODE_STATE *cs); ...@@ -272,6 +271,11 @@ static void PushState(CODE_STATE *cs);
static void FreeState (CODE_STATE *cs, int free_state); static void FreeState (CODE_STATE *cs, int free_state);
/* Test for tracing enabled */ /* Test for tracing enabled */
static int DoTrace(CODE_STATE *cs); static int DoTrace(CODE_STATE *cs);
static int default_my_dbug_sanity(void);
int (*dbug_sanity)(void)= default_my_dbug_sanity;
/* /*
return values of DoTrace. return values of DoTrace.
Can also be used as bitmask: ret & DO_TRACE Can also be used as bitmask: ret & DO_TRACE
...@@ -1121,7 +1125,7 @@ void _db_enter_(const char *_func_, const char *_file_, ...@@ -1121,7 +1125,7 @@ void _db_enter_(const char *_func_, const char *_file_,
if (!TRACING) break; if (!TRACING) break;
/* fall through */ /* fall through */
case DO_TRACE: case DO_TRACE:
if ((cs->stack->flags & SANITY_CHECK_ON) && sf_sanity()) if ((cs->stack->flags & SANITY_CHECK_ON) && (*dbug_sanity)())
cs->stack->flags &= ~SANITY_CHECK_ON; cs->stack->flags &= ~SANITY_CHECK_ON;
if (TRACING) if (TRACING)
{ {
...@@ -1190,7 +1194,7 @@ void _db_return_(struct _db_stack_frame_ *_stack_frame_) ...@@ -1190,7 +1194,7 @@ void _db_return_(struct _db_stack_frame_ *_stack_frame_)
if (DoTrace(cs) & DO_TRACE) if (DoTrace(cs) & DO_TRACE)
{ {
int org_cs_locked; int org_cs_locked;
if ((cs->stack->flags & SANITY_CHECK_ON) && sf_sanity()) if ((cs->stack->flags & SANITY_CHECK_ON) && (*dbug_sanity)())
cs->stack->flags &= ~SANITY_CHECK_ON; cs->stack->flags &= ~SANITY_CHECK_ON;
if (TRACING) if (TRACING)
{ {
...@@ -2248,6 +2252,12 @@ const char* _db_get_func_(void) ...@@ -2248,6 +2252,12 @@ const char* _db_get_func_(void)
return cs->func; return cs->func;
} }
static int default_my_dbug_sanity(void)
{
return 0;
}
#else #else
/* /*
......
...@@ -63,6 +63,7 @@ extern void _db_flush_(void); ...@@ -63,6 +63,7 @@ extern void _db_flush_(void);
extern void dbug_swap_code_state(void **code_state_store); extern void dbug_swap_code_state(void **code_state_store);
extern void dbug_free_code_state(void **code_state_store); extern void dbug_free_code_state(void **code_state_store);
extern const char* _db_get_func_(void); extern const char* _db_get_func_(void);
extern int (*dbug_sanity)(void);
#define DBUG_LEAVE do { \ #define DBUG_LEAVE do { \
_db_stack_frame_.line= __LINE__; \ _db_stack_frame_.line= __LINE__; \
......
...@@ -157,6 +157,7 @@ char *guess_malloc_library(); ...@@ -157,6 +157,7 @@ char *guess_malloc_library();
/* If we have our own safemalloc (for debugging) */ /* If we have our own safemalloc (for debugging) */
#if defined(SAFEMALLOC) #if defined(SAFEMALLOC)
void sf_report_leaked_memory(my_thread_id id); void sf_report_leaked_memory(my_thread_id id);
int sf_sanity();
extern my_thread_id (*sf_malloc_dbug_id)(void); extern my_thread_id (*sf_malloc_dbug_id)(void);
#define SAFEMALLOC_REPORT_MEMORY(X) sf_report_leaked_memory(X) #define SAFEMALLOC_REPORT_MEMORY(X) sf_report_leaked_memory(X)
#else #else
......
...@@ -105,6 +105,10 @@ my_bool my_init(void) ...@@ -105,6 +105,10 @@ my_bool my_init(void)
if (my_thread_global_init()) if (my_thread_global_init())
return 1; return 1;
#if defined(SAFEMALLOC) && !defined(DBUG_OFF)
dbug_sanity= sf_sanity;
#endif
/* $HOME is needed early to parse configuration files located in ~/ */ /* $HOME is needed early to parse configuration files located in ~/ */
if ((home_dir= getenv("HOME")) != 0) if ((home_dir= getenv("HOME")) != 0)
home_dir= intern_filename(home_dir_buff, home_dir); home_dir= intern_filename(home_dir_buff, home_dir);
......
...@@ -200,8 +200,6 @@ void *my_realloc(void *oldpoint, size_t size, myf my_flags) ...@@ -200,8 +200,6 @@ void *my_realloc(void *oldpoint, size_t size, myf my_flags)
/** /**
Free memory allocated with my_malloc. Free memory allocated with my_malloc.
@remark Relies on free being able to handle a NULL argument.
@param ptr Pointer to the memory allocated by my_malloc. @param ptr Pointer to the memory allocated by my_malloc.
*/ */
void my_free(void *ptr) void my_free(void *ptr)
......
...@@ -330,7 +330,7 @@ static int bad_ptr(const char *where, void *ptr) ...@@ -330,7 +330,7 @@ static int bad_ptr(const char *where, void *ptr)
magicend[3] != MAGICEND3) magicend[3] != MAGICEND3)
{ {
DBUG_PRINT("error",("Overrun buffer %p", ptr)); DBUG_PRINT("error",("Overrun buffer %p", ptr));
warn("Error: %s overrun buffer %p", where); warn("Error: %s overrun buffer %p", where, ptr);
fprintf(stderr, "Allocated at "); fprintf(stderr, "Allocated at ");
print_stack(irem->frame); print_stack(irem->frame);
return 1; return 1;
...@@ -340,7 +340,7 @@ static int bad_ptr(const char *where, void *ptr) ...@@ -340,7 +340,7 @@ static int bad_ptr(const char *where, void *ptr)
} }
/* check all allocated memory list for consistency */ /* check all allocated memory list for consistency */
static int sf_sanity() int sf_sanity()
{ {
struct st_irem *irem; struct st_irem *irem;
int flag= 0; int flag= 0;
......
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