diff options
Diffstat (limited to 'base')
-rw-r--r-- | base/debug_util.h | 6 | ||||
-rw-r--r-- | base/leak_tracker.h | 26 |
2 files changed, 27 insertions, 5 deletions
diff --git a/base/debug_util.h b/base/debug_util.h index 8ccb020..11c1d7c 100644 --- a/base/debug_util.h +++ b/base/debug_util.h @@ -25,6 +25,10 @@ class StackTrace { public: // Creates a stacktrace from the current location StackTrace(); + + // Note that the default copy constructor and assignment constructors + // are OK. + #if defined(OS_WIN) // Creates a stacktrace for an exception. // Note: this function will throw an import not found (StackWalk64) exception @@ -48,8 +52,6 @@ class StackTrace { static const int MAX_TRACES = 62; void* trace_[MAX_TRACES]; int count_; - - DISALLOW_EVIL_CONSTRUCTORS(StackTrace); }; class DebugUtil { diff --git a/base/leak_tracker.h b/base/leak_tracker.h index a5d105a..de6ff29 100644 --- a/base/leak_tracker.h +++ b/base/leak_tracker.h @@ -72,15 +72,35 @@ class LeakTracker : public LinkNode<LeakTracker<T> > { static void CheckForLeaks() { // Walk the allocation list and print each entry it contains. - int count = 0; + size_t count = 0; + + // Copy the first 3 leak allocation callstacks onto the stack. + // This way if we hit the CHECK() in a release build, the leak + // information will be available in mini-dump. + const size_t kMaxStackTracesToCopyOntoStack = 3; + StackTrace stacktraces[kMaxStackTracesToCopyOntoStack]; + for (LinkNode<LeakTracker<T> >* node = instances()->head(); node != instances()->end(); node = node->next()) { + StackTrace& allocation_stack = node->value()->allocation_stack_; + + if (count < kMaxStackTracesToCopyOntoStack) + stacktraces[count] = allocation_stack; + ++count; LOG(ERROR) << "Leaked " << node << " which was allocated by:"; - node->value()->allocation_stack_.PrintBacktrace(); + allocation_stack.PrintBacktrace(); + } + + CHECK(0u == count); + + // Hack to keep |stacktraces| and |count| alive (so compiler + // doesn't optimize it out, and it will appear in mini-dumps). + if (count == 0x1234) { + for (size_t i = 0; i < kMaxStackTracesToCopyOntoStack; ++i) + stacktraces[i].PrintBacktrace(); } - CHECK(0 == count); } static int NumLiveInstances() { |