diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2015-05-27 13:48:45 +0100 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2015-05-27 13:48:45 +0100 |
| commit | 7245d2abe907b11bfa67c4ea0059ab00b34b5bc9 (patch) | |
| tree | adeaababe327ba7edaa275a17d9e7de6208e97e9 /src/safe_ptr.cc | |
| parent | 4a588d6ce5065c698f8a455f7e8025b56a23cd14 (diff) | |
Extract Backtrace out of SafePtr as a general utility
Diffstat (limited to 'src/safe_ptr.cc')
| -rw-r--r-- | src/safe_ptr.cc | 60 |
1 files changed, 0 insertions, 60 deletions
diff --git a/src/safe_ptr.cc b/src/safe_ptr.cc deleted file mode 100644 index c4d5f485..00000000 --- a/src/safe_ptr.cc +++ /dev/null @@ -1,60 +0,0 @@ -#include "safe_ptr.hh" - -#ifdef SAFE_PTR_TRACK_CALLSTACKS - -#include <string.h> - -#if defined(__linux__) -# include <execinfo.h> -#elif defined(__CYGWIN__) -# include <windows.h> -#endif - - -namespace Kakoune -{ - - -SafeCountable::Backtrace::Backtrace() -{ - #if defined(__linux__) - num_frames = backtrace(stackframes, max_frames); - #elif defined(__CYGWIN__) - num_frames = CaptureStackBackTrace(0, max_frames, stackframes, nullptr); - #endif -} - -const char* SafeCountable::Backtrace::desc() const -{ - #if defined(__linux__) - char** symbols = backtrace_symbols(stackframes, num_frames); - int size = 0; - for (int i = 0; i < num_frames; ++i) - size += strlen(symbols[i]) + 1; - - char* res = (char*)malloc(size+1); - res[0] = 0; - for (int i = 0; i < num_frames; ++i) - { - strcat(res, symbols[i]); - strcat(res, "\n"); - } - free(symbols); - return res; - #elif defined(__CYGWIN__) - char* res = (char*)malloc(num_frames * 20); - res[0] = 0; - for (int i = 0; i < num_frames; ++i) - { - char addr[20]; - snprintf(addr, 20, "0x%p", stackframes[i]); - strcat(res, addr); - } - return res; - #else - return "<not implemented>"; - #endif -} - -} -#endif |
