| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 #include "lib/error.h" |
| 6 |
| 7 #include "vm/bootstrap_natives.h" |
| 8 #include "vm/exceptions.h" |
| 9 #include "vm/object_store.h" |
| 10 #include "vm/runtime_entry.h" |
| 11 #include "vm/stack_frame.h" |
| 12 |
| 13 namespace dart { |
| 14 |
| 15 // Get a full stack trace. |
| 16 // Arg0: stack trace object. |
| 17 // Return value: String that represents the full stack trace. |
| 18 DEFINE_NATIVE_ENTRY(Stacktrace_getFullStacktrace, 1) { |
| 19 const Stacktrace& trace = |
| 20 Stacktrace::CheckedHandle(arguments->NativeArgAt(0)); |
| 21 return trace.FullStacktrace(); |
| 22 } |
| 23 |
| 24 |
| 25 // Get a concise and pertinent stack trace. |
| 26 // Arg0: stack trace object. |
| 27 // Return value: String that represents the concise and pertinent stack trace. |
| 28 DEFINE_NATIVE_ENTRY(Stacktrace_getStacktrace, 1) { |
| 29 const Stacktrace& trace = |
| 30 Stacktrace::CheckedHandle(arguments->NativeArgAt(0)); |
| 31 return String::New(trace.ToCStringInternal()); |
| 32 } |
| 33 |
| 34 |
| 35 // Setup a full stack trace. |
| 36 // Arg0: stack trace object. |
| 37 // Return value: None. |
| 38 DEFINE_NATIVE_ENTRY(Stacktrace_setupFullStacktrace, 1) { |
| 39 const Stacktrace& trace = |
| 40 Stacktrace::CheckedHandle(arguments->NativeArgAt(0)); |
| 41 const GrowableObjectArray& func_list = |
| 42 GrowableObjectArray::Handle(GrowableObjectArray::New()); |
| 43 const GrowableObjectArray& code_list = |
| 44 GrowableObjectArray::Handle(GrowableObjectArray::New()); |
| 45 const GrowableObjectArray& pc_offset_list = |
| 46 GrowableObjectArray::Handle(GrowableObjectArray::New()); |
| 47 StackFrameIterator frames(StackFrameIterator::kDontValidateFrames); |
| 48 StackFrame* frame = frames.NextFrame(); |
| 49 ASSERT(frame != NULL); // We expect to find a dart invocation frame. |
| 50 Function& func = Function::Handle(); |
| 51 Code& code = Code::Handle(); |
| 52 Smi& offset = Smi::Handle(); |
| 53 bool catch_frame_skipped = false; // Tracks if catch frame has been skipped. |
| 54 while (!frame->IsEntryFrame()) { |
| 55 if (frame->IsDartFrame()) { |
| 56 code = frame->LookupDartCode(); |
| 57 if (code.is_optimized()) { |
| 58 // For optimized frames, extract all the inlined functions if any |
| 59 // into the stack trace. |
| 60 for (InlinedFunctionsIterator it(frame); !it.Done(); it.Advance()) { |
| 61 func = it.function(); |
| 62 code = it.code(); |
| 63 uword pc = it.pc(); |
| 64 ASSERT(pc != 0); |
| 65 ASSERT(code.EntryPoint() <= pc); |
| 66 ASSERT(pc < (code.EntryPoint() + code.Size())); |
| 67 if (func.is_visible()) { |
| 68 if (!catch_frame_skipped) { |
| 69 catch_frame_skipped = true; |
| 70 } else { |
| 71 offset = Smi::New(pc - code.EntryPoint()); |
| 72 func_list.Add(func); |
| 73 code_list.Add(code); |
| 74 pc_offset_list.Add(offset); |
| 75 } |
| 76 } |
| 77 } |
| 78 } else { |
| 79 offset = Smi::New(frame->pc() - code.EntryPoint()); |
| 80 func = code.function(); |
| 81 if (func.is_visible()) { |
| 82 if (!catch_frame_skipped) { |
| 83 catch_frame_skipped = true; |
| 84 } else { |
| 85 func_list.Add(func); |
| 86 code_list.Add(code); |
| 87 pc_offset_list.Add(offset); |
| 88 } |
| 89 } |
| 90 } |
| 91 } |
| 92 frame = frames.NextFrame(); |
| 93 ASSERT(frame != NULL); |
| 94 } |
| 95 const Array& func_array = Array::Handle(Array::MakeArray(func_list)); |
| 96 const Array& code_array = Array::Handle(Array::MakeArray(code_list)); |
| 97 const Array& pc_offset_array = |
| 98 Array::Handle(Array::MakeArray(pc_offset_list)); |
| 99 trace.SetCatchStacktrace(func_array, code_array, pc_offset_array); |
| 100 return Object::null(); |
| 101 } |
| 102 |
| 103 } // namespace dart |
| OLD | NEW |