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

Side by Side Diff: runtime/lib/stacktrace.cc

Issue 23964003: Traverse inlined frames lazily when printing the stacktrace. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | runtime/vm/exceptions.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "vm/bootstrap_natives.h" 5 #include "vm/bootstrap_natives.h"
6 #include "vm/exceptions.h" 6 #include "vm/exceptions.h"
7 #include "vm/object_store.h" 7 #include "vm/object_store.h"
8 #include "vm/runtime_entry.h" 8 #include "vm/runtime_entry.h"
9 #include "vm/stack_frame.h" 9 #include "vm/stack_frame.h"
10 10
(...skipping 12 matching lines...) Expand all
23 // Get a concise and pertinent stack trace. 23 // Get a concise and pertinent stack trace.
24 // Arg0: stack trace object. 24 // Arg0: stack trace object.
25 // Return value: String that represents the concise and pertinent stack trace. 25 // Return value: String that represents the concise and pertinent stack trace.
26 DEFINE_NATIVE_ENTRY(Stacktrace_getStacktrace, 1) { 26 DEFINE_NATIVE_ENTRY(Stacktrace_getStacktrace, 1) {
27 const Stacktrace& trace = 27 const Stacktrace& trace =
28 Stacktrace::CheckedHandle(arguments->NativeArgAt(0)); 28 Stacktrace::CheckedHandle(arguments->NativeArgAt(0));
29 return String::New(trace.ToCStringInternal(0)); 29 return String::New(trace.ToCStringInternal(0));
30 } 30 }
31 31
32 32
33 static void iterateFrames(const GrowableObjectArray& func_list, 33 static void IterateFrames(const GrowableObjectArray& code_list,
34 const GrowableObjectArray& code_list,
35 const GrowableObjectArray& pc_offset_list) { 34 const GrowableObjectArray& pc_offset_list) {
36 StackFrameIterator frames(StackFrameIterator::kDontValidateFrames); 35 StackFrameIterator frames(StackFrameIterator::kDontValidateFrames);
37 StackFrame* frame = frames.NextFrame(); 36 StackFrame* frame = frames.NextFrame();
38 ASSERT(frame != NULL); // We expect to find a dart invocation frame. 37 ASSERT(frame != NULL); // We expect to find a dart invocation frame.
39 Function& func = Function::Handle();
40 Code& code = Code::Handle(); 38 Code& code = Code::Handle();
41 Smi& offset = Smi::Handle(); 39 Smi& offset = Smi::Handle();
42 bool catch_frame_skipped = false; // Tracks if catch frame has been skipped. 40 bool catch_frame_skipped = false; // Tracks if catch frame has been skipped.
43 while (frame != NULL) { 41 while (frame != NULL) {
44 if (frame->IsDartFrame()) { 42 if (frame->IsDartFrame()) {
45 code = frame->LookupDartCode(); 43 code = frame->LookupDartCode();
46 if (code.is_optimized()) { 44 offset = Smi::New(frame->pc() - code.EntryPoint());
47 // For optimized frames, extract all the inlined functions if any 45 if (!catch_frame_skipped) {
48 // into the stack trace. 46 const Function& func = Function::Handle(code.function());
49 for (InlinedFunctionsIterator it(code, frame->pc()); 47 // Skip over hidden native, and mark first visible frame as catch frame.
50 !it.Done(); it.Advance()) { 48 if (func.is_visible()) {
51 func = it.function(); 49 catch_frame_skipped = true;
52 code = it.code();
53 uword pc = it.pc();
54 ASSERT(pc != 0);
55 ASSERT(code.EntryPoint() <= pc);
56 ASSERT(pc < (code.EntryPoint() + code.Size()));
57 if (func.is_visible()) {
58 if (!catch_frame_skipped) {
59 catch_frame_skipped = true;
60 } else {
61 offset = Smi::New(pc - code.EntryPoint());
62 func_list.Add(func);
63 code_list.Add(code);
64 pc_offset_list.Add(offset);
65 }
66 }
67 } 50 }
68 } else { 51 } else {
69 offset = Smi::New(frame->pc() - code.EntryPoint()); 52 code_list.Add(code);
70 func = code.function(); 53 pc_offset_list.Add(offset);
71 if (func.is_visible()) {
72 if (!catch_frame_skipped) {
73 catch_frame_skipped = true;
74 } else {
75 func_list.Add(func);
76 code_list.Add(code);
77 pc_offset_list.Add(offset);
78 }
79 }
80 } 54 }
81 } 55 }
82 frame = frames.NextFrame(); 56 frame = frames.NextFrame();
83 } 57 }
84 } 58 }
85 59
86 60
87 // Setup a full stack trace. 61 // Setup a full stack trace.
88 // Arg0: stack trace object. 62 // Arg0: stack trace object.
89 // Return value: None. 63 // Return value: None.
90 DEFINE_NATIVE_ENTRY(Stacktrace_setupFullStacktrace, 1) { 64 DEFINE_NATIVE_ENTRY(Stacktrace_setupFullStacktrace, 1) {
91 const Stacktrace& trace = 65 const Stacktrace& trace =
92 Stacktrace::CheckedHandle(arguments->NativeArgAt(0)); 66 Stacktrace::CheckedHandle(arguments->NativeArgAt(0));
93 const GrowableObjectArray& func_list =
94 GrowableObjectArray::Handle(GrowableObjectArray::New());
95 const GrowableObjectArray& code_list = 67 const GrowableObjectArray& code_list =
96 GrowableObjectArray::Handle(GrowableObjectArray::New()); 68 GrowableObjectArray::Handle(GrowableObjectArray::New());
97 const GrowableObjectArray& pc_offset_list = 69 const GrowableObjectArray& pc_offset_list =
98 GrowableObjectArray::Handle(GrowableObjectArray::New()); 70 GrowableObjectArray::Handle(GrowableObjectArray::New());
99 iterateFrames(func_list, code_list, pc_offset_list); 71 IterateFrames(code_list, pc_offset_list);
100 const Array& func_array = Array::Handle(Array::MakeArray(func_list));
101 const Array& code_array = Array::Handle(Array::MakeArray(code_list)); 72 const Array& code_array = Array::Handle(Array::MakeArray(code_list));
102 const Array& pc_offset_array = 73 const Array& pc_offset_array =
103 Array::Handle(Array::MakeArray(pc_offset_list)); 74 Array::Handle(Array::MakeArray(pc_offset_list));
104 trace.SetCatchStacktrace(func_array, code_array, pc_offset_array); 75 trace.SetCatchStacktrace(code_array, pc_offset_array);
105 return Object::null(); 76 return Object::null();
106 } 77 }
107 78
108 79
109 // An utility method for convenient printing of dart stack traces when 80 // An utility method for convenient printing of dart stack traces when
110 // inside 'gdb'. Note: This function will only work when there is a 81 // inside 'gdb'. Note: This function will only work when there is a
111 // valid exit frame information. It will not work when a breakpoint is 82 // valid exit frame information. It will not work when a breakpoint is
112 // set in dart code and control is got inside 'gdb' without going through 83 // set in dart code and control is got inside 'gdb' without going through
113 // the runtime or native transition stub. 84 // the runtime or native transition stub.
114 void _printCurrentStacktrace() { 85 void _printCurrentStacktrace() {
115 const GrowableObjectArray& func_list =
116 GrowableObjectArray::Handle(GrowableObjectArray::New());
117 const GrowableObjectArray& code_list = 86 const GrowableObjectArray& code_list =
118 GrowableObjectArray::Handle(GrowableObjectArray::New()); 87 GrowableObjectArray::Handle(GrowableObjectArray::New());
119 const GrowableObjectArray& pc_offset_list = 88 const GrowableObjectArray& pc_offset_list =
120 GrowableObjectArray::Handle(GrowableObjectArray::New()); 89 GrowableObjectArray::Handle(GrowableObjectArray::New());
121 iterateFrames(func_list, code_list, pc_offset_list); 90 IterateFrames(code_list, pc_offset_list);
122 const Array& func_array = Array::Handle(Array::MakeArray(func_list));
123 const Array& code_array = Array::Handle(Array::MakeArray(code_list)); 91 const Array& code_array = Array::Handle(Array::MakeArray(code_list));
124 const Array& pc_offset_array = 92 const Array& pc_offset_array =
125 Array::Handle(Array::MakeArray(pc_offset_list)); 93 Array::Handle(Array::MakeArray(pc_offset_list));
126 const Stacktrace& stacktrace = Stacktrace::Handle( 94 const Stacktrace& stacktrace = Stacktrace::Handle(
127 Stacktrace::New(func_array, code_array, pc_offset_array)); 95 Stacktrace::New(code_array, pc_offset_array));
128 OS::Print("%s\n", stacktrace.ToCString()); 96 OS::Print("%s\n", stacktrace.ToCString());
129 } 97 }
130 98
131 } // namespace dart 99 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/exceptions.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698