summaryrefslogtreecommitdiffstats
path: root/base/tracked.cc
diff options
context:
space:
mode:
authorapatrick@chromium.org <apatrick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-19 22:28:25 +0000
committerapatrick@chromium.org <apatrick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-19 22:28:25 +0000
commitfcb30f7bc726a11540d942deec17baf62511c2e0 (patch)
treea6f695de8a0f6689cd7a7565ae199277f151141b /base/tracked.cc
parent216813957f67962e1c50fcbbad0d3e8fcd17760e (diff)
downloadchromium_src-fcb30f7bc726a11540d942deec17baf62511c2e0.zip
chromium_src-fcb30f7bc726a11540d942deec17baf62511c2e0.tar.gz
chromium_src-fcb30f7bc726a11540d942deec17baf62511c2e0.tar.bz2
Tag all tracked objects, including Tasks, with the program counter at the site of FROM_HERE.
This is to make it easier to determine the site Tasks are posted from in release builds, especially when only a minidump is available. It should help diagnose http://crbug.com/81499. I added a debug function to alias variables so that the optimizer will not strip them out if they are not live. The semantics of the MessageLoop::PostTask functions is changed and it is wrong but I am not sure what semantics are intended. It seems location information was no longer being tracked for Tasks wrapped as Closures and I don't know if this was intended. PTAL. Update: this has since been fixed. TEST=Set breakpoint in TaskClosureAdapter::Run and very that the post site can be located in an optimized build. BUG=81499 Review URL: http://codereview.chromium.org/7039020 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@85991 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/tracked.cc')
-rw-r--r--base/tracked.cc44
1 files changed, 35 insertions, 9 deletions
diff --git a/base/tracked.cc b/base/tracked.cc
index 767f072..9a135f5 100644
--- a/base/tracked.cc
+++ b/base/tracked.cc
@@ -1,7 +1,13 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 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 "build/build_config.h"
+
+#if defined(COMPILER_MSVC)
+#include <intrin.h>
+#endif
+
#include "base/tracked.h"
#include "base/stringprintf.h"
@@ -13,17 +19,21 @@ namespace tracked_objects {
//------------------------------------------------------------------------------
-Location::Location(const char* function_name, const char* file_name,
- int line_number)
+Location::Location(const char* function_name,
+ const char* file_name,
+ int line_number,
+ const void* program_counter)
: function_name_(function_name),
file_name_(file_name),
- line_number_(line_number) {
+ line_number_(line_number),
+ program_counter_(program_counter) {
}
Location::Location()
: function_name_("Unknown"),
file_name_("Unknown"),
- line_number_(-1) {
+ line_number_(-1),
+ program_counter_(NULL) {
}
void Location::Write(bool display_filename, bool display_function_name,
@@ -58,15 +68,29 @@ void Location::WriteFunctionName(std::string* output) const {
}
}
+BASE_API const void* GetProgramCounter() {
+#if defined(COMPILER_MSVC)
+ return _ReturnAddress();
+#elif defined(COMPILER_GCC)
+ return __builtin_extract_return_addr(__builtin_return_address(0));
+#endif // COMPILER_GCC
+
+ return NULL;
+}
+
//------------------------------------------------------------------------------
#ifndef TRACK_ALL_TASK_OBJECTS
-Tracked::Tracked() {}
+Tracked::Tracked() : birth_program_counter_(NULL) {}
Tracked::~Tracked() {}
-void Tracked::SetBirthPlace(const Location& from_here) {}
+
+void Tracked::SetBirthPlace(const Location& from_here) {
+ birth_program_counter_ = from_here.program_counter();
+}
+
const Location Tracked::GetBirthPlace() const {
- static Location kNone("NoFunctionName", "NeedToSetBirthPlace", -1);
+ static Location kNone("NoFunctionName", "NeedToSetBirthPlace", -1, NULL);
return kNone;
}
bool Tracked::MissingBirthplace() const { return false; }
@@ -79,7 +103,7 @@ Tracked::Tracked()
tracked_birth_time_(TimeTicks::Now()) {
if (!ThreadData::IsActive())
return;
- SetBirthPlace(Location("NoFunctionName", "NeedToSetBirthPlace", -1));
+ SetBirthPlace(Location("NoFunctionName", "NeedToSetBirthPlace", -1, NULL));
}
Tracked::~Tracked() {
@@ -98,6 +122,8 @@ void Tracked::SetBirthPlace(const Location& from_here) {
if (!current_thread_data)
return; // Shutdown started, and this thread wasn't registered.
tracked_births_ = current_thread_data->TallyABirth(from_here);
+
+ birth_program_counter_ = from_here.program_counter();
}
const Location Tracked::GetBirthPlace() const {