libverbose_terminate, pass 1 of N

Phil Edwards phil@jaj.com
Thu Dec 19 12:45:00 GMT 2002


Jason's patch

    http://gcc.gnu.org/ml/gcc-patches/2002-12/msg00957.html

started an interesting thread of about a dozen messages.  The upshot is that
currently, using __verbose_terminate() as the termination handler requires a
change to user code, usually main().  It Would Be Cool[tm] if the user could
install this handler at link-time with -l, or at runtime with LD_PRELOAD.

Here's a patch for discussion purposes.  It installs a libverbose_terminate,
and I've verified by hand that using -lverbose_terminate or LD_PRELOAD
both DTRT.  I've made an attempt at a testcase, but dg-output doesn't do
what I thought it did; the testsuite log shows

    PASS: ext/verbose_terminate.cc (test for excess errors)
    terminate called after throwing a `int'
    FAIL: ext/verbose_terminate.cc execution test

                    === libstdc++-v3 Summary ===

    # of expected passes            1
    # of unexpected failures        1

I'm guessing that dg-output is only scanning stdout, not stderr.  Ironically,
Jason's patch that started this whole idea is what changed the message
from stdout to stderr.


Thoughts?


2002-12-19  Phil Edwards  <pme@gcc.gnu.org>

	* src/verb_term.cc:  New file.
	* src/Makefile.am (toolexeclib_LTLIBRARIES):  Add
	libverbose_terminate.la, built from verb_term.cc.
	* testsuite/ext/verbose_terminate.cc:  New file.


Index: src/Makefile.am
===================================================================
RCS file: /home/pme/Repositories/GCC/gcc/libstdc++-v3/src/Makefile.am,v
retrieving revision 1.114
diff -u -3 -p -r1.114 Makefile.am
--- src/Makefile.am	16 Dec 2002 19:02:01 -0000	1.114
+++ src/Makefile.am	19 Dec 2002 20:13:25 -0000
@@ -33,7 +33,7 @@ glibcpp_srcdir=@glibcpp_srcdir@
 glibcpp_builddir=@glibcpp_builddir@
 toolexecdir = @glibcpp_toolexecdir@
 toolexeclibdir = @glibcpp_toolexeclibdir@
-toolexeclib_LTLIBRARIES = libstdc++.la
+toolexeclib_LTLIBRARIES = libstdc++.la libverbose_terminate.la
 
 # Symbol versioning for shared libraries.
 if GLIBCPP_BUILD_VERSIONED_SHLIB
@@ -151,6 +151,7 @@ sources = \
 VPATH = $(top_srcdir)/src:$(top_srcdir)
 
 libstdc___la_SOURCES = $(sources)
+libverbose_terminate_la_SOURCES = verb_term.cc
 
 libstdc___la_LIBADD = \
 	$(top_builddir)/libmath/libmath.la @libio_la@ \
Index: src/verb_term.cc
===================================================================
RCS file: src/verb_term.cc
diff -N src/verb_term.cc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/verb_term.cc	19 Dec 2002 20:04:41 -0000
@@ -0,0 +1,39 @@
+// -*- C++ -*- 
+// Copyright (C) 2002 Free Software Foundation
+//
+// This file is part of GNU CC.
+//
+// GNU CC is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// GNU CC is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with GNU CC; see the file COPYING.  If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free software
+// library without restriction.  Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License.  This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+#include <exception>
+
+namespace __gnu_cxx
+{
+  static struct __Verb_Term_Preload
+  {
+    __Verb_Term_Preload ()
+      { std::set_terminate (__gnu_cxx::__verbose_terminate_handler); }
+  } __verb_term_dummy;
+}
Index: testsuite/ext/verbose_terminate.cc
===================================================================
RCS file: testsuite/ext/verbose_terminate.cc
diff -N testsuite/ext/verbose_terminate.cc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ testsuite/ext/verbose_terminate.cc	19 Dec 2002 20:24:44 -0000
@@ -0,0 +1,32 @@
+// 2002-12-19  Phil Edwards  <pme@gcc.gnu.org>
+//
+// Copyright (C) 2002 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING.  If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// { dg-options "-lverbose_terminate" }
+// { dg-do run }
+// { dg-output "terminate called after throwing a" }
+
+#include <exception>
+#include <testsuite_hooks.h>
+
+int main()
+{
+  throw 42;
+  return 0;
+}



More information about the Gcc-patches mailing list