PostgreSQL Source Code  git master
assert.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * assert.c
4  * Assert code.
5  *
6  * Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group
7  * Portions Copyright (c) 1994, Regents of the University of California
8  *
9  *
10  * IDENTIFICATION
11  * src/backend/utils/error/assert.c
12  *
13  * NOTE
14  * This should eventually work with elog()
15  *
16  *-------------------------------------------------------------------------
17  */
18 #include "postgres.h"
19 
20 #include <unistd.h>
21 #ifdef HAVE_EXECINFO_H
22 #include <execinfo.h>
23 #endif
24 
25 /*
26  * ExceptionalCondition - Handles the failure of an Assert()
27  */
28 void
29 ExceptionalCondition(const char *conditionName,
30  const char *errorType,
31  const char *fileName,
32  int lineNumber)
33 {
34  if (!PointerIsValid(conditionName)
35  || !PointerIsValid(fileName)
36  || !PointerIsValid(errorType))
37  write_stderr("TRAP: ExceptionalCondition: bad arguments\n");
38  else
39  {
40  write_stderr("TRAP: %s(\"%s\", File: \"%s\", Line: %d)\n",
41  errorType, conditionName,
42  fileName, lineNumber);
43  }
44 
45  /* Usually this shouldn't be needed, but make sure the msg went out */
46  fflush(stderr);
47 
48 #ifdef HAVE_BACKTRACE_SYMBOLS
49  {
50  void *buf[100];
51  int nframes;
52 
53  nframes = backtrace(buf, lengthof(buf));
54  backtrace_symbols_fd(buf, nframes, fileno(stderr));
55  }
56 #endif
57 
58 #ifdef SLEEP_ON_ASSERT
59 
60  /*
61  * It would be nice to use pg_usleep() here, but only does 2000 sec or 33
62  * minutes, which seems too short.
63  */
64  sleep(1000000);
65 #endif
66 
67  abort();
68 }
#define write_stderr(str)
Definition: parallel.c:181
#define lengthof(array)
Definition: c.h:669
void ExceptionalCondition(const char *conditionName, const char *errorType, const char *fileName, int lineNumber)
Definition: assert.c:29
static char * buf
Definition: pg_test_fsync.c:67
#define PointerIsValid(pointer)
Definition: c.h:633