PostgreSQL Source Code  git master
assert.c File Reference
#include "postgres.h"
#include <unistd.h>
Include dependency graph for assert.c:

Go to the source code of this file.

Functions

void ExceptionalCondition (const char *conditionName, const char *fileName, int lineNumber)
 

Function Documentation

◆ ExceptionalCondition()

void ExceptionalCondition ( const char *  conditionName,
const char *  fileName,
int  lineNumber 
)

Definition at line 30 of file assert.c.

33 {
34  /* Report the failure on stderr (or local equivalent) */
35  if (!PointerIsValid(conditionName)
36  || !PointerIsValid(fileName))
37  write_stderr("TRAP: ExceptionalCondition: bad arguments in PID %d\n",
38  (int) getpid());
39  else
40  write_stderr("TRAP: failed Assert(\"%s\"), File: \"%s\", Line: %d, PID: %d\n",
41  conditionName, fileName, lineNumber, (int) getpid());
42 
43  /* Usually this shouldn't be needed, but make sure the msg went out */
44  fflush(stderr);
45 
46  /* If we have support for it, dump a simple backtrace */
47 #ifdef HAVE_BACKTRACE_SYMBOLS
48  {
49  void *buf[100];
50  int nframes;
51 
52  nframes = backtrace(buf, lengthof(buf));
53  backtrace_symbols_fd(buf, nframes, fileno(stderr));
54  }
55 #endif
56 
57  /*
58  * If configured to do so, sleep indefinitely to allow user to attach a
59  * debugger. It would be nice to use pg_usleep() here, but that can sleep
60  * at most 2G usec or ~33 minutes, which seems too short.
61  */
62 #ifdef SLEEP_ON_ASSERT
63  sleep(1000000);
64 #endif
65 
66  abort();
67 }
#define write_stderr(str)
Definition: parallel.c:184
#define PointerIsValid(pointer)
Definition: c.h:763
#define lengthof(array)
Definition: c.h:788
static void const char fflush(stdout)
static char * buf
Definition: pg_test_fsync.c:73

References buf, fflush(), lengthof, PointerIsValid, and write_stderr.

Referenced by pg_re_throw().