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