OLD | NEW |
---|---|
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
61 Normal: 2 }; | 61 Normal: 2 }; |
62 | 62 |
63 // The different types of script compilations matching enum | 63 // The different types of script compilations matching enum |
64 // Script::CompilationType in objects.h. | 64 // Script::CompilationType in objects.h. |
65 Debug.ScriptCompilationType = { Host: 0, | 65 Debug.ScriptCompilationType = { Host: 0, |
66 Eval: 1, | 66 Eval: 1, |
67 JSON: 2 }; | 67 JSON: 2 }; |
68 | 68 |
69 // The different script break point types. | 69 // The different script break point types. |
70 Debug.ScriptBreakPointType = { ScriptId: 0, | 70 Debug.ScriptBreakPointType = { ScriptId: 0, |
71 ScriptName: 1 }; | 71 ScriptName: 1, |
72 ScriptRegExp: 2 }; | |
72 | 73 |
73 function ScriptTypeFlag(type) { | 74 function ScriptTypeFlag(type) { |
74 return (1 << type); | 75 return (1 << type); |
75 } | 76 } |
76 | 77 |
77 // Globals. | 78 // Globals. |
78 var next_response_seq = 0; | 79 var next_response_seq = 0; |
79 var next_break_point_number = 1; | 80 var next_break_point_number = 1; |
80 var break_points = []; | 81 var break_points = []; |
81 var script_break_points = []; | 82 var script_break_points = []; |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
248 | 249 |
249 | 250 |
250 // Object representing a script break point. The script is referenced by its | 251 // Object representing a script break point. The script is referenced by its |
251 // script name or script id and the break point is represented as line and | 252 // script name or script id and the break point is represented as line and |
252 // column. | 253 // column. |
253 function ScriptBreakPoint(type, script_id_or_name, opt_line, opt_column, | 254 function ScriptBreakPoint(type, script_id_or_name, opt_line, opt_column, |
254 opt_groupId) { | 255 opt_groupId) { |
255 this.type_ = type; | 256 this.type_ = type; |
256 if (type == Debug.ScriptBreakPointType.ScriptId) { | 257 if (type == Debug.ScriptBreakPointType.ScriptId) { |
257 this.script_id_ = script_id_or_name; | 258 this.script_id_ = script_id_or_name; |
258 } else { // type == Debug.ScriptBreakPointType.ScriptName | 259 } else if (type == Debug.ScriptBreakPointType.ScriptName) { |
259 this.script_name_ = script_id_or_name; | 260 this.script_name_ = script_id_or_name; |
261 } else if (type == Debug.ScriptBreakPointType.ScriptRegExp) { | |
262 this.script_regexp_object_ = new RegExp(script_id_or_name); | |
263 } else { | |
264 throw new Error("Unexpected breakpoint type " + type); | |
260 } | 265 } |
261 this.line_ = opt_line || 0; | 266 this.line_ = opt_line || 0; |
262 this.column_ = opt_column; | 267 this.column_ = opt_column; |
263 this.groupId_ = opt_groupId; | 268 this.groupId_ = opt_groupId; |
264 this.hit_count_ = 0; | 269 this.hit_count_ = 0; |
265 this.active_ = true; | 270 this.active_ = true; |
266 this.condition_ = null; | 271 this.condition_ = null; |
267 this.ignoreCount_ = 0; | 272 this.ignoreCount_ = 0; |
268 this.break_points_ = []; | 273 this.break_points_ = []; |
269 } | 274 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
302 ScriptBreakPoint.prototype.script_id = function() { | 307 ScriptBreakPoint.prototype.script_id = function() { |
303 return this.script_id_; | 308 return this.script_id_; |
304 }; | 309 }; |
305 | 310 |
306 | 311 |
307 ScriptBreakPoint.prototype.script_name = function() { | 312 ScriptBreakPoint.prototype.script_name = function() { |
308 return this.script_name_; | 313 return this.script_name_; |
309 }; | 314 }; |
310 | 315 |
311 | 316 |
317 ScriptBreakPoint.prototype.script_regexp_object = function() { | |
318 return this.script_regexp_object_; | |
319 }; | |
320 | |
321 | |
312 ScriptBreakPoint.prototype.line = function() { | 322 ScriptBreakPoint.prototype.line = function() { |
313 return this.line_; | 323 return this.line_; |
314 }; | 324 }; |
315 | 325 |
316 | 326 |
317 ScriptBreakPoint.prototype.column = function() { | 327 ScriptBreakPoint.prototype.column = function() { |
318 return this.column_; | 328 return this.column_; |
319 }; | 329 }; |
320 | 330 |
321 | 331 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
377 this.break_points_[i].setIgnoreCount(ignoreCount); | 387 this.break_points_[i].setIgnoreCount(ignoreCount); |
378 } | 388 } |
379 }; | 389 }; |
380 | 390 |
381 | 391 |
382 // Check whether a script matches this script break point. Currently this is | 392 // Check whether a script matches this script break point. Currently this is |
383 // only based on script name. | 393 // only based on script name. |
384 ScriptBreakPoint.prototype.matchesScript = function(script) { | 394 ScriptBreakPoint.prototype.matchesScript = function(script) { |
385 if (this.type_ == Debug.ScriptBreakPointType.ScriptId) { | 395 if (this.type_ == Debug.ScriptBreakPointType.ScriptId) { |
386 return this.script_id_ == script.id; | 396 return this.script_id_ == script.id; |
387 } else { // this.type_ == Debug.ScriptBreakPointType.ScriptName | 397 } else { |
388 return this.script_name_ == script.nameOrSourceURL() && | 398 // We might want to account columns here as well. |
389 script.line_offset <= this.line_ && | 399 if (!(script.line_offset <= this.line_ && |
390 this.line_ < script.line_offset + script.lineCount(); | 400 this.line_ < script.line_offset + script.lineCount())) { |
401 return false; | |
402 } | |
403 if (this.type_ == Debug.ScriptBreakPointType.ScriptName) { | |
404 return this.script_name_ == script.nameOrSourceURL(); | |
405 } else if (this.type_ == Debug.ScriptBreakPointType.ScriptRegExp) { | |
406 return this.script_regexp_object_.test(script.nameOrSourceURL()); | |
407 } else { | |
408 throw new Error("Unexpected breakpoint type " + this.type_); | |
409 } | |
391 } | 410 } |
392 }; | 411 }; |
393 | 412 |
394 | 413 |
395 // Set the script break point in a script. | 414 // Set the script break point in a script. |
396 ScriptBreakPoint.prototype.set = function (script) { | 415 ScriptBreakPoint.prototype.set = function (script) { |
397 var column = this.column(); | 416 var column = this.column(); |
398 var line = this.line(); | 417 var line = this.line(); |
399 // If the column is undefined the break is on the line. To help locate the | 418 // If the column is undefined the break is on the line. To help locate the |
400 // first piece of breakable code on the line try to find the column on the | 419 // first piece of breakable code on the line try to find the column on the |
(...skipping 23 matching lines...) Expand all Loading... | |
424 | 443 |
425 // Create a break point object and set the break point. | 444 // Create a break point object and set the break point. |
426 break_point = MakeBreakPoint(position, this); | 445 break_point = MakeBreakPoint(position, this); |
427 break_point.setIgnoreCount(this.ignoreCount()); | 446 break_point.setIgnoreCount(this.ignoreCount()); |
428 var actual_position = %SetScriptBreakPoint(script, position, break_point); | 447 var actual_position = %SetScriptBreakPoint(script, position, break_point); |
429 if (IS_UNDEFINED(actual_position)) { | 448 if (IS_UNDEFINED(actual_position)) { |
430 actual_position = position; | 449 actual_position = position; |
431 } | 450 } |
432 var actual_location = script.locationFromPosition(actual_position, true); | 451 var actual_location = script.locationFromPosition(actual_position, true); |
433 break_point.actual_location = { line: actual_location.line, | 452 break_point.actual_location = { line: actual_location.line, |
434 column: actual_location.column }; | 453 column: actual_location.column, |
454 script_id: script.id }; | |
435 this.break_points_.push(break_point); | 455 this.break_points_.push(break_point); |
436 return break_point; | 456 return break_point; |
437 }; | 457 }; |
438 | 458 |
439 | 459 |
440 // Clear all the break points created from this script break point | 460 // Clear all the break points created from this script break point |
441 ScriptBreakPoint.prototype.clear = function () { | 461 ScriptBreakPoint.prototype.clear = function () { |
442 var remaining_break_points = []; | 462 var remaining_break_points = []; |
443 for (var i = 0; i < break_points.length; i++) { | 463 for (var i = 0; i < break_points.length; i++) { |
444 if (break_points[i].script_break_point() && | 464 if (break_points[i].script_break_point() && |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
637 location.line, location.column, | 657 location.line, location.column, |
638 opt_condition); | 658 opt_condition); |
639 } else { | 659 } else { |
640 // Set a break point directly on the function. | 660 // Set a break point directly on the function. |
641 var break_point = MakeBreakPoint(source_position); | 661 var break_point = MakeBreakPoint(source_position); |
642 var actual_position = | 662 var actual_position = |
643 %SetFunctionBreakPoint(func, source_position, break_point); | 663 %SetFunctionBreakPoint(func, source_position, break_point); |
644 actual_position += this.sourcePosition(func); | 664 actual_position += this.sourcePosition(func); |
645 var actual_location = script.locationFromPosition(actual_position, true); | 665 var actual_location = script.locationFromPosition(actual_position, true); |
646 break_point.actual_location = { line: actual_location.line, | 666 break_point.actual_location = { line: actual_location.line, |
647 column: actual_location.column }; | 667 column: actual_location.column, |
668 script_id: script.id }; | |
648 break_point.setCondition(opt_condition); | 669 break_point.setCondition(opt_condition); |
649 return break_point.number(); | 670 return break_point.number(); |
650 } | 671 } |
651 }; | 672 }; |
652 | 673 |
653 | 674 |
654 Debug.setBreakPointByScriptIdAndPosition = function(script_id, position, | 675 Debug.setBreakPointByScriptIdAndPosition = function(script_id, position, |
655 condition, enabled) | 676 condition, enabled) |
656 { | 677 { |
657 break_point = MakeBreakPoint(position); | 678 break_point = MakeBreakPoint(position); |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
792 | 813 |
793 Debug.setScriptBreakPointByName = function(script_name, | 814 Debug.setScriptBreakPointByName = function(script_name, |
794 opt_line, opt_column, | 815 opt_line, opt_column, |
795 opt_condition, opt_groupId) { | 816 opt_condition, opt_groupId) { |
796 return this.setScriptBreakPoint(Debug.ScriptBreakPointType.ScriptName, | 817 return this.setScriptBreakPoint(Debug.ScriptBreakPointType.ScriptName, |
797 script_name, opt_line, opt_column, | 818 script_name, opt_line, opt_column, |
798 opt_condition, opt_groupId); | 819 opt_condition, opt_groupId); |
799 } | 820 } |
800 | 821 |
801 | 822 |
823 Debug.setScriptBreakPointByRegExp = function(script_regexp, | |
824 opt_line, opt_column, | |
825 opt_condition, opt_groupId) { | |
826 return this.setScriptBreakPoint(Debug.ScriptBreakPointType.ScriptRegExp, | |
827 script_regexp, opt_line, opt_column, | |
828 opt_condition, opt_groupId); | |
829 } | |
830 | |
831 | |
802 Debug.enableScriptBreakPoint = function(break_point_number) { | 832 Debug.enableScriptBreakPoint = function(break_point_number) { |
803 var script_break_point = this.findScriptBreakPoint(break_point_number, false); | 833 var script_break_point = this.findScriptBreakPoint(break_point_number, false); |
804 script_break_point.enable(); | 834 script_break_point.enable(); |
805 }; | 835 }; |
806 | 836 |
807 | 837 |
808 Debug.disableScriptBreakPoint = function(break_point_number) { | 838 Debug.disableScriptBreakPoint = function(break_point_number) { |
809 var script_break_point = this.findScriptBreakPoint(break_point_number, false); | 839 var script_break_point = this.findScriptBreakPoint(break_point_number, false); |
810 script_break_point.disable(); | 840 script_break_point.disable(); |
811 }; | 841 }; |
(...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1542 true : request.arguments.enabled; | 1572 true : request.arguments.enabled; |
1543 var condition = request.arguments.condition; | 1573 var condition = request.arguments.condition; |
1544 var ignoreCount = request.arguments.ignoreCount; | 1574 var ignoreCount = request.arguments.ignoreCount; |
1545 var groupId = request.arguments.groupId; | 1575 var groupId = request.arguments.groupId; |
1546 | 1576 |
1547 // Check for legal arguments. | 1577 // Check for legal arguments. |
1548 if (!type || IS_UNDEFINED(target)) { | 1578 if (!type || IS_UNDEFINED(target)) { |
1549 response.failed('Missing argument "type" or "target"'); | 1579 response.failed('Missing argument "type" or "target"'); |
1550 return; | 1580 return; |
1551 } | 1581 } |
1552 if (type != 'function' && type != 'handle' && | 1582 |
1553 type != 'script' && type != 'scriptId') { | |
1554 response.failed('Illegal type "' + type + '"'); | |
1555 return; | |
1556 } | |
1557 | |
1558 // Either function or script break point. | 1583 // Either function or script break point. |
1559 var break_point_number; | 1584 var break_point_number; |
1560 if (type == 'function') { | 1585 if (type == 'function') { |
1561 // Handle function break point. | 1586 // Handle function break point. |
1562 if (!IS_STRING(target)) { | 1587 if (!IS_STRING(target)) { |
1563 response.failed('Argument "target" is not a string value'); | 1588 response.failed('Argument "target" is not a string value'); |
1564 return; | 1589 return; |
1565 } | 1590 } |
1566 var f; | 1591 var f; |
1567 try { | 1592 try { |
(...skipping 23 matching lines...) Expand all Loading... | |
1591 } | 1616 } |
1592 | 1617 |
1593 // Set function break point. | 1618 // Set function break point. |
1594 break_point_number = Debug.setBreakPoint(mirror.value(), | 1619 break_point_number = Debug.setBreakPoint(mirror.value(), |
1595 line, column, condition); | 1620 line, column, condition); |
1596 } else if (type == 'script') { | 1621 } else if (type == 'script') { |
1597 // set script break point. | 1622 // set script break point. |
1598 break_point_number = | 1623 break_point_number = |
1599 Debug.setScriptBreakPointByName(target, line, column, condition, | 1624 Debug.setScriptBreakPointByName(target, line, column, condition, |
1600 groupId); | 1625 groupId); |
1601 } else { // type == 'scriptId. | 1626 } else if (type == 'scriptId') { |
1602 break_point_number = | 1627 break_point_number = |
1603 Debug.setScriptBreakPointById(target, line, column, condition, groupId); | 1628 Debug.setScriptBreakPointById(target, line, column, condition, groupId); |
1629 } else if (type == 'scriptRegExp') { | |
1630 break_point_number = | |
1631 Debug.setScriptBreakPointByRegExp(target, line, column, condition, | |
1632 groupId); | |
1633 } else { | |
1634 response.failed('Illegal type "' + type + '"'); | |
1635 return; | |
1604 } | 1636 } |
1605 | 1637 |
1606 // Set additional break point properties. | 1638 // Set additional break point properties. |
1607 var break_point = Debug.findBreakPoint(break_point_number); | 1639 var break_point = Debug.findBreakPoint(break_point_number); |
1608 if (ignoreCount) { | 1640 if (ignoreCount) { |
1609 Debug.changeBreakPointIgnoreCount(break_point_number, ignoreCount); | 1641 Debug.changeBreakPointIgnoreCount(break_point_number, ignoreCount); |
1610 } | 1642 } |
1611 if (!enabled) { | 1643 if (!enabled) { |
1612 Debug.disableBreakPoint(break_point_number); | 1644 Debug.disableBreakPoint(break_point_number); |
1613 } | 1645 } |
1614 | 1646 |
1615 // Add the break point number to the response. | 1647 // Add the break point number to the response. |
1616 response.body = { type: type, | 1648 response.body = { type: type, |
1617 breakpoint: break_point_number } | 1649 breakpoint: break_point_number } |
1618 | 1650 |
1619 // Add break point information to the response. | 1651 // Add break point information to the response. |
1620 if (break_point instanceof ScriptBreakPoint) { | 1652 if (break_point instanceof ScriptBreakPoint) { |
1621 if (break_point.type() == Debug.ScriptBreakPointType.ScriptId) { | 1653 if (break_point.type() == Debug.ScriptBreakPointType.ScriptId) { |
1622 response.body.type = 'scriptId'; | 1654 response.body.type = 'scriptId'; |
1623 response.body.script_id = break_point.script_id(); | 1655 response.body.script_id = break_point.script_id(); |
1624 } else { | 1656 } else if (break_point.type() == Debug.ScriptBreakPointType.ScriptName) { |
1625 response.body.type = 'scriptName'; | 1657 response.body.type = 'scriptName'; |
1626 response.body.script_name = break_point.script_name(); | 1658 response.body.script_name = break_point.script_name(); |
1659 } else if (break_point.type() == Debug.ScriptBreakPointType.ScriptRegExp) { | |
1660 response.body.type = 'scriptRegExp'; | |
1661 response.body.script_regexp = break_point.script_regexp_object().source; | |
1662 } else { | |
1663 throw new Error("Unexpected breakpoint type: " + break_point.type()); | |
Søren Thygesen Gjesse
2011/06/21 08:04:40
Maybe this message should start with "Internal err
Peter Rybin
2011/06/21 19:18:30
Good point.
Done.
| |
1627 } | 1664 } |
1628 response.body.line = break_point.line(); | 1665 response.body.line = break_point.line(); |
1629 response.body.column = break_point.column(); | 1666 response.body.column = break_point.column(); |
1630 response.body.actual_locations = break_point.actual_locations(); | 1667 response.body.actual_locations = break_point.actual_locations(); |
1631 } else { | 1668 } else { |
1632 response.body.type = 'function'; | 1669 response.body.type = 'function'; |
1633 response.body.actual_locations = [break_point.actual_location]; | 1670 response.body.actual_locations = [break_point.actual_location]; |
1634 } | 1671 } |
1635 }; | 1672 }; |
1636 | 1673 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1746 hit_count: break_point.hit_count(), | 1783 hit_count: break_point.hit_count(), |
1747 active: break_point.active(), | 1784 active: break_point.active(), |
1748 condition: break_point.condition(), | 1785 condition: break_point.condition(), |
1749 ignoreCount: break_point.ignoreCount(), | 1786 ignoreCount: break_point.ignoreCount(), |
1750 actual_locations: break_point.actual_locations() | 1787 actual_locations: break_point.actual_locations() |
1751 } | 1788 } |
1752 | 1789 |
1753 if (break_point.type() == Debug.ScriptBreakPointType.ScriptId) { | 1790 if (break_point.type() == Debug.ScriptBreakPointType.ScriptId) { |
1754 description.type = 'scriptId'; | 1791 description.type = 'scriptId'; |
1755 description.script_id = break_point.script_id(); | 1792 description.script_id = break_point.script_id(); |
1756 } else { | 1793 } else if (break_point.type() == Debug.ScriptBreakPointType.ScriptName) { |
1757 description.type = 'scriptName'; | 1794 description.type = 'scriptName'; |
1758 description.script_name = break_point.script_name(); | 1795 description.script_name = break_point.script_name(); |
1796 } else if (break_point.type() == Debug.ScriptBreakPointType.ScriptRegExp) { | |
1797 description.type = 'scriptRegExp'; | |
1798 description.script_regexp = break_point.script_regexp_object().source; | |
1799 } else { | |
1800 throw new Error("Unexpected breakpoint type: " + break_point.type()); | |
Søren Thygesen Gjesse
2011/06/21 08:04:40
Ditto.
Peter Rybin
2011/06/21 19:18:30
Done.
| |
1759 } | 1801 } |
1760 array.push(description); | 1802 array.push(description); |
1761 } | 1803 } |
1762 | 1804 |
1763 response.body = { | 1805 response.body = { |
1764 breakpoints: array, | 1806 breakpoints: array, |
1765 breakOnExceptions: Debug.isBreakOnException(), | 1807 breakOnExceptions: Debug.isBreakOnException(), |
1766 breakOnUncaughtExceptions: Debug.isBreakOnUncaughtException() | 1808 breakOnUncaughtExceptions: Debug.isBreakOnUncaughtException() |
1767 } | 1809 } |
1768 } | 1810 } |
(...skipping 791 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2560 case 'string': | 2602 case 'string': |
2561 case 'number': | 2603 case 'number': |
2562 json = value; | 2604 json = value; |
2563 break | 2605 break |
2564 | 2606 |
2565 default: | 2607 default: |
2566 json = null; | 2608 json = null; |
2567 } | 2609 } |
2568 return json; | 2610 return json; |
2569 } | 2611 } |
OLD | NEW |