LCOV - code coverage report
Current view: top level - src/backend/utils/error - assert.c (source / functions) Hit Total Coverage
Test: PostgreSQL 15devel Lines: 0 12 0.0 %
Date: 2021-11-29 05:09:10 Functions: 0 1 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*-------------------------------------------------------------------------
       2             :  *
       3             :  * assert.c
       4             :  *    Assert support code.
       5             :  *
       6             :  * Portions Copyright (c) 1996-2021, 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             :  *-------------------------------------------------------------------------
      14             :  */
      15             : #include "postgres.h"
      16             : 
      17             : #include <unistd.h>
      18             : #ifdef HAVE_EXECINFO_H
      19             : #include <execinfo.h>
      20             : #endif
      21             : 
      22             : /*
      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.
      28             :  */
      29             : void
      30           0 : ExceptionalCondition(const char *conditionName,
      31             :                      const char *errorType,
      32             :                      const char *fileName,
      33             :                      int lineNumber)
      34             : {
      35             :     /* Report the failure on stderr (or local equivalent) */
      36           0 :     if (!PointerIsValid(conditionName)
      37           0 :         || !PointerIsValid(fileName)
      38           0 :         || !PointerIsValid(errorType))
      39           0 :         write_stderr("TRAP: ExceptionalCondition: bad arguments in PID %d\n",
      40           0 :                      (int) getpid());
      41             :     else
      42           0 :         write_stderr("TRAP: %s(\"%s\", File: \"%s\", Line: %d, PID: %d)\n",
      43             :                      errorType, conditionName,
      44           0 :                      fileName, lineNumber, (int) getpid());
      45             : 
      46             :     /* Usually this shouldn't be needed, but make sure the msg went out */
      47           0 :     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           0 :         nframes = backtrace(buf, lengthof(buf));
      56           0 :         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           0 :     abort();
      70             : }

Generated by: LCOV version 1.14