diff options
author | michaelbai@google.com <michaelbai@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-07 20:46:50 +0000 |
---|---|---|
committer | michaelbai@google.com <michaelbai@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-07 20:46:50 +0000 |
commit | 3132e35cb49119f36a529f2370d9de5887582bc2 (patch) | |
tree | e23bdd40d066e3523e870c46ea9d77189d83d954 | |
parent | 16adff66ea7224ddd91d01160a7bcc54f5d8b5a6 (diff) | |
download | chromium_src-3132e35cb49119f36a529f2370d9de5887582bc2.zip chromium_src-3132e35cb49119f36a529f2370d9de5887582bc2.tar.gz chromium_src-3132e35cb49119f36a529f2370d9de5887582bc2.tar.bz2 |
Upstream android debug and log related files
BUG=
TEST=
Review URL: http://codereview.chromium.org/7238012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@91748 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | base/debug/debugger.cc | 10 | ||||
-rw-r--r-- | base/debug/debugger_posix.cc | 23 | ||||
-rw-r--r-- | base/debug/stack_trace_android.cc | 56 | ||||
-rw-r--r-- | base/logging.cc | 28 | ||||
-rw-r--r-- | base/logging.h | 5 | ||||
-rw-r--r-- | base/shared_memory_posix.cc | 2 | ||||
-rw-r--r-- | base/string_number_conversions.cc | 1 | ||||
-rw-r--r-- | base/string_util.h | 1 | ||||
-rw-r--r-- | base/system_monitor/system_monitor_android.cc | 14 | ||||
-rw-r--r-- | base/third_party/symbolize/symbolize.cc | 1 | ||||
-rw-r--r-- | base/third_party/symbolize/symbolize.h | 3 |
11 files changed, 137 insertions, 7 deletions
diff --git a/base/debug/debugger.cc b/base/debug/debugger.cc index 8674f1f..3777fa1 100644 --- a/base/debug/debugger.cc +++ b/base/debug/debugger.cc @@ -1,9 +1,9 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "base/debug/debugger.h" - +#include "base/logging.h" #include "base/threading/platform_thread.h" namespace base { @@ -12,6 +12,12 @@ namespace debug { static bool is_debug_ui_suppressed = false; bool WaitForDebugger(int wait_seconds, bool silent) { +#if defined(OS_ANDROID) + // The pid from which we know which process to attach to are not output by + // android ddms, so we have to print it out explicitly. + LOG(INFO) << "DebugUtil::WaitForDebugger(pid=" << static_cast<int>(getpid()) + << ")"; +#endif for (int i = 0; i < wait_seconds * 10; ++i) { if (BeingDebugged()) { if (!silent) diff --git a/base/debug/debugger_posix.cc b/base/debug/debugger_posix.cc index a1551a3..b3c9bc8 100644 --- a/base/debug/debugger_posix.cc +++ b/base/debug/debugger_posix.cc @@ -44,6 +44,11 @@ #include "base/third_party/symbolize/symbolize.h" #endif +#if defined(OS_ANDROID) +#include <execinfo.h> +#include "base/threading/platform_thread.h" +#endif + namespace base { namespace debug { @@ -94,7 +99,7 @@ bool BeingDebugged() { return being_debugged; } -#elif defined(OS_LINUX) +#elif defined(OS_LINUX) || defined(OS_ANDROID) // 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. @@ -161,7 +166,7 @@ bool BeingDebugged() { // Linux: Debug mode, send SIGTRAP; Release mode, send SIGABRT. // Mac: Always send SIGTRAP. -#if defined(NDEBUG) && !defined(OS_MACOSX) +#if defined(NDEBUG) && !defined(OS_MACOSX) && !defined(OS_ANDROID) #define DEBUG_BREAK() abort() #elif defined(OS_NACL) // The NaCl verifier doesn't let use use int3. For now, we call abort(). We @@ -169,7 +174,21 @@ bool BeingDebugged() { // http://code.google.com/p/nativeclient/issues/detail?id=645 #define DEBUG_BREAK() abort() #elif defined(ARCH_CPU_ARM_FAMILY) +#if defined(OS_ANDROID) +// Though Android has a "helpful" process called debuggerd to catch native +// signals on the general assumption that they are fatal errors, we've had great +// difficulty continuing in a debugger once we stop from SIGINT triggered by +// native code. +// +// Use GDB to set |go| to 1 to resume execution. +#define DEBUG_BREAK() do { \ + volatile int go = 0; \ + while (!go) { base::PlatformThread::Sleep(100); } \ +} while (0) +#else +// ARM && !ANDROID #define DEBUG_BREAK() asm("bkpt 0") +#endif #else #define DEBUG_BREAK() asm("int3") #endif diff --git a/base/debug/stack_trace_android.cc b/base/debug/stack_trace_android.cc new file mode 100644 index 0000000..2ccf406 --- /dev/null +++ b/base/debug/stack_trace_android.cc @@ -0,0 +1,56 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/debug/stack_trace.h" + +#include <signal.h> +#include <sys/types.h> +#include <unistd.h> + +#include "base/logging.h" + +namespace base { +namespace debug { + +StackTrace::StackTrace() { +} + +StackTrace::~StackTrace() { +} + +const void* const* StackTrace::Addresses(size_t* count) const { + NOTIMPLEMENTED(); + return NULL; +} + +// Sends fake SIGSTKFLT signals to let the Android linker and debuggerd dump +// stack. See inlined comments and Android bionic/linker/debugger.c and +// system/core/debuggerd/debuggerd.c for details. +void StackTrace::PrintBacktrace() const { + // Get the current handler of SIGSTKFLT for later use. + sighandler_t sig_handler = signal(SIGSTKFLT, SIG_DFL); + signal(SIGSTKFLT, sig_handler); + + // The Android linker will handle this signal and send a stack dumping request + // to debuggerd which will ptrace_attach this process. Before returning from + // the signal handler, the linker sets the signal handler to SIG_IGN. + kill(gettid(), SIGSTKFLT); + + // Because debuggerd will wait for the process to be stopped by the actual + // signal in crashing scenarios, signal is sent again to met the expectation. + // Debuggerd will dump stack into the system log and /data/tombstones/ files. + // NOTE: If this process runs in the interactive shell, it will be put + // in the background. To resume it in the foreground, use 'fg' command. + kill(gettid(), SIGSTKFLT); + + // Restore the signal handler so that this method can work the next time. + signal(SIGSTKFLT, sig_handler); +} + +void StackTrace::OutputToStream(std::ostream* os) const { + NOTIMPLEMENTED(); +} + +} // namespace debug +} // namespace base diff --git a/base/logging.cc b/base/logging.cc index e5c8c8d..11ad935 100644 --- a/base/logging.cc +++ b/base/logging.cc @@ -58,6 +58,10 @@ typedef pthread_mutex_t* MutexHandle; #include "base/safe_strerror_posix.h" #endif +#if defined(OS_ANDROID) +#include <android/log.h> +#endif + namespace logging { DcheckState g_dcheck_state = DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS; @@ -129,6 +133,8 @@ int32 CurrentThreadId() { return mach_thread_self(); #elif defined(OS_LINUX) return syscall(__NR_gettid); +#elif defined(OS_ANDROID) + return gettid(); #elif defined(OS_FREEBSD) // TODO(BSD): find a better thread ID return reinterpret_cast<int64>(pthread_self()); @@ -546,7 +552,9 @@ LogMessage::LogMessage(const char* file, int line, LogSeverity severity, } LogMessage::~LogMessage() { -#ifndef NDEBUG + // TODO(port): enable stacktrace generation on LOG_FATAL once backtrace are + // working in Android. +#if !defined(NDEBUG) && !defined(OS_ANDROID) if (severity_ == LOG_FATAL) { // Include a stack trace on a fatal. base::debug::StackTrace trace; @@ -568,6 +576,24 @@ LogMessage::~LogMessage() { logging_destination == LOG_TO_BOTH_FILE_AND_SYSTEM_DEBUG_LOG) { #if defined(OS_WIN) OutputDebugStringA(str_newline.c_str()); +#elif defined(OS_ANDROID) + android_LogPriority priority = ANDROID_LOG_UNKNOWN; + switch (severity_) { + case LOG_INFO: + priority = ANDROID_LOG_INFO; + break; + case LOG_WARNING: + priority = ANDROID_LOG_WARN; + break; + case LOG_ERROR: + case LOG_ERROR_REPORT: + priority = ANDROID_LOG_ERROR; + break; + case LOG_FATAL: + priority = ANDROID_LOG_FATAL; + break; + } + __android_log_write(priority, "chromium", str_newline.c_str()); #endif fprintf(stderr, "%s", str_newline.c_str()); fflush(stderr); diff --git a/base/logging.h b/base/logging.h index b12defc..849de0e 100644 --- a/base/logging.h +++ b/base/logging.h @@ -703,7 +703,12 @@ const LogSeverity LOG_DCHECK = LOG_INFO; #define DCHECK_GE(val1, val2) DCHECK_OP(GE, >=, val1, val2) #define DCHECK_GT(val1, val2) DCHECK_OP(GT, > , val1, val2) +#if defined(OS_ANDROID) && !defined(OFFICIAL_BUILD) +// TODO(port): fix once "enough" works +#define NOTREACHED() LOG(ERROR) << "NOTREACHED()" +#else #define NOTREACHED() DCHECK(false) +#endif // Redefine the standard assert to use our nice log files #undef assert diff --git a/base/shared_memory_posix.cc b/base/shared_memory_posix.cc index f81d88c..942a04c 100644 --- a/base/shared_memory_posix.cc +++ b/base/shared_memory_posix.cc @@ -223,7 +223,7 @@ bool SharedMemory::Map(uint32 bytes) { #if defined(OS_ANDROID) if (bytes == 0) { - int ashmem_bytes = ashmem_get_size_region(); + int ashmem_bytes = ashmem_get_size_region(mapped_file_); if (ashmem_bytes < 0) return false; diff --git a/base/string_number_conversions.cc b/base/string_number_conversions.cc index efa7d5f..c700467 100644 --- a/base/string_number_conversions.cc +++ b/base/string_number_conversions.cc @@ -4,6 +4,7 @@ #include "base/string_number_conversions.h" +#include <ctype.h> #include <errno.h> #include <stdlib.h> #include <wctype.h> diff --git a/base/string_util.h b/base/string_util.h index f731c34..3f695a8 100644 --- a/base/string_util.h +++ b/base/string_util.h @@ -8,6 +8,7 @@ #define BASE_STRING_UTIL_H_ #pragma once +#include <ctype.h> #include <stdarg.h> // va_list #include <string> diff --git a/base/system_monitor/system_monitor_android.cc b/base/system_monitor/system_monitor_android.cc new file mode 100644 index 0000000..c86076d --- /dev/null +++ b/base/system_monitor/system_monitor_android.cc @@ -0,0 +1,14 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/system_monitor/system_monitor.h" + +namespace base { + +bool SystemMonitor::IsBatteryPower() { + NOTIMPLEMENTED(); + return true; +} + +} // namespace base diff --git a/base/third_party/symbolize/symbolize.cc b/base/third_party/symbolize/symbolize.cc index 684361f..0a1ba6c 100644 --- a/base/third_party/symbolize/symbolize.cc +++ b/base/third_party/symbolize/symbolize.cc @@ -99,7 +99,6 @@ _END_GOOGLE_NAMESPACE_ #include <errno.h> #include <fcntl.h> #include <limits.h> -#include <link.h> // For ElfW() macro. #include <stdint.h> #include <stdio.h> #include <stdlib.h> diff --git a/base/third_party/symbolize/symbolize.h b/base/third_party/symbolize/symbolize.h index c3e41be..441e543 100644 --- a/base/third_party/symbolize/symbolize.h +++ b/base/third_party/symbolize/symbolize.h @@ -66,7 +66,10 @@ #else #include <elf.h> #endif + +#if !defined(ANDROID) #include <link.h> // For ElfW() macro. +#endif // For systems where SIZEOF_VOID_P is not defined, determine it // based on __LP64__ (defined by gcc on 64-bit systems) |