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

Side by Side Diff: runtime/bin/dbg_message.cc

Issue 13144018: Add text location in debugger event (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 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 | « no previous file | runtime/include/dart_debugger_api.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 "bin/dbg_connection.h" 5 #include "bin/dbg_connection.h"
6 #include "bin/dbg_message.h" 6 #include "bin/dbg_message.h"
7 #include "bin/dartutils.h" 7 #include "bin/dartutils.h"
8 #include "bin/thread.h" 8 #include "bin/thread.h"
9 #include "bin/utils.h" 9 #include "bin/utils.h"
10 10
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 if (i > index) { 382 if (i > index) {
383 buf->Printf(","); 383 buf->Printf(",");
384 } 384 }
385 FormatValueObj(buf, value); 385 FormatValueObj(buf, value);
386 } 386 }
387 buf->Printf("]}"); 387 buf->Printf("]}");
388 return NULL; 388 return NULL;
389 } 389 }
390 390
391 391
392 static void FormatLocationFromTrace(dart::TextBuffer* msg,
393 Dart_StackTrace trace) {
394 intptr_t trace_len = 0;
395 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len);
396 ASSERT_NOT_ERROR(res);
397 Dart_ActivationFrame frame;
398 res = Dart_GetActivationFrame(trace, 0, &frame);
399 ASSERT_NOT_ERROR(res);
400 Dart_Handle script_url;
401 intptr_t token_number = 0;
402 intptr_t line_number = 0;
403 res = Dart_ActivationFrameInfo(frame, NULL, NULL, &line_number, NULL);
404 ASSERT_NOT_ERROR(res);
405 res = Dart_ActivationFrameGetLocation(frame, &script_url, &token_number);
406 ASSERT_NOT_ERROR(res);
407 if (!Dart_IsNull(script_url)) {
408 ASSERT(Dart_IsString(script_url));
409 msg->Printf("\"location\": { \"url\":");
410 FormatEncodedString(msg, script_url);
411 msg->Printf(",\"tokenOffset\":%"Pd",", token_number);
412 msg->Printf("\"lineNumber\":%"Pd"},", line_number);
413 }
414 }
415
416
392 static void FormatCallFrames(dart::TextBuffer* msg, Dart_StackTrace trace) { 417 static void FormatCallFrames(dart::TextBuffer* msg, Dart_StackTrace trace) {
393 intptr_t trace_len = 0; 418 intptr_t trace_len = 0;
394 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len); 419 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len);
395 ASSERT_NOT_ERROR(res); 420 ASSERT_NOT_ERROR(res);
396 msg->Printf("\"callFrames\" : [ "); 421 msg->Printf("\"callFrames\" : [ ");
397 for (int i = 0; i < trace_len; i++) { 422 for (int i = 0; i < trace_len; i++) {
398 Dart_ActivationFrame frame; 423 Dart_ActivationFrame frame;
399 res = Dart_GetActivationFrame(trace, i, &frame); 424 res = Dart_GetActivationFrame(trace, i, &frame);
400 ASSERT_NOT_ERROR(res); 425 ASSERT_NOT_ERROR(res);
401 Dart_Handle func_name; 426 Dart_Handle func_name;
402 Dart_Handle script_url; 427 Dart_Handle script_url;
403 intptr_t line_number = 0; 428 intptr_t line_number = 0;
429 intptr_t token_number = 0;
404 intptr_t library_id = 0; 430 intptr_t library_id = 0;
405 res = Dart_ActivationFrameInfo( 431 res = Dart_ActivationFrameInfo(
406 frame, &func_name, &script_url, &line_number, &library_id); 432 frame, &func_name, NULL, &line_number, &library_id);
407 ASSERT_NOT_ERROR(res); 433 ASSERT_NOT_ERROR(res);
434
408 ASSERT(Dart_IsString(func_name)); 435 ASSERT(Dart_IsString(func_name));
409 msg->Printf("%s{\"functionName\":", (i > 0) ? "," : ""); 436 msg->Printf("%s{\"functionName\":", (i > 0) ? "," : "");
410 FormatEncodedString(msg, func_name); 437 FormatEncodedString(msg, func_name);
411 msg->Printf(",\"libraryId\": %"Pd",", library_id); 438 msg->Printf(",\"libraryId\": %"Pd",", library_id);
412 439
413 ASSERT(Dart_IsString(script_url)); 440 res = Dart_ActivationFrameGetLocation(frame, &script_url, &token_number);
414 msg->Printf("\"location\": { \"url\":"); 441 ASSERT_NOT_ERROR(res);
415 FormatEncodedString(msg, script_url); 442 if (!Dart_IsNull(script_url)) {
416 msg->Printf(",\"lineNumber\":%"Pd"},", line_number); 443 ASSERT(Dart_IsString(script_url));
444 msg->Printf("\"location\": { \"url\":");
445 FormatEncodedString(msg, script_url);
446 msg->Printf(",\"tokenOffset\":%"Pd",", token_number);
447 msg->Printf("\"lineNumber\":%"Pd"},", line_number);
448 }
417 449
418 Dart_Handle locals = Dart_GetLocalVariables(frame); 450 Dart_Handle locals = Dart_GetLocalVariables(frame);
419 ASSERT_NOT_ERROR(locals); 451 ASSERT_NOT_ERROR(locals);
420 msg->Printf("\"locals\":"); 452 msg->Printf("\"locals\":");
421 FormatNamedValueList(msg, locals); 453 FormatNamedValueList(msg, locals);
422 msg->Printf("}"); 454 msg->Printf("}");
423 } 455 }
424 msg->Printf("]"); 456 msg->Printf("]");
425 } 457 }
426 458
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
905 937
906 938
907 void DbgMsgQueue::SendQueuedMsgs() { 939 void DbgMsgQueue::SendQueuedMsgs() {
908 if (queued_output_messages_.length() > 0) { 940 if (queued_output_messages_.length() > 0) {
909 DebuggerConnectionHandler::BroadcastMsg(&queued_output_messages_); 941 DebuggerConnectionHandler::BroadcastMsg(&queued_output_messages_);
910 queued_output_messages_.Clear(); 942 queued_output_messages_.Clear();
911 } 943 }
912 } 944 }
913 945
914 946
947 // TODO(hausner): Remove stack trace parameter once we remove the stack
948 // trace from the paused event in the wire protocol.
915 void DbgMsgQueue::SendBreakpointEvent(Dart_StackTrace trace) { 949 void DbgMsgQueue::SendBreakpointEvent(Dart_StackTrace trace) {
916 dart::TextBuffer msg(128); 950 dart::TextBuffer msg(128);
917 msg.Printf("{ \"event\": \"paused\", \"params\": { "); 951 msg.Printf("{ \"event\": \"paused\", \"params\": { ");
918 msg.Printf("\"reason\": \"breakpoint\", "); 952 msg.Printf("\"reason\": \"breakpoint\", ");
919 msg.Printf("\"id\": %"Pd64", ", isolate_id_); 953 msg.Printf("\"id\": %"Pd64", ", isolate_id_);
954 FormatLocationFromTrace(&msg, trace);
920 FormatCallFrames(&msg, trace); 955 FormatCallFrames(&msg, trace);
921 msg.Printf("}}"); 956 msg.Printf("}}");
922 DebuggerConnectionHandler::BroadcastMsg(&msg); 957 DebuggerConnectionHandler::BroadcastMsg(&msg);
923 } 958 }
924 959
925 960
961 // TODO(hausner): Remove stack trace parameter once we remove the stack
962 // trace from the paused event in the wire protocol.
926 void DbgMsgQueue::SendExceptionEvent(Dart_Handle exception, 963 void DbgMsgQueue::SendExceptionEvent(Dart_Handle exception,
927 Dart_StackTrace stack_trace) { 964 Dart_StackTrace stack_trace) {
928 intptr_t exception_id = Dart_CacheObject(exception); 965 intptr_t exception_id = Dart_CacheObject(exception);
929 ASSERT(exception_id >= 0); 966 ASSERT(exception_id >= 0);
930 dart::TextBuffer msg(128); 967 dart::TextBuffer msg(128);
931 msg.Printf("{ \"event\": \"paused\", \"params\": {"); 968 msg.Printf("{ \"event\": \"paused\", \"params\": {");
932 msg.Printf("\"reason\": \"exception\", "); 969 msg.Printf("\"reason\": \"exception\", ");
933 msg.Printf("\"id\": %"Pd64", ", isolate_id_); 970 msg.Printf("\"id\": %"Pd64", ", isolate_id_);
934 msg.Printf("\"exception\":"); 971 msg.Printf("\"exception\":");
935 FormatRemoteObj(&msg, exception); 972 FormatRemoteObj(&msg, exception);
936 msg.Printf(", "); 973 msg.Printf(", ");
974 FormatLocationFromTrace(&msg, stack_trace);
937 FormatCallFrames(&msg, stack_trace); 975 FormatCallFrames(&msg, stack_trace);
938 msg.Printf("}}"); 976 msg.Printf("}}");
939 DebuggerConnectionHandler::BroadcastMsg(&msg); 977 DebuggerConnectionHandler::BroadcastMsg(&msg);
940 } 978 }
941 979
942 980
981 // TODO(hausner): Remove stack trace parameter once we remove the stack
982 // trace from the interrupted event in the wire protocol.
943 void DbgMsgQueue::SendIsolateEvent(Dart_IsolateId isolate_id, 983 void DbgMsgQueue::SendIsolateEvent(Dart_IsolateId isolate_id,
944 Dart_IsolateEvent kind) { 984 Dart_IsolateEvent kind) {
945 dart::TextBuffer msg(128); 985 dart::TextBuffer msg(128);
946 if (kind == kInterrupted) { 986 if (kind == kInterrupted) {
947 Dart_StackTrace trace; 987 Dart_StackTrace trace;
948 Dart_Handle res = Dart_GetStackTrace(&trace); 988 Dart_Handle res = Dart_GetStackTrace(&trace);
949 ASSERT_NOT_ERROR(res); 989 ASSERT_NOT_ERROR(res);
950 msg.Printf("{ \"event\": \"paused\", \"params\": { "); 990 msg.Printf("{ \"event\": \"paused\", \"params\": { ");
951 msg.Printf("\"reason\": \"interrupted\", "); 991 msg.Printf("\"reason\": \"interrupted\", ");
952 msg.Printf("\"id\": %"Pd64", ", isolate_id); 992 msg.Printf("\"id\": %"Pd64", ", isolate_id);
993 FormatLocationFromTrace(&msg, trace);
953 FormatCallFrames(&msg, trace); 994 FormatCallFrames(&msg, trace);
954 msg.Printf("}}"); 995 msg.Printf("}}");
955 } else { 996 } else {
956 msg.Printf("{ \"event\": \"isolate\", \"params\": { "); 997 msg.Printf("{ \"event\": \"isolate\", \"params\": { ");
957 if (kind == kCreated) { 998 if (kind == kCreated) {
958 msg.Printf("\"reason\": \"created\", "); 999 msg.Printf("\"reason\": \"created\", ");
959 } else { 1000 } else {
960 ASSERT(kind == kShutdown); 1001 ASSERT(kind == kShutdown);
961 msg.Printf("\"reason\": \"shutdown\", "); 1002 msg.Printf("\"reason\": \"shutdown\", ");
962 } 1003 }
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
1138 msg_queue->SendIsolateEvent(isolate_id, kind); 1179 msg_queue->SendIsolateEvent(isolate_id, kind);
1139 if (kind == kInterrupted) { 1180 if (kind == kInterrupted) {
1140 msg_queue->HandleMessages(); 1181 msg_queue->HandleMessages();
1141 } else { 1182 } else {
1142 ASSERT(kind == kShutdown); 1183 ASSERT(kind == kShutdown);
1143 RemoveIsolateMsgQueue(isolate_id); 1184 RemoveIsolateMsgQueue(isolate_id);
1144 } 1185 }
1145 } 1186 }
1146 Dart_ExitScope(); 1187 Dart_ExitScope();
1147 } 1188 }
OLDNEW
« no previous file with comments | « no previous file | runtime/include/dart_debugger_api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698