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