Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(863)

Side by Side Diff: runtime/vm/stack_trace.cc

Issue 2603383004: Sane asynchronous debugging and stack traces (Closed)
Patch Set: rebase Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/vm/stack_trace.h ('k') | runtime/vm/stub_code.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2015, 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,
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 // We have hit the sentinel, stop.
34 break;
35 }
36 }
37 }
38 frame = frames.NextFrame();
39 }
40 // We hit the sentinel.
41 ASSERT(async_function_is_null ||
42 (async_function.raw() == function.parent_function()));
43 return frame_count;
44 }
45
46
47 intptr_t StackTraceUtils::CollectFrames(const Array& code_array,
48 const Array& pc_offset_array,
49 intptr_t array_offset,
50 intptr_t count,
51 int skip_frames,
52 bool collect_invisible_frames) {
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();
57 Code& code = Code::Handle();
58 Smi& offset = Smi::Handle();
59 intptr_t collected_frames_count = 0;
60 while ((frame != NULL) && (count > 0)) {
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 count--;
74 }
75 }
76 }
77 frame = frames.NextFrame();
78 }
79 return collected_frames_count;
80 }
81
82
83 intptr_t StackTraceUtils::ExtractAsyncStackTraceInfo(
84 Thread* thread,
85 Function* async_function,
86 Array* async_code_array,
87 Array* async_pc_offset_array) {
88 if (thread->async_stack_trace() == StackTrace::null()) {
89 return 0;
90 }
91 const StackTrace& async_stack_trace =
92 StackTrace::Handle(thread->async_stack_trace());
93 const intptr_t async_stack_trace_length = async_stack_trace.Length();
94 // At least two entries (0: gap marker, 1: async function).
95 ASSERT(async_stack_trace_length >= 2);
96 // Validate the structure of this stack trace.
97 *async_code_array = async_stack_trace.code_array();
98 ASSERT(!async_code_array->IsNull());
99 *async_pc_offset_array = async_stack_trace.pc_offset_array();
100 ASSERT(!async_pc_offset_array->IsNull());
101 // We start with the asynchronous gap marker.
102 ASSERT(async_code_array->At(0) != Code::null());
103 ASSERT(async_code_array->At(0) ==
104 StubCode::AsynchronousGapMarker_entry()->code());
105 const Code& code = Code::Handle(Code::RawCast(async_code_array->At(1)));
106 *async_function = code.function();
107 ASSERT(!async_function->IsNull());
108 ASSERT(async_function->IsAsyncFunction() ||
109 async_function->IsAsyncGenerator());
110 return async_stack_trace_length;
111 }
112
113 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/stack_trace.h ('k') | runtime/vm/stub_code.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698