00001 // Verbose terminate_handler -*- C++ -*- 00002 00003 // Copyright (C) 2001, 2002 Free Software Foundation 00004 // 00005 // This file is part of GNU CC. 00006 // 00007 // GNU CC is free software; you can redistribute it and/or modify 00008 // it under the terms of the GNU General Public License as published by 00009 // the Free Software Foundation; either version 2, or (at your option) 00010 // any later version. 00011 // 00012 // GNU CC is distributed in the hope that it will be useful, 00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 // GNU General Public License for more details. 00016 // 00017 // You should have received a copy of the GNU General Public License 00018 // along with GNU CC; see the file COPYING. If not, write to 00019 // the Free Software Foundation, 59 Temple Place - Suite 330, 00020 // Boston, MA 02111-1307, USA. 00021 00022 // As a special exception, you may use this file as part of a free software 00023 // library without restriction. Specifically, if other files instantiate 00024 // templates or use macros or inline functions from this file, or you compile 00025 // this file and link it with other files to produce an executable, this 00026 // file does not by itself cause the resulting executable to be covered by 00027 // the GNU General Public License. This exception does not however 00028 // invalidate any other reasons why the executable file might be covered by 00029 // the GNU General Public License. 00030 00031 #include <cstdlib> 00032 #include <cstdio> 00033 #include <exception> 00034 #include <exception_defines.h> 00035 #include <cxxabi.h> 00036 00037 using namespace std; 00038 using namespace abi; 00039 00040 namespace __gnu_cxx 00041 { 00042 /* A replacement for the standard terminate_handler which prints 00043 more information about the terminating exception (if any) on 00044 stderr. */ 00045 void __verbose_terminate_handler() 00046 { 00047 // Make sure there was an exception; terminate is also called for an 00048 // attempt to rethrow when there is no suitable exception. 00049 type_info *t = __cxa_current_exception_type(); 00050 if (t) 00051 { 00052 char const *name = t->name(); 00053 // Note that "name" is the mangled name. 00054 00055 { 00056 int status = -1; 00057 char *dem = 0; 00058 00059 // Disabled until __cxa_demangle gets the runtime GPL exception. 00060 dem = __cxa_demangle(name, 0, 0, &status); 00061 00062 printf("terminate called after throwing a `%s'\n", 00063 status == 0 ? dem : name); 00064 00065 if (status == 0) 00066 free(dem); 00067 } 00068 00069 // If the exception is derived from std::exception, we can give more 00070 // information. 00071 try { __throw_exception_again; } 00072 #ifdef __EXCEPTIONS 00073 catch (exception &exc) 00074 { fprintf(stderr, " what(): %s\n", exc.what()); } 00075 #endif 00076 catch (...) { } 00077 } 00078 else 00079 fprintf(stderr, "terminate called without an active exception\n"); 00080 00081 abort(); 00082 } 00083 } // namespace __gnu_cxx