| 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 var next_break_point_number = 1; | 68 var next_break_point_number = 1; |
| 69 var break_points = []; | 69 var break_points = []; |
| 70 var script_break_points = []; | 70 var script_break_points = []; |
| 71 | 71 |
| 72 | 72 |
| 73 // Create a new break point object and add it to the list of break points. | 73 // Create a new break point object and add it to the list of break points. |
| 74 function MakeBreakPoint(source_position, opt_line, opt_column, opt_script_break_
point) { | 74 function MakeBreakPoint(source_position, opt_line, opt_column, opt_script_break_
point) { |
| 75 var break_point = new BreakPoint(source_position, opt_line, opt_column, opt_sc
ript_break_point); | 75 var break_point = new BreakPoint(source_position, opt_line, opt_column, opt_sc
ript_break_point); |
| 76 break_points.push(break_point); | 76 break_points.push(break_point); |
| 77 return break_point; | 77 return break_point; |
| 78 }; | 78 } |
| 79 | 79 |
| 80 | 80 |
| 81 // Object representing a break point. | 81 // Object representing a break point. |
| 82 // NOTE: This object does not have a reference to the function having break | 82 // NOTE: This object does not have a reference to the function having break |
| 83 // point as this would cause function not to be garbage collected when it is | 83 // point as this would cause function not to be garbage collected when it is |
| 84 // not used any more. We do not want break points to keep functions alive. | 84 // not used any more. We do not want break points to keep functions alive. |
| 85 function BreakPoint(source_position, opt_line, opt_column, opt_script_break_poin
t) { | 85 function BreakPoint(source_position, opt_line, opt_column, opt_script_break_poin
t) { |
| 86 this.source_position_ = source_position; | 86 this.source_position_ = source_position; |
| 87 this.source_line_ = opt_line; | 87 this.source_line_ = opt_line; |
| 88 this.source_column_ = opt_column; | 88 this.source_column_ = opt_column; |
| 89 if (opt_script_break_point) { | 89 if (opt_script_break_point) { |
| 90 this.script_break_point_ = opt_script_break_point; | 90 this.script_break_point_ = opt_script_break_point; |
| 91 } else { | 91 } else { |
| 92 this.number_ = next_break_point_number++; | 92 this.number_ = next_break_point_number++; |
| 93 } | 93 } |
| 94 this.hit_count_ = 0; | 94 this.hit_count_ = 0; |
| 95 this.active_ = true; | 95 this.active_ = true; |
| 96 this.condition_ = null; | 96 this.condition_ = null; |
| 97 this.ignoreCount_ = 0; | 97 this.ignoreCount_ = 0; |
| 98 }; | 98 } |
| 99 | 99 |
| 100 | 100 |
| 101 BreakPoint.prototype.number = function() { | 101 BreakPoint.prototype.number = function() { |
| 102 return this.number_; | 102 return this.number_; |
| 103 }; | 103 }; |
| 104 | 104 |
| 105 | 105 |
| 106 BreakPoint.prototype.func = function() { | 106 BreakPoint.prototype.func = function() { |
| 107 return this.func_; | 107 return this.func_; |
| 108 }; | 108 }; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 | 197 |
| 198 // Break point triggered. | 198 // Break point triggered. |
| 199 return true; | 199 return true; |
| 200 }; | 200 }; |
| 201 | 201 |
| 202 | 202 |
| 203 // Function called from the runtime when a break point is hit. Returns true if | 203 // Function called from the runtime when a break point is hit. Returns true if |
| 204 // the break point is triggered and supposed to break execution. | 204 // the break point is triggered and supposed to break execution. |
| 205 function IsBreakPointTriggered(break_id, break_point) { | 205 function IsBreakPointTriggered(break_id, break_point) { |
| 206 return break_point.isTriggered(MakeExecutionState(break_id)); | 206 return break_point.isTriggered(MakeExecutionState(break_id)); |
| 207 }; | 207 } |
| 208 | 208 |
| 209 | 209 |
| 210 // Object representing a script break point. The script is referenced by its | 210 // Object representing a script break point. The script is referenced by its |
| 211 // script name and the break point is represented as line and column. | 211 // script name and the break point is represented as line and column. |
| 212 function ScriptBreakPoint(script_name, opt_line, opt_column) { | 212 function ScriptBreakPoint(script_name, opt_line, opt_column) { |
| 213 this.script_name_ = script_name; | 213 this.script_name_ = script_name; |
| 214 this.line_ = opt_line || 0; | 214 this.line_ = opt_line || 0; |
| 215 this.column_ = opt_column; | 215 this.column_ = opt_column; |
| 216 this.hit_count_ = 0; | 216 this.hit_count_ = 0; |
| 217 this.active_ = true; | 217 this.active_ = true; |
| 218 this.condition_ = null; | 218 this.condition_ = null; |
| 219 this.ignoreCount_ = 0; | 219 this.ignoreCount_ = 0; |
| 220 }; | 220 } |
| 221 | 221 |
| 222 | 222 |
| 223 ScriptBreakPoint.prototype.number = function() { | 223 ScriptBreakPoint.prototype.number = function() { |
| 224 return this.number_; | 224 return this.number_; |
| 225 }; | 225 }; |
| 226 | 226 |
| 227 | 227 |
| 228 ScriptBreakPoint.prototype.script_name = function() { | 228 ScriptBreakPoint.prototype.script_name = function() { |
| 229 return this.script_name_; | 229 return this.script_name_; |
| 230 }; | 230 }; |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 | 347 |
| 348 | 348 |
| 349 // Function called from runtime when a new script is compiled to set any script | 349 // Function called from runtime when a new script is compiled to set any script |
| 350 // break points set in this script. | 350 // break points set in this script. |
| 351 function UpdateScriptBreakPoints(script) { | 351 function UpdateScriptBreakPoints(script) { |
| 352 for (var i = 0; i < script_break_points.length; i++) { | 352 for (var i = 0; i < script_break_points.length; i++) { |
| 353 if (script_break_points[i].script_name() == script.name) { | 353 if (script_break_points[i].script_name() == script.name) { |
| 354 script_break_points[i].set(script); | 354 script_break_points[i].set(script); |
| 355 } | 355 } |
| 356 } | 356 } |
| 357 }; | 357 } |
| 358 | 358 |
| 359 | 359 |
| 360 // Function called from the runtime to handle a debug request receiced from the | 360 // Function called from the runtime to handle a debug request receiced from the |
| 361 // debugger. When this function is called the debugger is in the broken state | 361 // debugger. When this function is called the debugger is in the broken state |
| 362 // reflected by the exec_state parameter. When pending requests are handled the | 362 // reflected by the exec_state parameter. When pending requests are handled the |
| 363 // parameter stopping indicate the expected running state. | 363 // parameter stopping indicate the expected running state. |
| 364 function ProcessDebugRequest(exec_state, request, stopping) { | 364 function ProcessDebugRequest(exec_state, request, stopping) { |
| 365 return exec_state.debugCommandProcessor().processDebugJSONRequest(request, sto
pping); | 365 return exec_state.debugCommandProcessor().processDebugJSONRequest(request, sto
pping); |
| 366 } | 366 } |
| 367 | 367 |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 669 | 669 |
| 670 // Get all the scripts currently loaded. Locating all the scripts is based on | 670 // Get all the scripts currently loaded. Locating all the scripts is based on |
| 671 // scanning the heap. | 671 // scanning the heap. |
| 672 Debug.scripts = function() { | 672 Debug.scripts = function() { |
| 673 // Collect all scripts in the heap. | 673 // Collect all scripts in the heap. |
| 674 return %DebugGetLoadedScripts(); | 674 return %DebugGetLoadedScripts(); |
| 675 } | 675 } |
| 676 | 676 |
| 677 function MakeExecutionState(break_id) { | 677 function MakeExecutionState(break_id) { |
| 678 return new ExecutionState(break_id); | 678 return new ExecutionState(break_id); |
| 679 }; | 679 } |
| 680 | 680 |
| 681 function ExecutionState(break_id) { | 681 function ExecutionState(break_id) { |
| 682 this.break_id = break_id; | 682 this.break_id = break_id; |
| 683 this.selected_frame = 0; | 683 this.selected_frame = 0; |
| 684 }; | 684 } |
| 685 | 685 |
| 686 ExecutionState.prototype.prepareStep = function(opt_action, opt_count) { | 686 ExecutionState.prototype.prepareStep = function(opt_action, opt_count) { |
| 687 var action = Debug.StepAction.StepIn; | 687 var action = Debug.StepAction.StepIn; |
| 688 if (!IS_UNDEFINED(opt_action)) action = %ToNumber(opt_action); | 688 if (!IS_UNDEFINED(opt_action)) action = %ToNumber(opt_action); |
| 689 var count = opt_count ? %ToNumber(opt_count) : 1; | 689 var count = opt_count ? %ToNumber(opt_count) : 1; |
| 690 | 690 |
| 691 return %PrepareStep(this.break_id, action, count); | 691 return %PrepareStep(this.break_id, action, count); |
| 692 } | 692 } |
| 693 | 693 |
| 694 ExecutionState.prototype.evaluateGlobal = function(source, disable_break) { | 694 ExecutionState.prototype.evaluateGlobal = function(source, disable_break) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 720 return this.selected_frame; | 720 return this.selected_frame; |
| 721 }; | 721 }; |
| 722 | 722 |
| 723 ExecutionState.prototype.debugCommandProcessor = function(protocol) { | 723 ExecutionState.prototype.debugCommandProcessor = function(protocol) { |
| 724 return new DebugCommandProcessor(this, protocol); | 724 return new DebugCommandProcessor(this, protocol); |
| 725 }; | 725 }; |
| 726 | 726 |
| 727 | 727 |
| 728 function MakeBreakEvent(exec_state, break_points_hit) { | 728 function MakeBreakEvent(exec_state, break_points_hit) { |
| 729 return new BreakEvent(exec_state, break_points_hit); | 729 return new BreakEvent(exec_state, break_points_hit); |
| 730 }; | 730 } |
| 731 | 731 |
| 732 | 732 |
| 733 function BreakEvent(exec_state, break_points_hit) { | 733 function BreakEvent(exec_state, break_points_hit) { |
| 734 this.exec_state_ = exec_state; | 734 this.exec_state_ = exec_state; |
| 735 this.break_points_hit_ = break_points_hit; | 735 this.break_points_hit_ = break_points_hit; |
| 736 }; | 736 } |
| 737 | 737 |
| 738 | 738 |
| 739 BreakEvent.prototype.func = function() { | 739 BreakEvent.prototype.func = function() { |
| 740 return this.exec_state_.frame(0).func(); | 740 return this.exec_state_.frame(0).func(); |
| 741 }; | 741 }; |
| 742 | 742 |
| 743 | 743 |
| 744 BreakEvent.prototype.sourceLine = function() { | 744 BreakEvent.prototype.sourceLine = function() { |
| 745 return this.exec_state_.frame(0).sourceLine(); | 745 return this.exec_state_.frame(0).sourceLine(); |
| 746 }; | 746 }; |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 839 o.body.breakpoints.push(number); | 839 o.body.breakpoints.push(number); |
| 840 } | 840 } |
| 841 } | 841 } |
| 842 | 842 |
| 843 return SimpleObjectToJSON_(o); | 843 return SimpleObjectToJSON_(o); |
| 844 }; | 844 }; |
| 845 | 845 |
| 846 | 846 |
| 847 function MakeExceptionEvent(exec_state, exception, uncaught) { | 847 function MakeExceptionEvent(exec_state, exception, uncaught) { |
| 848 return new ExceptionEvent(exec_state, exception, uncaught); | 848 return new ExceptionEvent(exec_state, exception, uncaught); |
| 849 }; | 849 } |
| 850 | 850 |
| 851 function ExceptionEvent(exec_state, exception, uncaught) { | 851 function ExceptionEvent(exec_state, exception, uncaught) { |
| 852 this.exec_state_ = exec_state; | 852 this.exec_state_ = exec_state; |
| 853 this.exception_ = exception; | 853 this.exception_ = exception; |
| 854 this.uncaught_ = uncaught; | 854 this.uncaught_ = uncaught; |
| 855 }; | 855 } |
| 856 | 856 |
| 857 ExceptionEvent.prototype.uncaught = function() { | 857 ExceptionEvent.prototype.uncaught = function() { |
| 858 return this.uncaught_; | 858 return this.uncaught_; |
| 859 } | 859 } |
| 860 | 860 |
| 861 ExceptionEvent.prototype.func = function() { | 861 ExceptionEvent.prototype.func = function() { |
| 862 return this.exec_state_.frame(0).func(); | 862 return this.exec_state_.frame(0).func(); |
| 863 }; | 863 }; |
| 864 | 864 |
| 865 | 865 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 924 columnOffset: script.columnOffset(), | 924 columnOffset: script.columnOffset(), |
| 925 lineCount: script.lineCount() | 925 lineCount: script.lineCount() |
| 926 }; | 926 }; |
| 927 } | 927 } |
| 928 | 928 |
| 929 return SimpleObjectToJSON_(o); | 929 return SimpleObjectToJSON_(o); |
| 930 }; | 930 }; |
| 931 | 931 |
| 932 function MakeCompileEvent(script_source, script_name, script_function) { | 932 function MakeCompileEvent(script_source, script_name, script_function) { |
| 933 return new CompileEvent(script_source, script_name, script_function); | 933 return new CompileEvent(script_source, script_name, script_function); |
| 934 }; | 934 } |
| 935 | 935 |
| 936 function CompileEvent(script_source, script_name, script_function) { | 936 function CompileEvent(script_source, script_name, script_function) { |
| 937 this.scriptSource = script_source; | 937 this.scriptSource = script_source; |
| 938 this.scriptName = script_name; | 938 this.scriptName = script_name; |
| 939 this.scriptFunction = script_function; | 939 this.scriptFunction = script_function; |
| 940 }; | 940 } |
| 941 | 941 |
| 942 CompileEvent.prototype.details = function() { | 942 CompileEvent.prototype.details = function() { |
| 943 var result = ""; | 943 var result = ""; |
| 944 result = "Script added" | 944 result = "Script added" |
| 945 if (this.scriptData) { | 945 if (this.scriptData) { |
| 946 result += ": '"; | 946 result += ": '"; |
| 947 result += this.scriptData; | 947 result += this.scriptData; |
| 948 result += "'"; | 948 result += "'"; |
| 949 } | 949 } |
| 950 return result; | 950 return result; |
| 951 }; | 951 }; |
| 952 | 952 |
| 953 CompileEvent.prototype.debugPrompt = function() { | 953 CompileEvent.prototype.debugPrompt = function() { |
| 954 var result = "source" | 954 var result = "source" |
| 955 if (this.scriptData) { | 955 if (this.scriptData) { |
| 956 result += " '"; | 956 result += " '"; |
| 957 result += this.scriptData; | 957 result += this.scriptData; |
| 958 result += "'"; | 958 result += "'"; |
| 959 } | 959 } |
| 960 if (this.func) { | 960 if (this.func) { |
| 961 result += " added"; | 961 result += " added"; |
| 962 } else { | 962 } else { |
| 963 result += " compiled"; | 963 result += " compiled"; |
| 964 } | 964 } |
| 965 return result; | 965 return result; |
| 966 }; | 966 }; |
| 967 | 967 |
| 968 function MakeNewFunctionEvent(func) { | 968 function MakeNewFunctionEvent(func) { |
| 969 return new NewFunctionEvent(func); | 969 return new NewFunctionEvent(func); |
| 970 }; | 970 } |
| 971 | 971 |
| 972 function NewFunctionEvent(func) { | 972 function NewFunctionEvent(func) { |
| 973 this.func = func; | 973 this.func = func; |
| 974 }; | 974 } |
| 975 | 975 |
| 976 NewFunctionEvent.prototype.details = function() { | 976 NewFunctionEvent.prototype.details = function() { |
| 977 var result = ""; | 977 var result = ""; |
| 978 result = "Function added: "; | 978 result = "Function added: "; |
| 979 result += this.func.name; | 979 result += this.func.name; |
| 980 return result; | 980 return result; |
| 981 }; | 981 }; |
| 982 | 982 |
| 983 NewFunctionEvent.prototype.debugPrompt = function() { | 983 NewFunctionEvent.prototype.debugPrompt = function() { |
| 984 var result = "function"; | 984 var result = "function"; |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1307 if (source_text[i] == '\t') { | 1307 if (source_text[i] == '\t') { |
| 1308 underline += '\t'; | 1308 underline += '\t'; |
| 1309 } else { | 1309 } else { |
| 1310 underline += ' '; | 1310 underline += ' '; |
| 1311 } | 1311 } |
| 1312 } | 1312 } |
| 1313 underline += '^'; | 1313 underline += '^'; |
| 1314 | 1314 |
| 1315 // Return the source line text with the underline beneath. | 1315 // Return the source line text with the underline beneath. |
| 1316 return source_text + '\n' + underline; | 1316 return source_text + '\n' + underline; |
| 1317 }; | 1317 } |
| 1318 | 1318 |
| 1319 | 1319 |
| 1320 function FrameSourceUnderline(frame) { | 1320 function FrameSourceUnderline(frame) { |
| 1321 var location = frame.sourceLocation(); | 1321 var location = frame.sourceLocation(); |
| 1322 if (location) { | 1322 if (location) { |
| 1323 return SourceUnderline(location.sourceText(), location.position - location.s
tart); | 1323 return SourceUnderline(location.sourceText(), location.position - location.s
tart); |
| 1324 } | 1324 } |
| 1325 }; | 1325 } |
| 1326 | 1326 |
| 1327 | 1327 |
| 1328 function RequestPacket(command) { | 1328 function RequestPacket(command) { |
| 1329 this.seq = 0; | 1329 this.seq = 0; |
| 1330 this.type = 'request'; | 1330 this.type = 'request'; |
| 1331 this.command = command; | 1331 this.command = command; |
| 1332 }; | 1332 } |
| 1333 | 1333 |
| 1334 | 1334 |
| 1335 RequestPacket.prototype.toJSONProtocol = function() { | 1335 RequestPacket.prototype.toJSONProtocol = function() { |
| 1336 // Encode the protocol header. | 1336 // Encode the protocol header. |
| 1337 var json = '{'; | 1337 var json = '{'; |
| 1338 json += '"seq":' + this.seq; | 1338 json += '"seq":' + this.seq; |
| 1339 json += ',"type":"' + this.type + '"'; | 1339 json += ',"type":"' + this.type + '"'; |
| 1340 if (this.command) { | 1340 if (this.command) { |
| 1341 json += ',"command":' + StringToJSON_(this.command); | 1341 json += ',"command":' + StringToJSON_(this.command); |
| 1342 } | 1342 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1360 | 1360 |
| 1361 | 1361 |
| 1362 function ResponsePacket(request) { | 1362 function ResponsePacket(request) { |
| 1363 // Build the initial response from the request. | 1363 // Build the initial response from the request. |
| 1364 this.seq = next_response_seq++; | 1364 this.seq = next_response_seq++; |
| 1365 this.type = 'response'; | 1365 this.type = 'response'; |
| 1366 if (request) this.request_seq = request.seq; | 1366 if (request) this.request_seq = request.seq; |
| 1367 if (request) this.command = request.command; | 1367 if (request) this.command = request.command; |
| 1368 this.success = true; | 1368 this.success = true; |
| 1369 this.running = false; | 1369 this.running = false; |
| 1370 }; | 1370 } |
| 1371 | 1371 |
| 1372 | 1372 |
| 1373 ResponsePacket.prototype.failed = function(message) { | 1373 ResponsePacket.prototype.failed = function(message) { |
| 1374 this.success = false; | 1374 this.success = false; |
| 1375 this.message = message; | 1375 this.message = message; |
| 1376 } | 1376 } |
| 1377 | 1377 |
| 1378 | 1378 |
| 1379 ResponsePacket.prototype.toJSONProtocol = function() { | 1379 ResponsePacket.prototype.toJSONProtocol = function() { |
| 1380 // Encode the protocol header. | 1380 // Encode the protocol header. |
| (...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1988 | 1988 |
| 1989 // Add the property if relevant. | 1989 // Add the property if relevant. |
| 1990 if (property_value_json) { | 1990 if (property_value_json) { |
| 1991 content.push(StringToJSON_(key) + ':' + property_value_json); | 1991 content.push(StringToJSON_(key) + ':' + property_value_json); |
| 1992 } | 1992 } |
| 1993 } | 1993 } |
| 1994 } | 1994 } |
| 1995 | 1995 |
| 1996 // Make JSON object representation. | 1996 // Make JSON object representation. |
| 1997 return '{' + content.join(',') + '}'; | 1997 return '{' + content.join(',') + '}'; |
| 1998 }; | 1998 } |
| 1999 | 1999 |
| 2000 /** | 2000 /** |
| 2001 * Convert an array to its JSON representation. This is a VERY simple | 2001 * Convert an array to its JSON representation. This is a VERY simple |
| 2002 * implementation just to support what is needed for the debugger. | 2002 * implementation just to support what is needed for the debugger. |
| 2003 * @param {Array} arrya The array to format as JSON | 2003 * @param {Array} arrya The array to format as JSON |
| 2004 * @return {string} JSON formatted array value | 2004 * @return {string} JSON formatted array value |
| 2005 */ | 2005 */ |
| 2006 function SimpleArrayToJSON_(array) { | 2006 function SimpleArrayToJSON_(array) { |
| 2007 // Make JSON array representation. | 2007 // Make JSON array representation. |
| 2008 var json = '['; | 2008 var json = '['; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2020 } else if (IS_NUMBER(elem)) { | 2020 } else if (IS_NUMBER(elem)) { |
| 2021 json += NumberToJSON_(elem); | 2021 json += NumberToJSON_(elem); |
| 2022 } else if (IS_STRING(elem)) { | 2022 } else if (IS_STRING(elem)) { |
| 2023 json += StringToJSON_(elem); | 2023 json += StringToJSON_(elem); |
| 2024 } else { | 2024 } else { |
| 2025 json += elem; | 2025 json += elem; |
| 2026 } | 2026 } |
| 2027 } | 2027 } |
| 2028 json += ']'; | 2028 json += ']'; |
| 2029 return json; | 2029 return json; |
| 2030 }; | 2030 } |
| OLD | NEW |