1
This commit is contained in:
parent
9593a04aa3
commit
0535045139
@ -4,19 +4,17 @@
|
|||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
|
||||||
|
#if __GNUC__ > 4
|
||||||
static void ErrorCallback(void *data, const char *msg, int errnum)
|
static void ErrorCallback(void *data, const char *msg, int errnum)
|
||||||
{
|
{
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
static int SimpleCallback(void *data, uintptr_t pc)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TraceMgr::Init(const std::string& filename)
|
void TraceMgr::Init(const std::string& filename)
|
||||||
{
|
{
|
||||||
filename_ = filename;
|
filename_ = filename;
|
||||||
|
#if __GNUC__ > 4
|
||||||
state_ = backtrace_create_state(filename_.c_str(),
|
state_ = backtrace_create_state(filename_.c_str(),
|
||||||
0,
|
0,
|
||||||
ErrorCallback,
|
ErrorCallback,
|
||||||
@ -24,6 +22,7 @@ void TraceMgr::Init(const std::string& filename)
|
|||||||
if (!state_) {
|
if (!state_) {
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
log_file_ = fopen("backtrace.log", "w");
|
log_file_ = fopen("backtrace.log", "w");
|
||||||
if (!log_file_) {
|
if (!log_file_) {
|
||||||
abort();
|
abort();
|
||||||
@ -40,10 +39,12 @@ void TraceMgr::UnInit()
|
|||||||
|
|
||||||
void TraceMgr::Trace(const std::string& hint)
|
void TraceMgr::Trace(const std::string& hint)
|
||||||
{
|
{
|
||||||
|
#if __GNUC__ > 4
|
||||||
fputs(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n", log_file_);
|
fputs(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n", log_file_);
|
||||||
fputs(hint.c_str(), log_file_);
|
fputs(hint.c_str(), log_file_);
|
||||||
backtrace_print(state_, 0, log_file_);
|
backtrace_print(state_, 0, log_file_);
|
||||||
fputs("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n", log_file_);
|
fputs("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n", log_file_);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -2,7 +2,9 @@
|
|||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
|
||||||
|
#if __GNUC__ > 4
|
||||||
#include <backtrace.h>
|
#include <backtrace.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
class TraceMgr : public a8::Singleton<TraceMgr>
|
class TraceMgr : public a8::Singleton<TraceMgr>
|
||||||
{
|
{
|
||||||
@ -20,7 +22,9 @@ class TraceMgr : public a8::Singleton<TraceMgr>
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
std::string filename_;
|
std::string filename_;
|
||||||
|
#if __GNUC__ > 4
|
||||||
backtrace_state* state_ = nullptr;
|
backtrace_state* state_ = nullptr;
|
||||||
|
#endif
|
||||||
FILE* log_file_ = nullptr;
|
FILE* log_file_ = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user