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

Unified Diff: base/debug_util_posix.cc

Issue 201050: Print stack trace on exception in unit tests on Windows.... (Closed) Base URL: svn://svn.chromium.org/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 side-by-side diff with in-line comments
Download patch
Index: base/debug_util_posix.cc
===================================================================
--- base/debug_util_posix.cc (revision 25620)
+++ base/debug_util_posix.cc (working copy)
@@ -116,42 +116,30 @@
}
StackTrace::StackTrace() {
- const int kMaxCallers = 256;
-
- void* callers[kMaxCallers];
- int count = backtrace(callers, kMaxCallers);
-
// Though the backtrace API man page does not list any possible negative
- // return values, we still still exclude them because they would break the
- // memcpy code below.
- if (count > 0) {
- trace_.resize(count);
- memcpy(&trace_[0], callers, sizeof(callers[0]) * count);
- } else {
- trace_.resize(0);
- }
+ // return values, we take no chance.
+ count_ = std::max(backtrace(trace_, arraysize(trace_)), 0);
}
void StackTrace::PrintBacktrace() {
fflush(stderr);
- backtrace_symbols_fd(&trace_[0], trace_.size(), STDERR_FILENO);
+ backtrace_symbols_fd(trace_, count_, STDERR_FILENO);
}
void StackTrace::OutputToStream(std::ostream* os) {
- scoped_ptr_malloc<char*> trace_symbols(
- backtrace_symbols(&trace_[0], trace_.size()));
+ scoped_ptr_malloc<char*> trace_symbols(backtrace_symbols(trace_, count_));
// If we can't retrieve the symbols, print an error and just dump the raw
// addresses.
if (trace_symbols.get() == NULL) {
(*os) << "Unable get symbols for backtrace (" << strerror(errno)
<< "). Dumping raw addresses in trace:\n";
- for (size_t i = 0; i < trace_.size(); ++i) {
+ for (int i = 0; i < count_; ++i) {
(*os) << "\t" << trace_[i] << "\n";
}
} else {
(*os) << "Backtrace:\n";
- for (size_t i = 0; i < trace_.size(); ++i) {
+ for (int i = 0; i < count_; ++i) {
(*os) << "\t" << trace_symbols.get()[i] << "\n";
}
}
« no previous file with comments | « base/debug_util.cc ('k') | base/debug_util_win.cc » ('j') | base/debug_util_win.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698