123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- #ifndef IVBACKTRACE_H
- #define IVBACKTRACE_H
- #include <QtCore/qglobal.h>
- #if defined(IVBACKTRACE_LIBRARY)
- # define IVBACKTRACE_EXPORT Q_DECL_EXPORT
- #else
- # define IVBACKTRACE_EXPORT Q_DECL_IMPORT
- #endif
- #ifndef USE_BOOSTBACKTRACE
- void RegisterIVBackTrace();
- #else
- #ifdef Q_OS_LINUX
- #ifndef BOOST_STACKTRACE_USE_BACKTRACE
- #define BOOST_STACKTRACE_USE_BACKTRACE
- #endif
- #endif
- #include <string>
- #include <boost/noncopyable.hpp>
- #include <boost/function.hpp>
- #include <boost/stacktrace.hpp>
- #include <signal.h> // ::signal, ::raise
- #include <stdexcept> // std::logic_error
- #include <iostream> // std::cerr
- #include <boost/filesystem.hpp>
- #include <strstream>
- #include <iostream>
- #include <QFile>
- #include <QDateTime>
- #include <QDir>
- void x_signal_handler(int signum) {
- ::signal(signum, SIG_DFL);
- std::ostrstream ostr;
- ostr<<boost::stacktrace::stacktrace()<<std::endl;
- char strpath[1024];
- QDateTime dt = QDateTime::currentDateTime();
- char path[1000];
- char processname[1024];
- snprintf(strpath,255,"%s/log/%s-%d-%s.log",getenv("HOME"),processname, getpid(),dt.toString("yyyyMMddhhmmsszzz").toLatin1().data());
- char strdir[1024];
- snprintf(strdir,255,"%s/log",getenv("HOME"));
- QDir xdir;
- xdir.setPath(strdir);
- if(!xdir.exists())
- {
- qDebug("create dir %s",strdir);
- xdir.mkdir(strdir);
- }
- QFile xFile;
- xFile.setFileName(strpath);
- if(xFile.open(QIODevice::ReadWrite))
- {
- xFile.write(ostr.str());
- }
- else
- {
- std::cout<<ostr.str()<<std::endl;
- }
- xFile.close();
- ::raise(SIGABRT);
- }
- void RegisterIVBackTrace()
- {
- std::ostrstream ostr;
- ostr << boost::stacktrace::stacktrace()<<std::endl;
- ::signal(SIGSEGV, &x_signal_handler);
- }
- #endif
- #endif
|