NO-OP: whitespace & revert samples -> [stack]frames

This commit is contained in:
Robin Gareus 2019-04-08 00:35:00 +02:00
parent eeb2cddd26
commit e4f18c1771
No known key found for this signature in database
GPG key ID: A090BCE02CF57F04
2 changed files with 65 additions and 67 deletions

View file

@ -45,71 +45,71 @@ namespace PBD {
template<typename T> template<typename T>
class /*LIBPBD_API*/ thing_with_backtrace class /*LIBPBD_API*/ thing_with_backtrace
{ {
public: public:
thing_with_backtrace () { thing_with_backtrace () {
trace_twb(); trace_twb();
#ifdef HAVE_EXECINFO #ifdef HAVE_EXECINFO
allocation_backtrace = new void*[50]; allocation_backtrace = new void*[50];
allocation_backtrace_size = backtrace (allocation_backtrace, 50); allocation_backtrace_size = backtrace (allocation_backtrace, 50);
#else #else
allocation_backtrace_size = 0; allocation_backtrace_size = 0;
#endif #endif
Glib::Threads::Mutex::Lock lm (all_mutex); Glib::Threads::Mutex::Lock lm (all_mutex);
all.push_back (this); all.push_back (this);
} }
thing_with_backtrace (const thing_with_backtrace<T>& other) { thing_with_backtrace (const thing_with_backtrace<T>& other) {
trace_twb(); trace_twb();
#ifdef HAVE_EXECINFO #ifdef HAVE_EXECINFO
allocation_backtrace = new void*[50]; allocation_backtrace = new void*[50];
allocation_backtrace_size = backtrace (allocation_backtrace, 50); allocation_backtrace_size = backtrace (allocation_backtrace, 50);
#else #else
allocation_backtrace_size = 0; allocation_backtrace_size = 0;
#endif #endif
Glib::Threads::Mutex::Lock lm (all_mutex); Glib::Threads::Mutex::Lock lm (all_mutex);
all.push_back (this); all.push_back (this);
} }
~thing_with_backtrace() { ~thing_with_backtrace() {
if (allocation_backtrace_size) { if (allocation_backtrace_size) {
delete [] allocation_backtrace; delete [] allocation_backtrace;
} }
Glib::Threads::Mutex::Lock lm (all_mutex); Glib::Threads::Mutex::Lock lm (all_mutex);
all.remove (this); all.remove (this);
} }
thing_with_backtrace<T>& operator= (const thing_with_backtrace<T>& other) { thing_with_backtrace<T>& operator= (const thing_with_backtrace<T>& other) {
/* no copyable members */ /* no copyable members */
return *this; return *this;
} }
static void peek_a_boo (std::ostream& stream) { static void peek_a_boo (std::ostream& stream) {
#ifdef HAVE_EXECINFO #ifdef HAVE_EXECINFO
typename std::list<thing_with_backtrace<T>*>::iterator x; typename std::list<thing_with_backtrace<T>*>::iterator x;
for (x = all.begin(); x != all.end(); ++x) { for (x = all.begin(); x != all.end(); ++x) {
char **strings; char **strings;
size_t i; 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) { if (strings) {
stream << "--- ALLOCATED SHARED_PTR @ " << (*x) << std::endl; stream << "--- ALLOCATED SHARED_PTR @ " << (*x) << std::endl;
for (i = 0; i < (*x)->allocation_backtrace_size && i < 50U; i++) { for (i = 0; i < (*x)->allocation_backtrace_size && i < 50U; i++) {
stream << strings[i] << std::endl; stream << strings[i] << std::endl;
} }
free (strings); free (strings);
} }
} }
#else #else
stream << "execinfo not defined for this platform" << std::endl; stream << "execinfo not defined for this platform" << std::endl;
#endif #endif
} }
private: private:
void** allocation_backtrace; void** allocation_backtrace;
int allocation_backtrace_size; int allocation_backtrace_size;
static std::list<thing_with_backtrace<T>* > all; static std::list<thing_with_backtrace<T>* > all;
static Glib::Threads::Mutex all_mutex; static Glib::Threads::Mutex all_mutex;
}; };
template<typename T> /*LIBPBD_API*/ std::list<PBD::thing_with_backtrace<T> *> PBD::thing_with_backtrace<T>::all; template<typename T> /*LIBPBD_API*/ std::list<PBD::thing_with_backtrace<T> *> PBD::thing_with_backtrace<T>::all;

View file

@ -77,48 +77,46 @@ PBD::stacktrace (std::ostream& out, int levels)
#define CaptureStackBackTrace RtlCaptureStackBackTrace #define CaptureStackBackTrace RtlCaptureStackBackTrace
extern "C" { extern "C" {
__declspec(dllimport) USHORT WINAPI CaptureStackBackTrace ( __declspec(dllimport) USHORT WINAPI CaptureStackBackTrace (
ULONG SamplesToSkip, ULONG FramesToSkip,
ULONG SamplesToCapture, ULONG FramesToCapture,
PVOID *BackTrace, PVOID *BackTrace,
PULONG BackTraceHash PULONG BackTraceHash);
);
} }
#endif #endif
void void
PBD::stacktrace( std::ostream& out, int) PBD::stacktrace (std::ostream& out, int)
{ {
#ifdef DEBUG #ifdef DEBUG
const size_t levels = 62; // does not support more then 62 levels of stacktrace const size_t levels = 62; // does not support more then 62 levels of stacktrace
unsigned int i; unsigned int i;
void * stack[ levels ]; void * stack[ levels ];
unsigned short samples; unsigned short frames;
SYMBOL_INFO * symbol; SYMBOL_INFO * symbol;
HANDLE process; HANDLE process;
process = GetCurrentProcess(); process = GetCurrentProcess();
out << "+++++Backtrace process: " << DEBUG_THREAD_SELF << std::endl; 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->MaxNameLen = 255;
symbol->SizeOfStruct = sizeof( SYMBOL_INFO ); symbol->SizeOfStruct = sizeof (SYMBOL_INFO);
for( i = 0; i < samples; i++ ) for (i = 0; i < frames; ++i) {
{ SymFromAddr (process, (DWORD64)(stack[i]), 0, symbol);
SymFromAddr( process, ( DWORD64 )( stack[ i ] ), 0, symbol ); out << string_compose ("%1: %2 - %3\n", samples - i - 1, symbol->Name, symbol->Address);
out << string_compose( "%1: %2 - %3\n", samples - i - 1, symbol->Name, symbol->Address );
} }
out.flush(); out.flush ();
free( symbol ); free (symbol);
#endif #endif
} }