1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-08 11:22:35 +03:00

MDEV-20425 Implement Boolean debug build option debug_assert

Commit 536215e32f 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.
This commit is contained in:
Marko Mäkelä
2019-08-29 13:10:40 +03:00
parent 1a3c365953
commit e50b2bdbcf
5 changed files with 30 additions and 18 deletions

View File

@@ -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))