| 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 15 matching lines...) Expand all Loading... |
| 26 | 26 |
| 27 void printHelp() { | 27 void printHelp() { |
| 28 print(""" | 28 print(""" |
| 29 q Quit debugger shell | 29 q Quit debugger shell |
| 30 bt Show backtrace | 30 bt Show backtrace |
| 31 r Resume execution | 31 r Resume execution |
| 32 s Single step | 32 s Single step |
| 33 so Step over | 33 so Step over |
| 34 si Step into | 34 si Step into |
| 35 sbp [<file>] <line> Set breakpoint | 35 sbp [<file>] <line> Set breakpoint |
| 36 rbp <id> Remove breakpoint with given id |
| 36 po <id> Print object info for given id | 37 po <id> Print object info for given id |
| 37 pc <id> Print class info for given id | 38 pc <id> Print class info for given id |
| 38 ll List loaded libraries | 39 ll List loaded libraries |
| 40 pl <id> Print dlibrary info for given id |
| 39 ls <libname> List loaded scripts in library | 41 ls <libname> List loaded scripts in library |
| 40 h Print help | 42 h Print help |
| 41 """); | 43 """); |
| 42 } | 44 } |
| 43 | 45 |
| 44 | 46 |
| 45 void quitShell() { | 47 void quitShell() { |
| 46 vmStream.close(); | 48 vmStream.close(); |
| 47 vmSock.close(); | 49 vmSock.close(); |
| 48 stdin.close(); | 50 stdin.close(); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 71 var simple_commands = | 73 var simple_commands = |
| 72 { 'r':'resume', 's':'stepOver', 'si':'stepInto', 'so':'stepOut'}; | 74 { 'r':'resume', 's':'stepOver', 'si':'stepInto', 'so':'stepOut'}; |
| 73 if (simple_commands[command] != null) { | 75 if (simple_commands[command] != null) { |
| 74 var cmd = { "id": seqNum, "command": simple_commands[command]}; | 76 var cmd = { "id": seqNum, "command": simple_commands[command]}; |
| 75 sendCmd(cmd).then((result) => handleGenericResponse(result)); | 77 sendCmd(cmd).then((result) => handleGenericResponse(result)); |
| 76 stackTrace = curFrame = null; | 78 stackTrace = curFrame = null; |
| 77 } else if (command == "bt") { | 79 } else if (command == "bt") { |
| 78 var cmd = { "id": seqNum, "command": "getStackTrace" }; | 80 var cmd = { "id": seqNum, "command": "getStackTrace" }; |
| 79 sendCmd(cmd).then((result) => handleStackTraceResponse(result)); | 81 sendCmd(cmd).then((result) => handleStackTraceResponse(result)); |
| 80 } else if (command == "ll") { | 82 } else if (command == "ll") { |
| 81 var cmd = { "id": seqNum, "command": "getLibraryURLs" }; | 83 var cmd = { "id": seqNum, "command": "getLibraries" }; |
| 82 sendCmd(cmd).then((result) => handleGetLibraryResponse(result)); | 84 sendCmd(cmd).then((result) => handleGetLibraryResponse(result)); |
| 83 } else if (command == "sbp" && args.length >= 2) { | 85 } else if (command == "sbp" && args.length >= 2) { |
| 84 var url, line; | 86 var url, line; |
| 85 if (args.length == 2) { | 87 if (args.length == 2) { |
| 86 url = stackTrace[0]["location"]["url"]; | 88 url = stackTrace[0]["location"]["url"]; |
| 87 line = Math.parseInt(args[1]); | 89 line = Math.parseInt(args[1]); |
| 88 } else { | 90 } else { |
| 89 url = args[1]; | 91 url = args[1]; |
| 90 line = Math.parseInt(args[2]); | 92 line = Math.parseInt(args[2]); |
| 91 } | 93 } |
| 92 var cmd = { "id": seqNum, | 94 var cmd = { "id": seqNum, |
| 93 "command": "setBreakpoint", | 95 "command": "setBreakpoint", |
| 94 "params": { "url": url, "line": line }}; | 96 "params": { "url": url, "line": line }}; |
| 95 sendCmd(cmd).then((result) => handleSetBpResponse(result)); | 97 sendCmd(cmd).then((result) => handleSetBpResponse(result)); |
| 98 } else if (command == "rbp" && args.length == 2) { |
| 99 var cmd = { "id": seqNum, |
| 100 "command": "removeBreakpoint", |
| 101 "params": { "breakpointId": Math.parseInt(args[1]) }}; |
| 102 sendCmd(cmd).then((result) => handleGenericResponse(result)); |
| 96 } else if (command == "ls" && args.length == 2) { | 103 } else if (command == "ls" && args.length == 2) { |
| 97 var cmd = { "id": seqNum, | 104 var cmd = { "id": seqNum, |
| 98 "command": "getScriptURLs", | 105 "command": "getScriptURLs", |
| 99 "params": { "library": args[1] }}; | 106 "params": { "libraryId": Math.parseInt(args[1]) }}; |
| 100 sendCmd(cmd).then((result) => handleGetScriptsResponse(result)); | 107 sendCmd(cmd).then((result) => handleGetScriptsResponse(result)); |
| 101 } else if (command == "po" && args.length == 2) { | 108 } else if (command == "po" && args.length == 2) { |
| 102 var cmd = { "id": seqNum, "command": "getObjectProperties", | 109 var cmd = { "id": seqNum, "command": "getObjectProperties", |
| 103 "params": {"objectId": Math.parseInt(args[1]) }}; | 110 "params": {"objectId": Math.parseInt(args[1]) }}; |
| 104 sendCmd(cmd).then((result) => handleGetObjPropsResponse(result)); | 111 sendCmd(cmd).then((result) => handleGetObjPropsResponse(result)); |
| 105 } else if (command == "pc" && args.length == 2) { | 112 } else if (command == "pc" && args.length == 2) { |
| 106 var cmd = { "id": seqNum, "command": "getClassProperties", | 113 var cmd = { "id": seqNum, "command": "getClassProperties", |
| 107 "params": {"classId": Math.parseInt(args[1]) }}; | 114 "params": {"classId": Math.parseInt(args[1]) }}; |
| 108 sendCmd(cmd).then((result) => handleGetClassPropsResponse(result)); | 115 sendCmd(cmd).then((result) => handleGetClassPropsResponse(result)); |
| 116 } else if (command == "pl" && args.length == 2) { |
| 117 var cmd = { "id": seqNum, "command": "getLibraryProperties", |
| 118 "params": {"libraryId": Math.parseInt(args[1]) }}; |
| 119 sendCmd(cmd).then((result) => handleGetLibraryPropsResponse(result)); |
| 109 } else if (command == "q") { | 120 } else if (command == "q") { |
| 110 quitShell(); | 121 quitShell(); |
| 111 } else if (command == "h") { | 122 } else if (command == "h") { |
| 112 printHelp(); | 123 printHelp(); |
| 113 } else { | 124 } else { |
| 114 print("command '$command' not understood, try h for help"); | 125 print("command '$command' not understood, try h for help"); |
| 115 } | 126 } |
| 116 } | 127 } |
| 117 | 128 |
| 118 | 129 |
| 119 printNamedObject(obj) { | 130 printNamedObject(obj) { |
| 120 var name = obj["name"]; | 131 var name = obj["name"]; |
| 121 var value = obj["value"]; | 132 var value = obj["value"]; |
| 122 var kind = value["kind"]; | 133 var kind = value["kind"]; |
| 123 var text = value["text"]; | 134 var text = value["text"]; |
| 124 var id = value["objectId"]; | 135 var id = value["objectId"]; |
| 125 if (kind == "string") { | 136 if (kind == "string") { |
| 126 print(" $name = '$text'"); | 137 print(" $name = '$text'"); |
| 127 } else if (kind == "object") { | 138 } else if (kind == "object") { |
| 128 print(" $name (id:$id) = $text"); | 139 print(" $name (id:$id) = $text"); |
| 129 } else { | 140 } else { |
| 130 print(" $name = $text"); | 141 print(" $name = $text"); |
| 131 } | 142 } |
| 132 } | 143 } |
| 133 | 144 |
| 134 | 145 |
| 135 handleGetObjPropsResponse(response) { | 146 handleGetObjPropsResponse(response) { |
| 136 Map props = response["result"]; | 147 Map props = response["result"]; |
| 137 int class_id = props["classId"]; | 148 int class_id = props["classId"]; |
| 149 if (class_id == -1) { |
| 150 print(" null"); |
| 151 return; |
| 152 } |
| 138 List fields = props["fields"]; | 153 List fields = props["fields"]; |
| 139 print(" class id: $class_id"); | 154 print(" class id: $class_id"); |
| 140 for (int i = 0; i < fields.length; i++) { | 155 for (int i = 0; i < fields.length; i++) { |
| 141 printNamedObject(fields[i]); | 156 printNamedObject(fields[i]); |
| 142 } | 157 } |
| 143 } | 158 } |
| 144 | 159 |
| 145 | 160 |
| 146 handleGetClassPropsResponse(response) { | 161 handleGetClassPropsResponse(response) { |
| 147 Map props = response["result"]; | 162 Map props = response["result"]; |
| 148 assert(props["name"] != null); | 163 assert(props["name"] != null); |
| 149 int libId = props["libraryId"]; | 164 int libId = props["libraryId"]; |
| 150 assert(libId != null); | 165 assert(libId != null); |
| 151 print(" class ${props["name"]} (library id: $libId)"); | 166 print(" class ${props["name"]} (library id: $libId)"); |
| 152 List fields = props["fields"]; | 167 List fields = props["fields"]; |
| 153 if (fields.length > 0) { | 168 if (fields.length > 0) { |
| 154 print(" static fields:"); | 169 print(" static fields:"); |
| 155 for (int i = 0; i < fields.length; i++) { | 170 for (int i = 0; i < fields.length; i++) { |
| 156 printNamedObject(fields[i]); | 171 printNamedObject(fields[i]); |
| 157 } | 172 } |
| 158 } | 173 } |
| 159 } | 174 } |
| 160 | 175 |
| 161 | 176 |
| 177 handleGetLibraryPropsResponse(response) { |
| 178 Map props = response["result"]; |
| 179 assert(props["url"] != null); |
| 180 print(" library url=${props["url"]}"); |
| 181 List imports = props["imports"]; |
| 182 assert(imports != null); |
| 183 if (imports.length > 0) { |
| 184 print(" imports:"); |
| 185 for (int i = 0; i < imports.length; i++) { |
| 186 print(" id ${imports[i]["libraryId"]} prefix ${imports[i]["prefix"]}"); |
| 187 } |
| 188 } |
| 189 List globals = props["globals"]; |
| 190 assert(globals != null); |
| 191 if (globals.length > 0) { |
| 192 print(" global variables:"); |
| 193 for (int i = 0; i < globals.length; i++) { |
| 194 printNamedObject(globals[i]); |
| 195 } |
| 196 } |
| 197 } |
| 198 |
| 199 |
| 162 void handleGetLibraryResponse(response) { | 200 void handleGetLibraryResponse(response) { |
| 163 Map result = response["result"]; | 201 Map result = response["result"]; |
| 164 List urls = result["urls"]; | 202 List libs = result["libraries"]; |
| 165 print("Loaded libraries:"); | 203 print("Loaded libraries:"); |
| 166 for (int i = 0; i < urls.length; i++) { | 204 print(libs); |
| 167 print(" $i ${urls[i]}"); | 205 for (int i = 0; i < libs.length; i++) { |
| 206 print(" ${libs[i]["id"]} ${libs[i]["url"]}"); |
| 168 } | 207 } |
| 169 } | 208 } |
| 170 | 209 |
| 171 | 210 |
| 172 void handleGetScriptsResponse(response) { | 211 void handleGetScriptsResponse(response) { |
| 173 Map result = response["result"]; | 212 Map result = response["result"]; |
| 174 List urls = result["urls"]; | 213 List urls = result["urls"]; |
| 175 print("Loaded scripts:"); | 214 print("Loaded scripts:"); |
| 176 for (int i = 0; i < urls.length; i++) { | 215 for (int i = 0; i < urls.length; i++) { |
| 177 print(" $i ${urls[i]}"); | 216 print(" $i ${urls[i]}"); |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 }; | 346 }; |
| 308 vmInStream.onError = (err) { | 347 vmInStream.onError = (err) { |
| 309 print("Error in debug connection: $err"); | 348 print("Error in debug connection: $err"); |
| 310 quitShell(); | 349 quitShell(); |
| 311 }; | 350 }; |
| 312 vmInStream.onClosed = () { | 351 vmInStream.onClosed = () { |
| 313 print("VM debugger connection closed"); | 352 print("VM debugger connection closed"); |
| 314 quitShell(); | 353 quitShell(); |
| 315 }; | 354 }; |
| 316 } | 355 } |
| OLD | NEW |