欢迎来到虫虫下载站 | 资源下载 资源专辑 关于我们
虫虫下载站

execution_monitor.ipp

Boost provides free peer-reviewed portable C++ source libraries. We emphasize libraries that work
IPP
第 1 页 / 共 3 页
字号:
//  (C) Copyright Gennadiy Rozental 2001-2008.//  (C) Copyright Beman Dawes and Ullrich Koethe 1995-2001.//  Use, modification, and distribution are subject to the//  Boost Software License, Version 1.0. (See accompanying file//  http://www.boost.org/LICENSE_1_0.txt)//  See http://www.boost.org/libs/test for the library home page.////  File        : $RCSfile$////  Version     : $Revision: 49312 $////  Description : provides execution monitor implementation for all supported//  configurations, including Microsoft structured exception based, unix signals//  based and special workarounds for borland////  Note that when testing requirements or user wishes preclude use of this//  file as a separate compilation unit, it may be included as a header file.////  Header dependencies are deliberately restricted to reduce coupling to other//  boost libraries.// ***************************************************************************#ifndef BOOST_TEST_EXECUTION_MONITOR_IPP_012205GER#define BOOST_TEST_EXECUTION_MONITOR_IPP_012205GER// Boost.Test#include <boost/test/detail/config.hpp>#include <boost/test/detail/workaround.hpp>#include <boost/test/execution_monitor.hpp>#include <boost/test/debug.hpp>// Boost#include <boost/cstdlib.hpp>    // for exit codes#include <boost/config.hpp>     // for workarounds// STL#include <string>               // for std::string#include <new>                  // for std::bad_alloc#include <typeinfo>             // for std::bad_cast, std::bad_typeid#include <exception>            // for std::exception, std::bad_exception#include <stdexcept>            // for std exception hierarchy#include <cstring>              // for C string API#include <cassert>              // for assert#include <cstddef>              // for NULL#include <cstdio>               // for vsnprintf#include <cstdarg>              // for varargs#ifdef BOOST_NO_STDC_NAMESPACEnamespace std { using ::strerror; using ::strlen; using ::strncat; }#endif// to use vsnprintf#if defined(__SUNPRO_CC) || defined(__SunOS)#  include <stdio.h>#  include <stdarg.h>using std::va_list;#endif// to use vsnprintf #if defined(__QNXNTO__) #  include <stdio.h> #endif#if defined(_WIN32) && !defined(BOOST_DISABLE_WIN32) &&                  \    (!defined(__COMO__) && !defined(__MWERKS__) && !defined(__GNUC__) || \     BOOST_WORKAROUND(__MWERKS__, >= 0x3000))#  define BOOST_SEH_BASED_SIGNAL_HANDLING#  include <windows.h>#  if defined(__MWERKS__) || (defined(_MSC_VER) && !defined(UNDER_CE))#    include <eh.h>#  endif#  if defined(__BORLANDC__) && __BORLANDC__ >= 0x560 || defined(__MWERKS__)#    include <stdint.h>#  endif#  if defined(__BORLANDC__) && __BORLANDC__ < 0x560    typedef unsigned uintptr_t;#  endif#  if BOOST_WORKAROUND(_MSC_VER,  < 1300 ) || defined(UNDER_CE)typedef void* uintptr_t;#  endif// for the FP control routines#include <float.h>#ifndef EM_INVALID#define EM_INVALID _EM_INVALID#endif#ifndef EM_DENORMAL#define EM_DENORMAL _EM_DENORMAL#endif#ifndef EM_ZERODIVIDE#define EM_ZERODIVIDE _EM_ZERODIVIDE#endif#ifndef EM_OVERFLOW#define EM_OVERFLOW _EM_OVERFLOW#endif#ifndef EM_UNDERFLOW#define EM_UNDERFLOW _EM_UNDERFLOW#endif#ifndef MCW_EM#define MCW_EM _MCW_EM#endif#  if !defined(NDEBUG) && defined(_MSC_VER) && !defined(UNDER_CE)#    define BOOST_TEST_USE_DEBUG_MS_CRT#    include <crtdbg.h>#  endif#  if !BOOST_WORKAROUND(_MSC_VER,  >= 1400 ) || defined(UNDER_CE)typedef void* _invalid_parameter_handler;inline _invalid_parameter_handler_set_invalid_parameter_handler( _invalid_parameter_handler arg ){    return arg;}#  endif#  if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x0564)) || defined(UNDER_CE)namespace { void _set_se_translator( void* ) {} }#  endif#elif defined(BOOST_HAS_SIGACTION)#  define BOOST_SIGACTION_BASED_SIGNAL_HANDLING#  include <unistd.h>#  include <signal.h>#  include <setjmp.h>#  if !defined(__CYGWIN__) && !defined(__QNXNTO__)#   define BOOST_TEST_USE_ALT_STACK#  endif#  if defined(SIGPOLL) && !defined(__CYGWIN__)                              && \      !(defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__))  && \      !defined(__NetBSD__)                                                  && \      !defined(__QNXNTO__)#    define BOOST_TEST_CATCH_SIGPOLL#  endif#  ifdef BOOST_TEST_USE_ALT_STACK#    define BOOST_TEST_ALT_STACK_SIZE SIGSTKSZ#  endif#else#  define BOOST_NO_SIGNAL_HANDLING#endif#ifndef UNDER_CE#include <errno.h>#endif#include <boost/test/detail/suppress_warnings.hpp>//____________________________________________________________________________//namespace boost {// ************************************************************************** //// **************                  report_error                ************** //// ************************************************************************** //namespace detail {#ifdef __BORLANDC__#  define BOOST_TEST_VSNPRINTF( a1, a2, a3, a4 ) std::vsnprintf( (a1), (a2), (a3), (a4) )#elif BOOST_WORKAROUND(_MSC_VER, <= 1310) || \      BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3000)) || \      defined(UNDER_CE)#  define BOOST_TEST_VSNPRINTF( a1, a2, a3, a4 ) _vsnprintf( (a1), (a2), (a3), (a4) )#else#  define BOOST_TEST_VSNPRINTF( a1, a2, a3, a4 ) vsnprintf( (a1), (a2), (a3), (a4) )#endifstatic voidreport_error( execution_exception::error_code ec, char const* format, ... ){    static const int REPORT_ERROR_BUFFER_SIZE = 512;    static char buf[REPORT_ERROR_BUFFER_SIZE];    va_list args;    va_start( args, format );    BOOST_TEST_VSNPRINTF( buf, sizeof(buf), format, args );    va_end( args );    throw execution_exception( ec, buf );}//____________________________________________________________________________//template<typename Tr,typename Functor>inline intdo_invoke( Tr const& tr, Functor const& F ){    return tr ? (*tr)( F ) : F();}//____________________________________________________________________________//} // namespace detail#if defined(BOOST_SIGACTION_BASED_SIGNAL_HANDLING)// ************************************************************************** //// **************       Sigaction based signal handling        ************** //// ************************************************************************** //namespace detail {// ************************************************************************** //// **************    boost::detail::system_signal_exception    ************** //// ************************************************************************** //class system_signal_exception {public:    // Constructor    system_signal_exception()    : m_sig_info( 0 )    , m_context( 0 )    {}    // Access methods    void        operator()( siginfo_t* i, void* c )    {        m_sig_info  = i;        m_context   = c;    }    void        report() const;private:    // Data members    siginfo_t*  m_sig_info; // system signal detailed info    void*       m_context;  // signal context};//____________________________________________________________________________//voidsystem_signal_exception::report() const{    if( !m_sig_info )        return; // no error actually occur?    switch( m_sig_info->si_code ) {    case SI_USER:        report_error( execution_exception::system_error,                      "signal: generated by kill() (or family); uid=%d; pid=%d",                      (int)m_sig_info->si_uid, (int)m_sig_info->si_pid );        break;    case SI_QUEUE:        report_error( execution_exception::system_error,                      "signal: sent by sigqueue()" );        break;    case SI_TIMER:        report_error( execution_exception::system_error,                      "signal: the expiration of a timer set by timer_settimer()" );        break;    case SI_ASYNCIO:        report_error( execution_exception::system_error,                      "signal: generated by the completion of an asynchronous I/O request" );        break;    case SI_MESGQ:        report_error( execution_exception::system_error,                      "signal: generated by the the arrival of a message on an empty message queue" );        break;    default:        break;    }    switch( m_sig_info->si_signo ) {    case SIGILL:        switch( m_sig_info->si_code ) {        case ILL_ILLOPC:            report_error( execution_exception::system_fatal_error,                          "signal: illegal opcode; address of failing instruction: 0x%08lx",                          m_sig_info->si_addr );            break;        case ILL_ILLOPN:            report_error( execution_exception::system_fatal_error,                          "signal: illegal operand; address of failing instruction: 0x%08lx",                          m_sig_info->si_addr );            break;        case ILL_ILLADR:            report_error( execution_exception::system_fatal_error,                          "signal: illegal addressing mode; address of failing instruction: 0x%08lx",                          m_sig_info->si_addr );            break;        case ILL_ILLTRP:            report_error( execution_exception::system_fatal_error,                          "signal: illegal trap; address of failing instruction: 0x%08lx",                          m_sig_info->si_addr );            break;        case ILL_PRVOPC:            report_error( execution_exception::system_fatal_error,                          "signal: privileged opcode; address of failing instruction: 0x%08lx",                          m_sig_info->si_addr );            break;        case ILL_PRVREG:            report_error( execution_exception::system_fatal_error,                          "signal: privileged register; address of failing instruction: 0x%08lx",                          m_sig_info->si_addr );            break;        case ILL_COPROC:            report_error( execution_exception::system_fatal_error,                          "signal: co-processor error; address of failing instruction: 0x%08lx",                          m_sig_info->si_addr );            break;        case ILL_BADSTK:            report_error( execution_exception::system_fatal_error,                          "signal: internal stack error; address of failing instruction: 0x%08lx",                          m_sig_info->si_addr );            break;        }        break;    case SIGFPE:        switch( m_sig_info->si_code ) {        case FPE_INTDIV:            report_error( execution_exception::system_error,                          "signal: integer divide by zero; address of failing instruction: 0x%08lx",                          m_sig_info->si_addr );            break;        case FPE_INTOVF:            report_error( execution_exception::system_error,                          "signal: integer overflow; address of failing instruction: 0x%08lx",                          m_sig_info->si_addr );            break;        case FPE_FLTDIV:            report_error( execution_exception::system_error,                          "signal: floating point divide by zero; address of failing instruction: 0x%08lx",                          m_sig_info->si_addr );            break;        case FPE_FLTOVF:            report_error( execution_exception::system_error,                          "signal: floating point overflow; address of failing instruction: 0x%08lx",                          m_sig_info->si_addr );            break;        case FPE_FLTUND:            report_error( execution_exception::system_error,                          "signal: floating point underflow; address of failing instruction: 0x%08lx",                          m_sig_info->si_addr );            break;        case FPE_FLTRES:            report_error( execution_exception::system_error,                          "signal: floating point inexact result; address of failing instruction: 0x%08lx",                          m_sig_info->si_addr );            break;        case FPE_FLTINV:            report_error( execution_exception::system_error,                          "signal: invalid floating point operation; address of failing instruction: 0x%08lx",                          m_sig_info->si_addr );            break;        case FPE_FLTSUB:            report_error( execution_exception::system_error,                          "signal: subscript out of range; address of failing instruction: 0x%08lx",                          m_sig_info->si_addr );            break;        }        break;    case SIGSEGV:        switch( m_sig_info->si_code ) {        case SEGV_MAPERR:            report_error( execution_exception::system_fatal_error,                          "memory access violation at address: 0x%08lx: no mapping at fault address",                          m_sig_info->si_addr );            break;        case SEGV_ACCERR:            report_error( execution_exception::system_fatal_error,                          "memory access violation at address: 0x%08lx: invalid permissions",                          m_sig_info->si_addr );            break;        }        break;    case SIGBUS:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -