execution_monitor.ipp
字号:
switch( m_sig_info->si_code ) { case BUS_ADRALN: report_error( execution_exception::system_fatal_error, "memory access violation at address: 0x%08lx: invalid address alignment", m_sig_info->si_addr ); break; case BUS_ADRERR: report_error( execution_exception::system_fatal_error, "memory access violation at address: 0x%08lx: non-existent physical address", m_sig_info->si_addr ); break; case BUS_OBJERR: report_error( execution_exception::system_fatal_error, "memory access violation at address: 0x%08lx: object specific hardware error", m_sig_info->si_addr ); break; } break; case SIGCHLD: switch( m_sig_info->si_code ) { case CLD_EXITED: report_error( execution_exception::system_error, "child has exited; pid: %d; uid: %d; exit value: %d", (int)m_sig_info->si_pid, (int)m_sig_info->si_uid, (int)m_sig_info->si_status ); break; case CLD_KILLED: report_error( execution_exception::system_error, "child was killed; pid: %d; uid: %d; exit value: %d", (int)m_sig_info->si_pid, (int)m_sig_info->si_uid, (int)m_sig_info->si_status ); break; case CLD_DUMPED: report_error( execution_exception::system_error, "child terminated abnormally; pid: %d; uid: %d; exit value: %d", (int)m_sig_info->si_pid, (int)m_sig_info->si_uid, (int)m_sig_info->si_status ); break; case CLD_TRAPPED: report_error( execution_exception::system_error, "traced child has trapped; pid: %d; uid: %d; exit value: %d", (int)m_sig_info->si_pid, (int)m_sig_info->si_uid, (int)m_sig_info->si_status ); break; case CLD_STOPPED: report_error( execution_exception::system_error, "child has stopped; pid: %d; uid: %d; exit value: %d", (int)m_sig_info->si_pid, (int)m_sig_info->si_uid, (int)m_sig_info->si_status ); break; case CLD_CONTINUED: report_error( execution_exception::system_error, "stopped child had continued; pid: %d; uid: %d; exit value: %d", (int)m_sig_info->si_pid, (int)m_sig_info->si_uid, (int)m_sig_info->si_status ); break; } break;#if defined(BOOST_TEST_CATCH_SIGPOLL) case SIGPOLL: switch( m_sig_info->si_code ) { case POLL_IN: report_error( execution_exception::system_error, "data input available; band event %d", (int)m_sig_info->si_band ); break; case POLL_OUT: report_error( execution_exception::system_error, "output buffers available; band event %d", (int)m_sig_info->si_band ); break; case POLL_MSG: report_error( execution_exception::system_error, "input message available; band event %d", (int)m_sig_info->si_band ); break; case POLL_ERR: report_error( execution_exception::system_error, "i/o error; band event %d", (int)m_sig_info->si_band ); break; case POLL_PRI: report_error( execution_exception::system_error, "high priority input available; band event %d", (int)m_sig_info->si_band ); break;#if defined(POLL_ERR) && defined(POLL_HUP) && (POLL_ERR - POLL_HUP) case POLL_HUP: report_error( execution_exception::system_error, "device disconnected; band event %d", (int)m_sig_info->si_band ); break;#endif } break;#endif case SIGABRT: report_error( execution_exception::system_error, "signal: SIGABRT (application abort requested)" ); break; case SIGALRM: report_error( execution_exception::timeout_error, "signal: SIGALRM (timeout while executing function)" ); break; default: report_error( execution_exception::system_error, "unrecognized signal" ); }}//____________________________________________________________________________//// ************************************************************************** //// ************** boost::detail::signal_action ************** //// ************************************************************************** //// Forward declarationextern "C" {static void execution_monitor_jumping_signal_handler( int sig, siginfo_t* info, void* context );static void execution_monitor_attaching_signal_handler( int sig, siginfo_t* info, void* context );}class signal_action { typedef struct sigaction* sigaction_ptr;public: //Constructor explicit signal_action( int sig, bool install, bool attach_dbg, char* alt_stack ); ~signal_action();private: // Data members int m_sig; bool m_installed; struct sigaction m_new_action; struct sigaction m_old_action;};//____________________________________________________________________________//signal_action::signal_action( int sig, bool install, bool attach_dbg, char* alt_stack ): m_sig( sig ), m_installed( install ){ if( !install ) return; std::memset( &m_new_action, 0, sizeof(struct sigaction) ); BOOST_TEST_SYS_ASSERT( ::sigaction( m_sig , sigaction_ptr(), &m_new_action ) != -1 ); if( m_new_action.sa_sigaction || m_new_action.sa_handler ) { m_installed = false; return; } m_new_action.sa_flags |= SA_SIGINFO; m_new_action.sa_sigaction = attach_dbg ? &execution_monitor_attaching_signal_handler : &execution_monitor_jumping_signal_handler; BOOST_TEST_SYS_ASSERT( sigemptyset( &m_new_action.sa_mask ) != -1 );#ifdef BOOST_TEST_USE_ALT_STACK if( alt_stack ) m_new_action.sa_flags |= SA_ONSTACK;#endif BOOST_TEST_SYS_ASSERT( ::sigaction( m_sig, &m_new_action, &m_old_action ) != -1 );}//____________________________________________________________________________//signal_action::~signal_action(){ if( m_installed ) ::sigaction( m_sig, &m_old_action , sigaction_ptr() );}//____________________________________________________________________________//// ************************************************************************** //// ************** boost::detail::signal_handler ************** //// ************************************************************************** //class signal_handler {public: // Constructor explicit signal_handler( bool catch_system_errors, int timeout, bool attach_dbg, char* alt_stack ); // Destructor ~signal_handler(); // access methods static sigjmp_buf& jump_buffer() { assert( !!s_active_handler ); return s_active_handler->m_sigjmp_buf; } static system_signal_exception& sys_sig() { assert( !!s_active_handler ); return s_active_handler->m_sys_sig; }private: // Data members signal_handler* m_prev_handler; int m_timeout; signal_action m_ILL_action; signal_action m_FPE_action; signal_action m_SEGV_action; signal_action m_BUS_action; signal_action m_CHLD_action;#ifdef BOOST_TEST_CATCH_SIGPOLL signal_action m_POLL_action;#endif signal_action m_ABRT_action; signal_action m_ALRM_action; sigjmp_buf m_sigjmp_buf; system_signal_exception m_sys_sig; static signal_handler* s_active_handler;};// !! need to be placed in thread specific storagetypedef signal_handler* signal_handler_ptr;signal_handler* signal_handler::s_active_handler = signal_handler_ptr();//____________________________________________________________________________//signal_handler::signal_handler( bool catch_system_errors, int timeout, bool attach_dbg, char* alt_stack ): m_prev_handler( s_active_handler ), m_timeout( timeout ), m_ILL_action ( SIGILL , catch_system_errors, attach_dbg, alt_stack ), m_FPE_action ( SIGFPE , catch_system_errors, attach_dbg, alt_stack ), m_SEGV_action( SIGSEGV, catch_system_errors, attach_dbg, alt_stack ), m_BUS_action ( SIGBUS , catch_system_errors, attach_dbg, alt_stack ), m_CHLD_action( SIGCHLD, catch_system_errors, attach_dbg, alt_stack )#ifdef BOOST_TEST_CATCH_SIGPOLL, m_POLL_action( SIGPOLL, catch_system_errors, attach_dbg, alt_stack )#endif, m_ABRT_action( SIGABRT, catch_system_errors, attach_dbg, alt_stack ), m_ALRM_action( SIGALRM, timeout > 0 , attach_dbg, alt_stack ){ s_active_handler = this; if( m_timeout > 0 ) { ::alarm( 0 ); ::alarm( timeout ); }#ifdef BOOST_TEST_USE_ALT_STACK if( alt_stack ) { stack_t sigstk; std::memset( &sigstk, 0, sizeof(stack_t) ); BOOST_TEST_SYS_ASSERT( ::sigaltstack( 0, &sigstk ) != -1 ); if( sigstk.ss_flags & SS_DISABLE ) { sigstk.ss_sp = alt_stack; sigstk.ss_size = BOOST_TEST_ALT_STACK_SIZE; sigstk.ss_flags = 0; BOOST_TEST_SYS_ASSERT( ::sigaltstack( &sigstk, 0 ) != -1 ); } }#endif}//____________________________________________________________________________//signal_handler::~signal_handler(){ assert( s_active_handler == this ); if( m_timeout > 0 ) ::alarm( 0 );#ifdef BOOST_TEST_USE_ALT_STACK stack_t sigstk = {}; sigstk.ss_size = MINSIGSTKSZ; sigstk.ss_flags = SS_DISABLE; BOOST_TEST_SYS_ASSERT( ::sigaltstack( &sigstk, 0 ) != -1 );#endif s_active_handler = m_prev_handler;}//____________________________________________________________________________//// ************************************************************************** //// ************** execution_monitor_signal_handler ************** //// ************************************************************************** //extern "C" {static bool ignore_sigchild( siginfo_t* info ){ return info->si_signo == SIGCHLD && info->si_code == CLD_EXITED #ifdef BOOST_TEST_IGNORE_NON_ZERO_CHILD_CODE ;#else && (int)info->si_status == 0;#endif}//____________________________________________________________________________//static void execution_monitor_jumping_signal_handler( int sig, siginfo_t* info, void* context ){ if( ignore_sigchild( info ) ) return; signal_handler::sys_sig()( info, context ); siglongjmp( signal_handler::jump_buffer(), sig );}//____________________________________________________________________________//static void execution_monitor_attaching_signal_handler( int sig, siginfo_t* info, void* context ){ if( ignore_sigchild( info ) ) return; if( !debug::attach_debugger( false ) ) execution_monitor_jumping_signal_handler( sig, info, context ); // debugger attached; it will handle the signal BOOST_TEST_SYS_ASSERT( ::signal( sig, SIG_DFL ) != SIG_ERR );}//____________________________________________________________________________//}} // namespace detail// ************************************************************************** //// ************** execution_monitor::catch_signals ************** //// ************************************************************************** //intexecution_monitor::catch_signals( unit_test::callback0<int> const& F ){ using namespace detail;#if defined(__CYGWIN__) p_catch_system_errors.value = false;#endif#ifdef BOOST_TEST_USE_ALT_STACK if( !!p_use_alt_stack && !m_alt_stack ) m_alt_stack.reset( new char[BOOST_TEST_ALT_STACK_SIZE] );#else p_use_alt_stack.value = false;#endif signal_handler local_signal_handler( p_catch_system_errors, p_timeout, p_auto_start_dbg, !p_use_alt_stack ? 0 : m_alt_stack.get() ); if( !sigsetjmp( signal_handler::jump_buffer(), 1 ) ) return detail::do_invoke( m_custom_translators , F ); else throw local_signal_handler.sys_sig();}//____________________________________________________________________________//#elif defined(BOOST_SEH_BASED_SIGNAL_HANDLING)// ************************************************************************** //// ************** Microsoft structured exception handling ************** //// ************************************************************************** //#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x0564))namespace { void _set_se_translator( void* ) {} }#endifnamespace detail {// ************************************************************************** //// ************** boost::detail::system_signal_exception ************** //// ************************************************************************** //class system_signal_exception {public: // Constructor explicit system_signal_exception( execution_monitor* em ) : m_em( em ) , m_se_id( 0 ) , m_fault_address( 0 ) , m_dir( false )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -