stack_trace.cc 898 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "base/debug/stack_trace.h"
  5. #include "base/basictypes.h"
  6. #include <string.h>
  7. #include <algorithm>
  8. #include <sstream>
  9. namespace base {
  10. namespace debug {
  11. StackTrace::StackTrace(const void* const* trace, size_t count) {
  12. count = std::min(count, arraysize(trace_));
  13. if (count)
  14. memcpy(trace_, trace, count * sizeof(trace_[0]));
  15. count_ = count;
  16. }
  17. StackTrace::~StackTrace() {
  18. }
  19. const void *const *StackTrace::Addresses(size_t* count) const {
  20. *count = count_;
  21. if (count_)
  22. return trace_;
  23. return NULL;
  24. }
  25. std::string StackTrace::ToString() const {
  26. std::stringstream stream;
  27. #if !defined(__UCLIBC__)
  28. OutputToStream(&stream);
  29. #endif
  30. return stream.str();
  31. }
  32. } // namespace debug
  33. } // namespace base