1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/ipc/chromium/src/base/debug_util.cc Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,77 @@ 1.4 +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1.5 +// Use of this source code is governed by a BSD-style license that can be 1.6 +// found in the LICENSE file. 1.7 + 1.8 +#include "base/debug_util.h" 1.9 + 1.10 +#include "base/platform_thread.h" 1.11 + 1.12 +#include <stdarg.h> 1.13 +#include <stdio.h> 1.14 +#include <stdlib.h> 1.15 + 1.16 +#ifdef OS_WIN 1.17 +#include <io.h> 1.18 +#else 1.19 +#include <unistd.h> 1.20 +#endif 1.21 + 1.22 +#ifndef STDOUT_FILENO 1.23 +#define STDOUT_FILENO 1 1.24 +#endif 1.25 + 1.26 +bool DebugUtil::WaitForDebugger(int wait_seconds, bool silent) { 1.27 + for (int i = 0; i < wait_seconds * 10; ++i) { 1.28 + if (BeingDebugged()) { 1.29 + if (!silent) 1.30 + BreakDebugger(); 1.31 + return true; 1.32 + } 1.33 + PlatformThread::Sleep(100); 1.34 + } 1.35 + return false; 1.36 +} 1.37 + 1.38 +const void *const *StackTrace::Addresses(size_t* count) { 1.39 + *count = trace_.size(); 1.40 + if (trace_.size()) 1.41 + return &trace_[0]; 1.42 + return NULL; 1.43 +} 1.44 + 1.45 +namespace mozilla { 1.46 + 1.47 +EnvironmentLog::EnvironmentLog(const char* varname) 1.48 +{ 1.49 + const char *e = getenv(varname); 1.50 + if (e && *e) 1.51 + fname_ = e; 1.52 +} 1.53 + 1.54 +EnvironmentLog::~EnvironmentLog() 1.55 +{ 1.56 +} 1.57 + 1.58 +void 1.59 +EnvironmentLog::print(const char* format, ...) 1.60 +{ 1.61 + if (!fname_.size()) 1.62 + return; 1.63 + 1.64 + FILE* f; 1.65 + if (fname_.compare("-") == 0) 1.66 + f = fdopen(dup(STDOUT_FILENO), "a"); 1.67 + else 1.68 + f = fopen(fname_.c_str(), "a"); 1.69 + 1.70 + if (!f) 1.71 + return; 1.72 + 1.73 + va_list a; 1.74 + va_start(a, format); 1.75 + vfprintf(f, format, a); 1.76 + va_end(a); 1.77 + fclose(f); 1.78 +} 1.79 + 1.80 +} // namespace mozilla