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

Side by Side Diff: vm/exceptions.cc

Issue 10824128: Eagerly get the function and code corresponding to the frame elements in a stack trace so that we w… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 4 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 | vm/object.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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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/exceptions.h" 5 #include "vm/exceptions.h"
6 6
7 #include "vm/dart_entry.h" 7 #include "vm/dart_entry.h"
8 #include "vm/debugger.h" 8 #include "vm/debugger.h"
9 #include "vm/flags.h" 9 #include "vm/flags.h"
10 #include "vm/object.h" 10 #include "vm/object.h"
11 #include "vm/stack_frame.h" 11 #include "vm/stack_frame.h"
12 #include "vm/stub_code.h" 12 #include "vm/stub_code.h"
13 #include "vm/symbols.h" 13 #include "vm/symbols.h"
14 14
15 namespace dart { 15 namespace dart {
16 16
17 DEFINE_FLAG(bool, print_stacktrace_at_throw, false, 17 DEFINE_FLAG(bool, print_stacktrace_at_throw, false,
18 "Prints a stack trace everytime a throw occurs."); 18 "Prints a stack trace everytime a throw occurs.");
19 19
20 20
21 const char* Exceptions::kCastExceptionDstName = "type cast"; 21 const char* Exceptions::kCastExceptionDstName = "type cast";
22 22
23 23
24 // Iterate through the stack frames and try to find a frame with an 24 // Iterate through the stack frames and try to find a frame with an
25 // exception handler. Once found, set the pc, sp and fp so that execution 25 // exception handler. Once found, set the pc, sp and fp so that execution
26 // can continue in that frame. 26 // can continue in that frame.
27 static bool FindExceptionHandler(uword* handler_pc, 27 static bool FindExceptionHandler(uword* handler_pc,
28 uword* handler_sp, 28 uword* handler_sp,
29 uword* handler_fp, 29 uword* handler_fp,
30 GrowableArray<uword>* stack_frame_pcs) { 30 GrowableArray<uword>* stack_frame_pcs,
31 const GrowableObjectArray& func_list,
32 const GrowableObjectArray& code_list) {
Ivan Posva 2012/08/03 20:49:53 How about this: FindExceptionHandler(... const
31 StackFrameIterator frames(StackFrameIterator::kDontValidateFrames); 33 StackFrameIterator frames(StackFrameIterator::kDontValidateFrames);
32 StackFrame* frame = frames.NextFrame(); 34 StackFrame* frame = frames.NextFrame();
33 ASSERT(frame != NULL); 35 ASSERT(frame != NULL);
36 Function& func = Function::Handle();
37 Code& code = Code::Handle();
34 while (!frame->IsEntryFrame()) { 38 while (!frame->IsEntryFrame()) {
35 if (frame->IsDartFrame()) { 39 if (frame->IsDartFrame()) {
36 stack_frame_pcs->Add(frame->pc()); 40 stack_frame_pcs->Add(frame->pc());
41 func = frame->LookupDartFunction();
42 code = frame->LookupDartCode();
43 func_list.Add(func);
44 code_list.Add(code);
37 if (frame->FindExceptionHandler(handler_pc)) { 45 if (frame->FindExceptionHandler(handler_pc)) {
38 *handler_sp = frame->sp(); 46 *handler_sp = frame->sp();
39 *handler_fp = frame->fp(); 47 *handler_fp = frame->fp();
40 return true; 48 return true;
41 } 49 }
42 } 50 }
43 frame = frames.NextFrame(); 51 frame = frames.NextFrame();
44 ASSERT(frame != NULL); 52 ASSERT(frame != NULL);
45 } 53 }
46 ASSERT(frame->IsEntryFrame()); 54 ASSERT(frame->IsEntryFrame());
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 const Instance& existing_stacktrace) { 137 const Instance& existing_stacktrace) {
130 Instance& exception = Instance::Handle(incoming_exception.raw()); 138 Instance& exception = Instance::Handle(incoming_exception.raw());
131 if (exception.IsNull()) { 139 if (exception.IsNull()) {
132 GrowableArray<const Object*> arguments; 140 GrowableArray<const Object*> arguments;
133 exception ^= Exceptions::Create(Exceptions::kNullPointer, arguments); 141 exception ^= Exceptions::Create(Exceptions::kNullPointer, arguments);
134 } 142 }
135 uword handler_pc = 0; 143 uword handler_pc = 0;
136 uword handler_sp = 0; 144 uword handler_sp = 0;
137 uword handler_fp = 0; 145 uword handler_fp = 0;
138 GrowableArray<uword> stack_frame_pcs; 146 GrowableArray<uword> stack_frame_pcs;
147 const GrowableObjectArray& func_list =
148 GrowableObjectArray::Handle(GrowableObjectArray::New());
149 const GrowableObjectArray& code_list =
150 GrowableObjectArray::Handle(GrowableObjectArray::New());
139 bool handler_exists = FindExceptionHandler(&handler_pc, 151 bool handler_exists = FindExceptionHandler(&handler_pc,
140 &handler_sp, 152 &handler_sp,
141 &handler_fp, 153 &handler_fp,
142 &stack_frame_pcs); 154 &stack_frame_pcs,
155 func_list,
156 code_list);
143 // TODO(5411263): At some point we can optimize by figuring out if a 157 // TODO(5411263): At some point we can optimize by figuring out if a
144 // stack trace is needed based on whether the catch code specifies a 158 // stack trace is needed based on whether the catch code specifies a
145 // stack trace object or there is a rethrow in the catch clause. 159 // stack trace object or there is a rethrow in the catch clause.
146 Stacktrace& stacktrace = Stacktrace::Handle(); 160 Stacktrace& stacktrace = Stacktrace::Handle();
147 if (!stack_frame_pcs.is_empty()) { 161 if (!stack_frame_pcs.is_empty()) {
148 if (existing_stacktrace.IsNull()) { 162 if (existing_stacktrace.IsNull()) {
149 stacktrace = Stacktrace::New(stack_frame_pcs); 163 stacktrace = Stacktrace::New(stack_frame_pcs, func_list, code_list);
150 } else { 164 } else {
151 stacktrace ^= existing_stacktrace.raw(); 165 stacktrace ^= existing_stacktrace.raw();
152 stacktrace.Append(stack_frame_pcs); 166 stacktrace.Append(stack_frame_pcs, func_list, code_list);
153 } 167 }
154 } else { 168 } else {
155 stacktrace ^= existing_stacktrace.raw(); 169 stacktrace ^= existing_stacktrace.raw();
156 } 170 }
157 if (FLAG_print_stacktrace_at_throw) { 171 if (FLAG_print_stacktrace_at_throw) {
158 OS::Print("Exception '%s' thrown:\n", exception.ToCString()); 172 OS::Print("Exception '%s' thrown:\n", exception.ToCString());
159 OS::Print("%s\n", stacktrace.ToCString()); 173 OS::Print("%s\n", stacktrace.ToCString());
160 } 174 }
161 if (handler_exists) { 175 if (handler_exists) {
162 // Found a dart handler for the exception, jump to it. 176 // Found a dart handler for the exception, jump to it.
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 case kIsolateSpawn: 432 case kIsolateSpawn:
419 library = Library::IsolateLibrary(); 433 library = Library::IsolateLibrary();
420 class_name = Symbols::New("IsolateSpawnException"); 434 class_name = Symbols::New("IsolateSpawnException");
421 break; 435 break;
422 } 436 }
423 437
424 return DartLibraryCalls::ExceptionCreate(library, class_name, arguments); 438 return DartLibraryCalls::ExceptionCreate(library, class_name, arguments);
425 } 439 }
426 440
427 } // namespace dart 441 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | vm/object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698