Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Side by Side Diff: base/debug_util_posix.cc

Issue 18303: Add StackTrace debugging utility class. (Closed)
Patch Set: Addressing comments Created 11 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "build/build_config.h"
5 #include "base/debug_util.h" 6 #include "base/debug_util.h"
6 7
8 #if defined(OS_LINUX)
9 #include <unistd.h>
10 #include <execinfo.h>
11 #endif
12
13 #include <stdio.h>
7 #include <fcntl.h> 14 #include <fcntl.h>
8 #include <sys/stat.h> 15 #include <sys/stat.h>
9 #include <sys/sysctl.h> 16 #include <sys/sysctl.h>
10 #include <sys/types.h> 17 #include <sys/types.h>
11 #include <unistd.h> 18 #include <unistd.h>
12 19
13 #include "base/basictypes.h" 20 #include "base/basictypes.h"
14 #include "base/logging.h" 21 #include "base/logging.h"
15 #include "base/string_piece.h" 22 #include "base/string_piece.h"
16 23
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 pid_index += tracer.size(); 90 pid_index += tracer.size();
84 return pid_index < status.size() && status[pid_index] != '0'; 91 return pid_index < status.size() && status[pid_index] != '0';
85 } 92 }
86 93
87 #endif // OS_LINUX 94 #endif // OS_LINUX
88 95
89 // static 96 // static
90 void DebugUtil::BreakDebugger() { 97 void DebugUtil::BreakDebugger() {
91 asm ("int3"); 98 asm ("int3");
92 } 99 }
100
101 #if defined(OS_LINUX)
102
103 StackTrace::StackTrace() {
104 static const unsigned kMaxCallers = 256;
105
106 void* callers[kMaxCallers];
107 int count = backtrace(callers, kMaxCallers);
108 trace_.resize(count);
109 memcpy(&trace_[0], callers, sizeof(void*) * count);
110 }
111
112 void StackTrace::PrintBacktrace() {
113 fflush(stderr);
114 backtrace_symbols_fd(&trace_[0], trace_.size(), STDERR_FILENO);
115 }
116
117 #elif defined(OS_MACOSX)
118
119 // TODO(port): complete this code
120 StackTrace::StackTrace() { }
121
122 StackTrace::PrintBacktrace() {
123 NOTIMPLEMENTED();
124 fprintf(stderr, "<printing stacktraces not implemented>\n");
Evan Martin 2009/01/16 18:30:08 you won't need this anymore with the above
125 }
126
127 #endif // defined(OS_MACOSX)
128
129 const void *const *StackTrace::Addresses(size_t* count) {
130 *count = trace_.size();
131 if (trace_.size())
132 return &trace_[0];
133 return NULL;
134 }
OLDNEW
« no previous file with comments | « base/debug_util.h ('k') | base/debug_util_win.cc » ('j') | base/debug_util_win.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698