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 *errorType, const char *fileName, int lineNumber)
 

Function Documentation

◆ ExceptionalCondition()

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

Definition at line 30 of file assert.c.

References buf, lengthof, PointerIsValid, and write_stderr.

Referenced by pg_re_throw().

34 {
35  /* Report the failure on stderr (or local equivalent) */
36  if (!PointerIsValid(conditionName)
37  || !PointerIsValid(fileName)
38  || !PointerIsValid(errorType))
39  write_stderr("TRAP: ExceptionalCondition: bad arguments in PID %d\n",
40  (int) getpid());
41  else
42  write_stderr("TRAP: %s(\"%s\", File: \"%s\", Line: %d, PID: %d)\n",
43  errorType, conditionName,
44  fileName, lineNumber, (int) getpid());
45 
46  /* Usually this shouldn't be needed, but make sure the msg went out */
47  fflush(stderr);
48 
49  /* If we have support for it, dump a simple backtrace */
50 #ifdef HAVE_BACKTRACE_SYMBOLS
51  {
52  void *buf[100];
53  int nframes;
54 
55  nframes = backtrace(buf, lengthof(buf));
56  backtrace_symbols_fd(buf, nframes, fileno(stderr));
57  }
58 #endif
59 
60  /*
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.
64  */
65 #ifdef SLEEP_ON_ASSERT
66  sleep(1000000);
67 #endif
68 
69  abort();
70 }
#define write_stderr(str)
Definition: parallel.c:186
#define lengthof(array)
Definition: c.h:734
static char * buf
Definition: pg_test_fsync.c:68
#define PointerIsValid(pointer)
Definition: c.h:698