OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/debug/stack_trace.h" | 5 #include "base/debug/stack_trace.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <sstream> | 10 #include <sstream> |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 | 192 |
193 } // namespace | 193 } // namespace |
194 | 194 |
195 StackTrace::StackTrace(const void* const* trace, size_t count) { | 195 StackTrace::StackTrace(const void* const* trace, size_t count) { |
196 count = std::min(count, arraysize(trace_)); | 196 count = std::min(count, arraysize(trace_)); |
197 if (count) | 197 if (count) |
198 memcpy(trace_, trace, count * sizeof(trace_[0])); | 198 memcpy(trace_, trace, count * sizeof(trace_[0])); |
199 count_ = count; | 199 count_ = count; |
200 } | 200 } |
201 | 201 |
202 StackTrace::~StackTrace() { | 202 StackTrace StackTrace::Truncate(size_t max_entries) const { |
| 203 return StackTrace(trace_, std::min(count_, max_entries)); |
203 } | 204 } |
204 | 205 |
205 const void *const *StackTrace::Addresses(size_t* count) const { | 206 const void *const *StackTrace::Addresses(size_t* count) const { |
206 *count = count_; | 207 *count = count_; |
207 if (count_) | 208 if (count_) |
208 return trace_; | 209 return trace_; |
209 return NULL; | 210 return NULL; |
210 } | 211 } |
211 | 212 |
212 std::string StackTrace::ToString() const { | 213 std::string StackTrace::ToString() const { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 ScopedStackFrameLinker::~ScopedStackFrameLinker() { | 266 ScopedStackFrameLinker::~ScopedStackFrameLinker() { |
266 void* previous_parent_fp = LinkStackFrames(fp_, original_parent_fp_); | 267 void* previous_parent_fp = LinkStackFrames(fp_, original_parent_fp_); |
267 CHECK_EQ(parent_fp_, previous_parent_fp) | 268 CHECK_EQ(parent_fp_, previous_parent_fp) |
268 << "Stack frame's parent pointer has changed!"; | 269 << "Stack frame's parent pointer has changed!"; |
269 } | 270 } |
270 | 271 |
271 #endif // HAVE_TRACE_STACK_FRAME_POINTERS | 272 #endif // HAVE_TRACE_STACK_FRAME_POINTERS |
272 | 273 |
273 } // namespace debug | 274 } // namespace debug |
274 } // namespace base | 275 } // namespace base |
OLD | NEW |