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

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

Issue 939773003: - Simplify collection of stack traces. If we determine that a stack (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 5 years, 10 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/lib/stacktrace.dart » ('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
11 namespace dart { 11 namespace dart {
12 12
13 static void IterateFrames(const GrowableObjectArray& code_list, 13 static void IterateFrames(const GrowableObjectArray& code_list,
14 const GrowableObjectArray& pc_offset_list) { 14 const GrowableObjectArray& pc_offset_list) {
15 StackFrameIterator frames(StackFrameIterator::kDontValidateFrames); 15 StackFrameIterator frames(StackFrameIterator::kDontValidateFrames);
16 StackFrame* frame = frames.NextFrame(); 16 StackFrame* frame = frames.NextFrame();
17 ASSERT(frame != NULL); // We expect to find a dart invocation frame. 17 ASSERT(frame != NULL); // We expect to find a dart invocation frame.
18 Code& code = Code::Handle(); 18 Code& code = Code::Handle();
19 Smi& offset = Smi::Handle(); 19 Smi& offset = Smi::Handle();
20 intptr_t frames_to_skip = 2; // _setupFullStackTrace and the catch frame.
21 while (frame != NULL) { 20 while (frame != NULL) {
22 if (frame->IsDartFrame()) { 21 if (frame->IsDartFrame()) {
23 code = frame->LookupDartCode(); 22 code = frame->LookupDartCode();
24 offset = Smi::New(frame->pc() - code.EntryPoint()); 23 offset = Smi::New(frame->pc() - code.EntryPoint());
25 if (frames_to_skip > 0) { 24 code_list.Add(code);
26 frames_to_skip--; 25 pc_offset_list.Add(offset);
27 } else {
28 code_list.Add(code);
29 pc_offset_list.Add(offset);
30 }
31 } 26 }
32 frame = frames.NextFrame(); 27 frame = frames.NextFrame();
33 } 28 }
34 } 29 }
35 30
36 31
37 // Setup a full stack trace.
38 // Arg0: stack trace object.
39 // Return value: None.
40 DEFINE_NATIVE_ENTRY(Stacktrace_setupFullStacktrace, 1) {
41 const Stacktrace& trace =
42 Stacktrace::CheckedHandle(arguments->NativeArgAt(0));
43 const GrowableObjectArray& code_list =
44 GrowableObjectArray::Handle(GrowableObjectArray::New());
45 const GrowableObjectArray& pc_offset_list =
46 GrowableObjectArray::Handle(GrowableObjectArray::New());
47 IterateFrames(code_list, pc_offset_list);
48 const Array& code_array = Array::Handle(Array::MakeArray(code_list));
49 const Array& pc_offset_array =
50 Array::Handle(Array::MakeArray(pc_offset_list));
51 trace.SetCatchStacktrace(code_array, pc_offset_array);
52 return Object::null();
53 }
54
55
56 // An utility method for convenient printing of dart stack traces when 32 // An utility method for convenient printing of dart stack traces when
57 // inside 'gdb'. Note: This function will only work when there is a 33 // inside 'gdb'. Note: This function will only work when there is a
58 // valid exit frame information. It will not work when a breakpoint is 34 // valid exit frame information. It will not work when a breakpoint is
59 // set in dart code and control is got inside 'gdb' without going through 35 // set in dart code and control is got inside 'gdb' without going through
60 // the runtime or native transition stub. 36 // the runtime or native transition stub.
61 void _printCurrentStacktrace() { 37 void _printCurrentStacktrace() {
62 const GrowableObjectArray& code_list = 38 const GrowableObjectArray& code_list =
63 GrowableObjectArray::Handle(GrowableObjectArray::New()); 39 GrowableObjectArray::Handle(GrowableObjectArray::New());
64 const GrowableObjectArray& pc_offset_list = 40 const GrowableObjectArray& pc_offset_list =
65 GrowableObjectArray::Handle(GrowableObjectArray::New()); 41 GrowableObjectArray::Handle(GrowableObjectArray::New());
66 IterateFrames(code_list, pc_offset_list); 42 IterateFrames(code_list, pc_offset_list);
67 const Array& code_array = Array::Handle(Array::MakeArray(code_list)); 43 const Array& code_array = Array::Handle(Array::MakeArray(code_list));
68 const Array& pc_offset_array = 44 const Array& pc_offset_array =
69 Array::Handle(Array::MakeArray(pc_offset_list)); 45 Array::Handle(Array::MakeArray(pc_offset_list));
70 const Stacktrace& stacktrace = Stacktrace::Handle( 46 const Stacktrace& stacktrace = Stacktrace::Handle(
71 Stacktrace::New(code_array, pc_offset_array)); 47 Stacktrace::New(code_array, pc_offset_array));
72 OS::Print("%s\n", stacktrace.ToCString()); 48 OS::PrintErr("=== Current Trace:\n%s\n===\n", stacktrace.ToCString());
73 } 49 }
74 50
75 } // namespace dart 51 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/lib/stacktrace.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698