| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 (function (global, utils) { | 5 (function (global, utils) { |
| 6 "use strict"; | 6 "use strict"; |
| 7 | 7 |
| 8 // ---------------------------------------------------------------------------- | 8 // ---------------------------------------------------------------------------- |
| 9 // Imports | 9 // Imports |
| 10 | 10 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 | 59 |
| 60 // The different types of steps. | 60 // The different types of steps. |
| 61 Debug.StepAction = { StepOut: 0, | 61 Debug.StepAction = { StepOut: 0, |
| 62 StepNext: 1, | 62 StepNext: 1, |
| 63 StepIn: 2, | 63 StepIn: 2, |
| 64 StepFrame: 3 }; | 64 StepFrame: 3 }; |
| 65 | 65 |
| 66 // The different types of scripts matching enum ScriptType in objects.h. | 66 // The different types of scripts matching enum ScriptType in objects.h. |
| 67 Debug.ScriptType = { Native: 0, | 67 Debug.ScriptType = { Native: 0, |
| 68 Extension: 1, | 68 Extension: 1, |
| 69 Normal: 2 }; | 69 Normal: 2, |
| 70 Wasm: 3}; |
| 70 | 71 |
| 71 // The different types of script compilations matching enum | 72 // The different types of script compilations matching enum |
| 72 // Script::CompilationType in objects.h. | 73 // Script::CompilationType in objects.h. |
| 73 Debug.ScriptCompilationType = { Host: 0, | 74 Debug.ScriptCompilationType = { Host: 0, |
| 74 Eval: 1, | 75 Eval: 1, |
| 75 JSON: 2 }; | 76 JSON: 2 }; |
| 76 | 77 |
| 77 // The different script break point types. | 78 // The different script break point types. |
| 78 Debug.ScriptBreakPointType = { ScriptId: 0, | 79 Debug.ScriptBreakPointType = { ScriptId: 0, |
| 79 ScriptName: 1, | 80 ScriptName: 1, |
| (...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 | 481 |
| 481 // Returns a Script object. If the parameter is a function the return value | 482 // Returns a Script object. If the parameter is a function the return value |
| 482 // is the script in which the function is defined. If the parameter is a string | 483 // is the script in which the function is defined. If the parameter is a string |
| 483 // the return value is the script for which the script name has that string | 484 // the return value is the script for which the script name has that string |
| 484 // value. If it is a regexp and there is a unique script whose name matches | 485 // value. If it is a regexp and there is a unique script whose name matches |
| 485 // we return that, otherwise undefined. | 486 // we return that, otherwise undefined. |
| 486 Debug.findScript = function(func_or_script_name) { | 487 Debug.findScript = function(func_or_script_name) { |
| 487 if (IS_FUNCTION(func_or_script_name)) { | 488 if (IS_FUNCTION(func_or_script_name)) { |
| 488 return %FunctionGetScript(func_or_script_name); | 489 return %FunctionGetScript(func_or_script_name); |
| 489 } else if (IS_REGEXP(func_or_script_name)) { | 490 } else if (IS_REGEXP(func_or_script_name)) { |
| 490 var scripts = Debug.scripts(); | 491 var scripts = this.scripts(); |
| 491 var last_result = null; | 492 var last_result = null; |
| 492 var result_count = 0; | 493 var result_count = 0; |
| 493 for (var i in scripts) { | 494 for (var i in scripts) { |
| 494 var script = scripts[i]; | 495 var script = scripts[i]; |
| 495 if (func_or_script_name.test(script.name)) { | 496 if (func_or_script_name.test(script.name)) { |
| 496 last_result = script; | 497 last_result = script; |
| 497 result_count++; | 498 result_count++; |
| 498 } | 499 } |
| 499 } | 500 } |
| 500 // Return the unique script matching the regexp. If there are more | 501 // Return the unique script matching the regexp. If there are more |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 626 | 627 |
| 627 Debug.setBreakPointByScriptIdAndPosition = function(script_id, position, | 628 Debug.setBreakPointByScriptIdAndPosition = function(script_id, position, |
| 628 condition, enabled, | 629 condition, enabled, |
| 629 opt_position_alignment) | 630 opt_position_alignment) |
| 630 { | 631 { |
| 631 var break_point = MakeBreakPoint(position); | 632 var break_point = MakeBreakPoint(position); |
| 632 break_point.setCondition(condition); | 633 break_point.setCondition(condition); |
| 633 if (!enabled) { | 634 if (!enabled) { |
| 634 break_point.disable(); | 635 break_point.disable(); |
| 635 } | 636 } |
| 636 var scripts = this.scripts(); | 637 var script = scriptById(script_id); |
| 637 var position_alignment = IS_UNDEFINED(opt_position_alignment) | 638 if (script) { |
| 638 ? Debug.BreakPositionAlignment.Statement : opt_position_alignment; | 639 var position_alignment = IS_UNDEFINED(opt_position_alignment) |
| 639 for (var i = 0; i < scripts.length; i++) { | 640 ? Debug.BreakPositionAlignment.Statement : opt_position_alignment; |
| 640 if (script_id == scripts[i].id) { | 641 break_point.actual_position = %SetScriptBreakPoint(script, position, |
| 641 break_point.actual_position = %SetScriptBreakPoint(scripts[i], position, | 642 position_alignment, break_point); |
| 642 position_alignment, break_point); | |
| 643 break; | |
| 644 } | |
| 645 } | 643 } |
| 646 return break_point; | 644 return break_point; |
| 647 }; | 645 }; |
| 648 | 646 |
| 649 | 647 |
| 650 Debug.enableBreakPoint = function(break_point_number) { | 648 Debug.enableBreakPoint = function(break_point_number) { |
| 651 var break_point = this.findBreakPoint(break_point_number, false); | 649 var break_point = this.findBreakPoint(break_point_number, false); |
| 652 // Only enable if the breakpoint hasn't been deleted: | 650 // Only enable if the breakpoint hasn't been deleted: |
| 653 if (break_point) { | 651 if (break_point) { |
| 654 break_point.enable(); | 652 break_point.enable(); |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 851 | 849 |
| 852 | 850 |
| 853 // Get all the scripts currently loaded. Locating all the scripts is based on | 851 // Get all the scripts currently loaded. Locating all the scripts is based on |
| 854 // scanning the heap. | 852 // scanning the heap. |
| 855 Debug.scripts = function() { | 853 Debug.scripts = function() { |
| 856 // Collect all scripts in the heap. | 854 // Collect all scripts in the heap. |
| 857 return %DebugGetLoadedScripts(); | 855 return %DebugGetLoadedScripts(); |
| 858 }; | 856 }; |
| 859 | 857 |
| 860 | 858 |
| 859 // Get a specific script currently loaded. This is based on scanning the heap. |
| 860 // TODO(clemensh): Create a runtime function for this. |
| 861 function scriptById(scriptId) { |
| 862 var scripts = Debug.scripts(); |
| 863 for (var script of scripts) { |
| 864 if (script.id == scriptId) return script; |
| 865 } |
| 866 return UNDEFINED; |
| 867 }; |
| 868 |
| 869 |
| 861 Debug.debuggerFlags = function() { | 870 Debug.debuggerFlags = function() { |
| 862 return debugger_flags; | 871 return debugger_flags; |
| 863 }; | 872 }; |
| 864 | 873 |
| 874 Debug.getWasmFunctionOffsetTable = function(scriptId) { |
| 875 var script = scriptById(scriptId); |
| 876 return script ? %GetWasmFunctionOffsetTable(script) : UNDEFINED; |
| 877 } |
| 878 |
| 879 Debug.disassembleWasmFunction = function(scriptId) { |
| 880 var script = scriptById(scriptId); |
| 881 return script ? %DisassembleWasmFunction(script) : UNDEFINED; |
| 882 } |
| 883 |
| 865 Debug.MakeMirror = MakeMirror; | 884 Debug.MakeMirror = MakeMirror; |
| 866 | 885 |
| 867 function MakeExecutionState(break_id) { | 886 function MakeExecutionState(break_id) { |
| 868 return new ExecutionState(break_id); | 887 return new ExecutionState(break_id); |
| 869 } | 888 } |
| 870 | 889 |
| 871 function ExecutionState(break_id) { | 890 function ExecutionState(break_id) { |
| 872 this.break_id = break_id; | 891 this.break_id = break_id; |
| 873 this.selected_frame = 0; | 892 this.selected_frame = 0; |
| 874 } | 893 } |
| (...skipping 1273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2148 if (!IS_UNDEFINED(request.arguments.filter)) { | 2167 if (!IS_UNDEFINED(request.arguments.filter)) { |
| 2149 var num = TO_NUMBER(request.arguments.filter); | 2168 var num = TO_NUMBER(request.arguments.filter); |
| 2150 if (!IsNaN(num)) { | 2169 if (!IsNaN(num)) { |
| 2151 filterNum = num; | 2170 filterNum = num; |
| 2152 } | 2171 } |
| 2153 filterStr = request.arguments.filter; | 2172 filterStr = request.arguments.filter; |
| 2154 } | 2173 } |
| 2155 } | 2174 } |
| 2156 | 2175 |
| 2157 // Collect all scripts in the heap. | 2176 // Collect all scripts in the heap. |
| 2158 var scripts = %DebugGetLoadedScripts(); | 2177 var scripts = Debug.scripts(); |
| 2159 | 2178 |
| 2160 response.body = []; | 2179 response.body = []; |
| 2161 | 2180 |
| 2162 for (var i = 0; i < scripts.length; i++) { | 2181 for (var i = 0; i < scripts.length; i++) { |
| 2163 if (idsToInclude && !idsToInclude[scripts[i].id]) { | 2182 if (idsToInclude && !idsToInclude[scripts[i].id]) { |
| 2164 continue; | 2183 continue; |
| 2165 } | 2184 } |
| 2166 if (filterStr || filterNum) { | 2185 if (filterStr || filterNum) { |
| 2167 var script = scripts[i]; | 2186 var script = scripts[i]; |
| 2168 var found = false; | 2187 var found = false; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 2198 | 2217 |
| 2199 | 2218 |
| 2200 DebugCommandProcessor.prototype.changeLiveRequest_ = function( | 2219 DebugCommandProcessor.prototype.changeLiveRequest_ = function( |
| 2201 request, response) { | 2220 request, response) { |
| 2202 if (!request.arguments) { | 2221 if (!request.arguments) { |
| 2203 return response.failed('Missing arguments'); | 2222 return response.failed('Missing arguments'); |
| 2204 } | 2223 } |
| 2205 var script_id = request.arguments.script_id; | 2224 var script_id = request.arguments.script_id; |
| 2206 var preview_only = !!request.arguments.preview_only; | 2225 var preview_only = !!request.arguments.preview_only; |
| 2207 | 2226 |
| 2208 var scripts = %DebugGetLoadedScripts(); | 2227 var the_script = scriptById(script_id); |
| 2209 | |
| 2210 var the_script = null; | |
| 2211 for (var i = 0; i < scripts.length; i++) { | |
| 2212 if (scripts[i].id == script_id) { | |
| 2213 the_script = scripts[i]; | |
| 2214 } | |
| 2215 } | |
| 2216 if (!the_script) { | 2228 if (!the_script) { |
| 2217 response.failed('Script not found'); | 2229 response.failed('Script not found'); |
| 2218 return; | 2230 return; |
| 2219 } | 2231 } |
| 2220 | 2232 |
| 2221 var change_log = new GlobalArray(); | 2233 var change_log = new GlobalArray(); |
| 2222 | 2234 |
| 2223 if (!IS_STRING(request.arguments.new_source)) { | 2235 if (!IS_STRING(request.arguments.new_source)) { |
| 2224 throw "new_source argument expected"; | 2236 throw "new_source argument expected"; |
| 2225 } | 2237 } |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2476 "IsBreakPointTriggered", IsBreakPointTriggered, | 2488 "IsBreakPointTriggered", IsBreakPointTriggered, |
| 2477 "UpdateScriptBreakPoints", UpdateScriptBreakPoints, | 2489 "UpdateScriptBreakPoints", UpdateScriptBreakPoints, |
| 2478 ]); | 2490 ]); |
| 2479 | 2491 |
| 2480 // Export to liveedit.js | 2492 // Export to liveedit.js |
| 2481 utils.Export(function(to) { | 2493 utils.Export(function(to) { |
| 2482 to.GetScriptBreakPoints = GetScriptBreakPoints; | 2494 to.GetScriptBreakPoints = GetScriptBreakPoints; |
| 2483 }); | 2495 }); |
| 2484 | 2496 |
| 2485 }) | 2497 }) |
| OLD | NEW |