diff options
author | maruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-08 23:53:53 +0000 |
---|---|---|
committer | maruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-08 23:53:53 +0000 |
commit | 0fe31f2ba217cceb277b670e2812667c3aee8e80 (patch) | |
tree | 3d2adea86b5d61d297318ea60c3faf1b1636c996 /base/debug_util_posix.cc | |
parent | 2f66ed584522a2383f0f7193b264b3da7928eb82 (diff) | |
download | chromium_src-0fe31f2ba217cceb277b670e2812667c3aee8e80.zip chromium_src-0fe31f2ba217cceb277b670e2812667c3aee8e80.tar.gz chromium_src-0fe31f2ba217cceb277b670e2812667c3aee8e80.tar.bz2 |
Print stack trace on exception in unit tests on Windows.
Also remove std::vector<> from StackTrace to reduce heap usage during potential unstable execution.
TEST=none
BUG=http://crbug.com/20996
Review URL: http://codereview.chromium.org/201050
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25685 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/debug_util_posix.cc')
-rw-r--r-- | base/debug_util_posix.cc | 24 |
1 files changed, 6 insertions, 18 deletions
diff --git a/base/debug_util_posix.cc b/base/debug_util_posix.cc index 84aebc3..dd22710 100644 --- a/base/debug_util_posix.cc +++ b/base/debug_util_posix.cc @@ -116,42 +116,30 @@ void DebugUtil::BreakDebugger() { } 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"; } } |