Uncommented beaudio code
[pwlib.git] / src / ptlib / unix / assert.cxx
blob8d49d70ca7ff85657a24220dd75525d37de7c249
1 /*
2 * assert.cxx
4 * Assert function implementation.
6 * Portable Windows Library
8 * Copyright (c) 1993-1998 Equivalence Pty. Ltd.
10 * The contents of this file are subject to the Mozilla Public License
11 * Version 1.0 (the "License"); you may not use this file except in
12 * compliance with the License. You may obtain a copy of the License at
13 * http://www.mozilla.org/MPL/
15 * Software distributed under the License is distributed on an "AS IS"
16 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17 * the License for the specific language governing rights and limitations
18 * under the License.
20 * The Original Code is Portable Windows Library.
22 * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
24 * Portions are Copyright (C) 1993 Free Software Foundation, Inc.
25 * All Rights Reserved.
27 * Contributor(s): ______________________________________.
29 * $Log$
30 * Revision 1.16 2002/06/25 04:05:19 robertj
31 * Fixed new assert function that does not have file/line parameters.
33 * Revision 1.15 2002/06/25 02:26:05 robertj
34 * Improved assertion system to allow C++ class name to be displayed if
35 * desired, especially relevant to container classes.
37 * Revision 1.14 2001/09/03 08:13:54 robertj
38 * Changed "stack dump" option to "run debugger" when get assert.
40 * Revision 1.13 2001/08/30 08:58:09 robertj
41 * Added explicit output to trace file if get assert.
43 * Revision 1.12 2001/07/03 04:41:25 yurik
44 * Corrections to Jac's submission from 6/28
46 * Revision 1.11 2001/06/30 06:59:07 yurik
47 * Jac Goudsmit from Be submit these changes 6/28. Implemented by Yuri Kiryanov
49 * Revision 1.10 2001/05/03 01:14:09 robertj
50 * Put in check to ignore assert if stdin not TTY or not open.
51 * Changed default action on assert to ignore if get EOF.
53 * Revision 1.9 2001/04/20 10:13:02 robertj
54 * Made sure cannot have nested asserts.
56 * Revision 1.8 2000/03/27 18:20:09 craigs
57 * Added the ability to get a stack dump on assert
59 * Revision 1.7 2000/03/21 03:09:54 craigs
60 * Fixed the fix with EOF
62 * Revision 1.6 2000/03/20 22:59:18 craigs
63 * Fixed problem with asserts generating unlimited output when input is redirected
65 * Revision 1.5 2000/02/18 01:49:18 craigs
66 * Added VxWorks code
68 * Revision 1.4 1999/06/23 14:19:46 robertj
69 * Fixed core dump problem with SIGINT/SIGTERM terminating process.
71 * Revision 1.3 1998/09/24 04:12:08 robertj
72 * Added open software license.
74 * Revision 1.2 1998/06/17 14:47:47 robertj
75 * Fixed continuous display of assert if input is from /dev/null
77 * Revision 1.1 1996/01/26 11:09:15 craigs
78 * Initial revision
82 #include <ptlib.h>
84 #include <ctype.h>
85 #include <signal.h>
87 void PAssertFunc(const char * msg)
90 #ifdef __BEOS__
91 // Print location in Eddie-compatible format
92 PError << msg << endl;
93 // Pop up the debugger dialog that gives the user the necessary choices
94 // "Ignore" is not supported on BeOS but you can instruct the
95 // debugger to continue executing.
96 // Note: if you choose "debug" you get a debug prompt. Type bdb to
97 // start the Be Debugger.
98 debugger(msg);
99 #else
100 static BOOL inAssert;
101 if (inAssert)
102 return;
103 inAssert = TRUE;
105 ostream & trace = PTrace::Begin(0, __FILE__, __LINE__);
106 trace << "PWLib\t" << msg << PTrace::End;
108 if (&trace != &PError)
109 PError << msg << endl;
111 #ifndef P_VXWORKS
113 // Check for if stdin is not a TTY and just ignore the assert if so.
114 if (!isatty(STDIN_FILENO)) {
115 inAssert = FALSE;
116 return;
119 for(;;) {
120 PError << "\n<A>bort, <C>ore dump, <I>gnore"
121 #ifdef _DEBUG
122 << ", <D>ebug"
123 #endif
124 << "? " << flush;
125 int c = getchar();
127 switch (c) {
128 case 'a' :
129 case 'A' :
130 PError << "\nAborting.\n";
131 _exit(1);
133 #ifdef _DEBUG
134 case 'd' :
135 case 'D' :
137 PString cmd = "gdb " + PProcess::Current().GetFile();
138 cmd.sprintf(" %d", getpid());
139 system((const char *)cmd);
141 break;
142 #endif
144 case 'c' :
145 case 'C' :
146 PError << "\nDumping core.\n";
147 kill(getpid(), SIGABRT);
149 case 'i' :
150 case 'I' :
151 case EOF :
152 PError << "\nIgnoring.\n";
153 inAssert = FALSE;
154 return;
158 #else // P_VXWORKS
160 exit(1);
161 kill(taskIdSelf(), SIGABRT);
163 #endif // P_VXWORKS
164 #endif // __BEOS__
167 // End Of File ///////////////////////////////////////////////////////////////