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'; // If not in debugger mode, break with a frame request . | |
Søren Thygesen Gjesse
2011/01/03 08:56:07
Long line. Some more below.
marklam
2011/01/04 20:12:13
Done. Shortened the comment.
| |
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_ = this.frameCommandToJSONRequest_('' + (Debug.State.currentF rame + 1)); | |
marklam
2011/01/04 20:12:13
broke up this line to fit in 80 columns.
| |
387 break; | |
388 | |
389 case 'down': | |
390 case 'do': | |
391 this.request_ = this.frameCommandToJSONRequest_('' + (Debug.State.currentF rame - 1)); | |
marklam
2011/01/04 20:12:13
broke up this line to fit in 80 columns.
| |
392 break; | |
393 | |
394 case 'set': | |
314 case 'print': | 395 case 'print': |
315 case 'p': | 396 case 'p': |
316 this.request_ = this.printCommandToJSONRequest_(args); | 397 this.request_ = this.printCommandToJSONRequest_(args); |
317 break; | 398 break; |
318 | 399 |
319 case 'dir': | 400 case 'dir': |
320 this.request_ = this.dirCommandToJSONRequest_(args); | 401 this.request_ = this.dirCommandToJSONRequest_(args); |
321 break; | 402 break; |
322 | 403 |
323 case 'references': | 404 case 'references': |
324 this.request_ = this.referencesCommandToJSONRequest_(args); | 405 this.request_ = this.referencesCommandToJSONRequest_(args); |
325 break; | 406 break; |
326 | 407 |
327 case 'instances': | 408 case 'instances': |
328 this.request_ = this.instancesCommandToJSONRequest_(args); | 409 this.request_ = this.instancesCommandToJSONRequest_(args); |
329 break; | 410 break; |
330 | 411 |
412 case 'list': | |
413 case 'l': | |
414 this.request_ = this.listCommandToJSONRequest_(args); | |
415 break; | |
331 case 'source': | 416 case 'source': |
332 this.request_ = this.sourceCommandToJSONRequest_(args); | 417 this.request_ = this.sourceCommandToJSONRequest_(args); |
333 break; | 418 break; |
334 | 419 |
335 case 'scripts': | 420 case 'scripts': |
421 case 'script': | |
422 case 'scr': | |
336 this.request_ = this.scriptsCommandToJSONRequest_(args); | 423 this.request_ = this.scriptsCommandToJSONRequest_(args); |
337 break; | 424 break; |
338 | 425 |
339 case 'break': | 426 case 'break': |
340 case 'b': | 427 case 'b': |
341 this.request_ = this.breakCommandToJSONRequest_(args); | 428 this.request_ = this.breakCommandToJSONRequest_(args); |
342 break; | 429 break; |
343 | 430 |
344 case 'breakpoints': | 431 case 'breakpoints': |
345 case 'bb': | 432 case 'bb': |
346 this.request_ = this.breakpointsCommandToJSONRequest_(args); | 433 this.request_ = this.breakpointsCommandToJSONRequest_(args); |
347 break; | 434 break; |
348 | 435 |
349 case 'clear': | 436 case 'clear': |
437 case 'delete': | |
438 case 'd': | |
350 this.request_ = this.clearCommandToJSONRequest_(args); | 439 this.request_ = this.clearCommandToJSONRequest_(args); |
351 break; | 440 break; |
352 | 441 |
353 case 'threads': | 442 case 'threads': |
354 this.request_ = this.threadsCommandToJSONRequest_(args); | 443 this.request_ = this.threadsCommandToJSONRequest_(args); |
355 break; | 444 break; |
356 | 445 |
446 case 'cond': | |
447 this.request_ = this.changeBreakpointCommandToJSONRequest_(args, 'cond'); | |
448 break; | |
449 | |
450 case 'enable': | |
451 case 'en': | |
452 this.request_ = this.changeBreakpointCommandToJSONRequest_(args, 'enable') ; | |
marklam
2011/01/04 20:12:13
changed to fit into 80 columns.
| |
453 break; | |
454 | |
455 case 'disable': | |
456 case 'dis': | |
457 this.request_ = this.changeBreakpointCommandToJSONRequest_(args, 'disable' ); | |
marklam
2011/01/04 20:12:13
changed to fit into 80 columns.
| |
458 break; | |
459 | |
460 case 'ignore': | |
461 this.request_ = this.changeBreakpointCommandToJSONRequest_(args, 'ignore') ; | |
marklam
2011/01/04 20:12:13
changed to fit into 80 columns.
| |
462 break; | |
463 | |
464 case 'info': | |
465 case 'inf': | |
466 this.request_ = this.infoCommandToJSONRequest_(args); | |
467 break; | |
468 | |
469 case 'flags': | |
470 this.request_ = this.v8FlagsToJSONRequest_(args); | |
471 break; | |
472 | |
473 case 'gc': | |
474 this.request_ = this.gcToJSONRequest_(args); | |
475 break; | |
476 | |
357 case 'trace': | 477 case 'trace': |
478 case 'tr': | |
358 // Return undefined to indicate command handled internally (no JSON). | 479 // Return undefined to indicate command handled internally (no JSON). |
359 this.request_ = void 0; | 480 this.request_ = void 0; |
360 this.traceCommand_(args); | 481 this.traceCommand_(args); |
361 break; | 482 break; |
362 | 483 |
363 case 'help': | 484 case 'help': |
364 case '?': | 485 case '?': |
365 this.helpCommand_(args); | 486 this.helpCommand_(args); |
366 // Return undefined to indicate command handled internally (no JSON). | 487 // Return undefined to indicate command handled internally (no JSON). |
367 this.request_ = void 0; | 488 this.request_ = void 0; |
368 break; | 489 break; |
369 | 490 |
370 default: | 491 default: |
371 throw new Error('Unknown command "' + cmd + '"'); | 492 throw new Error('Unknown command "' + cmd + '"'); |
372 } | 493 } |
373 | |
374 last_cmd = cmd; | |
375 } | 494 } |
376 | 495 |
377 DebugRequest.prototype.JSONRequest = function() { | 496 DebugRequest.prototype.JSONRequest = function() { |
378 return this.request_; | 497 return this.request_; |
379 } | 498 } |
380 | 499 |
381 | 500 |
382 function RequestPacket(command) { | 501 function RequestPacket(command) { |
383 this.seq = 0; | 502 this.seq = 0; |
384 this.type = 'request'; | 503 this.type = 'request'; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
458 | 577 |
459 | 578 |
460 // Create a JSON request for the continue command. | 579 // Create a JSON request for the continue command. |
461 DebugRequest.prototype.continueCommandToJSONRequest_ = function(args) { | 580 DebugRequest.prototype.continueCommandToJSONRequest_ = function(args) { |
462 var request = this.createRequest('continue'); | 581 var request = this.createRequest('continue'); |
463 return request.toJSONProtocol(); | 582 return request.toJSONProtocol(); |
464 }; | 583 }; |
465 | 584 |
466 | 585 |
467 // Create a JSON request for the step command. | 586 // Create a JSON request for the step command. |
468 DebugRequest.prototype.stepCommandToJSONRequest_ = function(args) { | 587 DebugRequest.prototype.stepCommandToJSONRequest_ = function(args, type) { |
469 // Requesting a step is through the continue command with additional | 588 // Requesting a step is through the continue command with additional |
470 // arguments. | 589 // arguments. |
471 var request = this.createRequest('continue'); | 590 var request = this.createRequest('continue'); |
472 request.arguments = {}; | 591 request.arguments = {}; |
473 | 592 |
474 // Process arguments if any. | 593 // Process arguments if any. |
594 | |
595 // Only process args if the command is 'step' which is indicated by type being | |
596 // set to 'in'. For all other commands, ignore the args. | |
475 if (args && args.length > 0) { | 597 if (args && args.length > 0) { |
476 args = args.split(/\s*[ ]+\s*/g); | 598 args = args.split(/\s+/g); |
477 | 599 |
478 if (args.length > 2) { | 600 if (args.length > 2) { |
479 throw new Error('Invalid step arguments.'); | 601 throw new Error('Invalid step arguments.'); |
480 } | 602 } |
481 | 603 |
482 if (args.length > 0) { | 604 if (args.length > 0) { |
483 // Get step count argument if any. | 605 // Check if we have a gdb stype step command. If so, the 1st arg would |
484 if (args.length == 2) { | 606 // be the step count. If it's not a number, then assume that we're |
485 var stepcount = parseInt(args[1]); | 607 // parsing for the legacy v8 step command. |
486 if (isNaN(stepcount) || stepcount <= 0) { | 608 var stepcount = Number(args[0]); |
Søren Thygesen Gjesse
2011/01/03 08:56:07
Tab character sneaked in.
marklam
2011/01/04 20:12:13
Done.
| |
487 throw new Error('Invalid step count argument "' + args[0] + '".'); | 609 » if (stepcount == Number.NaN) { |
610 // No step count at arg 1. Process as legacy d8 step command: | |
611 if (args.length == 2) { | |
612 var stepcount = parseInt(args[1]); | |
613 if (isNaN(stepcount) || stepcount <= 0) { | |
614 throw new Error('Invalid step count argument "' + args[0] + '".'); | |
615 } | |
616 request.arguments.stepcount = stepcount; | |
488 } | 617 } |
618 | |
619 // Get the step action. | |
620 switch (args[0]) { | |
621 case 'in': | |
622 case 'i': | |
623 request.arguments.stepaction = 'in'; | |
624 break; | |
625 | |
626 case 'min': | |
627 case 'm': | |
628 request.arguments.stepaction = 'min'; | |
629 break; | |
630 | |
631 case 'next': | |
632 case 'n': | |
633 request.arguments.stepaction = 'next'; | |
634 break; | |
635 | |
636 case 'out': | |
637 case 'o': | |
638 request.arguments.stepaction = 'out'; | |
639 break; | |
640 | |
641 default: | |
642 throw new Error('Invalid step argument "' + args[0] + '".'); | |
643 } | |
644 | |
645 } else { | |
646 // gdb style step commands: | |
647 request.arguments.stepaction = type; | |
489 request.arguments.stepcount = stepcount; | 648 request.arguments.stepcount = stepcount; |
490 } | 649 } |
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 } | 650 } |
518 } else { | 651 } else { |
519 // Default is step next. | 652 // Default is step of the specified type. |
520 request.arguments.stepaction = 'next'; | 653 request.arguments.stepaction = type; |
521 } | 654 } |
522 | 655 |
523 return request.toJSONProtocol(); | 656 return request.toJSONProtocol(); |
524 }; | 657 }; |
525 | 658 |
526 | 659 |
527 // Create a JSON request for the backtrace command. | 660 // Create a JSON request for the backtrace command. |
528 DebugRequest.prototype.backtraceCommandToJSONRequest_ = function(args) { | 661 DebugRequest.prototype.backtraceCommandToJSONRequest_ = function(args) { |
529 // Build a backtrace request from the text command. | 662 // Build a backtrace request from the text command. |
530 var request = this.createRequest('backtrace'); | 663 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. | 774 // Build an evaluate request from the text command. |
642 if (args.length == 0) { | 775 if (args.length == 0) { |
643 throw new Error('Missing object id.'); | 776 throw new Error('Missing object id.'); |
644 } | 777 } |
645 | 778 |
646 // Build a references request. | 779 // Build a references request. |
647 return this.makeReferencesJSONRequest_(args, 'constructedBy'); | 780 return this.makeReferencesJSONRequest_(args, 'constructedBy'); |
648 }; | 781 }; |
649 | 782 |
650 | 783 |
784 // Create a JSON request for the list command. | |
785 DebugRequest.prototype.listCommandToJSONRequest_ = function(args) { | |
786 | |
787 // Default is ten lines starting five lines before the current location. | |
788 if (Debug.State.displaySourceEndLine == -1) { | |
Søren Thygesen Gjesse
2011/01/03 08:56:07
Comment indented more that source line (This comme
marklam
2011/01/04 20:12:13
There was some accidental tabs in here. Fixed. T
| |
789 // If we list forwards, start from 5 lines before the current location. | |
790 Debug.State.displaySourceEndLine = Debug.State.currentSourceLine - 5; | |
791 // If we list backwards, start from 1 lines before the current location. | |
Søren Thygesen Gjesse
2011/01/03 08:56:07
This sets displaySourceStartLine if displaySourceE
marklam
2011/01/04 20:12:13
displaySourceStartLine and displaySourceEndLine ar
| |
792 Debug.State.displaySourceStartLine = Debug.State.currentSourceLine + 1; | |
793 } | |
794 | |
795 var from = Debug.State.displaySourceEndLine + 1; | |
796 var lines = 10; | |
797 | |
798 // Parse the arguments. | |
799 args = args.split(/\s*,\s*/g); | |
800 if (args == '') { | |
801 } else if ((args.length == 1) && (args[0] == '-')) { | |
802 from = Debug.State.displaySourceStartLine - lines; | |
803 } else if (args.length == 2) { | |
804 from = parseInt(args[0]); | |
805 lines = parseInt(args[1]) - from + 1; // inclusive of the ending line. | |
806 } else { | |
807 throw new Error('Invalid list arguments.'); | |
808 } | |
809 Debug.State.displaySourceStartLine = from; | |
810 Debug.State.displaySourceEndLine = from + lines - 1; | |
811 var sourceArgs = '' + from + ' ' + lines; | |
812 return this.sourceCommandToJSONRequest_(sourceArgs); | |
813 }; | |
814 | |
815 | |
651 // Create a JSON request for the source command. | 816 // Create a JSON request for the source command. |
652 DebugRequest.prototype.sourceCommandToJSONRequest_ = function(args) { | 817 DebugRequest.prototype.sourceCommandToJSONRequest_ = function(args) { |
653 // Build a evaluate request from the text command. | 818 // Build a evaluate request from the text command. |
654 var request = this.createRequest('source'); | 819 var request = this.createRequest('source'); |
655 | 820 |
656 // Default is ten lines starting five lines before the current location. | 821 // Default is ten lines starting five lines before the current location. |
657 var from = Debug.State.currentSourceLine - 5; | 822 var from = Debug.State.currentSourceLine - 5; |
658 var lines = 10; | 823 var lines = 10; |
659 | 824 |
660 // Parse the arguments. | 825 // Parse the arguments. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
702 break; | 867 break; |
703 | 868 |
704 case 'all': | 869 case 'all': |
705 request.arguments.types = | 870 request.arguments.types = |
706 ScriptTypeFlag(Debug.ScriptType.Normal) | | 871 ScriptTypeFlag(Debug.ScriptType.Normal) | |
707 ScriptTypeFlag(Debug.ScriptType.Native) | | 872 ScriptTypeFlag(Debug.ScriptType.Native) | |
708 ScriptTypeFlag(Debug.ScriptType.Extension); | 873 ScriptTypeFlag(Debug.ScriptType.Extension); |
709 break; | 874 break; |
710 | 875 |
711 default: | 876 default: |
712 throw new Error('Invalid argument "' + args[0] + '".'); | 877 // If the arg is not one of the know one aboves, then it must be a |
878 // filter used for filtering the results: | |
879 request.arguments.filter = args[0]; | |
880 break; | |
713 } | 881 } |
714 } | 882 } |
715 | 883 |
716 return request.toJSONProtocol(); | 884 return request.toJSONProtocol(); |
717 }; | 885 }; |
718 | 886 |
719 | 887 |
720 // Create a JSON request for the break command. | 888 // Create a JSON request for the break command. |
721 DebugRequest.prototype.breakCommandToJSONRequest_ = function(args) { | 889 DebugRequest.prototype.breakCommandToJSONRequest_ = function(args) { |
722 // Build a evaluate request from the text command. | 890 // Build a evaluate request from the text command. |
723 // Process arguments if any. | 891 // Process arguments if any. |
724 if (args && args.length > 0) { | 892 if (args && args.length > 0) { |
725 var target = args; | 893 var target = args; |
726 var type = 'function'; | 894 var type = 'function'; |
727 var line; | 895 var line; |
728 var column; | 896 var column; |
729 var condition; | 897 var condition; |
730 var pos; | 898 var pos; |
731 | 899 |
732 var request = this.createRequest('setbreakpoint'); | 900 var request = this.createRequest('setbreakpoint'); |
733 | 901 |
902 // Break the args into target spec and condition if appropriate. | |
903 | |
734 // Check for breakpoint condition. | 904 // Check for breakpoint condition. |
735 pos = args.indexOf(' '); | 905 pos = args.indexOf(' '); |
736 if (pos > 0) { | 906 if (pos > 0) { |
737 target = args.substring(0, pos); | 907 target = args.substring(0, pos); |
738 condition = args.substring(pos + 1, args.length); | 908 condition = args.substring(pos + 1, args.length); |
739 } | 909 } |
740 | 910 |
741 // Check for script breakpoint (name:line[:column]). If no ':' in break | 911 // Check for script breakpoint (name:line[:column]). If no ':' in break |
742 // specification it is considered a function break point. | 912 // specification it is considered a function break point. |
743 pos = target.indexOf(':'); | 913 pos = target.indexOf(':'); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
794 request.arguments = {}; | 964 request.arguments = {}; |
795 request.arguments.breakpoint = parseInt(args); | 965 request.arguments.breakpoint = parseInt(args); |
796 } else { | 966 } else { |
797 throw new Error('Invalid break arguments.'); | 967 throw new Error('Invalid break arguments.'); |
798 } | 968 } |
799 | 969 |
800 return request.toJSONProtocol(); | 970 return request.toJSONProtocol(); |
801 }; | 971 }; |
802 | 972 |
803 | 973 |
974 // Create a JSON request for the change breakpoint command. | |
975 DebugRequest.prototype.changeBreakpointCommandToJSONRequest_ = function(args, co mmand) { | |
marklam
2011/01/04 20:12:13
broke up this line to fit in 80 columns.
| |
976 var request; | |
977 | |
978 // Check for exception breaks first: | |
Søren Thygesen Gjesse
2011/01/03 08:56:07
Why do you want both
en exc all
and
en all
marklam
2011/01/04 20:12:13
"en exc all" when we think in terms of types: enab
| |
979 // en[able] exc[eptions] [all|unc[aught]] | |
980 // en[able] [all|unc[aught]] exc[eptions] | |
981 // dis[able] exc[eptions] [all|unc[aught]] | |
982 // dis[able] [all|unc[aught]] exc[eptions] | |
983 if ((command == 'enable' || command == 'disable') && args && args.length > 1) { | |
marklam
2011/01/04 20:12:13
broke up this line to fit in 80 columns.
| |
984 var nextPos = args.indexOf(' '); | |
985 var arg1 = (nextPos > 0) ? args.substring(0, nextPos) : args; | |
986 var excType = null; | |
987 | |
988 // Check for: | |
989 // en[able] exc[eptions] [all|unc[aught]] | |
990 // dis[able] exc[eptions] [all|unc[aught]] | |
991 if (arg1 == 'exc' || arg1 == 'exception' || arg1 == 'exceptions') { | |
992 | |
993 var arg2 = (nextPos > 0) ? args.substring(nextPos + 1, args.length) : 'all '; | |
marklam
2011/01/04 20:12:13
broke up this line to fit in 80 columns.
| |
994 if (!arg2) { | |
995 arg2 = 'all'; // if unspecified, set for all. | |
996 } if (arg2 == 'unc') { // check for short cut. | |
997 arg2 = 'uncaught'; | |
998 } | |
999 excType = arg2; | |
1000 | |
1001 // Check for: | |
1002 // en[able] [all|unc[aught]] exc[eptions] | |
1003 // dis[able] [all|unc[aught]] exc[eptions] | |
1004 } else if (arg1 == 'all' || arg1 == 'unc' || arg1 == 'uncaught') { | |
1005 | |
1006 var arg2 = (nextPos > 0) ? args.substring(nextPos + 1, args.length) : null ; | |
marklam
2011/01/04 20:12:13
broke up this line to fit in 80 columns.
| |
1007 if (arg2 == 'exc' || arg1 == 'exception' || arg1 == 'exceptions') { | |
1008 excType = arg1; | |
1009 if (excType == 'unc') { | |
1010 excType = 'uncaught'; | |
1011 } | |
1012 } | |
1013 } | |
1014 | |
1015 // If we matched one of the command formats, then excType will be non-null: | |
1016 if (excType) { | |
1017 // Build a evaluate request from the text command. | |
1018 request = this.createRequest('setexceptionbreak'); | |
1019 | |
1020 request.arguments = {}; | |
1021 request.arguments.type = excType; | |
1022 request.arguments.enabled = (command == 'enable'); | |
1023 | |
1024 return request.toJSONProtocol(); | |
1025 } | |
1026 } | |
1027 | |
1028 // Build a evaluate request from the text command. | |
1029 request = this.createRequest('changebreakpoint'); | |
1030 | |
1031 // Process arguments if any. | |
1032 if (args && args.length > 0) { | |
1033 request.arguments = {}; | |
1034 var pos = args.indexOf(' '); | |
1035 var breakpointArg = args; | |
1036 var otherArgs; | |
1037 if (pos > 0) { | |
1038 breakpointArg = args.substring(0, pos); | |
1039 otherArgs = args.substring(pos + 1, args.length); | |
1040 } | |
1041 | |
1042 request.arguments.breakpoint = parseInt(breakpointArg); | |
1043 | |
1044 switch(command) { | |
1045 case 'cond': | |
1046 request.arguments.condition = otherArgs ? otherArgs : null; | |
1047 break; | |
1048 case 'enable': | |
1049 request.arguments.enabled = true; | |
1050 break; | |
1051 case 'disable': | |
1052 request.arguments.enabled = false; | |
1053 break; | |
1054 case 'ignore': | |
1055 request.arguments.ignoreCount = parseInt(otherArgs); | |
1056 break; | |
1057 default: | |
1058 throw new Error('Invalid arguments.'); | |
1059 } | |
1060 } else { | |
1061 throw new Error('Invalid arguments.'); | |
1062 } | |
1063 | |
1064 return request.toJSONProtocol(); | |
1065 }; | |
1066 | |
1067 | |
1068 // Create a JSON request for the disconnect command. | |
1069 DebugRequest.prototype.disconnectCommandToJSONRequest_ = function(args) { | |
1070 var request; | |
1071 request = this.createRequest('disconnect'); | |
1072 return request.toJSONProtocol(); | |
1073 }; | |
1074 | |
1075 | |
1076 // Create a JSON request for the info command. | |
1077 DebugRequest.prototype.infoCommandToJSONRequest_ = function(args) { | |
1078 var request; | |
1079 if (args && (args == 'break' || args == 'br')) { | |
1080 // Build a evaluate request from the text command. | |
1081 request = this.createRequest('listbreakpoints'); | |
1082 last_cmd = 'info break'; | |
1083 } else if (args && (args == 'locals' || args == 'lo')) { | |
1084 // Build a evaluate request from the text command. | |
1085 request = this.createRequest('frame'); | |
1086 last_cmd = 'info locals'; | |
1087 } else if (args && (args == 'args' || args == 'ar')) { | |
1088 // Build a evaluate request from the text command. | |
1089 request = this.createRequest('frame'); | |
1090 last_cmd = 'info args'; | |
1091 } else { | |
1092 throw new Error('Invalid info arguments.'); | |
1093 } | |
1094 | |
1095 return request.toJSONProtocol(); | |
1096 }; | |
1097 | |
1098 | |
1099 DebugRequest.prototype.v8FlagsToJSONRequest_ = function(args) { | |
1100 var request; | |
1101 request = this.createRequest('v8flags'); | |
1102 request.arguments = {}; | |
1103 request.arguments.flags = args; | |
1104 return request.toJSONProtocol(); | |
1105 }; | |
1106 | |
1107 | |
1108 DebugRequest.prototype.gcToJSONRequest_ = function(args) { | |
1109 var request; | |
1110 if (!args) { | |
1111 args = 'all'; | |
1112 } | |
1113 var args = args.split(/\s+/g); | |
1114 var cmd = args[0]; | |
1115 | |
1116 switch(cmd) { | |
1117 case 'all': | |
1118 case 'quick': | |
1119 case 'full': | |
1120 case 'young': | |
1121 case 'old': | |
1122 case 'compact': | |
1123 case 'sweep': | |
1124 case 'scavenge': { | |
1125 if (cmd == 'young') { cmd = 'quick'; } | |
1126 else if (cmd == 'old') { cmd = 'full'; } | |
1127 | |
1128 request = this.createRequest('gc'); | |
1129 request.arguments = {}; | |
1130 request.arguments.type = cmd; | |
1131 break; | |
1132 } | |
1133 // Else fall thru to the default case below to report the error. | |
1134 default: | |
1135 throw new Error('Missing arguments after ' + cmd + '.'); | |
1136 } | |
1137 return request.toJSONProtocol(); | |
1138 }; | |
1139 | |
1140 | |
804 // Create a JSON request for the threads command. | 1141 // Create a JSON request for the threads command. |
805 DebugRequest.prototype.threadsCommandToJSONRequest_ = function(args) { | 1142 DebugRequest.prototype.threadsCommandToJSONRequest_ = function(args) { |
806 // Build a threads request from the text command. | 1143 // Build a threads request from the text command. |
807 var request = this.createRequest('threads'); | 1144 var request = this.createRequest('threads'); |
808 return request.toJSONProtocol(); | 1145 return request.toJSONProtocol(); |
809 }; | 1146 }; |
810 | 1147 |
811 | 1148 |
812 // Handle the trace command. | 1149 // Handle the trace command. |
813 DebugRequest.prototype.traceCommand_ = function(args) { | 1150 DebugRequest.prototype.traceCommand_ = function(args) { |
814 // Process arguments. | 1151 // Process arguments. |
815 if (args && args.length > 0) { | 1152 if (args && args.length > 0) { |
816 if (args == 'compile') { | 1153 if (args == 'compile') { |
817 trace_compile = !trace_compile; | 1154 trace_compile = !trace_compile; |
818 print('Tracing of compiled scripts ' + (trace_compile ? 'on' : 'off')); | 1155 print('Tracing of compiled scripts ' + (trace_compile ? 'on' : 'off')); |
1156 } else if (args === 'debug json' || args === 'json' || args === 'packets') { | |
1157 trace_debug_json = !trace_debug_json; | |
1158 print('Tracing of debug json packets ' + | |
1159 (trace_debug_json ? 'on' : 'off')); | |
819 } else { | 1160 } else { |
820 throw new Error('Invalid trace arguments.'); | 1161 throw new Error('Invalid trace arguments.'); |
821 } | 1162 } |
822 } else { | 1163 } else { |
823 throw new Error('Invalid trace arguments.'); | 1164 throw new Error('Invalid trace arguments.'); |
824 } | 1165 } |
825 } | 1166 } |
826 | 1167 |
827 // Handle the help command. | 1168 // Handle the help command. |
828 DebugRequest.prototype.helpCommand_ = function(args) { | 1169 DebugRequest.prototype.helpCommand_ = function(args) { |
829 // Help os quite simple. | 1170 // Help os quite simple. |
830 if (args && args.length > 0) { | 1171 if (args && args.length > 0) { |
831 print('warning: arguments to \'help\' are ignored'); | 1172 print('warning: arguments to \'help\' are ignored'); |
832 } | 1173 } |
833 | 1174 |
834 print('break'); | 1175 print('Note: <> denotes symbollic values to be replaced with real values.'); |
835 print('break location [condition]'); | 1176 print('Note: [] denotes optional parts of commands, or optional options / argu ments.'); |
marklam
2011/01/04 20:12:13
How strict do you want to be on long strings like
| |
836 print(' break on named function: location is a function name'); | 1177 print(' e.g. d[elete] - you get the same command if you type d or delete. '); |
837 print(' break on function: location is #<id>#'); | 1178 print(''); |
838 print(' break on script position: location is name:line[:column]'); | 1179 print('[break] - break as soon as possible'); |
839 print('clear <breakpoint #>'); | 1180 print('b[reak] location [condition]'); |
840 print('backtrace [n] | [-n] | [from to]'); | 1181 print(' - break on named function: location is a function name'); |
841 print('frame <frame #>'); | 1182 print(' - break on function: location is #<id>#'); |
1183 print(' - break on script position: location is name:line[:column]'); | |
1184 print(''); | |
1185 print('clear <breakpoint #> - deletes the specified user defined breakpo int'); | |
1186 print('d[elete] <breakpoint #> - deletes the specified user defined breakpo int'); | |
1187 print('dis[able] <breakpoint #> - disables the specified user defined breakp oint'); | |
1188 print('dis[able] exc[eptions] [[all] | unc[aught]]'); | |
1189 print(' - disables breaking on exceptions'); | |
1190 print('en[able] <breakpoint #> - enables the specified user defined breakpo int'); | |
1191 print('en[able] exc[eptions] [[all] | unc[aught]]'); | |
1192 print(' - enables breaking on exceptions'); | |
1193 print(''); | |
1194 print('b[ack]t[race] [n] | [-n] | [from to]'); | |
1195 print(' - prints the stack back trace'); | |
1196 print('f[rame] - prints info about the current frame contex t'); | |
1197 print('f[rame] <frame #> - set context to specified frame #'); | |
842 print('scopes'); | 1198 print('scopes'); |
843 print('scope <scope #>'); | 1199 print('scope <scope #>'); |
1200 print(''); | |
1201 print('up - set context to caller of current frame'); | |
1202 print('do[wn] - set context to callee of current frame'); | |
1203 print('inf[o] br[eak] - prints info about breakpoints in use'); | |
1204 print('inf[o] ar[gs] - prints info about arguments of the current function'); | |
1205 print('inf[o] lo[cals] - prints info about locals in the current fu nction'); | |
1206 print('inf[o] liveobjectlist|lol - same as \'lol info\''); | |
1207 print(''); | |
844 print('step [in | next | out| min [step count]]'); | 1208 print('step [in | next | out| min [step count]]'); |
845 print('print <expression>'); | 1209 print('c[ontinue] - continue executing after a breakpoint'); |
846 print('dir <expression>'); | 1210 print('s[tep] [<N>] - step into the next N callees (default N is 1)'); |
1211 print('s[tep]i [<N>] - step into the next N callees (default N is 1)'); | |
1212 print('n[ext] [<N>] - step over the next N callees (default N is 1)'); | |
1213 print('fin[ish] [<N>] - step out of N frames (default N is 1)'); | |
1214 print(''); | |
1215 print('p[rint] <expression> - prints the result of the specified express ion'); | |
1216 print('dir <expression> - prints the object structure of the result' ); | |
1217 print('set <var> = <expression> - executes the specified statement'); | |
1218 print(''); | |
1219 print('l[ist] - list the source code around for the curren t pc'); | |
1220 print('l[ist] [- | <start>,<end>] - list the specified range of source code'); | |
847 print('source [from line [num lines]]'); | 1221 print('source [from line [num lines]]'); |
848 print('scripts'); | 1222 print('scr[ipts] [native|extensions|all]'); |
849 print('continue'); | 1223 print('scr[ipts] [<filter text>] - list scripts with the specified text in it s description'); |
1224 print(''); | |
1225 print('gc - runs the garbage collector'); | |
1226 print(''); | |
850 print('trace compile'); | 1227 print('trace compile'); |
Søren Thygesen Gjesse
2011/01/03 08:56:07
Code in comment. PLease just use an "ordinary" for
marklam
2011/01/04 20:12:13
I presume you mean to use an ordinary comment and
| |
851 print('help'); | 1228 //print('trace debug json - toggles tracing of debug json packets'); |
1229 print(''); | |
1230 print('disconnect|exit|quit - disconnects and quits the debugger'); | |
1231 print('help - prints this help information'); | |
852 } | 1232 } |
853 | 1233 |
854 | 1234 |
855 function formatHandleReference_(value) { | 1235 function formatHandleReference_(value) { |
856 if (value.handle() >= 0) { | 1236 if (value.handle() >= 0) { |
857 return '#' + value.handle() + '#'; | 1237 return '#' + value.handle() + '#'; |
858 } else { | 1238 } else { |
859 return '#Transient#'; | 1239 return '#Transient#'; |
860 } | 1240 } |
861 } | 1241 } |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
923 case Debug.ScopeType.Closure: | 1303 case Debug.ScopeType.Closure: |
924 result += 'Closure'; | 1304 result += 'Closure'; |
925 break; | 1305 break; |
926 default: | 1306 default: |
927 result += 'UNKNOWN'; | 1307 result += 'UNKNOWN'; |
928 } | 1308 } |
929 return result; | 1309 return result; |
930 } | 1310 } |
931 | 1311 |
932 | 1312 |
1313 function refObjectToString_(protocolPackage, handle) { | |
Søren Thygesen Gjesse
2011/01/03 08:56:07
Please use 2-char indentation.
marklam
2011/01/04 20:12:13
Sorry. Some tabs snuck in. Fixed.
| |
1314 var value = protocolPackage.lookup(handle); | |
1315 var result = ''; | |
1316 if (value.isString()) { | |
1317 result = '"' + value.value() + '"'; | |
1318 } else if (value.isPrimitive()) { | |
1319 result = value.valueString(); | |
1320 } else if (value.isObject()) { | |
1321 result += formatObject_(value, true); | |
1322 } | |
1323 return result; | |
1324 } | |
1325 | |
1326 | |
1327 // Rounds number 'num' to 'length' decimal places. | |
1328 function roundNumber(num, length) { | |
1329 var factor = Math.pow(10, length); | |
1330 return Math.round(num * factor) / factor; | |
1331 } | |
1332 | |
1333 | |
933 // Convert a JSON response to text for display in a text based debugger. | 1334 // Convert a JSON response to text for display in a text based debugger. |
934 function DebugResponseDetails(response) { | 1335 function DebugResponseDetails(response) { |
935 details = {text:'', running:false} | 1336 details = {text:'', running:false} |
936 | 1337 |
937 try { | 1338 try { |
938 if (!response.success()) { | 1339 if (!response.success()) { |
939 details.text = response.message(); | 1340 details.text = response.message(); |
940 return details; | 1341 return details; |
941 } | 1342 } |
942 | 1343 |
(...skipping 12 matching lines...) Expand all Loading... | |
955 result += body.breakpoint; | 1356 result += body.breakpoint; |
956 details.text = result; | 1357 details.text = result; |
957 break; | 1358 break; |
958 | 1359 |
959 case 'clearbreakpoint': | 1360 case 'clearbreakpoint': |
960 result = 'cleared breakpoint #'; | 1361 result = 'cleared breakpoint #'; |
961 result += body.breakpoint; | 1362 result += body.breakpoint; |
962 details.text = result; | 1363 details.text = result; |
963 break; | 1364 break; |
964 | 1365 |
1366 case 'changebreakpoint': | |
1367 result = 'successfully changed breakpoint'; | |
1368 details.text = result; | |
1369 break; | |
1370 | |
965 case 'listbreakpoints': | 1371 case 'listbreakpoints': |
966 result = 'breakpoints: (' + body.breakpoints.length + ')'; | 1372 result = 'breakpoints: (' + body.breakpoints.length + ')'; |
967 for (var i = 0; i < body.breakpoints.length; i++) { | 1373 for (var i = 0; i < body.breakpoints.length; i++) { |
968 var breakpoint = body.breakpoints[i]; | 1374 var breakpoint = body.breakpoints[i]; |
969 result += '\n id=' + breakpoint.number; | 1375 result += '\n id=' + breakpoint.number; |
970 result += ' type=' + breakpoint.type; | 1376 result += ' type=' + breakpoint.type; |
971 if (breakpoint.script_id) { | 1377 if (breakpoint.script_id) { |
972 result += ' script_id=' + breakpoint.script_id; | 1378 result += ' script_id=' + breakpoint.script_id; |
973 } | 1379 } |
974 if (breakpoint.script_name) { | 1380 if (breakpoint.script_name) { |
975 result += ' script_name=' + breakpoint.script_name; | 1381 result += ' script_name=' + breakpoint.script_name; |
976 } | 1382 } |
977 result += ' line=' + breakpoint.line; | 1383 result += ' line=' + (breakpoint.line + 1); |
978 if (breakpoint.column != null) { | 1384 if (breakpoint.column != null) { |
979 result += ' column=' + breakpoint.column; | 1385 result += ' column=' + (breakpoint.column + 1); |
980 } | 1386 } |
981 if (breakpoint.groupId) { | 1387 if (breakpoint.groupId) { |
982 result += ' groupId=' + breakpoint.groupId; | 1388 result += ' groupId=' + breakpoint.groupId; |
983 } | 1389 } |
984 if (breakpoint.ignoreCount) { | 1390 if (breakpoint.ignoreCount) { |
985 result += ' ignoreCount=' + breakpoint.ignoreCount; | 1391 result += ' ignoreCount=' + breakpoint.ignoreCount; |
986 } | 1392 } |
987 if (breakpoint.active === false) { | 1393 if (breakpoint.active === false) { |
988 result += ' inactive'; | 1394 result += ' inactive'; |
989 } | 1395 } |
990 if (breakpoint.condition) { | 1396 if (breakpoint.condition) { |
991 result += ' condition=' + breakpoint.condition; | 1397 result += ' condition=' + breakpoint.condition; |
992 } | 1398 } |
993 result += ' hit_count=' + breakpoint.hit_count; | 1399 result += ' hit_count=' + breakpoint.hit_count; |
994 } | 1400 } |
1401 if (body.breakpoints.length === 0) { | |
1402 result = "No user defined breakpoints\n"; | |
1403 } else { | |
1404 result += '\n'; | |
1405 } | |
1406 if (body.breakOnExceptions) { | |
1407 result += '* breaking on ALL exceptions is enabled\n'; | |
1408 } else if (body.breakOnUncaughtExceptions) { | |
1409 result += '* breaking on UNCAUGHT exceptions is enabled\n'; | |
1410 } else { | |
1411 result += '* all exception breakpoints are disabled\n'; | |
1412 } | |
1413 details.text = result; | |
1414 break; | |
1415 | |
1416 case 'setexceptionbreak': | |
1417 result = 'Break on ' + body.type + ' exceptions: '; | |
1418 result += body.enabled ? 'enabled':'disabled'; | |
Søren Thygesen Gjesse
2011/01/03 08:56:07
Please add spaces on both sides of ':'.
marklam
2011/01/04 20:12:13
Done.
| |
995 details.text = result; | 1419 details.text = result; |
996 break; | 1420 break; |
997 | 1421 |
998 case 'backtrace': | 1422 case 'backtrace': |
999 if (body.totalFrames == 0) { | 1423 if (body.totalFrames == 0) { |
1000 result = '(empty stack)'; | 1424 result = '(empty stack)'; |
1001 } else { | 1425 } else { |
1002 var result = 'Frames #' + body.fromFrame + ' to #' + | 1426 var result = 'Frames #' + body.fromFrame + ' to #' + |
1003 (body.toFrame - 1) + ' of ' + body.totalFrames + '\n'; | 1427 (body.toFrame - 1) + ' of ' + body.totalFrames + '\n'; |
1004 for (i = 0; i < body.frames.length; i++) { | 1428 for (i = 0; i < body.frames.length; i++) { |
1005 if (i != 0) result += '\n'; | 1429 if (i != 0) result += '\n'; |
1006 result += body.frames[i].text; | 1430 result += body.frames[i].text; |
1007 } | 1431 } |
1008 } | 1432 } |
1009 details.text = result; | 1433 details.text = result; |
1010 break; | 1434 break; |
1011 | 1435 |
1012 case 'frame': | 1436 case 'frame': |
1013 details.text = SourceUnderline(body.sourceLineText, | 1437 if (last_cmd === 'info locals') { |
1014 body.column); | 1438 var locals = body.locals; |
1015 Debug.State.currentSourceLine = body.line; | 1439 if (locals.length === 0) { |
1016 Debug.State.currentFrame = body.index; | 1440 result = 'No locals'; |
1441 } else { | |
1442 for (var i = 0; i < locals.length; i++) { | |
1443 var local = locals[i]; | |
1444 result += local.name + ' = '; | |
1445 result += refObjectToString_(response, local.value.ref); | |
1446 result += '\n'; | |
1447 } | |
1448 } | |
1449 } else if (last_cmd === 'info args') { | |
1450 var args = body.arguments; | |
1451 if (args.length === 0) { | |
1452 result = 'No arguments'; | |
1453 } else { | |
1454 for (var i = 0; i < args.length; i++) { | |
1455 var arg = args[i]; | |
1456 result += arg.name + ' = '; | |
1457 result += refObjectToString_(response, arg.value.ref); | |
1458 result += '\n'; | |
1459 } | |
1460 } | |
1461 } else { | |
1462 result = SourceUnderline(body.sourceLineText, | |
1463 body.column); | |
1464 Debug.State.currentSourceLine = body.line; | |
1465 Debug.State.currentFrame = body.index; | |
1466 Debug.State.displaySourceStartLine = -1; | |
1467 Debug.State.displaySourceEndLine = -1; | |
1468 } | |
Søren Thygesen Gjesse
2011/01/03 08:56:07
Tabs.
marklam
2011/01/04 20:12:13
Done.
| |
1469 » » details.text = result; | |
1017 break; | 1470 break; |
1018 | 1471 |
1019 case 'scopes': | 1472 case 'scopes': |
1020 if (body.totalScopes == 0) { | 1473 if (body.totalScopes == 0) { |
1021 result = '(no scopes)'; | 1474 result = '(no scopes)'; |
1022 } else { | 1475 } else { |
1023 result = 'Scopes #' + body.fromScope + ' to #' + | 1476 result = 'Scopes #' + body.fromScope + ' to #' + |
1024 (body.toScope - 1) + ' of ' + body.totalScopes + '\n'; | 1477 (body.toScope - 1) + ' of ' + body.totalScopes + '\n'; |
1025 for (i = 0; i < body.scopes.length; i++) { | 1478 for (i = 0; i < body.scopes.length; i++) { |
1026 if (i != 0) { | 1479 if (i != 0) { |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1125 if (i != 0) result += '\n'; | 1578 if (i != 0) result += '\n'; |
1126 if (body[i].id) { | 1579 if (body[i].id) { |
1127 result += body[i].id; | 1580 result += body[i].id; |
1128 } else { | 1581 } else { |
1129 result += '[no id]'; | 1582 result += '[no id]'; |
1130 } | 1583 } |
1131 result += ', '; | 1584 result += ', '; |
1132 if (body[i].name) { | 1585 if (body[i].name) { |
1133 result += body[i].name; | 1586 result += body[i].name; |
1134 } else { | 1587 } else { |
1135 if (body[i].compilationType == Debug.ScriptCompilationType.Eval) { | 1588 if (body[i].compilationType == Debug.ScriptCompilationType.Eval |
1589 && body[i].evalFromScript | |
1590 ) { | |
1136 result += 'eval from '; | 1591 result += 'eval from '; |
1137 var script_value = response.lookup(body[i].evalFromScript.ref); | 1592 var script_value = response.lookup(body[i].evalFromScript.ref); |
1138 result += ' ' + script_value.field('name'); | 1593 result += ' ' + script_value.field('name'); |
1139 result += ':' + (body[i].evalFromLocation.line + 1); | 1594 result += ':' + (body[i].evalFromLocation.line + 1); |
1140 result += ':' + body[i].evalFromLocation.column; | 1595 result += ':' + body[i].evalFromLocation.column; |
1141 } else if (body[i].compilationType == | 1596 } else if (body[i].compilationType == |
1142 Debug.ScriptCompilationType.JSON) { | 1597 Debug.ScriptCompilationType.JSON) { |
1143 result += 'JSON '; | 1598 result += 'JSON '; |
1144 } else { // body[i].compilation == Debug.ScriptCompilationType.Host | 1599 } else { // body[i].compilation == Debug.ScriptCompilationType.Host |
1145 result += '[unnamed] '; | 1600 result += '[unnamed] '; |
1146 } | 1601 } |
1147 } | 1602 } |
1148 result += ' (lines: '; | 1603 result += ' (lines: '; |
1149 result += body[i].lineCount; | 1604 result += body[i].lineCount; |
1150 result += ', length: '; | 1605 result += ', length: '; |
1151 result += body[i].sourceLength; | 1606 result += body[i].sourceLength; |
1152 if (body[i].type == Debug.ScriptType.Native) { | 1607 if (body[i].type == Debug.ScriptType.Native) { |
1153 result += ', native'; | 1608 result += ', native'; |
1154 } else if (body[i].type == Debug.ScriptType.Extension) { | 1609 } else if (body[i].type == Debug.ScriptType.Extension) { |
1155 result += ', extension'; | 1610 result += ', extension'; |
1156 } | 1611 } |
1157 result += '), ['; | 1612 result += '), ['; |
1158 var sourceStart = body[i].sourceStart; | 1613 var sourceStart = body[i].sourceStart; |
1159 if (sourceStart.length > 40) { | 1614 if (sourceStart.length > 40) { |
1160 sourceStart = sourceStart.substring(0, 37) + '...'; | 1615 sourceStart = sourceStart.substring(0, 37) + '...'; |
1161 } | 1616 } |
1162 result += sourceStart; | 1617 result += sourceStart; |
1163 result += ']'; | 1618 result += ']'; |
1164 } | 1619 } |
1620 if (body.length == 0) { | |
1621 result = "no matching scripts found"; | |
1622 } | |
1165 details.text = result; | 1623 details.text = result; |
1166 break; | 1624 break; |
1167 | 1625 |
1168 case 'threads': | 1626 case 'threads': |
1169 var result = 'Active V8 threads: ' + body.totalThreads + '\n'; | 1627 var result = 'Active V8 threads: ' + body.totalThreads + '\n'; |
1170 body.threads.sort(function(a, b) { return a.id - b.id; }); | 1628 body.threads.sort(function(a, b) { return a.id - b.id; }); |
1171 for (i = 0; i < body.threads.length; i++) { | 1629 for (i = 0; i < body.threads.length; i++) { |
1172 result += body.threads[i].current ? '*' : ' '; | 1630 result += body.threads[i].current ? '*' : ' '; |
1173 result += ' '; | 1631 result += ' '; |
1174 result += body.threads[i].id; | 1632 result += body.threads[i].id; |
1175 result += '\n'; | 1633 result += '\n'; |
1176 } | 1634 } |
1177 details.text = result; | 1635 details.text = result; |
1178 break; | 1636 break; |
1179 | 1637 |
1180 case 'continue': | 1638 case 'continue': |
1181 details.text = "(running)"; | 1639 details.text = "(running)"; |
1182 break; | 1640 break; |
1183 | 1641 |
1642 case 'v8flags': | |
1643 details.text = "flags set"; | |
1644 break; | |
1645 | |
1646 case 'gc': | |
1647 details.text = "GC " + body.before + " => " + body.after; | |
1648 if (body.after > (1024*1024)) { | |
1649 details.text += | |
1650 " (" + roundNumber(body.before/(1024*1024), 1) + "M => " + | |
1651 roundNumber(body.after/(1024*1024), 1) + "M)"; | |
1652 } else if (body.after > 1024) { | |
1653 details.text += | |
1654 " (" + roundNumber(body.before/1024, 1) + "K => " + | |
1655 roundNumber(body.after/1024, 1) + "K)"; | |
1656 } | |
1657 break; | |
1658 | |
1184 default: | 1659 default: |
1185 details.text = | 1660 details.text = |
1186 'Response for unknown command \'' + response.command() + '\'' + | 1661 'Response for unknown command \'' + response.command() + '\'' + |
1187 ' (' + response.raw_json() + ')'; | 1662 ' (' + response.raw_json() + ')'; |
1188 } | 1663 } |
1189 } catch (e) { | 1664 } catch (e) { |
1190 details.text = 'Error: "' + e + '" formatting response'; | 1665 details.text = 'Error: "' + e + '" formatting response'; |
1191 } | 1666 } |
1192 | 1667 |
1193 return details; | 1668 return details; |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1460 | 1935 |
1461 /** | 1936 /** |
1462 * Check is the value is a string. | 1937 * Check is the value is a string. |
1463 * @return {boolean} true if the value is a string | 1938 * @return {boolean} true if the value is a string |
1464 */ | 1939 */ |
1465 ProtocolValue.prototype.value = function() { | 1940 ProtocolValue.prototype.value = function() { |
1466 return this.value_.value; | 1941 return this.value_.value; |
1467 } | 1942 } |
1468 | 1943 |
1469 | 1944 |
1945 ProtocolValue.prototype.valueString = function() { | |
1946 return this.value_.text; | |
1947 } | |
1948 | |
1949 | |
1470 function ProtocolReference(handle) { | 1950 function ProtocolReference(handle) { |
1471 this.handle_ = handle; | 1951 this.handle_ = handle; |
1472 } | 1952 } |
1473 | 1953 |
1474 | 1954 |
1475 ProtocolReference.prototype.handle = function() { | 1955 ProtocolReference.prototype.handle = function() { |
1476 return this.handle_; | 1956 return this.handle_; |
1477 } | 1957 } |
1478 | 1958 |
1479 | 1959 |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1606 var content = []; | 2086 var content = []; |
1607 for (var key in object) { | 2087 for (var key in object) { |
1608 // Only consider string keys. | 2088 // Only consider string keys. |
1609 if (typeof key == 'string') { | 2089 if (typeof key == 'string') { |
1610 var property_value = object[key]; | 2090 var property_value = object[key]; |
1611 | 2091 |
1612 // Format the value based on its type. | 2092 // Format the value based on its type. |
1613 var property_value_json; | 2093 var property_value_json; |
1614 switch (typeof property_value) { | 2094 switch (typeof property_value) { |
1615 case 'object': | 2095 case 'object': |
1616 if (typeof property_value.toJSONProtocol == 'function') { | 2096 if (property_value === null) { |
Søren Thygesen Gjesse
2011/01/03 08:56:07
Tab.
marklam
2011/01/04 20:12:13
Done.
| |
2097 » property_value_json = 'null'; | |
2098 } else if (typeof property_value.toJSONProtocol == 'function') { | |
1617 property_value_json = property_value.toJSONProtocol(true) | 2099 property_value_json = property_value.toJSONProtocol(true) |
1618 } else if (property_value.constructor.name == 'Array'){ | 2100 } else if (property_value.constructor.name == 'Array'){ |
1619 property_value_json = SimpleArrayToJSON_(property_value); | 2101 property_value_json = SimpleArrayToJSON_(property_value); |
1620 } else { | 2102 } else { |
1621 property_value_json = SimpleObjectToJSON_(property_value); | 2103 property_value_json = SimpleObjectToJSON_(property_value); |
1622 } | 2104 } |
1623 break; | 2105 break; |
1624 | 2106 |
1625 case 'boolean': | 2107 case 'boolean': |
1626 property_value_json = BooleanToJSON_(property_value); | 2108 property_value_json = BooleanToJSON_(property_value); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1674 json += NumberToJSON_(elem); | 2156 json += NumberToJSON_(elem); |
1675 } else if (typeof(elem) === 'string') { | 2157 } else if (typeof(elem) === 'string') { |
1676 json += StringToJSON_(elem); | 2158 json += StringToJSON_(elem); |
1677 } else { | 2159 } else { |
1678 json += elem; | 2160 json += elem; |
1679 } | 2161 } |
1680 } | 2162 } |
1681 json += ']'; | 2163 json += ']'; |
1682 return json; | 2164 return json; |
1683 } | 2165 } |
OLD | NEW |