ipc/chromium/src/base/debug_util.cc

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial