| OLD | NEW |
| 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 "platform/address_sanitizer.h" | 7 #include "platform/address_sanitizer.h" |
| 8 | 8 |
| 9 #include "vm/dart_api_impl.h" | 9 #include "vm/dart_api_impl.h" |
| 10 #include "vm/dart_entry.h" | 10 #include "vm/dart_entry.h" |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 } | 125 } |
| 126 frame = frames.NextFrame(); | 126 frame = frames.NextFrame(); |
| 127 } | 127 } |
| 128 } | 128 } |
| 129 | 129 |
| 130 | 130 |
| 131 // Iterate through the stack frames and try to find a frame with an | 131 // Iterate through the stack frames and try to find a frame with an |
| 132 // exception handler. Once found, set the pc, sp and fp so that execution | 132 // exception handler. Once found, set the pc, sp and fp so that execution |
| 133 // can continue in that frame. Sets 'needs_stacktrace' if there is no | 133 // can continue in that frame. Sets 'needs_stacktrace' if there is no |
| 134 // cath-all handler or if a stack-trace is specified in the catch. | 134 // cath-all handler or if a stack-trace is specified in the catch. |
| 135 static bool FindExceptionHandler(Isolate* isolate, | 135 static bool FindExceptionHandler(Thread* thread, |
| 136 uword* handler_pc, | 136 uword* handler_pc, |
| 137 uword* handler_sp, | 137 uword* handler_sp, |
| 138 uword* handler_fp, | 138 uword* handler_fp, |
| 139 bool* needs_stacktrace) { | 139 bool* needs_stacktrace) { |
| 140 StackFrameIterator frames(StackFrameIterator::kDontValidateFrames); | 140 StackFrameIterator frames(StackFrameIterator::kDontValidateFrames); |
| 141 StackFrame* frame = frames.NextFrame(); | 141 StackFrame* frame = frames.NextFrame(); |
| 142 ASSERT(frame != NULL); // We expect to find a dart invocation frame. | 142 ASSERT(frame != NULL); // We expect to find a dart invocation frame. |
| 143 bool handler_pc_set = false; | 143 bool handler_pc_set = false; |
| 144 *needs_stacktrace = false; | 144 *needs_stacktrace = false; |
| 145 bool is_catch_all = false; | 145 bool is_catch_all = false; |
| 146 uword temp_handler_pc = kUwordMax; | 146 uword temp_handler_pc = kUwordMax; |
| 147 while (!frame->IsEntryFrame()) { | 147 while (!frame->IsEntryFrame()) { |
| 148 if (frame->IsDartFrame()) { | 148 if (frame->IsDartFrame()) { |
| 149 if (frame->FindExceptionHandler(isolate, | 149 if (frame->FindExceptionHandler(thread, |
| 150 &temp_handler_pc, | 150 &temp_handler_pc, |
| 151 needs_stacktrace, | 151 needs_stacktrace, |
| 152 &is_catch_all)) { | 152 &is_catch_all)) { |
| 153 if (!handler_pc_set) { | 153 if (!handler_pc_set) { |
| 154 handler_pc_set = true; | 154 handler_pc_set = true; |
| 155 *handler_pc = temp_handler_pc; | 155 *handler_pc = temp_handler_pc; |
| 156 *handler_sp = frame->sp(); | 156 *handler_sp = frame->sp(); |
| 157 *handler_fp = frame->fp(); | 157 *handler_fp = frame->fp(); |
| 158 } | 158 } |
| 159 if (*needs_stacktrace || is_catch_all) { | 159 if (*needs_stacktrace || is_catch_all) { |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 } | 304 } |
| 305 uword handler_pc = 0; | 305 uword handler_pc = 0; |
| 306 uword handler_sp = 0; | 306 uword handler_sp = 0; |
| 307 uword handler_fp = 0; | 307 uword handler_fp = 0; |
| 308 Instance& stacktrace = Instance::Handle(isolate); | 308 Instance& stacktrace = Instance::Handle(isolate); |
| 309 bool handler_exists = false; | 309 bool handler_exists = false; |
| 310 bool handler_needs_stacktrace = false; | 310 bool handler_needs_stacktrace = false; |
| 311 if (use_preallocated_stacktrace) { | 311 if (use_preallocated_stacktrace) { |
| 312 stacktrace ^= isolate->object_store()->preallocated_stack_trace(); | 312 stacktrace ^= isolate->object_store()->preallocated_stack_trace(); |
| 313 PreallocatedStacktraceBuilder frame_builder(stacktrace); | 313 PreallocatedStacktraceBuilder frame_builder(stacktrace); |
| 314 handler_exists = FindExceptionHandler(isolate, | 314 handler_exists = FindExceptionHandler(thread, |
| 315 &handler_pc, | 315 &handler_pc, |
| 316 &handler_sp, | 316 &handler_sp, |
| 317 &handler_fp, | 317 &handler_fp, |
| 318 &handler_needs_stacktrace); | 318 &handler_needs_stacktrace); |
| 319 if (handler_needs_stacktrace) { | 319 if (handler_needs_stacktrace) { |
| 320 BuildStackTrace(isolate, &frame_builder); | 320 BuildStackTrace(isolate, &frame_builder); |
| 321 } | 321 } |
| 322 } else { | 322 } else { |
| 323 // Get stacktrace field of class Error. This is needed to determine whether | 323 // Get stacktrace field of class Error. This is needed to determine whether |
| 324 // we have a subclass of Error which carries around its stack trace. | 324 // we have a subclass of Error which carries around its stack trace. |
| 325 const Field& stacktrace_field = | 325 const Field& stacktrace_field = |
| 326 Field::Handle(isolate, LookupStacktraceField(exception)); | 326 Field::Handle(isolate, LookupStacktraceField(exception)); |
| 327 | 327 |
| 328 // Find the exception handler and determine if the handler needs a | 328 // Find the exception handler and determine if the handler needs a |
| 329 // stacktrace. | 329 // stacktrace. |
| 330 handler_exists = FindExceptionHandler(isolate, | 330 handler_exists = FindExceptionHandler(thread, |
| 331 &handler_pc, | 331 &handler_pc, |
| 332 &handler_sp, | 332 &handler_sp, |
| 333 &handler_fp, | 333 &handler_fp, |
| 334 &handler_needs_stacktrace); | 334 &handler_needs_stacktrace); |
| 335 if (!existing_stacktrace.IsNull()) { | 335 if (!existing_stacktrace.IsNull()) { |
| 336 // If we have an existing stack trace then this better be a rethrow. The | 336 // If we have an existing stack trace then this better be a rethrow. The |
| 337 // reverse is not necessarily true (e.g. Dart_PropagateError can cause | 337 // reverse is not necessarily true (e.g. Dart_PropagateError can cause |
| 338 // a rethrow being called without an existing stacktrace.) | 338 // a rethrow being called without an existing stacktrace.) |
| 339 ASSERT(is_rethrow); | 339 ASSERT(is_rethrow); |
| 340 ASSERT(stacktrace_field.IsNull() || | 340 ASSERT(stacktrace_field.IsNull() || |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 671 | 671 |
| 672 // Throw JavascriptCompatibilityError exception. | 672 // Throw JavascriptCompatibilityError exception. |
| 673 void Exceptions::ThrowJavascriptCompatibilityError(const char* msg) { | 673 void Exceptions::ThrowJavascriptCompatibilityError(const char* msg) { |
| 674 const Array& exc_args = Array::Handle(Array::New(1)); | 674 const Array& exc_args = Array::Handle(Array::New(1)); |
| 675 const String& msg_str = String::Handle(String::New(msg)); | 675 const String& msg_str = String::Handle(String::New(msg)); |
| 676 exc_args.SetAt(0, msg_str); | 676 exc_args.SetAt(0, msg_str); |
| 677 Exceptions::ThrowByType(Exceptions::kJavascriptCompatibilityError, exc_args); | 677 Exceptions::ThrowByType(Exceptions::kJavascriptCompatibilityError, exc_args); |
| 678 } | 678 } |
| 679 | 679 |
| 680 } // namespace dart | 680 } // namespace dart |
| OLD | NEW |