diff options
author | siggi@chromium.org <siggi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-31 12:54:52 +0000 |
---|---|---|
committer | siggi@chromium.org <siggi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-31 12:54:52 +0000 |
commit | 7afa6f3a5c5a13fda9e96b65dee2c08071af0c05 (patch) | |
tree | 17934718219b741cbc73c0844c50b7f2da8c7eda /base | |
parent | 5443f2966a428ac79a598f0b17d96a9d677204ed (diff) | |
download | chromium_src-7afa6f3a5c5a13fda9e96b65dee2c08071af0c05.zip chromium_src-7afa6f3a5c5a13fda9e96b65dee2c08071af0c05.tar.gz chromium_src-7afa6f3a5c5a13fda9e96b65dee2c08071af0c05.tar.bz2 |
Signal thread names in instrumented binaries, even when a debugger is not attached.
Cache the determiniation whether a binary is instrumented or not, as it'll never change for a given binary.
R=jar@google.com
BUG=None
TEST=None
Review URL: https://chromiumcodereview.appspot.com/10454076
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@139777 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/debug/profiler.cc | 37 | ||||
-rw-r--r-- | base/threading/platform_thread_win.cc | 5 |
2 files changed, 31 insertions, 11 deletions
diff --git a/base/debug/profiler.cc b/base/debug/profiler.cc index e1f2514..de79124 100644 --- a/base/debug/profiler.cc +++ b/base/debug/profiler.cc @@ -88,17 +88,34 @@ ReturnAddressLocationResolver GetProfilerReturnAddrResolutionFunc() { extern "C" IMAGE_DOS_HEADER __ImageBase; bool IsBinaryInstrumented() { - HMODULE this_module = reinterpret_cast<HMODULE>(&__ImageBase); - base::win::PEImage image(this_module); - - // This should be self-evident, soon as we're executing. - DCHECK(image.VerifyMagic()); + enum InstrumentationCheckState { + UNINITIALIZED, + INSTRUMENTED_IMAGE, + NON_INSTRUMENTED_IMAGE, + }; + + static InstrumentationCheckState state = UNINITIALIZED; + + if (state == UNINITIALIZED) { + HMODULE this_module = reinterpret_cast<HMODULE>(&__ImageBase); + base::win::PEImage image(this_module); + + // Check to be sure our image is structured as we'd expect. + DCHECK(image.VerifyMagic()); + + // Syzygy-instrumented binaries contain a PE image section named ".thunks", + // and all Syzygy-modified binaries contain the ".syzygy" image section. + // This is a very fast check, as it only looks at the image header. + if ((image.GetImageSectionHeaderByName(".thunks") != NULL) && + (image.GetImageSectionHeaderByName(".syzygy") != NULL)) { + state = INSTRUMENTED_IMAGE; + } else { + state = NON_INSTRUMENTED_IMAGE; + } + } + DCHECK(state != UNINITIALIZED); - // Syzygy-instrumented binaries contain a PE image section named ".thunks", - // and all Syzygy-modified binaries contain the ".syzygy" image section. - // This is a very fast check, as it only looks at the image header. - return (image.GetImageSectionHeaderByName(".thunks") != NULL) && - (image.GetImageSectionHeaderByName(".syzygy") != NULL); + return state == INSTRUMENTED_IMAGE; } // Callback function to PEImage::EnumImportChunks. diff --git a/base/threading/platform_thread_win.cc b/base/threading/platform_thread_win.cc index bd4282f..4dc839b 100644 --- a/base/threading/platform_thread_win.cc +++ b/base/threading/platform_thread_win.cc @@ -5,6 +5,7 @@ #include "base/threading/platform_thread.h" #include "base/debug/alias.h" +#include "base/debug/profiler.h" #include "base/logging.h" #include "base/threading/thread_local.h" #include "base/threading/thread_restrictions.h" @@ -133,7 +134,9 @@ void PlatformThread::SetName(const char* name) { // The debugger needs to be around to catch the name in the exception. If // there isn't a debugger, we are just needlessly throwing an exception. - if (!::IsDebuggerPresent()) + // If this image file is instrumented, we raise the exception anyway + // to provide the profiler with human-readable thread names. + if (!::IsDebuggerPresent() && !base::debug::IsBinaryInstrumented()) return; SetNameInternal(CurrentId(), name); |