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

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

Issue 51793002: Add an API function to get a debugger stack trace from an error handle. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 1 month 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
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 "include/dart_api.h" 5 #include "include/dart_api.h"
6 #include "include/dart_mirrors_api.h" 6 #include "include/dart_mirrors_api.h"
7 #include "include/dart_native_api.h" 7 #include "include/dart_native_api.h"
8 8
9 #include "platform/assert.h" 9 #include "platform/assert.h"
10 #include "vm/bigint_operations.h" 10 #include "vm/bigint_operations.h"
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 if (obj.IsUnhandledException()) { 380 if (obj.IsUnhandledException()) {
381 const UnhandledException& error = UnhandledException::Cast(obj); 381 const UnhandledException& error = UnhandledException::Cast(obj);
382 return Api::NewHandle(isolate, error.stacktrace()); 382 return Api::NewHandle(isolate, error.stacktrace());
383 } else if (obj.IsError()) { 383 } else if (obj.IsError()) {
384 return Api::NewError("This error is not an unhandled exception error."); 384 return Api::NewError("This error is not an unhandled exception error.");
385 } else { 385 } else {
386 return Api::NewError("Can only get stacktraces from error handles."); 386 return Api::NewError("Can only get stacktraces from error handles.");
387 } 387 }
388 } 388 }
389 389
390 DART_EXPORT Dart_Handle Dart_StacktraceLength(Dart_Handle handle,
391 intptr_t* length) {
392 Isolate* isolate = Isolate::Current();
393 DARTSCOPE(isolate);
394 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle));
395 if (obj.IsStacktrace()) {
396 const Stacktrace& stacktrace = Stacktrace::Cast(obj);
397 if (length != NULL) {
398 *length = stacktrace.VisibleLength();
399 }
400 return Api::Success();
401 } else {
402 return Api::NewError(
403 "%s expects argument 'handle' to be a stacktrace handle.",
404 CURRENT_FUNC);
405 }
406 }
407
408 DART_EXPORT Dart_Handle Dart_StacktraceFrameInfo(
409 Dart_Handle handle,
410 intptr_t frame_index,
411 Dart_Handle* function_name,
412 Dart_Handle* script_url,
413 intptr_t* line_number,
414 intptr_t* col_number) {
415 Isolate* isolate = Isolate::Current();
416 DARTSCOPE(isolate);
417 Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle));
418 if (obj.IsStacktrace()) {
419 const Stacktrace& stacktrace = Stacktrace::Cast(obj);
420 String& internal_function_name = String::Handle();
421 String& internal_script_url = String::Handle();
422 intptr_t internal_line_number = 0;
423 intptr_t internal_col_num = 0;
424 bool in_bounds = stacktrace.VisibleFrameInfoAt(frame_index,
425 &internal_function_name,
426 &internal_script_url,
427 &internal_line_number,
428 &internal_col_num);
429 if (!in_bounds) {
430 return Api::NewError(
431 "%s: frame index was out of bounds (%" Pd ")",
432 CURRENT_FUNC, frame_index);
433 }
434 if (function_name != NULL) {
435 *function_name = Api::NewHandle(isolate, internal_function_name.raw());
436 }
437 if (script_url != NULL) {
438 *script_url = Api::NewHandle(isolate, internal_script_url.raw());
439 }
440 if (line_number != NULL) {
441 *line_number = internal_line_number;
442 }
443 if (col_number != NULL) {
444 *col_number = internal_col_num;
445 }
446 return Api::Success();
447 } else {
448 return Api::NewError(
449 "%s expects argument 'handle' to be a stacktrace handle.",
450 CURRENT_FUNC);
451 }
452 }
453
390 454
391 // TODO(turnidge): This clones Api::NewError. I need to use va_copy to 455 // TODO(turnidge): This clones Api::NewError. I need to use va_copy to
392 // fix this but not sure if it available on all of our builds. 456 // fix this but not sure if it available on all of our builds.
393 DART_EXPORT Dart_Handle Dart_NewApiError(const char* error) { 457 DART_EXPORT Dart_Handle Dart_NewApiError(const char* error) {
394 Isolate* isolate = Isolate::Current(); 458 Isolate* isolate = Isolate::Current();
395 DARTSCOPE(isolate); 459 DARTSCOPE(isolate);
396 CHECK_CALLBACK_STATE(isolate); 460 CHECK_CALLBACK_STATE(isolate);
397 461
398 const String& message = String::Handle(isolate, String::New(error)); 462 const String& message = String::Handle(isolate, String::New(error));
399 return Api::NewHandle(isolate, ApiError::New(message)); 463 return Api::NewHandle(isolate, ApiError::New(message));
(...skipping 4013 matching lines...) Expand 10 before | Expand all | Expand 10 after
4413 } 4477 }
4414 { 4478 {
4415 NoGCScope no_gc; 4479 NoGCScope no_gc;
4416 RawObject* raw_obj = obj.raw(); 4480 RawObject* raw_obj = obj.raw();
4417 isolate->heap()->SetPeer(raw_obj, peer); 4481 isolate->heap()->SetPeer(raw_obj, peer);
4418 } 4482 }
4419 return Api::Success(); 4483 return Api::Success();
4420 } 4484 }
4421 4485
4422 } // namespace dart 4486 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698