Author: pluto
Date: Wed Aug 30 02:36:44 2006
New Revision: 7689

Modified:
   backtracexx/backtracexx.cpp
   backtracexx/backtracexx.hpp
   backtracexx/example.cpp
Log:
- signal frame support.


Modified: backtracexx/backtracexx.cpp
==============================================================================
--- backtracexx/backtracexx.cpp (original)
+++ backtracexx/backtracexx.cpp Wed Aug 30 02:36:44 2006
@@ -29,9 +29,12 @@
 
                _Unwind_Reason_Code helper( struct _Unwind_Context* ctx, void* 
arg )
                {
-                       _Unwind_Ptr ip = _Unwind_GetIP( ctx );
-                       reinterpret_cast< raw_backtrace_type* >( arg 
)->push_back(
-                               caller( reinterpret_cast< unsigned char const* 
>( ip ) ) );
+                       int beforeInsn = 0;
+                       _Unwind_Ptr ip = _Unwind_GetIPInfo( ctx, &beforeInsn );
+                       unwind_point_type up( reinterpret_cast< unsigned char 
const* >( ip ), beforeInsn );
+                       if ( !beforeInsn )
+                               up.first = caller( reinterpret_cast< unsigned 
char const* >( up.first ) );
+                       reinterpret_cast< raw_backtrace_type* >( arg 
)->push_back( up );
                        return _URC_NO_REASON;
                }
        }
@@ -53,8 +56,9 @@
                {
                        os.str( std::string() );
                        Dl_info info;
-                       os << std::setw( 18 ) << *i << " : ";
-                       if ( dladdr( const_cast< void* >( *i ), &info ) )
+                       unwind_point_type up = *i;
+                       os << std::setw( 18 ) << up.first << " : ";
+                       if ( dladdr( const_cast< void* >( up.first ), &info ) )
                        {
                                if ( !info.dli_saddr )
                                        // the image containing address is 
found, but no nearest symbol was found.
@@ -65,7 +69,7 @@
                                        char* demangled = abi::__cxa_demangle( 
info.dli_sname, 0, 0, &status );
                                        if ( status != -1 )
                                        {
-                                               long offset = reinterpret_cast< 
long >( *i ) - reinterpret_cast< long >( info.dli_saddr );
+                                               long offset = reinterpret_cast< 
long >( up.first ) - reinterpret_cast< long >( info.dli_saddr );
                                                os << ( ( status == 0 ) ? 
demangled : info.dli_sname ) << '+' << offset;
                                                if ( status == 0 )
                                                        free( demangled );
@@ -75,6 +79,8 @@
                        }
                        else
                                os << "??";
+                       if ( up.second )
+                               os << " [signal frame]";
                        sbt.push_back( os.str() );
                }
                return sbt;

Modified: backtracexx/backtracexx.hpp
==============================================================================
--- backtracexx/backtracexx.hpp (original)
+++ backtracexx/backtracexx.hpp Wed Aug 30 02:36:44 2006
@@ -3,10 +3,14 @@
 
 #include <list>
 #include <string>
+#include <utility>
 
 namespace backtracexx
 {
-       typedef std::list< void const* > raw_backtrace_type;
+       typedef std::pair< void const*,
+               bool /* signal frame */ > unwind_point_type;
+
+       typedef std::list< unwind_point_type > raw_backtrace_type;
        typedef std::list< std::string > symbolic_backtrace_type;
 
        raw_backtrace_type scan();

Modified: backtracexx/example.cpp
==============================================================================
--- backtracexx/example.cpp     (original)
+++ backtracexx/example.cpp     Wed Aug 30 02:36:44 2006
@@ -1,11 +1,22 @@
 #include "backtracexx.hpp"
+#include <csetjmp>
+#include <csignal>
 #include <iostream>
 #include <iterator>
 
-void zoo()
+jmp_buf context;
+
+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 );
+}
+
+void zoo()
+{
+       volatile int* p = 0;
+       *p = 0;
 }
 
 void bar( void ( *f )() )
@@ -20,6 +31,10 @@
 
 int main()
 {
-       foo();
+       signal( SIGSEGV, signalHandler );
+       if ( setjmp( context ) == 0 )
+       {
+               foo();
+       }
        return 0;
 }
_______________________________________________
pld-cvs-commit mailing list
[email protected]
http://lists.pld-linux.org/mailman/listinfo/pld-cvs-commit

Reply via email to