| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 "lib/stacktrace.h" | 5 #include "lib/stacktrace.h" |
| 6 #include "vm/bootstrap_natives.h" | 6 #include "vm/bootstrap_natives.h" |
| 7 #include "vm/debugger.h" | 7 #include "vm/debugger.h" |
| 8 #include "vm/exceptions.h" | 8 #include "vm/exceptions.h" |
| 9 #include "vm/native_entry.h" | 9 #include "vm/native_entry.h" |
| 10 #include "vm/object_store.h" | 10 #include "vm/object_store.h" |
| 11 #include "vm/runtime_entry.h" | 11 #include "vm/runtime_entry.h" |
| 12 #include "vm/stack_frame.h" | 12 #include "vm/stack_frame.h" |
| 13 #include "vm/stack_trace.h" | 13 #include "vm/stack_trace.h" |
| 14 | 14 |
| 15 namespace dart { | 15 namespace dart { |
| 16 | 16 |
| 17 DECLARE_FLAG(bool, show_invisible_frames); | 17 DECLARE_FLAG(bool, show_invisible_frames); |
| 18 | 18 |
| 19 static RawStackTrace* CurrentSyncStackTrace(Thread* thread) { | 19 static RawStackTrace* CurrentSyncStackTrace(Thread* thread, |
| 20 intptr_t skip_frames = 1) { |
| 20 Zone* zone = thread->zone(); | 21 Zone* zone = thread->zone(); |
| 21 const Function& null_function = Function::ZoneHandle(zone); | 22 const Function& null_function = Function::ZoneHandle(zone); |
| 22 // Skip the Dart exit frame. | |
| 23 const intptr_t skip_frames = 1; | |
| 24 | 23 |
| 25 // Determine how big the stack trace is. | 24 // Determine how big the stack trace is. |
| 26 const intptr_t stack_trace_length = | 25 const intptr_t stack_trace_length = |
| 27 StackTraceUtils::CountFrames(thread, skip_frames, null_function); | 26 StackTraceUtils::CountFrames(thread, skip_frames, null_function); |
| 28 | 27 |
| 29 // Allocate once. | 28 // Allocate once. |
| 30 const Array& code_array = | 29 const Array& code_array = |
| 31 Array::ZoneHandle(zone, Array::New(stack_trace_length)); | 30 Array::ZoneHandle(zone, Array::New(stack_trace_length)); |
| 32 const Array& pc_offset_array = | 31 const Array& pc_offset_array = |
| 33 Array::ZoneHandle(zone, Array::New(stack_trace_length)); | 32 Array::ZoneHandle(zone, Array::New(stack_trace_length)); |
| 34 | 33 |
| 35 // Collect the frames. | 34 // Collect the frames. |
| 36 const intptr_t collected_frames_count = StackTraceUtils::CollectFrames( | 35 const intptr_t collected_frames_count = StackTraceUtils::CollectFrames( |
| 37 thread, code_array, pc_offset_array, 0, stack_trace_length, skip_frames); | 36 thread, code_array, pc_offset_array, 0, stack_trace_length, skip_frames); |
| 38 | 37 |
| 39 ASSERT(collected_frames_count == stack_trace_length); | 38 ASSERT(collected_frames_count == stack_trace_length); |
| 40 | 39 |
| 41 return StackTrace::New(code_array, pc_offset_array); | 40 return StackTrace::New(code_array, pc_offset_array); |
| 42 } | 41 } |
| 43 | 42 |
| 44 | 43 |
| 45 static RawStackTrace* CurrentStackTrace( | 44 static RawStackTrace* CurrentStackTrace( |
| 46 Thread* thread, | 45 Thread* thread, |
| 47 bool for_async_function, | 46 bool for_async_function, |
| 48 intptr_t skip_frames = 1, | 47 intptr_t skip_frames = 1, |
| 49 bool causal_async_stacks = FLAG_causal_async_stacks) { | 48 bool causal_async_stacks = FLAG_causal_async_stacks) { |
| 50 if (!causal_async_stacks) { | 49 if (!causal_async_stacks) { |
| 51 // Return the synchronous stack trace. | 50 // Return the synchronous stack trace. |
| 52 return CurrentSyncStackTrace(thread); | 51 return CurrentSyncStackTrace(thread, skip_frames); |
| 53 } | 52 } |
| 54 | 53 |
| 55 Zone* zone = thread->zone(); | 54 Zone* zone = thread->zone(); |
| 56 Code& code = Code::ZoneHandle(zone); | 55 Code& code = Code::ZoneHandle(zone); |
| 57 Smi& offset = Smi::ZoneHandle(zone); | 56 Smi& offset = Smi::ZoneHandle(zone); |
| 58 Function& async_function = Function::ZoneHandle(zone); | 57 Function& async_function = Function::ZoneHandle(zone); |
| 59 StackTrace& async_stack_trace = StackTrace::ZoneHandle(zone); | 58 StackTrace& async_stack_trace = StackTrace::ZoneHandle(zone); |
| 60 Array& async_code_array = Array::ZoneHandle(zone); | 59 Array& async_code_array = Array::ZoneHandle(zone); |
| 61 Array& async_pc_offset_array = Array::ZoneHandle(zone); | 60 Array& async_pc_offset_array = Array::ZoneHandle(zone); |
| 62 | 61 |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 void _printCurrentStackTraceNoSafepoint() { | 186 void _printCurrentStackTraceNoSafepoint() { |
| 188 StackFrameIterator frames(StackFrameIterator::kDontValidateFrames); | 187 StackFrameIterator frames(StackFrameIterator::kDontValidateFrames); |
| 189 StackFrame* frame = frames.NextFrame(); | 188 StackFrame* frame = frames.NextFrame(); |
| 190 while (frame != NULL) { | 189 while (frame != NULL) { |
| 191 OS::PrintErr("%s\n", frame->ToCString()); | 190 OS::PrintErr("%s\n", frame->ToCString()); |
| 192 frame = frames.NextFrame(); | 191 frame = frames.NextFrame(); |
| 193 } | 192 } |
| 194 } | 193 } |
| 195 | 194 |
| 196 } // namespace dart | 195 } // namespace dart |
| OLD | NEW |