11/*-------------------------------------------------------------------------
22 *
33 * assert.c
4- * Assert code.
4+ * Assert support code.
55 *
66 * Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group
77 * Portions Copyright (c) 1994, Regents of the University of California
1010 * IDENTIFICATION
1111 * src/backend/utils/error/assert.c
1212 *
13- * NOTE
14- * This should eventually work with elog()
15- *
1613 *-------------------------------------------------------------------------
1714 */
1815#include "postgres.h"
2421
2522/*
2623 * ExceptionalCondition - Handles the failure of an Assert()
24+ *
25+ * We intentionally do not go through elog() here, on the grounds of
26+ * wanting to minimize the amount of infrastructure that has to be
27+ * working to report an assertion failure.
2728 */
2829void
2930ExceptionalCondition (const char * conditionName ,
3031 const char * errorType ,
3132 const char * fileName ,
3233 int lineNumber )
3334{
35+ /* Report the failure on stderr (or local equivalent) */
3436 if (!PointerIsValid (conditionName )
3537 || !PointerIsValid (fileName )
3638 || !PointerIsValid (errorType ))
37- write_stderr ("TRAP: ExceptionalCondition: bad arguments\n" );
39+ write_stderr ("TRAP: ExceptionalCondition: bad arguments in PID %d\n" ,
40+ (int ) getpid ());
3841 else
39- {
40- write_stderr ("TRAP: %s(\"%s\", File: \"%s\", Line: %d)\n" ,
42+ write_stderr ("TRAP: %s(\"%s\", File: \"%s\", Line: %d, PID: %d)\n" ,
4143 errorType , conditionName ,
42- fileName , lineNumber );
43- }
44+ fileName , lineNumber , (int ) getpid ());
4445
4546 /* Usually this shouldn't be needed, but make sure the msg went out */
4647 fflush (stderr );
4748
49+ /* If we have support for it, dump a simple backtrace */
4850#ifdef HAVE_BACKTRACE_SYMBOLS
4951 {
5052 void * buf [100 ];
@@ -55,12 +57,12 @@ ExceptionalCondition(const char *conditionName,
5557 }
5658#endif
5759
58- #ifdef SLEEP_ON_ASSERT
59-
6060 /*
61- * It would be nice to use pg_usleep() here, but only does 2000 sec or 33
62- * minutes, which seems too short.
61+ * If configured to do so, sleep indefinitely to allow user to attach a
62+ * debugger. It would be nice to use pg_usleep() here, but that can sleep
63+ * at most 2G usec or ~33 minutes, which seems too short.
6364 */
65+ #ifdef SLEEP_ON_ASSERT
6466 sleep (1000000 );
6567#endif
6668
0 commit comments