blob: ce9e9ad550090b70cf525f3d040d8482e11fb36e [file] [log] [blame]
jhawkins@chromium.org98c85e52012-07-26 06:43:44 +09001// Copyright (c) 2012 The Chromium Authors. All rights reserved.
brettw@chromium.org2f49b122010-10-26 13:07:50 +09002// 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.orgeb401402011-08-31 04:33:04 +09007#include "base/basictypes.h"
8
9#include <string.h>
10
11#include <algorithm>
satorux@chromium.org44f30042011-10-13 01:13:40 +090012#include <sstream>
shess@chromium.orgeb401402011-08-31 04:33:04 +090013
brettw@chromium.org2f49b122010-10-26 13:07:50 +090014namespace base {
15namespace debug {
16
shess@chromium.orgeb401402011-08-31 04:33:04 +090017StackTrace::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.org98c85e52012-07-26 06:43:44 +090021 count_ = count;
shess@chromium.orgeb401402011-08-31 04:33:04 +090022}
23
brettw@chromium.org2f49b122010-10-26 13:07:50 +090024StackTrace::~StackTrace() {
25}
26
willchan@chromium.org8bfb85a2011-04-15 01:34:00 +090027const void *const *StackTrace::Addresses(size_t* count) const {
brettw@chromium.org2f49b122010-10-26 13:07:50 +090028 *count = count_;
29 if (count_)
30 return trace_;
31 return NULL;
32}
33
satorux@chromium.org44f30042011-10-13 01:13:40 +090034std::string StackTrace::ToString() const {
35 std::stringstream stream;
mostynb@opera.comb946b882014-04-10 07:29:38 +090036#if !defined(__UCLIBC__)
satorux@chromium.org44f30042011-10-13 01:13:40 +090037 OutputToStream(&stream);
mostynb@opera.comb946b882014-04-10 07:29:38 +090038#endif
satorux@chromium.org44f30042011-10-13 01:13:40 +090039 return stream.str();
40}
41
brettw@chromium.org2f49b122010-10-26 13:07:50 +090042} // namespace debug
43} // namespace base