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

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

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