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

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

Issue 1448003002: Add StackTrace.current getter. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Address VM comments. Created 5 years 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
« no previous file with comments | « runtime/lib/core_patch.dart ('k') | runtime/vm/bootstrap_natives.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
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 int skip_frames) {
15 StackFrameIterator frames(StackFrameIterator::kDontValidateFrames); 16 StackFrameIterator frames(StackFrameIterator::kDontValidateFrames);
16 StackFrame* frame = frames.NextFrame(); 17 StackFrame* frame = frames.NextFrame();
17 ASSERT(frame != NULL); // We expect to find a dart invocation frame. 18 ASSERT(frame != NULL); // We expect to find a dart invocation frame.
18 Code& code = Code::Handle(); 19 Code& code = Code::Handle();
19 Smi& offset = Smi::Handle(); 20 Smi& offset = Smi::Handle();
20 while (frame != NULL) { 21 while (frame != NULL) {
21 if (frame->IsDartFrame()) { 22 if (frame->IsDartFrame()) {
22 code = frame->LookupDartCode(); 23 if (skip_frames > 0) {
23 offset = Smi::New(frame->pc() - code.EntryPoint()); 24 skip_frames--;
24 code_list.Add(code); 25 } else {
25 pc_offset_list.Add(offset); 26 code = frame->LookupDartCode();
27 offset = Smi::New(frame->pc() - code.EntryPoint());
28 code_list.Add(code);
29 pc_offset_list.Add(offset);
30 }
26 } 31 }
27 frame = frames.NextFrame(); 32 frame = frames.NextFrame();
28 } 33 }
29 } 34 }
30 35
36 // Creates a Stacktrace object from the current stack.
37 //
38 // Skips the first skip_frames Dart frames.
39 static const Stacktrace& GetCurrentStacktrace(int skip_frames) {
40 const GrowableObjectArray& code_list =
41 GrowableObjectArray::Handle(GrowableObjectArray::New());
42 const GrowableObjectArray& pc_offset_list =
43 GrowableObjectArray::Handle(GrowableObjectArray::New());
44 IterateFrames(code_list, pc_offset_list, skip_frames);
45 const Array& code_array = Array::Handle(Array::MakeArray(code_list));
46 const Array& pc_offset_array =
47 Array::Handle(Array::MakeArray(pc_offset_list));
48 const Stacktrace& stacktrace = Stacktrace::Handle(
49 Stacktrace::New(code_array, pc_offset_array));
50 return stacktrace;
51 }
31 52
32 // An utility method for convenient printing of dart stack traces when 53 // An utility method for convenient printing of dart stack traces when
33 // inside 'gdb'. Note: This function will only work when there is a 54 // inside 'gdb'. Note: This function will only work when there is a
34 // valid exit frame information. It will not work when a breakpoint is 55 // valid exit frame information. It will not work when a breakpoint is
35 // set in dart code and control is got inside 'gdb' without going through 56 // set in dart code and control is got inside 'gdb' without going through
36 // the runtime or native transition stub. 57 // the runtime or native transition stub.
37 void _printCurrentStacktrace() { 58 void _printCurrentStacktrace() {
38 const GrowableObjectArray& code_list = 59 const Stacktrace& stacktrace = GetCurrentStacktrace(0);
39 GrowableObjectArray::Handle(GrowableObjectArray::New());
40 const GrowableObjectArray& pc_offset_list =
41 GrowableObjectArray::Handle(GrowableObjectArray::New());
42 IterateFrames(code_list, pc_offset_list);
43 const Array& code_array = Array::Handle(Array::MakeArray(code_list));
44 const Array& pc_offset_array =
45 Array::Handle(Array::MakeArray(pc_offset_list));
46 const Stacktrace& stacktrace = Stacktrace::Handle(
47 Stacktrace::New(code_array, pc_offset_array));
48 OS::PrintErr("=== Current Trace:\n%s===\n", stacktrace.ToCString()); 60 OS::PrintErr("=== Current Trace:\n%s===\n", stacktrace.ToCString());
49 } 61 }
50 62
63 DEFINE_NATIVE_ENTRY(StackTrace_current, 0) {
64 const Stacktrace& stacktrace = GetCurrentStacktrace(1);
65 return stacktrace.raw();
66 }
67
51 } // namespace dart 68 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/lib/core_patch.dart ('k') | runtime/vm/bootstrap_natives.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698