Commit e50b2bdb authored by Marko Mäkelä's avatar Marko Mäkelä

MDEV-20425 Implement Boolean debug build option debug_assert

Commit 536215e3 in MariaDB Server 10.3.1
introduced the compiler flag (not cmake option) DBUG_ASSERT_AS_PRINTF
that converts DBUG_ASSERT in non-debug builds into printouts.

For debug builds, it could be useful to be able to convert DBUG_ASSERT
into a warning or error printout, to allow execution to continue.
This would allow debug builds to be used for reproducing hard failures
that occur with release builds.

my_assert: A Boolean flag (set by default), tied to the new option
debug_assert that is available on debug builds only.
When set, DBUG_ASSERT() will invoke assert(), like it did until now.
When unset, DBUG_ASSERT() will invoke fprintf(stderr, ...)
with the file name, line number and assertion expression.
parent 1a3c3659
/* Copyright (c) 2000, 2010, Oracle and/or its affiliates.
Copyright (C) 2000, 2017, MariaDB Corporation Ab
Copyright (C) 2000, 2019, MariaDB Corporation.
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
......@@ -35,6 +35,7 @@ struct _db_stack_frame_ {
};
struct _db_code_state_;
extern MYSQL_PLUGIN_IMPORT my_bool my_assert;
extern my_bool _dbug_on_;
extern my_bool _db_keyword_(struct _db_code_state_ *, const char *, int);
extern int _db_explain_(struct _db_code_state_ *cs, char *buf, size_t len);
......@@ -103,7 +104,10 @@ extern int (*dbug_sanity)(void);
#define DBUG_END() _db_end_ ()
#define DBUG_LOCK_FILE _db_lock_file_()
#define DBUG_UNLOCK_FILE _db_unlock_file_()
#define DBUG_ASSERT(A) do { if (!(A)) { _db_flush_(); assert(A); }} while (0)
#define DBUG_ASSERT(A) do { if (!(A)) { _db_flush_(); \
if (my_assert) assert(A); \
else fprintf(stderr, "%s:%d: assert: %s\n", __FILE__, __LINE__, #A); \
}} while (0)
#define DBUG_SLOW_ASSERT(A) DBUG_ASSERT(A)
#define DBUG_ASSERT_EXISTS
#define DBUG_EXPLAIN(buf,len) _db_explain_(0, (buf),(len))
......
/*
Copyright (c) 2001, 2013, Oracle and/or its affiliates.
Copyright (c) 2009, 2017, MariaDB Corporation
Copyright (c) 2009, 2019, MariaDB Corporation.
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
......@@ -1043,6 +1043,19 @@ typedef ulong myf; /* Type of MyFlags in my_funcs */
#define reg16 register
#endif
/*
MYSQL_PLUGIN_IMPORT macro is used to export mysqld data
(i.e variables) for usage in storage engine loadable plugins.
Outside of Windows, it is dummy.
*/
#ifndef MYSQL_PLUGIN_IMPORT
#if (defined(_WIN32) && defined(MYSQL_DYNAMIC_PLUGIN))
#define MYSQL_PLUGIN_IMPORT __declspec(dllimport)
#else
#define MYSQL_PLUGIN_IMPORT
#endif
#endif
#include <my_dbug.h>
/* Some helper macros */
......@@ -1169,19 +1182,6 @@ typedef struct { const char *dli_fname, dli_fbase; } Dl_info;
#endif
#endif /* !defined(__func__) */
/*
MYSQL_PLUGIN_IMPORT macro is used to export mysqld data
(i.e variables) for usage in storage engine loadable plugins.
Outside of Windows, it is dummy.
*/
#ifndef MYSQL_PLUGIN_IMPORT
#if (defined(_WIN32) && defined(MYSQL_DYNAMIC_PLUGIN))
#define MYSQL_PLUGIN_IMPORT __declspec(dllimport)
#else
#define MYSQL_PLUGIN_IMPORT
#endif
#endif
/* Defines that are unique to the embedded version of MySQL */
#ifdef EMBEDDED_LIBRARY
......
/* Copyright (c) 2000, 2013, Oracle and/or its affiliates.
Copyright (c) 2010, 2017, MariaDB Corporation.
Copyright (c) 2010, 2019, MariaDB Corporation.
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
......@@ -267,6 +267,7 @@ extern ulong my_sync_count;
extern uint mysys_usage_id;
extern int32 my_file_opened;
extern my_bool my_init_done, my_thr_key_mysys_exists;
extern MYSQL_PLUGIN_IMPORT my_bool my_assert;
extern my_bool my_assert_on_error;
extern myf my_global_flags; /* Set to MY_WME for more error messages */
/* Point to current my_message() */
......
/* Copyright (c) 2000, 2011, Oracle and/or its affiliates.
Copyright (c) 2009, 2012, Monty Program Ab.
Copyright (c) 2009, 2019, MariaDB Corporation.
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
......@@ -36,6 +36,9 @@ ulong my_file_total_opened= 0;
int my_umask=0664, my_umask_dir=0777;
myf my_global_flags= 0;
#ifndef DBUG_OFF
my_bool my_assert= 1;
#endif
my_bool my_assert_on_error= 0;
struct st_my_file_info my_file_info_default[MY_NFILE];
uint my_file_limit= MY_NFILE;
......
......@@ -7454,6 +7454,10 @@ struct my_option my_long_options[]=
0, GET_INT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
#endif /* HAVE_REPLICATION */
#ifndef DBUG_OFF
{"debug-assert", 0,
"Allow DBUG_ASSERT() to invoke assert()",
&my_assert, &my_assert,
0, GET_BOOL, OPT_ARG, 1, 0, 0, 0, 0, 0},
{"debug-assert-on-error", 0,
"Do an assert in various functions if we get a fatal error",
&my_assert_on_error, &my_assert_on_error,
......
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