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

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

Issue 11946020: Check whether exceptions are caught (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 11 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/debugger.h ('k') | runtime/vm/object.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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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/debugger.h" 5 #include "vm/debugger.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 8
9 #include "vm/code_generator.h" 9 #include "vm/code_generator.h"
10 #include "vm/code_patcher.h" 10 #include "vm/code_patcher.h"
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 294
295 intptr_t ActivationFrame::PcDescIndex() { 295 intptr_t ActivationFrame::PcDescIndex() {
296 if (pc_desc_index_ < 0) { 296 if (pc_desc_index_ < 0) {
297 TokenPos(); 297 TokenPos();
298 ASSERT(pc_desc_index_ >= 0); 298 ASSERT(pc_desc_index_ >= 0);
299 } 299 }
300 return pc_desc_index_; 300 return pc_desc_index_;
301 } 301 }
302 302
303 303
304 intptr_t ActivationFrame::TryIndex() {
305 intptr_t desc_index = PcDescIndex();
306 return pc_desc_.TryIndex(desc_index);
307 }
308
309
304 intptr_t ActivationFrame::LineNumber() { 310 intptr_t ActivationFrame::LineNumber() {
305 // Compute line number lazily since it causes scanning of the script. 311 // Compute line number lazily since it causes scanning of the script.
306 if (line_number_ < 0) { 312 if (line_number_ < 0) {
307 const Script& script = Script::Handle(SourceScript()); 313 const Script& script = Script::Handle(SourceScript());
308 intptr_t ignore_column; 314 intptr_t ignore_column;
309 script.GetTokenLocation(TokenPos(), &line_number_, &ignore_column); 315 script.GetTokenLocation(TokenPos(), &line_number_, &ignore_column);
310 } 316 }
311 return line_number_; 317 return line_number_;
312 } 318 }
313 319
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 var_descriptors_.GetInfo(i, &var_info); 371 var_descriptors_.GetInfo(i, &var_info);
366 if (var_info.kind == RawLocalVarDescriptors::kContextChain) { 372 if (var_info.kind == RawLocalVarDescriptors::kContextChain) {
367 return reinterpret_cast<RawContext*>(GetLocalVarValue(var_info.index)); 373 return reinterpret_cast<RawContext*>(GetLocalVarValue(var_info.index));
368 } 374 }
369 } 375 }
370 // Caller uses same context chain. 376 // Caller uses same context chain.
371 return ctx_.raw(); 377 return ctx_.raw();
372 } 378 }
373 379
374 380
381 // TODO(hausner): Eliminate this helper function by sorting the
382 // ExceptionHandlers entries by try_index and eliminating
383 // the try_index field altogether.
384 static intptr_t FindTryIndex(const ExceptionHandlers& handlers,
385 intptr_t try_index) {
386 intptr_t len = handlers.Length();
387 for (int i = 0; i < len; i++) {
388 if (handlers.TryIndex(i) == try_index) return i;
389 }
390 UNREACHABLE();
391 return -1;
392 }
393
394
395 ActivationFrame* DebuggerStackTrace::GetHandlerFrame(
396 const Instance& exc_obj) const {
397 ExceptionHandlers& handlers = ExceptionHandlers::Handle();
398 Array& handled_types = Array::Handle();
399 AbstractType& type = Type::Handle();
400 const TypeArguments& no_instantiator = TypeArguments::Handle();
401 for (int frame_index = 0; frame_index < Length(); frame_index++) {
402 ActivationFrame* frame = trace_[frame_index];
403 intptr_t try_index = frame->TryIndex();
404 if (try_index < 0) continue;
405 const Code& code = frame->DartCode();
406 handlers = code.exception_handlers();
407 ASSERT(!handlers.IsNull());
408 intptr_t num_handlers_checked = 0;
409 while (try_index >= 0) {
410 intptr_t i = FindTryIndex(handlers, try_index);
411 // Detect circles in the exception handler data.
412 num_handlers_checked++;
413 ASSERT(num_handlers_checked <= handlers.Length());
414 handled_types = handlers.GetHandledTypes(i);
415 const intptr_t num_types = handled_types.Length();
416 for (int k = 0; k < num_types; k++) {
417 type ^= handled_types.At(k);
418 ASSERT(!type.IsNull());
419 // Uninstantiated types are not added to ExceptionHandlers data.
420 ASSERT(type.IsInstantiated());
421 if (type.IsDynamicType()) return frame;
422 if (type.IsMalformed()) continue;
423 if (exc_obj.IsInstanceOf(type, no_instantiator, NULL)) {
424 return frame;
425 }
426 }
427 try_index = handlers.OuterTryIndex(i);
428 }
429 }
430 return NULL;
431 }
432
433
375 void ActivationFrame::GetDescIndices() { 434 void ActivationFrame::GetDescIndices() {
376 if (vars_initialized_) { 435 if (vars_initialized_) {
377 return; 436 return;
378 } 437 }
379 GetVarDescriptors(); 438 GetVarDescriptors();
380 439
381 // We don't trust variable descriptors in optimized code. 440 // We don't trust variable descriptors in optimized code.
382 // Rather than potentially displaying incorrect values, we 441 // Rather than potentially displaying incorrect values, we
383 // pretend that there are no variables in the frame. 442 // pretend that there are no variables in the frame.
384 // We should be more clever about this in the future. 443 // We should be more clever about this in the future.
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after
859 (pause_info == kPauseOnAllExceptions)); 918 (pause_info == kPauseOnAllExceptions));
860 exc_pause_info_ = pause_info; 919 exc_pause_info_ = pause_info;
861 } 920 }
862 921
863 922
864 Dart_ExceptionPauseInfo Debugger::GetExceptionPauseInfo() { 923 Dart_ExceptionPauseInfo Debugger::GetExceptionPauseInfo() {
865 return (Dart_ExceptionPauseInfo)exc_pause_info_; 924 return (Dart_ExceptionPauseInfo)exc_pause_info_;
866 } 925 }
867 926
868 927
869 // TODO(hausner): Determine whether the exception is handled or not.
870 bool Debugger::ShouldPauseOnException(DebuggerStackTrace* stack_trace, 928 bool Debugger::ShouldPauseOnException(DebuggerStackTrace* stack_trace,
871 const Object& exc) { 929 const Instance& exc) {
872 if (exc_pause_info_ == kNoPauseOnExceptions) { 930 if (exc_pause_info_ == kNoPauseOnExceptions) {
873 return false; 931 return false;
874 } 932 }
875 if ((exc_pause_info_ & kPauseOnAllExceptions) != 0) { 933 if (exc_pause_info_ == kPauseOnAllExceptions) {
876 return true; 934 return true;
877 } 935 }
878 // Assume TypeError and AssertionError exceptions are unhandled. 936 ASSERT(exc_pause_info_ == kPauseOnUnhandledExceptions);
879 const Class& exc_class = Class::Handle(exc.clazz()); 937 ActivationFrame* handler_frame = stack_trace->GetHandlerFrame(exc);
880 const String& class_name = String::Handle(exc_class.Name()); 938 if (handler_frame == NULL) {
881 // TODO(hausner): Note the poor man's type test. This code will go 939 // Did not find an exception handler that catches this exception.
882 // away when we have a way to determine whether an exception is unhandled. 940 // Note that this check is not precise, since we can't check
883 if (class_name.Equals("TypeErrorImplementation")) { 941 // uninstantiated types, i.e. types containing type parameters.
884 return true; 942 // Thus, we may report an exception as unhandled when in fact
885 } 943 // it will be caught once we unwind the stack.
886 if (class_name.Equals("AssertionErrorImplementation")) {
887 return true; 944 return true;
888 } 945 }
889 return false; 946 return false;
890 } 947 }
891 948
892 949
893 void Debugger::SignalExceptionThrown(const Object& exc) { 950 void Debugger::SignalExceptionThrown(const Instance& exc) {
894 // We ignore this exception event when the VM is executing code invoked 951 // We ignore this exception event when the VM is executing code invoked
895 // by the debugger to evaluate variables values, when we see a nested 952 // by the debugger to evaluate variables values, when we see a nested
896 // breakpoint or exception event, or if the debugger is not 953 // breakpoint or exception event, or if the debugger is not
897 // interested in exception events. 954 // interested in exception events.
898 if (ignore_breakpoints_ || 955 if (ignore_breakpoints_ ||
899 (stack_trace_ != NULL) || 956 (stack_trace_ != NULL) ||
900 (event_handler_ == NULL) || 957 (event_handler_ == NULL) ||
901 (exc_pause_info_ == kNoPauseOnExceptions)) { 958 (exc_pause_info_ == kNoPauseOnExceptions)) {
902 return; 959 return;
903 } 960 }
(...skipping 776 matching lines...) Expand 10 before | Expand all | Expand 10 after
1680 } 1737 }
1681 1738
1682 1739
1683 void Debugger::RegisterCodeBreakpoint(CodeBreakpoint* bpt) { 1740 void Debugger::RegisterCodeBreakpoint(CodeBreakpoint* bpt) {
1684 ASSERT(bpt->next() == NULL); 1741 ASSERT(bpt->next() == NULL);
1685 bpt->set_next(code_breakpoints_); 1742 bpt->set_next(code_breakpoints_);
1686 code_breakpoints_ = bpt; 1743 code_breakpoints_ = bpt;
1687 } 1744 }
1688 1745
1689 } // namespace dart 1746 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/debugger.h ('k') | runtime/vm/object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698