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

Side by Side Diff: base/debug_util_posix.cc

Issue 201122: Changes needed for MacOS X 10.4 support.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « base/compat_execinfo.h ('k') | base/file_util_posix.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 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 "build/build_config.h"
6 #include "base/debug_util.h" 6 #include "base/debug_util.h"
7 7
8 #include <errno.h> 8 #include <errno.h>
9 #include <execinfo.h>
10 #include <fcntl.h> 9 #include <fcntl.h>
11 #include <stdio.h> 10 #include <stdio.h>
12 #include <sys/stat.h> 11 #include <sys/stat.h>
13 #include <sys/sysctl.h> 12 #include <sys/sysctl.h>
14 #include <sys/types.h> 13 #include <sys/types.h>
15 #include <unistd.h> 14 #include <unistd.h>
16 15
17 #include "base/basictypes.h" 16 #include "base/basictypes.h"
17 #include "base/compat_execinfo.h"
18 #include "base/eintr_wrapper.h" 18 #include "base/eintr_wrapper.h"
19 #include "base/logging.h" 19 #include "base/logging.h"
20 #include "base/scoped_ptr.h" 20 #include "base/scoped_ptr.h"
21 #include "base/string_piece.h" 21 #include "base/string_piece.h"
22 22
23 // static 23 // static
24 bool DebugUtil::SpawnDebuggerOnProcess(unsigned /* process_id */) { 24 bool DebugUtil::SpawnDebuggerOnProcess(unsigned /* process_id */) {
25 NOTIMPLEMENTED(); 25 NOTIMPLEMENTED();
26 return false; 26 return false;
27 } 27 }
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 // static 109 // static
110 void DebugUtil::BreakDebugger() { 110 void DebugUtil::BreakDebugger() {
111 #if defined(ARCH_CPU_ARM_FAMILY) 111 #if defined(ARCH_CPU_ARM_FAMILY)
112 asm("bkpt 0"); 112 asm("bkpt 0");
113 #else 113 #else
114 asm("int3"); 114 asm("int3");
115 #endif 115 #endif
116 } 116 }
117 117
118 StackTrace::StackTrace() { 118 StackTrace::StackTrace() {
119 // Though the backtrace API man page does not list any possible negative 119 if (backtrace == NULL) {
120 // return values, we take no chance. 120 count_ = 0;
121 count_ = std::max(backtrace(trace_, arraysize(trace_)), 0); 121 } else {
122 // Though the backtrace API man page does not list any possible negative
123 // return values, we take no chance.
124 count_ = std::max(backtrace(trace_, arraysize(trace_)), 0);
125 }
122 } 126 }
123 127
124 void StackTrace::PrintBacktrace() { 128 void StackTrace::PrintBacktrace() {
125 fflush(stderr); 129 if (backtrace_symbols_fd != NULL) {
126 backtrace_symbols_fd(trace_, count_, STDERR_FILENO); 130 fflush(stderr);
131 backtrace_symbols_fd(trace_, count_, STDERR_FILENO);
132 }
127 } 133 }
128 134
129 void StackTrace::OutputToStream(std::ostream* os) { 135 void StackTrace::OutputToStream(std::ostream* os) {
130 scoped_ptr_malloc<char*> trace_symbols(backtrace_symbols(trace_, count_)); 136 if (backtrace_symbols != NULL) {
137 scoped_ptr_malloc<char*> trace_symbols(backtrace_symbols(trace_, count_));
131 138
132 // If we can't retrieve the symbols, print an error and just dump the raw 139 // If we can't retrieve the symbols, print an error and just dump the raw
133 // addresses. 140 // addresses.
134 if (trace_symbols.get() == NULL) { 141 if (trace_symbols.get() == NULL) {
135 (*os) << "Unable get symbols for backtrace (" << strerror(errno) 142 (*os) << "Unable get symbols for backtrace (" << strerror(errno)
136 << "). Dumping raw addresses in trace:\n"; 143 << "). Dumping raw addresses in trace:\n";
137 for (int i = 0; i < count_; ++i) { 144 for (int i = 0; i < count_; ++i) {
138 (*os) << "\t" << trace_[i] << "\n"; 145 (*os) << "\t" << trace_[i] << "\n";
139 } 146 }
140 } else { 147 } else {
141 (*os) << "Backtrace:\n"; 148 (*os) << "Backtrace:\n";
142 for (int i = 0; i < count_; ++i) { 149 for (int i = 0; i < count_; ++i) {
143 (*os) << "\t" << trace_symbols.get()[i] << "\n"; 150 (*os) << "\t" << trace_symbols.get()[i] << "\n";
151 }
144 } 152 }
145 } 153 }
146 } 154 }
OLDNEW
« no previous file with comments | « base/compat_execinfo.h ('k') | base/file_util_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698