ipc/chromium/src/base/debug_util.cc

branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
equal deleted inserted replaced
-1:000000000000 0:5a5ffbdc7435
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.
4
5 #include "base/debug_util.h"
6
7 #include "base/platform_thread.h"
8
9 #include <stdarg.h>
10 #include <stdio.h>
11 #include <stdlib.h>
12
13 #ifdef OS_WIN
14 #include <io.h>
15 #else
16 #include <unistd.h>
17 #endif
18
19 #ifndef STDOUT_FILENO
20 #define STDOUT_FILENO 1
21 #endif
22
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 }
34
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 }
41
42 namespace mozilla {
43
44 EnvironmentLog::EnvironmentLog(const char* varname)
45 {
46 const char *e = getenv(varname);
47 if (e && *e)
48 fname_ = e;
49 }
50
51 EnvironmentLog::~EnvironmentLog()
52 {
53 }
54
55 void
56 EnvironmentLog::print(const char* format, ...)
57 {
58 if (!fname_.size())
59 return;
60
61 FILE* f;
62 if (fname_.compare("-") == 0)
63 f = fdopen(dup(STDOUT_FILENO), "a");
64 else
65 f = fopen(fname_.c_str(), "a");
66
67 if (!f)
68 return;
69
70 va_list a;
71 va_start(a, format);
72 vfprintf(f, format, a);
73 va_end(a);
74 fclose(f);
75 }
76
77 } // namespace mozilla

mercurial