michael@0: // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: michael@0: #include "base/debug_util.h" michael@0: michael@0: #include "base/platform_thread.h" michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: #ifdef OS_WIN michael@0: #include michael@0: #else michael@0: #include michael@0: #endif michael@0: michael@0: #ifndef STDOUT_FILENO michael@0: #define STDOUT_FILENO 1 michael@0: #endif michael@0: michael@0: bool DebugUtil::WaitForDebugger(int wait_seconds, bool silent) { michael@0: for (int i = 0; i < wait_seconds * 10; ++i) { michael@0: if (BeingDebugged()) { michael@0: if (!silent) michael@0: BreakDebugger(); michael@0: return true; michael@0: } michael@0: PlatformThread::Sleep(100); michael@0: } michael@0: return false; michael@0: } michael@0: michael@0: const void *const *StackTrace::Addresses(size_t* count) { michael@0: *count = trace_.size(); michael@0: if (trace_.size()) michael@0: return &trace_[0]; michael@0: return NULL; michael@0: } michael@0: michael@0: namespace mozilla { michael@0: michael@0: EnvironmentLog::EnvironmentLog(const char* varname) michael@0: { michael@0: const char *e = getenv(varname); michael@0: if (e && *e) michael@0: fname_ = e; michael@0: } michael@0: michael@0: EnvironmentLog::~EnvironmentLog() michael@0: { michael@0: } michael@0: michael@0: void michael@0: EnvironmentLog::print(const char* format, ...) michael@0: { michael@0: if (!fname_.size()) michael@0: return; michael@0: michael@0: FILE* f; michael@0: if (fname_.compare("-") == 0) michael@0: f = fdopen(dup(STDOUT_FILENO), "a"); michael@0: else michael@0: f = fopen(fname_.c_str(), "a"); michael@0: michael@0: if (!f) michael@0: return; michael@0: michael@0: va_list a; michael@0: va_start(a, format); michael@0: vfprintf(f, format, a); michael@0: va_end(a); michael@0: fclose(f); michael@0: } michael@0: michael@0: } // namespace mozilla