Commit 2cb9f48b authored by Sergei Golubchik's avatar Sergei Golubchik

robust protection against missing DBUG_RETURN

(instead of a C++ only thingy that was lost in a merge)
parent 319847a4
...@@ -324,7 +324,7 @@ static void Indent(CODE_STATE *cs, int indent); ...@@ -324,7 +324,7 @@ static void Indent(CODE_STATE *cs, int indent);
static void DbugFlush(CODE_STATE *); static void DbugFlush(CODE_STATE *);
static void DbugExit(const char *why); static void DbugExit(const char *why);
static const char *DbugStrTok(const char *s); static const char *DbugStrTok(const char *s);
static void DbugFprintf(FILE *stream, const char* format, va_list args); static void DbugVfprintf(FILE *stream, const char* format, va_list args);
#ifndef THREAD #ifndef THREAD
/* Open profile output stream */ /* Open profile output stream */
...@@ -339,7 +339,7 @@ static unsigned long Clock(void); ...@@ -339,7 +339,7 @@ static unsigned long Clock(void);
* Miscellaneous printf format strings. * Miscellaneous printf format strings.
*/ */
#define ERR_MISSING_RETURN "%s: missing DBUG_RETURN or DBUG_VOID_RETURN macro in function \"%s\"\n" #define ERR_MISSING_RETURN "missing DBUG_RETURN or DBUG_VOID_RETURN macro in function \"%s\"\n"
#define ERR_OPEN "%s: can't open debug output stream \"%s\": " #define ERR_OPEN "%s: can't open debug output stream \"%s\": "
#define ERR_CLOSE "%s: can't close debug file: " #define ERR_CLOSE "%s: can't close debug file: "
#define ERR_ABORT "%s: debugger aborting because %s\n" #define ERR_ABORT "%s: debugger aborting because %s\n"
...@@ -1228,7 +1228,6 @@ void _db_enter_(const char *_func_, const char *_file_, ...@@ -1228,7 +1228,6 @@ void _db_enter_(const char *_func_, const char *_file_,
* *
*/ */
/* helper macro */
void _db_return_(uint _line_, struct _db_stack_frame_ *_stack_frame_) void _db_return_(uint _line_, struct _db_stack_frame_ *_stack_frame_)
{ {
int save_errno=errno; int save_errno=errno;
...@@ -1236,34 +1235,29 @@ void _db_return_(uint _line_, struct _db_stack_frame_ *_stack_frame_) ...@@ -1236,34 +1235,29 @@ void _db_return_(uint _line_, struct _db_stack_frame_ *_stack_frame_)
CODE_STATE *cs; CODE_STATE *cs;
get_code_state_or_return; get_code_state_or_return;
if (cs->level != _slevel_) if (cs->framep != _stack_frame_)
{ {
if (!cs->locked) char buf[512];
pthread_mutex_lock(&THR_LOCK_dbug); my_snprintf(buf, sizeof(buf), ERR_MISSING_RETURN, cs->func);
(void) fprintf(cs->stack->out_file, ERR_MISSING_RETURN, cs->process, DbugExit(buf);
cs->func);
DbugFlush(cs);
} }
else
{
#ifndef THREAD #ifndef THREAD
if (DoProfile(cs)) if (DoProfile(cs))
(void) fprintf(cs->stack->prof_file, PROF_XFMT, Clock(), cs->func); (void) fprintf(cs->stack->prof_file, PROF_XFMT, Clock(), cs->func);
#endif #endif
if (DoTrace(cs) & DO_TRACE) if (DoTrace(cs) & DO_TRACE)
{
if ((cs->stack->flags & SANITY_CHECK_ON) &&
_sanity(_stack_frame_->file,_line_))
cs->stack->flags &= ~SANITY_CHECK_ON;
if (TRACING)
{ {
if ((cs->stack->flags & SANITY_CHECK_ON) && if (!cs->locked)
_sanity(_stack_frame_->file,_line_)) pthread_mutex_lock(&THR_LOCK_dbug);
cs->stack->flags &= ~SANITY_CHECK_ON; DoPrefix(cs, _line_);
if (TRACING) Indent(cs, cs->level);
{ (void) fprintf(cs->stack->out_file, "<%s\n", cs->func);
if (!cs->locked) DbugFlush(cs);
pthread_mutex_lock(&THR_LOCK_dbug);
DoPrefix(cs, _line_);
Indent(cs, cs->level);
(void) fprintf(cs->stack->out_file, "<%s\n", cs->func);
DbugFlush(cs);
}
} }
} }
/* /*
...@@ -1353,7 +1347,7 @@ void _db_doprnt_(const char *format,...) ...@@ -1353,7 +1347,7 @@ void _db_doprnt_(const char *format,...)
else else
(void) fprintf(cs->stack->out_file, "%s: ", cs->func); (void) fprintf(cs->stack->out_file, "%s: ", cs->func);
(void) fprintf(cs->stack->out_file, "%s: ", cs->u_keyword); (void) fprintf(cs->stack->out_file, "%s: ", cs->u_keyword);
DbugFprintf(cs->stack->out_file, format, args); DbugVfprintf(cs->stack->out_file, format, args);
DbugFlush(cs); DbugFlush(cs);
errno=save_errno; errno=save_errno;
} }
...@@ -1361,10 +1355,10 @@ void _db_doprnt_(const char *format,...) ...@@ -1361,10 +1355,10 @@ void _db_doprnt_(const char *format,...)
} }
/* /*
* fprintf clone with consistent, platform independent output for * vfprintf clone with consistent, platform independent output for
* problematic formats like %p, %zd and %lld. * problematic formats like %p, %zd and %lld.
*/ */
static void DbugFprintf(FILE *stream, const char* format, va_list args) static void DbugVfprintf(FILE *stream, const char* format, va_list args)
{ {
char cvtbuf[1024]; char cvtbuf[1024];
size_t len; size_t len;
...@@ -1388,14 +1382,13 @@ static void DbugFprintf(FILE *stream, const char* format, va_list args) ...@@ -1388,14 +1382,13 @@ static void DbugFprintf(FILE *stream, const char* format, va_list args)
* *
* DESCRIPTION * DESCRIPTION
* Dump N characters in a binary array. * Dump N characters in a binary array.
* Is used to examine corrputed memory or arrays. * Is used to examine corrupted memory or arrays.
*/ */
void _db_dump_(uint _line_, const char *keyword, void _db_dump_(uint _line_, const char *keyword,
const unsigned char *memory, size_t length) const unsigned char *memory, size_t length)
{ {
int pos; int pos;
char dbuff[90];
CODE_STATE *cs; CODE_STATE *cs;
get_code_state_or_return; get_code_state_or_return;
...@@ -1413,9 +1406,8 @@ void _db_dump_(uint _line_, const char *keyword, ...@@ -1413,9 +1406,8 @@ void _db_dump_(uint _line_, const char *keyword,
{ {
fprintf(cs->stack->out_file, "%s: ", cs->func); fprintf(cs->stack->out_file, "%s: ", cs->func);
} }
sprintf(dbuff,"%s: Memory: 0x%lx Bytes: (%ld)\n", (void) fprintf(cs->stack->out_file, "%s: Memory: 0x%lx Bytes: (%ld)\n",
keyword, (ulong) memory, (long) length); keyword, (ulong) memory, (long) length);
(void) fputs(dbuff,cs->stack->out_file);
pos=0; pos=0;
while (length-- > 0) while (length-- > 0)
...@@ -2155,7 +2147,7 @@ static void DbugExit(const char *why) ...@@ -2155,7 +2147,7 @@ static void DbugExit(const char *why)
CODE_STATE *cs=code_state(); CODE_STATE *cs=code_state();
(void) fprintf(stderr, ERR_ABORT, cs ? cs->process : "(null)", why); (void) fprintf(stderr, ERR_ABORT, cs ? cs->process : "(null)", why);
(void) fflush(stderr); (void) fflush(stderr);
exit(1); DBUG_ABORT();
} }
......
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