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

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') | runtime/vm/dart_api_impl.h » ('J')
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 27 matching lines...) Expand all
82 } else { 73 } else {
83 func_list.Add(func); 74 func_list.Add(func);
84 code_list.Add(code); 75 code_list.Add(code);
85 pc_offset_list.Add(offset); 76 pc_offset_list.Add(offset);
86 } 77 }
87 } 78 }
88 } 79 }
89 } 80 }
90 frame = frames.NextFrame(); 81 frame = frames.NextFrame();
91 } 82 }
83 }
84
85
86 // Setup a full stack trace.
87 // Arg0: stack trace object.
88 // Return value: None.
89 DEFINE_NATIVE_ENTRY(Stacktrace_setupFullStacktrace, 1) {
90 const Stacktrace& trace =
91 Stacktrace::CheckedHandle(arguments->NativeArgAt(0));
92 const GrowableObjectArray& func_list =
93 GrowableObjectArray::Handle(GrowableObjectArray::New());
94 const GrowableObjectArray& code_list =
95 GrowableObjectArray::Handle(GrowableObjectArray::New());
96 const GrowableObjectArray& pc_offset_list =
97 GrowableObjectArray::Handle(GrowableObjectArray::New());
98 iterateFrames(func_list, code_list, pc_offset_list);
92 const Array& func_array = Array::Handle(Array::MakeArray(func_list)); 99 const Array& func_array = Array::Handle(Array::MakeArray(func_list));
93 const Array& code_array = Array::Handle(Array::MakeArray(code_list)); 100 const Array& code_array = Array::Handle(Array::MakeArray(code_list));
94 const Array& pc_offset_array = 101 const Array& pc_offset_array =
95 Array::Handle(Array::MakeArray(pc_offset_list)); 102 Array::Handle(Array::MakeArray(pc_offset_list));
96 trace.SetCatchStacktrace(func_array, code_array, pc_offset_array); 103 trace.SetCatchStacktrace(func_array, code_array, pc_offset_array);
97 return Object::null(); 104 return Object::null();
98 } 105 }
99 106
107
108 // An utility method for convenient printing of dart stack traces when
109 // inside 'gdb'. Note: This function will only work when there is a
110 // valid exit frame information. It will not work when a breakpoint is
111 // set in dart code and control is got inside 'gdb' without going through
112 // the runtime or native transition stub.
113 void _printCurrentStacktrace() {
114 const GrowableObjectArray& func_list =
115 GrowableObjectArray::Handle(GrowableObjectArray::New());
116 const GrowableObjectArray& code_list =
117 GrowableObjectArray::Handle(GrowableObjectArray::New());
118 const GrowableObjectArray& pc_offset_list =
119 GrowableObjectArray::Handle(GrowableObjectArray::New());
120 iterateFrames(func_list, code_list, pc_offset_list);
121 const Array& func_array = Array::Handle(Array::MakeArray(func_list));
122 const Array& code_array = Array::Handle(Array::MakeArray(code_list));
123 const Array& pc_offset_array =
124 Array::Handle(Array::MakeArray(pc_offset_list));
125 const Stacktrace& stacktrace = Stacktrace::Handle(
126 Stacktrace::New(func_array, code_array, pc_offset_array));
127 OS::Print("%s\n", stacktrace.ToCString());
128 }
129
100 } // namespace dart 130 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/dart_api_impl.h » ('j') | runtime/vm/dart_api_impl.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698