X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fpbd%2Fboost_debug.cc;h=b60a7b73363ce10c0756e94c89f1f4195c02094d;hb=def4be728506c8edf710c48cd0891a902dc0a6b9;hp=6b9c0cbc922f15e9a2859f5e866100f890ee4531;hpb=2b9421fd391efcddde0be3397cb66e19b744a155;p=ardour.git diff --git a/libs/pbd/boost_debug.cc b/libs/pbd/boost_debug.cc index 6b9c0cbc92..b60a7b7336 100644 --- a/libs/pbd/boost_debug.cc +++ b/libs/pbd/boost_debug.cc @@ -1,22 +1,21 @@ /* - Copyright (C) 2009 Paul Davis - From an idea by Carl Hetherington. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ + * Copyright (C) 2009-2018 Paul Davis + * Copyright (C) 2015-2019 Robin Gareus + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ #include "libpbd-config.h" @@ -37,19 +36,18 @@ class Backtrace { public: - Backtrace (); - std::ostream& print (std::ostream& str) const; + Backtrace (); + std::ostream& print (std::ostream& str) const; private: - void* trace[200]; - size_t size; + void* trace[200]; + size_t size; }; std::ostream& operator<< (std::ostream& str, const Backtrace& bt) { return bt.print (str); } - -Backtrace::Backtrace() -{ +Backtrace::Backtrace() +{ #ifdef HAVE_EXECINFO size = ::backtrace (trace, 200); #endif @@ -64,7 +62,7 @@ Backtrace::print (std::ostream& str) const if (size) { #ifdef HAVE_EXECINFO strings = ::backtrace_symbols (trace, size); -#endif +#endif if (strings) { for (i = 3; i < 5+18 && i < size; i++) { str << strings[i] << std::endl; @@ -76,14 +74,13 @@ Backtrace::print (std::ostream& str) const return str; } -struct BTPair { - - Backtrace* ref; - Backtrace* rel; +struct BTPair { - BTPair (Backtrace* bt) : ref (bt), rel (0) {} - ~BTPair () { } + Backtrace* ref; + Backtrace* rel; + BTPair (Backtrace* bt) : ref (bt), rel (0) {} + ~BTPair () { } }; std::ostream& operator<<(std::ostream& str, const BTPair& btp) { @@ -94,15 +91,15 @@ std::ostream& operator<<(std::ostream& str, const BTPair& btp) { return str; } -struct SPDebug { - Backtrace* constructor; - Backtrace* destructor; - - SPDebug (Backtrace* c) : constructor (c), destructor (0) {} - ~SPDebug () { - delete constructor; - delete destructor; - } +struct SPDebug { + Backtrace* constructor; + Backtrace* destructor; + + SPDebug (Backtrace* c) : constructor (c), destructor (0) {} + ~SPDebug () { + delete constructor; + delete destructor; + } }; std::ostream& operator<< (std::ostream& str, const SPDebug& spd) @@ -115,43 +112,46 @@ std::ostream& operator<< (std::ostream& str, const SPDebug& spd) return str; } -typedef std::multimap PointerMap; -typedef std::map IPointerMap; +typedef std::multimap PointerMap; +typedef std::map IPointerMap; using namespace std; static PointerMap* _sptrs; -PointerMap& sptrs() { - if (_sptrs == 0) { - _sptrs = new PointerMap; - } - return *_sptrs; +PointerMap& sptrs() +{ + if (_sptrs == 0) { + _sptrs = new PointerMap; + } + return *_sptrs; } static IPointerMap* _interesting_pointers; -IPointerMap& interesting_pointers() { - if (_interesting_pointers == 0) { - _interesting_pointers = new IPointerMap; - } - return *_interesting_pointers; +IPointerMap& interesting_pointers() +{ + if (_interesting_pointers == 0) { + _interesting_pointers = new IPointerMap; + } + return *_interesting_pointers; } static Glib::Threads::Mutex* _the_lock; -static Glib::Threads::Mutex& the_lock() { - if (_the_lock == 0) { - _the_lock = new Glib::Threads::Mutex; - } - return *_the_lock; +static Glib::Threads::Mutex& the_lock() +{ + if (_the_lock == 0) { + _the_lock = new Glib::Threads::Mutex; + } + return *_the_lock; } static bool -is_interesting_object (void const* ptr) +is_interesting_object (volatile void const* ptr) { if (ptr == 0) { return false; } - + return interesting_pointers().find (ptr) != interesting_pointers().end(); } @@ -169,7 +169,7 @@ void boost_debug_shared_ptr_mark_interesting (void* ptr, const char* type) { Glib::Threads::Mutex::Lock guard (the_lock()); - pair newpair (ptr, type); + pair newpair (ptr, type); interesting_pointers().insert (newpair); if (debug_out) { cerr << "Interesting object @ " << ptr << " of type " << type << endl; @@ -193,11 +193,11 @@ boost_debug_shared_ptr_operator_equals (void const *sp, void const *old_obj, int if (is_interesting_object (old_obj)) { if (debug_out) { - cerr << "\tlost old sp @ " << sp << " for " << old_obj << " UC = " << old_use_count << " now for " << obj << " UC = " << new_use_count - << " (total sp's = " << sptrs().size() << ')' << endl; + cerr << "\tlost old sp @ " << sp << " for " << old_obj << " UC = " << old_use_count << " now for " << obj << " UC = " << new_use_count + << " (total sp's = " << sptrs().size() << ')' << endl; } PointerMap::iterator x = sptrs().find (sp); - + if (x != sptrs().end()) { sptrs().erase (x); if (debug_out) { @@ -214,14 +214,14 @@ boost_debug_shared_ptr_operator_equals (void const *sp, void const *old_obj, int newpair.second = new SPDebug (new Backtrace()); sptrs().insert (newpair); - + if (debug_out) { - cerr << "assignment created sp for " << obj << " @ " << sp << " used to point to " << old_obj << " UC = " << old_use_count - << " UC = " << new_use_count - << " (total sp's = " << sptrs().size() << ')' << endl; + cerr << "assignment created sp for " << obj << " @ " << sp << " used to point to " << old_obj << " UC = " << old_use_count + << " UC = " << new_use_count + << " (total sp's = " << sptrs().size() << ')' << endl; cerr << *newpair.second << endl; } - } + } } void @@ -241,11 +241,11 @@ boost_debug_shared_ptr_reset (void const *sp, void const *old_obj, int old_use_c if (is_interesting_object (old_obj)) { if (debug_out) { - cerr << "\tlost old sp @ " << sp << " for " << old_obj << " UC = " << old_use_count << " now for " << obj << " UC = " << new_use_count - << " (total sp's = " << sptrs().size() << ')' << endl; + cerr << "\tlost old sp @ " << sp << " for " << old_obj << " UC = " << old_use_count << " now for " << obj << " UC = " << new_use_count + << " (total sp's = " << sptrs().size() << ')' << endl; } PointerMap::iterator x = sptrs().find (sp); - + if (x != sptrs().end()) { sptrs().erase (x); if (debug_out) { @@ -262,18 +262,18 @@ boost_debug_shared_ptr_reset (void const *sp, void const *old_obj, int old_use_c newpair.second = new SPDebug (new Backtrace()); sptrs().insert (newpair); - + if (debug_out) { - cerr << "reset created sp for " << obj << " @ " << sp << " used to point to " << old_obj << " UC = " << old_use_count - << " UC = " << new_use_count - << " (total sp's = " << sptrs().size() << ')' << endl; + cerr << "reset created sp for " << obj << " @ " << sp << " used to point to " << old_obj << " UC = " << old_use_count + << " UC = " << new_use_count + << " (total sp's = " << sptrs().size() << ')' << endl; cerr << *newpair.second << endl; } - } + } } void -boost_debug_shared_ptr_destructor (void const *sp, void const *obj, int use_count) +boost_debug_shared_ptr_destructor (void const *sp, volatile void const *obj, int use_count) { Glib::Threads::Mutex::Lock guard (the_lock()); PointerMap::iterator x = sptrs().find (sp); @@ -287,7 +287,7 @@ boost_debug_shared_ptr_destructor (void const *sp, void const *obj, int use_coun } void -boost_debug_shared_ptr_constructor (void const *sp, void const *obj, int use_count) +boost_debug_shared_ptr_constructor (void const *sp, volatile void const *obj, int use_count) { if (is_interesting_object (obj)) { Glib::Threads::Mutex::Lock guard (the_lock()); @@ -341,7 +341,7 @@ void sp_counter_ref_hook (void* /*pn*/, long /* use count */) { } -void sp_counter_release_hook (void* /*pn*/, long /*use_count*/) +void sp_counter_release_hook (void* /*pn*/, long /*use_count*/) { }