| 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 "lib/stacktrace.h" | 9 #include "lib/stacktrace.h" |
| 10 | 10 |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 } | 121 } |
| 122 cur_index_ = (StackTrace::kPreallocatedStackdepth - 1); | 122 cur_index_ = (StackTrace::kPreallocatedStackdepth - 1); |
| 123 } | 123 } |
| 124 stacktrace_.SetCodeAtFrame(cur_index_, code); | 124 stacktrace_.SetCodeAtFrame(cur_index_, code); |
| 125 stacktrace_.SetPcOffsetAtFrame(cur_index_, offset); | 125 stacktrace_.SetPcOffsetAtFrame(cur_index_, offset); |
| 126 cur_index_ += 1; | 126 cur_index_ += 1; |
| 127 } | 127 } |
| 128 | 128 |
| 129 | 129 |
| 130 static void BuildStackTrace(StackTraceBuilder* builder) { | 130 static void BuildStackTrace(StackTraceBuilder* builder) { |
| 131 StackFrameIterator frames(StackFrameIterator::kDontValidateFrames); | 131 StackFrameIterator frames(StackFrameIterator::kDontValidateFrames, |
| 132 Thread::Current(), |
| 133 StackFrameIterator::kNoCrossThreadIteration); |
| 132 StackFrame* frame = frames.NextFrame(); | 134 StackFrame* frame = frames.NextFrame(); |
| 133 ASSERT(frame != NULL); // We expect to find a dart invocation frame. | 135 ASSERT(frame != NULL); // We expect to find a dart invocation frame. |
| 134 Code& code = Code::Handle(); | 136 Code& code = Code::Handle(); |
| 135 Smi& offset = Smi::Handle(); | 137 Smi& offset = Smi::Handle(); |
| 136 while (frame != NULL) { | 138 while (frame != NULL) { |
| 137 if (frame->IsDartFrame()) { | 139 if (frame->IsDartFrame()) { |
| 138 code = frame->LookupDartCode(); | 140 code = frame->LookupDartCode(); |
| 139 ASSERT(code.ContainsInstructionAt(frame->pc())); | 141 ASSERT(code.ContainsInstructionAt(frame->pc())); |
| 140 offset = Smi::New(frame->pc() - code.PayloadStart()); | 142 offset = Smi::New(frame->pc() - code.PayloadStart()); |
| 141 builder->AddFrame(code, offset); | 143 builder->AddFrame(code, offset); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 162 class ExceptionHandlerFinder : public StackResource { | 164 class ExceptionHandlerFinder : public StackResource { |
| 163 public: | 165 public: |
| 164 explicit ExceptionHandlerFinder(Thread* thread) | 166 explicit ExceptionHandlerFinder(Thread* thread) |
| 165 : StackResource(thread), thread_(thread), cache_(NULL), metadata_(NULL) {} | 167 : StackResource(thread), thread_(thread), cache_(NULL), metadata_(NULL) {} |
| 166 | 168 |
| 167 // Iterate through the stack frames and try to find a frame with an | 169 // Iterate through the stack frames and try to find a frame with an |
| 168 // exception handler. Once found, set the pc, sp and fp so that execution | 170 // exception handler. Once found, set the pc, sp and fp so that execution |
| 169 // can continue in that frame. Sets 'needs_stacktrace' if there is no | 171 // can continue in that frame. Sets 'needs_stacktrace' if there is no |
| 170 // cath-all handler or if a stack-trace is specified in the catch. | 172 // cath-all handler or if a stack-trace is specified in the catch. |
| 171 bool Find() { | 173 bool Find() { |
| 172 StackFrameIterator frames(StackFrameIterator::kDontValidateFrames); | 174 StackFrameIterator frames(StackFrameIterator::kDontValidateFrames, |
| 175 Thread::Current(), |
| 176 StackFrameIterator::kNoCrossThreadIteration); |
| 173 StackFrame* frame = frames.NextFrame(); | 177 StackFrame* frame = frames.NextFrame(); |
| 174 if (frame == NULL) return false; // No Dart frame. | 178 if (frame == NULL) return false; // No Dart frame. |
| 175 handler_pc_set_ = false; | 179 handler_pc_set_ = false; |
| 176 needs_stacktrace = false; | 180 needs_stacktrace = false; |
| 177 bool is_catch_all = false; | 181 bool is_catch_all = false; |
| 178 uword temp_handler_pc = kUwordMax; | 182 uword temp_handler_pc = kUwordMax; |
| 179 bool is_optimized = false; | 183 bool is_optimized = false; |
| 180 code_ = NULL; | 184 code_ = NULL; |
| 181 cache_ = thread_->isolate()->catch_entry_state_cache(); | 185 cache_ = thread_->isolate()->catch_entry_state_cache(); |
| 182 | 186 |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 bool handler_pc_set_; | 344 bool handler_pc_set_; |
| 341 intptr_t* metadata_; // MetaData generated from deopt. | 345 intptr_t* metadata_; // MetaData generated from deopt. |
| 342 CatchEntryState cached_; // Value of per PC MetaData cache. | 346 CatchEntryState cached_; // Value of per PC MetaData cache. |
| 343 intptr_t pc_; // Current pc in the handler frame. | 347 intptr_t pc_; // Current pc in the handler frame. |
| 344 }; | 348 }; |
| 345 | 349 |
| 346 | 350 |
| 347 static void FindErrorHandler(uword* handler_pc, | 351 static void FindErrorHandler(uword* handler_pc, |
| 348 uword* handler_sp, | 352 uword* handler_sp, |
| 349 uword* handler_fp) { | 353 uword* handler_fp) { |
| 350 StackFrameIterator frames(StackFrameIterator::kDontValidateFrames); | 354 StackFrameIterator frames(StackFrameIterator::kDontValidateFrames, |
| 355 Thread::Current(), |
| 356 StackFrameIterator::kNoCrossThreadIteration); |
| 351 StackFrame* frame = frames.NextFrame(); | 357 StackFrame* frame = frames.NextFrame(); |
| 352 ASSERT(frame != NULL); | 358 ASSERT(frame != NULL); |
| 353 while (!frame->IsEntryFrame()) { | 359 while (!frame->IsEntryFrame()) { |
| 354 frame = frames.NextFrame(); | 360 frame = frames.NextFrame(); |
| 355 ASSERT(frame != NULL); | 361 ASSERT(frame != NULL); |
| 356 } | 362 } |
| 357 ASSERT(frame->IsEntryFrame()); | 363 ASSERT(frame->IsEntryFrame()); |
| 358 *handler_pc = frame->pc(); | 364 *handler_pc = frame->pc(); |
| 359 *handler_sp = frame->sp(); | 365 *handler_sp = frame->sp(); |
| 360 *handler_fp = frame->fp(); | 366 *handler_fp = frame->fp(); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 | 399 |
| 394 static void ClearLazyDeopts(Thread* thread, uword frame_pointer) { | 400 static void ClearLazyDeopts(Thread* thread, uword frame_pointer) { |
| 395 #if !defined(TARGET_ARCH_DBC) | 401 #if !defined(TARGET_ARCH_DBC) |
| 396 MallocGrowableArray<PendingLazyDeopt>* pending_deopts = | 402 MallocGrowableArray<PendingLazyDeopt>* pending_deopts = |
| 397 thread->isolate()->pending_deopts(); | 403 thread->isolate()->pending_deopts(); |
| 398 if (pending_deopts->length() > 0) { | 404 if (pending_deopts->length() > 0) { |
| 399 // We may be jumping over frames scheduled for lazy deopt. Remove these | 405 // We may be jumping over frames scheduled for lazy deopt. Remove these |
| 400 // frames from the pending deopt table, but only after unmarking them so | 406 // frames from the pending deopt table, but only after unmarking them so |
| 401 // any stack walk that happens before the stack is unwound will still work. | 407 // any stack walk that happens before the stack is unwound will still work. |
| 402 { | 408 { |
| 403 DartFrameIterator frames(thread); | 409 DartFrameIterator frames(thread, |
| 410 StackFrameIterator::kNoCrossThreadIteration); |
| 404 StackFrame* frame = frames.NextFrame(); | 411 StackFrame* frame = frames.NextFrame(); |
| 405 while ((frame != NULL) && (frame->fp() < frame_pointer)) { | 412 while ((frame != NULL) && (frame->fp() < frame_pointer)) { |
| 406 if (frame->IsMarkedForLazyDeopt()) { | 413 if (frame->IsMarkedForLazyDeopt()) { |
| 407 frame->UnmarkForLazyDeopt(); | 414 frame->UnmarkForLazyDeopt(); |
| 408 } | 415 } |
| 409 frame = frames.NextFrame(); | 416 frame = frames.NextFrame(); |
| 410 } | 417 } |
| 411 } | 418 } |
| 412 | 419 |
| 413 #if defined(DEBUG) | 420 #if defined(DEBUG) |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 662 | 669 |
| 663 | 670 |
| 664 // Allocate, initialize, and throw a TypeError or CastError. | 671 // Allocate, initialize, and throw a TypeError or CastError. |
| 665 // If error_msg is not null, throw a TypeError, even for a type cast. | 672 // If error_msg is not null, throw a TypeError, even for a type cast. |
| 666 void Exceptions::CreateAndThrowTypeError(TokenPosition location, | 673 void Exceptions::CreateAndThrowTypeError(TokenPosition location, |
| 667 const AbstractType& src_type, | 674 const AbstractType& src_type, |
| 668 const AbstractType& dst_type, | 675 const AbstractType& dst_type, |
| 669 const String& dst_name, | 676 const String& dst_name, |
| 670 const String& bound_error_msg) { | 677 const String& bound_error_msg) { |
| 671 ASSERT(!dst_name.IsNull()); // Pass Symbols::Empty() instead. | 678 ASSERT(!dst_name.IsNull()); // Pass Symbols::Empty() instead. |
| 672 Zone* zone = Thread::Current()->zone(); | 679 Thread* thread = Thread::Current(); |
| 680 Zone* zone = thread->zone(); |
| 673 const Array& args = Array::Handle(zone, Array::New(4)); | 681 const Array& args = Array::Handle(zone, Array::New(4)); |
| 674 | 682 |
| 675 ExceptionType exception_type = | 683 ExceptionType exception_type = |
| 676 (bound_error_msg.IsNull() && | 684 (bound_error_msg.IsNull() && |
| 677 (dst_name.raw() == Symbols::InTypeCast().raw())) | 685 (dst_name.raw() == Symbols::InTypeCast().raw())) |
| 678 ? kCast | 686 ? kCast |
| 679 : kType; | 687 : kType; |
| 680 | 688 |
| 681 DartFrameIterator iterator; | 689 DartFrameIterator iterator(thread, |
| 690 StackFrameIterator::kNoCrossThreadIteration); |
| 682 const Script& script = Script::Handle(zone, GetCallerScript(&iterator)); | 691 const Script& script = Script::Handle(zone, GetCallerScript(&iterator)); |
| 683 intptr_t line = -1; | 692 intptr_t line = -1; |
| 684 intptr_t column = -1; | 693 intptr_t column = -1; |
| 685 ASSERT(!script.IsNull()); | 694 ASSERT(!script.IsNull()); |
| 686 if (location.IsReal()) { | 695 if (location.IsReal()) { |
| 687 if (script.HasSource() || script.kind() == RawScript::kKernelTag) { | 696 if (script.HasSource() || script.kind() == RawScript::kKernelTag) { |
| 688 script.GetTokenLocation(location, &line, &column); | 697 script.GetTokenLocation(location, &line, &column); |
| 689 } else { | 698 } else { |
| 690 script.GetTokenLocation(location, &line, NULL); | 699 script.GetTokenLocation(location, &line, NULL); |
| 691 } | 700 } |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 974 } | 983 } |
| 975 | 984 |
| 976 Thread* thread = Thread::Current(); | 985 Thread* thread = Thread::Current(); |
| 977 NoReloadScope no_reload_scope(thread->isolate(), thread); | 986 NoReloadScope no_reload_scope(thread->isolate(), thread); |
| 978 return DartLibraryCalls::InstanceCreate(library, *class_name, | 987 return DartLibraryCalls::InstanceCreate(library, *class_name, |
| 979 *constructor_name, arguments); | 988 *constructor_name, arguments); |
| 980 } | 989 } |
| 981 | 990 |
| 982 | 991 |
| 983 } // namespace dart | 992 } // namespace dart |
| OLD | NEW |