summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarko Mäkelä <marko.makela@mariadb.com>2019-08-29 13:10:40 +0300
committerMarko Mäkelä <marko.makela@mariadb.com>2019-08-29 13:13:17 +0300
commite50b2bdbcf045e46d1a84ffeb9872d81e3aa5eff (patch)
treea6e8b1fae0fa313d05682901cf022ff3bd0dffe7
parent1a3c36595320bd4cf94ba5ab6c5127129269af67 (diff)
downloadmariadb-git-bb-10.3-MDEV-20425.tar.gz
MDEV-20425 Implement Boolean debug build option debug_assertbb-10.3-MDEV-20425
Commit 536215e32fc43aa423684e9807640dcf3453924b 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.
-rw-r--r--include/my_dbug.h8
-rw-r--r--include/my_global.h28
-rw-r--r--include/my_sys.h3
-rw-r--r--mysys/my_static.c5
-rw-r--r--sql/mysqld.cc4
5 files changed, 30 insertions, 18 deletions
diff --git a/include/my_dbug.h b/include/my_dbug.h
index 4b69787c2fe..bce33285788 100644
--- a/include/my_dbug.h
+++ b/include/my_dbug.h
@@ -1,5 +1,5 @@
/* 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))
diff --git a/include/my_global.h b/include/my_global.h
index da3ce121fb0..819d388f367 100644
--- a/include/my_global.h
+++ b/include/my_global.h
@@ -1,6 +1,6 @@
/*
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
diff --git a/include/my_sys.h b/include/my_sys.h
index 62c76adedfc..a746dd9de1b 100644
--- a/include/my_sys.h
+++ b/include/my_sys.h
@@ -1,5 +1,5 @@
/* 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() */
diff --git a/mysys/my_static.c b/mysys/my_static.c
index 909d9ce77fd..2b5f6c3eb1d 100644
--- a/mysys/my_static.c
+++ b/mysys/my_static.c
@@ -1,5 +1,5 @@
/* 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;
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index c2475bbb46f..443fb54d466 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -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,