Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
michael@0 | 2 | // Use of this source code is governed by a BSD-style license that can be |
michael@0 | 3 | // found in the LICENSE file. |
michael@0 | 4 | |
michael@0 | 5 | #include "base/debug_util.h" |
michael@0 | 6 | |
michael@0 | 7 | #include "base/platform_thread.h" |
michael@0 | 8 | |
michael@0 | 9 | #include <stdarg.h> |
michael@0 | 10 | #include <stdio.h> |
michael@0 | 11 | #include <stdlib.h> |
michael@0 | 12 | |
michael@0 | 13 | #ifdef OS_WIN |
michael@0 | 14 | #include <io.h> |
michael@0 | 15 | #else |
michael@0 | 16 | #include <unistd.h> |
michael@0 | 17 | #endif |
michael@0 | 18 | |
michael@0 | 19 | #ifndef STDOUT_FILENO |
michael@0 | 20 | #define STDOUT_FILENO 1 |
michael@0 | 21 | #endif |
michael@0 | 22 | |
michael@0 | 23 | bool DebugUtil::WaitForDebugger(int wait_seconds, bool silent) { |
michael@0 | 24 | for (int i = 0; i < wait_seconds * 10; ++i) { |
michael@0 | 25 | if (BeingDebugged()) { |
michael@0 | 26 | if (!silent) |
michael@0 | 27 | BreakDebugger(); |
michael@0 | 28 | return true; |
michael@0 | 29 | } |
michael@0 | 30 | PlatformThread::Sleep(100); |
michael@0 | 31 | } |
michael@0 | 32 | return false; |
michael@0 | 33 | } |
michael@0 | 34 | |
michael@0 | 35 | const void *const *StackTrace::Addresses(size_t* count) { |
michael@0 | 36 | *count = trace_.size(); |
michael@0 | 37 | if (trace_.size()) |
michael@0 | 38 | return &trace_[0]; |
michael@0 | 39 | return NULL; |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | namespace mozilla { |
michael@0 | 43 | |
michael@0 | 44 | EnvironmentLog::EnvironmentLog(const char* varname) |
michael@0 | 45 | { |
michael@0 | 46 | const char *e = getenv(varname); |
michael@0 | 47 | if (e && *e) |
michael@0 | 48 | fname_ = e; |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | EnvironmentLog::~EnvironmentLog() |
michael@0 | 52 | { |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | void |
michael@0 | 56 | EnvironmentLog::print(const char* format, ...) |
michael@0 | 57 | { |
michael@0 | 58 | if (!fname_.size()) |
michael@0 | 59 | return; |
michael@0 | 60 | |
michael@0 | 61 | FILE* f; |
michael@0 | 62 | if (fname_.compare("-") == 0) |
michael@0 | 63 | f = fdopen(dup(STDOUT_FILENO), "a"); |
michael@0 | 64 | else |
michael@0 | 65 | f = fopen(fname_.c_str(), "a"); |
michael@0 | 66 | |
michael@0 | 67 | if (!f) |
michael@0 | 68 | return; |
michael@0 | 69 | |
michael@0 | 70 | va_list a; |
michael@0 | 71 | va_start(a, format); |
michael@0 | 72 | vfprintf(f, format, a); |
michael@0 | 73 | va_end(a); |
michael@0 | 74 | fclose(f); |
michael@0 | 75 | } |
michael@0 | 76 | |
michael@0 | 77 | } // namespace mozilla |