[pgpool-hackers: 539] Re: cassert failure
Muhammad Usama
m.usama at gmail.com
Tue Jun 3 22:42:51 JST 2014
Hi
Please see the attached patch which adds the --enable-cassert option to the
pgpool-II configure and once compiled with cassert enabled the assertion
checking can be enabled or disabled from command line option
(--debug-assertions or -x)
--usama
On Thu, May 15, 2014 at 6:28 PM, Tatsuo Ishii <ishii at postgresql.org> wrote:
> Hi Usama,
>
> A user reported that git master head has a problem with assertion enabled.
>
> Making all in parser
> make[2]: Entering directory `/home/t-ishii/work/
> git.postgresql.org/pgpool2/src/parser'
> gcc -DHAVE_CONFIG_H -I. -I../../src/include -D_GNU_SOURCE -I
> ../../src/include/parser -I /usr/local/pgsql/include -g -O2 -Wall
> -Wmissing-prototypes -Wmissing-declarations -MT copyfuncs.o -MD -MP -MF
> .deps/copyfuncs.Tpo -c -o copyfuncs.o copyfuncs.c
> copyfuncs.c: In function '_copyList':
> copyfuncs.c:2660: error: 'assert_enabled' undeclared (first use in this
> function)
> copyfuncs.c:2660: error: (Each undeclared identifier is reported only once
> copyfuncs.c:2660: error: for each function it appears in.)
> copyfuncs.c:2660: warning: passing argument 1 of 'list_length' discards
> qualifiers from pointer target type
> ../../src/include/parser/pg_list.h:100: note: expected 'struct List *' but
> argument is of type 'const struct List *'
> copyfuncs.c:2660: warning: implicit declaration of function
> 'ExceptionalCondition'
> make[2]: *** [copyfuncs.o] Error 1
> make[2]: Leaving directory `/home/t-ishii/work/
> git.postgresql.org/pgpool2/src/parser'
> make[1]: *** [all-recursive] Error 1
> make[1]: Leaving directory `/home/t-ishii/work/
> git.postgresql.org/pgpool2/src'
> make: *** [all-recursive] Error 1
>
> Besides configure does not accept --enable-cassert, I have seen the
> erros above if I manually set
>
> #define USE_ASSERT_CHECKING
>
> in pool_type.h.
>
> Best regards,
> --
> Tatsuo Ishii
> SRA OSS, Inc. Japan
> English: http://www.sraoss.co.jp/index_en.php
> Japanese: http://www.sraoss.co.jp
> _______________________________________________
> pgpool-hackers mailing list
> pgpool-hackers at pgpool.net
> http://www.pgpool.net/mailman/listinfo/pgpool-hackers
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.sraoss.jp/pipermail/pgpool-hackers/attachments/20140603/e4a5a374/attachment.html>
-------------- next part --------------
diff --git a/src/utils/error/assert.c b/src/utils/error/assert.c
new file mode 100644
index 0000000..2a7cb76
--- /dev/null
+++ b/src/utils/error/assert.c
@@ -0,0 +1,55 @@
+/*-------------------------------------------------------------------------
+ *
+ * assert.c
+ * Assert code.
+ *
+ * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
+ *
+ * IDENTIFICATION
+ * src/backend/utils/error/assert.c
+ *
+ * NOTE
+ * This should eventually work with elog()
+ *
+ *-------------------------------------------------------------------------
+ */
+#include "utils/elog.h"
+
+#include <unistd.h>
+
+/*
+ * ExceptionalCondition - Handles the failure of an Assert()
+ */
+void
+ExceptionalCondition(const char *conditionName,
+ const char *errorType,
+ const char *fileName,
+ int lineNumber)
+{
+ if (!PointerIsValid(conditionName)
+ || !PointerIsValid(fileName)
+ || !PointerIsValid(errorType))
+ write_stderr("TRAP: ExceptionalCondition: bad arguments\n");
+ else
+ {
+ write_stderr("TRAP: %s(\"%s\", File: \"%s\", Line: %d)\n",
+ errorType, conditionName,
+ fileName, lineNumber);
+ }
+
+ /* Usually this shouldn't be needed, but make sure the msg went out */
+ fflush(stderr);
+
+#ifdef SLEEP_ON_ASSERT
+
+ /*
+ * It would be nice to use pg_usleep() here, but only does 2000 sec or 33
+ * minutes, which seems too short.
+ */
+ sleep(1000000);
+#endif
+
+ abort();
+}
diff --git a/configure b/configure
index e3101c7..e92f847 100755
--- a/configure
+++ b/configure
@@ -781,6 +781,7 @@ with_memcached
enable_rpath
enable_sequence_lock
enable_table_lock
+enable_cassert
'
ac_precious_vars='build_alias
host_alias
@@ -1427,6 +1428,7 @@ Optional Features:
(until 3.0.4)
--enable-table-lock insert_lock compatible with pgpool-II 2.2 and 2.3
series
+ --enable-cassert build with assertion checks
Optional Packages:
--with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
@@ -14519,6 +14521,38 @@ fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $enable_table_lock" >&5
$as_echo "$enable_table_lock" >&6; }
+
+pgac_args="$pgac_args enable_cassert"
+
+# Check whether --enable-cassert was given.
+if test "${enable_cassert+set}" = set; then :
+ enableval=$enable_cassert;
+ case $enableval in
+ yes)
+ :
+ ;;
+ no)
+ :
+ ;;
+ *)
+ as_fn_error $? "no argument expected for --enable-cassert option" "$LINENO" 5
+ ;;
+ esac
+
+else
+ enable_cassert=no
+
+fi
+
+
+if test "$enable_cassert" = yes ; then
+
+$as_echo "#define USE_ASSERT_CHECKING 1" >>confdefs.h
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: enable cassert = $enable_cassert" >&5
+$as_echo "enable cassert = $enable_cassert" >&6; }
+
ac_config_headers="$ac_config_headers src/include/config.h"
diff --git a/configure.in b/configure.in
index 934542a..1def881 100644
--- a/configure.in
+++ b/configure.in
@@ -396,6 +396,13 @@ if test "$enable_table_lock" = yes ; then
fi
AC_MSG_RESULT([$enable_table_lock])
+PGAC_ARG_BOOL(enable, cassert, no, [build with assertion checks])
+if test "$enable_cassert" = yes ; then
+ AC_DEFINE([USE_ASSERT_CHECKING], 1,
+ [Define to 1 to build with assertion checks. (--enable-cassert)])
+fi
+AC_MSG_RESULT([enable cassert = $enable_cassert])
+
AM_CONFIG_HEADER(src/include/config.h)
AC_OUTPUT([Makefile doc/Makefile src/Makefile src/include/Makefile src/parser/Makefile src/libs/Makefile src/libs/pcp/Makefile src/tools/Makefile src/tools/pgmd5/Makefile src/tools/pcp/Makefile src/watchdog/Makefile])
diff --git a/doc/pgpool-en.html b/doc/pgpool-en.html
index 74afebf..a23c138 100644
--- a/doc/pgpool-en.html
+++ b/doc/pgpool-en.html
@@ -3124,7 +3124,7 @@ before starting pgpool-II.
</p>
<pre>
-pgpool [-c][-f config_file][-a hba_file][-F pcp_config_file][-n][-D][-d]
+pgpool [-c][-f config_file][-a hba_file][-F pcp_config_file][-n][-D][-d][x]
</pre>
<table border>
@@ -3147,6 +3147,8 @@ pgpool [-c][-f config_file][-a hba_file][-F pcp_config_file][-n][-D][-d]
if shmem, discard whenever pgpool starts).
<span class="version">V3.2 -</span></td></tr>
<tr><td>-d</td><td>--debug</td><td>debug mode</tr>
+ <tr><td>-x</td><td>--debug-assertions</td>
+ <td>Turns on various assertion checks, This is a debugging aid</td></tr>
</table>
<h2 id="stop_pgpool">Stop pgpool-II</h2>
diff --git a/src/Makefile.am b/src/Makefile.am
index acb83fa..cb9b88e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -46,6 +46,7 @@ pgpool_SOURCES = main/main.c \
utils/mmgr/mcxt.c \
utils/mmgr/aset.c \
utils/error/elog.c \
+ utils/error/assert.c \
utils/pcp/pcp_stream.c \
utils/pcp/pcp_error.c \
utils/pcp/pcp_timeout.c
diff --git a/src/Makefile.in b/src/Makefile.in
index 59c084d..fcb5655 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -130,8 +130,8 @@ am_pgpool_OBJECTS = main/main.$(OBJEXT) main/pool_globals.$(OBJEXT) \
utils/pool_ssl.$(OBJEXT) utils/pool_stream.$(OBJEXT) \
utils/getopt_long.$(OBJEXT) utils/mmgr/mcxt.$(OBJEXT) \
utils/mmgr/aset.$(OBJEXT) utils/error/elog.$(OBJEXT) \
- utils/pcp/pcp_stream.$(OBJEXT) utils/pcp/pcp_error.$(OBJEXT) \
- utils/pcp/pcp_timeout.$(OBJEXT)
+ utils/error/assert.$(OBJEXT) utils/pcp/pcp_stream.$(OBJEXT) \
+ utils/pcp/pcp_error.$(OBJEXT) utils/pcp/pcp_timeout.$(OBJEXT)
pgpool_OBJECTS = $(am_pgpool_OBJECTS)
pgpool_DEPENDENCIES = parser/libsql-parser.a parser/nodes.o \
watchdog/lib-watchdog.a
@@ -455,6 +455,7 @@ pgpool_SOURCES = main/main.c \
utils/mmgr/mcxt.c \
utils/mmgr/aset.c \
utils/error/elog.c \
+ utils/error/assert.c \
utils/pcp/pcp_stream.c \
utils/pcp/pcp_error.c \
utils/pcp/pcp_timeout.c
@@ -803,6 +804,8 @@ utils/error/$(DEPDIR)/$(am__dirstamp):
@: > utils/error/$(DEPDIR)/$(am__dirstamp)
utils/error/elog.$(OBJEXT): utils/error/$(am__dirstamp) \
utils/error/$(DEPDIR)/$(am__dirstamp)
+utils/error/assert.$(OBJEXT): utils/error/$(am__dirstamp) \
+ utils/error/$(DEPDIR)/$(am__dirstamp)
utils/pcp/$(am__dirstamp):
@$(MKDIR_P) utils/pcp
@: > utils/pcp/$(am__dirstamp)
@@ -881,6 +884,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote at utils/$(DEPDIR)/pool_stream.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at utils/$(DEPDIR)/ps_status.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at utils/$(DEPDIR)/strlcpy.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at utils/error/$(DEPDIR)/assert.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at utils/error/$(DEPDIR)/elog.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at utils/mmgr/$(DEPDIR)/aset.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at utils/mmgr/$(DEPDIR)/mcxt.Po at am__quote@
diff --git a/src/include/config.h.in b/src/include/config.h.in
index b5c7685..f0ee62c 100644
--- a/src/include/config.h.in
+++ b/src/include/config.h.in
@@ -299,6 +299,9 @@
*/
#undef UINT64_FORMAT
+/* Define to 1 to build with assertion checks. (--enable-cassert) */
+#undef USE_ASSERT_CHECKING
+
/* Define to 1 if you want float4 values to be passed by value.
(--enable-float4-byval) */
#undef USE_FLOAT4_BYVAL
diff --git a/src/include/pool_type.h b/src/include/pool_type.h
index 4a2fedd..e6ab805 100644
--- a/src/include/pool_type.h
+++ b/src/include/pool_type.h
@@ -58,6 +58,7 @@ typedef char bool;
#endif /* not C++ */
#endif /* __BEOS__ */
+#define PointerIsValid(pointer) ((const void*)(pointer) != NULL)
typedef signed char int8; /* == 8 bits */
typedef signed short int16; /* == 16 bits */
typedef signed int int32; /* == 32 bits */
@@ -86,7 +87,7 @@ typedef struct {
BACKEND_STATUS status[MAX_NUM_BACKENDS];
} BackendStatusRecord;
-
+extern int assert_enabled;
#define MAXIMUM_ALIGNOF 8
#define TYPEALIGN(ALIGNVAL,LEN) \
@@ -231,7 +232,6 @@ typedef void (*pg_on_exit_callback) (int code, Datum arg);
#define TrapMacro(condition, errorType) (true)
#elif defined(FRONTEND)
-
#include <assert.h>
#define Assert(p) assert(p)
#define AssertMacro(p) ((void) assert(p))
diff --git a/src/main/main.c b/src/main/main.c
index d540197..e561d21 100644
--- a/src/main/main.c
+++ b/src/main/main.c
@@ -59,7 +59,7 @@ static int not_detach = 0; /* non 0 if non detach option (-n) is given */
int stop_sig = SIGTERM; /* stopping signal default value */
int myargc;
char **myargv;
-
+int assert_enabled = 0;
int main(int argc, char **argv)
{
int opt;
@@ -79,6 +79,7 @@ int main(int argc, char **argv)
{"dont-detach", no_argument, NULL, 'n'},
{"discard-status", no_argument, NULL, 'D'},
{"clear-oidmaps", no_argument, NULL, 'C'},
+ {"debug-assertions", no_argument, NULL, 'x'},
{"version", no_argument, NULL, 'v'},
{NULL, 0, NULL, 0}
};
@@ -89,8 +90,7 @@ int main(int argc, char **argv)
snprintf(conf_file, sizeof(conf_file), "%s/%s", DEFAULT_CONFIGDIR, POOL_CONF_FILE_NAME);
snprintf(pcp_conf_file, sizeof(pcp_conf_file), "%s/%s", DEFAULT_CONFIGDIR, PCP_PASSWD_FILE_NAME);
snprintf(hba_file, sizeof(hba_file), "%s/%s", DEFAULT_CONFIGDIR, HBA_CONF_FILE_NAME);
-
- while ((opt = getopt_long(argc, argv, "a:df:F:hm:nDCv", long_options, &optindex)) != -1)
+ while ((opt = getopt_long(argc, argv, "a:df:F:hm:nDCxv", long_options, &optindex)) != -1)
{
switch (opt)
{
@@ -103,6 +103,10 @@ int main(int argc, char **argv)
strlcpy(hba_file, optarg, sizeof(hba_file));
break;
+ case 'x': /* enable cassert */
+ assert_enabled = 1;
+ break;
+
case 'd': /* debug option */
debug_level = 1;
break;
@@ -170,7 +174,6 @@ int main(int argc, char **argv)
exit(1);
}
}
-
#ifdef USE_SSL
/* global ssl init */
SSL_library_init();
@@ -352,6 +355,7 @@ static void usage(void)
fprintf(stderr, " -C, --clear-oidmaps Clears query cache oidmaps when memqcache_method is memcached\n");
fprintf(stderr, " (If shmem, discards whenever pgpool starts.)\n");
fprintf(stderr, " -n, --dont-detach Don't run in daemon mode, does not detach control tty\n");
+ fprintf(stderr, " -x, --debug-assertions Turns on various assertion checks, This is a debugging aid\n");
fprintf(stderr, " -D, --discard-status Discard pgpool_status file and do not restore previous status\n");
fprintf(stderr, " -d, --debug Debug mode\n\n");
fprintf(stderr, "Stop options:\n");
More information about the pgpool-hackers
mailing list