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 "vm/dart_api_impl.h" | 7 #include "vm/dart_api_impl.h" |
8 #include "vm/dart_entry.h" | 8 #include "vm/dart_entry.h" |
9 #include "vm/debugger.h" | 9 #include "vm/debugger.h" |
10 #include "vm/flags.h" | 10 #include "vm/flags.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 // exception handler. Once found, set the pc, sp and fp so that execution | 26 // exception handler. Once found, set the pc, sp and fp so that execution |
27 // can continue in that frame. | 27 // can continue in that frame. |
28 static bool FindExceptionHandler(uword* handler_pc, | 28 static bool FindExceptionHandler(uword* handler_pc, |
29 uword* handler_sp, | 29 uword* handler_sp, |
30 uword* handler_fp, | 30 uword* handler_fp, |
31 const GrowableObjectArray& func_list, | 31 const GrowableObjectArray& func_list, |
32 const GrowableObjectArray& code_list, | 32 const GrowableObjectArray& code_list, |
33 const GrowableObjectArray& pc_offset_list) { | 33 const GrowableObjectArray& pc_offset_list) { |
34 StackFrameIterator frames(StackFrameIterator::kDontValidateFrames); | 34 StackFrameIterator frames(StackFrameIterator::kDontValidateFrames); |
35 StackFrame* frame = frames.NextFrame(); | 35 StackFrame* frame = frames.NextFrame(); |
36 if (frame == NULL) { | 36 ASSERT(frame != NULL); // We expect to find a dart invocation frame. |
37 // We have no dart invocation frames and hence cannot find a handler | |
38 // to return to. | |
39 return false; | |
40 } | |
41 Function& func = Function::Handle(); | 37 Function& func = Function::Handle(); |
42 Code& code = Code::Handle(); | 38 Code& code = Code::Handle(); |
43 Smi& offset = Smi::Handle(); | 39 Smi& offset = Smi::Handle(); |
44 while (!frame->IsEntryFrame()) { | 40 while (!frame->IsEntryFrame()) { |
45 if (frame->IsDartFrame()) { | 41 if (frame->IsDartFrame()) { |
46 func = frame->LookupDartFunction(); | 42 func = frame->LookupDartFunction(); |
47 code = frame->LookupDartCode(); | 43 code = frame->LookupDartCode(); |
48 offset = Smi::New(frame->pc() - code.EntryPoint()); | 44 offset = Smi::New(frame->pc() - code.EntryPoint()); |
49 func_list.Add(func); | 45 func_list.Add(func); |
50 code_list.Add(code); | 46 code_list.Add(code); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 const GrowableObjectArray& code_list = | 151 const GrowableObjectArray& code_list = |
156 GrowableObjectArray::Handle(GrowableObjectArray::New()); | 152 GrowableObjectArray::Handle(GrowableObjectArray::New()); |
157 const GrowableObjectArray& pc_offset_list = | 153 const GrowableObjectArray& pc_offset_list = |
158 GrowableObjectArray::Handle(GrowableObjectArray::New()); | 154 GrowableObjectArray::Handle(GrowableObjectArray::New()); |
159 bool handler_exists = FindExceptionHandler(&handler_pc, | 155 bool handler_exists = FindExceptionHandler(&handler_pc, |
160 &handler_sp, | 156 &handler_sp, |
161 &handler_fp, | 157 &handler_fp, |
162 func_list, | 158 func_list, |
163 code_list, | 159 code_list, |
164 pc_offset_list); | 160 pc_offset_list); |
165 if (handler_pc == 0) { | 161 // We expect to find a handler_pc, if the exception is unhandled |
166 // There are no dart invocation frames on the stack so we do not | 162 // then we expect to at least have the dart entry frame on the |
167 // have a caller to return to. | 163 // stack as Exceptions::Throw should happen only after a dart |
168 ASSERT(!handler_exists); | 164 // invocation has been done. |
169 if (Isolate::UnhandledExceptionCallback() != NULL) { | 165 ASSERT(handler_pc != 0); |
170 // Notify embedder that an unhandled exception occurred. | 166 |
171 Dart_EnterScope(); | |
172 Dart_Handle error_handle = Api::NewHandle(Isolate::Current(), | |
173 incoming_exception.raw()); | |
174 (Isolate::UnhandledExceptionCallback())(error_handle); | |
175 Dart_ExitScope(); | |
176 } else { | |
177 OS::PrintErr("Exception '%s' thrown:\n", exception.ToCString()); | |
178 OS::PrintErr("Shutting down the isolate\n"); | |
179 } | |
180 Dart_ShutdownIsolate(); | |
181 } | |
182 // TODO(5411263): At some point we can optimize by figuring out if a | 167 // TODO(5411263): At some point we can optimize by figuring out if a |
183 // stack trace is needed based on whether the catch code specifies a | 168 // stack trace is needed based on whether the catch code specifies a |
184 // stack trace object or there is a rethrow in the catch clause. | 169 // stack trace object or there is a rethrow in the catch clause. |
185 Stacktrace& stacktrace = Stacktrace::Handle(); | 170 Stacktrace& stacktrace = Stacktrace::Handle(); |
186 if (pc_offset_list.Length() != 0) { | 171 if (pc_offset_list.Length() != 0) { |
187 if (existing_stacktrace.IsNull()) { | 172 if (existing_stacktrace.IsNull()) { |
188 stacktrace = Stacktrace::New(func_list, code_list, pc_offset_list); | 173 stacktrace = Stacktrace::New(func_list, code_list, pc_offset_list); |
189 } else { | 174 } else { |
190 stacktrace ^= existing_stacktrace.raw(); | 175 stacktrace ^= existing_stacktrace.raw(); |
191 stacktrace.Append(func_list, code_list, pc_offset_list); | 176 stacktrace.Append(func_list, code_list, pc_offset_list); |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 case kIsolateSpawn: | 430 case kIsolateSpawn: |
446 library = Library::IsolateLibrary(); | 431 library = Library::IsolateLibrary(); |
447 class_name = Symbols::New("IsolateSpawnException"); | 432 class_name = Symbols::New("IsolateSpawnException"); |
448 break; | 433 break; |
449 } | 434 } |
450 | 435 |
451 return DartLibraryCalls::ExceptionCreate(library, class_name, arguments); | 436 return DartLibraryCalls::ExceptionCreate(library, class_name, arguments); |
452 } | 437 } |
453 | 438 |
454 } // namespace dart | 439 } // namespace dart |
OLD | NEW |