This commit is contained in:
aozhiwei 2022-10-01 08:06:20 +08:00
parent fbf50878bf
commit 58f14b7107
2 changed files with 24 additions and 0 deletions

View File

@ -1,5 +1,7 @@
#include "precompile.h"
#include <execinfo.h>
#include "tracemgr.h"
#ifdef DEBUG
@ -47,4 +49,25 @@ void TraceMgr::Trace(const std::string& hint)
#endif
}
std::string TraceMgr::GetBackTrace()
{
const int BT_BUF_SIZE = 1024 * 10;
std::string data;
void *buffer[BT_BUF_SIZE];
char **strings = nullptr;
int nptrs = backtrace(buffer, BT_BUF_SIZE);
strings = backtrace_symbols(buffer, nptrs);
if (strings) {
for (int i = 0; i < nptrs; i++) {
data += strings[i];
data += "\n";
}
free(strings);
}
return data;
}
#endif

View File

@ -19,6 +19,7 @@ class TraceMgr : public a8::Singleton<TraceMgr>
void UnInit();
void Trace(const std::string& hint);
std::string GetBackTrace();
private:
std::string filename_;