50 lines
1004 B
C++
50 lines
1004 B
C++
#include "precompile.h"
|
|
|
|
#include "tracemgr.h"
|
|
|
|
#ifdef DEBUG
|
|
|
|
static void ErrorCallback(void *data, const char *msg, int errnum)
|
|
{
|
|
abort();
|
|
}
|
|
|
|
static int SimpleCallback(void *data, uintptr_t pc)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
void TraceMgr::Init(const std::string& filename)
|
|
{
|
|
filename_ = filename;
|
|
state_ = backtrace_create_state(filename_.c_str(),
|
|
0,
|
|
ErrorCallback,
|
|
nullptr);
|
|
if (!state_) {
|
|
abort();
|
|
}
|
|
log_file_ = fopen("backtrace.log", "w");
|
|
if (!log_file_) {
|
|
abort();
|
|
}
|
|
}
|
|
|
|
void TraceMgr::UnInit()
|
|
{
|
|
if (log_file_) {
|
|
fclose(log_file_);
|
|
log_file_ = nullptr;
|
|
}
|
|
}
|
|
|
|
void TraceMgr::Trace(const std::string& hint)
|
|
{
|
|
fputs(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n", log_file_);
|
|
fputs(hint.c_str(), log_file_);
|
|
backtrace_print(state_, 0, log_file_);
|
|
fputs("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n", log_file_);
|
|
}
|
|
|
|
#endif
|