OLD | NEW |
1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 Local: 1, | 103 Local: 1, |
104 With: 2, | 104 With: 2, |
105 Closure: 3, | 105 Closure: 3, |
106 Catch: 4 }; | 106 Catch: 4 }; |
107 | 107 |
108 | 108 |
109 // Current debug state. | 109 // Current debug state. |
110 const kNoFrame = -1; | 110 const kNoFrame = -1; |
111 Debug.State = { | 111 Debug.State = { |
112 currentFrame: kNoFrame, | 112 currentFrame: kNoFrame, |
| 113 displaySourceStartLine: -1, |
| 114 displaySourceEndLine: -1, |
113 currentSourceLine: -1 | 115 currentSourceLine: -1 |
114 } | 116 } |
115 var trace_compile = false; // Tracing all compile events? | 117 var trace_compile = false; // Tracing all compile events? |
| 118 var trace_debug_json = false; // Tracing all debug json packets? |
| 119 var last_cmd_line = ''; |
| 120 var repeat_cmd_line = ''; |
| 121 var is_running = true; |
| 122 |
| 123 // Copied from debug-delay.js. This is needed below: |
| 124 function ScriptTypeFlag(type) { |
| 125 return (1 << type); |
| 126 } |
116 | 127 |
117 | 128 |
118 // Process a debugger JSON message into a display text and a running status. | 129 // Process a debugger JSON message into a display text and a running status. |
119 // This function returns an object with properties "text" and "running" holding | 130 // This function returns an object with properties "text" and "running" holding |
120 // this information. | 131 // this information. |
121 function DebugMessageDetails(message) { | 132 function DebugMessageDetails(message) { |
| 133 if (trace_debug_json) { |
| 134 print("received: '" + message + "'"); |
| 135 } |
122 // Convert the JSON string to an object. | 136 // Convert the JSON string to an object. |
123 var response = new ProtocolPackage(message); | 137 var response = new ProtocolPackage(message); |
| 138 is_running = response.running(); |
124 | 139 |
125 if (response.type() == 'event') { | 140 if (response.type() == 'event') { |
126 return DebugEventDetails(response); | 141 return DebugEventDetails(response); |
127 } else { | 142 } else { |
128 return DebugResponseDetails(response); | 143 return DebugResponseDetails(response); |
129 } | 144 } |
130 } | 145 } |
131 | 146 |
132 function DebugEventDetails(response) { | 147 function DebugEventDetails(response) { |
133 details = {text:'', running:false} | 148 details = {text:'', running:false} |
(...skipping 20 matching lines...) Expand all Loading... |
154 } else { | 169 } else { |
155 result += 'break'; | 170 result += 'break'; |
156 } | 171 } |
157 result += ' in '; | 172 result += ' in '; |
158 result += body.invocationText; | 173 result += body.invocationText; |
159 result += ', '; | 174 result += ', '; |
160 result += SourceInfo(body); | 175 result += SourceInfo(body); |
161 result += '\n'; | 176 result += '\n'; |
162 result += SourceUnderline(body.sourceLineText, body.sourceColumn); | 177 result += SourceUnderline(body.sourceLineText, body.sourceColumn); |
163 Debug.State.currentSourceLine = body.sourceLine; | 178 Debug.State.currentSourceLine = body.sourceLine; |
| 179 Debug.State.displaySourceStartLine = -1; |
| 180 Debug.State.displaySourceEndLine = -1; |
164 Debug.State.currentFrame = 0; | 181 Debug.State.currentFrame = 0; |
165 details.text = result; | 182 details.text = result; |
166 break; | 183 break; |
167 | 184 |
168 case 'exception': | 185 case 'exception': |
169 if (body.uncaught) { | 186 if (body.uncaught) { |
170 result += 'Uncaught: '; | 187 result += 'Uncaught: '; |
171 } else { | 188 } else { |
172 result += 'Exception: '; | 189 result += 'Exception: '; |
173 } | 190 } |
174 result += '"'; | 191 result += '"'; |
175 result += body.exception.text; | 192 result += body.exception.text; |
176 result += '"'; | 193 result += '"'; |
177 if (body.sourceLine >= 0) { | 194 if (body.sourceLine >= 0) { |
178 result += ', '; | 195 result += ', '; |
179 result += SourceInfo(body); | 196 result += SourceInfo(body); |
180 result += '\n'; | 197 result += '\n'; |
181 result += SourceUnderline(body.sourceLineText, body.sourceColumn); | 198 result += SourceUnderline(body.sourceLineText, body.sourceColumn); |
182 Debug.State.currentSourceLine = body.sourceLine; | 199 Debug.State.currentSourceLine = body.sourceLine; |
| 200 Debug.State.displaySourceStartLine = -1; |
| 201 Debug.State.displaySourceEndLine = -1; |
183 Debug.State.currentFrame = 0; | 202 Debug.State.currentFrame = 0; |
184 } else { | 203 } else { |
185 result += ' (empty stack)'; | 204 result += ' (empty stack)'; |
186 Debug.State.currentSourceLine = -1; | 205 Debug.State.currentSourceLine = -1; |
| 206 Debug.State.displaySourceStartLine = -1; |
| 207 Debug.State.displaySourceEndLine = -1; |
187 Debug.State.currentFrame = kNoFrame; | 208 Debug.State.currentFrame = kNoFrame; |
188 } | 209 } |
189 details.text = result; | 210 details.text = result; |
190 break; | 211 break; |
191 | 212 |
192 case 'afterCompile': | 213 case 'afterCompile': |
193 if (trace_compile) { | 214 if (trace_compile) { |
194 result = 'Source ' + body.script.name + ' compiled:\n' | 215 result = 'Source ' + body.script.name + ' compiled:\n' |
195 var source = body.script.source; | 216 var source = body.script.source; |
196 if (!(source[source.length - 1] == '\n')) { | 217 if (!(source[source.length - 1] == '\n')) { |
197 result += source; | 218 result += source; |
198 } else { | 219 } else { |
199 result += source.substring(0, source.length - 1); | 220 result += source.substring(0, source.length - 1); |
200 } | 221 } |
201 } | 222 } |
202 details.text = result; | 223 details.text = result; |
203 break; | 224 break; |
204 | 225 |
| 226 case 'scriptCollected': |
| 227 details.text = result; |
| 228 break; |
| 229 |
205 default: | 230 default: |
206 details.text = 'Unknown debug event ' + response.event(); | 231 details.text = 'Unknown debug event ' + response.event(); |
207 } | 232 } |
208 | 233 |
209 return details; | 234 return details; |
210 }; | 235 }; |
211 | 236 |
212 | 237 |
213 function SourceInfo(body) { | 238 function SourceInfo(body) { |
214 var result = ''; | 239 var result = ''; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 } | 272 } |
248 underline += '^'; | 273 underline += '^'; |
249 | 274 |
250 // Return the source line text with the underline beneath. | 275 // Return the source line text with the underline beneath. |
251 return source_text + '\n' + underline; | 276 return source_text + '\n' + underline; |
252 }; | 277 }; |
253 | 278 |
254 | 279 |
255 // Converts a text command to a JSON request. | 280 // Converts a text command to a JSON request. |
256 function DebugCommandToJSONRequest(cmd_line) { | 281 function DebugCommandToJSONRequest(cmd_line) { |
257 return new DebugRequest(cmd_line).JSONRequest(); | 282 var result = new DebugRequest(cmd_line).JSONRequest(); |
| 283 if (trace_debug_json && result) { |
| 284 print("sending: '" + result + "'"); |
| 285 } |
| 286 return result; |
258 }; | 287 }; |
259 | 288 |
260 | 289 |
261 function DebugRequest(cmd_line) { | 290 function DebugRequest(cmd_line) { |
262 // If the very first character is a { assume that a JSON request have been | 291 // If the very first character is a { assume that a JSON request have been |
263 // entered as a command. Converting that to a JSON request is trivial. | 292 // entered as a command. Converting that to a JSON request is trivial. |
264 if (cmd_line && cmd_line.length > 0 && cmd_line.charAt(0) == '{') { | 293 if (cmd_line && cmd_line.length > 0 && cmd_line.charAt(0) == '{') { |
265 this.request_ = cmd_line; | 294 this.request_ = cmd_line; |
266 return; | 295 return; |
267 } | 296 } |
268 | 297 |
| 298 // Check for a simple carriage return to repeat the last command: |
| 299 var is_repeating = false; |
| 300 if (cmd_line == '\n') { |
| 301 if (is_running) { |
| 302 cmd_line = 'break'; // Not in debugger mode, break with a frame request. |
| 303 } else { |
| 304 cmd_line = repeat_cmd_line; // use command to repeat. |
| 305 is_repeating = true; |
| 306 } |
| 307 } |
| 308 if (!is_running) { // Only save the command if in debugger mode. |
| 309 repeat_cmd_line = cmd_line; // save last command. |
| 310 } |
| 311 |
269 // Trim string for leading and trailing whitespace. | 312 // Trim string for leading and trailing whitespace. |
270 cmd_line = cmd_line.replace(/^\s+|\s+$/g, ''); | 313 cmd_line = cmd_line.replace(/^\s+|\s+$/g, ''); |
271 | 314 |
272 // Find the command. | 315 // Find the command. |
273 var pos = cmd_line.indexOf(' '); | 316 var pos = cmd_line.indexOf(' '); |
274 var cmd; | 317 var cmd; |
275 var args; | 318 var args; |
276 if (pos == -1) { | 319 if (pos == -1) { |
277 cmd = cmd_line; | 320 cmd = cmd_line; |
278 args = ''; | 321 args = ''; |
279 } else { | 322 } else { |
280 cmd = cmd_line.slice(0, pos); | 323 cmd = cmd_line.slice(0, pos); |
281 args = cmd_line.slice(pos).replace(/^\s+|\s+$/g, ''); | 324 args = cmd_line.slice(pos).replace(/^\s+|\s+$/g, ''); |
282 } | 325 } |
283 | 326 |
| 327 if ((cmd === undefined) || !cmd) { |
| 328 this.request_ = void 0; |
| 329 return; |
| 330 } |
| 331 |
| 332 last_cmd = cmd; |
| 333 |
284 // Switch on command. | 334 // Switch on command. |
285 switch (cmd) { | 335 switch (cmd) { |
286 case 'continue': | 336 case 'continue': |
287 case 'c': | 337 case 'c': |
288 this.request_ = this.continueCommandToJSONRequest_(args); | 338 this.request_ = this.continueCommandToJSONRequest_(args); |
289 break; | 339 break; |
290 | 340 |
291 case 'step': | 341 case 'step': |
292 case 's': | 342 case 's': |
293 this.request_ = this.stepCommandToJSONRequest_(args); | 343 this.request_ = this.stepCommandToJSONRequest_(args, 'in'); |
| 344 break; |
| 345 |
| 346 case 'stepi': |
| 347 case 'si': |
| 348 this.request_ = this.stepCommandToJSONRequest_(args, 'min'); |
| 349 break; |
| 350 |
| 351 case 'next': |
| 352 case 'n': |
| 353 this.request_ = this.stepCommandToJSONRequest_(args, 'next'); |
| 354 break; |
| 355 |
| 356 case 'finish': |
| 357 case 'fin': |
| 358 this.request_ = this.stepCommandToJSONRequest_(args, 'out'); |
294 break; | 359 break; |
295 | 360 |
296 case 'backtrace': | 361 case 'backtrace': |
297 case 'bt': | 362 case 'bt': |
298 this.request_ = this.backtraceCommandToJSONRequest_(args); | 363 this.request_ = this.backtraceCommandToJSONRequest_(args); |
299 break; | 364 break; |
300 | 365 |
301 case 'frame': | 366 case 'frame': |
302 case 'f': | 367 case 'f': |
303 this.request_ = this.frameCommandToJSONRequest_(args); | 368 this.request_ = this.frameCommandToJSONRequest_(args); |
304 break; | 369 break; |
305 | 370 |
306 case 'scopes': | 371 case 'scopes': |
307 this.request_ = this.scopesCommandToJSONRequest_(args); | 372 this.request_ = this.scopesCommandToJSONRequest_(args); |
308 break; | 373 break; |
309 | 374 |
310 case 'scope': | 375 case 'scope': |
311 this.request_ = this.scopeCommandToJSONRequest_(args); | 376 this.request_ = this.scopeCommandToJSONRequest_(args); |
312 break; | 377 break; |
313 | 378 |
| 379 case 'disconnect': |
| 380 case 'exit': |
| 381 case 'quit': |
| 382 this.request_ = this.disconnectCommandToJSONRequest_(args); |
| 383 break; |
| 384 |
| 385 case 'up': |
| 386 this.request_ = |
| 387 this.frameCommandToJSONRequest_('' + |
| 388 (Debug.State.currentFrame + 1)); |
| 389 break; |
| 390 |
| 391 case 'down': |
| 392 case 'do': |
| 393 this.request_ = |
| 394 this.frameCommandToJSONRequest_('' + |
| 395 (Debug.State.currentFrame - 1)); |
| 396 break; |
| 397 |
| 398 case 'set': |
314 case 'print': | 399 case 'print': |
315 case 'p': | 400 case 'p': |
316 this.request_ = this.printCommandToJSONRequest_(args); | 401 this.request_ = this.printCommandToJSONRequest_(args); |
317 break; | 402 break; |
318 | 403 |
319 case 'dir': | 404 case 'dir': |
320 this.request_ = this.dirCommandToJSONRequest_(args); | 405 this.request_ = this.dirCommandToJSONRequest_(args); |
321 break; | 406 break; |
322 | 407 |
323 case 'references': | 408 case 'references': |
324 this.request_ = this.referencesCommandToJSONRequest_(args); | 409 this.request_ = this.referencesCommandToJSONRequest_(args); |
325 break; | 410 break; |
326 | 411 |
327 case 'instances': | 412 case 'instances': |
328 this.request_ = this.instancesCommandToJSONRequest_(args); | 413 this.request_ = this.instancesCommandToJSONRequest_(args); |
329 break; | 414 break; |
330 | 415 |
| 416 case 'list': |
| 417 case 'l': |
| 418 this.request_ = this.listCommandToJSONRequest_(args); |
| 419 break; |
331 case 'source': | 420 case 'source': |
332 this.request_ = this.sourceCommandToJSONRequest_(args); | 421 this.request_ = this.sourceCommandToJSONRequest_(args); |
333 break; | 422 break; |
334 | 423 |
335 case 'scripts': | 424 case 'scripts': |
| 425 case 'script': |
| 426 case 'scr': |
336 this.request_ = this.scriptsCommandToJSONRequest_(args); | 427 this.request_ = this.scriptsCommandToJSONRequest_(args); |
337 break; | 428 break; |
338 | 429 |
339 case 'break': | 430 case 'break': |
340 case 'b': | 431 case 'b': |
341 this.request_ = this.breakCommandToJSONRequest_(args); | 432 this.request_ = this.breakCommandToJSONRequest_(args); |
342 break; | 433 break; |
343 | 434 |
344 case 'breakpoints': | 435 case 'breakpoints': |
345 case 'bb': | 436 case 'bb': |
346 this.request_ = this.breakpointsCommandToJSONRequest_(args); | 437 this.request_ = this.breakpointsCommandToJSONRequest_(args); |
347 break; | 438 break; |
348 | 439 |
349 case 'clear': | 440 case 'clear': |
| 441 case 'delete': |
| 442 case 'd': |
350 this.request_ = this.clearCommandToJSONRequest_(args); | 443 this.request_ = this.clearCommandToJSONRequest_(args); |
351 break; | 444 break; |
352 | 445 |
353 case 'threads': | 446 case 'threads': |
354 this.request_ = this.threadsCommandToJSONRequest_(args); | 447 this.request_ = this.threadsCommandToJSONRequest_(args); |
355 break; | 448 break; |
356 | 449 |
| 450 case 'cond': |
| 451 this.request_ = this.changeBreakpointCommandToJSONRequest_(args, 'cond'); |
| 452 break; |
| 453 |
| 454 case 'enable': |
| 455 case 'en': |
| 456 this.request_ = |
| 457 this.changeBreakpointCommandToJSONRequest_(args, 'enable'); |
| 458 break; |
| 459 |
| 460 case 'disable': |
| 461 case 'dis': |
| 462 this.request_ = |
| 463 this.changeBreakpointCommandToJSONRequest_(args, 'disable'); |
| 464 break; |
| 465 |
| 466 case 'ignore': |
| 467 this.request_ = |
| 468 this.changeBreakpointCommandToJSONRequest_(args, 'ignore'); |
| 469 break; |
| 470 |
| 471 case 'info': |
| 472 case 'inf': |
| 473 this.request_ = this.infoCommandToJSONRequest_(args); |
| 474 break; |
| 475 |
| 476 case 'flags': |
| 477 this.request_ = this.v8FlagsToJSONRequest_(args); |
| 478 break; |
| 479 |
| 480 case 'gc': |
| 481 this.request_ = this.gcToJSONRequest_(args); |
| 482 break; |
| 483 |
357 case 'trace': | 484 case 'trace': |
| 485 case 'tr': |
358 // Return undefined to indicate command handled internally (no JSON). | 486 // Return undefined to indicate command handled internally (no JSON). |
359 this.request_ = void 0; | 487 this.request_ = void 0; |
360 this.traceCommand_(args); | 488 this.traceCommand_(args); |
361 break; | 489 break; |
362 | 490 |
363 case 'help': | 491 case 'help': |
364 case '?': | 492 case '?': |
365 this.helpCommand_(args); | 493 this.helpCommand_(args); |
366 // Return undefined to indicate command handled internally (no JSON). | 494 // Return undefined to indicate command handled internally (no JSON). |
367 this.request_ = void 0; | 495 this.request_ = void 0; |
368 break; | 496 break; |
369 | 497 |
370 default: | 498 default: |
371 throw new Error('Unknown command "' + cmd + '"'); | 499 throw new Error('Unknown command "' + cmd + '"'); |
372 } | 500 } |
373 | |
374 last_cmd = cmd; | |
375 } | 501 } |
376 | 502 |
377 DebugRequest.prototype.JSONRequest = function() { | 503 DebugRequest.prototype.JSONRequest = function() { |
378 return this.request_; | 504 return this.request_; |
379 } | 505 } |
380 | 506 |
381 | 507 |
382 function RequestPacket(command) { | 508 function RequestPacket(command) { |
383 this.seq = 0; | 509 this.seq = 0; |
384 this.type = 'request'; | 510 this.type = 'request'; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 | 584 |
459 | 585 |
460 // Create a JSON request for the continue command. | 586 // Create a JSON request for the continue command. |
461 DebugRequest.prototype.continueCommandToJSONRequest_ = function(args) { | 587 DebugRequest.prototype.continueCommandToJSONRequest_ = function(args) { |
462 var request = this.createRequest('continue'); | 588 var request = this.createRequest('continue'); |
463 return request.toJSONProtocol(); | 589 return request.toJSONProtocol(); |
464 }; | 590 }; |
465 | 591 |
466 | 592 |
467 // Create a JSON request for the step command. | 593 // Create a JSON request for the step command. |
468 DebugRequest.prototype.stepCommandToJSONRequest_ = function(args) { | 594 DebugRequest.prototype.stepCommandToJSONRequest_ = function(args, type) { |
469 // Requesting a step is through the continue command with additional | 595 // Requesting a step is through the continue command with additional |
470 // arguments. | 596 // arguments. |
471 var request = this.createRequest('continue'); | 597 var request = this.createRequest('continue'); |
472 request.arguments = {}; | 598 request.arguments = {}; |
473 | 599 |
474 // Process arguments if any. | 600 // Process arguments if any. |
| 601 |
| 602 // Only process args if the command is 'step' which is indicated by type being |
| 603 // set to 'in'. For all other commands, ignore the args. |
475 if (args && args.length > 0) { | 604 if (args && args.length > 0) { |
476 args = args.split(/\s*[ ]+\s*/g); | 605 args = args.split(/\s+/g); |
477 | 606 |
478 if (args.length > 2) { | 607 if (args.length > 2) { |
479 throw new Error('Invalid step arguments.'); | 608 throw new Error('Invalid step arguments.'); |
480 } | 609 } |
481 | 610 |
482 if (args.length > 0) { | 611 if (args.length > 0) { |
483 // Get step count argument if any. | 612 // Check if we have a gdb stype step command. If so, the 1st arg would |
484 if (args.length == 2) { | 613 // be the step count. If it's not a number, then assume that we're |
485 var stepcount = parseInt(args[1]); | 614 // parsing for the legacy v8 step command. |
486 if (isNaN(stepcount) || stepcount <= 0) { | 615 var stepcount = Number(args[0]); |
487 throw new Error('Invalid step count argument "' + args[0] + '".'); | 616 if (stepcount == Number.NaN) { |
| 617 // No step count at arg 1. Process as legacy d8 step command: |
| 618 if (args.length == 2) { |
| 619 var stepcount = parseInt(args[1]); |
| 620 if (isNaN(stepcount) || stepcount <= 0) { |
| 621 throw new Error('Invalid step count argument "' + args[0] + '".'); |
| 622 } |
| 623 request.arguments.stepcount = stepcount; |
488 } | 624 } |
| 625 |
| 626 // Get the step action. |
| 627 switch (args[0]) { |
| 628 case 'in': |
| 629 case 'i': |
| 630 request.arguments.stepaction = 'in'; |
| 631 break; |
| 632 |
| 633 case 'min': |
| 634 case 'm': |
| 635 request.arguments.stepaction = 'min'; |
| 636 break; |
| 637 |
| 638 case 'next': |
| 639 case 'n': |
| 640 request.arguments.stepaction = 'next'; |
| 641 break; |
| 642 |
| 643 case 'out': |
| 644 case 'o': |
| 645 request.arguments.stepaction = 'out'; |
| 646 break; |
| 647 |
| 648 default: |
| 649 throw new Error('Invalid step argument "' + args[0] + '".'); |
| 650 } |
| 651 |
| 652 } else { |
| 653 // gdb style step commands: |
| 654 request.arguments.stepaction = type; |
489 request.arguments.stepcount = stepcount; | 655 request.arguments.stepcount = stepcount; |
490 } | 656 } |
491 | |
492 // Get the step action. | |
493 switch (args[0]) { | |
494 case 'in': | |
495 case 'i': | |
496 request.arguments.stepaction = 'in'; | |
497 break; | |
498 | |
499 case 'min': | |
500 case 'm': | |
501 request.arguments.stepaction = 'min'; | |
502 break; | |
503 | |
504 case 'next': | |
505 case 'n': | |
506 request.arguments.stepaction = 'next'; | |
507 break; | |
508 | |
509 case 'out': | |
510 case 'o': | |
511 request.arguments.stepaction = 'out'; | |
512 break; | |
513 | |
514 default: | |
515 throw new Error('Invalid step argument "' + args[0] + '".'); | |
516 } | |
517 } | 657 } |
518 } else { | 658 } else { |
519 // Default is step next. | 659 // Default is step of the specified type. |
520 request.arguments.stepaction = 'next'; | 660 request.arguments.stepaction = type; |
521 } | 661 } |
522 | 662 |
523 return request.toJSONProtocol(); | 663 return request.toJSONProtocol(); |
524 }; | 664 }; |
525 | 665 |
526 | 666 |
527 // Create a JSON request for the backtrace command. | 667 // Create a JSON request for the backtrace command. |
528 DebugRequest.prototype.backtraceCommandToJSONRequest_ = function(args) { | 668 DebugRequest.prototype.backtraceCommandToJSONRequest_ = function(args) { |
529 // Build a backtrace request from the text command. | 669 // Build a backtrace request from the text command. |
530 var request = this.createRequest('backtrace'); | 670 var request = this.createRequest('backtrace'); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
641 // Build an evaluate request from the text command. | 781 // Build an evaluate request from the text command. |
642 if (args.length == 0) { | 782 if (args.length == 0) { |
643 throw new Error('Missing object id.'); | 783 throw new Error('Missing object id.'); |
644 } | 784 } |
645 | 785 |
646 // Build a references request. | 786 // Build a references request. |
647 return this.makeReferencesJSONRequest_(args, 'constructedBy'); | 787 return this.makeReferencesJSONRequest_(args, 'constructedBy'); |
648 }; | 788 }; |
649 | 789 |
650 | 790 |
| 791 // Create a JSON request for the list command. |
| 792 DebugRequest.prototype.listCommandToJSONRequest_ = function(args) { |
| 793 |
| 794 // Default is ten lines starting five lines before the current location. |
| 795 if (Debug.State.displaySourceEndLine == -1) { |
| 796 // If we list forwards, we will start listing after the last source end |
| 797 // line. Set it to start from 5 lines before the current location. |
| 798 Debug.State.displaySourceEndLine = Debug.State.currentSourceLine - 5; |
| 799 // If we list backwards, we will start listing backwards from the last |
| 800 // source start line. Set it to start from 1 lines before the current |
| 801 // location. |
| 802 Debug.State.displaySourceStartLine = Debug.State.currentSourceLine + 1; |
| 803 } |
| 804 |
| 805 var from = Debug.State.displaySourceEndLine + 1; |
| 806 var lines = 10; |
| 807 |
| 808 // Parse the arguments. |
| 809 args = args.split(/\s*,\s*/g); |
| 810 if (args == '') { |
| 811 } else if ((args.length == 1) && (args[0] == '-')) { |
| 812 from = Debug.State.displaySourceStartLine - lines; |
| 813 } else if (args.length == 2) { |
| 814 from = parseInt(args[0]); |
| 815 lines = parseInt(args[1]) - from + 1; // inclusive of the ending line. |
| 816 } else { |
| 817 throw new Error('Invalid list arguments.'); |
| 818 } |
| 819 Debug.State.displaySourceStartLine = from; |
| 820 Debug.State.displaySourceEndLine = from + lines - 1; |
| 821 var sourceArgs = '' + from + ' ' + lines; |
| 822 return this.sourceCommandToJSONRequest_(sourceArgs); |
| 823 }; |
| 824 |
| 825 |
651 // Create a JSON request for the source command. | 826 // Create a JSON request for the source command. |
652 DebugRequest.prototype.sourceCommandToJSONRequest_ = function(args) { | 827 DebugRequest.prototype.sourceCommandToJSONRequest_ = function(args) { |
653 // Build a evaluate request from the text command. | 828 // Build a evaluate request from the text command. |
654 var request = this.createRequest('source'); | 829 var request = this.createRequest('source'); |
655 | 830 |
656 // Default is ten lines starting five lines before the current location. | 831 // Default is ten lines starting five lines before the current location. |
657 var from = Debug.State.currentSourceLine - 5; | 832 var from = Debug.State.currentSourceLine - 5; |
658 var lines = 10; | 833 var lines = 10; |
659 | 834 |
660 // Parse the arguments. | 835 // Parse the arguments. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
702 break; | 877 break; |
703 | 878 |
704 case 'all': | 879 case 'all': |
705 request.arguments.types = | 880 request.arguments.types = |
706 ScriptTypeFlag(Debug.ScriptType.Normal) | | 881 ScriptTypeFlag(Debug.ScriptType.Normal) | |
707 ScriptTypeFlag(Debug.ScriptType.Native) | | 882 ScriptTypeFlag(Debug.ScriptType.Native) | |
708 ScriptTypeFlag(Debug.ScriptType.Extension); | 883 ScriptTypeFlag(Debug.ScriptType.Extension); |
709 break; | 884 break; |
710 | 885 |
711 default: | 886 default: |
712 throw new Error('Invalid argument "' + args[0] + '".'); | 887 // If the arg is not one of the know one aboves, then it must be a |
| 888 // filter used for filtering the results: |
| 889 request.arguments.filter = args[0]; |
| 890 break; |
713 } | 891 } |
714 } | 892 } |
715 | 893 |
716 return request.toJSONProtocol(); | 894 return request.toJSONProtocol(); |
717 }; | 895 }; |
718 | 896 |
719 | 897 |
720 // Create a JSON request for the break command. | 898 // Create a JSON request for the break command. |
721 DebugRequest.prototype.breakCommandToJSONRequest_ = function(args) { | 899 DebugRequest.prototype.breakCommandToJSONRequest_ = function(args) { |
722 // Build a evaluate request from the text command. | 900 // Build a evaluate request from the text command. |
723 // Process arguments if any. | 901 // Process arguments if any. |
724 if (args && args.length > 0) { | 902 if (args && args.length > 0) { |
725 var target = args; | 903 var target = args; |
726 var type = 'function'; | 904 var type = 'function'; |
727 var line; | 905 var line; |
728 var column; | 906 var column; |
729 var condition; | 907 var condition; |
730 var pos; | 908 var pos; |
731 | 909 |
732 var request = this.createRequest('setbreakpoint'); | 910 var request = this.createRequest('setbreakpoint'); |
733 | 911 |
| 912 // Break the args into target spec and condition if appropriate. |
| 913 |
734 // Check for breakpoint condition. | 914 // Check for breakpoint condition. |
735 pos = args.indexOf(' '); | 915 pos = args.indexOf(' '); |
736 if (pos > 0) { | 916 if (pos > 0) { |
737 target = args.substring(0, pos); | 917 target = args.substring(0, pos); |
738 condition = args.substring(pos + 1, args.length); | 918 condition = args.substring(pos + 1, args.length); |
739 } | 919 } |
740 | 920 |
741 // Check for script breakpoint (name:line[:column]). If no ':' in break | 921 // Check for script breakpoint (name:line[:column]). If no ':' in break |
742 // specification it is considered a function break point. | 922 // specification it is considered a function break point. |
743 pos = target.indexOf(':'); | 923 pos = target.indexOf(':'); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
794 request.arguments = {}; | 974 request.arguments = {}; |
795 request.arguments.breakpoint = parseInt(args); | 975 request.arguments.breakpoint = parseInt(args); |
796 } else { | 976 } else { |
797 throw new Error('Invalid break arguments.'); | 977 throw new Error('Invalid break arguments.'); |
798 } | 978 } |
799 | 979 |
800 return request.toJSONProtocol(); | 980 return request.toJSONProtocol(); |
801 }; | 981 }; |
802 | 982 |
803 | 983 |
| 984 // Create a JSON request for the change breakpoint command. |
| 985 DebugRequest.prototype.changeBreakpointCommandToJSONRequest_ = |
| 986 function(args, command) { |
| 987 |
| 988 var request; |
| 989 |
| 990 // Check for exception breaks first: |
| 991 // en[able] exc[eptions] [all|unc[aught]] |
| 992 // en[able] [all|unc[aught]] exc[eptions] |
| 993 // dis[able] exc[eptions] [all|unc[aught]] |
| 994 // dis[able] [all|unc[aught]] exc[eptions] |
| 995 if ((command == 'enable' || command == 'disable') && |
| 996 args && args.length > 1) { |
| 997 var nextPos = args.indexOf(' '); |
| 998 var arg1 = (nextPos > 0) ? args.substring(0, nextPos) : args; |
| 999 var excType = null; |
| 1000 |
| 1001 // Check for: |
| 1002 // en[able] exc[eptions] [all|unc[aught]] |
| 1003 // dis[able] exc[eptions] [all|unc[aught]] |
| 1004 if (arg1 == 'exc' || arg1 == 'exception' || arg1 == 'exceptions') { |
| 1005 |
| 1006 var arg2 = (nextPos > 0) ? |
| 1007 args.substring(nextPos + 1, args.length) : 'all'; |
| 1008 if (!arg2) { |
| 1009 arg2 = 'all'; // if unspecified, set for all. |
| 1010 } if (arg2 == 'unc') { // check for short cut. |
| 1011 arg2 = 'uncaught'; |
| 1012 } |
| 1013 excType = arg2; |
| 1014 |
| 1015 // Check for: |
| 1016 // en[able] [all|unc[aught]] exc[eptions] |
| 1017 // dis[able] [all|unc[aught]] exc[eptions] |
| 1018 } else if (arg1 == 'all' || arg1 == 'unc' || arg1 == 'uncaught') { |
| 1019 |
| 1020 var arg2 = (nextPos > 0) ? |
| 1021 args.substring(nextPos + 1, args.length) : null; |
| 1022 if (arg2 == 'exc' || arg1 == 'exception' || arg1 == 'exceptions') { |
| 1023 excType = arg1; |
| 1024 if (excType == 'unc') { |
| 1025 excType = 'uncaught'; |
| 1026 } |
| 1027 } |
| 1028 } |
| 1029 |
| 1030 // If we matched one of the command formats, then excType will be non-null: |
| 1031 if (excType) { |
| 1032 // Build a evaluate request from the text command. |
| 1033 request = this.createRequest('setexceptionbreak'); |
| 1034 |
| 1035 request.arguments = {}; |
| 1036 request.arguments.type = excType; |
| 1037 request.arguments.enabled = (command == 'enable'); |
| 1038 |
| 1039 return request.toJSONProtocol(); |
| 1040 } |
| 1041 } |
| 1042 |
| 1043 // Build a evaluate request from the text command. |
| 1044 request = this.createRequest('changebreakpoint'); |
| 1045 |
| 1046 // Process arguments if any. |
| 1047 if (args && args.length > 0) { |
| 1048 request.arguments = {}; |
| 1049 var pos = args.indexOf(' '); |
| 1050 var breakpointArg = args; |
| 1051 var otherArgs; |
| 1052 if (pos > 0) { |
| 1053 breakpointArg = args.substring(0, pos); |
| 1054 otherArgs = args.substring(pos + 1, args.length); |
| 1055 } |
| 1056 |
| 1057 request.arguments.breakpoint = parseInt(breakpointArg); |
| 1058 |
| 1059 switch(command) { |
| 1060 case 'cond': |
| 1061 request.arguments.condition = otherArgs ? otherArgs : null; |
| 1062 break; |
| 1063 case 'enable': |
| 1064 request.arguments.enabled = true; |
| 1065 break; |
| 1066 case 'disable': |
| 1067 request.arguments.enabled = false; |
| 1068 break; |
| 1069 case 'ignore': |
| 1070 request.arguments.ignoreCount = parseInt(otherArgs); |
| 1071 break; |
| 1072 default: |
| 1073 throw new Error('Invalid arguments.'); |
| 1074 } |
| 1075 } else { |
| 1076 throw new Error('Invalid arguments.'); |
| 1077 } |
| 1078 |
| 1079 return request.toJSONProtocol(); |
| 1080 }; |
| 1081 |
| 1082 |
| 1083 // Create a JSON request for the disconnect command. |
| 1084 DebugRequest.prototype.disconnectCommandToJSONRequest_ = function(args) { |
| 1085 var request; |
| 1086 request = this.createRequest('disconnect'); |
| 1087 return request.toJSONProtocol(); |
| 1088 }; |
| 1089 |
| 1090 |
| 1091 // Create a JSON request for the info command. |
| 1092 DebugRequest.prototype.infoCommandToJSONRequest_ = function(args) { |
| 1093 var request; |
| 1094 if (args && (args == 'break' || args == 'br')) { |
| 1095 // Build a evaluate request from the text command. |
| 1096 request = this.createRequest('listbreakpoints'); |
| 1097 last_cmd = 'info break'; |
| 1098 } else if (args && (args == 'locals' || args == 'lo')) { |
| 1099 // Build a evaluate request from the text command. |
| 1100 request = this.createRequest('frame'); |
| 1101 last_cmd = 'info locals'; |
| 1102 } else if (args && (args == 'args' || args == 'ar')) { |
| 1103 // Build a evaluate request from the text command. |
| 1104 request = this.createRequest('frame'); |
| 1105 last_cmd = 'info args'; |
| 1106 } else { |
| 1107 throw new Error('Invalid info arguments.'); |
| 1108 } |
| 1109 |
| 1110 return request.toJSONProtocol(); |
| 1111 }; |
| 1112 |
| 1113 |
| 1114 DebugRequest.prototype.v8FlagsToJSONRequest_ = function(args) { |
| 1115 var request; |
| 1116 request = this.createRequest('v8flags'); |
| 1117 request.arguments = {}; |
| 1118 request.arguments.flags = args; |
| 1119 return request.toJSONProtocol(); |
| 1120 }; |
| 1121 |
| 1122 |
| 1123 DebugRequest.prototype.gcToJSONRequest_ = function(args) { |
| 1124 var request; |
| 1125 if (!args) { |
| 1126 args = 'all'; |
| 1127 } |
| 1128 var args = args.split(/\s+/g); |
| 1129 var cmd = args[0]; |
| 1130 |
| 1131 switch(cmd) { |
| 1132 case 'all': |
| 1133 case 'quick': |
| 1134 case 'full': |
| 1135 case 'young': |
| 1136 case 'old': |
| 1137 case 'compact': |
| 1138 case 'sweep': |
| 1139 case 'scavenge': { |
| 1140 if (cmd == 'young') { cmd = 'quick'; } |
| 1141 else if (cmd == 'old') { cmd = 'full'; } |
| 1142 |
| 1143 request = this.createRequest('gc'); |
| 1144 request.arguments = {}; |
| 1145 request.arguments.type = cmd; |
| 1146 break; |
| 1147 } |
| 1148 // Else fall thru to the default case below to report the error. |
| 1149 default: |
| 1150 throw new Error('Missing arguments after ' + cmd + '.'); |
| 1151 } |
| 1152 return request.toJSONProtocol(); |
| 1153 }; |
| 1154 |
| 1155 |
804 // Create a JSON request for the threads command. | 1156 // Create a JSON request for the threads command. |
805 DebugRequest.prototype.threadsCommandToJSONRequest_ = function(args) { | 1157 DebugRequest.prototype.threadsCommandToJSONRequest_ = function(args) { |
806 // Build a threads request from the text command. | 1158 // Build a threads request from the text command. |
807 var request = this.createRequest('threads'); | 1159 var request = this.createRequest('threads'); |
808 return request.toJSONProtocol(); | 1160 return request.toJSONProtocol(); |
809 }; | 1161 }; |
810 | 1162 |
811 | 1163 |
812 // Handle the trace command. | 1164 // Handle the trace command. |
813 DebugRequest.prototype.traceCommand_ = function(args) { | 1165 DebugRequest.prototype.traceCommand_ = function(args) { |
814 // Process arguments. | 1166 // Process arguments. |
815 if (args && args.length > 0) { | 1167 if (args && args.length > 0) { |
816 if (args == 'compile') { | 1168 if (args == 'compile') { |
817 trace_compile = !trace_compile; | 1169 trace_compile = !trace_compile; |
818 print('Tracing of compiled scripts ' + (trace_compile ? 'on' : 'off')); | 1170 print('Tracing of compiled scripts ' + (trace_compile ? 'on' : 'off')); |
| 1171 } else if (args === 'debug json' || args === 'json' || args === 'packets') { |
| 1172 trace_debug_json = !trace_debug_json; |
| 1173 print('Tracing of debug json packets ' + |
| 1174 (trace_debug_json ? 'on' : 'off')); |
819 } else { | 1175 } else { |
820 throw new Error('Invalid trace arguments.'); | 1176 throw new Error('Invalid trace arguments.'); |
821 } | 1177 } |
822 } else { | 1178 } else { |
823 throw new Error('Invalid trace arguments.'); | 1179 throw new Error('Invalid trace arguments.'); |
824 } | 1180 } |
825 } | 1181 } |
826 | 1182 |
827 // Handle the help command. | 1183 // Handle the help command. |
828 DebugRequest.prototype.helpCommand_ = function(args) { | 1184 DebugRequest.prototype.helpCommand_ = function(args) { |
829 // Help os quite simple. | 1185 // Help os quite simple. |
830 if (args && args.length > 0) { | 1186 if (args && args.length > 0) { |
831 print('warning: arguments to \'help\' are ignored'); | 1187 print('warning: arguments to \'help\' are ignored'); |
832 } | 1188 } |
833 | 1189 |
834 print('break'); | 1190 print('Note: <> denotes symbollic values to be replaced with real values.'); |
835 print('break location [condition]'); | 1191 print('Note: [] denotes optional parts of commands, or optional options / argu
ments.'); |
836 print(' break on named function: location is a function name'); | 1192 print(' e.g. d[elete] - you get the same command if you type d or delete.
'); |
837 print(' break on function: location is #<id>#'); | 1193 print(''); |
838 print(' break on script position: location is name:line[:column]'); | 1194 print('[break] - break as soon as possible'); |
839 print('clear <breakpoint #>'); | 1195 print('b[reak] location [condition]'); |
840 print('backtrace [n] | [-n] | [from to]'); | 1196 print(' - break on named function: location is a function name'); |
841 print('frame <frame #>'); | 1197 print(' - break on function: location is #<id>#'); |
| 1198 print(' - break on script position: location is name:line[:column]'); |
| 1199 print(''); |
| 1200 print('clear <breakpoint #> - deletes the specified user defined breakpo
int'); |
| 1201 print('d[elete] <breakpoint #> - deletes the specified user defined breakpo
int'); |
| 1202 print('dis[able] <breakpoint #> - disables the specified user defined breakp
oint'); |
| 1203 print('dis[able] exc[eptions] [[all] | unc[aught]]'); |
| 1204 print(' - disables breaking on exceptions'); |
| 1205 print('en[able] <breakpoint #> - enables the specified user defined breakpo
int'); |
| 1206 print('en[able] exc[eptions] [[all] | unc[aught]]'); |
| 1207 print(' - enables breaking on exceptions'); |
| 1208 print(''); |
| 1209 print('b[ack]t[race] [n] | [-n] | [from to]'); |
| 1210 print(' - prints the stack back trace'); |
| 1211 print('f[rame] - prints info about the current frame contex
t'); |
| 1212 print('f[rame] <frame #> - set context to specified frame #'); |
842 print('scopes'); | 1213 print('scopes'); |
843 print('scope <scope #>'); | 1214 print('scope <scope #>'); |
| 1215 print(''); |
| 1216 print('up - set context to caller of current frame'); |
| 1217 print('do[wn] - set context to callee of current frame'); |
| 1218 print('inf[o] br[eak] - prints info about breakpoints in use'); |
| 1219 print('inf[o] ar[gs] - prints info about arguments of the current
function'); |
| 1220 print('inf[o] lo[cals] - prints info about locals in the current fu
nction'); |
| 1221 print('inf[o] liveobjectlist|lol - same as \'lol info\''); |
| 1222 print(''); |
844 print('step [in | next | out| min [step count]]'); | 1223 print('step [in | next | out| min [step count]]'); |
845 print('print <expression>'); | 1224 print('c[ontinue] - continue executing after a breakpoint'); |
846 print('dir <expression>'); | 1225 print('s[tep] [<N>] - step into the next N callees (default N is
1)'); |
| 1226 print('s[tep]i [<N>] - step into the next N callees (default N is
1)'); |
| 1227 print('n[ext] [<N>] - step over the next N callees (default N is
1)'); |
| 1228 print('fin[ish] [<N>] - step out of N frames (default N is 1)'); |
| 1229 print(''); |
| 1230 print('p[rint] <expression> - prints the result of the specified express
ion'); |
| 1231 print('dir <expression> - prints the object structure of the result'
); |
| 1232 print('set <var> = <expression> - executes the specified statement'); |
| 1233 print(''); |
| 1234 print('l[ist] - list the source code around for the curren
t pc'); |
| 1235 print('l[ist] [- | <start>,<end>] - list the specified range of source code'); |
847 print('source [from line [num lines]]'); | 1236 print('source [from line [num lines]]'); |
848 print('scripts'); | 1237 print('scr[ipts] [native|extensions|all]'); |
849 print('continue'); | 1238 print('scr[ipts] [<filter text>] - list scripts with the specified text in it
s description'); |
| 1239 print(''); |
| 1240 print('gc - runs the garbage collector'); |
| 1241 print(''); |
850 print('trace compile'); | 1242 print('trace compile'); |
851 print('help'); | 1243 // hidden command: trace debug json - toggles tracing of debug json packets |
| 1244 print(''); |
| 1245 print('disconnect|exit|quit - disconnects and quits the debugger'); |
| 1246 print('help - prints this help information'); |
852 } | 1247 } |
853 | 1248 |
854 | 1249 |
855 function formatHandleReference_(value) { | 1250 function formatHandleReference_(value) { |
856 if (value.handle() >= 0) { | 1251 if (value.handle() >= 0) { |
857 return '#' + value.handle() + '#'; | 1252 return '#' + value.handle() + '#'; |
858 } else { | 1253 } else { |
859 return '#Transient#'; | 1254 return '#Transient#'; |
860 } | 1255 } |
861 } | 1256 } |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
923 case Debug.ScopeType.Closure: | 1318 case Debug.ScopeType.Closure: |
924 result += 'Closure'; | 1319 result += 'Closure'; |
925 break; | 1320 break; |
926 default: | 1321 default: |
927 result += 'UNKNOWN'; | 1322 result += 'UNKNOWN'; |
928 } | 1323 } |
929 return result; | 1324 return result; |
930 } | 1325 } |
931 | 1326 |
932 | 1327 |
| 1328 function refObjectToString_(protocolPackage, handle) { |
| 1329 var value = protocolPackage.lookup(handle); |
| 1330 var result = ''; |
| 1331 if (value.isString()) { |
| 1332 result = '"' + value.value() + '"'; |
| 1333 } else if (value.isPrimitive()) { |
| 1334 result = value.valueString(); |
| 1335 } else if (value.isObject()) { |
| 1336 result += formatObject_(value, true); |
| 1337 } |
| 1338 return result; |
| 1339 } |
| 1340 |
| 1341 |
| 1342 // Rounds number 'num' to 'length' decimal places. |
| 1343 function roundNumber(num, length) { |
| 1344 var factor = Math.pow(10, length); |
| 1345 return Math.round(num * factor) / factor; |
| 1346 } |
| 1347 |
| 1348 |
933 // Convert a JSON response to text for display in a text based debugger. | 1349 // Convert a JSON response to text for display in a text based debugger. |
934 function DebugResponseDetails(response) { | 1350 function DebugResponseDetails(response) { |
935 details = {text:'', running:false} | 1351 details = {text:'', running:false} |
936 | 1352 |
937 try { | 1353 try { |
938 if (!response.success()) { | 1354 if (!response.success()) { |
939 details.text = response.message(); | 1355 details.text = response.message(); |
940 return details; | 1356 return details; |
941 } | 1357 } |
942 | 1358 |
(...skipping 12 matching lines...) Expand all Loading... |
955 result += body.breakpoint; | 1371 result += body.breakpoint; |
956 details.text = result; | 1372 details.text = result; |
957 break; | 1373 break; |
958 | 1374 |
959 case 'clearbreakpoint': | 1375 case 'clearbreakpoint': |
960 result = 'cleared breakpoint #'; | 1376 result = 'cleared breakpoint #'; |
961 result += body.breakpoint; | 1377 result += body.breakpoint; |
962 details.text = result; | 1378 details.text = result; |
963 break; | 1379 break; |
964 | 1380 |
| 1381 case 'changebreakpoint': |
| 1382 result = 'successfully changed breakpoint'; |
| 1383 details.text = result; |
| 1384 break; |
| 1385 |
965 case 'listbreakpoints': | 1386 case 'listbreakpoints': |
966 result = 'breakpoints: (' + body.breakpoints.length + ')'; | 1387 result = 'breakpoints: (' + body.breakpoints.length + ')'; |
967 for (var i = 0; i < body.breakpoints.length; i++) { | 1388 for (var i = 0; i < body.breakpoints.length; i++) { |
968 var breakpoint = body.breakpoints[i]; | 1389 var breakpoint = body.breakpoints[i]; |
969 result += '\n id=' + breakpoint.number; | 1390 result += '\n id=' + breakpoint.number; |
970 result += ' type=' + breakpoint.type; | 1391 result += ' type=' + breakpoint.type; |
971 if (breakpoint.script_id) { | 1392 if (breakpoint.script_id) { |
972 result += ' script_id=' + breakpoint.script_id; | 1393 result += ' script_id=' + breakpoint.script_id; |
973 } | 1394 } |
974 if (breakpoint.script_name) { | 1395 if (breakpoint.script_name) { |
975 result += ' script_name=' + breakpoint.script_name; | 1396 result += ' script_name=' + breakpoint.script_name; |
976 } | 1397 } |
977 result += ' line=' + breakpoint.line; | 1398 result += ' line=' + (breakpoint.line + 1); |
978 if (breakpoint.column != null) { | 1399 if (breakpoint.column != null) { |
979 result += ' column=' + breakpoint.column; | 1400 result += ' column=' + (breakpoint.column + 1); |
980 } | 1401 } |
981 if (breakpoint.groupId) { | 1402 if (breakpoint.groupId) { |
982 result += ' groupId=' + breakpoint.groupId; | 1403 result += ' groupId=' + breakpoint.groupId; |
983 } | 1404 } |
984 if (breakpoint.ignoreCount) { | 1405 if (breakpoint.ignoreCount) { |
985 result += ' ignoreCount=' + breakpoint.ignoreCount; | 1406 result += ' ignoreCount=' + breakpoint.ignoreCount; |
986 } | 1407 } |
987 if (breakpoint.active === false) { | 1408 if (breakpoint.active === false) { |
988 result += ' inactive'; | 1409 result += ' inactive'; |
989 } | 1410 } |
990 if (breakpoint.condition) { | 1411 if (breakpoint.condition) { |
991 result += ' condition=' + breakpoint.condition; | 1412 result += ' condition=' + breakpoint.condition; |
992 } | 1413 } |
993 result += ' hit_count=' + breakpoint.hit_count; | 1414 result += ' hit_count=' + breakpoint.hit_count; |
994 } | 1415 } |
| 1416 if (body.breakpoints.length === 0) { |
| 1417 result = "No user defined breakpoints\n"; |
| 1418 } else { |
| 1419 result += '\n'; |
| 1420 } |
| 1421 if (body.breakOnExceptions) { |
| 1422 result += '* breaking on ALL exceptions is enabled\n'; |
| 1423 } else if (body.breakOnUncaughtExceptions) { |
| 1424 result += '* breaking on UNCAUGHT exceptions is enabled\n'; |
| 1425 } else { |
| 1426 result += '* all exception breakpoints are disabled\n'; |
| 1427 } |
| 1428 details.text = result; |
| 1429 break; |
| 1430 |
| 1431 case 'setexceptionbreak': |
| 1432 result = 'Break on ' + body.type + ' exceptions: '; |
| 1433 result += body.enabled ? 'enabled' : 'disabled'; |
995 details.text = result; | 1434 details.text = result; |
996 break; | 1435 break; |
997 | 1436 |
998 case 'backtrace': | 1437 case 'backtrace': |
999 if (body.totalFrames == 0) { | 1438 if (body.totalFrames == 0) { |
1000 result = '(empty stack)'; | 1439 result = '(empty stack)'; |
1001 } else { | 1440 } else { |
1002 var result = 'Frames #' + body.fromFrame + ' to #' + | 1441 var result = 'Frames #' + body.fromFrame + ' to #' + |
1003 (body.toFrame - 1) + ' of ' + body.totalFrames + '\n'; | 1442 (body.toFrame - 1) + ' of ' + body.totalFrames + '\n'; |
1004 for (i = 0; i < body.frames.length; i++) { | 1443 for (i = 0; i < body.frames.length; i++) { |
1005 if (i != 0) result += '\n'; | 1444 if (i != 0) result += '\n'; |
1006 result += body.frames[i].text; | 1445 result += body.frames[i].text; |
1007 } | 1446 } |
1008 } | 1447 } |
1009 details.text = result; | 1448 details.text = result; |
1010 break; | 1449 break; |
1011 | 1450 |
1012 case 'frame': | 1451 case 'frame': |
1013 details.text = SourceUnderline(body.sourceLineText, | 1452 if (last_cmd === 'info locals') { |
1014 body.column); | 1453 var locals = body.locals; |
1015 Debug.State.currentSourceLine = body.line; | 1454 if (locals.length === 0) { |
1016 Debug.State.currentFrame = body.index; | 1455 result = 'No locals'; |
| 1456 } else { |
| 1457 for (var i = 0; i < locals.length; i++) { |
| 1458 var local = locals[i]; |
| 1459 result += local.name + ' = '; |
| 1460 result += refObjectToString_(response, local.value.ref); |
| 1461 result += '\n'; |
| 1462 } |
| 1463 } |
| 1464 } else if (last_cmd === 'info args') { |
| 1465 var args = body.arguments; |
| 1466 if (args.length === 0) { |
| 1467 result = 'No arguments'; |
| 1468 } else { |
| 1469 for (var i = 0; i < args.length; i++) { |
| 1470 var arg = args[i]; |
| 1471 result += arg.name + ' = '; |
| 1472 result += refObjectToString_(response, arg.value.ref); |
| 1473 result += '\n'; |
| 1474 } |
| 1475 } |
| 1476 } else { |
| 1477 result = SourceUnderline(body.sourceLineText, |
| 1478 body.column); |
| 1479 Debug.State.currentSourceLine = body.line; |
| 1480 Debug.State.currentFrame = body.index; |
| 1481 Debug.State.displaySourceStartLine = -1; |
| 1482 Debug.State.displaySourceEndLine = -1; |
| 1483 } |
| 1484 details.text = result; |
1017 break; | 1485 break; |
1018 | 1486 |
1019 case 'scopes': | 1487 case 'scopes': |
1020 if (body.totalScopes == 0) { | 1488 if (body.totalScopes == 0) { |
1021 result = '(no scopes)'; | 1489 result = '(no scopes)'; |
1022 } else { | 1490 } else { |
1023 result = 'Scopes #' + body.fromScope + ' to #' + | 1491 result = 'Scopes #' + body.fromScope + ' to #' + |
1024 (body.toScope - 1) + ' of ' + body.totalScopes + '\n'; | 1492 (body.toScope - 1) + ' of ' + body.totalScopes + '\n'; |
1025 for (i = 0; i < body.scopes.length; i++) { | 1493 for (i = 0; i < body.scopes.length; i++) { |
1026 if (i != 0) { | 1494 if (i != 0) { |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1125 if (i != 0) result += '\n'; | 1593 if (i != 0) result += '\n'; |
1126 if (body[i].id) { | 1594 if (body[i].id) { |
1127 result += body[i].id; | 1595 result += body[i].id; |
1128 } else { | 1596 } else { |
1129 result += '[no id]'; | 1597 result += '[no id]'; |
1130 } | 1598 } |
1131 result += ', '; | 1599 result += ', '; |
1132 if (body[i].name) { | 1600 if (body[i].name) { |
1133 result += body[i].name; | 1601 result += body[i].name; |
1134 } else { | 1602 } else { |
1135 if (body[i].compilationType == Debug.ScriptCompilationType.Eval) { | 1603 if (body[i].compilationType == Debug.ScriptCompilationType.Eval |
| 1604 && body[i].evalFromScript |
| 1605 ) { |
1136 result += 'eval from '; | 1606 result += 'eval from '; |
1137 var script_value = response.lookup(body[i].evalFromScript.ref); | 1607 var script_value = response.lookup(body[i].evalFromScript.ref); |
1138 result += ' ' + script_value.field('name'); | 1608 result += ' ' + script_value.field('name'); |
1139 result += ':' + (body[i].evalFromLocation.line + 1); | 1609 result += ':' + (body[i].evalFromLocation.line + 1); |
1140 result += ':' + body[i].evalFromLocation.column; | 1610 result += ':' + body[i].evalFromLocation.column; |
1141 } else if (body[i].compilationType == | 1611 } else if (body[i].compilationType == |
1142 Debug.ScriptCompilationType.JSON) { | 1612 Debug.ScriptCompilationType.JSON) { |
1143 result += 'JSON '; | 1613 result += 'JSON '; |
1144 } else { // body[i].compilation == Debug.ScriptCompilationType.Host | 1614 } else { // body[i].compilation == Debug.ScriptCompilationType.Host |
1145 result += '[unnamed] '; | 1615 result += '[unnamed] '; |
1146 } | 1616 } |
1147 } | 1617 } |
1148 result += ' (lines: '; | 1618 result += ' (lines: '; |
1149 result += body[i].lineCount; | 1619 result += body[i].lineCount; |
1150 result += ', length: '; | 1620 result += ', length: '; |
1151 result += body[i].sourceLength; | 1621 result += body[i].sourceLength; |
1152 if (body[i].type == Debug.ScriptType.Native) { | 1622 if (body[i].type == Debug.ScriptType.Native) { |
1153 result += ', native'; | 1623 result += ', native'; |
1154 } else if (body[i].type == Debug.ScriptType.Extension) { | 1624 } else if (body[i].type == Debug.ScriptType.Extension) { |
1155 result += ', extension'; | 1625 result += ', extension'; |
1156 } | 1626 } |
1157 result += '), ['; | 1627 result += '), ['; |
1158 var sourceStart = body[i].sourceStart; | 1628 var sourceStart = body[i].sourceStart; |
1159 if (sourceStart.length > 40) { | 1629 if (sourceStart.length > 40) { |
1160 sourceStart = sourceStart.substring(0, 37) + '...'; | 1630 sourceStart = sourceStart.substring(0, 37) + '...'; |
1161 } | 1631 } |
1162 result += sourceStart; | 1632 result += sourceStart; |
1163 result += ']'; | 1633 result += ']'; |
1164 } | 1634 } |
| 1635 if (body.length == 0) { |
| 1636 result = "no matching scripts found"; |
| 1637 } |
1165 details.text = result; | 1638 details.text = result; |
1166 break; | 1639 break; |
1167 | 1640 |
1168 case 'threads': | 1641 case 'threads': |
1169 var result = 'Active V8 threads: ' + body.totalThreads + '\n'; | 1642 var result = 'Active V8 threads: ' + body.totalThreads + '\n'; |
1170 body.threads.sort(function(a, b) { return a.id - b.id; }); | 1643 body.threads.sort(function(a, b) { return a.id - b.id; }); |
1171 for (i = 0; i < body.threads.length; i++) { | 1644 for (i = 0; i < body.threads.length; i++) { |
1172 result += body.threads[i].current ? '*' : ' '; | 1645 result += body.threads[i].current ? '*' : ' '; |
1173 result += ' '; | 1646 result += ' '; |
1174 result += body.threads[i].id; | 1647 result += body.threads[i].id; |
1175 result += '\n'; | 1648 result += '\n'; |
1176 } | 1649 } |
1177 details.text = result; | 1650 details.text = result; |
1178 break; | 1651 break; |
1179 | 1652 |
1180 case 'continue': | 1653 case 'continue': |
1181 details.text = "(running)"; | 1654 details.text = "(running)"; |
1182 break; | 1655 break; |
1183 | 1656 |
| 1657 case 'v8flags': |
| 1658 details.text = "flags set"; |
| 1659 break; |
| 1660 |
| 1661 case 'gc': |
| 1662 details.text = "GC " + body.before + " => " + body.after; |
| 1663 if (body.after > (1024*1024)) { |
| 1664 details.text += |
| 1665 " (" + roundNumber(body.before/(1024*1024), 1) + "M => " + |
| 1666 roundNumber(body.after/(1024*1024), 1) + "M)"; |
| 1667 } else if (body.after > 1024) { |
| 1668 details.text += |
| 1669 " (" + roundNumber(body.before/1024, 1) + "K => " + |
| 1670 roundNumber(body.after/1024, 1) + "K)"; |
| 1671 } |
| 1672 break; |
| 1673 |
1184 default: | 1674 default: |
1185 details.text = | 1675 details.text = |
1186 'Response for unknown command \'' + response.command() + '\'' + | 1676 'Response for unknown command \'' + response.command() + '\'' + |
1187 ' (' + response.raw_json() + ')'; | 1677 ' (' + response.raw_json() + ')'; |
1188 } | 1678 } |
1189 } catch (e) { | 1679 } catch (e) { |
1190 details.text = 'Error: "' + e + '" formatting response'; | 1680 details.text = 'Error: "' + e + '" formatting response'; |
1191 } | 1681 } |
1192 | 1682 |
1193 return details; | 1683 return details; |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1460 | 1950 |
1461 /** | 1951 /** |
1462 * Check is the value is a string. | 1952 * Check is the value is a string. |
1463 * @return {boolean} true if the value is a string | 1953 * @return {boolean} true if the value is a string |
1464 */ | 1954 */ |
1465 ProtocolValue.prototype.value = function() { | 1955 ProtocolValue.prototype.value = function() { |
1466 return this.value_.value; | 1956 return this.value_.value; |
1467 } | 1957 } |
1468 | 1958 |
1469 | 1959 |
| 1960 ProtocolValue.prototype.valueString = function() { |
| 1961 return this.value_.text; |
| 1962 } |
| 1963 |
| 1964 |
1470 function ProtocolReference(handle) { | 1965 function ProtocolReference(handle) { |
1471 this.handle_ = handle; | 1966 this.handle_ = handle; |
1472 } | 1967 } |
1473 | 1968 |
1474 | 1969 |
1475 ProtocolReference.prototype.handle = function() { | 1970 ProtocolReference.prototype.handle = function() { |
1476 return this.handle_; | 1971 return this.handle_; |
1477 } | 1972 } |
1478 | 1973 |
1479 | 1974 |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1606 var content = []; | 2101 var content = []; |
1607 for (var key in object) { | 2102 for (var key in object) { |
1608 // Only consider string keys. | 2103 // Only consider string keys. |
1609 if (typeof key == 'string') { | 2104 if (typeof key == 'string') { |
1610 var property_value = object[key]; | 2105 var property_value = object[key]; |
1611 | 2106 |
1612 // Format the value based on its type. | 2107 // Format the value based on its type. |
1613 var property_value_json; | 2108 var property_value_json; |
1614 switch (typeof property_value) { | 2109 switch (typeof property_value) { |
1615 case 'object': | 2110 case 'object': |
1616 if (typeof property_value.toJSONProtocol == 'function') { | 2111 if (property_value === null) { |
| 2112 property_value_json = 'null'; |
| 2113 } else if (typeof property_value.toJSONProtocol == 'function') { |
1617 property_value_json = property_value.toJSONProtocol(true) | 2114 property_value_json = property_value.toJSONProtocol(true) |
1618 } else if (property_value.constructor.name == 'Array'){ | 2115 } else if (property_value.constructor.name == 'Array'){ |
1619 property_value_json = SimpleArrayToJSON_(property_value); | 2116 property_value_json = SimpleArrayToJSON_(property_value); |
1620 } else { | 2117 } else { |
1621 property_value_json = SimpleObjectToJSON_(property_value); | 2118 property_value_json = SimpleObjectToJSON_(property_value); |
1622 } | 2119 } |
1623 break; | 2120 break; |
1624 | 2121 |
1625 case 'boolean': | 2122 case 'boolean': |
1626 property_value_json = BooleanToJSON_(property_value); | 2123 property_value_json = BooleanToJSON_(property_value); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1674 json += NumberToJSON_(elem); | 2171 json += NumberToJSON_(elem); |
1675 } else if (typeof(elem) === 'string') { | 2172 } else if (typeof(elem) === 'string') { |
1676 json += StringToJSON_(elem); | 2173 json += StringToJSON_(elem); |
1677 } else { | 2174 } else { |
1678 json += elem; | 2175 json += elem; |
1679 } | 2176 } |
1680 } | 2177 } |
1681 json += ']'; | 2178 json += ']'; |
1682 return json; | 2179 return json; |
1683 } | 2180 } |
OLD | NEW |