Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(521)

Side by Side Diff: src/debug-debugger.js

Issue 18349004: Debug: support breakpoints set in the middle of statement (try #2 after rollback) (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/debug.cc ('k') | src/runtime.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 ScriptRegExp: 2 };
73 73
74 // The different types of breakpoint position alignments.
75 // Must match BreakPositionAlignment in debug.h.
76 Debug.BreakPositionAlignment = {
77 Statement: 0,
78 BreakPosition: 1
79 };
80
74 function ScriptTypeFlag(type) { 81 function ScriptTypeFlag(type) {
75 return (1 << type); 82 return (1 << type);
76 } 83 }
77 84
78 // Globals. 85 // Globals.
79 var next_response_seq = 0; 86 var next_response_seq = 0;
80 var next_break_point_number = 1; 87 var next_break_point_number = 1;
81 var break_points = []; 88 var break_points = [];
82 var script_break_points = []; 89 var script_break_points = [];
83 var debugger_flags = { 90 var debugger_flags = {
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 // the break point is triggered and supposed to break execution. 251 // the break point is triggered and supposed to break execution.
245 function IsBreakPointTriggered(break_id, break_point) { 252 function IsBreakPointTriggered(break_id, break_point) {
246 return break_point.isTriggered(MakeExecutionState(break_id)); 253 return break_point.isTriggered(MakeExecutionState(break_id));
247 } 254 }
248 255
249 256
250 // Object representing a script break point. The script is referenced by its 257 // 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 258 // script name or script id and the break point is represented as line and
252 // column. 259 // column.
253 function ScriptBreakPoint(type, script_id_or_name, opt_line, opt_column, 260 function ScriptBreakPoint(type, script_id_or_name, opt_line, opt_column,
254 opt_groupId) { 261 opt_groupId, opt_position_alignment) {
255 this.type_ = type; 262 this.type_ = type;
256 if (type == Debug.ScriptBreakPointType.ScriptId) { 263 if (type == Debug.ScriptBreakPointType.ScriptId) {
257 this.script_id_ = script_id_or_name; 264 this.script_id_ = script_id_or_name;
258 } else if (type == Debug.ScriptBreakPointType.ScriptName) { 265 } else if (type == Debug.ScriptBreakPointType.ScriptName) {
259 this.script_name_ = script_id_or_name; 266 this.script_name_ = script_id_or_name;
260 } else if (type == Debug.ScriptBreakPointType.ScriptRegExp) { 267 } else if (type == Debug.ScriptBreakPointType.ScriptRegExp) {
261 this.script_regexp_object_ = new RegExp(script_id_or_name); 268 this.script_regexp_object_ = new RegExp(script_id_or_name);
262 } else { 269 } else {
263 throw new Error("Unexpected breakpoint type " + type); 270 throw new Error("Unexpected breakpoint type " + type);
264 } 271 }
265 this.line_ = opt_line || 0; 272 this.line_ = opt_line || 0;
266 this.column_ = opt_column; 273 this.column_ = opt_column;
267 this.groupId_ = opt_groupId; 274 this.groupId_ = opt_groupId;
275 this.position_alignment_ = IS_UNDEFINED(opt_position_alignment)
276 ? Debug.BreakPositionAlignment.Statement : opt_position_alignment;
268 this.hit_count_ = 0; 277 this.hit_count_ = 0;
269 this.active_ = true; 278 this.active_ = true;
270 this.condition_ = null; 279 this.condition_ = null;
271 this.ignoreCount_ = 0; 280 this.ignoreCount_ = 0;
272 this.break_points_ = []; 281 this.break_points_ = [];
273 } 282 }
274 283
275 284
276 //Creates a clone of script breakpoint that is linked to another script. 285 //Creates a clone of script breakpoint that is linked to another script.
277 ScriptBreakPoint.prototype.cloneForOtherScript = function (other_script) { 286 ScriptBreakPoint.prototype.cloneForOtherScript = function (other_script) {
278 var copy = new ScriptBreakPoint(Debug.ScriptBreakPointType.ScriptId, 287 var copy = new ScriptBreakPoint(Debug.ScriptBreakPointType.ScriptId,
279 other_script.id, this.line_, this.column_, this.groupId_); 288 other_script.id, this.line_, this.column_, this.groupId_,
289 this.position_alignment_);
280 copy.number_ = next_break_point_number++; 290 copy.number_ = next_break_point_number++;
281 script_break_points.push(copy); 291 script_break_points.push(copy);
282 292
283 copy.hit_count_ = this.hit_count_; 293 copy.hit_count_ = this.hit_count_;
284 copy.active_ = this.active_; 294 copy.active_ = this.active_;
285 copy.condition_ = this.condition_; 295 copy.condition_ = this.condition_;
286 copy.ignoreCount_ = this.ignoreCount_; 296 copy.ignoreCount_ = this.ignoreCount_;
287 return copy; 297 return copy;
288 }; 298 };
289 299
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 // Convert the line and column into an absolute position within the script. 446 // Convert the line and column into an absolute position within the script.
437 var position = Debug.findScriptSourcePosition(script, this.line(), column); 447 var position = Debug.findScriptSourcePosition(script, this.line(), column);
438 448
439 // If the position is not found in the script (the script might be shorter 449 // If the position is not found in the script (the script might be shorter
440 // than it used to be) just ignore it. 450 // than it used to be) just ignore it.
441 if (position === null) return; 451 if (position === null) return;
442 452
443 // Create a break point object and set the break point. 453 // Create a break point object and set the break point.
444 break_point = MakeBreakPoint(position, this); 454 break_point = MakeBreakPoint(position, this);
445 break_point.setIgnoreCount(this.ignoreCount()); 455 break_point.setIgnoreCount(this.ignoreCount());
446 var actual_position = %SetScriptBreakPoint(script, position, break_point); 456 var actual_position = %SetScriptBreakPoint(script, position,
457 this.position_alignment_,
458 break_point);
447 if (IS_UNDEFINED(actual_position)) { 459 if (IS_UNDEFINED(actual_position)) {
448 actual_position = position; 460 actual_position = position;
449 } 461 }
450 var actual_location = script.locationFromPosition(actual_position, true); 462 var actual_location = script.locationFromPosition(actual_position, true);
451 break_point.actual_location = { line: actual_location.line, 463 break_point.actual_location = { line: actual_location.line,
452 column: actual_location.column, 464 column: actual_location.column,
453 script_id: script.id }; 465 script_id: script.id };
454 this.break_points_.push(break_point); 466 this.break_points_.push(break_point);
455 return break_point; 467 return break_point;
456 }; 468 };
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 throw new Error('Parameters have wrong types.'); 514 throw new Error('Parameters have wrong types.');
503 } 515 }
504 %SetDebugEventListener(listener, opt_data); 516 %SetDebugEventListener(listener, opt_data);
505 }; 517 };
506 518
507 519
508 Debug.breakExecution = function(f) { 520 Debug.breakExecution = function(f) {
509 %Break(); 521 %Break();
510 }; 522 };
511 523
512 Debug.breakLocations = function(f) { 524 Debug.breakLocations = function(f, opt_position_aligment) {
513 if (!IS_FUNCTION(f)) throw new Error('Parameters have wrong types.'); 525 if (!IS_FUNCTION(f)) throw new Error('Parameters have wrong types.');
514 return %GetBreakLocations(f); 526 var position_aligment = IS_UNDEFINED(opt_position_aligment)
527 ? Debug.BreakPositionAlignment.Statement : opt_position_aligment;
528 return %GetBreakLocations(f, position_aligment);
515 }; 529 };
516 530
517 // Returns a Script object. If the parameter is a function the return value 531 // Returns a Script object. If the parameter is a function the return value
518 // is the script in which the function is defined. If the parameter is a string 532 // is the script in which the function is defined. If the parameter is a string
519 // the return value is the script for which the script name has that string 533 // the return value is the script for which the script name has that string
520 // value. If it is a regexp and there is a unique script whose name matches 534 // value. If it is a regexp and there is a unique script whose name matches
521 // we return that, otherwise undefined. 535 // we return that, otherwise undefined.
522 Debug.findScript = function(func_or_script_name) { 536 Debug.findScript = function(func_or_script_name) {
523 if (IS_FUNCTION(func_or_script_name)) { 537 if (IS_FUNCTION(func_or_script_name)) {
524 return %FunctionGetScript(func_or_script_name); 538 return %FunctionGetScript(func_or_script_name);
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 break_point.actual_location = { line: actual_location.line, 681 break_point.actual_location = { line: actual_location.line,
668 column: actual_location.column, 682 column: actual_location.column,
669 script_id: script.id }; 683 script_id: script.id };
670 break_point.setCondition(opt_condition); 684 break_point.setCondition(opt_condition);
671 return break_point.number(); 685 return break_point.number();
672 } 686 }
673 }; 687 };
674 688
675 689
676 Debug.setBreakPointByScriptIdAndPosition = function(script_id, position, 690 Debug.setBreakPointByScriptIdAndPosition = function(script_id, position,
677 condition, enabled) 691 condition, enabled,
692 opt_position_alignment)
678 { 693 {
679 break_point = MakeBreakPoint(position); 694 break_point = MakeBreakPoint(position);
680 break_point.setCondition(condition); 695 break_point.setCondition(condition);
681 if (!enabled) { 696 if (!enabled) {
682 break_point.disable(); 697 break_point.disable();
683 } 698 }
684 var scripts = this.scripts(); 699 var scripts = this.scripts();
700 var position_alignment = IS_UNDEFINED(opt_position_alignment)
701 ? Debug.BreakPositionAlignment.Statement : opt_position_alignment;
685 for (var i = 0; i < scripts.length; i++) { 702 for (var i = 0; i < scripts.length; i++) {
686 if (script_id == scripts[i].id) { 703 if (script_id == scripts[i].id) {
687 break_point.actual_position = %SetScriptBreakPoint(scripts[i], position, 704 break_point.actual_position = %SetScriptBreakPoint(scripts[i], position,
688 break_point); 705 position_alignment, break_point);
689 break; 706 break;
690 } 707 }
691 } 708 }
692 return break_point; 709 return break_point;
693 }; 710 };
694 711
695 712
696 Debug.enableBreakPoint = function(break_point_number) { 713 Debug.enableBreakPoint = function(break_point_number) {
697 var break_point = this.findBreakPoint(break_point_number, false); 714 var break_point = this.findBreakPoint(break_point_number, false);
698 // Only enable if the breakpoint hasn't been deleted: 715 // Only enable if the breakpoint hasn't been deleted:
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
773 } 790 }
774 } 791 }
775 return script_break_point; 792 return script_break_point;
776 }; 793 };
777 794
778 795
779 // Sets a breakpoint in a script identified through id or name at the 796 // Sets a breakpoint in a script identified through id or name at the
780 // specified source line and column within that line. 797 // specified source line and column within that line.
781 Debug.setScriptBreakPoint = function(type, script_id_or_name, 798 Debug.setScriptBreakPoint = function(type, script_id_or_name,
782 opt_line, opt_column, opt_condition, 799 opt_line, opt_column, opt_condition,
783 opt_groupId) { 800 opt_groupId, opt_position_alignment) {
784 // Create script break point object. 801 // Create script break point object.
785 var script_break_point = 802 var script_break_point =
786 new ScriptBreakPoint(type, script_id_or_name, opt_line, opt_column, 803 new ScriptBreakPoint(type, script_id_or_name, opt_line, opt_column,
787 opt_groupId); 804 opt_groupId, opt_position_alignment);
788 805
789 // Assign number to the new script break point and add it. 806 // Assign number to the new script break point and add it.
790 script_break_point.number_ = next_break_point_number++; 807 script_break_point.number_ = next_break_point_number++;
791 script_break_point.setCondition(opt_condition); 808 script_break_point.setCondition(opt_condition);
792 script_break_points.push(script_break_point); 809 script_break_points.push(script_break_point);
793 810
794 // Run through all scripts to see if this script break point matches any 811 // Run through all scripts to see if this script break point matches any
795 // loaded scripts. 812 // loaded scripts.
796 var scripts = this.scripts(); 813 var scripts = this.scripts();
797 for (var i = 0; i < scripts.length; i++) { 814 for (var i = 0; i < scripts.length; i++) {
798 if (script_break_point.matchesScript(scripts[i])) { 815 if (script_break_point.matchesScript(scripts[i])) {
799 script_break_point.set(scripts[i]); 816 script_break_point.set(scripts[i]);
800 } 817 }
801 } 818 }
802 819
803 return script_break_point.number(); 820 return script_break_point.number();
804 }; 821 };
805 822
806 823
807 Debug.setScriptBreakPointById = function(script_id, 824 Debug.setScriptBreakPointById = function(script_id,
808 opt_line, opt_column, 825 opt_line, opt_column,
809 opt_condition, opt_groupId) { 826 opt_condition, opt_groupId,
827 opt_position_alignment) {
810 return this.setScriptBreakPoint(Debug.ScriptBreakPointType.ScriptId, 828 return this.setScriptBreakPoint(Debug.ScriptBreakPointType.ScriptId,
811 script_id, opt_line, opt_column, 829 script_id, opt_line, opt_column,
812 opt_condition, opt_groupId); 830 opt_condition, opt_groupId,
831 opt_position_alignment);
813 }; 832 };
814 833
815 834
816 Debug.setScriptBreakPointByName = function(script_name, 835 Debug.setScriptBreakPointByName = function(script_name,
817 opt_line, opt_column, 836 opt_line, opt_column,
818 opt_condition, opt_groupId) { 837 opt_condition, opt_groupId) {
819 return this.setScriptBreakPoint(Debug.ScriptBreakPointType.ScriptName, 838 return this.setScriptBreakPoint(Debug.ScriptBreakPointType.ScriptName,
820 script_name, opt_line, opt_column, 839 script_name, opt_line, opt_column,
821 opt_condition, opt_groupId); 840 opt_condition, opt_groupId);
822 }; 841 };
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
886 }; 905 };
887 906
888 Debug.clearBreakOnUncaughtException = function() { 907 Debug.clearBreakOnUncaughtException = function() {
889 return %ChangeBreakOnException(Debug.ExceptionBreak.Uncaught, false); 908 return %ChangeBreakOnException(Debug.ExceptionBreak.Uncaught, false);
890 }; 909 };
891 910
892 Debug.isBreakOnUncaughtException = function() { 911 Debug.isBreakOnUncaughtException = function() {
893 return !!%IsBreakOnException(Debug.ExceptionBreak.Uncaught); 912 return !!%IsBreakOnException(Debug.ExceptionBreak.Uncaught);
894 }; 913 };
895 914
896 Debug.showBreakPoints = function(f, full) { 915 Debug.showBreakPoints = function(f, full, opt_position_alignment) {
897 if (!IS_FUNCTION(f)) throw new Error('Parameters have wrong types.'); 916 if (!IS_FUNCTION(f)) throw new Error('Parameters have wrong types.');
898 var source = full ? this.scriptSource(f) : this.source(f); 917 var source = full ? this.scriptSource(f) : this.source(f);
899 var offset = full ? this.sourcePosition(f) : 0; 918 var offset = full ? this.sourcePosition(f) : 0;
900 var locations = this.breakLocations(f); 919 var locations = this.breakLocations(f, opt_position_alignment);
901 if (!locations) return source; 920 if (!locations) return source;
902 locations.sort(function(x, y) { return x - y; }); 921 locations.sort(function(x, y) { return x - y; });
903 var result = ""; 922 var result = "";
904 var prev_pos = 0; 923 var prev_pos = 0;
905 var pos; 924 var pos;
906 for (var i = 0; i < locations.length; i++) { 925 for (var i = 0; i < locations.length; i++) {
907 pos = locations[i] - offset; 926 pos = locations[i] - offset;
908 result += source.slice(prev_pos, pos); 927 result += source.slice(prev_pos, pos);
909 result += "[B" + i + "]"; 928 result += "[B" + i + "]";
910 prev_pos = pos; 929 prev_pos = pos;
(...skipping 1713 matching lines...) Expand 10 before | Expand all | Expand 10 after
2624 2643
2625 default: 2644 default:
2626 json = null; 2645 json = null;
2627 } 2646 }
2628 return json; 2647 return json;
2629 } 2648 }
2630 2649
2631 Debug.TestApi = { 2650 Debug.TestApi = {
2632 CommandProcessorResolveValue: DebugCommandProcessor.resolveValue_ 2651 CommandProcessorResolveValue: DebugCommandProcessor.resolveValue_
2633 }; 2652 };
OLDNEW
« no previous file with comments | « src/debug.cc ('k') | src/runtime.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698