diff --git a/src/safe_ptr.cc b/src/backtrace.cc similarity index 80% rename from src/safe_ptr.cc rename to 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 +#include -#if defined(__linux__) +#if defined(__linux__) || defined(__APPLE__) # include #elif defined(__CYGWIN__) # include #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 #include @@ -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) {}