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

Side by Side Diff: tools/ddbg.dart

Issue 10407071: Introduce remote objects in Debugger protocol (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 7 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
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 // Simple interactive debugger shell that connects to the Dart VM's debugger 5 // Simple interactive debugger shell that connects to the Dart VM's debugger
6 // connection port. 6 // connection port.
7 7
8 #import("dart:io"); 8 #import("dart:io");
9 #import("dart:json"); 9 #import("dart:json");
10 10
11 Map<int, Completer> outstandingCommands; 11 Map<int, Completer> outstandingCommands;
12 12
13 Socket vmSock; 13 Socket vmSock;
14 OutputStream vmStream; 14 OutputStream vmStream;
15 int seqNum = 0; 15 int seqNum = 0;
16 16
17 bool verbose = false; 17 bool verbose = false;
18 18
19 // The current stack trace, while the VM is paused. It's a list
20 // of activation frames.
21 List stackTrace;
22
23 // The current activation frame, while the VM is paused.
24 Map curFrame;
25
19 26
20 void printHelp() { 27 void printHelp() {
21 print(""" 28 print("""
22 q Quit debugger shell 29 q Quit debugger shell
23 bt Show backtrace 30 bt Show backtrace
24 r Resume execution 31 r Resume execution
25 s Single step 32 s Single step
26 so Step over 33 so Step over
27 si Step into 34 si Step into
28 sbp <file> <line> Set breakpoint 35 sbp [<file>] <line> Set breakpoint
36 po <id> Print object
siva 2012/05/22 01:49:09 missing help for command 'pc' ? Also noticed 'h'
hausner 2012/05/22 18:03:57 Done.
29 ll List loaded libraries 37 ll List loaded libraries
30 ls <libname> List loaded scripts in library 38 ls <libname> List loaded scripts in library
31 """); 39 """);
32 } 40 }
33 41
34 42
35 void quitShell() { 43 void quitShell() {
36 vmStream.close(); 44 vmStream.close();
37 vmSock.close(); 45 vmSock.close();
38 stdin.close(); 46 stdin.close();
(...skipping 16 matching lines...) Expand all
55 void processCommand(String cmdLine) { 63 void processCommand(String cmdLine) {
56 seqNum++; 64 seqNum++;
57 var args = cmdLine.split(' '); 65 var args = cmdLine.split(' ');
58 if (args.length == 0) { 66 if (args.length == 0) {
59 return; 67 return;
60 } 68 }
61 var cmd = args[0]; 69 var cmd = args[0];
62 if (cmd == "r") { 70 if (cmd == "r") {
63 var cmd = { "id": seqNum, "command": "resume" }; 71 var cmd = { "id": seqNum, "command": "resume" };
64 sendCmd(cmd).then((result) => handleGenericResponse(result)); 72 sendCmd(cmd).then((result) => handleGenericResponse(result));
73 stackTrace = curFrame = null;
65 } else if (cmd == "s") { 74 } else if (cmd == "s") {
66 var cmd = { "id": seqNum, "command": "stepOver" }; 75 var cmd = { "id": seqNum, "command": "stepOver" };
67 sendCmd(cmd).then((result) => handleGenericResponse(result)); 76 sendCmd(cmd).then((result) => handleGenericResponse(result));
77 stackTrace = curFrame = null;
68 } else if (cmd == "si") { 78 } else if (cmd == "si") {
69 var cmd = { "id": seqNum, "command": "stepInto" }; 79 var cmd = { "id": seqNum, "command": "stepInto" };
70 sendCmd(cmd).then((result) => handleGenericResponse(result)); 80 sendCmd(cmd).then((result) => handleGenericResponse(result));
81 stackTrace = curFrame = null;
71 } else if (cmd == "so") { 82 } else if (cmd == "so") {
72 var cmd = { "id": seqNum, "command": "stepOut" }; 83 var cmd = { "id": seqNum, "command": "stepOut" };
73 sendCmd(cmd).then((result) => handleGenericResponse(result)); 84 sendCmd(cmd).then((result) => handleGenericResponse(result));
85 stackTrace = curFrame = null;
74 } else if (cmd == "bt") { 86 } else if (cmd == "bt") {
75 var cmd = { "id": seqNum, "command": "getStackTrace" }; 87 var cmd = { "id": seqNum, "command": "getStackTrace" };
76 sendCmd(cmd).then((result) => handleStackTraceResponse(result)); 88 sendCmd(cmd).then((result) => handleStackTraceResponse(result));
77 } else if (cmd == "ll") { 89 } else if (cmd == "ll") {
78 var cmd = { "id": seqNum, "command": "getLibraryURLs" }; 90 var cmd = { "id": seqNum, "command": "getLibraryURLs" };
79 sendCmd(cmd).then((result) => handleGetLibraryResponse(result)); 91 sendCmd(cmd).then((result) => handleGetLibraryResponse(result));
80 } else if (cmd == "sbp") { 92 } else if (cmd == "sbp" && args.length >= 2) {
81 if (args.length < 3) { 93 var url, line;
82 return; 94 if (args.length == 2) {
95 url = stackTrace[0]["location"]["url"];
96 line = Math.parseInt(args[1]);
97 } else {
98 url = args[1];
99 line = Math.parseInt(args[2]);
83 } 100 }
84 var cmd = { "id": seqNum, 101 var cmd = { "id": seqNum,
85 "command": "setBreakpoint", 102 "command": "setBreakpoint",
86 "params": { "url": args[1], "line": Math.parseInt(args[2]) }}; 103 "params": { "url": url, "line": line }};
87 sendCmd(cmd).then((result) => handleSetBpResponse(result)); 104 sendCmd(cmd).then((result) => handleSetBpResponse(result));
88 } else if (cmd == "ls") { 105 } else if (cmd == "ls" && args.length == 2) {
89 if (args.length < 2) {
90 return;
91 }
92 var cmd = { "id": seqNum, 106 var cmd = { "id": seqNum,
93 "command": "getScriptURLs", 107 "command": "getScriptURLs",
94 "params": { "library": args[1] }}; 108 "params": { "library": args[1] }};
95 sendCmd(cmd).then((result) => handleGetScriptsResponse(result)); 109 sendCmd(cmd).then((result) => handleGetScriptsResponse(result));
110 } else if (cmd == "po" && args.length == 2) {
111 var cmd = { "id": seqNum, "command": "getObjectProperties",
112 "params": {"objectId": Math.parseInt(args[1]) }};
113 sendCmd(cmd).then((result) => handleGetObjPropsResponse(result));
114 } else if (cmd == "pc" && args.length == 2) {
115 var cmd = { "id": seqNum, "command": "getClassProperties",
116 "params": {"classId": Math.parseInt(args[1]) }};
117 sendCmd(cmd).then((result) => handleGetClassPropsResponse(result));
96 } else if (cmd == "q") { 118 } else if (cmd == "q") {
97 quitShell(); 119 quitShell();
98 } else if (cmd == "h") { 120 } else if (cmd == "h") {
99 printHelp(); 121 printHelp();
100 } else { 122 } else {
101 print("command '$cmd' not understood, try h for help"); 123 print("command '$cmd' not understood, try h for help");
102 } 124 }
103 } 125 }
104 126
105 127
128 printNamedObject(obj) {
129 var name = obj["name"];
130 var value = obj["value"];
131 var kind = value["kind"];
132 var text = value["text"];
133 var id = value["objectId"];
134 if (kind == "string") {
135 print(" $name = '$text'");
136 } else if (kind == "object") {
137 print(" $name (id:$id) = $text");
138 } else {
139 print(" $name = $text");
140 }
141 }
142
143
144 handleGetObjPropsResponse(response) {
145 var props = response["result"];
146 assert(props != null);
147 var class_id = props["classId"];
148 assert(class_id != null);
149 var fields = props["fields"];
150 assert(fields != null);
siva 2012/05/22 01:49:09 Just curious, what is the point of this assert, wo
hausner 2012/05/22 18:03:57 I guess so. Old C++ habits...
151 assert(fields is List);
siva 2012/05/22 01:49:09 Also what is the style here? instead of adding our
hausner 2012/05/22 18:03:57 This is my early code in which I was experimenting
152 print(" class id: $class_id");
153 for (int i = 0; i < fields.length; i++) {
154 printNamedObject(fields[i]);
155 }
156 }
157
158
159 handleGetClassPropsResponse(response) {
160 var props = response["result"];
161 assert(props != null);
162 assert(props["name"] != null);
163 var libId = props["libraryId"];
164 assert(libId != null);
165 print(" class ${props["name"]} (library id: $libId)");
166 var fields = props["fields"];
167 assert(fields != null);
168 assert(fields is List);
169 if (fields.length > 0) {
170 print(" static fields:");
171 for (int i = 0; i < fields.length; i++) {
172 printNamedObject(fields[i]);
173 }
174 }
175 }
176
177
106 void handleGetLibraryResponse(response) { 178 void handleGetLibraryResponse(response) {
107 var result = response["result"]; 179 var result = response["result"];
108 assert(result != null); 180 assert(result != null);
109 var urls = result["urls"]; 181 var urls = result["urls"];
110 assert(urls != null); 182 assert(urls != null);
111 assert(urls is List); 183 assert(urls is List);
112 print("Loaded libraries:"); 184 print("Loaded libraries:");
113 for (int i = 0; i < urls.length; i++) { 185 for (int i = 0; i < urls.length; i++) {
114 print(" $i ${urls[i]}"); 186 print(" $i ${urls[i]}");
115 } 187 }
(...skipping 27 matching lines...) Expand all
143 print("Error: ${response["error"]}"); 215 print("Error: ${response["error"]}");
144 } 216 }
145 } 217 }
146 218
147 219
148 void handleStackTraceResponse(response) { 220 void handleStackTraceResponse(response) {
149 var result = response["result"]; 221 var result = response["result"];
150 assert(result != null); 222 assert(result != null);
151 var callFrames = result["callFrames"]; 223 var callFrames = result["callFrames"];
152 assert(callFrames != null); 224 assert(callFrames != null);
153 printStackTrace(result); 225 printStackTrace(callFrames);
154 } 226 }
155 227
156 228
157 void printStackTrace(trace) { 229 void printStackFrame(frame_num, frame) {
158 assert(trace != null); 230 var fname = frame["functionName"];
159 var frames = trace["callFrames"]; 231 var url = frame["location"]["url"];
160 if (frames is !List) { 232 var line = frame["location"]["lineNumber"];
161 print("unexpected type for frames parameter $frames"); 233 print("$frame_num $fname ($url:$line)");
162 return; 234 var locals = frame["locals"];
235 assert(locals is List);
siva 2012/05/22 01:49:09 Ditto question about explicit type check assert.
hausner 2012/05/22 18:03:57 Done.
236 for (int i = 0; i < locals.length; i++) {
237 printNamedObject(locals[i]);
163 } 238 }
239 }
240
241
242 void printStackTrace(List frames) {
164 for (int i = 0; i < frames.length; i++) { 243 for (int i = 0; i < frames.length; i++) {
165 var frame = frames[i]; 244 printStackFrame(i, frames[i]);
166 var fname = frame["functionName"];
167 var url = frame["location"]["url"];
168 var line = frame["location"]["lineNumber"];
169 print("$i $fname ($url:$line)");
170 } 245 }
171 } 246 }
172 247
173 248
249 void handlePausedEvent(msg) {
250 assert(msg["params"] != null);
251 stackTrace = msg["params"]["callFrames"];
252 assert(stackTrace != null);
253 assert(stackTrace.length >= 1);
254 curFrame = stackTrace[0];
255 print("VM paused, stack trace:");
256 printStackTrace(stackTrace);
257 }
258
259
174 void processVmMessage(String json) { 260 void processVmMessage(String json) {
175 var msg = JSON.parse(json); 261 var msg = JSON.parse(json);
176 if (msg == null) { 262 if (msg == null) {
177 return; 263 return;
178 } 264 }
179 var event = msg["event"]; 265 var event = msg["event"];
180 if (event == "paused") { 266 if (event == "paused") {
181 print("VM paused, stack trace:"); 267 handlePausedEvent(msg);
182 printStackTrace(msg["params"]);
183 return; 268 return;
184 } 269 }
185 if (event == "breakpointResolved") { 270 if (event == "breakpointResolved") {
186 var params = msg["params"]; 271 var params = msg["params"];
187 assert(params != null); 272 assert(params != null);
188 print("BP ${params["breakpointId"]} resolved and " 273 print("BP ${params["breakpointId"]} resolved and "
189 "set at line ${params["line"]}."); 274 "set at line ${params["line"]}.");
190 return; 275 return;
191 } 276 }
192 if (msg["id"] != null) { 277 if (msg["id"] != null) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 }; 332 };
248 vmInStream.onError = (err) { 333 vmInStream.onError = (err) {
249 print("Error in debug connection: $err"); 334 print("Error in debug connection: $err");
250 quitShell(); 335 quitShell();
251 }; 336 };
252 vmInStream.onClosed = () { 337 vmInStream.onClosed = () {
253 print("VM debugger connection closed"); 338 print("VM debugger connection closed");
254 quitShell(); 339 quitShell();
255 }; 340 };
256 } 341 }
OLDNEW
« runtime/vm/debugger_api_impl.cc ('K') | « runtime/vm/debugger_api_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698