jhawkins@chromium.org | 98c85e5 | 2012-07-26 06:43:44 +0900 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
brettw@chromium.org | 2f49b12 | 2010-10-26 13:07:50 +0900 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "base/debug/stack_trace.h" |
| 6 | |
shess@chromium.org | eb40140 | 2011-08-31 04:33:04 +0900 | [diff] [blame] | 7 | #include "base/basictypes.h" |
| 8 | |
| 9 | #include <string.h> |
| 10 | |
| 11 | #include <algorithm> |
satorux@chromium.org | 44f3004 | 2011-10-13 01:13:40 +0900 | [diff] [blame] | 12 | #include <sstream> |
shess@chromium.org | eb40140 | 2011-08-31 04:33:04 +0900 | [diff] [blame] | 13 | |
brettw@chromium.org | 2f49b12 | 2010-10-26 13:07:50 +0900 | [diff] [blame] | 14 | namespace base { |
| 15 | namespace debug { |
| 16 | |
shess@chromium.org | eb40140 | 2011-08-31 04:33:04 +0900 | [diff] [blame] | 17 | StackTrace::StackTrace(const void* const* trace, size_t count) { |
| 18 | count = std::min(count, arraysize(trace_)); |
| 19 | if (count) |
| 20 | memcpy(trace_, trace, count * sizeof(trace_[0])); |
jhawkins@chromium.org | 98c85e5 | 2012-07-26 06:43:44 +0900 | [diff] [blame] | 21 | count_ = count; |
shess@chromium.org | eb40140 | 2011-08-31 04:33:04 +0900 | [diff] [blame] | 22 | } |
| 23 | |
brettw@chromium.org | 2f49b12 | 2010-10-26 13:07:50 +0900 | [diff] [blame] | 24 | StackTrace::~StackTrace() { |
| 25 | } |
| 26 | |
willchan@chromium.org | 8bfb85a | 2011-04-15 01:34:00 +0900 | [diff] [blame] | 27 | const void *const *StackTrace::Addresses(size_t* count) const { |
brettw@chromium.org | 2f49b12 | 2010-10-26 13:07:50 +0900 | [diff] [blame] | 28 | *count = count_; |
| 29 | if (count_) |
| 30 | return trace_; |
| 31 | return NULL; |
| 32 | } |
| 33 | |
satorux@chromium.org | 44f3004 | 2011-10-13 01:13:40 +0900 | [diff] [blame] | 34 | std::string StackTrace::ToString() const { |
| 35 | std::stringstream stream; |
mostynb@opera.com | b946b88 | 2014-04-10 07:29:38 +0900 | [diff] [blame] | 36 | #if !defined(__UCLIBC__) |
satorux@chromium.org | 44f3004 | 2011-10-13 01:13:40 +0900 | [diff] [blame] | 37 | OutputToStream(&stream); |
mostynb@opera.com | b946b88 | 2014-04-10 07:29:38 +0900 | [diff] [blame] | 38 | #endif |
satorux@chromium.org | 44f3004 | 2011-10-13 01:13:40 +0900 | [diff] [blame] | 39 | return stream.str(); |
| 40 | } |
| 41 | |
brettw@chromium.org | 2f49b12 | 2010-10-26 13:07:50 +0900 | [diff] [blame] | 42 | } // namespace debug |
| 43 | } // namespace base |