/*
- Copyright (C) 2009 Paul Davis
+ Copyright (C) 2009 Paul Davis
From an idea by Carl Hetherington.
This program is free software; you can redistribute it and/or modify
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
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;
return str;
}
-struct BTPair {
+struct BTPair {
Backtrace* ref;
Backtrace* rel;
return str;
}
-struct SPDebug {
+struct SPDebug {
Backtrace* constructor;
Backtrace* destructor;
-
+
SPDebug (Backtrace* c) : constructor (c), destructor (0) {}
~SPDebug () {
delete constructor;
using namespace std;
static PointerMap* _sptrs;
-PointerMap& sptrs() {
+PointerMap& sptrs() {
if (_sptrs == 0) {
_sptrs = new PointerMap;
}
}
static IPointerMap* _interesting_pointers;
-IPointerMap& interesting_pointers() {
+IPointerMap& interesting_pointers() {
if (_interesting_pointers == 0) {
_interesting_pointers = new IPointerMap;
}
if (ptr == 0) {
return false;
}
-
+
return interesting_pointers().find (ptr) != interesting_pointers().end();
}
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) {
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
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) {
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
{
}
-void sp_counter_release_hook (void* /*pn*/, long /*use_count*/)
+void sp_counter_release_hook (void* /*pn*/, long /*use_count*/)
{
}