Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 29 print(""" | 29 print(""" |
| 30 q Quit debugger shell | 30 q Quit debugger shell |
| 31 bt Show backtrace | 31 bt Show backtrace |
| 32 r Resume execution | 32 r Resume execution |
| 33 s Single step | 33 s Single step |
| 34 so Step over | 34 so Step over |
| 35 si Step into | 35 si Step into |
| 36 sbp [<file>] <line> Set breakpoint | 36 sbp [<file>] <line> Set breakpoint |
| 37 rbp <id> Remove breakpoint with given id | 37 rbp <id> Remove breakpoint with given id |
| 38 po <id> Print object info for given id | 38 po <id> Print object info for given id |
| 39 pl <id> <idx> [<len>] Print list element/slice | |
| 39 pc <id> Print class info for given id | 40 pc <id> Print class info for given id |
| 40 ll List loaded libraries | 41 ll List loaded libraries |
| 41 pl <id> Print library info for given library id | 42 plib <id> Print library info for given library id |
| 42 pg <id> Print all global variables visible within given library id | 43 pg <id> Print all global variables visible within given library id |
| 43 ls <libname> List loaded scripts in library | 44 ls <libname> List loaded scripts in library |
| 44 gs <lib_id> <script_url> Get source text of script in library | 45 gs <lib_id> <script_url> Get source text of script in library |
| 45 epi <none|all|unhandled> Set exception pause info | 46 epi <none|all|unhandled> Set exception pause info |
| 46 h Print help | 47 h Print help |
| 47 """); | 48 """); |
| 48 } | 49 } |
| 49 | 50 |
| 50 | 51 |
| 51 void quitShell() { | 52 void quitShell() { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 106 sendCmd(cmd).then((result) => handleGenericResponse(result)); | 107 sendCmd(cmd).then((result) => handleGenericResponse(result)); |
| 107 } else if (command == "ls" && args.length == 2) { | 108 } else if (command == "ls" && args.length == 2) { |
| 108 var cmd = { "id": seqNum, | 109 var cmd = { "id": seqNum, |
| 109 "command": "getScriptURLs", | 110 "command": "getScriptURLs", |
| 110 "params": { "libraryId": Math.parseInt(args[1]) }}; | 111 "params": { "libraryId": Math.parseInt(args[1]) }}; |
| 111 sendCmd(cmd).then((result) => handleGetScriptsResponse(result)); | 112 sendCmd(cmd).then((result) => handleGetScriptsResponse(result)); |
| 112 } else if (command == "po" && args.length == 2) { | 113 } else if (command == "po" && args.length == 2) { |
| 113 var cmd = { "id": seqNum, "command": "getObjectProperties", | 114 var cmd = { "id": seqNum, "command": "getObjectProperties", |
| 114 "params": {"objectId": Math.parseInt(args[1]) }}; | 115 "params": {"objectId": Math.parseInt(args[1]) }}; |
| 115 sendCmd(cmd).then((result) => handleGetObjPropsResponse(result)); | 116 sendCmd(cmd).then((result) => handleGetObjPropsResponse(result)); |
| 117 } else if (command == "pl" && args.length >= 3) { | |
| 118 var cmd; | |
| 119 if (args.length == 3) { | |
| 120 cmd = { "id": seqNum, "command": "getListElements", | |
| 121 "params": {"objectId": Math.parseInt(args[1]), | |
| 122 "index": Math.parseInt(args[2]) }}; | |
| 123 } else { | |
| 124 cmd = { "id": seqNum, "command": "getListElements", | |
| 125 "params": {"objectId": Math.parseInt(args[1]), | |
| 126 "index": Math.parseInt(args[2]), | |
| 127 "length": Math.parseInt(args[3]) }}; | |
| 128 } | |
| 129 sendCmd(cmd).then((result) => handleGetListResponse(result)); | |
| 116 } else if (command == "pc" && args.length == 2) { | 130 } else if (command == "pc" && args.length == 2) { |
| 117 var cmd = { "id": seqNum, "command": "getClassProperties", | 131 var cmd = { "id": seqNum, "command": "getClassProperties", |
| 118 "params": {"classId": Math.parseInt(args[1]) }}; | 132 "params": {"classId": Math.parseInt(args[1]) }}; |
| 119 sendCmd(cmd).then((result) => handleGetClassPropsResponse(result)); | 133 sendCmd(cmd).then((result) => handleGetClassPropsResponse(result)); |
| 120 } else if (command == "pl" && args.length == 2) { | 134 } else if (command == "plib" && args.length == 2) { |
| 121 var cmd = { "id": seqNum, "command": "getLibraryProperties", | 135 var cmd = { "id": seqNum, "command": "getLibraryProperties", |
| 122 "params": {"libraryId": Math.parseInt(args[1]) }}; | 136 "params": {"libraryId": Math.parseInt(args[1]) }}; |
| 123 sendCmd(cmd).then((result) => handleGetLibraryPropsResponse(result)); | 137 sendCmd(cmd).then((result) => handleGetLibraryPropsResponse(result)); |
| 124 } else if (command == "pg" && args.length == 2) { | 138 } else if (command == "pg" && args.length == 2) { |
| 125 var cmd = { "id": seqNum, "command": "getGlobalVariables", | 139 var cmd = { "id": seqNum, "command": "getGlobalVariables", |
| 126 "params": {"libraryId": Math.parseInt(args[1]) }}; | 140 "params": {"libraryId": Math.parseInt(args[1]) }}; |
| 127 sendCmd(cmd).then((result) => handleGetGlobalVarsResponse(result)); | 141 sendCmd(cmd).then((result) => handleGetGlobalVarsResponse(result)); |
| 128 } else if (command == "gs" && args.length == 3) { | 142 } else if (command == "gs" && args.length == 3) { |
| 129 var cmd = { "id": seqNum, "command": "getScriptSource", | 143 var cmd = { "id": seqNum, "command": "getScriptSource", |
| 130 "params": { "libraryId": Math.parseInt(args[1]), | 144 "params": { "libraryId": Math.parseInt(args[1]), |
| 131 "url": args[2] }}; | 145 "url": args[2] }}; |
| 132 sendCmd(cmd).then((result) => handleGetSourceResponse(result)); | 146 sendCmd(cmd).then((result) => handleGetSourceResponse(result)); |
| 133 } else if (command == "epi" && args.length == 2) { | 147 } else if (command == "epi" && args.length == 2) { |
| 134 var cmd = { "id": seqNum, "command": "setPauseOnException", | 148 var cmd = { "id": seqNum, "command": "setPauseOnException", |
| 135 "params": { "exceptions": args[1] }}; | 149 "params": { "exceptions": args[1] }}; |
| 136 sendCmd(cmd).then((result) => handleGenericResponse(result)); | 150 sendCmd(cmd).then((result) => handleGenericResponse(result)); |
| 137 } else if (command == "q") { | 151 } else if (command == "q") { |
| 138 quitShell(); | 152 quitShell(); |
| 139 } else if (command == "h") { | 153 } else if (command == "h") { |
| 140 printHelp(); | 154 printHelp(); |
| 141 } else { | 155 } else { |
| 142 print("command '$command' not understood, try h for help"); | 156 print("command '$command' not understood, try h for help"); |
| 143 } | 157 } |
| 144 } | 158 } |
| 145 | 159 |
| 146 | 160 |
| 147 String remoteValue(value) { | 161 String remoteObject(value) { |
| 148 var kind = value["kind"]; | 162 var kind = value["kind"]; |
| 149 var text = value["text"]; | 163 var text = value["text"]; |
| 150 var id = value["objectId"]; | 164 var id = value["objectId"]; |
| 151 if (kind == "string") { | 165 if (kind == "string") { |
| 152 return "'$text'"; | 166 return "(string, id $id) '$text'"; |
| 167 } else if (kind == "list") { | |
| 168 var len = value["length"]; | |
| 169 return "(list, id $id, len $len) $text"; | |
| 153 } else if (kind == "object") { | 170 } else if (kind == "object") { |
| 154 return "(obj id: $id) = $text"; | 171 return "(obj, id $id) $text"; |
| 155 } else { | 172 } else { |
| 156 return "$text"; | 173 return "$text"; |
| 157 } | 174 } |
| 158 } | 175 } |
| 159 | 176 |
| 160 | 177 |
| 161 printNamedObject(obj) { | 178 printNamedObject(obj) { |
| 162 var name = obj["name"]; | 179 var name = obj["name"]; |
| 163 var value = obj["value"]; | 180 var value = obj["value"]; |
| 164 print(" $name = ${remoteValue(value)}"); | 181 print(" $name = ${remoteObject(value)}"); |
| 165 } | 182 } |
| 166 | 183 |
| 167 | 184 |
| 168 handleGetObjPropsResponse(response) { | 185 handleGetObjPropsResponse(response) { |
| 169 Map props = response["result"]; | 186 Map props = response["result"]; |
| 170 int class_id = props["classId"]; | 187 int class_id = props["classId"]; |
| 171 if (class_id == -1) { | 188 if (class_id == -1) { |
| 172 print(" null"); | 189 print(" null"); |
| 173 return; | 190 return; |
| 174 } | 191 } |
| 175 List fields = props["fields"]; | 192 List fields = props["fields"]; |
| 176 print(" class id: $class_id"); | 193 print(" class id: $class_id"); |
| 177 for (int i = 0; i < fields.length; i++) { | 194 for (int i = 0; i < fields.length; i++) { |
| 178 printNamedObject(fields[i]); | 195 printNamedObject(fields[i]); |
| 179 } | 196 } |
| 180 } | 197 } |
| 181 | 198 |
| 199 handleGetListResponse(response) { | |
| 200 Map result = response["result"]; | |
| 201 if (result["elements"] != null) { | |
| 202 // List slice. | |
| 203 var index = result["index"]; | |
| 204 var length = result["length"]; | |
| 205 List elements = result["elements"]; | |
| 206 assert(length == elements.length); | |
| 207 for (int i = 0; i < length; i++) { | |
| 208 String kind = elements[i]["kind"]; | |
| 209 String text = elements[i]["text"]; | |
|
siva
2012/06/29 00:16:22
maybe:
var kind = ...;
var text = ...;
hausner
2012/06/29 00:52:11
Ok. I use types at a few places to make sure the d
| |
| 210 print(" ${index + i}: ($kind) $text"); | |
| 211 } | |
| 212 } else { | |
| 213 // One element, a remote object. | |
| 214 print(result); | |
| 215 print(" ${remoteObject(result)}"); | |
| 216 } | |
| 217 } | |
| 218 | |
| 182 | 219 |
| 183 handleGetClassPropsResponse(response) { | 220 handleGetClassPropsResponse(response) { |
| 184 Map props = response["result"]; | 221 Map props = response["result"]; |
| 185 assert(props["name"] != null); | 222 assert(props["name"] != null); |
| 186 int libId = props["libraryId"]; | 223 int libId = props["libraryId"]; |
| 187 assert(libId != null); | 224 assert(libId != null); |
| 188 print(" class ${props["name"]} (library id: $libId)"); | 225 print(" class ${props["name"]} (library id: $libId)"); |
| 189 List fields = props["fields"]; | 226 List fields = props["fields"]; |
| 190 if (fields.length > 0) { | 227 if (fields.length > 0) { |
| 191 print(" static fields:"); | 228 print(" static fields:"); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 304 stackTrace = msg["params"]["callFrames"]; | 341 stackTrace = msg["params"]["callFrames"]; |
| 305 assert(stackTrace != null); | 342 assert(stackTrace != null); |
| 306 assert(stackTrace.length >= 1); | 343 assert(stackTrace.length >= 1); |
| 307 curFrame = stackTrace[0]; | 344 curFrame = stackTrace[0]; |
| 308 if (reason == "breakpoint") { | 345 if (reason == "breakpoint") { |
| 309 print("VM paused on breakpoint"); | 346 print("VM paused on breakpoint"); |
| 310 } else { | 347 } else { |
| 311 assert(reason == "exception"); | 348 assert(reason == "exception"); |
| 312 var excObj = msg["params"]["exception"]; | 349 var excObj = msg["params"]["exception"]; |
| 313 print("VM paused on exception"); | 350 print("VM paused on exception"); |
| 314 print(remoteValue(excObj)); | 351 print(remoteObject(excObj)); |
| 315 } | 352 } |
| 316 print("Stack trace:"); | 353 print("Stack trace:"); |
| 317 printStackTrace(stackTrace); | 354 printStackTrace(stackTrace); |
| 318 } | 355 } |
| 319 | 356 |
| 320 | 357 |
| 321 void processVmMessage(String json) { | 358 void processVmMessage(String json) { |
| 322 var msg = JSON.parse(json); | 359 var msg = JSON.parse(json); |
| 323 if (msg == null) { | 360 if (msg == null) { |
| 324 return; | 361 return; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 396 }; | 433 }; |
| 397 vmInStream.onError = (err) { | 434 vmInStream.onError = (err) { |
| 398 print("Error in debug connection: $err"); | 435 print("Error in debug connection: $err"); |
| 399 quitShell(); | 436 quitShell(); |
| 400 }; | 437 }; |
| 401 vmInStream.onClosed = () { | 438 vmInStream.onClosed = () { |
| 402 print("VM debugger connection closed"); | 439 print("VM debugger connection closed"); |
| 403 quitShell(); | 440 quitShell(); |
| 404 }; | 441 }; |
| 405 } | 442 } |
| OLD | NEW |