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, | |
115 currentSourceLine: -1 | 113 currentSourceLine: -1 |
116 } | 114 } |
117 var trace_compile = false; // Tracing all compile events? | 115 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 } | |
127 | 116 |
128 | 117 |
129 // Process a debugger JSON message into a display text and a running status. | 118 // Process a debugger JSON message into a display text and a running status. |
130 // This function returns an object with properties "text" and "running" holding | 119 // This function returns an object with properties "text" and "running" holding |
131 // this information. | 120 // this information. |
132 function DebugMessageDetails(message) { | 121 function DebugMessageDetails(message) { |
133 if (trace_debug_json) { | |
134 print("received: '" + message + "'"); | |
135 } | |
136 // Convert the JSON string to an object. | 122 // Convert the JSON string to an object. |
137 var response = new ProtocolPackage(message); | 123 var response = new ProtocolPackage(message); |
138 is_running = response.running(); | |
139 | 124 |
140 if (response.type() == 'event') { | 125 if (response.type() == 'event') { |
141 return DebugEventDetails(response); | 126 return DebugEventDetails(response); |
142 } else { | 127 } else { |
143 return DebugResponseDetails(response); | 128 return DebugResponseDetails(response); |
144 } | 129 } |
145 } | 130 } |
146 | 131 |
147 function DebugEventDetails(response) { | 132 function DebugEventDetails(response) { |
148 details = {text:'', running:false} | 133 details = {text:'', running:false} |
(...skipping 20 matching lines...) Expand all Loading... |
169 } else { | 154 } else { |
170 result += 'break'; | 155 result += 'break'; |
171 } | 156 } |
172 result += ' in '; | 157 result += ' in '; |
173 result += body.invocationText; | 158 result += body.invocationText; |
174 result += ', '; | 159 result += ', '; |
175 result += SourceInfo(body); | 160 result += SourceInfo(body); |
176 result += '\n'; | 161 result += '\n'; |
177 result += SourceUnderline(body.sourceLineText, body.sourceColumn); | 162 result += SourceUnderline(body.sourceLineText, body.sourceColumn); |
178 Debug.State.currentSourceLine = body.sourceLine; | 163 Debug.State.currentSourceLine = body.sourceLine; |
179 Debug.State.displaySourceStartLine = -1; | |
180 Debug.State.displaySourceEndLine = -1; | |
181 Debug.State.currentFrame = 0; | 164 Debug.State.currentFrame = 0; |
182 details.text = result; | 165 details.text = result; |
183 break; | 166 break; |
184 | 167 |
185 case 'exception': | 168 case 'exception': |
186 if (body.uncaught) { | 169 if (body.uncaught) { |
187 result += 'Uncaught: '; | 170 result += 'Uncaught: '; |
188 } else { | 171 } else { |
189 result += 'Exception: '; | 172 result += 'Exception: '; |
190 } | 173 } |
191 result += '"'; | 174 result += '"'; |
192 result += body.exception.text; | 175 result += body.exception.text; |
193 result += '"'; | 176 result += '"'; |
194 if (body.sourceLine >= 0) { | 177 if (body.sourceLine >= 0) { |
195 result += ', '; | 178 result += ', '; |
196 result += SourceInfo(body); | 179 result += SourceInfo(body); |
197 result += '\n'; | 180 result += '\n'; |
198 result += SourceUnderline(body.sourceLineText, body.sourceColumn); | 181 result += SourceUnderline(body.sourceLineText, body.sourceColumn); |
199 Debug.State.currentSourceLine = body.sourceLine; | 182 Debug.State.currentSourceLine = body.sourceLine; |
200 Debug.State.displaySourceStartLine = -1; | |
201 Debug.State.displaySourceEndLine = -1; | |
202 Debug.State.currentFrame = 0; | 183 Debug.State.currentFrame = 0; |
203 } else { | 184 } else { |
204 result += ' (empty stack)'; | 185 result += ' (empty stack)'; |
205 Debug.State.currentSourceLine = -1; | 186 Debug.State.currentSourceLine = -1; |
206 Debug.State.displaySourceStartLine = -1; | |
207 Debug.State.displaySourceEndLine = -1; | |
208 Debug.State.currentFrame = kNoFrame; | 187 Debug.State.currentFrame = kNoFrame; |
209 } | 188 } |
210 details.text = result; | 189 details.text = result; |
211 break; | 190 break; |
212 | 191 |
213 case 'afterCompile': | 192 case 'afterCompile': |
214 if (trace_compile) { | 193 if (trace_compile) { |
215 result = 'Source ' + body.script.name + ' compiled:\n' | 194 result = 'Source ' + body.script.name + ' compiled:\n' |
216 var source = body.script.source; | 195 var source = body.script.source; |
217 if (!(source[source.length - 1] == '\n')) { | 196 if (!(source[source.length - 1] == '\n')) { |
218 result += source; | 197 result += source; |
219 } else { | 198 } else { |
220 result += source.substring(0, source.length - 1); | 199 result += source.substring(0, source.length - 1); |
221 } | 200 } |
222 } | 201 } |
223 details.text = result; | 202 details.text = result; |
224 break; | 203 break; |
225 | 204 |
226 case 'scriptCollected': | |
227 details.text = result; | |
228 break; | |
229 | |
230 default: | 205 default: |
231 details.text = 'Unknown debug event ' + response.event(); | 206 details.text = 'Unknown debug event ' + response.event(); |
232 } | 207 } |
233 | 208 |
234 return details; | 209 return details; |
235 }; | 210 }; |
236 | 211 |
237 | 212 |
238 function SourceInfo(body) { | 213 function SourceInfo(body) { |
239 var result = ''; | 214 var result = ''; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 } | 247 } |
273 underline += '^'; | 248 underline += '^'; |
274 | 249 |
275 // Return the source line text with the underline beneath. | 250 // Return the source line text with the underline beneath. |
276 return source_text + '\n' + underline; | 251 return source_text + '\n' + underline; |
277 }; | 252 }; |
278 | 253 |
279 | 254 |
280 // Converts a text command to a JSON request. | 255 // Converts a text command to a JSON request. |
281 function DebugCommandToJSONRequest(cmd_line) { | 256 function DebugCommandToJSONRequest(cmd_line) { |
282 var result = new DebugRequest(cmd_line).JSONRequest(); | 257 return new DebugRequest(cmd_line).JSONRequest(); |
283 if (trace_debug_json && result) { | |
284 print("sending: '" + result + "'"); | |
285 } | |
286 return result; | |
287 }; | 258 }; |
288 | 259 |
289 | 260 |
290 function DebugRequest(cmd_line) { | 261 function DebugRequest(cmd_line) { |
291 // If the very first character is a { assume that a JSON request have been | 262 // If the very first character is a { assume that a JSON request have been |
292 // entered as a command. Converting that to a JSON request is trivial. | 263 // entered as a command. Converting that to a JSON request is trivial. |
293 if (cmd_line && cmd_line.length > 0 && cmd_line.charAt(0) == '{') { | 264 if (cmd_line && cmd_line.length > 0 && cmd_line.charAt(0) == '{') { |
294 this.request_ = cmd_line; | 265 this.request_ = cmd_line; |
295 return; | 266 return; |
296 } | 267 } |
297 | 268 |
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 | |
312 // Trim string for leading and trailing whitespace. | 269 // Trim string for leading and trailing whitespace. |
313 cmd_line = cmd_line.replace(/^\s+|\s+$/g, ''); | 270 cmd_line = cmd_line.replace(/^\s+|\s+$/g, ''); |
314 | 271 |
315 // Find the command. | 272 // Find the command. |
316 var pos = cmd_line.indexOf(' '); | 273 var pos = cmd_line.indexOf(' '); |
317 var cmd; | 274 var cmd; |
318 var args; | 275 var args; |
319 if (pos == -1) { | 276 if (pos == -1) { |
320 cmd = cmd_line; | 277 cmd = cmd_line; |
321 args = ''; | 278 args = ''; |
322 } else { | 279 } else { |
323 cmd = cmd_line.slice(0, pos); | 280 cmd = cmd_line.slice(0, pos); |
324 args = cmd_line.slice(pos).replace(/^\s+|\s+$/g, ''); | 281 args = cmd_line.slice(pos).replace(/^\s+|\s+$/g, ''); |
325 } | 282 } |
326 | 283 |
327 if ((cmd === undefined) || !cmd) { | |
328 this.request_ = void 0; | |
329 return; | |
330 } | |
331 | |
332 last_cmd = cmd; | |
333 | |
334 // Switch on command. | 284 // Switch on command. |
335 switch (cmd) { | 285 switch (cmd) { |
336 case 'continue': | 286 case 'continue': |
337 case 'c': | 287 case 'c': |
338 this.request_ = this.continueCommandToJSONRequest_(args); | 288 this.request_ = this.continueCommandToJSONRequest_(args); |
339 break; | 289 break; |
340 | 290 |
341 case 'step': | 291 case 'step': |
342 case 's': | 292 case 's': |
343 this.request_ = this.stepCommandToJSONRequest_(args, 'in'); | 293 this.request_ = this.stepCommandToJSONRequest_(args); |
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'); | |
359 break; | 294 break; |
360 | 295 |
361 case 'backtrace': | 296 case 'backtrace': |
362 case 'bt': | 297 case 'bt': |
363 this.request_ = this.backtraceCommandToJSONRequest_(args); | 298 this.request_ = this.backtraceCommandToJSONRequest_(args); |
364 break; | 299 break; |
365 | 300 |
366 case 'frame': | 301 case 'frame': |
367 case 'f': | 302 case 'f': |
368 this.request_ = this.frameCommandToJSONRequest_(args); | 303 this.request_ = this.frameCommandToJSONRequest_(args); |
369 break; | 304 break; |
370 | 305 |
371 case 'scopes': | 306 case 'scopes': |
372 this.request_ = this.scopesCommandToJSONRequest_(args); | 307 this.request_ = this.scopesCommandToJSONRequest_(args); |
373 break; | 308 break; |
374 | 309 |
375 case 'scope': | 310 case 'scope': |
376 this.request_ = this.scopeCommandToJSONRequest_(args); | 311 this.request_ = this.scopeCommandToJSONRequest_(args); |
377 break; | 312 break; |
378 | 313 |
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': | |
399 case 'print': | 314 case 'print': |
400 case 'p': | 315 case 'p': |
401 this.request_ = this.printCommandToJSONRequest_(args); | 316 this.request_ = this.printCommandToJSONRequest_(args); |
402 break; | 317 break; |
403 | 318 |
404 case 'dir': | 319 case 'dir': |
405 this.request_ = this.dirCommandToJSONRequest_(args); | 320 this.request_ = this.dirCommandToJSONRequest_(args); |
406 break; | 321 break; |
407 | 322 |
408 case 'references': | 323 case 'references': |
409 this.request_ = this.referencesCommandToJSONRequest_(args); | 324 this.request_ = this.referencesCommandToJSONRequest_(args); |
410 break; | 325 break; |
411 | 326 |
412 case 'instances': | 327 case 'instances': |
413 this.request_ = this.instancesCommandToJSONRequest_(args); | 328 this.request_ = this.instancesCommandToJSONRequest_(args); |
414 break; | 329 break; |
415 | 330 |
416 case 'list': | |
417 case 'l': | |
418 this.request_ = this.listCommandToJSONRequest_(args); | |
419 break; | |
420 case 'source': | 331 case 'source': |
421 this.request_ = this.sourceCommandToJSONRequest_(args); | 332 this.request_ = this.sourceCommandToJSONRequest_(args); |
422 break; | 333 break; |
423 | 334 |
424 case 'scripts': | 335 case 'scripts': |
425 case 'script': | |
426 case 'scr': | |
427 this.request_ = this.scriptsCommandToJSONRequest_(args); | 336 this.request_ = this.scriptsCommandToJSONRequest_(args); |
428 break; | 337 break; |
429 | 338 |
430 case 'break': | 339 case 'break': |
431 case 'b': | 340 case 'b': |
432 this.request_ = this.breakCommandToJSONRequest_(args); | 341 this.request_ = this.breakCommandToJSONRequest_(args); |
433 break; | 342 break; |
434 | 343 |
435 case 'breakpoints': | 344 case 'breakpoints': |
436 case 'bb': | 345 case 'bb': |
437 this.request_ = this.breakpointsCommandToJSONRequest_(args); | 346 this.request_ = this.breakpointsCommandToJSONRequest_(args); |
438 break; | 347 break; |
439 | 348 |
440 case 'clear': | 349 case 'clear': |
441 case 'delete': | |
442 case 'd': | |
443 this.request_ = this.clearCommandToJSONRequest_(args); | 350 this.request_ = this.clearCommandToJSONRequest_(args); |
444 break; | 351 break; |
445 | 352 |
446 case 'threads': | 353 case 'threads': |
447 this.request_ = this.threadsCommandToJSONRequest_(args); | 354 this.request_ = this.threadsCommandToJSONRequest_(args); |
448 break; | 355 break; |
449 | 356 |
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 | |
484 case 'trace': | 357 case 'trace': |
485 case 'tr': | |
486 // Return undefined to indicate command handled internally (no JSON). | 358 // Return undefined to indicate command handled internally (no JSON). |
487 this.request_ = void 0; | 359 this.request_ = void 0; |
488 this.traceCommand_(args); | 360 this.traceCommand_(args); |
489 break; | 361 break; |
490 | 362 |
491 case 'help': | 363 case 'help': |
492 case '?': | 364 case '?': |
493 this.helpCommand_(args); | 365 this.helpCommand_(args); |
494 // Return undefined to indicate command handled internally (no JSON). | 366 // Return undefined to indicate command handled internally (no JSON). |
495 this.request_ = void 0; | 367 this.request_ = void 0; |
496 break; | 368 break; |
497 | 369 |
498 default: | 370 default: |
499 throw new Error('Unknown command "' + cmd + '"'); | 371 throw new Error('Unknown command "' + cmd + '"'); |
500 } | 372 } |
| 373 |
| 374 last_cmd = cmd; |
501 } | 375 } |
502 | 376 |
503 DebugRequest.prototype.JSONRequest = function() { | 377 DebugRequest.prototype.JSONRequest = function() { |
504 return this.request_; | 378 return this.request_; |
505 } | 379 } |
506 | 380 |
507 | 381 |
508 function RequestPacket(command) { | 382 function RequestPacket(command) { |
509 this.seq = 0; | 383 this.seq = 0; |
510 this.type = 'request'; | 384 this.type = 'request'; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
584 | 458 |
585 | 459 |
586 // Create a JSON request for the continue command. | 460 // Create a JSON request for the continue command. |
587 DebugRequest.prototype.continueCommandToJSONRequest_ = function(args) { | 461 DebugRequest.prototype.continueCommandToJSONRequest_ = function(args) { |
588 var request = this.createRequest('continue'); | 462 var request = this.createRequest('continue'); |
589 return request.toJSONProtocol(); | 463 return request.toJSONProtocol(); |
590 }; | 464 }; |
591 | 465 |
592 | 466 |
593 // Create a JSON request for the step command. | 467 // Create a JSON request for the step command. |
594 DebugRequest.prototype.stepCommandToJSONRequest_ = function(args, type) { | 468 DebugRequest.prototype.stepCommandToJSONRequest_ = function(args) { |
595 // Requesting a step is through the continue command with additional | 469 // Requesting a step is through the continue command with additional |
596 // arguments. | 470 // arguments. |
597 var request = this.createRequest('continue'); | 471 var request = this.createRequest('continue'); |
598 request.arguments = {}; | 472 request.arguments = {}; |
599 | 473 |
600 // Process arguments if any. | 474 // 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. | |
604 if (args && args.length > 0) { | 475 if (args && args.length > 0) { |
605 args = args.split(/\s+/g); | 476 args = args.split(/\s*[ ]+\s*/g); |
606 | 477 |
607 if (args.length > 2) { | 478 if (args.length > 2) { |
608 throw new Error('Invalid step arguments.'); | 479 throw new Error('Invalid step arguments.'); |
609 } | 480 } |
610 | 481 |
611 if (args.length > 0) { | 482 if (args.length > 0) { |
612 // Check if we have a gdb stype step command. If so, the 1st arg would | 483 // Get step count argument if any. |
613 // be the step count. If it's not a number, then assume that we're | 484 if (args.length == 2) { |
614 // parsing for the legacy v8 step command. | 485 var stepcount = parseInt(args[1]); |
615 var stepcount = Number(args[0]); | 486 if (isNaN(stepcount) || stepcount <= 0) { |
616 if (stepcount == Number.NaN) { | 487 throw new Error('Invalid step count argument "' + args[0] + '".'); |
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; | |
624 } | 488 } |
| 489 request.arguments.stepcount = stepcount; |
| 490 } |
625 | 491 |
626 // Get the step action. | 492 // Get the step action. |
627 switch (args[0]) { | 493 switch (args[0]) { |
628 case 'in': | 494 case 'in': |
629 case 'i': | 495 case 'i': |
630 request.arguments.stepaction = 'in'; | 496 request.arguments.stepaction = 'in'; |
631 break; | 497 break; |
632 | 498 |
633 case 'min': | 499 case 'min': |
634 case 'm': | 500 case 'm': |
635 request.arguments.stepaction = 'min'; | 501 request.arguments.stepaction = 'min'; |
636 break; | 502 break; |
637 | 503 |
638 case 'next': | 504 case 'next': |
639 case 'n': | 505 case 'n': |
640 request.arguments.stepaction = 'next'; | 506 request.arguments.stepaction = 'next'; |
641 break; | 507 break; |
642 | 508 |
643 case 'out': | 509 case 'out': |
644 case 'o': | 510 case 'o': |
645 request.arguments.stepaction = 'out'; | 511 request.arguments.stepaction = 'out'; |
646 break; | 512 break; |
647 | 513 |
648 default: | 514 default: |
649 throw new Error('Invalid step argument "' + args[0] + '".'); | 515 throw new Error('Invalid step argument "' + args[0] + '".'); |
650 } | |
651 | |
652 } else { | |
653 // gdb style step commands: | |
654 request.arguments.stepaction = type; | |
655 request.arguments.stepcount = stepcount; | |
656 } | 516 } |
657 } | 517 } |
658 } else { | 518 } else { |
659 // Default is step of the specified type. | 519 // Default is step next. |
660 request.arguments.stepaction = type; | 520 request.arguments.stepaction = 'next'; |
661 } | 521 } |
662 | 522 |
663 return request.toJSONProtocol(); | 523 return request.toJSONProtocol(); |
664 }; | 524 }; |
665 | 525 |
666 | 526 |
667 // Create a JSON request for the backtrace command. | 527 // Create a JSON request for the backtrace command. |
668 DebugRequest.prototype.backtraceCommandToJSONRequest_ = function(args) { | 528 DebugRequest.prototype.backtraceCommandToJSONRequest_ = function(args) { |
669 // Build a backtrace request from the text command. | 529 // Build a backtrace request from the text command. |
670 var request = this.createRequest('backtrace'); | 530 var request = this.createRequest('backtrace'); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
781 // Build an evaluate request from the text command. | 641 // Build an evaluate request from the text command. |
782 if (args.length == 0) { | 642 if (args.length == 0) { |
783 throw new Error('Missing object id.'); | 643 throw new Error('Missing object id.'); |
784 } | 644 } |
785 | 645 |
786 // Build a references request. | 646 // Build a references request. |
787 return this.makeReferencesJSONRequest_(args, 'constructedBy'); | 647 return this.makeReferencesJSONRequest_(args, 'constructedBy'); |
788 }; | 648 }; |
789 | 649 |
790 | 650 |
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 | |
826 // Create a JSON request for the source command. | 651 // Create a JSON request for the source command. |
827 DebugRequest.prototype.sourceCommandToJSONRequest_ = function(args) { | 652 DebugRequest.prototype.sourceCommandToJSONRequest_ = function(args) { |
828 // Build a evaluate request from the text command. | 653 // Build a evaluate request from the text command. |
829 var request = this.createRequest('source'); | 654 var request = this.createRequest('source'); |
830 | 655 |
831 // Default is ten lines starting five lines before the current location. | 656 // Default is ten lines starting five lines before the current location. |
832 var from = Debug.State.currentSourceLine - 5; | 657 var from = Debug.State.currentSourceLine - 5; |
833 var lines = 10; | 658 var lines = 10; |
834 | 659 |
835 // Parse the arguments. | 660 // Parse the arguments. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
877 break; | 702 break; |
878 | 703 |
879 case 'all': | 704 case 'all': |
880 request.arguments.types = | 705 request.arguments.types = |
881 ScriptTypeFlag(Debug.ScriptType.Normal) | | 706 ScriptTypeFlag(Debug.ScriptType.Normal) | |
882 ScriptTypeFlag(Debug.ScriptType.Native) | | 707 ScriptTypeFlag(Debug.ScriptType.Native) | |
883 ScriptTypeFlag(Debug.ScriptType.Extension); | 708 ScriptTypeFlag(Debug.ScriptType.Extension); |
884 break; | 709 break; |
885 | 710 |
886 default: | 711 default: |
887 // If the arg is not one of the know one aboves, then it must be a | 712 throw new Error('Invalid argument "' + args[0] + '".'); |
888 // filter used for filtering the results: | |
889 request.arguments.filter = args[0]; | |
890 break; | |
891 } | 713 } |
892 } | 714 } |
893 | 715 |
894 return request.toJSONProtocol(); | 716 return request.toJSONProtocol(); |
895 }; | 717 }; |
896 | 718 |
897 | 719 |
898 // Create a JSON request for the break command. | 720 // Create a JSON request for the break command. |
899 DebugRequest.prototype.breakCommandToJSONRequest_ = function(args) { | 721 DebugRequest.prototype.breakCommandToJSONRequest_ = function(args) { |
900 // Build a evaluate request from the text command. | 722 // Build a evaluate request from the text command. |
901 // Process arguments if any. | 723 // Process arguments if any. |
902 if (args && args.length > 0) { | 724 if (args && args.length > 0) { |
903 var target = args; | 725 var target = args; |
904 var type = 'function'; | 726 var type = 'function'; |
905 var line; | 727 var line; |
906 var column; | 728 var column; |
907 var condition; | 729 var condition; |
908 var pos; | 730 var pos; |
909 | 731 |
910 var request = this.createRequest('setbreakpoint'); | 732 var request = this.createRequest('setbreakpoint'); |
911 | 733 |
912 // Break the args into target spec and condition if appropriate. | |
913 | |
914 // Check for breakpoint condition. | 734 // Check for breakpoint condition. |
915 pos = args.indexOf(' '); | 735 pos = args.indexOf(' '); |
916 if (pos > 0) { | 736 if (pos > 0) { |
917 target = args.substring(0, pos); | 737 target = args.substring(0, pos); |
918 condition = args.substring(pos + 1, args.length); | 738 condition = args.substring(pos + 1, args.length); |
919 } | 739 } |
920 | 740 |
921 // Check for script breakpoint (name:line[:column]). If no ':' in break | 741 // Check for script breakpoint (name:line[:column]). If no ':' in break |
922 // specification it is considered a function break point. | 742 // specification it is considered a function break point. |
923 pos = target.indexOf(':'); | 743 pos = target.indexOf(':'); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
974 request.arguments = {}; | 794 request.arguments = {}; |
975 request.arguments.breakpoint = parseInt(args); | 795 request.arguments.breakpoint = parseInt(args); |
976 } else { | 796 } else { |
977 throw new Error('Invalid break arguments.'); | 797 throw new Error('Invalid break arguments.'); |
978 } | 798 } |
979 | 799 |
980 return request.toJSONProtocol(); | 800 return request.toJSONProtocol(); |
981 }; | 801 }; |
982 | 802 |
983 | 803 |
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 | |
1156 // Create a JSON request for the threads command. | 804 // Create a JSON request for the threads command. |
1157 DebugRequest.prototype.threadsCommandToJSONRequest_ = function(args) { | 805 DebugRequest.prototype.threadsCommandToJSONRequest_ = function(args) { |
1158 // Build a threads request from the text command. | 806 // Build a threads request from the text command. |
1159 var request = this.createRequest('threads'); | 807 var request = this.createRequest('threads'); |
1160 return request.toJSONProtocol(); | 808 return request.toJSONProtocol(); |
1161 }; | 809 }; |
1162 | 810 |
1163 | 811 |
1164 // Handle the trace command. | 812 // Handle the trace command. |
1165 DebugRequest.prototype.traceCommand_ = function(args) { | 813 DebugRequest.prototype.traceCommand_ = function(args) { |
1166 // Process arguments. | 814 // Process arguments. |
1167 if (args && args.length > 0) { | 815 if (args && args.length > 0) { |
1168 if (args == 'compile') { | 816 if (args == 'compile') { |
1169 trace_compile = !trace_compile; | 817 trace_compile = !trace_compile; |
1170 print('Tracing of compiled scripts ' + (trace_compile ? 'on' : 'off')); | 818 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')); | |
1175 } else { | 819 } else { |
1176 throw new Error('Invalid trace arguments.'); | 820 throw new Error('Invalid trace arguments.'); |
1177 } | 821 } |
1178 } else { | 822 } else { |
1179 throw new Error('Invalid trace arguments.'); | 823 throw new Error('Invalid trace arguments.'); |
1180 } | 824 } |
1181 } | 825 } |
1182 | 826 |
1183 // Handle the help command. | 827 // Handle the help command. |
1184 DebugRequest.prototype.helpCommand_ = function(args) { | 828 DebugRequest.prototype.helpCommand_ = function(args) { |
1185 // Help os quite simple. | 829 // Help os quite simple. |
1186 if (args && args.length > 0) { | 830 if (args && args.length > 0) { |
1187 print('warning: arguments to \'help\' are ignored'); | 831 print('warning: arguments to \'help\' are ignored'); |
1188 } | 832 } |
1189 | 833 |
1190 print('Note: <> denotes symbollic values to be replaced with real values.'); | 834 print('break'); |
1191 print('Note: [] denotes optional parts of commands, or optional options / argu
ments.'); | 835 print('break location [condition]'); |
1192 print(' e.g. d[elete] - you get the same command if you type d or delete.
'); | 836 print(' break on named function: location is a function name'); |
1193 print(''); | 837 print(' break on function: location is #<id>#'); |
1194 print('[break] - break as soon as possible'); | 838 print(' break on script position: location is name:line[:column]'); |
1195 print('b[reak] location [condition]'); | 839 print('clear <breakpoint #>'); |
1196 print(' - break on named function: location is a function name'); | 840 print('backtrace [n] | [-n] | [from to]'); |
1197 print(' - break on function: location is #<id>#'); | 841 print('frame <frame #>'); |
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 #'); | |
1213 print('scopes'); | 842 print('scopes'); |
1214 print('scope <scope #>'); | 843 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(''); | |
1223 print('step [in | next | out| min [step count]]'); | 844 print('step [in | next | out| min [step count]]'); |
1224 print('c[ontinue] - continue executing after a breakpoint'); | 845 print('print <expression>'); |
1225 print('s[tep] [<N>] - step into the next N callees (default N is
1)'); | 846 print('dir <expression>'); |
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'); | |
1236 print('source [from line [num lines]]'); | 847 print('source [from line [num lines]]'); |
1237 print('scr[ipts] [native|extensions|all]'); | 848 print('scripts'); |
1238 print('scr[ipts] [<filter text>] - list scripts with the specified text in it
s description'); | 849 print('continue'); |
1239 print(''); | |
1240 print('gc - runs the garbage collector'); | |
1241 print(''); | |
1242 print('trace compile'); | 850 print('trace compile'); |
1243 // hidden command: trace debug json - toggles tracing of debug json packets | 851 print('help'); |
1244 print(''); | |
1245 print('disconnect|exit|quit - disconnects and quits the debugger'); | |
1246 print('help - prints this help information'); | |
1247 } | 852 } |
1248 | 853 |
1249 | 854 |
1250 function formatHandleReference_(value) { | 855 function formatHandleReference_(value) { |
1251 if (value.handle() >= 0) { | 856 if (value.handle() >= 0) { |
1252 return '#' + value.handle() + '#'; | 857 return '#' + value.handle() + '#'; |
1253 } else { | 858 } else { |
1254 return '#Transient#'; | 859 return '#Transient#'; |
1255 } | 860 } |
1256 } | 861 } |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1318 case Debug.ScopeType.Closure: | 923 case Debug.ScopeType.Closure: |
1319 result += 'Closure'; | 924 result += 'Closure'; |
1320 break; | 925 break; |
1321 default: | 926 default: |
1322 result += 'UNKNOWN'; | 927 result += 'UNKNOWN'; |
1323 } | 928 } |
1324 return result; | 929 return result; |
1325 } | 930 } |
1326 | 931 |
1327 | 932 |
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 | |
1349 // Convert a JSON response to text for display in a text based debugger. | 933 // Convert a JSON response to text for display in a text based debugger. |
1350 function DebugResponseDetails(response) { | 934 function DebugResponseDetails(response) { |
1351 details = {text:'', running:false} | 935 details = {text:'', running:false} |
1352 | 936 |
1353 try { | 937 try { |
1354 if (!response.success()) { | 938 if (!response.success()) { |
1355 details.text = response.message(); | 939 details.text = response.message(); |
1356 return details; | 940 return details; |
1357 } | 941 } |
1358 | 942 |
(...skipping 12 matching lines...) Expand all Loading... |
1371 result += body.breakpoint; | 955 result += body.breakpoint; |
1372 details.text = result; | 956 details.text = result; |
1373 break; | 957 break; |
1374 | 958 |
1375 case 'clearbreakpoint': | 959 case 'clearbreakpoint': |
1376 result = 'cleared breakpoint #'; | 960 result = 'cleared breakpoint #'; |
1377 result += body.breakpoint; | 961 result += body.breakpoint; |
1378 details.text = result; | 962 details.text = result; |
1379 break; | 963 break; |
1380 | 964 |
1381 case 'changebreakpoint': | |
1382 result = 'successfully changed breakpoint'; | |
1383 details.text = result; | |
1384 break; | |
1385 | |
1386 case 'listbreakpoints': | 965 case 'listbreakpoints': |
1387 result = 'breakpoints: (' + body.breakpoints.length + ')'; | 966 result = 'breakpoints: (' + body.breakpoints.length + ')'; |
1388 for (var i = 0; i < body.breakpoints.length; i++) { | 967 for (var i = 0; i < body.breakpoints.length; i++) { |
1389 var breakpoint = body.breakpoints[i]; | 968 var breakpoint = body.breakpoints[i]; |
1390 result += '\n id=' + breakpoint.number; | 969 result += '\n id=' + breakpoint.number; |
1391 result += ' type=' + breakpoint.type; | 970 result += ' type=' + breakpoint.type; |
1392 if (breakpoint.script_id) { | 971 if (breakpoint.script_id) { |
1393 result += ' script_id=' + breakpoint.script_id; | 972 result += ' script_id=' + breakpoint.script_id; |
1394 } | 973 } |
1395 if (breakpoint.script_name) { | 974 if (breakpoint.script_name) { |
1396 result += ' script_name=' + breakpoint.script_name; | 975 result += ' script_name=' + breakpoint.script_name; |
1397 } | 976 } |
1398 result += ' line=' + (breakpoint.line + 1); | 977 result += ' line=' + breakpoint.line; |
1399 if (breakpoint.column != null) { | 978 if (breakpoint.column != null) { |
1400 result += ' column=' + (breakpoint.column + 1); | 979 result += ' column=' + breakpoint.column; |
1401 } | 980 } |
1402 if (breakpoint.groupId) { | 981 if (breakpoint.groupId) { |
1403 result += ' groupId=' + breakpoint.groupId; | 982 result += ' groupId=' + breakpoint.groupId; |
1404 } | 983 } |
1405 if (breakpoint.ignoreCount) { | 984 if (breakpoint.ignoreCount) { |
1406 result += ' ignoreCount=' + breakpoint.ignoreCount; | 985 result += ' ignoreCount=' + breakpoint.ignoreCount; |
1407 } | 986 } |
1408 if (breakpoint.active === false) { | 987 if (breakpoint.active === false) { |
1409 result += ' inactive'; | 988 result += ' inactive'; |
1410 } | 989 } |
1411 if (breakpoint.condition) { | 990 if (breakpoint.condition) { |
1412 result += ' condition=' + breakpoint.condition; | 991 result += ' condition=' + breakpoint.condition; |
1413 } | 992 } |
1414 result += ' hit_count=' + breakpoint.hit_count; | 993 result += ' hit_count=' + breakpoint.hit_count; |
1415 } | 994 } |
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'; | |
1434 details.text = result; | 995 details.text = result; |
1435 break; | 996 break; |
1436 | 997 |
1437 case 'backtrace': | 998 case 'backtrace': |
1438 if (body.totalFrames == 0) { | 999 if (body.totalFrames == 0) { |
1439 result = '(empty stack)'; | 1000 result = '(empty stack)'; |
1440 } else { | 1001 } else { |
1441 var result = 'Frames #' + body.fromFrame + ' to #' + | 1002 var result = 'Frames #' + body.fromFrame + ' to #' + |
1442 (body.toFrame - 1) + ' of ' + body.totalFrames + '\n'; | 1003 (body.toFrame - 1) + ' of ' + body.totalFrames + '\n'; |
1443 for (i = 0; i < body.frames.length; i++) { | 1004 for (i = 0; i < body.frames.length; i++) { |
1444 if (i != 0) result += '\n'; | 1005 if (i != 0) result += '\n'; |
1445 result += body.frames[i].text; | 1006 result += body.frames[i].text; |
1446 } | 1007 } |
1447 } | 1008 } |
1448 details.text = result; | 1009 details.text = result; |
1449 break; | 1010 break; |
1450 | 1011 |
1451 case 'frame': | 1012 case 'frame': |
1452 if (last_cmd === 'info locals') { | 1013 details.text = SourceUnderline(body.sourceLineText, |
1453 var locals = body.locals; | 1014 body.column); |
1454 if (locals.length === 0) { | 1015 Debug.State.currentSourceLine = body.line; |
1455 result = 'No locals'; | 1016 Debug.State.currentFrame = body.index; |
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; | |
1485 break; | 1017 break; |
1486 | 1018 |
1487 case 'scopes': | 1019 case 'scopes': |
1488 if (body.totalScopes == 0) { | 1020 if (body.totalScopes == 0) { |
1489 result = '(no scopes)'; | 1021 result = '(no scopes)'; |
1490 } else { | 1022 } else { |
1491 result = 'Scopes #' + body.fromScope + ' to #' + | 1023 result = 'Scopes #' + body.fromScope + ' to #' + |
1492 (body.toScope - 1) + ' of ' + body.totalScopes + '\n'; | 1024 (body.toScope - 1) + ' of ' + body.totalScopes + '\n'; |
1493 for (i = 0; i < body.scopes.length; i++) { | 1025 for (i = 0; i < body.scopes.length; i++) { |
1494 if (i != 0) { | 1026 if (i != 0) { |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1593 if (i != 0) result += '\n'; | 1125 if (i != 0) result += '\n'; |
1594 if (body[i].id) { | 1126 if (body[i].id) { |
1595 result += body[i].id; | 1127 result += body[i].id; |
1596 } else { | 1128 } else { |
1597 result += '[no id]'; | 1129 result += '[no id]'; |
1598 } | 1130 } |
1599 result += ', '; | 1131 result += ', '; |
1600 if (body[i].name) { | 1132 if (body[i].name) { |
1601 result += body[i].name; | 1133 result += body[i].name; |
1602 } else { | 1134 } else { |
1603 if (body[i].compilationType == Debug.ScriptCompilationType.Eval | 1135 if (body[i].compilationType == Debug.ScriptCompilationType.Eval) { |
1604 && body[i].evalFromScript | |
1605 ) { | |
1606 result += 'eval from '; | 1136 result += 'eval from '; |
1607 var script_value = response.lookup(body[i].evalFromScript.ref); | 1137 var script_value = response.lookup(body[i].evalFromScript.ref); |
1608 result += ' ' + script_value.field('name'); | 1138 result += ' ' + script_value.field('name'); |
1609 result += ':' + (body[i].evalFromLocation.line + 1); | 1139 result += ':' + (body[i].evalFromLocation.line + 1); |
1610 result += ':' + body[i].evalFromLocation.column; | 1140 result += ':' + body[i].evalFromLocation.column; |
1611 } else if (body[i].compilationType == | 1141 } else if (body[i].compilationType == |
1612 Debug.ScriptCompilationType.JSON) { | 1142 Debug.ScriptCompilationType.JSON) { |
1613 result += 'JSON '; | 1143 result += 'JSON '; |
1614 } else { // body[i].compilation == Debug.ScriptCompilationType.Host | 1144 } else { // body[i].compilation == Debug.ScriptCompilationType.Host |
1615 result += '[unnamed] '; | 1145 result += '[unnamed] '; |
1616 } | 1146 } |
1617 } | 1147 } |
1618 result += ' (lines: '; | 1148 result += ' (lines: '; |
1619 result += body[i].lineCount; | 1149 result += body[i].lineCount; |
1620 result += ', length: '; | 1150 result += ', length: '; |
1621 result += body[i].sourceLength; | 1151 result += body[i].sourceLength; |
1622 if (body[i].type == Debug.ScriptType.Native) { | 1152 if (body[i].type == Debug.ScriptType.Native) { |
1623 result += ', native'; | 1153 result += ', native'; |
1624 } else if (body[i].type == Debug.ScriptType.Extension) { | 1154 } else if (body[i].type == Debug.ScriptType.Extension) { |
1625 result += ', extension'; | 1155 result += ', extension'; |
1626 } | 1156 } |
1627 result += '), ['; | 1157 result += '), ['; |
1628 var sourceStart = body[i].sourceStart; | 1158 var sourceStart = body[i].sourceStart; |
1629 if (sourceStart.length > 40) { | 1159 if (sourceStart.length > 40) { |
1630 sourceStart = sourceStart.substring(0, 37) + '...'; | 1160 sourceStart = sourceStart.substring(0, 37) + '...'; |
1631 } | 1161 } |
1632 result += sourceStart; | 1162 result += sourceStart; |
1633 result += ']'; | 1163 result += ']'; |
1634 } | 1164 } |
1635 if (body.length == 0) { | |
1636 result = "no matching scripts found"; | |
1637 } | |
1638 details.text = result; | 1165 details.text = result; |
1639 break; | 1166 break; |
1640 | 1167 |
1641 case 'threads': | 1168 case 'threads': |
1642 var result = 'Active V8 threads: ' + body.totalThreads + '\n'; | 1169 var result = 'Active V8 threads: ' + body.totalThreads + '\n'; |
1643 body.threads.sort(function(a, b) { return a.id - b.id; }); | 1170 body.threads.sort(function(a, b) { return a.id - b.id; }); |
1644 for (i = 0; i < body.threads.length; i++) { | 1171 for (i = 0; i < body.threads.length; i++) { |
1645 result += body.threads[i].current ? '*' : ' '; | 1172 result += body.threads[i].current ? '*' : ' '; |
1646 result += ' '; | 1173 result += ' '; |
1647 result += body.threads[i].id; | 1174 result += body.threads[i].id; |
1648 result += '\n'; | 1175 result += '\n'; |
1649 } | 1176 } |
1650 details.text = result; | 1177 details.text = result; |
1651 break; | 1178 break; |
1652 | 1179 |
1653 case 'continue': | 1180 case 'continue': |
1654 details.text = "(running)"; | 1181 details.text = "(running)"; |
1655 break; | 1182 break; |
1656 | 1183 |
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 | |
1674 default: | 1184 default: |
1675 details.text = | 1185 details.text = |
1676 'Response for unknown command \'' + response.command() + '\'' + | 1186 'Response for unknown command \'' + response.command() + '\'' + |
1677 ' (' + response.raw_json() + ')'; | 1187 ' (' + response.raw_json() + ')'; |
1678 } | 1188 } |
1679 } catch (e) { | 1189 } catch (e) { |
1680 details.text = 'Error: "' + e + '" formatting response'; | 1190 details.text = 'Error: "' + e + '" formatting response'; |
1681 } | 1191 } |
1682 | 1192 |
1683 return details; | 1193 return details; |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1950 | 1460 |
1951 /** | 1461 /** |
1952 * Check is the value is a string. | 1462 * Check is the value is a string. |
1953 * @return {boolean} true if the value is a string | 1463 * @return {boolean} true if the value is a string |
1954 */ | 1464 */ |
1955 ProtocolValue.prototype.value = function() { | 1465 ProtocolValue.prototype.value = function() { |
1956 return this.value_.value; | 1466 return this.value_.value; |
1957 } | 1467 } |
1958 | 1468 |
1959 | 1469 |
1960 ProtocolValue.prototype.valueString = function() { | |
1961 return this.value_.text; | |
1962 } | |
1963 | |
1964 | |
1965 function ProtocolReference(handle) { | 1470 function ProtocolReference(handle) { |
1966 this.handle_ = handle; | 1471 this.handle_ = handle; |
1967 } | 1472 } |
1968 | 1473 |
1969 | 1474 |
1970 ProtocolReference.prototype.handle = function() { | 1475 ProtocolReference.prototype.handle = function() { |
1971 return this.handle_; | 1476 return this.handle_; |
1972 } | 1477 } |
1973 | 1478 |
1974 | 1479 |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2101 var content = []; | 1606 var content = []; |
2102 for (var key in object) { | 1607 for (var key in object) { |
2103 // Only consider string keys. | 1608 // Only consider string keys. |
2104 if (typeof key == 'string') { | 1609 if (typeof key == 'string') { |
2105 var property_value = object[key]; | 1610 var property_value = object[key]; |
2106 | 1611 |
2107 // Format the value based on its type. | 1612 // Format the value based on its type. |
2108 var property_value_json; | 1613 var property_value_json; |
2109 switch (typeof property_value) { | 1614 switch (typeof property_value) { |
2110 case 'object': | 1615 case 'object': |
2111 if (property_value === null) { | 1616 if (typeof property_value.toJSONProtocol == 'function') { |
2112 property_value_json = 'null'; | |
2113 } else if (typeof property_value.toJSONProtocol == 'function') { | |
2114 property_value_json = property_value.toJSONProtocol(true) | 1617 property_value_json = property_value.toJSONProtocol(true) |
2115 } else if (property_value.constructor.name == 'Array'){ | 1618 } else if (property_value.constructor.name == 'Array'){ |
2116 property_value_json = SimpleArrayToJSON_(property_value); | 1619 property_value_json = SimpleArrayToJSON_(property_value); |
2117 } else { | 1620 } else { |
2118 property_value_json = SimpleObjectToJSON_(property_value); | 1621 property_value_json = SimpleObjectToJSON_(property_value); |
2119 } | 1622 } |
2120 break; | 1623 break; |
2121 | 1624 |
2122 case 'boolean': | 1625 case 'boolean': |
2123 property_value_json = BooleanToJSON_(property_value); | 1626 property_value_json = BooleanToJSON_(property_value); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2171 json += NumberToJSON_(elem); | 1674 json += NumberToJSON_(elem); |
2172 } else if (typeof(elem) === 'string') { | 1675 } else if (typeof(elem) === 'string') { |
2173 json += StringToJSON_(elem); | 1676 json += StringToJSON_(elem); |
2174 } else { | 1677 } else { |
2175 json += elem; | 1678 json += elem; |
2176 } | 1679 } |
2177 } | 1680 } |
2178 json += ']'; | 1681 json += ']'; |
2179 return json; | 1682 return json; |
2180 } | 1683 } |
OLD | NEW |