]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/libsupc++/vterminate.cc
rs6000.md (movsf_hardfloat): Add POWER form of nop.
[thirdparty/gcc.git] / libstdc++-v3 / libsupc++ / vterminate.cc
CommitLineData
74a3070f
JM
1// Verbose terminate_handler -*- C++ -*-
2
2ca08953 3// Copyright (C) 2001, 2002 Free Software Foundation
74a3070f 4//
38cca750
BK
5// This file is part of the GNU ISO C++ Library. This library is free
6// software; you can redistribute it and/or modify it under the
7// terms of the GNU General Public License as published by the
8// Free Software Foundation; either version 2, or (at your option)
74a3070f 9// any later version.
38cca750
BK
10
11// This library is distributed in the hope that it will be useful,
74a3070f
JM
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
38cca750
BK
15
16// You should have received a copy of the GNU General Public License along
17// with this library; see the file COPYING. If not, write to the Free
18// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19// USA.
74a3070f
JM
20
21// As a special exception, you may use this file as part of a free software
22// library without restriction. Specifically, if other files instantiate
23// templates or use macros or inline functions from this file, or you compile
24// this file and link it with other files to produce an executable, this
25// file does not by itself cause the resulting executable to be covered by
26// the GNU General Public License. This exception does not however
27// invalidate any other reasons why the executable file might be covered by
28// the GNU General Public License.
29
fb705416 30#include <bits/c++config.h>
74a3070f 31#include <cstdlib>
2ca08953
BK
32#include <exception>
33#include <exception_defines.h>
74a3070f
JM
34#include <cxxabi.h>
35
3d7c150e 36#ifdef _GLIBCXX_HAVE_UNISTD_H
fb705416 37# include <unistd.h>
9795acc6 38# define writestr(str) write(2, str, __builtin_strlen(str))
fb705416
PE
39#else
40# include <cstdio>
41# define writestr(str) std::fputs(str, stderr)
42#endif
43
74a3070f
JM
44using namespace std;
45using namespace abi;
46
1b4a6975
PE
47namespace __gnu_cxx
48{
2ca08953
BK
49 /* A replacement for the standard terminate_handler which prints
50 more information about the terminating exception (if any) on
51 stderr. */
52 void __verbose_terminate_handler()
53 {
afc3bb58
MM
54 static bool terminating;
55
56 if (terminating)
57 {
58 writestr ("terminate called recursively\n");
59 abort ();
60 }
61
62 terminating = true;
63
2ca08953
BK
64 // Make sure there was an exception; terminate is also called for an
65 // attempt to rethrow when there is no suitable exception.
66 type_info *t = __cxa_current_exception_type();
67 if (t)
74a3070f 68 {
2ca08953
BK
69 char const *name = t->name();
70 // Note that "name" is the mangled name.
71
72 {
73 int status = -1;
74 char *dem = 0;
75
2ca08953 76 dem = __cxa_demangle(name, 0, 0, &status);
74a3070f 77
fb705416
PE
78 writestr("terminate called after throwing an instance of '");
79 if (status == 0)
80 writestr(dem);
81 else
82 writestr(name);
83 writestr("'\n");
74a3070f 84
2ca08953
BK
85 if (status == 0)
86 free(dem);
87 }
74a3070f 88
2ca08953
BK
89 // If the exception is derived from std::exception, we can give more
90 // information.
91 try { __throw_exception_again; }
92#ifdef __EXCEPTIONS
93 catch (exception &exc)
fb705416
PE
94 {
95 char const *w = exc.what();
96 writestr(" what(): ");
97 writestr(w);
98 writestr("\n");
99 }
2ca08953
BK
100#endif
101 catch (...) { }
102 }
103 else
fb705416 104 writestr("terminate called without an active exception\n");
2ca08953
BK
105
106 abort();
107 }
74a3070f 108} // namespace __gnu_cxx