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

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

Issue 23453035: 1. Add flag --trace-api to trace API function invocation (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/dart_api_impl.h » ('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 // Setup a full stack trace. 33 static void iterateFrames(const GrowableObjectArray& func_list,
34 // Arg0: stack trace object. 34 const GrowableObjectArray& code_list,
35 // Return value: None. 35 const GrowableObjectArray& pc_offset_list) {
36 DEFINE_NATIVE_ENTRY(Stacktrace_setupFullStacktrace, 1) {
37 const Stacktrace& trace =
38 Stacktrace::CheckedHandle(arguments->NativeArgAt(0));
39 const GrowableObjectArray& func_list =
40 GrowableObjectArray::Handle(GrowableObjectArray::New());
41 const GrowableObjectArray& code_list =
42 GrowableObjectArray::Handle(GrowableObjectArray::New());
43 const GrowableObjectArray& pc_offset_list =
44 GrowableObjectArray::Handle(GrowableObjectArray::New());
45 StackFrameIterator frames(StackFrameIterator::kDontValidateFrames); 36 StackFrameIterator frames(StackFrameIterator::kDontValidateFrames);
46 StackFrame* frame = frames.NextFrame(); 37 StackFrame* frame = frames.NextFrame();
47 ASSERT(frame != NULL); // We expect to find a dart invocation frame. 38 ASSERT(frame != NULL); // We expect to find a dart invocation frame.
48 Function& func = Function::Handle(); 39 Function& func = Function::Handle();
49 Code& code = Code::Handle(); 40 Code& code = Code::Handle();
50 Smi& offset = Smi::Handle(); 41 Smi& offset = Smi::Handle();
51 bool catch_frame_skipped = false; // Tracks if catch frame has been skipped. 42 bool catch_frame_skipped = false; // Tracks if catch frame has been skipped.
52 while (frame != NULL) { 43 while (frame != NULL) {
53 if (frame->IsDartFrame()) { 44 if (frame->IsDartFrame()) {
54 code = frame->LookupDartCode(); 45 code = frame->LookupDartCode();
(...skipping 28 matching lines...) Expand all
83 } else { 74 } else {
84 func_list.Add(func); 75 func_list.Add(func);
85 code_list.Add(code); 76 code_list.Add(code);
86 pc_offset_list.Add(offset); 77 pc_offset_list.Add(offset);
87 } 78 }
88 } 79 }
89 } 80 }
90 } 81 }
91 frame = frames.NextFrame(); 82 frame = frames.NextFrame();
92 } 83 }
84 }
85
86
87 // Setup a full stack trace.
88 // Arg0: stack trace object.
89 // Return value: None.
90 DEFINE_NATIVE_ENTRY(Stacktrace_setupFullStacktrace, 1) {
91 const Stacktrace& trace =
92 Stacktrace::CheckedHandle(arguments->NativeArgAt(0));
93 const GrowableObjectArray& func_list =
94 GrowableObjectArray::Handle(GrowableObjectArray::New());
95 const GrowableObjectArray& code_list =
96 GrowableObjectArray::Handle(GrowableObjectArray::New());
97 const GrowableObjectArray& pc_offset_list =
98 GrowableObjectArray::Handle(GrowableObjectArray::New());
99 iterateFrames(func_list, code_list, pc_offset_list);
93 const Array& func_array = Array::Handle(Array::MakeArray(func_list)); 100 const Array& func_array = Array::Handle(Array::MakeArray(func_list));
94 const Array& code_array = Array::Handle(Array::MakeArray(code_list)); 101 const Array& code_array = Array::Handle(Array::MakeArray(code_list));
95 const Array& pc_offset_array = 102 const Array& pc_offset_array =
96 Array::Handle(Array::MakeArray(pc_offset_list)); 103 Array::Handle(Array::MakeArray(pc_offset_list));
97 trace.SetCatchStacktrace(func_array, code_array, pc_offset_array); 104 trace.SetCatchStacktrace(func_array, code_array, pc_offset_array);
98 return Object::null(); 105 return Object::null();
99 } 106 }
100 107
108
109 // An utility method for convenient printing of dart stack traces when
110 // 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
112 // set in dart code and control is got inside 'gdb' without going through
113 // the runtime or native transition stub.
114 void _printCurrentStacktrace() {
115 const GrowableObjectArray& func_list =
116 GrowableObjectArray::Handle(GrowableObjectArray::New());
117 const GrowableObjectArray& code_list =
118 GrowableObjectArray::Handle(GrowableObjectArray::New());
119 const GrowableObjectArray& pc_offset_list =
120 GrowableObjectArray::Handle(GrowableObjectArray::New());
121 iterateFrames(func_list, 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));
124 const Array& pc_offset_array =
125 Array::Handle(Array::MakeArray(pc_offset_list));
126 const Stacktrace& stacktrace = Stacktrace::Handle(
127 Stacktrace::New(func_array, code_array, pc_offset_array));
128 OS::Print("%s\n", stacktrace.ToCString());
129 }
130
101 } // namespace dart 131 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/dart_api_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698