Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 #include "vm/stack_frame.h" | |
| 6 #include "vm/stack_trace.h" | |
| 7 | |
| 8 namespace dart { | |
| 9 | |
| 10 // Count the number of frames that are on the stack. | |
| 11 intptr_t StackTraceUtils::CountFrames(int skip_frames, | |
|
siva
2017/02/08 18:46:29
Thread* thread, int skip_frames,
Cutch
2017/02/09 22:45:51
Done.
| |
| 12 const Function& async_function, | |
| 13 bool count_invisible_frames) { | |
| 14 intptr_t frame_count = 0; | |
| 15 StackFrameIterator frames(StackFrameIterator::kDontValidateFrames); | |
| 16 StackFrame* frame = frames.NextFrame(); | |
| 17 ASSERT(frame != NULL); // We expect to find a dart invocation frame. | |
| 18 Code& code = Code::Handle(); | |
| 19 Function& function = Function::Handle(); | |
| 20 const bool async_function_is_null = async_function.IsNull(); | |
| 21 while (frame != NULL) { | |
| 22 if (frame->IsDartFrame()) { | |
| 23 if (skip_frames > 0) { | |
| 24 skip_frames--; | |
| 25 } else { | |
| 26 code = frame->LookupDartCode(); | |
| 27 function = code.function(); | |
| 28 if (function.is_visible() || count_invisible_frames) { | |
| 29 frame_count++; | |
| 30 } | |
| 31 if (!async_function_is_null && | |
| 32 (async_function.raw() == function.parent_function())) { | |
| 33 return frame_count; | |
| 34 } | |
| 35 } | |
| 36 } | |
| 37 frame = frames.NextFrame(); | |
| 38 } | |
| 39 // We hit the sentinel. | |
| 40 ASSERT(async_function_is_null); | |
| 41 return frame_count; | |
| 42 } | |
| 43 | |
| 44 | |
| 45 intptr_t StackTraceUtils::CollectFrames(Thread* thread, | |
| 46 const Array& code_array, | |
| 47 const Array& pc_offset_array, | |
| 48 intptr_t array_offset, | |
| 49 intptr_t count, | |
| 50 int skip_frames, | |
| 51 bool collect_invisible_frames) { | |
| 52 Zone* zone = thread->zone(); | |
| 53 StackFrameIterator frames(StackFrameIterator::kDontValidateFrames); | |
| 54 StackFrame* frame = frames.NextFrame(); | |
| 55 ASSERT(frame != NULL); // We expect to find a dart invocation frame. | |
| 56 Function& function = Function::Handle(zone); | |
| 57 Code& code = Code::Handle(zone); | |
| 58 Smi& offset = Smi::Handle(zone); | |
| 59 intptr_t collected_frames_count = 0; | |
| 60 while ((frame != NULL) && (collected_frames_count < count)) { | |
| 61 if (frame->IsDartFrame()) { | |
| 62 if (skip_frames > 0) { | |
| 63 skip_frames--; | |
| 64 } else { | |
| 65 code = frame->LookupDartCode(); | |
| 66 function = code.function(); | |
| 67 if (function.is_visible() || collect_invisible_frames) { | |
| 68 offset = Smi::New(frame->pc() - code.PayloadStart()); | |
| 69 code_array.SetAt(array_offset, code); | |
| 70 pc_offset_array.SetAt(array_offset, offset); | |
| 71 array_offset++; | |
| 72 collected_frames_count++; | |
| 73 } | |
| 74 } | |
| 75 } | |
| 76 frame = frames.NextFrame(); | |
| 77 } | |
| 78 return collected_frames_count; | |
| 79 } | |
| 80 | |
| 81 | |
| 82 intptr_t StackTraceUtils::ExtractAsyncStackTraceInfo( | |
| 83 Thread* thread, | |
| 84 Function* async_function, | |
| 85 StackTrace* async_stack_trace_out, | |
| 86 Array* async_code_array, | |
| 87 Array* async_pc_offset_array) { | |
| 88 if (thread->async_stack_trace() == StackTrace::null()) { | |
| 89 return 0; | |
| 90 } | |
| 91 *async_stack_trace_out = thread->async_stack_trace(); | |
| 92 ASSERT(!async_stack_trace_out->IsNull()); | |
| 93 const StackTrace& async_stack_trace = | |
| 94 StackTrace::Handle(thread->async_stack_trace()); | |
| 95 const intptr_t async_stack_trace_length = async_stack_trace.Length(); | |
| 96 // At least two entries (0: gap marker, 1: async function). | |
| 97 ASSERT(async_stack_trace_length >= 2); | |
| 98 // Validate the structure of this stack trace. | |
| 99 *async_code_array = async_stack_trace.code_array(); | |
| 100 ASSERT(!async_code_array->IsNull()); | |
| 101 *async_pc_offset_array = async_stack_trace.pc_offset_array(); | |
| 102 ASSERT(!async_pc_offset_array->IsNull()); | |
| 103 // We start with the asynchronous gap marker. | |
| 104 ASSERT(async_code_array->At(0) != Code::null()); | |
| 105 ASSERT(async_code_array->At(0) == | |
| 106 StubCode::AsynchronousGapMarker_entry()->code()); | |
| 107 const Code& code = Code::Handle(Code::RawCast(async_code_array->At(1))); | |
| 108 *async_function = code.function(); | |
| 109 ASSERT(!async_function->IsNull()); | |
| 110 ASSERT(async_function->IsAsyncFunction() || | |
| 111 async_function->IsAsyncGenerator()); | |
| 112 return async_stack_trace_length; | |
| 113 } | |
| 114 | |
| 115 } // namespace dart | |
| OLD | NEW |