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 | |
| parent | 4a588d6ce5065c698f8a455f7e8025b56a23cd14 (diff) | |
Extract Backtrace out of SafePtr as a general utility
Diffstat (limited to 'src')
| -rw-r--r-- | src/backtrace.cc (renamed from src/safe_ptr.cc) | 18 | ||||
| -rw-r--r-- | src/backtrace.hh | 20 | ||||
| -rw-r--r-- | src/safe_ptr.hh | 11 |
3 files changed, 28 insertions, 21 deletions
diff --git a/src/safe_ptr.cc b/src/backtrace.cc index c4d5f485..f7be9f76 100644 --- a/src/safe_ptr.cc +++ b/src/backtrace.cc @@ -1,32 +1,29 @@ -#include "safe_ptr.hh" - -#ifdef SAFE_PTR_TRACK_CALLSTACKS +#include "backtrace.hh" #include <string.h> +#include <stdlib.h> -#if defined(__linux__) +#if defined(__linux__) || defined(__APPLE__) # include <execinfo.h> #elif defined(__CYGWIN__) # include <windows.h> #endif - namespace Kakoune { - -SafeCountable::Backtrace::Backtrace() +Backtrace::Backtrace() { - #if defined(__linux__) + #if defined(__linux__) || defined(__APPLE__) num_frames = backtrace(stackframes, max_frames); #elif defined(__CYGWIN__) num_frames = CaptureStackBackTrace(0, max_frames, stackframes, nullptr); #endif } -const char* SafeCountable::Backtrace::desc() const +const char* Backtrace::desc() const { - #if defined(__linux__) + #if defined(__linux__) || defined(__APPLE__) char** symbols = backtrace_symbols(stackframes, num_frames); int size = 0; for (int i = 0; i < num_frames; ++i) @@ -57,4 +54,3 @@ const char* SafeCountable::Backtrace::desc() const } } -#endif diff --git a/src/backtrace.hh b/src/backtrace.hh new file mode 100644 index 00000000..5eca8827 --- /dev/null +++ b/src/backtrace.hh @@ -0,0 +1,20 @@ +#ifndef backtrace_hh_INCLUDED +#define backtrace_hh_INCLUDED + +namespace Kakoune +{ + +struct Backtrace +{ + static constexpr int max_frames = 16; + void* stackframes[max_frames]; + int num_frames = 0; + + Backtrace(); + const char* desc() const; +}; + +} + +#endif // backtrace_hh_INCLUDED + diff --git a/src/safe_ptr.hh b/src/safe_ptr.hh index 2e3b3d2b..a5e11ab6 100644 --- a/src/safe_ptr.hh +++ b/src/safe_ptr.hh @@ -5,6 +5,7 @@ #include "assert.hh" #include "ref_ptr.hh" +#include "backtrace.hh" #include <type_traits> #include <utility> @@ -64,16 +65,6 @@ public: private: #ifdef SAFE_PTR_TRACK_CALLSTACKS - struct Backtrace - { - static constexpr int max_frames = 16; - void* stackframes[max_frames]; - int num_frames = 0; - - Backtrace(); - const char* desc() const; - }; - struct Callstack { Callstack(void* p) : ptr(p) {} |
