From e4f18c177161466d28e357bcfc5ad946c6f7634a Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Mon, 8 Apr 2019 00:35:00 +0200 Subject: [PATCH] NO-OP: whitespace & revert samples -> [stack]frames --- libs/pbd/pbd/stacktrace.h | 96 +++++++++++++++++++-------------------- libs/pbd/stacktrace.cc | 36 +++++++-------- 2 files changed, 65 insertions(+), 67 deletions(-) diff --git a/libs/pbd/pbd/stacktrace.h b/libs/pbd/pbd/stacktrace.h index 99fc9d5c57..bf0c20867a 100644 --- a/libs/pbd/pbd/stacktrace.h +++ b/libs/pbd/pbd/stacktrace.h @@ -45,71 +45,71 @@ namespace PBD { template class /*LIBPBD_API*/ thing_with_backtrace { - public: - thing_with_backtrace () { - trace_twb(); +public: + thing_with_backtrace () { + trace_twb(); #ifdef HAVE_EXECINFO - allocation_backtrace = new void*[50]; - allocation_backtrace_size = backtrace (allocation_backtrace, 50); + allocation_backtrace = new void*[50]; + allocation_backtrace_size = backtrace (allocation_backtrace, 50); #else - allocation_backtrace_size = 0; + allocation_backtrace_size = 0; #endif - Glib::Threads::Mutex::Lock lm (all_mutex); - all.push_back (this); - } + Glib::Threads::Mutex::Lock lm (all_mutex); + all.push_back (this); + } - thing_with_backtrace (const thing_with_backtrace& other) { - trace_twb(); + thing_with_backtrace (const thing_with_backtrace& other) { + trace_twb(); #ifdef HAVE_EXECINFO - allocation_backtrace = new void*[50]; - allocation_backtrace_size = backtrace (allocation_backtrace, 50); + allocation_backtrace = new void*[50]; + allocation_backtrace_size = backtrace (allocation_backtrace, 50); #else - allocation_backtrace_size = 0; + allocation_backtrace_size = 0; #endif - Glib::Threads::Mutex::Lock lm (all_mutex); - all.push_back (this); - } + Glib::Threads::Mutex::Lock lm (all_mutex); + all.push_back (this); + } - ~thing_with_backtrace() { - if (allocation_backtrace_size) { - delete [] allocation_backtrace; - } - Glib::Threads::Mutex::Lock lm (all_mutex); - all.remove (this); - } + ~thing_with_backtrace() { + if (allocation_backtrace_size) { + delete [] allocation_backtrace; + } + Glib::Threads::Mutex::Lock lm (all_mutex); + all.remove (this); + } - thing_with_backtrace& operator= (const thing_with_backtrace& other) { - /* no copyable members */ - return *this; - } + thing_with_backtrace& operator= (const thing_with_backtrace& other) { + /* no copyable members */ + return *this; + } - static void peek_a_boo (std::ostream& stream) { + static void peek_a_boo (std::ostream& stream) { #ifdef HAVE_EXECINFO - typename std::list*>::iterator x; - for (x = all.begin(); x != all.end(); ++x) { - char **strings; - size_t i; + typename std::list*>::iterator x; + for (x = all.begin(); x != all.end(); ++x) { + char **strings; + size_t i; - strings = backtrace_symbols ((*x)->allocation_backtrace, (*x)->allocation_backtrace_size); + strings = backtrace_symbols ((*x)->allocation_backtrace, (*x)->allocation_backtrace_size); - if (strings) { - stream << "--- ALLOCATED SHARED_PTR @ " << (*x) << std::endl; - for (i = 0; i < (*x)->allocation_backtrace_size && i < 50U; i++) { - stream << strings[i] << std::endl; - } - free (strings); - } - } + if (strings) { + stream << "--- ALLOCATED SHARED_PTR @ " << (*x) << std::endl; + for (i = 0; i < (*x)->allocation_backtrace_size && i < 50U; i++) { + stream << strings[i] << std::endl; + } + free (strings); + } + } #else - stream << "execinfo not defined for this platform" << std::endl; + stream << "execinfo not defined for this platform" << std::endl; #endif - } + } private: - void** allocation_backtrace; - int allocation_backtrace_size; - static std::list* > all; - static Glib::Threads::Mutex all_mutex; + void** allocation_backtrace; + int allocation_backtrace_size; + static std::list* > all; + static Glib::Threads::Mutex all_mutex; }; template /*LIBPBD_API*/ std::list *> PBD::thing_with_backtrace::all; diff --git a/libs/pbd/stacktrace.cc b/libs/pbd/stacktrace.cc index 3b308f7db2..a1af1585dd 100644 --- a/libs/pbd/stacktrace.cc +++ b/libs/pbd/stacktrace.cc @@ -77,48 +77,46 @@ PBD::stacktrace (std::ostream& out, int levels) #define CaptureStackBackTrace RtlCaptureStackBackTrace extern "C" { - __declspec(dllimport) USHORT WINAPI CaptureStackBackTrace ( - ULONG SamplesToSkip, - ULONG SamplesToCapture, - PVOID *BackTrace, - PULONG BackTraceHash - ); + __declspec(dllimport) USHORT WINAPI CaptureStackBackTrace ( + ULONG FramesToSkip, + ULONG FramesToCapture, + PVOID *BackTrace, + PULONG BackTraceHash); } #endif void -PBD::stacktrace( std::ostream& out, int) +PBD::stacktrace (std::ostream& out, int) { #ifdef DEBUG const size_t levels = 62; // does not support more then 62 levels of stacktrace unsigned int i; void * stack[ levels ]; - unsigned short samples; + unsigned short frames; SYMBOL_INFO * symbol; HANDLE process; process = GetCurrentProcess(); out << "+++++Backtrace process: " << DEBUG_THREAD_SELF << std::endl; - SymInitialize( process, NULL, TRUE ); + SymInitialize (process, NULL, TRUE); - samples = CaptureStackBackTrace( 0, levels, stack, NULL ); + frames = CaptureStackBackTrace (0, levels, stack, NULL); - out << "+++++Backtrace samples: " << samples << std::endl; + out << "+++++Backtrace frames: " << frames << std::endl; - symbol = ( SYMBOL_INFO * )calloc( sizeof( SYMBOL_INFO ) + 256 * sizeof( char ), 1 ); + symbol = (SYMBOL_INFO*)calloc (sizeof (SYMBOL_INFO) + 256 * sizeof (char), 1); symbol->MaxNameLen = 255; - symbol->SizeOfStruct = sizeof( SYMBOL_INFO ); + symbol->SizeOfStruct = sizeof (SYMBOL_INFO); - for( i = 0; i < samples; i++ ) - { - SymFromAddr( process, ( DWORD64 )( stack[ i ] ), 0, symbol ); - out << string_compose( "%1: %2 - %3\n", samples - i - 1, symbol->Name, symbol->Address ); + for (i = 0; i < frames; ++i) { + SymFromAddr (process, (DWORD64)(stack[i]), 0, symbol); + out << string_compose ("%1: %2 - %3\n", samples - i - 1, symbol->Name, symbol->Address); } - out.flush(); + out.flush (); - free( symbol ); + free (symbol); #endif }