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

Side by Side Diff: base/debug/stack_trace_posix.cc

Issue 9315044: Get rid of <iostream> include in stack_trace_posix (forces a static initializer) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 10 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 | « no previous file | no next file » | 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/debug/stack_trace.h" 5 #include "base/debug/stack_trace.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <execinfo.h> 8 #include <execinfo.h>
9 #include <fcntl.h> 9 #include <fcntl.h>
10 #include <stdio.h> 10 #include <stdio.h>
11 #include <stdlib.h> 11 #include <stdlib.h>
12 #include <sys/param.h> 12 #include <sys/param.h>
13 #include <sys/stat.h> 13 #include <sys/stat.h>
14 #include <sys/types.h> 14 #include <sys/types.h>
15 #include <unistd.h> 15 #include <unistd.h>
16 16
17 #include <string> 17 #include <string>
18 #include <vector> 18 #include <vector>
19 19
20 #if defined(__GLIBCXX__) 20 #if defined(__GLIBCXX__)
21 #include <cxxabi.h> 21 #include <cxxabi.h>
22 #endif 22 #endif
23 23
24 #if defined(OS_MACOSX) 24 #if defined(OS_MACOSX)
25 #include <AvailabilityMacros.h> 25 #include <AvailabilityMacros.h>
26 #endif 26 #endif
27 27
28 #include <iostream>
29
30 #include "base/basictypes.h" 28 #include "base/basictypes.h"
31 #include "base/eintr_wrapper.h" 29 #include "base/eintr_wrapper.h"
32 #include "base/logging.h" 30 #include "base/logging.h"
33 #include "base/memory/scoped_ptr.h" 31 #include "base/memory/scoped_ptr.h"
34 #include "base/safe_strerror_posix.h" 32 #include "base/safe_strerror_posix.h"
35 #include "base/string_piece.h" 33 #include "base/string_piece.h"
36 #include "base/stringprintf.h" 34 #include "base/stringprintf.h"
37 35
38 #if defined(USE_SYMBOLIZE) 36 #if defined(USE_SYMBOLIZE)
39 #include "base/third_party/symbolize/symbolize.h" 37 #include "base/third_party/symbolize/symbolize.h"
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 161
164 void StackTrace::PrintBacktrace() const { 162 void StackTrace::PrintBacktrace() const {
165 #if defined(OS_MACOSX) && MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5 163 #if defined(OS_MACOSX) && MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
166 if (backtrace_symbols_fd == NULL) 164 if (backtrace_symbols_fd == NULL)
167 return; 165 return;
168 #endif 166 #endif
169 fflush(stderr); 167 fflush(stderr);
170 std::vector<std::string> trace_strings; 168 std::vector<std::string> trace_strings;
171 GetBacktraceStrings(trace_, count_, &trace_strings, NULL); 169 GetBacktraceStrings(trace_, count_, &trace_strings, NULL);
172 for (size_t i = 0; i < trace_strings.size(); ++i) { 170 for (size_t i = 0; i < trace_strings.size(); ++i) {
173 std::cerr << "\t" << trace_strings[i] << "\n"; 171 fprintf(stderr, "\t%s\n", trace_strings[i].c_str());
174 } 172 }
175 } 173 }
176 174
177 void StackTrace::OutputToStream(std::ostream* os) const { 175 void StackTrace::OutputToStream(std::ostream* os) const {
178 #if defined(OS_MACOSX) && MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5 176 #if defined(OS_MACOSX) && MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
179 if (backtrace_symbols == NULL) 177 if (backtrace_symbols == NULL)
180 return; 178 return;
181 #endif 179 #endif
182 std::vector<std::string> trace_strings; 180 std::vector<std::string> trace_strings;
183 std::string error_message; 181 std::string error_message;
184 if (GetBacktraceStrings(trace_, count_, &trace_strings, &error_message)) { 182 if (GetBacktraceStrings(trace_, count_, &trace_strings, &error_message)) {
185 (*os) << "Backtrace:\n"; 183 (*os) << "Backtrace:\n";
186 } else { 184 } else {
187 if (!error_message.empty()) 185 if (!error_message.empty())
188 error_message = " (" + error_message + ")"; 186 error_message = " (" + error_message + ")";
189 (*os) << "Unable to get symbols for backtrace" << error_message << ". " 187 (*os) << "Unable to get symbols for backtrace" << error_message << ". "
190 << "Dumping raw addresses in trace:\n"; 188 << "Dumping raw addresses in trace:\n";
191 } 189 }
192 190
193 for (size_t i = 0; i < trace_strings.size(); ++i) { 191 for (size_t i = 0; i < trace_strings.size(); ++i) {
194 (*os) << "\t" << trace_strings[i] << "\n"; 192 (*os) << "\t" << trace_strings[i] << "\n";
195 } 193 }
196 } 194 }
197 195
198 } // namespace debug 196 } // namespace debug
199 } // namespace base 197 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698