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 "vm/bootstrap_natives.h" | 6 #include "vm/bootstrap_natives.h" |
6 #include "vm/exceptions.h" | 7 #include "vm/exceptions.h" |
7 #include "vm/object_store.h" | 8 #include "vm/object_store.h" |
8 #include "vm/runtime_entry.h" | 9 #include "vm/runtime_entry.h" |
9 #include "vm/stack_frame.h" | 10 #include "vm/stack_frame.h" |
10 | 11 |
11 namespace dart { | 12 namespace dart { |
12 | 13 |
13 static void IterateFrames(const GrowableObjectArray& code_list, | 14 static void IterateFrames(const GrowableObjectArray& code_list, |
14 const GrowableObjectArray& pc_offset_list, | 15 const GrowableObjectArray& pc_offset_list, |
(...skipping 14 matching lines...) Expand all Loading... |
29 pc_offset_list.Add(offset); | 30 pc_offset_list.Add(offset); |
30 } | 31 } |
31 } | 32 } |
32 frame = frames.NextFrame(); | 33 frame = frames.NextFrame(); |
33 } | 34 } |
34 } | 35 } |
35 | 36 |
36 // Creates a Stacktrace object from the current stack. | 37 // Creates a Stacktrace object from the current stack. |
37 // | 38 // |
38 // Skips the first skip_frames Dart frames. | 39 // Skips the first skip_frames Dart frames. |
39 static const Stacktrace& GetCurrentStacktrace(int skip_frames) { | 40 const Stacktrace& GetCurrentStacktrace(int skip_frames) { |
40 const GrowableObjectArray& code_list = | 41 const GrowableObjectArray& code_list = |
41 GrowableObjectArray::Handle(GrowableObjectArray::New()); | 42 GrowableObjectArray::Handle(GrowableObjectArray::New()); |
42 const GrowableObjectArray& pc_offset_list = | 43 const GrowableObjectArray& pc_offset_list = |
43 GrowableObjectArray::Handle(GrowableObjectArray::New()); | 44 GrowableObjectArray::Handle(GrowableObjectArray::New()); |
44 IterateFrames(code_list, pc_offset_list, skip_frames); | 45 IterateFrames(code_list, pc_offset_list, skip_frames); |
45 const Array& code_array = Array::Handle(Array::MakeArray(code_list)); | 46 const Array& code_array = Array::Handle(Array::MakeArray(code_list)); |
46 const Array& pc_offset_array = | 47 const Array& pc_offset_array = |
47 Array::Handle(Array::MakeArray(pc_offset_list)); | 48 Array::Handle(Array::MakeArray(pc_offset_list)); |
48 const Stacktrace& stacktrace = Stacktrace::Handle( | 49 const Stacktrace& stacktrace = Stacktrace::Handle( |
49 Stacktrace::New(code_array, pc_offset_array)); | 50 Stacktrace::New(code_array, pc_offset_array)); |
50 return stacktrace; | 51 return stacktrace; |
51 } | 52 } |
52 | 53 |
53 // An utility method for convenient printing of dart stack traces when | 54 // An utility method for convenient printing of dart stack traces when |
54 // inside 'gdb'. Note: This function will only work when there is a | 55 // inside 'gdb'. Note: This function will only work when there is a |
55 // valid exit frame information. It will not work when a breakpoint is | 56 // valid exit frame information. It will not work when a breakpoint is |
56 // set in dart code and control is got inside 'gdb' without going through | 57 // set in dart code and control is got inside 'gdb' without going through |
57 // the runtime or native transition stub. | 58 // the runtime or native transition stub. |
58 void _printCurrentStacktrace() { | 59 void _printCurrentStacktrace() { |
59 const Stacktrace& stacktrace = GetCurrentStacktrace(0); | 60 const Stacktrace& stacktrace = GetCurrentStacktrace(0); |
60 OS::PrintErr("=== Current Trace:\n%s===\n", stacktrace.ToCString()); | 61 OS::PrintErr("=== Current Trace:\n%s===\n", stacktrace.ToCString()); |
61 } | 62 } |
62 | 63 |
63 DEFINE_NATIVE_ENTRY(StackTrace_current, 0) { | 64 DEFINE_NATIVE_ENTRY(StackTrace_current, 0) { |
64 const Stacktrace& stacktrace = GetCurrentStacktrace(1); | 65 const Stacktrace& stacktrace = GetCurrentStacktrace(1); |
65 return stacktrace.raw(); | 66 return stacktrace.raw(); |
66 } | 67 } |
67 | 68 |
68 } // namespace dart | 69 } // namespace dart |
OLD | NEW |