backtracexx: example.cpp makefile

pluto cvs at pld-linux.org
Thu Aug 31 20:27:28 CEST 2006


Author: pluto
Date: Thu Aug 31 20:27:26 2006
New Revision: 7697

Modified:
   backtracexx/example.cpp
   backtracexx/makefile
Log:
- throw exception from signal handler. it really works in gcc-4.2.


Modified: backtracexx/example.cpp
==============================================================================
--- backtracexx/example.cpp	(original)
+++ backtracexx/example.cpp	Thu Aug 31 20:27:26 2006
@@ -1,16 +1,15 @@
 #include "backtracexx.hpp"
-#include <csetjmp>
+
 #include <csignal>
 #include <iostream>
 #include <iterator>
-
-jmp_buf context;
+#include <stdexcept>
 
 void signalHandler( int signalNumber )
 {
 	backtracexx::symbolic_backtrace_type s = backtracexx::symbols( backtracexx::scan() );
-	std::copy(s.begin(), s.end(), std::ostream_iterator< std::string >( std::cout, "\n" ) );
-	longjmp( context, 1 );
+	std::copy( s.begin(), s.end(), std::ostream_iterator< std::string >( std::cout, "\n" ) );
+	throw std::runtime_error( "fatality." );
 }
 
 void zoo()
@@ -32,9 +31,13 @@
 int main()
 {
 	signal( SIGSEGV, signalHandler );
-	if ( setjmp( context ) == 0 )
+	try
 	{
 		foo();
 	}
+	catch ( std::exception const& e )
+	{
+		std::cerr << e.what() << std::endl;
+	}
 	return 0;
 }

Modified: backtracexx/makefile
==============================================================================
--- backtracexx/makefile	(original)
+++ backtracexx/makefile	Thu Aug 31 20:27:26 2006
@@ -5,11 +5,11 @@
 
 libbacktracexx.so: backtracexx.hpp backtracexx.cpp
 	$(CXX) backtracexx.cpp -o libbacktracexx.so -shared -ldl $(CXXFLAGS) \
-	-O3 -fpic -funwind-tables -fno-exceptions -fno-rtti
+	-O3 -fpic -funwind-tables -fno-exceptions -fno-rtti -s
 
 example: example.cpp libbacktracexx.so
 	$(CXX) example.cpp -o example ./libbacktracexx.so $(CXXFLAGS) \
-	-O1 -funwind-tables -Wl,-export-dynamic
+	-O1 -Wl,-export-dynamic -s
 
 clean:
 	rm -f libbacktracexx.so example


More information about the pld-cvs-commit mailing list