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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
169 if (IsStackFrameValid(next2_fp, next_fp, stack_end)) { | 169 if (IsStackFrameValid(next2_fp, next_fp, stack_end)) { |
170 return fp; | 170 return fp; |
171 } | 171 } |
172 } | 172 } |
173 } | 173 } |
174 #endif // defined(OS_LINUX) | 174 #endif // defined(OS_LINUX) |
175 | 175 |
176 return 0; | 176 return 0; |
177 } | 177 } |
178 | 178 |
179 // Links stack frame |fp| to |parent_fp|, so that during stack unwinding | |
Primiano Tucci (use gerrit)
2016/10/13 20:03:21
I think you commented this already in the .h. Usua
Dmitry Skiba
2016/10/17 22:09:11
That was for ScopedStackFrameLinker thing, and I r
| |
180 // TraceStackFramePointers() visits |parent_fp| after visiting |fp|. | |
181 // Both frame pointers must come from __builtin_frame_address(). | |
182 // Returns previous stack frame |fp| was linked to. | |
183 void* LinkStackFrames(void* fpp, void* parent_fp) { | |
184 uintptr_t fp = reinterpret_cast<uintptr_t>(fpp) - kStackFrameAdjustment; | |
185 void* prev_parent_fp = reinterpret_cast<void**>(fp)[0]; | |
186 reinterpret_cast<void**>(fp)[0] = parent_fp; | |
187 return prev_parent_fp; | |
188 } | |
189 | |
179 #endif // HAVE_TRACE_STACK_FRAME_POINTERS | 190 #endif // HAVE_TRACE_STACK_FRAME_POINTERS |
180 | 191 |
181 } // namespace | 192 } // namespace |
182 | 193 |
183 StackTrace::StackTrace(const void* const* trace, size_t count) { | 194 StackTrace::StackTrace(const void* const* trace, size_t count) { |
184 count = std::min(count, arraysize(trace_)); | 195 count = std::min(count, arraysize(trace_)); |
185 if (count) | 196 if (count) |
186 memcpy(trace_, trace, count * sizeof(trace_[0])); | 197 memcpy(trace_, trace, count * sizeof(trace_[0])); |
187 count_ = count; | 198 count_ = count; |
188 } | 199 } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
238 continue; | 249 continue; |
239 } | 250 } |
240 | 251 |
241 // Failed to find next frame. | 252 // Failed to find next frame. |
242 break; | 253 break; |
243 } | 254 } |
244 | 255 |
245 return depth; | 256 return depth; |
246 } | 257 } |
247 | 258 |
259 ScopedStackFrameLinker::ScopedStackFrameLinker(void* fp, void* parent_fp) | |
260 : fp_(fp), original_parent_fp_(LinkStackFrames(fp, parent_fp)) {} | |
261 | |
262 ScopedStackFrameLinker::~ScopedStackFrameLinker() { | |
263 LinkStackFrames(fp_, original_parent_fp_); | |
Primiano Tucci (use gerrit)
2016/10/13 20:03:21
could you add a CHECK here that verifies that the
Dmitry Skiba
2016/10/17 22:09:11
Done.
| |
264 } | |
265 | |
248 #endif // HAVE_TRACE_STACK_FRAME_POINTERS | 266 #endif // HAVE_TRACE_STACK_FRAME_POINTERS |
249 | 267 |
250 } // namespace debug | 268 } // namespace debug |
251 } // namespace base | 269 } // namespace base |
OLD | NEW |