diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-26 04:07:50 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-26 04:07:50 +0000 |
commit | 58580359a452cb7c3b9580edc0843c3ab3d158df (patch) | |
tree | 964dbcc1505f4b9c2bbb5e7a64720861d604c8f3 | |
parent | 23872906817de5d402b0c2da6d5f7ee6026378e6 (diff) | |
download | chromium_src-58580359a452cb7c3b9580edc0843c3ab3d158df.zip chromium_src-58580359a452cb7c3b9580edc0843c3ab3d158df.tar.gz chromium_src-58580359a452cb7c3b9580edc0843c3ab3d158df.tar.bz2 |
Move debug-related stuff from base to the base/debug directory and use the
base::debug namespace.
This splits apart debug_util into base/debugger and base/stack_trace
There are still two functions in debug_util that I'm not sure what to do with.
Since this uses the base::debug namespace, I removed the functions in
debugger.h from the static class and just made them free functions in the
namespace.
TEST=it compiles
BUG=none
Review URL: http://codereview.chromium.org/3945002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@63859 0039d316-1c4b-4281-b951-d872f2087c98
74 files changed, 830 insertions, 631 deletions
diff --git a/app/resource_bundle_win.cc b/app/resource_bundle_win.cc index 369ee40..fbc40b4 100644 --- a/app/resource_bundle_win.cc +++ b/app/resource_bundle_win.cc @@ -10,6 +10,7 @@ #include "app/l10n_util.h" #include "base/data_pack.h" #include "base/debug_util.h" +#include "base/debug/stack_trace.h" #include "base/file_util.h" #include "base/lock.h" #include "base/logging.h" @@ -139,7 +140,7 @@ string16 ResourceBundle::GetLocalizedString(int message_id) { // If for some reason we were unable to load a resource dll, return an empty // string (better than crashing). if (!locale_resources_data_) { - StackTrace().PrintBacktrace(); // See http://crbug.com/21925. + base::debug::StackTrace().PrintBacktrace(); // See http://crbug.com/21925. LOG(WARNING) << "locale resources are not loaded"; return string16(); } @@ -156,7 +157,8 @@ string16 ResourceBundle::GetLocalizedString(int message_id) { image = AtlGetStringResourceImage(_AtlBaseModule.GetModuleInstance(), message_id); if (!image) { - StackTrace().PrintBacktrace(); // See http://crbug.com/21925. + // See http://crbug.com/21925. + base::debug::StackTrace().PrintBacktrace(); NOTREACHED() << "unable to find resource: " << message_id; return std::wstring(); } diff --git a/base/base.gyp b/base/base.gyp index 2de9b4b..6a37f5d 100644 --- a/base/base.gyp +++ b/base/base.gyp @@ -75,7 +75,9 @@ 'crypto/signature_verifier_unittest.cc', 'crypto/symmetric_key_unittest.cc', 'data_pack_unittest.cc', - 'debug_util_unittest.cc', + 'debug/leak_tracker_unittest.cc', + 'debug/stack_trace_unittest.cc', + 'debug/trace_event_win_unittest.cc', 'dir_reader_posix_unittest.cc', 'environment_unittest.cc', 'event_trace_consumer_win_unittest.cc', @@ -97,7 +99,6 @@ 'json/json_writer_unittest.cc', 'json/string_escape_unittest.cc', 'lazy_instance_unittest.cc', - 'leak_tracker_unittest.cc', 'linked_list_unittest.cc', 'linked_ptr_unittest.cc', 'lock_unittest.cc', @@ -150,7 +151,6 @@ 'time_win_unittest.cc', 'timer_unittest.cc', 'tools_sanity_unittest.cc', - 'trace_event_win_unittest.cc', 'tracked_objects_unittest.cc', 'tuple_unittest.cc', 'utf_offset_string_conversions_unittest.cc', diff --git a/base/base.gypi b/base/base.gypi index d0fa20b..9a32325 100644 --- a/base/base.gypi +++ b/base/base.gypi @@ -58,8 +58,19 @@ 'debug_util.cc', 'debug_util.h', 'debug_util_mac.cc', - 'debug_util_posix.cc', - 'debug_util_win.cc', + 'debug/debugger.cc', + 'debug/debugger.h', + 'debug/debugger_posix.cc', + 'debug/debugger_win.cc', + 'debug/leak_annotations.h', + 'debug/leak_tracker.h', + 'debug/stack_trace.cc', + 'debug/stack_trace.h', + 'debug/stack_trace_posix.cc', + 'debug/stack_trace_win.cc', + 'debug/trace_event_win.cc', + 'debug/trace_event.cc', + 'debug/trace_event.h', 'dir_reader_fallback.h', 'dir_reader_linux.h', 'dir_reader_posix.h', @@ -104,8 +115,6 @@ 'json/string_escape.h', 'lazy_instance.cc', 'lazy_instance.h', - 'leak_annotations.h', - 'leak_tracker.h', 'linked_list.h', 'linked_ptr.h', 'lock.cc', @@ -259,9 +268,6 @@ 'time_win.cc', 'timer.cc', 'timer.h', - 'trace_event_win.cc', - 'trace_event.cc', - 'trace_event.h', 'tracked.cc', 'tracked.h', 'tracked_objects.cc', @@ -378,7 +384,7 @@ # regression to page cycler moz. 'sha1_win.cc', 'string16.cc', - 'trace_event.cc', + 'debug/trace_event.cc', ], },], ], diff --git a/base/crypto/rsa_private_key_nss.cc b/base/crypto/rsa_private_key_nss.cc index 13e4f1f..7786521 100644 --- a/base/crypto/rsa_private_key_nss.cc +++ b/base/crypto/rsa_private_key_nss.cc @@ -10,7 +10,7 @@ #include <list> -#include "base/leak_annotations.h" +#include "base/debug/leak_annotations.h" #include "base/logging.h" #include "base/nss_util.h" #include "base/nss_util_internal.h" diff --git a/base/debug/debugger.cc b/base/debug/debugger.cc new file mode 100644 index 0000000..9ca7e8d --- /dev/null +++ b/base/debug/debugger.cc @@ -0,0 +1,25 @@ +// Copyright (c) 2010 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/debugger.h" + +#include "base/platform_thread.h" + +namespace base { +namespace debug { + +bool WaitForDebugger(int wait_seconds, bool silent) { + for (int i = 0; i < wait_seconds * 10; ++i) { + if (BeingDebugged()) { + if (!silent) + BreakDebugger(); + return true; + } + PlatformThread::Sleep(100); + } + return false; +} + +} // namespace debug +} // namespace base diff --git a/base/debug/debugger.h b/base/debug/debugger.h new file mode 100644 index 0000000..008d77d --- /dev/null +++ b/base/debug/debugger.h @@ -0,0 +1,39 @@ +// Copyright (c) 2010 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. + +// This is a cross platform interface for helper functions related to +// debuggers. You should use this to test if you're running under a debugger, +// and if you would like to yield (breakpoint) into the debugger. + +#ifndef BASE_DEBUG_DEBUGGER_H +#define BASE_DEBUG_DEBUGGER_H +#pragma once + +namespace base { +namespace debug { + +// Starts the registered system-wide JIT debugger to attach it to specified +// process. +bool SpawnDebuggerOnProcess(unsigned process_id); + +// Waits wait_seconds seconds for a debugger to attach to the current process. +// When silent is false, an exception is thrown when a debugger is detected. +bool WaitForDebugger(int wait_seconds, bool silent); + +// Returns true if the given process is being run under a debugger. +// +// On OS X, the underlying mechanism doesn't work when the sandbox is enabled. +// To get around this, this function caches its value. +// +// WARNING: Because of this, on OS X, a call MUST be made to this function +// BEFORE the sandbox is enabled. +bool BeingDebugged(); + +// Break into the debugger, assumes a debugger is present. +void BreakDebugger(); + +} // namespace debug +} // namespace base + +#endif // BASE_DEBUG_DEBUGGER_H diff --git a/base/debug/debugger_posix.cc b/base/debug/debugger_posix.cc new file mode 100644 index 0000000..a5ab066 --- /dev/null +++ b/base/debug/debugger_posix.cc @@ -0,0 +1,165 @@ +// Copyright (c) 2010 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/debugger.h" + +#include <errno.h> +#include <fcntl.h> +#include <stdio.h> +#include <stdlib.h> +#include <sys/stat.h> +#include <sys/sysctl.h> +#include <sys/types.h> +#include <unistd.h> + +#include <string> +#include <vector> + +#if defined(__GLIBCXX__) +#include <cxxabi.h> +#endif + +#if defined(OS_MACOSX) +#include <AvailabilityMacros.h> +#endif + +#include <iostream> + +#include "base/basictypes.h" +#include "base/compat_execinfo.h" +#include "base/eintr_wrapper.h" +#include "base/logging.h" +#include "base/safe_strerror_posix.h" +#include "base/scoped_ptr.h" +#include "base/string_piece.h" +#include "base/stringprintf.h" + +#if defined(USE_SYMBOLIZE) +#include "base/third_party/symbolize/symbolize.h" +#endif + +namespace base { +namespace debug { + +bool SpawnDebuggerOnProcess(unsigned /* process_id */) { + NOTIMPLEMENTED(); + return false; +} + +#if defined(OS_MACOSX) + +// Based on Apple's recommended method as described in +// http://developer.apple.com/qa/qa2004/qa1361.html +bool BeingDebugged() { + // If the process is sandboxed then we can't use the sysctl, so cache the + // value. + static bool is_set = false; + static bool being_debugged = false; + + if (is_set) { + return being_debugged; + } + + // Initialize mib, which tells sysctl what info we want. In this case, + // we're looking for information about a specific process ID. + int mib[] = { + CTL_KERN, + KERN_PROC, + KERN_PROC_PID, + getpid() + }; + + // Caution: struct kinfo_proc is marked __APPLE_API_UNSTABLE. The source and + // binary interfaces may change. + struct kinfo_proc info; + size_t info_size = sizeof(info); + + int sysctl_result = sysctl(mib, arraysize(mib), &info, &info_size, NULL, 0); + DCHECK_EQ(sysctl_result, 0); + if (sysctl_result != 0) { + is_set = true; + being_debugged = false; + return being_debugged; + } + + // This process is being debugged if the P_TRACED flag is set. + is_set = true; + being_debugged = (info.kp_proc.p_flag & P_TRACED) != 0; + return being_debugged; +} + +#elif defined(OS_LINUX) + +// We can look in /proc/self/status for TracerPid. We are likely used in crash +// handling, so we are careful not to use the heap or have side effects. +// Another option that is common is to try to ptrace yourself, but then we +// can't detach without forking(), and that's not so great. +// static +bool BeingDebugged() { + int status_fd = open("/proc/self/status", O_RDONLY); + if (status_fd == -1) + return false; + + // We assume our line will be in the first 1024 characters and that we can + // read this much all at once. In practice this will generally be true. + // This simplifies and speeds up things considerably. + char buf[1024]; + + ssize_t num_read = HANDLE_EINTR(read(status_fd, buf, sizeof(buf))); + if (HANDLE_EINTR(close(status_fd)) < 0) + return false; + + if (num_read <= 0) + return false; + + StringPiece status(buf, num_read); + StringPiece tracer("TracerPid:\t"); + + StringPiece::size_type pid_index = status.find(tracer); + if (pid_index == StringPiece::npos) + return false; + + // Our pid is 0 without a debugger, assume this for any pid starting with 0. + pid_index += tracer.size(); + return pid_index < status.size() && status[pid_index] != '0'; +} + +#elif defined(OS_FREEBSD) + +bool DebugUtil::BeingDebugged() { + // TODO(benl): can we determine this under FreeBSD? + NOTIMPLEMENTED(); + return false; +} + +#endif // defined(OS_FREEBSD) + +// We want to break into the debugger in Debug mode, and cause a crash dump in +// Release mode. Breakpad behaves as follows: +// +// +-------+-----------------+-----------------+ +// | OS | Dump on SIGTRAP | Dump on SIGABRT | +// +-------+-----------------+-----------------+ +// | Linux | N | Y | +// | Mac | Y | N | +// +-------+-----------------+-----------------+ +// +// Thus we do the following: +// Linux: Debug mode, send SIGTRAP; Release mode, send SIGABRT. +// Mac: Always send SIGTRAP. + +#if defined(NDEBUG) && !defined(OS_MACOSX) +#define DEBUG_BREAK() abort() +#elif defined(ARCH_CPU_ARM_FAMILY) +#define DEBUG_BREAK() asm("bkpt 0") +#else +#define DEBUG_BREAK() asm("int3") +#endif + +void BreakDebugger() { + DEBUG_BREAK(); +} + +} // namespace debug +} // namespace base diff --git a/base/debug/debugger_win.cc b/base/debug/debugger_win.cc new file mode 100644 index 0000000..d1d47cd --- /dev/null +++ b/base/debug/debugger_win.cc @@ -0,0 +1,112 @@ +// Copyright (c) 2010 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/debugger.h" + +#include <windows.h> +#include <dbghelp.h> + +#include "base/basictypes.h" +#include "base/debug_util.h" +#include "base/logging.h" + +namespace base { +namespace debug { + +namespace { + +// Minimalist key reader. +// Note: Does not use the CRT. +bool RegReadString(HKEY root, const wchar_t* subkey, + const wchar_t* value_name, wchar_t* buffer, int* len) { + HKEY key = NULL; + DWORD res = RegOpenKeyEx(root, subkey, 0, KEY_READ, &key); + if (ERROR_SUCCESS != res || key == NULL) + return false; + + DWORD type = 0; + DWORD buffer_size = *len * sizeof(wchar_t); + // We don't support REG_EXPAND_SZ. + res = RegQueryValueEx(key, value_name, NULL, &type, + reinterpret_cast<BYTE*>(buffer), &buffer_size); + if (ERROR_SUCCESS == res && buffer_size != 0 && type == REG_SZ) { + // Make sure the buffer is NULL terminated. + buffer[*len - 1] = 0; + *len = lstrlen(buffer); + RegCloseKey(key); + return true; + } + RegCloseKey(key); + return false; +} + +// Replaces each "%ld" in input per a value. Not efficient but it works. +// Note: Does not use the CRT. +bool StringReplace(const wchar_t* input, int value, wchar_t* output, + int output_len) { + memset(output, 0, output_len*sizeof(wchar_t)); + int input_len = lstrlen(input); + + for (int i = 0; i < input_len; ++i) { + int current_output_len = lstrlen(output); + + if (input[i] == L'%' && input[i + 1] == L'l' && input[i + 2] == L'd') { + // Make sure we have enough place left. + if ((current_output_len + 12) >= output_len) + return false; + + // Cheap _itow(). + wsprintf(output+current_output_len, L"%d", value); + i += 2; + } else { + if (current_output_len >= output_len) + return false; + output[current_output_len] = input[i]; + } + } + return true; +} + +} // namespace + +// Note: Does not use the CRT. +bool SpawnDebuggerOnProcess(unsigned process_id) { + wchar_t reg_value[1026]; + int len = arraysize(reg_value); + if (RegReadString(HKEY_LOCAL_MACHINE, + L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug", + L"Debugger", reg_value, &len)) { + wchar_t command_line[1026]; + if (StringReplace(reg_value, process_id, command_line, + arraysize(command_line))) { + // We don't mind if the debugger is present because it will simply fail + // to attach to this process. + STARTUPINFO startup_info = {0}; + startup_info.cb = sizeof(startup_info); + PROCESS_INFORMATION process_info = {0}; + + if (CreateProcess(NULL, command_line, NULL, NULL, FALSE, 0, NULL, NULL, + &startup_info, &process_info)) { + CloseHandle(process_info.hThread); + WaitForInputIdle(process_info.hProcess, 10000); + CloseHandle(process_info.hProcess); + return true; + } + } + } + return false; +} + +bool BeingDebugged() { + return ::IsDebuggerPresent() != 0; +} + +void BreakDebugger() { + if (DebugUtil::AreDialogsSuppressed()) + _exit(1); + __debugbreak(); +} + +} // namespace debug +} // namespace base diff --git a/base/leak_annotations.h b/base/debug/leak_annotations.h index dd8280b..e1086fe 100644 --- a/base/leak_annotations.h +++ b/base/debug/leak_annotations.h @@ -1,9 +1,9 @@ -// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. -#ifndef BASE_LEAK_ANNOTATIONS_H_ -#define BASE_LEAK_ANNOTATIONS_H_ +#ifndef BASE_DEBUG_LEAK_ANNOTATIONS_H_ +#define BASE_DEBUG_LEAK_ANNOTATIONS_H_ #pragma once #include "build/build_config.h" @@ -25,4 +25,4 @@ #endif -#endif // BASE_LEAK_ANNOTATIONS_H_ +#endif // BASE_DEBUG_LEAK_ANNOTATIONS_H_ diff --git a/base/leak_tracker.h b/base/debug/leak_tracker.h index 96d8773..8af82a9 100644 --- a/base/leak_tracker.h +++ b/base/debug/leak_tracker.h @@ -1,9 +1,9 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. -#ifndef BASE_LEAK_TRACKER_H_ -#define BASE_LEAK_TRACKER_H_ +#ifndef BASE_DEBUG_LEAK_TRACKER_H_ +#define BASE_DEBUG_LEAK_TRACKER_H_ #pragma once // Only enable leak tracking in debug builds. @@ -12,7 +12,7 @@ #endif #ifdef ENABLE_LEAK_TRACKER -#include "base/debug_util.h" +#include "base/debug/stack_trace.h" #include "base/linked_list.h" #include "base/logging.h" #endif // ENABLE_LEAK_TRACKER @@ -45,6 +45,7 @@ // If ENABLE_LEAK_TRACKER is not defined, then the check has no effect. namespace base { +namespace debug { #ifndef ENABLE_LEAK_TRACKER @@ -127,6 +128,7 @@ class LeakTracker : public LinkNode<LeakTracker<T> > { #endif // ENABLE_LEAK_TRACKER +} // namespace debug } // namespace base -#endif // BASE_LEAK_TRACKER_H_ +#endif // BASE_DEBUG_LEAK_TRACKER_H_ diff --git a/base/debug/leak_tracker_unittest.cc b/base/debug/leak_tracker_unittest.cc new file mode 100644 index 0000000..2e6a9a5 --- /dev/null +++ b/base/debug/leak_tracker_unittest.cc @@ -0,0 +1,113 @@ +// Copyright (c) 2010 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/leak_tracker.h" +#include "base/scoped_ptr.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace base { +namespace debug { + +namespace { + +class ClassA { + private: + LeakTracker<ClassA> leak_tracker_; +}; + +class ClassB { + private: + LeakTracker<ClassB> leak_tracker_; +}; + +#ifndef ENABLE_LEAK_TRACKER + +// If leak tracking is disabled, we should do nothing. +TEST(LeakTrackerTest, NotEnabled) { + EXPECT_EQ(-1, LeakTracker<ClassA>::NumLiveInstances()); + EXPECT_EQ(-1, LeakTracker<ClassB>::NumLiveInstances()); + + // Use scoped_ptr so compiler doesn't complain about unused variables. + scoped_ptr<ClassA> a1(new ClassA); + scoped_ptr<ClassB> b1(new ClassB); + scoped_ptr<ClassB> b2(new ClassB); + + EXPECT_EQ(-1, LeakTracker<ClassA>::NumLiveInstances()); + EXPECT_EQ(-1, LeakTracker<ClassB>::NumLiveInstances()); +} + +#else + +TEST(LeakTrackerTest, Basic) { + { + ClassA a1; + + EXPECT_EQ(1, LeakTracker<ClassA>::NumLiveInstances()); + EXPECT_EQ(0, LeakTracker<ClassB>::NumLiveInstances()); + + ClassB b1; + ClassB b2; + + EXPECT_EQ(1, LeakTracker<ClassA>::NumLiveInstances()); + EXPECT_EQ(2, LeakTracker<ClassB>::NumLiveInstances()); + + scoped_ptr<ClassA> a2(new ClassA); + + EXPECT_EQ(2, LeakTracker<ClassA>::NumLiveInstances()); + EXPECT_EQ(2, LeakTracker<ClassB>::NumLiveInstances()); + + a2.reset(); + + EXPECT_EQ(1, LeakTracker<ClassA>::NumLiveInstances()); + EXPECT_EQ(2, LeakTracker<ClassB>::NumLiveInstances()); + } + + EXPECT_EQ(0, LeakTracker<ClassA>::NumLiveInstances()); + EXPECT_EQ(0, LeakTracker<ClassB>::NumLiveInstances()); +} + +// Try some orderings of create/remove to hit different cases in the linked-list +// assembly. +TEST(LeakTrackerTest, LinkedList) { + EXPECT_EQ(0, LeakTracker<ClassB>::NumLiveInstances()); + + scoped_ptr<ClassA> a1(new ClassA); + scoped_ptr<ClassA> a2(new ClassA); + scoped_ptr<ClassA> a3(new ClassA); + scoped_ptr<ClassA> a4(new ClassA); + + EXPECT_EQ(4, LeakTracker<ClassA>::NumLiveInstances()); + + // Remove the head of the list (a1). + a1.reset(); + EXPECT_EQ(3, LeakTracker<ClassA>::NumLiveInstances()); + + // Remove the tail of the list (a4). + a4.reset(); + EXPECT_EQ(2, LeakTracker<ClassA>::NumLiveInstances()); + + // Append to the new tail of the list (a3). + scoped_ptr<ClassA> a5(new ClassA); + EXPECT_EQ(3, LeakTracker<ClassA>::NumLiveInstances()); + + a2.reset(); + a3.reset(); + + EXPECT_EQ(1, LeakTracker<ClassA>::NumLiveInstances()); + + a5.reset(); + EXPECT_EQ(0, LeakTracker<ClassA>::NumLiveInstances()); +} + +TEST(LeakTrackerTest, NoOpCheckForLeaks) { + // There are no live instances of ClassA, so this should do nothing. + LeakTracker<ClassA>::CheckForLeaks(); +} + +#endif // ENABLE_LEAK_TRACKER + +} // namespace + +} // namespace debug +} // namespace base diff --git a/base/debug/stack_trace.cc b/base/debug/stack_trace.cc new file mode 100644 index 0000000..5be4c5c --- /dev/null +++ b/base/debug/stack_trace.cc @@ -0,0 +1,21 @@ +// Copyright (c) 2010 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() { +} + +const void *const *StackTrace::Addresses(size_t* count) { + *count = count_; + if (count_) + return trace_; + return NULL; +} + +} // namespace debug +} // namespace base diff --git a/base/debug/stack_trace.h b/base/debug/stack_trace.h new file mode 100644 index 0000000..8afc32c --- /dev/null +++ b/base/debug/stack_trace.h @@ -0,0 +1,63 @@ +// Copyright (c) 2010 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. + +#ifndef BASE_DEBUG_STACK_TRACE_H_ +#define BASE_DEBUG_STACK_TRACE_H_ +#pragma once + +#include <iosfwd> + +#include "build/build_config.h" + +#if defined(OS_WIN) +struct _EXCEPTION_POINTERS; +#endif + +namespace base { +namespace debug { + +// A stacktrace can be helpful in debugging. For example, you can include a +// stacktrace member in a object (probably around #ifndef NDEBUG) so that you +// can later see where the given object was created from. +class StackTrace { + public: + // Creates a stacktrace from the current location. + StackTrace(); + +#if defined(OS_WIN) + // Creates a stacktrace for an exception. + // Note: this function will throw an import not found (StackWalk64) exception + // on system without dbghelp 5.1. + StackTrace(_EXCEPTION_POINTERS* exception_pointers); +#endif + + // Copying and assignment are allowed with the default functions. + + ~StackTrace(); + + // Gets an array of instruction pointer values. |*count| will be set to the + // number of elements in the returned array. + const void* const* Addresses(size_t* count); + + // Prints a backtrace to stderr + void PrintBacktrace(); + + // Resolves backtrace to symbols and write to stream. + void OutputToStream(std::ostream* os); + + private: + // From http://msdn.microsoft.com/en-us/library/bb204633.aspx, + // the sum of FramesToSkip and FramesToCapture must be less than 63, + // so set it to 62. Even if on POSIX it could be a larger value, it usually + // doesn't give much more information. + static const int kMaxTraces = 62; + + void* trace_[kMaxTraces]; + int count_; +}; + +} // namespace debug +} // namespace base + +#endif // BASE_DEBUG_STACK_TRACE_H_ diff --git a/base/debug_util_posix.cc b/base/debug/stack_trace_posix.cc index 7d7aca4..e4b0ef2 100644 --- a/base/debug_util_posix.cc +++ b/base/debug/stack_trace_posix.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "base/debug_util.h" +#include "base/debug/stack_trace.h" #include <errno.h> #include <fcntl.h> @@ -39,7 +39,11 @@ #include "base/third_party/symbolize/symbolize.h" #endif +namespace base { +namespace debug { + namespace { + // The prefix used for mangled symbols, per the Itanium C++ ABI: // http://www.codesourcery.com/cxx-abi/abi.html#mangling const char kMangledSymbolPrefix[] = "_Z"; @@ -145,128 +149,6 @@ bool GetBacktraceStrings(void **trace, int size, } // namespace -// static -bool DebugUtil::SpawnDebuggerOnProcess(unsigned /* process_id */) { - NOTIMPLEMENTED(); - return false; -} - -#if defined(OS_MACOSX) - -// Based on Apple's recommended method as described in -// http://developer.apple.com/qa/qa2004/qa1361.html -// static -bool DebugUtil::BeingDebugged() { - // If the process is sandboxed then we can't use the sysctl, so cache the - // value. - static bool is_set = false; - static bool being_debugged = false; - - if (is_set) { - return being_debugged; - } - - // Initialize mib, which tells sysctl what info we want. In this case, - // we're looking for information about a specific process ID. - int mib[] = { - CTL_KERN, - KERN_PROC, - KERN_PROC_PID, - getpid() - }; - - // Caution: struct kinfo_proc is marked __APPLE_API_UNSTABLE. The source and - // binary interfaces may change. - struct kinfo_proc info; - size_t info_size = sizeof(info); - - int sysctl_result = sysctl(mib, arraysize(mib), &info, &info_size, NULL, 0); - DCHECK_EQ(sysctl_result, 0); - if (sysctl_result != 0) { - is_set = true; - being_debugged = false; - return being_debugged; - } - - // This process is being debugged if the P_TRACED flag is set. - is_set = true; - being_debugged = (info.kp_proc.p_flag & P_TRACED) != 0; - return being_debugged; -} - -#elif defined(OS_LINUX) - -// We can look in /proc/self/status for TracerPid. We are likely used in crash -// handling, so we are careful not to use the heap or have side effects. -// Another option that is common is to try to ptrace yourself, but then we -// can't detach without forking(), and that's not so great. -// static -bool DebugUtil::BeingDebugged() { - int status_fd = open("/proc/self/status", O_RDONLY); - if (status_fd == -1) - return false; - - // We assume our line will be in the first 1024 characters and that we can - // read this much all at once. In practice this will generally be true. - // This simplifies and speeds up things considerably. - char buf[1024]; - - ssize_t num_read = HANDLE_EINTR(read(status_fd, buf, sizeof(buf))); - if (HANDLE_EINTR(close(status_fd)) < 0) - return false; - - if (num_read <= 0) - return false; - - base::StringPiece status(buf, num_read); - base::StringPiece tracer("TracerPid:\t"); - - base::StringPiece::size_type pid_index = status.find(tracer); - if (pid_index == base::StringPiece::npos) - return false; - - // Our pid is 0 without a debugger, assume this for any pid starting with 0. - pid_index += tracer.size(); - return pid_index < status.size() && status[pid_index] != '0'; -} - -#elif defined(OS_FREEBSD) - -bool DebugUtil::BeingDebugged() { - // TODO(benl): can we determine this under FreeBSD? - NOTIMPLEMENTED(); - return false; -} - -#endif // defined(OS_FREEBSD) - -// We want to break into the debugger in Debug mode, and cause a crash dump in -// Release mode. Breakpad behaves as follows: -// -// +-------+-----------------+-----------------+ -// | OS | Dump on SIGTRAP | Dump on SIGABRT | -// +-------+-----------------+-----------------+ -// | Linux | N | Y | -// | Mac | Y | N | -// +-------+-----------------+-----------------+ -// -// Thus we do the following: -// Linux: Debug mode, send SIGTRAP; Release mode, send SIGABRT. -// Mac: Always send SIGTRAP. - -#if defined(NDEBUG) && !defined(OS_MACOSX) -#define DEBUG_BREAK() abort() -#elif defined(ARCH_CPU_ARM_FAMILY) -#define DEBUG_BREAK() asm("bkpt 0") -#else -#define DEBUG_BREAK() asm("int3") -#endif - -// static -void DebugUtil::BreakDebugger() { - DEBUG_BREAK(); -} - StackTrace::StackTrace() { #if defined(OS_MACOSX) && MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5 if (backtrace == NULL) { @@ -312,3 +194,6 @@ void StackTrace::OutputToStream(std::ostream* os) { (*os) << "\t" << trace_strings[i] << "\n"; } } + +} // namespace debug +} // namespace base diff --git a/base/debug_util_unittest.cc b/base/debug/stack_trace_unittest.cc index 8d0deab..e8e1e19 100644 --- a/base/debug_util_unittest.cc +++ b/base/debug/stack_trace_unittest.cc @@ -5,10 +5,13 @@ #include <sstream> #include <string> -#include "base/debug_util.h" +#include "base/debug/stack_trace.h" #include "base/logging.h" #include "testing/gtest/include/gtest/gtest.h" +namespace base { +namespace debug { + // Note: On Linux, this test currently only fully works on Debug builds. // See comments in the #ifdef soup if you intend to change this. // Flaky, crbug.com/32070. @@ -104,3 +107,6 @@ TEST(StackTrace, DebugOutputToStream) { TEST(StackTrace, DebugPrintBacktrace) { StackTrace().PrintBacktrace(); } + +} // namespace debug +} // namespace base diff --git a/base/debug_util_win.cc b/base/debug/stack_trace_win.cc index b60ba31..653d234 100644 --- a/base/debug_util_win.cc +++ b/base/debug/stack_trace_win.cc @@ -1,8 +1,8 @@ -// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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_util.h" +#include "base/debug/stack_trace.h" #include <windows.h> #include <dbghelp.h> @@ -14,59 +14,10 @@ #include "base/logging.h" #include "base/singleton.h" -namespace { - -// Minimalist key reader. -// Note: Does not use the CRT. -bool RegReadString(HKEY root, const wchar_t* subkey, - const wchar_t* value_name, wchar_t* buffer, int* len) { - HKEY key = NULL; - DWORD res = RegOpenKeyEx(root, subkey, 0, KEY_READ, &key); - if (ERROR_SUCCESS != res || key == NULL) - return false; - - DWORD type = 0; - DWORD buffer_size = *len * sizeof(wchar_t); - // We don't support REG_EXPAND_SZ. - res = RegQueryValueEx(key, value_name, NULL, &type, - reinterpret_cast<BYTE*>(buffer), &buffer_size); - if (ERROR_SUCCESS == res && buffer_size != 0 && type == REG_SZ) { - // Make sure the buffer is NULL terminated. - buffer[*len - 1] = 0; - *len = lstrlen(buffer); - RegCloseKey(key); - return true; - } - RegCloseKey(key); - return false; -} - -// Replaces each "%ld" in input per a value. Not efficient but it works. -// Note: Does not use the CRT. -bool StringReplace(const wchar_t* input, int value, wchar_t* output, - int output_len) { - memset(output, 0, output_len*sizeof(wchar_t)); - int input_len = lstrlen(input); - - for (int i = 0; i < input_len; ++i) { - int current_output_len = lstrlen(output); +namespace base { +namespace debug { - if (input[i] == L'%' && input[i + 1] == L'l' && input[i + 2] == L'd') { - // Make sure we have enough place left. - if ((current_output_len + 12) >= output_len) - return false; - - // Cheap _itow(). - wsprintf(output+current_output_len, L"%d", value); - i += 2; - } else { - if (current_output_len >= output_len) - return false; - output[current_output_len] = input[i]; - } - } - return true; -} +namespace { // SymbolContext is a threadsafe singleton that wraps the DbgHelp Sym* family // of functions. The Sym* family of functions may only be invoked by one @@ -184,47 +135,6 @@ class SymbolContext { } // namespace -// Note: Does not use the CRT. -bool DebugUtil::SpawnDebuggerOnProcess(unsigned process_id) { - wchar_t reg_value[1026]; - int len = arraysize(reg_value); - if (RegReadString(HKEY_LOCAL_MACHINE, - L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug", - L"Debugger", reg_value, &len)) { - wchar_t command_line[1026]; - if (StringReplace(reg_value, process_id, command_line, - arraysize(command_line))) { - // We don't mind if the debugger is present because it will simply fail - // to attach to this process. - STARTUPINFO startup_info = {0}; - startup_info.cb = sizeof(startup_info); - PROCESS_INFORMATION process_info = {0}; - - if (CreateProcess(NULL, command_line, NULL, NULL, FALSE, 0, NULL, NULL, - &startup_info, &process_info)) { - CloseHandle(process_info.hThread); - WaitForInputIdle(process_info.hProcess, 10000); - CloseHandle(process_info.hProcess); - return true; - } - } - } - return false; -} - -// static -bool DebugUtil::BeingDebugged() { - return ::IsDebuggerPresent() != 0; -} - -// static -void DebugUtil::BreakDebugger() { - if (suppress_dialogs_) - _exit(1); - - __debugbreak(); -} - StackTrace::StackTrace() { // When walking our own stack, use CaptureStackBackTrace(). count_ = CaptureStackBackTrace(0, arraysize(trace_), trace_, NULL); @@ -282,3 +192,6 @@ void StackTrace::OutputToStream(std::ostream* os) { context->OutputTraceToStream(trace_, count_, os); } } + +} // namespace debug +} // namespace base diff --git a/base/trace_event.cc b/base/debug/trace_event.cc index 6388c8c..4d1d315 100644 --- a/base/trace_event.cc +++ b/base/debug/trace_event.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "base/trace_event.h" +#include "base/debug/trace_event.h" #include "base/format_macros.h" #include "base/file_path.h" @@ -17,6 +17,7 @@ #define USE_UNRELIABLE_NOW namespace base { +namespace debug { static const char* kEventTypeNames[] = { "BEGIN", @@ -161,4 +162,5 @@ void TraceLog::Log(const std::string& msg) { fprintf(log_file_, "%s", msg.c_str()); } -} // namespace base +} // namespace debug +} // namespace base diff --git a/base/trace_event.h b/base/debug/trace_event.h index caa260d..49ba4bd 100644 --- a/base/trace_event.h +++ b/base/debug/trace_event.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -12,8 +12,8 @@ // trace report. In the future, it may use another mechansim to facilitate // real-time analysis. -#ifndef BASE_TRACE_EVENT_H_ -#define BASE_TRACE_EVENT_H_ +#ifndef BASE_DEBUG_TRACE_EVENT_H_ +#define BASE_DEBUG_TRACE_EVENT_H_ #pragma once #include "build/build_config.h" @@ -26,7 +26,7 @@ // value of the CHROMIUM_ENABLE_TRACE_EVENT define. The Windows implementation // is controlled by Event Tracing for Windows, which will turn tracing on only // if there is someone listening for the events it generates. -#include "base/trace_event_win.h" +#include "base/debug/trace_event_win.h" #else // defined(OS_WIN) #include <string> @@ -52,38 +52,41 @@ // Record that an event (of name, id) has begun. All BEGIN events should have // corresponding END events with a matching (name, id). #define TRACE_EVENT_BEGIN(name, id, extra) \ - Singleton<base::TraceLog>::get()->Trace(name, \ - base::TraceLog::EVENT_BEGIN, \ - reinterpret_cast<const void*>(id), \ - extra, \ - __FILE__, \ - __LINE__) + Singleton<base::debug::TraceLog>::get()->Trace( \ + name, \ + base::debug::TraceLog::EVENT_BEGIN, \ + reinterpret_cast<const void*>(id), \ + extra, \ + __FILE__, \ + __LINE__) // Record that an event (of name, id) has ended. All END events should have // corresponding BEGIN events with a matching (name, id). #define TRACE_EVENT_END(name, id, extra) \ - Singleton<base::TraceLog>::get()->Trace(name, \ - base::TraceLog::EVENT_END, \ - reinterpret_cast<const void*>(id), \ - extra, \ - __FILE__, \ - __LINE__) + Singleton<base::debug::TraceLog>::get()->Trace( \ + name, \ + base::debug::TraceLog::EVENT_END, \ + reinterpret_cast<const void*>(id), \ + extra, \ + __FILE__, \ + __LINE__) // Record that an event (of name, id) with no duration has happened. #define TRACE_EVENT_INSTANT(name, id, extra) \ - Singleton<base::TraceLog>::get()->Trace(name, \ - base::TraceLog::EVENT_INSTANT, \ - reinterpret_cast<const void*>(id), \ - extra, \ - __FILE__, \ - __LINE__) + Singleton<base::debug::TraceLog>::get()->Trace( \ + name, \ + base::debug::TraceLog::EVENT_INSTANT, \ + reinterpret_cast<const void*>(id), \ + extra, \ + __FILE__, \ + __LINE__) #endif // CHROMIUM_ENABLE_TRACE_EVENT namespace base { + class ProcessMetrics; -} -namespace base { +namespace debug { class TraceLog { public: @@ -136,7 +139,9 @@ class TraceLog { RepeatingTimer<TraceLog> timer_; }; -} // namespace base +} // namespace debug +} // namespace base + #endif // defined(OS_WIN) -#endif // BASE_TRACE_EVENT_H_ +#endif // BASE_DEBUG_TRACE_EVENT_H_ diff --git a/base/trace_event_win.cc b/base/debug/trace_event_win.cc index 7217283..129a992 100644 --- a/base/trace_event_win.cc +++ b/base/debug/trace_event_win.cc @@ -1,13 +1,15 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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/trace_event_win.h" + +#include "base/debug/trace_event_win.h" #include "base/logging.h" #include "base/singleton.h" #include <initguid.h> // NOLINT namespace base { +namespace debug { // {3DADA31D-19EF-4dc1-B345-037927193422} const GUID kChromeTraceProviderName = { @@ -22,7 +24,7 @@ const GUID kTraceEventClass64 = { 0x97be602d, 0x2930, 0x4ac3, 0x80, 0x46, 0xb6, 0x76, 0x3b, 0x63, 0x1d, 0xfe}; -TraceLog::TraceLog() : EtwTraceProvider(base::kChromeTraceProviderName) { +TraceLog::TraceLog() : EtwTraceProvider(kChromeTraceProviderName) { Register(); } @@ -36,7 +38,7 @@ bool TraceLog::StartTracing() { void TraceLog::TraceEvent(const char* name, size_t name_len, - base::TraceLog::EventType type, + EventType type, const void* id, const char* extra, size_t extra_len) { @@ -48,24 +50,24 @@ void TraceLog::TraceEvent(const char* name, EtwEventType etw_type = 0; switch (type) { - case base::TraceLog::EVENT_BEGIN: - etw_type = base::kTraceEventTypeBegin; + case TraceLog::EVENT_BEGIN: + etw_type = kTraceEventTypeBegin; break; - case base::TraceLog::EVENT_END: - etw_type = base::kTraceEventTypeEnd; + case TraceLog::EVENT_END: + etw_type = kTraceEventTypeEnd; break; - case base::TraceLog::EVENT_INSTANT: - etw_type = base::kTraceEventTypeInstant; + case TraceLog::EVENT_INSTANT: + etw_type = kTraceEventTypeInstant; break; default: NOTREACHED() << "Unknown event type"; - etw_type = base::kTraceEventTypeInstant; + etw_type = kTraceEventTypeInstant; break; } - EtwMofEvent<5> event(base::kTraceEventClass32, + EtwMofEvent<5> event(kTraceEventClass32, etw_type, TRACE_LEVEL_INFORMATION); event.SetField(0, name_len + 1, name); @@ -74,7 +76,7 @@ void TraceLog::TraceEvent(const char* name, // See whether we're to capture a backtrace. void* backtrace[32]; - if (enable_flags() & base::CAPTURE_STACK_TRACE) { + if (enable_flags() & CAPTURE_STACK_TRACE) { DWORD hash = 0; DWORD depth = CaptureStackBackTrace(0, arraysize(backtrace), @@ -110,4 +112,5 @@ void TraceLog::Resurrect() { StaticMemorySingletonTraits<TraceLog>::Resurrect(); } +} // namespace debug } // namespace base diff --git a/base/trace_event_win.h b/base/debug/trace_event_win.h index 77ab3fb..669667b 100644 --- a/base/trace_event_win.h +++ b/base/debug/trace_event_win.h @@ -3,36 +3,40 @@ // found in the LICENSE file. // This file contains the Windows-specific declarations for trace_event.h. -#ifndef BASE_TRACE_EVENT_WIN_H_ -#define BASE_TRACE_EVENT_WIN_H_ +#ifndef BASE_DEBUG_TRACE_EVENT_WIN_H_ +#define BASE_DEBUG_TRACE_EVENT_WIN_H_ #pragma once #include <string> #include "base/event_trace_provider_win.h" #define TRACE_EVENT_BEGIN(name, id, extra) \ - base::TraceLog::Trace(name, \ - base::TraceLog::EVENT_BEGIN, \ - reinterpret_cast<const void*>(id), \ - extra); + base::debug::TraceLog::Trace( \ + name, \ + base::debug::TraceLog::EVENT_BEGIN, \ + reinterpret_cast<const void*>(id), \ + extra); #define TRACE_EVENT_END(name, id, extra) \ - base::TraceLog::Trace(name, \ - base::TraceLog::EVENT_END, \ - reinterpret_cast<const void*>(id), \ - extra); + base::debug::TraceLog::Trace( \ + name, \ + base::debug::TraceLog::EVENT_END, \ + reinterpret_cast<const void*>(id), \ + extra); #define TRACE_EVENT_INSTANT(name, id, extra) \ - base::TraceLog::Trace(name, \ - base::TraceLog::EVENT_INSTANT, \ - reinterpret_cast<const void*>(id), \ - extra); + base::debug::TraceLog::Trace( \ + name, \ + base::debug::TraceLog::EVENT_INSTANT, \ + reinterpret_cast<const void*>(id), \ + extra); // Fwd. template <typename Type> struct StaticMemorySingletonTraits; namespace base { +namespace debug { // This EtwTraceProvider subclass implements ETW logging // for the macros above on Windows. @@ -95,7 +99,7 @@ class TraceLog : public EtwTraceProvider { // string will be used. void TraceEvent(const char* name, size_t name_len, - base::TraceLog::EventType type, + EventType type, const void* id, const char* extra, size_t extra_len); @@ -141,6 +145,7 @@ enum TraceEventFlags { // Forward decl. struct TraceLogSingletonTraits; +} // nemspace debug } // namespace base -#endif // BASE_TRACE_EVENT_WIN_H_ +#endif // BASE_DEBUG_TRACE_EVENT_WIN_H_ diff --git a/base/trace_event_win_unittest.cc b/base/debug/trace_event_win_unittest.cc index 79a48e3..a818b9b 100644 --- a/base/trace_event_win_unittest.cc +++ b/base/debug/trace_event_win_unittest.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "base/trace_event.h" +#include "base/debug/trace_event.h" #include <strstream> @@ -16,7 +16,11 @@ #include "testing/gtest/include/gtest/gtest.h" #include <initguid.h> // NOLINT - must be last include. +namespace base { +namespace debug { + namespace { + using testing::_; using testing::AnyNumber; using testing::InSequence; @@ -81,7 +85,7 @@ class TraceEventTest: public testing::Test { } void SetUp() { - bool is_xp = base::win::GetVersion() < base::win::VERSION_VISTA; + bool is_xp = win::GetVersion() < base::win::VERSION_VISTA; if (is_xp) { // Tear down any dangling session from an earlier failing test. @@ -94,10 +98,10 @@ class TraceEventTest: public testing::Test { // start the private, in-proc session, but on XP we need the global // session created and the provider enabled before we register our // provider. - base::TraceLog* tracelog = NULL; + TraceLog* tracelog = NULL; if (!is_xp) { - base::TraceLog::Resurrect(); - tracelog = base::TraceLog::Get(); + TraceLog::Resurrect(); + tracelog = TraceLog::Get(); ASSERT_TRUE(tracelog != NULL); ASSERT_FALSE(tracelog->IsTracing()); } @@ -127,13 +131,13 @@ class TraceEventTest: public testing::Test { // Enable the TraceLog provider GUID. ASSERT_HRESULT_SUCCEEDED( - controller_.EnableProvider(base::kChromeTraceProviderName, + controller_.EnableProvider(kChromeTraceProviderName, TRACE_LEVEL_INFORMATION, 0)); if (is_xp) { - base::TraceLog::Resurrect(); - tracelog = base::TraceLog::Get(); + TraceLog::Resurrect(); + tracelog = TraceLog::Get(); } ASSERT_TRUE(tracelog != NULL); EXPECT_TRUE(tracelog->IsTracing()); @@ -186,7 +190,7 @@ class TraceEventTest: public testing::Test { private: // We want our singleton torn down after each test. - base::ShadowingAtExitManager at_exit_manager_; + ShadowingAtExitManager at_exit_manager_; EtwTraceController controller_; FilePath log_file_; TestEventConsumer consumer_; @@ -202,67 +206,67 @@ TEST_F(TraceEventTest, TraceLog) { InSequence in_sequence; // Full argument version, passing lengths explicitly. - base::TraceLog::Trace(kName, + TraceLog::Trace(kName, strlen(kName), - base::TraceLog::EVENT_BEGIN, + TraceLog::EVENT_BEGIN, kId, kExtra, strlen(kExtra)); - ExpectEvent(base::kTraceEventClass32, - base::kTraceEventTypeBegin, + ExpectEvent(kTraceEventClass32, + kTraceEventTypeBegin, kName, strlen(kName), kId, kExtra, strlen(kExtra)); // Const char* version. - base::TraceLog::Trace(static_cast<const char*>(kName), - base::TraceLog::EVENT_END, + TraceLog::Trace(static_cast<const char*>(kName), + TraceLog::EVENT_END, kId, static_cast<const char*>(kExtra)); - ExpectEvent(base::kTraceEventClass32, - base::kTraceEventTypeEnd, + ExpectEvent(kTraceEventClass32, + kTraceEventTypeEnd, kName, strlen(kName), kId, kExtra, strlen(kExtra)); // std::string extra version. - base::TraceLog::Trace(static_cast<const char*>(kName), - base::TraceLog::EVENT_INSTANT, + TraceLog::Trace(static_cast<const char*>(kName), + TraceLog::EVENT_INSTANT, kId, std::string(kExtra)); - ExpectEvent(base::kTraceEventClass32, - base::kTraceEventTypeInstant, + ExpectEvent(kTraceEventClass32, + kTraceEventTypeInstant, kName, strlen(kName), kId, kExtra, strlen(kExtra)); // Test for sanity on NULL inputs. - base::TraceLog::Trace(NULL, + TraceLog::Trace(NULL, 0, - base::TraceLog::EVENT_BEGIN, + TraceLog::EVENT_BEGIN, kId, NULL, 0); - ExpectEvent(base::kTraceEventClass32, - base::kTraceEventTypeBegin, + ExpectEvent(kTraceEventClass32, + kTraceEventTypeBegin, kEmpty, 0, kId, kEmpty, 0); - base::TraceLog::Trace(NULL, + TraceLog::Trace(NULL, -1, - base::TraceLog::EVENT_END, + TraceLog::EVENT_END, kId, NULL, -1); - ExpectEvent(base::kTraceEventClass32, - base::kTraceEventTypeEnd, + ExpectEvent(kTraceEventClass32, + kTraceEventTypeEnd, kEmpty, 0, kId, kEmpty, 0); @@ -277,25 +281,28 @@ TEST_F(TraceEventTest, Macros) { InSequence in_sequence; TRACE_EVENT_BEGIN(kName, kId, kExtra); - ExpectEvent(base::kTraceEventClass32, - base::kTraceEventTypeBegin, + ExpectEvent(kTraceEventClass32, + kTraceEventTypeBegin, kName, strlen(kName), kId, kExtra, strlen(kExtra)); TRACE_EVENT_END(kName, kId, kExtra); - ExpectEvent(base::kTraceEventClass32, - base::kTraceEventTypeEnd, + ExpectEvent(kTraceEventClass32, + kTraceEventTypeEnd, kName, strlen(kName), kId, kExtra, strlen(kExtra)); TRACE_EVENT_INSTANT(kName, kId, kExtra); - ExpectEvent(base::kTraceEventClass32, - base::kTraceEventTypeInstant, + ExpectEvent(kTraceEventClass32, + kTraceEventTypeInstant, kName, strlen(kName), kId, kExtra, strlen(kExtra)); PlayLog(); } + +} // namespace debug +} // namespace base diff --git a/base/debug_on_start.cc b/base/debug_on_start.cc index 9cabde5..15dab05 100644 --- a/base/debug_on_start.cc +++ b/base/debug_on_start.cc @@ -8,7 +8,7 @@ #include "base/base_switches.h" #include "base/basictypes.h" -#include "base/debug_util.h" +#include "base/debug/debugger.h" // Minimalist implementation to try to find a command line argument. We can use // kernel32 exported functions but not the CRT functions because we're too early @@ -56,13 +56,13 @@ int __cdecl DebugOnStart::Init() { // - Do a int3. // It will fails if we run in a sandbox. That is expected. - DebugUtil::SpawnDebuggerOnProcess(GetCurrentProcessId()); + base::debug::SpawnDebuggerOnProcess(GetCurrentProcessId()); // Wait for a debugger to come take us. - DebugUtil::WaitForDebugger(60, false); + base::debug::WaitForDebugger(60, false); } else if (FindArgument(GetCommandLine(), switches::kWaitForDebugger)) { // Wait for a debugger to come take us. - DebugUtil::WaitForDebugger(60, true); + base::debug::WaitForDebugger(60, true); } return 0; } diff --git a/base/debug_util.cc b/base/debug_util.cc index 21f5b70..4773de3 100644 --- a/base/debug_util.cc +++ b/base/debug_util.cc @@ -4,25 +4,4 @@ #include "base/debug_util.h" -#include "base/platform_thread.h" - bool DebugUtil::suppress_dialogs_ = false; - -bool DebugUtil::WaitForDebugger(int wait_seconds, bool silent) { - for (int i = 0; i < wait_seconds * 10; ++i) { - if (BeingDebugged()) { - if (!silent) - BreakDebugger(); - return true; - } - PlatformThread::Sleep(100); - } - return false; -} - -const void *const *StackTrace::Addresses(size_t* count) { - *count = count_; - if (count_) - return trace_; - return NULL; -} diff --git a/base/debug_util.h b/base/debug_util.h index a7dba3a..a643ccf 100644 --- a/base/debug_util.h +++ b/base/debug_util.h @@ -2,78 +2,14 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// This is a cross platform interface for helper functions related to debuggers. -// You should use this to test if you're running under a debugger, and if you -// would like to yield (breakpoint) into the debugger. - #ifndef BASE_DEBUG_UTIL_H_ #define BASE_DEBUG_UTIL_H_ #pragma once -#include <iosfwd> - -#include "base/basictypes.h" - -#if defined(OS_WIN) -struct _EXCEPTION_POINTERS; -#endif - -// A stacktrace can be helpful in debugging. For example, you can include a -// stacktrace member in a object (probably around #ifndef NDEBUG) so that you -// can later see where the given object was created from. -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 - // on system without dbghelp 5.1. - StackTrace(_EXCEPTION_POINTERS* exception_pointers); -#endif - // Gets an array of instruction pointer values. - // count: (output) the number of elements in the returned array - const void *const *Addresses(size_t* count); - // Prints a backtrace to stderr - void PrintBacktrace(); - - // Resolves backtrace to symbols and write to stream. - void OutputToStream(std::ostream* os); - - private: - // From http://msdn.microsoft.com/en-us/library/bb204633.aspx, - // the sum of FramesToSkip and FramesToCapture must be less than 63, - // so set it to 62. Even if on POSIX it could be a larger value, it usually - // doesn't give much more information. - static const int MAX_TRACES = 62; - void* trace_[MAX_TRACES]; - int count_; -}; +#include "build/build_config.h" class DebugUtil { public: - // Starts the registered system-wide JIT debugger to attach it to specified - // process. - static bool SpawnDebuggerOnProcess(unsigned process_id); - - // Waits wait_seconds seconds for a debugger to attach to the current process. - // When silent is false, an exception is thrown when a debugger is detected. - static bool WaitForDebugger(int wait_seconds, bool silent); - - // Are we running under a debugger? - // On OS X, the underlying mechanism doesn't work when the sandbox is enabled. - // To get around this, this function caches its value. - // WARNING: Because of this, on OS X, a call MUST be made to this function - // BEFORE the sandbox is enabled. - static bool BeingDebugged(); - - // Break into the debugger, assumes a debugger is present. - static void BreakDebugger(); - #if defined(OS_MACOSX) // On Mac OS X, it can take a really long time for the OS crash handler to // process a Chrome crash when debugging symbols are available. This @@ -87,6 +23,10 @@ class DebugUtil { suppress_dialogs_ = true; } + static bool AreDialogsSuppressed() { + return suppress_dialogs_; + } + private: // If true, avoid displaying any dialogs that could cause problems // in non-interactive environments. diff --git a/base/debug_util_mac.cc b/base/debug_util_mac.cc index 78679f2..a4eed66 100644 --- a/base/debug_util_mac.cc +++ b/base/debug_util_mac.cc @@ -5,6 +5,7 @@ #include "base/debug_util.h" #include <signal.h> +#include <unistd.h> #include "base/basictypes.h" diff --git a/base/leak_tracker_unittest.cc b/base/leak_tracker_unittest.cc deleted file mode 100644 index 0217b17..0000000 --- a/base/leak_tracker_unittest.cc +++ /dev/null @@ -1,107 +0,0 @@ -// Copyright (c) 2009 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/leak_tracker.h" -#include "base/scoped_ptr.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace { - -class ClassA { - private: - base::LeakTracker<ClassA> leak_tracker_; -}; - -class ClassB { - private: - base::LeakTracker<ClassB> leak_tracker_; -}; - -#ifndef ENABLE_LEAK_TRACKER - -// If leak tracking is disabled, we should do nothing. -TEST(LeakTrackerTest, NotEnabled) { - EXPECT_EQ(-1, base::LeakTracker<ClassA>::NumLiveInstances()); - EXPECT_EQ(-1, base::LeakTracker<ClassB>::NumLiveInstances()); - - // Use scoped_ptr so compiler doesn't complain about unused variables. - scoped_ptr<ClassA> a1(new ClassA); - scoped_ptr<ClassB> b1(new ClassB); - scoped_ptr<ClassB> b2(new ClassB); - - EXPECT_EQ(-1, base::LeakTracker<ClassA>::NumLiveInstances()); - EXPECT_EQ(-1, base::LeakTracker<ClassB>::NumLiveInstances()); -} - -#else - -TEST(LeakTrackerTest, Basic) { - { - ClassA a1; - - EXPECT_EQ(1, base::LeakTracker<ClassA>::NumLiveInstances()); - EXPECT_EQ(0, base::LeakTracker<ClassB>::NumLiveInstances()); - - ClassB b1; - ClassB b2; - - EXPECT_EQ(1, base::LeakTracker<ClassA>::NumLiveInstances()); - EXPECT_EQ(2, base::LeakTracker<ClassB>::NumLiveInstances()); - - scoped_ptr<ClassA> a2(new ClassA); - - EXPECT_EQ(2, base::LeakTracker<ClassA>::NumLiveInstances()); - EXPECT_EQ(2, base::LeakTracker<ClassB>::NumLiveInstances()); - - a2.reset(); - - EXPECT_EQ(1, base::LeakTracker<ClassA>::NumLiveInstances()); - EXPECT_EQ(2, base::LeakTracker<ClassB>::NumLiveInstances()); - } - - EXPECT_EQ(0, base::LeakTracker<ClassA>::NumLiveInstances()); - EXPECT_EQ(0, base::LeakTracker<ClassB>::NumLiveInstances()); -} - -// Try some orderings of create/remove to hit different cases in the linked-list -// assembly. -TEST(LeakTrackerTest, LinkedList) { - EXPECT_EQ(0, base::LeakTracker<ClassB>::NumLiveInstances()); - - scoped_ptr<ClassA> a1(new ClassA); - scoped_ptr<ClassA> a2(new ClassA); - scoped_ptr<ClassA> a3(new ClassA); - scoped_ptr<ClassA> a4(new ClassA); - - EXPECT_EQ(4, base::LeakTracker<ClassA>::NumLiveInstances()); - - // Remove the head of the list (a1). - a1.reset(); - EXPECT_EQ(3, base::LeakTracker<ClassA>::NumLiveInstances()); - - // Remove the tail of the list (a4). - a4.reset(); - EXPECT_EQ(2, base::LeakTracker<ClassA>::NumLiveInstances()); - - // Append to the new tail of the list (a3). - scoped_ptr<ClassA> a5(new ClassA); - EXPECT_EQ(3, base::LeakTracker<ClassA>::NumLiveInstances()); - - a2.reset(); - a3.reset(); - - EXPECT_EQ(1, base::LeakTracker<ClassA>::NumLiveInstances()); - - a5.reset(); - EXPECT_EQ(0, base::LeakTracker<ClassA>::NumLiveInstances()); -} - -TEST(LeakTrackerTest, NoOpCheckForLeaks) { - // There are no live instances of ClassA, so this should do nothing. - base::LeakTracker<ClassA>::CheckForLeaks(); -} - -#endif // ENABLE_LEAK_TRACKER - -} // namespace diff --git a/base/logging.cc b/base/logging.cc index 273162f..a6b52a7 100644 --- a/base/logging.cc +++ b/base/logging.cc @@ -42,7 +42,8 @@ typedef pthread_mutex_t* MutexHandle; #include "base/base_switches.h" #include "base/command_line.h" -#include "base/debug_util.h" +#include "base/debug/debugger.h" +#include "base/debug/stack_trace.h" #include "base/eintr_wrapper.h" #include "base/lock_impl.h" #if defined(OS_POSIX) @@ -220,7 +221,7 @@ class LoggingLock { #if DEBUG // Keep the error code for debugging int error = GetLastError(); // NOLINT - DebugUtil::BreakDebugger(); + base::debug::BreakDebugger(); #endif // Return nicely without putting initialized to true. return; @@ -580,7 +581,7 @@ LogMessage::~LogMessage() { #ifndef NDEBUG if (severity_ == LOG_FATAL) { // Include a stack trace on a fatal. - StackTrace trace; + base::debug::StackTrace trace; stream_ << std::endl; // Newline to separate from log message. trace.OutputToStream(&stream_); } @@ -637,8 +638,8 @@ LogMessage::~LogMessage() { if (severity_ == LOG_FATAL) { // display a message or break into the debugger on a fatal error - if (DebugUtil::BeingDebugged()) { - DebugUtil::BreakDebugger(); + if (base::debug::BeingDebugged()) { + base::debug::BreakDebugger(); } else { if (log_assert_handler) { // make a copy of the string for the handler out of paranoia @@ -653,7 +654,7 @@ LogMessage::~LogMessage() { DisplayDebugMessageInDialog(stream_.str()); #endif // Crash the process to generate a dump. - DebugUtil::BreakDebugger(); + base::debug::BreakDebugger(); } } } else if (severity_ == LOG_ERROR_REPORT) { @@ -792,7 +793,7 @@ void RawLog(int level, const char* message) { } if (level == LOG_FATAL) - DebugUtil::BreakDebugger(); + base::debug::BreakDebugger(); } } // namespace logging diff --git a/base/process_util_mac.mm b/base/process_util_mac.mm index cae47bf..b167aa22 100644 --- a/base/process_util_mac.mm +++ b/base/process_util_mac.mm @@ -23,7 +23,7 @@ #include <new> #include <string> -#include "base/debug_util.h" +#include "base/debug/debugger.h" #include "base/eintr_wrapper.h" #include "base/logging.h" #include "base/string_util.h" @@ -166,7 +166,7 @@ bool ProcessIterator::CheckForNextProcess() { } bool NamedProcessIterator::IncludeEntry() { - return (base::SysWideToUTF8(executable_name_) == entry().exe_file() && + return (SysWideToUTF8(executable_name_) == entry().exe_file() && ProcessIterator::IncludeEntry()); } @@ -187,7 +187,7 @@ ProcessMetrics::ProcessMetrics(ProcessHandle process, last_time_(0), last_system_time_(0), port_provider_(port_provider) { - processor_count_ = base::SysInfo::NumberOfProcessors(); + processor_count_ = SysInfo::NumberOfProcessors(); } // static @@ -402,7 +402,7 @@ void* oom_killer_malloc(struct _malloc_zone_t* zone, size_t size) { void* result = g_old_malloc(zone, size); if (!result && size) - DebugUtil::BreakDebugger(); + debug::BreakDebugger(); return result; } @@ -411,7 +411,7 @@ void* oom_killer_calloc(struct _malloc_zone_t* zone, size_t size) { void* result = g_old_calloc(zone, num_items, size); if (!result && num_items && size) - DebugUtil::BreakDebugger(); + debug::BreakDebugger(); return result; } @@ -419,7 +419,7 @@ void* oom_killer_valloc(struct _malloc_zone_t* zone, size_t size) { void* result = g_old_valloc(zone, size); if (!result && size) - DebugUtil::BreakDebugger(); + debug::BreakDebugger(); return result; } @@ -428,7 +428,7 @@ void* oom_killer_realloc(struct _malloc_zone_t* zone, size_t size) { void* result = g_old_realloc(zone, ptr, size); if (!result && size) - DebugUtil::BreakDebugger(); + debug::BreakDebugger(); return result; } @@ -441,7 +441,7 @@ void* oom_killer_memalign(struct _malloc_zone_t* zone, // http://opensource.apple.com/source/Libc/Libc-583/gen/malloc.c ). if (!result && size && alignment >= sizeof(void*) && (alignment & (alignment - 1)) == 0) { - DebugUtil::BreakDebugger(); + debug::BreakDebugger(); } return result; } @@ -450,7 +450,7 @@ void* oom_killer_malloc_purgeable(struct _malloc_zone_t* zone, size_t size) { void* result = g_old_malloc_purgeable(zone, size); if (!result && size) - DebugUtil::BreakDebugger(); + debug::BreakDebugger(); return result; } @@ -459,7 +459,7 @@ void* oom_killer_calloc_purgeable(struct _malloc_zone_t* zone, size_t size) { void* result = g_old_calloc_purgeable(zone, num_items, size); if (!result && num_items && size) - DebugUtil::BreakDebugger(); + debug::BreakDebugger(); return result; } @@ -467,7 +467,7 @@ void* oom_killer_valloc_purgeable(struct _malloc_zone_t* zone, size_t size) { void* result = g_old_valloc_purgeable(zone, size); if (!result && size) - DebugUtil::BreakDebugger(); + debug::BreakDebugger(); return result; } @@ -476,7 +476,7 @@ void* oom_killer_realloc_purgeable(struct _malloc_zone_t* zone, size_t size) { void* result = g_old_realloc_purgeable(zone, ptr, size); if (!result && size) - DebugUtil::BreakDebugger(); + debug::BreakDebugger(); return result; } @@ -489,7 +489,7 @@ void* oom_killer_memalign_purgeable(struct _malloc_zone_t* zone, // http://opensource.apple.com/source/Libc/Libc-583/gen/malloc.c ). if (!result && size && alignment >= sizeof(void*) && (alignment & (alignment - 1)) == 0) { - DebugUtil::BreakDebugger(); + debug::BreakDebugger(); } return result; } @@ -497,7 +497,7 @@ void* oom_killer_memalign_purgeable(struct _malloc_zone_t* zone, // === C++ operator new === void oom_killer_new() { - DebugUtil::BreakDebugger(); + debug::BreakDebugger(); } // === Core Foundation CFAllocators === @@ -513,7 +513,7 @@ void* oom_killer_cfallocator_system_default(CFIndex alloc_size, void* info) { void* result = g_old_cfallocator_system_default(alloc_size, hint, info); if (!result) - DebugUtil::BreakDebugger(); + debug::BreakDebugger(); return result; } @@ -522,7 +522,7 @@ void* oom_killer_cfallocator_malloc(CFIndex alloc_size, void* info) { void* result = g_old_cfallocator_malloc(alloc_size, hint, info); if (!result) - DebugUtil::BreakDebugger(); + debug::BreakDebugger(); return result; } @@ -531,7 +531,7 @@ void* oom_killer_cfallocator_malloc_zone(CFIndex alloc_size, void* info) { void* result = g_old_cfallocator_malloc_zone(alloc_size, hint, info); if (!result) - DebugUtil::BreakDebugger(); + debug::BreakDebugger(); return result; } @@ -544,7 +544,7 @@ id oom_killer_allocWithZone(id self, SEL _cmd, NSZone* zone) { id result = g_old_allocWithZone(self, _cmd, zone); if (!result) - DebugUtil::BreakDebugger(); + debug::BreakDebugger(); return result; } diff --git a/base/process_util_posix.cc b/base/process_util_posix.cc index b1dbabd..07e3125 100644 --- a/base/process_util_posix.cc +++ b/base/process_util_posix.cc @@ -18,7 +18,7 @@ #include "base/command_line.h" #include "base/compiler_specific.h" -#include "base/debug_util.h" +#include "base/debug/stack_trace.h" #include "base/dir_reader_posix.h" #include "base/eintr_wrapper.h" #include "base/logging.h" @@ -103,7 +103,7 @@ int WaitpidWithTimeout(ProcessHandle handle, int64 wait_milliseconds, void StackDumpSignalHandler(int signal) { LOG(ERROR) << "Received signal " << signal; - StackTrace().PrintBacktrace(); + debug::StackTrace().PrintBacktrace(); _exit(1); } diff --git a/base/process_util_win.cc b/base/process_util_win.cc index 92077b1..097888e 100644 --- a/base/process_util_win.cc +++ b/base/process_util_win.cc @@ -13,7 +13,7 @@ #include <ios> #include "base/command_line.h" -#include "base/debug_util.h" +#include "base/debug/stack_trace.h" #include "base/logging.h" #include "base/metrics/histogram.h" #include "base/scoped_ptr.h" @@ -40,7 +40,7 @@ LPTOP_LEVEL_EXCEPTION_FILTER g_previous_filter = NULL; // Prints the exception call stack. // This is the unit tests exception filter. long WINAPI StackDumpExceptionFilter(EXCEPTION_POINTERS* info) { - StackTrace(info).PrintBacktrace(); + debug::StackTrace(info).PrintBacktrace(); if (g_previous_filter) return g_previous_filter(info); return EXCEPTION_CONTINUE_SEARCH; @@ -155,7 +155,7 @@ bool GetProcessIntegrityLevel(ProcessHandle process, IntegrityLevel *level) { if (!level) return false; - if (base::win::GetVersion() < base::win::VERSION_VISTA) + if (win::GetVersion() < base::win::VERSION_VISTA) return false; HANDLE process_token; @@ -163,7 +163,7 @@ bool GetProcessIntegrityLevel(ProcessHandle process, IntegrityLevel *level) { &process_token)) return false; - base::win::ScopedHandle scoped_process_token(process_token); + win::ScopedHandle scoped_process_token(process_token); DWORD token_info_length = 0; if (GetTokenInformation(process_token, TokenIntegrityLevel, NULL, 0, @@ -326,8 +326,8 @@ bool GetAppOutput(const CommandLine& cl, std::string* output) { } // Ensure we don't leak the handles. - base::win::ScopedHandle scoped_out_read(out_read); - base::win::ScopedHandle scoped_out_write(out_write); + win::ScopedHandle scoped_out_read(out_read); + win::ScopedHandle scoped_out_write(out_write); // Ensure the read handle to the pipe for STDOUT is not inherited. if (!SetHandleInformation(out_read, HANDLE_FLAG_INHERIT, 0)) { diff --git a/base/test/perf_test_suite.cc b/base/test/perf_test_suite.cc index b787add..232766a 100644 --- a/base/test/perf_test_suite.cc +++ b/base/test/perf_test_suite.cc @@ -5,7 +5,7 @@ #include "base/test/perf_test_suite.h" #include "base/command_line.h" -#include "base/debug_util.h" +#include "base/debug/debugger.h" #include "base/file_path.h" #include "base/path_service.h" #include "base/perftimer.h" @@ -34,7 +34,7 @@ void PerfTestSuite::Initialize() { // Raise to high priority to have more precise measurements. Since we don't // aim at 1% precision, it is not necessary to run at realtime level. - if (!DebugUtil::BeingDebugged()) + if (!base::debug::BeingDebugged()) base::RaiseProcessToHighPriority(); } diff --git a/base/test/test_suite.cc b/base/test/test_suite.cc index f2e6069..7d25a60 100644 --- a/base/test/test_suite.cc +++ b/base/test/test_suite.cc @@ -10,6 +10,8 @@ #include "base/command_line.h" #include "base/debug_on_start.h" #include "base/debug_util.h" +#include "base/debug/debugger.h" +#include "base/debug/debugger.h" #include "base/file_path.h" #include "base/i18n/icu_util.h" #include "base/logging.h" @@ -191,7 +193,7 @@ void TestSuite::Initialize() { #endif // defined(OS_WIN) // In some cases, we do not want to see standard error dialogs. - if (!DebugUtil::BeingDebugged() && + if (!base::debug::BeingDebugged() && !CommandLine::ForCurrentProcess()->HasSwitch("show-error-dialogs")) { SuppressErrorDialogs(); DebugUtil::SuppressDialogs(); diff --git a/chrome/app/chrome_dll_main.cc b/chrome/app/chrome_dll_main.cc index 0d59516..a3923b4 100644 --- a/chrome/app/chrome_dll_main.cc +++ b/chrome/app/chrome_dll_main.cc @@ -38,6 +38,7 @@ #include "base/at_exit.h" #include "base/command_line.h" #include "base/debug_util.h" +#include "base/debug/debugger.h" #include "base/i18n/icu_util.h" #include "base/mac/scoped_nsautorelease_pool.h" #include "base/message_loop.h" @@ -627,9 +628,10 @@ int ChromeMain(int argc, char** argv) { // console) but doesn't for the child processes, killing them. // The fix is to have child processes ignore SIGINT; they'll die // on their own when the browser process goes away. - // Note that we *can't* rely on DebugUtil::BeingDebugged to catch this - // case because we are the child process, which is not being debugged. - if (!DebugUtil::BeingDebugged()) + // + // Note that we *can't* rely on BeingDebugged to catch this case because we + // are the child process, which is not being debugged. + if (!base::debug::BeingDebugged()) signal(SIGINT, SIG_IGN); #endif } diff --git a/chrome/app/client_util.cc b/chrome/app/client_util.cc index 61d8c40..1741cb6 100644 --- a/chrome/app/client_util.cc +++ b/chrome/app/client_util.cc @@ -6,9 +6,9 @@ #include <shlwapi.h> #include "base/command_line.h" +#include "base/debug/trace_event.h" #include "base/environment.h" #include "base/file_util.h" -#include "base/trace_event.h" #include "base/logging.h" #include "base/scoped_ptr.h" #include "base/utf_string_conversions.h" diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc index 4c1d795..24b2048 100644 --- a/chrome/browser/automation/automation_provider.cc +++ b/chrome/browser/automation/automation_provider.cc @@ -8,6 +8,7 @@ #include "app/message_box_flags.h" #include "base/callback.h" +#include "base/debug/trace_event.h" #include "base/file_path.h" #include "base/json/json_reader.h" #include "base/json/json_writer.h" @@ -19,7 +20,6 @@ #include "base/string_util.h" #include "base/task.h" #include "base/thread.h" -#include "base/trace_event.h" #include "base/string_number_conversions.h" #include "base/utf_string_conversions.h" #include "base/values.h" diff --git a/chrome/browser/automation/automation_provider_win.cc b/chrome/browser/automation/automation_provider_win.cc index 3a30d25..7843c83 100644 --- a/chrome/browser/automation/automation_provider_win.cc +++ b/chrome/browser/automation/automation_provider_win.cc @@ -5,8 +5,8 @@ #include "chrome/browser/automation/automation_provider.h" #include "app/keyboard_codes.h" +#include "base/debug/trace_event.h" #include "base/json/json_reader.h" -#include "base/trace_event.h" #include "base/utf_string_conversions.h" #include "chrome/browser/automation/automation_browser_tracker.h" #include "chrome/browser/automation/automation_extension_function.h" diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc index 6381056..6e14230 100644 --- a/chrome/browser/browser_main.cc +++ b/chrome/browser/browser_main.cc @@ -14,6 +14,7 @@ #include "app/system_monitor.h" #include "base/at_exit.h" #include "base/command_line.h" +#include "base/debug/trace_event.h" #include "base/file_path.h" #include "base/file_util.h" #include "base/mac/scoped_nsautorelease_pool.h" @@ -28,7 +29,6 @@ #include "base/string_util.h" #include "base/sys_string_conversions.h" #include "base/time.h" -#include "base/trace_event.h" #include "base/utf_string_conversions.h" #include "base/values.h" #include "build/build_config.h" diff --git a/chrome/browser/browser_main_gtk.cc b/chrome/browser/browser_main_gtk.cc index 9f98f35..8790726 100644 --- a/chrome/browser/browser_main_gtk.cc +++ b/chrome/browser/browser_main_gtk.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -7,7 +7,7 @@ #include "app/x11_util.h" #include "app/x11_util_internal.h" #include "base/command_line.h" -#include "base/debug_util.h" +#include "base/debug/debugger.h" #include "chrome/browser/browser_list.h" #include "chrome/browser/browser_main_gtk.h" #include "chrome/browser/browser_main_win.h" @@ -51,7 +51,7 @@ void RecordBreakpadStatusUMA(MetricsService* metrics) { #else metrics->RecordBreakpadRegistration(false); #endif - metrics->RecordBreakpadHasDebugger(DebugUtil::BeingDebugged()); + metrics->RecordBreakpadHasDebugger(base::debug::BeingDebugged()); } void WarnAboutMinimumSystemRequirements() { diff --git a/chrome/browser/browser_main_mac.mm b/chrome/browser/browser_main_mac.mm index a00c47b..37c5246 100644 --- a/chrome/browser/browser_main_mac.mm +++ b/chrome/browser/browser_main_mac.mm @@ -10,7 +10,7 @@ #include "app/l10n_util_mac.h" #include "app/resource_bundle.h" #include "base/command_line.h" -#include "base/debug_util.h" +#include "base/debug/debugger.h" #include "base/file_path.h" #include "base/mac_util.h" #include "base/nss_util.h" @@ -36,7 +36,7 @@ void DidEndMainMessageLoop() { void RecordBreakpadStatusUMA(MetricsService* metrics) { metrics->RecordBreakpadRegistration(IsCrashReporterEnabled()); - metrics->RecordBreakpadHasDebugger(DebugUtil::BeingDebugged()); + metrics->RecordBreakpadHasDebugger(base::debug::BeingDebugged()); } void WarnAboutMinimumSystemRequirements() { diff --git a/chrome/browser/cocoa/chrome_browser_window_unittest.mm b/chrome/browser/cocoa/chrome_browser_window_unittest.mm index 2b82f79..fc39ccd 100644 --- a/chrome/browser/cocoa/chrome_browser_window_unittest.mm +++ b/chrome/browser/cocoa/chrome_browser_window_unittest.mm @@ -4,6 +4,7 @@ #import <Cocoa/Cocoa.h> +#include "base/debug/debugger.h" #import "chrome/browser/cocoa/chrome_browser_window.h" #import "chrome/browser/cocoa/cocoa_test_helper.h" #include "testing/gtest/include/gtest/gtest.h" @@ -22,7 +23,7 @@ class ChromeBrowserWindowTest : public CocoaTest { styleMask:mask backing:NSBackingStoreBuffered defer:NO]; - if (DebugUtil::BeingDebugged()) { + if (base::debug::BeingDebugged()) { [window_ orderFront:nil]; } else { [window_ orderBack:nil]; diff --git a/chrome/browser/cocoa/chrome_event_processing_window_unittest.mm b/chrome/browser/cocoa/chrome_event_processing_window_unittest.mm index 1b54dcb..e1db1bc 100644 --- a/chrome/browser/cocoa/chrome_event_processing_window_unittest.mm +++ b/chrome/browser/cocoa/chrome_event_processing_window_unittest.mm @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. - +#include "base/debug/debugger.h" #include "base/scoped_nsobject.h" #include "chrome/app/chrome_dll_resource.h" #import "chrome/browser/cocoa/chrome_event_processing_window.h" @@ -38,7 +38,7 @@ class ChromeEventProcessingWindowTest : public CocoaTest { styleMask:mask backing:NSBackingStoreBuffered defer:NO]; - if (DebugUtil::BeingDebugged()) { + if (base::debug::BeingDebugged()) { [window_ orderFront:nil]; } else { [window_ orderBack:nil]; diff --git a/chrome/browser/cocoa/cocoa_test_helper.mm b/chrome/browser/cocoa/cocoa_test_helper.mm index 136412b..217be1b 100644 --- a/chrome/browser/cocoa/cocoa_test_helper.mm +++ b/chrome/browser/cocoa/cocoa_test_helper.mm @@ -4,6 +4,7 @@ #import "chrome/browser/cocoa/cocoa_test_helper.h" +#include "base/debug/debugger.h" #include "base/logging.h" #include "base/test/test_timeouts.h" #import "chrome/browser/chrome_browser_application_mac.h" @@ -184,7 +185,7 @@ std::set<NSWindow*> CocoaTest::WindowsLeft() { CocoaTestHelperWindow* CocoaTest::test_window() { if (!test_window_) { test_window_ = [[CocoaTestHelperWindow alloc] init]; - if (DebugUtil::BeingDebugged()) { + if (base::debug::BeingDebugged()) { [test_window_ orderFront:nil]; } else { [test_window_ orderBack:nil]; diff --git a/chrome/browser/cocoa/content_setting_bubble_cocoa_unittest.mm b/chrome/browser/cocoa/content_setting_bubble_cocoa_unittest.mm index c42520d..3485782 100644 --- a/chrome/browser/cocoa/content_setting_bubble_cocoa_unittest.mm +++ b/chrome/browser/cocoa/content_setting_bubble_cocoa_unittest.mm @@ -6,6 +6,7 @@ #import <Cocoa/Cocoa.h> +#include "base/debug/debugger.h" #include "base/scoped_nsobject.h" #import "chrome/browser/cocoa/cocoa_test_helper.h" #include "chrome/browser/content_setting_bubble_model.h" @@ -42,7 +43,7 @@ TEST_F(ContentSettingBubbleControllerTest, Init) { backing:NSBackingStoreBuffered defer:NO]); [parent setReleasedWhenClosed:NO]; - if (DebugUtil::BeingDebugged()) + if (base::debug::BeingDebugged()) [parent.get() orderFront:nil]; else [parent.get() orderBack:nil]; diff --git a/chrome/browser/cocoa/first_run_bubble_controller_unittest.mm b/chrome/browser/cocoa/first_run_bubble_controller_unittest.mm index a6009a6..094b1f6 100644 --- a/chrome/browser/cocoa/first_run_bubble_controller_unittest.mm +++ b/chrome/browser/cocoa/first_run_bubble_controller_unittest.mm @@ -6,6 +6,7 @@ #import <Cocoa/Cocoa.h> +#include "base/debug/debugger.h" #include "base/scoped_nsobject.h" #include "chrome/browser/cocoa/browser_test_helper.h" #import "chrome/browser/cocoa/cocoa_test_helper.h" @@ -26,7 +27,7 @@ TEST_F(FirstRunBubbleControllerTest, Init) { backing:NSBackingStoreBuffered defer:NO]); [parent setReleasedWhenClosed:NO]; - if (DebugUtil::BeingDebugged()) + if (base::debug::BeingDebugged()) [parent.get() orderFront:nil]; else [parent.get() orderBack:nil]; diff --git a/chrome/browser/cocoa/framed_browser_window_unittest.mm b/chrome/browser/cocoa/framed_browser_window_unittest.mm index ae9c329..bf46fdd 100644 --- a/chrome/browser/cocoa/framed_browser_window_unittest.mm +++ b/chrome/browser/cocoa/framed_browser_window_unittest.mm @@ -4,6 +4,7 @@ #import <Cocoa/Cocoa.h> +#include "base/debug/debugger.h" #include "base/scoped_nsobject.h" #include "chrome/app/chrome_dll_resource.h" #import "chrome/browser/cocoa/browser_window_controller.h" @@ -27,7 +28,7 @@ class FramedBrowserWindowTest : public CocoaTest { styleMask:mask backing:NSBackingStoreBuffered defer:NO]; - if (DebugUtil::BeingDebugged()) { + if (base::debug::BeingDebugged()) { [window_ orderFront:nil]; } else { [window_ orderBack:nil]; diff --git a/chrome/browser/cocoa/sad_tab_controller_unittest.mm b/chrome/browser/cocoa/sad_tab_controller_unittest.mm index c125f87..7797397 100644 --- a/chrome/browser/cocoa/sad_tab_controller_unittest.mm +++ b/chrome/browser/cocoa/sad_tab_controller_unittest.mm @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/debug/debugger.h" #include "base/scoped_nsobject.h" #import "chrome/browser/cocoa/cocoa_test_helper.h" #import "chrome/browser/cocoa/sad_tab_controller.h" @@ -35,7 +36,7 @@ class SadTabControllerTest : public RenderViewHostTestHarness { // from CocoaTest, so do a bootstrap and create test window. CocoaTest::BootstrapCocoa(); test_window_ = [[CocoaTestHelperWindow alloc] init]; - if (DebugUtil::BeingDebugged()) { + if (base::debug::BeingDebugged()) { [test_window_ orderFront:nil]; } else { [test_window_ orderBack:nil]; diff --git a/chrome/browser/external_tab_container_win.cc b/chrome/browser/external_tab_container_win.cc index ffa0183..2830ce8 100644 --- a/chrome/browser/external_tab_container_win.cc +++ b/chrome/browser/external_tab_container_win.cc @@ -7,9 +7,9 @@ #include <string> #include "app/l10n_util.h" +#include "base/debug/trace_event.h" #include "base/i18n/rtl.h" #include "base/logging.h" -#include "base/trace_event.h" #include "base/win_util.h" #include "chrome/app/chrome_dll_resource.h" #include "chrome/browser/automation/automation_provider.h" diff --git a/chrome/browser/io_thread.cc b/chrome/browser/io_thread.cc index a2d0a50..18c54bd 100644 --- a/chrome/browser/io_thread.cc +++ b/chrome/browser/io_thread.cc @@ -5,7 +5,7 @@ #include "chrome/browser/io_thread.h" #include "base/command_line.h" -#include "base/leak_tracker.h" +#include "base/debug/leak_tracker.h" #include "base/logging.h" #include "base/metrics/field_trial.h" #include "base/stl_util-inl.h" @@ -331,7 +331,7 @@ void IOThread::CleanUpAfterMessageLoopDestruction() { // To allow for URLRequests to be deleted from // MessageLoop::DestructionObserver this check has to happen after CleanUp // (which runs before DestructionObservers). - base::LeakTracker<URLRequest>::CheckForLeaks(); + base::debug::LeakTracker<URLRequest>::CheckForLeaks(); } net::HttpAuthHandlerFactory* IOThread::CreateDefaultAuthHandlerFactory( diff --git a/chrome/browser/worker_host/worker_process_host.cc b/chrome/browser/worker_host/worker_process_host.cc index 4bb38c0..713e6db 100644 --- a/chrome/browser/worker_host/worker_process_host.cc +++ b/chrome/browser/worker_host/worker_process_host.cc @@ -9,7 +9,6 @@ #include "base/callback.h" #include "base/command_line.h" -#include "base/debug_util.h" #include "base/message_loop.h" #include "base/string_util.h" #include "base/utf_string_conversions.h" diff --git a/chrome/common/logging_chrome.cc b/chrome/common/logging_chrome.cc index beab5b8..3e52422 100644 --- a/chrome/common/logging_chrome.cc +++ b/chrome/common/logging_chrome.cc @@ -32,7 +32,7 @@ #include "base/command_line.h" #include "base/compiler_specific.h" -#include "base/debug_util.h" +#include "base/debug/debugger.h" #include "base/environment.h" #include "base/file_path.h" #include "base/file_util.h" @@ -73,7 +73,7 @@ DEFINE_GUID(kChromeTraceProviderName, // with that error in the str parameter. MSVC_DISABLE_OPTIMIZE(); static void SilentRuntimeAssertHandler(const std::string& str) { - DebugUtil::BreakDebugger(); + base::debug::BreakDebugger(); } static void SilentRuntimeReportHandler(const std::string& str) { } diff --git a/chrome/common/sandbox_policy.cc b/chrome/common/sandbox_policy.cc index f97da8a..89bea60 100644 --- a/chrome/common/sandbox_policy.cc +++ b/chrome/common/sandbox_policy.cc @@ -8,7 +8,8 @@ #include "app/win_util.h" #include "base/command_line.h" -#include "base/debug_util.h" +#include "base/debug/debugger.h" +#include "base/debug/trace_event.h" #include "base/file_util.h" #include "base/logging.h" #include "base/path_service.h" @@ -16,7 +17,6 @@ #include "base/stringprintf.h" #include "base/string_number_conversions.h" #include "base/string_util.h" -#include "base/trace_event.h" #include "base/win/windows_version.h" #include "chrome/common/child_process_info.h" #include "chrome/common/chrome_constants.h" @@ -579,7 +579,7 @@ base::ProcessHandle StartProcessWithAccess(CommandLine* cmd_line, // Help the process a little. It can't start the debugger by itself if // the process is in a sandbox. if (child_needs_help) - DebugUtil::SpawnDebuggerOnProcess(target.dwProcessId); + base::debug::SpawnDebuggerOnProcess(target.dwProcessId); return process; } diff --git a/chrome/renderer/render_thread.cc b/chrome/renderer/render_thread.cc index 4ce5f7f..cde829c 100644 --- a/chrome/renderer/render_thread.cc +++ b/chrome/renderer/render_thread.cc @@ -10,6 +10,7 @@ #include <vector> #include "base/command_line.h" +#include "base/debug/trace_event.h" #include "base/lazy_instance.h" #include "base/logging.h" #include "base/metrics/field_trial.h" @@ -20,7 +21,6 @@ #include "base/string_util.h" #include "base/task.h" #include "base/thread_local.h" -#include "base/trace_event.h" #include "base/utf_string_conversions.h" #include "base/values.h" #include "chrome/common/appcache/appcache_dispatcher.h" diff --git a/chrome/renderer/renderer_main.cc b/chrome/renderer/renderer_main.cc index 5b42d3e..4dd2ed7 100644 --- a/chrome/renderer/renderer_main.cc +++ b/chrome/renderer/renderer_main.cc @@ -10,6 +10,7 @@ #include "app/hi_res_timer_manager.h" #include "app/system_monitor.h" #include "base/command_line.h" +#include "base/debug/trace_event.h" #include "base/mac/scoped_nsautorelease_pool.h" #include "base/metrics/field_trial.h" #include "base/message_loop.h" @@ -19,7 +20,6 @@ #include "base/platform_thread.h" #include "base/process_util.h" #include "base/string_util.h" -#include "base/trace_event.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_counters.h" #include "chrome/common/chrome_switches.h" diff --git a/chrome/renderer/renderer_main_platform_delegate_linux.cc b/chrome/renderer/renderer_main_platform_delegate_linux.cc index ad43330..045e0cc 100644 --- a/chrome/renderer/renderer_main_platform_delegate_linux.cc +++ b/chrome/renderer/renderer_main_platform_delegate_linux.cc @@ -5,14 +5,13 @@ #include "chrome/renderer/renderer_main_platform_delegate.h" #include "base/command_line.h" -#include "base/debug_util.h" #include "seccompsandbox/sandbox.h" #include "chrome/common/chrome_switches.h" RendererMainPlatformDelegate::RendererMainPlatformDelegate( const MainFunctionParams& parameters) - : parameters_(parameters) { + : parameters_(parameters) { } RendererMainPlatformDelegate::~RendererMainPlatformDelegate() { diff --git a/chrome/service/service_main.cc b/chrome/service/service_main.cc index 6686ccc..96e7ea6 100644 --- a/chrome/service/service_main.cc +++ b/chrome/service/service_main.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "base/debug_util.h" +#include "base/debug/debugger.h" #include "base/message_loop.h" #include "base/path_service.h" #include "base/singleton.h" @@ -22,7 +22,7 @@ int ServiceProcessMain(const MainFunctionParams& parameters) { MessageLoopForUI main_message_loop; if (parameters.command_line_.HasSwitch(switches::kWaitForDebugger)) { - DebugUtil::WaitForDebugger(60, true); + base::debug::WaitForDebugger(60, true); } PlatformThread::SetName("CrServiceMain"); diff --git a/chrome_frame/chrome_active_document.cc b/chrome_frame/chrome_active_document.cc index 141a544..004b9d5 100644 --- a/chrome_frame/chrome_active_document.cc +++ b/chrome_frame/chrome_active_document.cc @@ -18,6 +18,7 @@ #include <wininet.h> #include "base/command_line.h" +#include "base/debug/trace_event.h" #include "base/file_util.h" #include "base/logging.h" #include "base/path_service.h" @@ -26,7 +27,6 @@ #include "base/string_util.h" #include "base/thread.h" #include "base/thread_local.h" -#include "base/trace_event.h" #include "base/utf_string_conversions.h" #include "base/win/scoped_variant.h" #include "grit/generated_resources.h" diff --git a/chrome_frame/chrome_frame.gyp b/chrome_frame/chrome_frame.gyp index 9a99434..af2d00d 100644 --- a/chrome_frame/chrome_frame.gyp +++ b/chrome_frame/chrome_frame.gyp @@ -337,6 +337,7 @@ 'msvs_guid': '3767888B-76ED-4D2A-B1F5-263CC56A12AA', 'type': 'executable', 'dependencies': [ + '../base/base.gyp:base', '../base/base.gyp:base_i18n', '../base/base.gyp:test_support_base', '../build/temp_gyp/googleurl.gyp:googleurl', diff --git a/chrome_frame/chrome_frame_activex.cc b/chrome_frame/chrome_frame_activex.cc index 023bc7d..5d7904a 100644 --- a/chrome_frame/chrome_frame_activex.cc +++ b/chrome_frame/chrome_frame_activex.cc @@ -11,6 +11,7 @@ #include "base/basictypes.h" #include "base/command_line.h" +#include "base/debug/trace_event.h" #include "base/file_util.h" #include "base/logging.h" #include "base/path_service.h" @@ -19,7 +20,6 @@ #include "base/string_split.h" #include "base/string_util.h" #include "base/stringprintf.h" -#include "base/trace_event.h" #include "base/utf_string_conversions.h" #include "base/win/scoped_bstr.h" #include "base/win/scoped_variant.h" diff --git a/chrome_frame/chrome_frame_automation.cc b/chrome_frame/chrome_frame_automation.cc index 28362e5..9f62523 100644 --- a/chrome_frame/chrome_frame_automation.cc +++ b/chrome_frame/chrome_frame_automation.cc @@ -8,7 +8,7 @@ #include "base/callback.h" #include "base/command_line.h" #include "base/compiler_specific.h" -#include "base/trace_event.h" +#include "base/debug/trace_event.h" #include "base/file_util.h" #include "base/file_version_info.h" #include "base/lock.h" diff --git a/chrome_frame/protocol_sink_wrap.h b/chrome_frame/protocol_sink_wrap.h index 0d837a0aa..24810aa 100644 --- a/chrome_frame/protocol_sink_wrap.h +++ b/chrome_frame/protocol_sink_wrap.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. diff --git a/chrome_frame/test/perf/chrome_frame_perftest.cc b/chrome_frame/test/perf/chrome_frame_perftest.cc index e026d48..d0612ec 100644 --- a/chrome_frame/test/perf/chrome_frame_perftest.cc +++ b/chrome_frame/test/perf/chrome_frame_perftest.cc @@ -21,7 +21,7 @@ #include "base/string_util.h" #include "base/stringprintf.h" #include "base/time.h" -#include "base/trace_event_win.h" +#include "base/debug/trace_event_win.h" #include "base/utf_string_conversions.h" #include "base/win/registry.h" #include "base/win/scoped_bstr.h" @@ -1159,19 +1159,19 @@ class EtwConsumer : public EtwTraceConsumerBase<EtwConsumer> { static void ProcessEvent(EVENT_TRACE* event) { DCHECK(delegate_); - if (event->Header.Guid != base::kTraceEventClass32) + if (event->Header.Guid != base::debug::kTraceEventClass32) return; if (event->Header.Class.Version != 0) return; switch (event->Header.Class.Type) { - case base::kTraceEventTypeBegin: + case base::debug::kTraceEventTypeBegin: delegate_->OnTraceEventBegin(event); break; - case base::kTraceEventTypeEnd: + case base::debug::kTraceEventTypeEnd: delegate_->OnTraceEventEnd(event); break; - case base::kTraceEventTypeInstant: + case base::debug::kTraceEventTypeInstant: delegate_->OnTraceEventInstant(event); break; default: @@ -1203,9 +1203,9 @@ class EtwPerfSession { ASSERT_HRESULT_SUCCEEDED(controller_.StartFileSession(L"cf_perf", etl_log_file_.value().c_str(), false)); ASSERT_HRESULT_SUCCEEDED(controller_.EnableProvider( - base::kChromeTraceProviderName, + base::debug::kChromeTraceProviderName, TRACE_LEVEL_INFORMATION, - ~(base::CAPTURE_STACK_TRACE))); + ~(base::debug::CAPTURE_STACK_TRACE))); } HRESULT Stop() { diff --git a/net/base/host_resolver_impl.cc b/net/base/host_resolver_impl.cc index 4dd8f5b..246f50a 100644 --- a/net/base/host_resolver_impl.cc +++ b/net/base/host_resolver_impl.cc @@ -16,7 +16,8 @@ #include "base/basictypes.h" #include "base/compiler_specific.h" -#include "base/debug_util.h" +#include "base/debug/debugger.h" +#include "base/debug/stack_trace.h" #include "base/lock.h" #include "base/message_loop.h" #include "base/metrics/field_trial.h" @@ -1065,7 +1066,7 @@ void HostResolverImpl::CancelRequest(RequestHandle req_handle) { // Because we destroy outstanding requests during Shutdown(), // |req_handle| is already cancelled. LOG(ERROR) << "Called HostResolverImpl::CancelRequest() after Shutdown()."; - StackTrace().PrintBacktrace(); + base::debug::StackTrace().PrintBacktrace(); return; } Request* req = reinterpret_cast<Request*>(req_handle); diff --git a/net/disk_cache/stress_cache.cc b/net/disk_cache/stress_cache.cc index 98dcbe1..dcde1e1 100644 --- a/net/disk_cache/stress_cache.cc +++ b/net/disk_cache/stress_cache.cc @@ -27,7 +27,7 @@ #include "base/at_exit.h" #include "base/command_line.h" -#include "base/debug_util.h" +#include "base/debug/debugger.h" #include "base/file_path.h" #include "base/logging.h" #include "base/message_loop.h" @@ -213,7 +213,7 @@ bool StartCrashThread() { void CrashHandler(const std::string& str) { g_crashing = true; - DebugUtil::BreakDebugger(); + base::debug::BreakDebugger(); } // ----------------------------------------------------------------------- diff --git a/net/socket/socks5_client_socket.cc b/net/socket/socks5_client_socket.cc index 81d7de8..ef929fd 100644 --- a/net/socket/socks5_client_socket.cc +++ b/net/socket/socks5_client_socket.cc @@ -6,6 +6,7 @@ #include "base/basictypes.h" #include "base/compiler_specific.h" +#include "base/debug/trace_event.h" #include "base/format_macros.h" #include "base/string_util.h" #include "net/base/io_buffer.h" diff --git a/net/test/test_server.cc b/net/test/test_server.cc index c3359a4..0b1cd085 100644 --- a/net/test/test_server.cc +++ b/net/test/test_server.cc @@ -15,8 +15,8 @@ #endif #include "base/command_line.h" +#include "base/debug/leak_annotations.h" #include "base/file_util.h" -#include "base/leak_annotations.h" #include "base/logging.h" #include "base/path_service.h" #include "base/string_number_conversions.h" diff --git a/net/url_request/url_request.h b/net/url_request/url_request.h index 31b732e..f573111 100644 --- a/net/url_request/url_request.h +++ b/net/url_request/url_request.h @@ -10,7 +10,7 @@ #include <string> #include <vector> -#include "base/leak_tracker.h" +#include "base/debug/leak_tracker.h" #include "base/linked_ptr.h" #include "base/logging.h" #include "base/non_thread_safe.h" @@ -634,7 +634,7 @@ class URLRequest : public NonThreadSafe { // this to determine which URLRequest to allocate sockets to first. net::RequestPriority priority_; - base::LeakTracker<URLRequest> leak_tracker_; + base::debug::LeakTracker<URLRequest> leak_tracker_; DISALLOW_COPY_AND_ASSIGN(URLRequest); }; diff --git a/webkit/glue/webkitclient_impl.cc b/webkit/glue/webkitclient_impl.cc index 648f3bd5..01051d2 100644 --- a/webkit/glue/webkitclient_impl.cc +++ b/webkit/glue/webkitclient_impl.cc @@ -12,6 +12,7 @@ #include <vector> +#include "base/debug/trace_event.h" #include "base/lock.h" #include "base/message_loop.h" #include "base/metrics/stats_counters.h" @@ -22,7 +23,6 @@ #include "base/string_util.h" #include "base/time.h" #include "base/utf_string_conversions.h" -#include "base/trace_event.h" #include "grit/webkit_resources.h" #include "grit/webkit_strings.h" #include "third_party/WebKit/WebKit/chromium/public/WebCookie.h" diff --git a/webkit/support/webkit_support.cc b/webkit/support/webkit_support.cc index 6b5b9c3..94ff251 100644 --- a/webkit/support/webkit_support.cc +++ b/webkit/support/webkit_support.cc @@ -8,7 +8,7 @@ #include "base/at_exit.h" #include "base/base64.h" #include "base/command_line.h" -#include "base/debug_util.h" +#include "base/debug/debugger.h" #include "base/file_path.h" #include "base/file_util.h" #include "base/i18n/icu_util.h" @@ -330,7 +330,7 @@ void ServeAsynchronousMockedRequests() { // Wrapper for debug_util bool BeingDebugged() { - return DebugUtil::BeingDebugged(); + return base::debug::BeingDebugged(); } // Wrappers for MessageLoop diff --git a/webkit/tools/test_shell/test_shell_mac.mm b/webkit/tools/test_shell/test_shell_mac.mm index e2cd61d..d2b90a7 100644 --- a/webkit/tools/test_shell/test_shell_mac.mm +++ b/webkit/tools/test_shell/test_shell_mac.mm @@ -13,7 +13,7 @@ #include "base/basictypes.h" #include "base/data_pack.h" #include "base/debug_on_start.h" -#include "base/debug_util.h" +#include "base/debug/debugger.h" #include "base/file_path.h" #include "base/file_util.h" #include "base/logging.h" @@ -403,7 +403,7 @@ void TestShell::TestFinished() { // check for debugger, just bail if so. We don't want the timeouts hitting // when we're trying to track down an issue. - if (DebugUtil::BeingDebugged()) + if (base::debug::BeingDebugged()) return; NSThread* currentThread = [NSThread currentThread]; diff --git a/webkit/tools/test_shell/test_shell_main.cc b/webkit/tools/test_shell/test_shell_main.cc index a41ce74..8d7d3b9 100644 --- a/webkit/tools/test_shell/test_shell_main.cc +++ b/webkit/tools/test_shell/test_shell_main.cc @@ -7,6 +7,7 @@ #include "base/at_exit.h" #include "base/basictypes.h" #include "base/command_line.h" +#include "base/debug/trace_event.h" #include "base/environment.h" #include "base/event_recorder.h" #include "base/file_path.h" @@ -20,7 +21,6 @@ #include "base/rand_util.h" #include "base/string_number_conversions.h" #include "base/sys_info.h" -#include "base/trace_event.h" #include "base/utf_string_conversions.h" #include "net/base/cookie_monster.h" #include "net/base/net_module.h" @@ -146,7 +146,7 @@ int main(int argc, char* argv[]) { } if (parsed_command_line.HasSwitch(test_shell::kEnableTracing)) - base::TraceLog::StartTracing(); + base::debug::TraceLog::StartTracing(); net::HttpCache::Mode cache_mode = net::HttpCache::NORMAL; diff --git a/webkit/tools/test_shell/test_shell_switches.cc b/webkit/tools/test_shell/test_shell_switches.cc index b66e3a4..b3ed0bc 100644 --- a/webkit/tools/test_shell/test_shell_switches.cc +++ b/webkit/tools/test_shell/test_shell_switches.cc @@ -63,7 +63,7 @@ const char kDebugMemoryInUse[] = "debug-memory-in-use"; // Enable cookies on the file:// scheme. --layout-tests also enables this. const char kEnableFileCookies[] = "enable-file-cookies"; -// Enable tracing events (see base/trace_event.h) +// Enable tracing events (see base/debug/trace_event.h) const char kEnableTracing[] = "enable-tracing"; // Allow scripts to close windows in all cases. diff --git a/webkit/tools/test_shell/test_shell_win.cc b/webkit/tools/test_shell/test_shell_win.cc index 2bf4ceb..3853755 100644 --- a/webkit/tools/test_shell/test_shell_win.cc +++ b/webkit/tools/test_shell/test_shell_win.cc @@ -11,6 +11,7 @@ #include <shlwapi.h> #include "base/command_line.h" +#include "base/debug/trace_event.h" #include "base/file_util.h" #include "base/memory_debug.h" #include "base/message_loop.h" @@ -19,7 +20,6 @@ #include "base/stack_container.h" #include "base/string_piece.h" #include "base/string_util.h" -#include "base/trace_event.h" #include "base/utf_string_conversions.h" #include "base/win_util.h" #include "breakpad/src/client/windows/handler/exception_handler.h" diff --git a/webkit/tools/test_shell/test_webview_delegate.cc b/webkit/tools/test_shell/test_webview_delegate.cc index 8b0b4bc..e6d43f1 100644 --- a/webkit/tools/test_shell/test_webview_delegate.cc +++ b/webkit/tools/test_shell/test_webview_delegate.cc @@ -8,12 +8,12 @@ #include "webkit/tools/test_shell/test_webview_delegate.h" +#include "base/debug/trace_event.h" #include "base/file_util.h" #include "base/message_loop.h" #include "base/process_util.h" #include "base/string_util.h" #include "base/stringprintf.h" -#include "base/trace_event.h" #include "base/string_number_conversions.h" #include "base/utf_string_conversions.h" #include "gfx/native_widget_types.h" diff --git a/webkit/tools/test_shell/test_webview_delegate_win.cc b/webkit/tools/test_shell/test_webview_delegate_win.cc index 150f3bb..64b6a1b 100644 --- a/webkit/tools/test_shell/test_webview_delegate_win.cc +++ b/webkit/tools/test_shell/test_webview_delegate_win.cc @@ -12,8 +12,8 @@ #include <shlobj.h> #include <shlwapi.h> +#include "base/debug/trace_event.h" #include "base/message_loop.h" -#include "base/trace_event.h" #include "base/utf_string_conversions.h" #include "gfx/native_widget_types.h" #include "gfx/gdi_util.h" |