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
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): ______________________________________.
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
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
87 void PAssertFunc(const char * msg
)
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.
100 static BOOL inAssert
;
105 ostream
& trace
= PTrace::Begin(0, __FILE__
, __LINE__
);
106 trace
<< "PWLib\t" << msg
<< PTrace::End
;
108 if (&trace
!= &PError
)
109 PError
<< msg
<< endl
;
113 // Check for if stdin is not a TTY and just ignore the assert if so.
114 if (!isatty(STDIN_FILENO
)) {
120 PError
<< "\n<A>bort, <C>ore dump, <I>gnore"
130 PError
<< "\nAborting.\n";
137 PString cmd
= "gdb " + PProcess::Current().GetFile();
138 cmd
.sprintf(" %d", getpid());
139 system((const char *)cmd
);
146 PError
<< "\nDumping core.\n";
147 kill(getpid(), SIGABRT
);
152 PError
<< "\nIgnoring.\n";
161 kill(taskIdSelf(), SIGABRT
);
167 // End Of File ///////////////////////////////////////////////////////////////