1
1
/*-------------------------------------------------------------------------
2
2
*
3
3
* assert.c
4
- * Assert code.
4
+ * Assert support code.
5
5
*
6
6
* Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group
7
7
* Portions Copyright (c) 1994, Regents of the University of California
10
10
* IDENTIFICATION
11
11
* src/backend/utils/error/assert.c
12
12
*
13
- * NOTE
14
- * This should eventually work with elog()
15
- *
16
13
*-------------------------------------------------------------------------
17
14
*/
18
15
#include "postgres.h"
24
21
25
22
/*
26
23
* 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.
27
28
*/
28
29
void
29
30
ExceptionalCondition (const char * conditionName ,
30
31
const char * errorType ,
31
32
const char * fileName ,
32
33
int lineNumber )
33
34
{
35
+ /* Report the failure on stderr (or local equivalent) */
34
36
if (!PointerIsValid (conditionName )
35
37
|| !PointerIsValid (fileName )
36
38
|| !PointerIsValid (errorType ))
37
- write_stderr ("TRAP: ExceptionalCondition: bad arguments\n" );
39
+ write_stderr ("TRAP: ExceptionalCondition: bad arguments in PID %d\n" ,
40
+ (int ) getpid ());
38
41
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" ,
41
43
errorType , conditionName ,
42
- fileName , lineNumber );
43
- }
44
+ fileName , lineNumber , (int ) getpid ());
44
45
45
46
/* Usually this shouldn't be needed, but make sure the msg went out */
46
47
fflush (stderr );
47
48
49
+ /* If we have support for it, dump a simple backtrace */
48
50
#ifdef HAVE_BACKTRACE_SYMBOLS
49
51
{
50
52
void * buf [100 ];
@@ -55,12 +57,12 @@ ExceptionalCondition(const char *conditionName,
55
57
}
56
58
#endif
57
59
58
- #ifdef SLEEP_ON_ASSERT
59
-
60
60
/*
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.
63
64
*/
65
+ #ifdef SLEEP_ON_ASSERT
64
66
sleep (1000000 );
65
67
#endif
66
68
0 commit comments