OSDN Git Service

Add SLEEP_ON_ABORT
[pg-rex/syncrep.git] / src / backend / utils / error / assert.c
1 /*-------------------------------------------------------------------------
2  *
3  * assert.c--
4  *        Assert code.
5  *
6  * Copyright (c) 1994, Regents of the University of California
7  *
8  *
9  * IDENTIFICATION
10  *        $Header: /cvsroot/pgsql/src/backend/utils/error/assert.c,v 1.9 1998/06/18 16:35:38 momjian Exp $
11  *
12  * NOTE
13  *        This should eventually work with elog(), dlog(), etc.
14  *
15  *-------------------------------------------------------------------------
16  */
17 #include <stdio.h>
18 #include <unistd.h>
19
20 #include "postgres.h"                   /* where the declaration goes */
21 #include "utils/module.h"
22
23 #include "utils/exc.h"
24
25 int
26 ExceptionalCondition(char *conditionName,
27                                          Exception *exceptionP,
28                                          char *detail,
29                                          char *fileName,
30                                          int lineNumber)
31 {
32         extern char *ExcFileName;       /* XXX */
33         extern Index ExcLineNumber; /* XXX */
34
35         ExcFileName = fileName;
36         ExcLineNumber = lineNumber;
37
38         if (!PointerIsValid(conditionName)
39                 || !PointerIsValid(fileName)
40                 || !PointerIsValid(exceptionP))
41         {
42                 fprintf(stderr, "ExceptionalCondition: bad arguments\n");
43
44                 ExcAbort(exceptionP,
45                                  (ExcDetail) detail,
46                                  (ExcData) NULL,
47                                  (ExcMessage) NULL);
48         }
49         else
50         {
51                 fprintf(stderr,
52                                 "%s(\"%s:%s\", File: \"%s\", Line: %d)\n",
53                 exceptionP->message, conditionName, detail == NULL ? "" : detail,
54                                 fileName, lineNumber);
55         }
56
57 #ifdef ABORT_ON_ASSERT
58         abort();
59 #endif
60 #ifdef SLEEP_ON_ASSERT
61         sleep(1000000);
62 #endif
63
64         /*
65          * XXX Depending on the Exception and tracing conditions, you will XXX
66          * want to stop here immediately and maybe dump core. XXX This may be
67          * especially true for Assert(), etc.
68          */
69
70         /* TraceDump();         dump the trace stack */
71
72         /* XXX FIXME: detail is lost */
73         ExcRaise(exceptionP, (ExcDetail) 0, (ExcData) NULL, conditionName);
74         return (0);
75 }