OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/stack_frame.h" | 5 #include "vm/stack_frame.h" |
6 #include "vm/stack_trace.h" | 6 #include "vm/stack_trace.h" |
7 | 7 |
8 namespace dart { | 8 namespace dart { |
9 | 9 |
10 // Count the number of frames that are on the stack. | 10 // Count the number of frames that are on the stack. |
11 intptr_t StackTraceUtils::CountFrames(Thread* thread, | 11 intptr_t StackTraceUtils::CountFrames(Thread* thread, |
12 int skip_frames, | 12 int skip_frames, |
13 const Function& async_function, | 13 const Function& async_function) { |
14 bool count_invisible_frames) { | |
15 Zone* zone = thread->zone(); | 14 Zone* zone = thread->zone(); |
16 intptr_t frame_count = 0; | 15 intptr_t frame_count = 0; |
17 StackFrameIterator frames(StackFrameIterator::kDontValidateFrames); | 16 StackFrameIterator frames(StackFrameIterator::kDontValidateFrames); |
18 StackFrame* frame = frames.NextFrame(); | 17 StackFrame* frame = frames.NextFrame(); |
19 ASSERT(frame != NULL); // We expect to find a dart invocation frame. | 18 ASSERT(frame != NULL); // We expect to find a dart invocation frame. |
20 Code& code = Code::Handle(zone); | 19 Code& code = Code::Handle(zone); |
21 Function& function = Function::Handle(zone); | 20 Function& function = Function::Handle(zone); |
22 const bool async_function_is_null = async_function.IsNull(); | 21 const bool async_function_is_null = async_function.IsNull(); |
23 while (frame != NULL) { | 22 while (frame != NULL) { |
24 if (frame->IsDartFrame()) { | 23 if (frame->IsDartFrame()) { |
25 if (skip_frames > 0) { | 24 if (skip_frames > 0) { |
26 skip_frames--; | 25 skip_frames--; |
27 } else { | 26 } else { |
28 code = frame->LookupDartCode(); | 27 code = frame->LookupDartCode(); |
29 function = code.function(); | 28 function = code.function(); |
30 if (function.is_visible() || count_invisible_frames) { | 29 frame_count++; |
31 frame_count++; | |
32 } | |
33 if (!async_function_is_null && | 30 if (!async_function_is_null && |
34 (async_function.raw() == function.parent_function())) { | 31 (async_function.raw() == function.parent_function())) { |
35 return frame_count; | 32 return frame_count; |
36 } | 33 } |
37 } | 34 } |
38 } | 35 } |
39 frame = frames.NextFrame(); | 36 frame = frames.NextFrame(); |
40 } | 37 } |
41 // We hit the sentinel. | 38 // We hit the sentinel. |
42 ASSERT(async_function_is_null); | 39 ASSERT(async_function_is_null); |
43 return frame_count; | 40 return frame_count; |
44 } | 41 } |
45 | 42 |
46 | 43 |
47 intptr_t StackTraceUtils::CollectFrames(Thread* thread, | 44 intptr_t StackTraceUtils::CollectFrames(Thread* thread, |
48 const Array& code_array, | 45 const Array& code_array, |
49 const Array& pc_offset_array, | 46 const Array& pc_offset_array, |
50 intptr_t array_offset, | 47 intptr_t array_offset, |
51 intptr_t count, | 48 intptr_t count, |
52 int skip_frames, | 49 int skip_frames) { |
53 bool collect_invisible_frames) { | |
54 Zone* zone = thread->zone(); | 50 Zone* zone = thread->zone(); |
55 StackFrameIterator frames(StackFrameIterator::kDontValidateFrames); | 51 StackFrameIterator frames(StackFrameIterator::kDontValidateFrames); |
56 StackFrame* frame = frames.NextFrame(); | 52 StackFrame* frame = frames.NextFrame(); |
57 ASSERT(frame != NULL); // We expect to find a dart invocation frame. | 53 ASSERT(frame != NULL); // We expect to find a dart invocation frame. |
58 Function& function = Function::Handle(zone); | 54 Function& function = Function::Handle(zone); |
59 Code& code = Code::Handle(zone); | 55 Code& code = Code::Handle(zone); |
60 Smi& offset = Smi::Handle(zone); | 56 Smi& offset = Smi::Handle(zone); |
61 intptr_t collected_frames_count = 0; | 57 intptr_t collected_frames_count = 0; |
62 while ((frame != NULL) && (collected_frames_count < count)) { | 58 while ((frame != NULL) && (collected_frames_count < count)) { |
63 if (frame->IsDartFrame()) { | 59 if (frame->IsDartFrame()) { |
64 if (skip_frames > 0) { | 60 if (skip_frames > 0) { |
65 skip_frames--; | 61 skip_frames--; |
66 } else { | 62 } else { |
67 code = frame->LookupDartCode(); | 63 code = frame->LookupDartCode(); |
68 function = code.function(); | 64 function = code.function(); |
69 if (function.is_visible() || collect_invisible_frames) { | 65 offset = Smi::New(frame->pc() - code.PayloadStart()); |
70 offset = Smi::New(frame->pc() - code.PayloadStart()); | 66 code_array.SetAt(array_offset, code); |
71 code_array.SetAt(array_offset, code); | 67 pc_offset_array.SetAt(array_offset, offset); |
72 pc_offset_array.SetAt(array_offset, offset); | 68 array_offset++; |
73 array_offset++; | 69 collected_frames_count++; |
74 collected_frames_count++; | |
75 } | |
76 } | 70 } |
77 } | 71 } |
78 frame = frames.NextFrame(); | 72 frame = frames.NextFrame(); |
79 } | 73 } |
80 return collected_frames_count; | 74 return collected_frames_count; |
81 } | 75 } |
82 | 76 |
83 | 77 |
84 intptr_t StackTraceUtils::ExtractAsyncStackTraceInfo( | 78 intptr_t StackTraceUtils::ExtractAsyncStackTraceInfo( |
85 Thread* thread, | 79 Thread* thread, |
(...skipping 22 matching lines...) Expand all Loading... |
108 StubCode::AsynchronousGapMarker_entry()->code()); | 102 StubCode::AsynchronousGapMarker_entry()->code()); |
109 const Code& code = Code::Handle(Code::RawCast(async_code_array->At(1))); | 103 const Code& code = Code::Handle(Code::RawCast(async_code_array->At(1))); |
110 *async_function = code.function(); | 104 *async_function = code.function(); |
111 ASSERT(!async_function->IsNull()); | 105 ASSERT(!async_function->IsNull()); |
112 ASSERT(async_function->IsAsyncFunction() || | 106 ASSERT(async_function->IsAsyncFunction() || |
113 async_function->IsAsyncGenerator()); | 107 async_function->IsAsyncGenerator()); |
114 return async_stack_trace_length; | 108 return async_stack_trace_length; |
115 } | 109 } |
116 | 110 |
117 } // namespace dart | 111 } // namespace dart |
OLD | NEW |