forked from chromium/chromium
-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add logging of where a sequence/thread was bound when a failure occurs
Use SequenceChecker::EnableStackLogging() to enable this logging. When DCHECK() fails for a ThreadChecker or SequenceChecker, if the error is not at the site of checking, it takes a great amount of knowledge and persistence to figure out where the erroroneous thread/sequence- attachment occurred. This is especially fun for a WeakPtr, which if checked on the wrong thread becomes bound to the thread. Then if the WeakPtrFactory is invalidated later, it's difficult to determine why it believes it is on the wrong thread. This adds a copy of the StackTrace in SequenceChecker and ThreadChecker that is set whenever they are bound to a thread/sequence. Then on failure the DCHECK() callers will get back a copy of the StackTrace and include it in the log message. WeakPtr calls the SequenceChecker manually instead of using the macros, since it has an additional condition so we also add the StackTrace to the message there. The StackTrace logging slows things down a bit, enough that we'd slow bots down without good reason, so the logging is optional. You may use SequenceChecker::EnableStackLogging() to enable this logging, or the equivalent alias ThreadChecker::EnableStackLogging(). Example output with stack logging enabled: [890744:1:1201/174351.878197:FATAL:weak_ptr.cc(23)] Check failed: sequence_checker_.CalledOnValidSequence(&bound_at) || HasOneRef(). WeakPtrs must be invalidated on the same sequenced thread as where they are bound. This was bound at: #0 0x7fd813c8d369 base::debug::CollectStackTrace() #1 0x7fd813b94103 base::debug::StackTrace::StackTrace() #2 0x7fd813c70aef base::ThreadCheckerImpl::ThreadCheckerImpl() #3 0x7fd813c02155 base::SequenceCheckerImpl::CalledOnValidSequence() #4 0x7fd813ba4f55 base::ScopedValidateSequenceChecker::ScopedValidateSequenceChecker() #5 0x7fd813bbfa4f base::internal::WeakReference::IsValid() #6 0x7fd80acd0f36 blink::FrameWidgetInputHandlerImpl::FrameWidgetInputHandlerImpl() [...] Check failed at: #0 0x7fd813c8d369 base::debug::CollectStackTrace() #1 0x7fd813b94103 base::debug::StackTrace::StackTrace() #2 0x7fd813bb3c53 logging::LogMessage::~LogMessage() #3 0x7fd813bb45ae logging::LogMessage::~LogMessage() #4 0x7fd813bbf91c base::internal::WeakReference::Flag::Invalidate() #5 0x7fd813bbfc8c base::internal::WeakReferenceOwner::Invalidate() #6 0x7fd80ca6eda7 blink::WebFrameWidgetImpl::Close() #7 0x7fd80ff22359 content::RenderWidget::Close() #8 0x7fd80ff21eff content::RenderWidget::CloseForFrame() [...] [email protected] Change-Id: Id89c12eaedfba9788b3cd2624447c6a1616f0afa Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2568446 Commit-Queue: danakj <[email protected]> Reviewed-by: Gabriel Charette <[email protected]> Reviewed-by: Nico Weber <[email protected]> Cr-Commit-Position: refs/heads/master@{#847805}
- Loading branch information
Showing
10 changed files
with
192 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright 2020 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "base/debug/stack_trace.h" | ||
|
||
namespace base { | ||
namespace debug { | ||
|
||
StackTrace::StackTrace() = default; | ||
StackTrace::StackTrace(size_t count) : StackTrace() {} | ||
StackTrace::StackTrace(const void* const* trace, size_t count) : StackTrace() {} | ||
|
||
const void* const* StackTrace::Addresses(size_t* count) const { | ||
return nullptr; | ||
} | ||
|
||
void StackTrace::Print() const {} | ||
|
||
void StackTrace::OutputToStream(std::ostream* os) const {} | ||
|
||
std::string StackTrace::ToString() const { | ||
return ""; | ||
} | ||
|
||
std::string StackTrace::ToStringWithPrefix(const char* prefix_string) const { | ||
return ""; | ||
} | ||
|
||
std::ostream& operator<<(std::ostream& os, const StackTrace& s) { | ||
return os; | ||
} | ||
|
||
} // namespace debug | ||
} // namespace base |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.