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

Side by Side Diff: runtime/vm/exceptions.cc

Issue 248213002: Expose functionality to create a stack trace to internal vm code. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 8 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 | « runtime/vm/exceptions.h ('k') | runtime/vm/flow_graph_builder.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_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 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 } 338 }
339 type = test_class.super_type(); 339 type = test_class.super_type();
340 if (type.IsNull()) return Field::null(); 340 if (type.IsNull()) return Field::null();
341 test_class = type.type_class(); 341 test_class = type.type_class();
342 }; 342 };
343 UNREACHABLE(); 343 UNREACHABLE();
344 return Field::null(); 344 return Field::null();
345 } 345 }
346 346
347 347
348 RawStacktrace* Exceptions::CurrentStacktrace() {
349 Isolate* isolate = Isolate::Current();
350 RegularStacktraceBuilder frame_builder(true);
351 BuildStackTrace(&frame_builder);
352
353 // Create arrays for code and pc_offset tuples of each frame.
354 const Array& full_code_array = Array::Handle(isolate,
355 Array::MakeArray(frame_builder.code_list()));
356 const Array& full_pc_offset_array = Array::Handle(isolate,
357 Array::MakeArray(frame_builder.pc_offset_list()));
358 const Array& full_catch_code_array = Array::Handle(isolate,
359 Array::MakeArray(frame_builder.catch_code_list()));
360 const Array& full_catch_pc_offset_array = Array::Handle(isolate,
361 Array::MakeArray(frame_builder.catch_pc_offset_list()));
362 const Stacktrace& full_stacktrace = Stacktrace::Handle(
363 Stacktrace::New(full_code_array, full_pc_offset_array));
364 full_stacktrace.SetCatchStacktrace(full_catch_code_array,
365 full_catch_pc_offset_array);
366 return full_stacktrace.raw();
367 }
368
369
348 static void ThrowExceptionHelper(const Instance& incoming_exception, 370 static void ThrowExceptionHelper(const Instance& incoming_exception,
349 const Instance& existing_stacktrace) { 371 const Instance& existing_stacktrace) {
350 bool use_preallocated_stacktrace = false; 372 bool use_preallocated_stacktrace = false;
351 Isolate* isolate = Isolate::Current(); 373 Isolate* isolate = Isolate::Current();
352 Instance& exception = Instance::Handle(isolate, incoming_exception.raw()); 374 Instance& exception = Instance::Handle(isolate, incoming_exception.raw());
353 if (exception.IsNull()) { 375 if (exception.IsNull()) {
354 exception ^= Exceptions::Create(Exceptions::kNullThrown, 376 exception ^= Exceptions::Create(Exceptions::kNullThrown,
355 Object::empty_array()); 377 Object::empty_array());
356 } else if (exception.raw() == isolate->object_store()->out_of_memory() || 378 } else if (exception.raw() == isolate->object_store()->out_of_memory() ||
357 exception.raw() == isolate->object_store()->stack_overflow()) { 379 exception.raw() == isolate->object_store()->stack_overflow()) {
(...skipping 26 matching lines...) Expand all
384 Array& code_array = Array::Handle(isolate, Object::empty_array().raw()); 406 Array& code_array = Array::Handle(isolate, Object::empty_array().raw());
385 Array& pc_offset_array = 407 Array& pc_offset_array =
386 Array::Handle(isolate, Object::empty_array().raw()); 408 Array::Handle(isolate, Object::empty_array().raw());
387 // If we have an error with a stacktrace field then collect the full stack 409 // If we have an error with a stacktrace field then collect the full stack
388 // trace and store it into the field. 410 // trace and store it into the field.
389 if (!stacktrace_field.IsNull()) { 411 if (!stacktrace_field.IsNull()) {
390 if (exception.GetField(stacktrace_field) == Object::null()) { 412 if (exception.GetField(stacktrace_field) == Object::null()) {
391 // This is an error object and we need to capture the full stack trace 413 // This is an error object and we need to capture the full stack trace
392 // here implicitly, so we set up the stack trace. The stack trace field 414 // here implicitly, so we set up the stack trace. The stack trace field
393 // is set only once, it is not overriden. 415 // is set only once, it is not overriden.
394 RegularStacktraceBuilder frame_builder(true); 416 const Stacktrace& full_stacktrace =
395 BuildStackTrace(&frame_builder); 417 Stacktrace::Handle(isolate, Exceptions::CurrentStacktrace());
396
397 // Create arrays for code and pc_offset tuples of each frame.
398 const Array& full_code_array = Array::Handle(isolate,
399 Array::MakeArray(frame_builder.code_list()));
400 const Array& full_pc_offset_array = Array::Handle(isolate,
401 Array::MakeArray(frame_builder.pc_offset_list()));
402 const Array& full_catch_code_array = Array::Handle(isolate,
403 Array::MakeArray(frame_builder.catch_code_list()));
404 const Array& full_catch_pc_offset_array = Array::Handle(isolate,
405 Array::MakeArray(frame_builder.catch_pc_offset_list()));
406 const Stacktrace& full_stacktrace = Stacktrace::Handle(isolate,
407 Stacktrace::New(full_code_array, full_pc_offset_array));
408 full_stacktrace.SetCatchStacktrace(full_catch_code_array,
409 full_catch_pc_offset_array);
410 exception.SetField(stacktrace_field, full_stacktrace); 418 exception.SetField(stacktrace_field, full_stacktrace);
411 } 419 }
412 } 420 }
413 if (handler_needs_stacktrace) { 421 if (handler_needs_stacktrace) {
414 RegularStacktraceBuilder frame_builder(false); 422 RegularStacktraceBuilder frame_builder(false);
415 BuildStackTrace(&frame_builder); 423 BuildStackTrace(&frame_builder);
416 424
417 // Create arrays for code and pc_offset tuples of each frame. 425 // Create arrays for code and pc_offset tuples of each frame.
418 code_array = Array::MakeArray(frame_builder.code_list()); 426 code_array = Array::MakeArray(frame_builder.code_list());
419 pc_offset_array = Array::MakeArray(frame_builder.pc_offset_list()); 427 pc_offset_array = Array::MakeArray(frame_builder.pc_offset_list());
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
710 break; 718 break;
711 } 719 }
712 720
713 return DartLibraryCalls::InstanceCreate(library, 721 return DartLibraryCalls::InstanceCreate(library,
714 *class_name, 722 *class_name,
715 *constructor_name, 723 *constructor_name,
716 arguments); 724 arguments);
717 } 725 }
718 726
719 } // namespace dart 727 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/exceptions.h ('k') | runtime/vm/flow_graph_builder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698