ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | // Default number of frames to include in the response to backtrace request. |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 29 | var kDefaultBacktraceLength = 10; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 30 | |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 31 | var Debug = {}; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 32 | |
| 33 | // Regular expression to skip "crud" at the beginning of a source line which is |
| 34 | // not really code. Currently the regular expression matches whitespace and |
| 35 | // comments. |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 36 | var sourceLineBeginningSkip = /^(?:\s*(?:\/\*.*?\*\/)*)*/; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 37 | |
| 38 | // Debug events which can occour in the V8 JavaScript engine. These originate |
| 39 | // from the API include file debug.h. |
| 40 | Debug.DebugEvent = { Break: 1, |
| 41 | Exception: 2, |
| 42 | NewFunction: 3, |
| 43 | BeforeCompile: 4, |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 44 | AfterCompile: 5, |
| 45 | ScriptCollected: 6 }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 46 | |
| 47 | // Types of exceptions that can be broken upon. |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 48 | Debug.ExceptionBreak = { Caught : 0, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 49 | Uncaught: 1 }; |
| 50 | |
| 51 | // The different types of steps. |
| 52 | Debug.StepAction = { StepOut: 0, |
| 53 | StepNext: 1, |
| 54 | StepIn: 2, |
| 55 | StepMin: 3, |
| 56 | StepInMin: 4 }; |
| 57 | |
| 58 | // The different types of scripts matching enum ScriptType in objects.h. |
| 59 | Debug.ScriptType = { Native: 0, |
| 60 | Extension: 1, |
| 61 | Normal: 2 }; |
| 62 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 63 | // The different types of script compilations matching enum |
| 64 | // Script::CompilationType in objects.h. |
| 65 | Debug.ScriptCompilationType = { Host: 0, |
| 66 | Eval: 1, |
| 67 | JSON: 2 }; |
| 68 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 69 | // The different script break point types. |
| 70 | Debug.ScriptBreakPointType = { ScriptId: 0, |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 71 | ScriptName: 1, |
| 72 | ScriptRegExp: 2 }; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 73 | |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame^] | 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 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 81 | function ScriptTypeFlag(type) { |
| 82 | return (1 << type); |
| 83 | } |
| 84 | |
| 85 | // Globals. |
| 86 | var next_response_seq = 0; |
| 87 | var next_break_point_number = 1; |
| 88 | var break_points = []; |
| 89 | var script_break_points = []; |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 90 | var debugger_flags = { |
| 91 | breakPointsActive: { |
| 92 | value: true, |
| 93 | getValue: function() { return this.value; }, |
| 94 | setValue: function(value) { |
| 95 | this.value = !!value; |
| 96 | %SetDisableBreak(!this.value); |
| 97 | } |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 98 | }, |
| 99 | breakOnCaughtException: { |
| 100 | getValue: function() { return Debug.isBreakOnException(); }, |
| 101 | setValue: function(value) { |
| 102 | if (value) { |
| 103 | Debug.setBreakOnException(); |
| 104 | } else { |
| 105 | Debug.clearBreakOnException(); |
| 106 | } |
| 107 | } |
| 108 | }, |
| 109 | breakOnUncaughtException: { |
| 110 | getValue: function() { return Debug.isBreakOnUncaughtException(); }, |
| 111 | setValue: function(value) { |
| 112 | if (value) { |
| 113 | Debug.setBreakOnUncaughtException(); |
| 114 | } else { |
| 115 | Debug.clearBreakOnUncaughtException(); |
| 116 | } |
| 117 | } |
| 118 | }, |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 119 | }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 120 | |
| 121 | |
| 122 | // Create a new break point object and add it to the list of break points. |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 123 | function MakeBreakPoint(source_position, opt_script_break_point) { |
| 124 | var break_point = new BreakPoint(source_position, opt_script_break_point); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 125 | break_points.push(break_point); |
| 126 | return break_point; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 127 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 128 | |
| 129 | |
| 130 | // Object representing a break point. |
| 131 | // NOTE: This object does not have a reference to the function having break |
| 132 | // point as this would cause function not to be garbage collected when it is |
| 133 | // not used any more. We do not want break points to keep functions alive. |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 134 | function BreakPoint(source_position, opt_script_break_point) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 135 | this.source_position_ = source_position; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 136 | if (opt_script_break_point) { |
| 137 | this.script_break_point_ = opt_script_break_point; |
| 138 | } else { |
| 139 | this.number_ = next_break_point_number++; |
| 140 | } |
| 141 | this.hit_count_ = 0; |
| 142 | this.active_ = true; |
| 143 | this.condition_ = null; |
| 144 | this.ignoreCount_ = 0; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 145 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 146 | |
| 147 | |
| 148 | BreakPoint.prototype.number = function() { |
| 149 | return this.number_; |
| 150 | }; |
| 151 | |
| 152 | |
| 153 | BreakPoint.prototype.func = function() { |
| 154 | return this.func_; |
| 155 | }; |
| 156 | |
| 157 | |
| 158 | BreakPoint.prototype.source_position = function() { |
| 159 | return this.source_position_; |
| 160 | }; |
| 161 | |
| 162 | |
| 163 | BreakPoint.prototype.hit_count = function() { |
| 164 | return this.hit_count_; |
| 165 | }; |
| 166 | |
| 167 | |
| 168 | BreakPoint.prototype.active = function() { |
| 169 | if (this.script_break_point()) { |
| 170 | return this.script_break_point().active(); |
| 171 | } |
| 172 | return this.active_; |
| 173 | }; |
| 174 | |
| 175 | |
| 176 | BreakPoint.prototype.condition = function() { |
| 177 | if (this.script_break_point() && this.script_break_point().condition()) { |
| 178 | return this.script_break_point().condition(); |
| 179 | } |
| 180 | return this.condition_; |
| 181 | }; |
| 182 | |
| 183 | |
| 184 | BreakPoint.prototype.ignoreCount = function() { |
| 185 | return this.ignoreCount_; |
| 186 | }; |
| 187 | |
| 188 | |
| 189 | BreakPoint.prototype.script_break_point = function() { |
| 190 | return this.script_break_point_; |
| 191 | }; |
| 192 | |
| 193 | |
| 194 | BreakPoint.prototype.enable = function() { |
| 195 | this.active_ = true; |
| 196 | }; |
| 197 | |
| 198 | |
| 199 | BreakPoint.prototype.disable = function() { |
| 200 | this.active_ = false; |
| 201 | }; |
| 202 | |
| 203 | |
| 204 | BreakPoint.prototype.setCondition = function(condition) { |
| 205 | this.condition_ = condition; |
| 206 | }; |
| 207 | |
| 208 | |
| 209 | BreakPoint.prototype.setIgnoreCount = function(ignoreCount) { |
| 210 | this.ignoreCount_ = ignoreCount; |
| 211 | }; |
| 212 | |
| 213 | |
| 214 | BreakPoint.prototype.isTriggered = function(exec_state) { |
| 215 | // Break point not active - not triggered. |
| 216 | if (!this.active()) return false; |
| 217 | |
| 218 | // Check for conditional break point. |
| 219 | if (this.condition()) { |
| 220 | // If break point has condition try to evaluate it in the top frame. |
| 221 | try { |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 222 | var mirror = exec_state.frame(0).evaluate(this.condition()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 223 | // If no sensible mirror or non true value break point not triggered. |
| 224 | if (!(mirror instanceof ValueMirror) || !%ToBoolean(mirror.value_)) { |
| 225 | return false; |
| 226 | } |
| 227 | } catch (e) { |
| 228 | // Exception evaluating condition counts as not triggered. |
| 229 | return false; |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | // Update the hit count. |
| 234 | this.hit_count_++; |
| 235 | if (this.script_break_point_) { |
| 236 | this.script_break_point_.hit_count_++; |
| 237 | } |
| 238 | |
| 239 | // If the break point has an ignore count it is not triggered. |
| 240 | if (this.ignoreCount_ > 0) { |
| 241 | this.ignoreCount_--; |
| 242 | return false; |
| 243 | } |
| 244 | |
| 245 | // Break point triggered. |
| 246 | return true; |
| 247 | }; |
| 248 | |
| 249 | |
| 250 | // Function called from the runtime when a break point is hit. Returns true if |
| 251 | // the break point is triggered and supposed to break execution. |
| 252 | function IsBreakPointTriggered(break_id, break_point) { |
| 253 | return break_point.isTriggered(MakeExecutionState(break_id)); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 254 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 255 | |
| 256 | |
| 257 | // Object representing a script break point. The script is referenced by its |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 258 | // script name or script id and the break point is represented as line and |
| 259 | // column. |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 260 | function ScriptBreakPoint(type, script_id_or_name, opt_line, opt_column, |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame^] | 261 | opt_groupId, opt_position_alignment) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 262 | this.type_ = type; |
| 263 | if (type == Debug.ScriptBreakPointType.ScriptId) { |
| 264 | this.script_id_ = script_id_or_name; |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 265 | } else if (type == Debug.ScriptBreakPointType.ScriptName) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 266 | this.script_name_ = script_id_or_name; |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 267 | } else if (type == Debug.ScriptBreakPointType.ScriptRegExp) { |
| 268 | this.script_regexp_object_ = new RegExp(script_id_or_name); |
| 269 | } else { |
| 270 | throw new Error("Unexpected breakpoint type " + type); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 271 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 272 | this.line_ = opt_line || 0; |
| 273 | this.column_ = opt_column; |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 274 | this.groupId_ = opt_groupId; |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame^] | 275 | this.position_alignment_ = IS_UNDEFINED(opt_position_alignment) |
| 276 | ? Debug.BreakPositionAlignment.Statement : opt_position_alignment; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 277 | this.hit_count_ = 0; |
| 278 | this.active_ = true; |
| 279 | this.condition_ = null; |
| 280 | this.ignoreCount_ = 0; |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 281 | this.break_points_ = []; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 282 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 283 | |
| 284 | |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 285 | //Creates a clone of script breakpoint that is linked to another script. |
| 286 | ScriptBreakPoint.prototype.cloneForOtherScript = function (other_script) { |
| 287 | var copy = new ScriptBreakPoint(Debug.ScriptBreakPointType.ScriptId, |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame^] | 288 | other_script.id, this.line_, this.column_, this.groupId_, |
| 289 | this.position_alignment_); |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 290 | copy.number_ = next_break_point_number++; |
| 291 | script_break_points.push(copy); |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 292 | |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 293 | copy.hit_count_ = this.hit_count_; |
| 294 | copy.active_ = this.active_; |
| 295 | copy.condition_ = this.condition_; |
| 296 | copy.ignoreCount_ = this.ignoreCount_; |
| 297 | return copy; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 298 | }; |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 299 | |
| 300 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 301 | ScriptBreakPoint.prototype.number = function() { |
| 302 | return this.number_; |
| 303 | }; |
| 304 | |
| 305 | |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 306 | ScriptBreakPoint.prototype.groupId = function() { |
| 307 | return this.groupId_; |
| 308 | }; |
| 309 | |
| 310 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 311 | ScriptBreakPoint.prototype.type = function() { |
| 312 | return this.type_; |
| 313 | }; |
| 314 | |
| 315 | |
| 316 | ScriptBreakPoint.prototype.script_id = function() { |
| 317 | return this.script_id_; |
| 318 | }; |
| 319 | |
| 320 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 321 | ScriptBreakPoint.prototype.script_name = function() { |
| 322 | return this.script_name_; |
| 323 | }; |
| 324 | |
| 325 | |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 326 | ScriptBreakPoint.prototype.script_regexp_object = function() { |
| 327 | return this.script_regexp_object_; |
| 328 | }; |
| 329 | |
| 330 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 331 | ScriptBreakPoint.prototype.line = function() { |
| 332 | return this.line_; |
| 333 | }; |
| 334 | |
| 335 | |
| 336 | ScriptBreakPoint.prototype.column = function() { |
| 337 | return this.column_; |
| 338 | }; |
| 339 | |
| 340 | |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 341 | ScriptBreakPoint.prototype.actual_locations = function() { |
| 342 | var locations = []; |
| 343 | for (var i = 0; i < this.break_points_.length; i++) { |
| 344 | locations.push(this.break_points_[i].actual_location); |
| 345 | } |
| 346 | return locations; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 347 | }; |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 348 | |
| 349 | |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 350 | ScriptBreakPoint.prototype.update_positions = function(line, column) { |
| 351 | this.line_ = line; |
| 352 | this.column_ = column; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 353 | }; |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 354 | |
| 355 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 356 | ScriptBreakPoint.prototype.hit_count = function() { |
| 357 | return this.hit_count_; |
| 358 | }; |
| 359 | |
| 360 | |
| 361 | ScriptBreakPoint.prototype.active = function() { |
| 362 | return this.active_; |
| 363 | }; |
| 364 | |
| 365 | |
| 366 | ScriptBreakPoint.prototype.condition = function() { |
| 367 | return this.condition_; |
| 368 | }; |
| 369 | |
| 370 | |
| 371 | ScriptBreakPoint.prototype.ignoreCount = function() { |
| 372 | return this.ignoreCount_; |
| 373 | }; |
| 374 | |
| 375 | |
| 376 | ScriptBreakPoint.prototype.enable = function() { |
| 377 | this.active_ = true; |
| 378 | }; |
| 379 | |
| 380 | |
| 381 | ScriptBreakPoint.prototype.disable = function() { |
| 382 | this.active_ = false; |
| 383 | }; |
| 384 | |
| 385 | |
| 386 | ScriptBreakPoint.prototype.setCondition = function(condition) { |
| 387 | this.condition_ = condition; |
| 388 | }; |
| 389 | |
| 390 | |
| 391 | ScriptBreakPoint.prototype.setIgnoreCount = function(ignoreCount) { |
| 392 | this.ignoreCount_ = ignoreCount; |
| 393 | |
| 394 | // Set ignore count on all break points created from this script break point. |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 395 | for (var i = 0; i < this.break_points_.length; i++) { |
| 396 | this.break_points_[i].setIgnoreCount(ignoreCount); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 397 | } |
| 398 | }; |
| 399 | |
| 400 | |
| 401 | // Check whether a script matches this script break point. Currently this is |
| 402 | // only based on script name. |
| 403 | ScriptBreakPoint.prototype.matchesScript = function(script) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 404 | if (this.type_ == Debug.ScriptBreakPointType.ScriptId) { |
| 405 | return this.script_id_ == script.id; |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 406 | } else { |
| 407 | // We might want to account columns here as well. |
| 408 | if (!(script.line_offset <= this.line_ && |
| 409 | this.line_ < script.line_offset + script.lineCount())) { |
| 410 | return false; |
| 411 | } |
| 412 | if (this.type_ == Debug.ScriptBreakPointType.ScriptName) { |
| 413 | return this.script_name_ == script.nameOrSourceURL(); |
| 414 | } else if (this.type_ == Debug.ScriptBreakPointType.ScriptRegExp) { |
| 415 | return this.script_regexp_object_.test(script.nameOrSourceURL()); |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 416 | } else { |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 417 | throw new Error("Unexpected breakpoint type " + this.type_); |
| 418 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 419 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 420 | }; |
| 421 | |
| 422 | |
| 423 | // Set the script break point in a script. |
| 424 | ScriptBreakPoint.prototype.set = function (script) { |
| 425 | var column = this.column(); |
| 426 | var line = this.line(); |
| 427 | // If the column is undefined the break is on the line. To help locate the |
| 428 | // first piece of breakable code on the line try to find the column on the |
| 429 | // line which contains some source. |
| 430 | if (IS_UNDEFINED(column)) { |
| 431 | var source_line = script.sourceLine(this.line()); |
| 432 | |
| 433 | // Allocate array for caching the columns where the actual source starts. |
| 434 | if (!script.sourceColumnStart_) { |
| 435 | script.sourceColumnStart_ = new Array(script.lineCount()); |
| 436 | } |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 437 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 438 | // Fill cache if needed and get column where the actual source starts. |
| 439 | if (IS_UNDEFINED(script.sourceColumnStart_[line])) { |
| 440 | script.sourceColumnStart_[line] = |
| 441 | source_line.match(sourceLineBeginningSkip)[0].length; |
| 442 | } |
| 443 | column = script.sourceColumnStart_[line]; |
| 444 | } |
| 445 | |
| 446 | // Convert the line and column into an absolute position within the script. |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 447 | var position = Debug.findScriptSourcePosition(script, this.line(), column); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 448 | |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 449 | // If the position is not found in the script (the script might be shorter |
| 450 | // than it used to be) just ignore it. |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 451 | if (position === null) return; |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 452 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 453 | // Create a break point object and set the break point. |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 454 | break_point = MakeBreakPoint(position, this); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 455 | break_point.setIgnoreCount(this.ignoreCount()); |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame^] | 456 | var actual_position = %SetScriptBreakPoint(script, position, |
| 457 | this.position_alignment_, |
| 458 | break_point); |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 459 | if (IS_UNDEFINED(actual_position)) { |
| 460 | actual_position = position; |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 461 | } |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 462 | var actual_location = script.locationFromPosition(actual_position, true); |
| 463 | break_point.actual_location = { line: actual_location.line, |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 464 | column: actual_location.column, |
| 465 | script_id: script.id }; |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 466 | this.break_points_.push(break_point); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 467 | return break_point; |
| 468 | }; |
| 469 | |
| 470 | |
| 471 | // Clear all the break points created from this script break point |
| 472 | ScriptBreakPoint.prototype.clear = function () { |
| 473 | var remaining_break_points = []; |
| 474 | for (var i = 0; i < break_points.length; i++) { |
| 475 | if (break_points[i].script_break_point() && |
| 476 | break_points[i].script_break_point() === this) { |
| 477 | %ClearBreakPoint(break_points[i]); |
| 478 | } else { |
| 479 | remaining_break_points.push(break_points[i]); |
| 480 | } |
| 481 | } |
| 482 | break_points = remaining_break_points; |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 483 | this.break_points_ = []; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 484 | }; |
| 485 | |
| 486 | |
| 487 | // Function called from runtime when a new script is compiled to set any script |
| 488 | // break points set in this script. |
| 489 | function UpdateScriptBreakPoints(script) { |
| 490 | for (var i = 0; i < script_break_points.length; i++) { |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 491 | var break_point = script_break_points[i]; |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 492 | if ((break_point.type() == Debug.ScriptBreakPointType.ScriptName || |
| 493 | break_point.type() == Debug.ScriptBreakPointType.ScriptRegExp) && |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 494 | break_point.matchesScript(script)) { |
| 495 | break_point.set(script); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 496 | } |
| 497 | } |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 498 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 499 | |
| 500 | |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 501 | function GetScriptBreakPoints(script) { |
| 502 | var result = []; |
| 503 | for (var i = 0; i < script_break_points.length; i++) { |
| 504 | if (script_break_points[i].matchesScript(script)) { |
| 505 | result.push(script_break_points[i]); |
| 506 | } |
| 507 | } |
| 508 | return result; |
| 509 | } |
| 510 | |
| 511 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 512 | Debug.setListener = function(listener, opt_data) { |
| 513 | if (!IS_FUNCTION(listener) && !IS_UNDEFINED(listener) && !IS_NULL(listener)) { |
| 514 | throw new Error('Parameters have wrong types.'); |
| 515 | } |
| 516 | %SetDebugEventListener(listener, opt_data); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 517 | }; |
| 518 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 519 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 520 | Debug.breakExecution = function(f) { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 521 | %Break(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 522 | }; |
| 523 | |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame^] | 524 | Debug.breakLocations = function(f, opt_position_aligment) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 525 | if (!IS_FUNCTION(f)) throw new Error('Parameters have wrong types.'); |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame^] | 526 | var position_aligment = IS_UNDEFINED(opt_position_aligment) |
| 527 | ? Debug.BreakPositionAlignment.Statement : opt_position_aligment; |
| 528 | return %GetBreakLocations(f, position_aligment); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 529 | }; |
| 530 | |
| 531 | // 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 |
| 533 | // the return value is the script for which the script name has that string |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 534 | // value. If it is a regexp and there is a unique script whose name matches |
| 535 | // we return that, otherwise undefined. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 536 | Debug.findScript = function(func_or_script_name) { |
| 537 | if (IS_FUNCTION(func_or_script_name)) { |
| 538 | return %FunctionGetScript(func_or_script_name); |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 539 | } else if (IS_REGEXP(func_or_script_name)) { |
| 540 | var scripts = Debug.scripts(); |
| 541 | var last_result = null; |
| 542 | var result_count = 0; |
| 543 | for (var i in scripts) { |
| 544 | var script = scripts[i]; |
| 545 | if (func_or_script_name.test(script.name)) { |
| 546 | last_result = script; |
| 547 | result_count++; |
| 548 | } |
| 549 | } |
| 550 | // Return the unique script matching the regexp. If there are more |
| 551 | // than one we don't return a value since there is no good way to |
| 552 | // decide which one to return. Returning a "random" one, say the |
| 553 | // first, would introduce nondeterminism (or something close to it) |
| 554 | // because the order is the heap iteration order. |
| 555 | if (result_count == 1) { |
| 556 | return last_result; |
| 557 | } else { |
| 558 | return undefined; |
| 559 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 560 | } else { |
| 561 | return %GetScript(func_or_script_name); |
| 562 | } |
| 563 | }; |
| 564 | |
| 565 | // Returns the script source. If the parameter is a function the return value |
| 566 | // is the script source for the script in which the function is defined. If the |
| 567 | // parameter is a string the return value is the script for which the script |
| 568 | // name has that string value. |
| 569 | Debug.scriptSource = function(func_or_script_name) { |
| 570 | return this.findScript(func_or_script_name).source; |
| 571 | }; |
| 572 | |
| 573 | Debug.source = function(f) { |
| 574 | if (!IS_FUNCTION(f)) throw new Error('Parameters have wrong types.'); |
| 575 | return %FunctionGetSourceCode(f); |
| 576 | }; |
| 577 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 578 | Debug.disassemble = function(f) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 579 | if (!IS_FUNCTION(f)) throw new Error('Parameters have wrong types.'); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 580 | return %DebugDisassembleFunction(f); |
| 581 | }; |
| 582 | |
| 583 | Debug.disassembleConstructor = function(f) { |
| 584 | if (!IS_FUNCTION(f)) throw new Error('Parameters have wrong types.'); |
| 585 | return %DebugDisassembleConstructor(f); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 586 | }; |
| 587 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 588 | Debug.ExecuteInDebugContext = function(f, without_debugger) { |
| 589 | if (!IS_FUNCTION(f)) throw new Error('Parameters have wrong types.'); |
| 590 | return %ExecuteInDebugContext(f, !!without_debugger); |
| 591 | }; |
| 592 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 593 | Debug.sourcePosition = function(f) { |
| 594 | if (!IS_FUNCTION(f)) throw new Error('Parameters have wrong types.'); |
| 595 | return %FunctionGetScriptSourcePosition(f); |
| 596 | }; |
| 597 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 598 | |
| 599 | Debug.findFunctionSourceLocation = function(func, opt_line, opt_column) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 600 | var script = %FunctionGetScript(func); |
| 601 | var script_offset = %FunctionGetScriptSourcePosition(func); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 602 | return script.locationFromLine(opt_line, opt_column, script_offset); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 603 | }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 604 | |
| 605 | |
| 606 | // Returns the character position in a script based on a line number and an |
| 607 | // optional position within that line. |
| 608 | Debug.findScriptSourcePosition = function(script, opt_line, opt_column) { |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 609 | var location = script.locationFromLine(opt_line, opt_column); |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 610 | return location ? location.position : null; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 611 | }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 612 | |
| 613 | |
| 614 | Debug.findBreakPoint = function(break_point_number, remove) { |
| 615 | var break_point; |
| 616 | for (var i = 0; i < break_points.length; i++) { |
| 617 | if (break_points[i].number() == break_point_number) { |
| 618 | break_point = break_points[i]; |
| 619 | // Remove the break point from the list if requested. |
| 620 | if (remove) { |
| 621 | break_points.splice(i, 1); |
| 622 | } |
| 623 | break; |
| 624 | } |
| 625 | } |
| 626 | if (break_point) { |
| 627 | return break_point; |
| 628 | } else { |
| 629 | return this.findScriptBreakPoint(break_point_number, remove); |
| 630 | } |
| 631 | }; |
| 632 | |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 633 | Debug.findBreakPointActualLocations = function(break_point_number) { |
| 634 | for (var i = 0; i < script_break_points.length; i++) { |
| 635 | if (script_break_points[i].number() == break_point_number) { |
| 636 | return script_break_points[i].actual_locations(); |
| 637 | } |
| 638 | } |
| 639 | for (var i = 0; i < break_points.length; i++) { |
| 640 | if (break_points[i].number() == break_point_number) { |
| 641 | return [break_points[i].actual_location]; |
| 642 | } |
| 643 | } |
| 644 | return []; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 645 | }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 646 | |
| 647 | Debug.setBreakPoint = function(func, opt_line, opt_column, opt_condition) { |
| 648 | if (!IS_FUNCTION(func)) throw new Error('Parameters have wrong types.'); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 649 | // Break points in API functions are not supported. |
| 650 | if (%FunctionIsAPIFunction(func)) { |
| 651 | throw new Error('Cannot set break point in native code.'); |
| 652 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 653 | // Find source position relative to start of the function |
| 654 | var break_position = |
| 655 | this.findFunctionSourceLocation(func, opt_line, opt_column).position; |
| 656 | var source_position = break_position - this.sourcePosition(func); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 657 | // Find the script for the function. |
| 658 | var script = %FunctionGetScript(func); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 659 | // Break in builtin JavaScript code is not supported. |
| 660 | if (script.type == Debug.ScriptType.Native) { |
| 661 | throw new Error('Cannot set break point in native code.'); |
| 662 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 663 | // If the script for the function has a name convert this to a script break |
| 664 | // point. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 665 | if (script && script.id) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 666 | // Adjust the source position to be script relative. |
| 667 | source_position += %FunctionGetScriptSourcePosition(func); |
| 668 | // Find line and column for the position in the script and set a script |
| 669 | // break point from that. |
ager@chromium.org | 3a6061e | 2009-03-12 14:24:36 +0000 | [diff] [blame] | 670 | var location = script.locationFromPosition(source_position, false); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 671 | return this.setScriptBreakPointById(script.id, |
| 672 | location.line, location.column, |
| 673 | opt_condition); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 674 | } else { |
| 675 | // Set a break point directly on the function. |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 676 | var break_point = MakeBreakPoint(source_position); |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 677 | var actual_position = |
| 678 | %SetFunctionBreakPoint(func, source_position, break_point); |
| 679 | actual_position += this.sourcePosition(func); |
| 680 | var actual_location = script.locationFromPosition(actual_position, true); |
| 681 | break_point.actual_location = { line: actual_location.line, |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 682 | column: actual_location.column, |
| 683 | script_id: script.id }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 684 | break_point.setCondition(opt_condition); |
| 685 | return break_point.number(); |
| 686 | } |
| 687 | }; |
| 688 | |
| 689 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 690 | Debug.setBreakPointByScriptIdAndPosition = function(script_id, position, |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame^] | 691 | condition, enabled, |
| 692 | opt_position_alignment) |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 693 | { |
| 694 | break_point = MakeBreakPoint(position); |
| 695 | break_point.setCondition(condition); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 696 | if (!enabled) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 697 | break_point.disable(); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 698 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 699 | var scripts = this.scripts(); |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame^] | 700 | var position_alignment = IS_UNDEFINED(opt_position_alignment) |
| 701 | ? Debug.BreakPositionAlignment.Statement : opt_position_alignment; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 702 | for (var i = 0; i < scripts.length; i++) { |
| 703 | if (script_id == scripts[i].id) { |
| 704 | break_point.actual_position = %SetScriptBreakPoint(scripts[i], position, |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame^] | 705 | position_alignment, break_point); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 706 | break; |
| 707 | } |
| 708 | } |
| 709 | return break_point; |
| 710 | }; |
| 711 | |
| 712 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 713 | Debug.enableBreakPoint = function(break_point_number) { |
| 714 | var break_point = this.findBreakPoint(break_point_number, false); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 715 | // Only enable if the breakpoint hasn't been deleted: |
| 716 | if (break_point) { |
| 717 | break_point.enable(); |
| 718 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 719 | }; |
| 720 | |
| 721 | |
| 722 | Debug.disableBreakPoint = function(break_point_number) { |
| 723 | var break_point = this.findBreakPoint(break_point_number, false); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 724 | // Only enable if the breakpoint hasn't been deleted: |
| 725 | if (break_point) { |
| 726 | break_point.disable(); |
| 727 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 728 | }; |
| 729 | |
| 730 | |
| 731 | Debug.changeBreakPointCondition = function(break_point_number, condition) { |
| 732 | var break_point = this.findBreakPoint(break_point_number, false); |
| 733 | break_point.setCondition(condition); |
| 734 | }; |
| 735 | |
| 736 | |
| 737 | Debug.changeBreakPointIgnoreCount = function(break_point_number, ignoreCount) { |
| 738 | if (ignoreCount < 0) { |
| 739 | throw new Error('Invalid argument'); |
| 740 | } |
| 741 | var break_point = this.findBreakPoint(break_point_number, false); |
| 742 | break_point.setIgnoreCount(ignoreCount); |
| 743 | }; |
| 744 | |
| 745 | |
| 746 | Debug.clearBreakPoint = function(break_point_number) { |
| 747 | var break_point = this.findBreakPoint(break_point_number, true); |
| 748 | if (break_point) { |
| 749 | return %ClearBreakPoint(break_point); |
| 750 | } else { |
| 751 | break_point = this.findScriptBreakPoint(break_point_number, true); |
| 752 | if (!break_point) { |
| 753 | throw new Error('Invalid breakpoint'); |
| 754 | } |
| 755 | } |
| 756 | }; |
| 757 | |
| 758 | |
| 759 | Debug.clearAllBreakPoints = function() { |
| 760 | for (var i = 0; i < break_points.length; i++) { |
| 761 | break_point = break_points[i]; |
| 762 | %ClearBreakPoint(break_point); |
| 763 | } |
| 764 | break_points = []; |
| 765 | }; |
| 766 | |
| 767 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 768 | Debug.disableAllBreakPoints = function() { |
| 769 | // Disable all user defined breakpoints: |
| 770 | for (var i = 1; i < next_break_point_number; i++) { |
| 771 | Debug.disableBreakPoint(i); |
| 772 | } |
| 773 | // Disable all exception breakpoints: |
| 774 | %ChangeBreakOnException(Debug.ExceptionBreak.Caught, false); |
| 775 | %ChangeBreakOnException(Debug.ExceptionBreak.Uncaught, false); |
| 776 | }; |
| 777 | |
| 778 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 779 | Debug.findScriptBreakPoint = function(break_point_number, remove) { |
| 780 | var script_break_point; |
| 781 | for (var i = 0; i < script_break_points.length; i++) { |
| 782 | if (script_break_points[i].number() == break_point_number) { |
| 783 | script_break_point = script_break_points[i]; |
| 784 | // Remove the break point from the list if requested. |
| 785 | if (remove) { |
| 786 | script_break_point.clear(); |
| 787 | script_break_points.splice(i,1); |
| 788 | } |
| 789 | break; |
| 790 | } |
| 791 | } |
| 792 | return script_break_point; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 793 | }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 794 | |
| 795 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 796 | // Sets a breakpoint in a script identified through id or name at the |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 797 | // specified source line and column within that line. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 798 | Debug.setScriptBreakPoint = function(type, script_id_or_name, |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 799 | opt_line, opt_column, opt_condition, |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame^] | 800 | opt_groupId, opt_position_alignment) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 801 | // Create script break point object. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 802 | var script_break_point = |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 803 | new ScriptBreakPoint(type, script_id_or_name, opt_line, opt_column, |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame^] | 804 | opt_groupId, opt_position_alignment); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 805 | |
| 806 | // Assign number to the new script break point and add it. |
| 807 | script_break_point.number_ = next_break_point_number++; |
| 808 | script_break_point.setCondition(opt_condition); |
| 809 | script_break_points.push(script_break_point); |
| 810 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 811 | // Run through all scripts to see if this script break point matches any |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 812 | // loaded scripts. |
| 813 | var scripts = this.scripts(); |
| 814 | for (var i = 0; i < scripts.length; i++) { |
| 815 | if (script_break_point.matchesScript(scripts[i])) { |
| 816 | script_break_point.set(scripts[i]); |
| 817 | } |
| 818 | } |
| 819 | |
| 820 | return script_break_point.number(); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 821 | }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 822 | |
| 823 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 824 | Debug.setScriptBreakPointById = function(script_id, |
| 825 | opt_line, opt_column, |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame^] | 826 | opt_condition, opt_groupId, |
| 827 | opt_position_alignment) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 828 | return this.setScriptBreakPoint(Debug.ScriptBreakPointType.ScriptId, |
| 829 | script_id, opt_line, opt_column, |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame^] | 830 | opt_condition, opt_groupId, |
| 831 | opt_position_alignment); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 832 | }; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 833 | |
| 834 | |
| 835 | Debug.setScriptBreakPointByName = function(script_name, |
| 836 | opt_line, opt_column, |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 837 | opt_condition, opt_groupId) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 838 | return this.setScriptBreakPoint(Debug.ScriptBreakPointType.ScriptName, |
| 839 | script_name, opt_line, opt_column, |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 840 | opt_condition, opt_groupId); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 841 | }; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 842 | |
| 843 | |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 844 | Debug.setScriptBreakPointByRegExp = function(script_regexp, |
| 845 | opt_line, opt_column, |
| 846 | opt_condition, opt_groupId) { |
| 847 | return this.setScriptBreakPoint(Debug.ScriptBreakPointType.ScriptRegExp, |
| 848 | script_regexp, opt_line, opt_column, |
| 849 | opt_condition, opt_groupId); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 850 | }; |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 851 | |
| 852 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 853 | Debug.enableScriptBreakPoint = function(break_point_number) { |
| 854 | var script_break_point = this.findScriptBreakPoint(break_point_number, false); |
| 855 | script_break_point.enable(); |
| 856 | }; |
| 857 | |
| 858 | |
| 859 | Debug.disableScriptBreakPoint = function(break_point_number) { |
| 860 | var script_break_point = this.findScriptBreakPoint(break_point_number, false); |
| 861 | script_break_point.disable(); |
| 862 | }; |
| 863 | |
| 864 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 865 | Debug.changeScriptBreakPointCondition = function( |
| 866 | break_point_number, condition) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 867 | var script_break_point = this.findScriptBreakPoint(break_point_number, false); |
| 868 | script_break_point.setCondition(condition); |
| 869 | }; |
| 870 | |
| 871 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 872 | Debug.changeScriptBreakPointIgnoreCount = function( |
| 873 | break_point_number, ignoreCount) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 874 | if (ignoreCount < 0) { |
| 875 | throw new Error('Invalid argument'); |
| 876 | } |
| 877 | var script_break_point = this.findScriptBreakPoint(break_point_number, false); |
| 878 | script_break_point.setIgnoreCount(ignoreCount); |
| 879 | }; |
| 880 | |
| 881 | |
| 882 | Debug.scriptBreakPoints = function() { |
| 883 | return script_break_points; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 884 | }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 885 | |
| 886 | |
| 887 | Debug.clearStepping = function() { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 888 | %ClearStepping(); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 889 | }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 890 | |
| 891 | Debug.setBreakOnException = function() { |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 892 | return %ChangeBreakOnException(Debug.ExceptionBreak.Caught, true); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 893 | }; |
| 894 | |
| 895 | Debug.clearBreakOnException = function() { |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 896 | return %ChangeBreakOnException(Debug.ExceptionBreak.Caught, false); |
| 897 | }; |
| 898 | |
| 899 | Debug.isBreakOnException = function() { |
| 900 | return !!%IsBreakOnException(Debug.ExceptionBreak.Caught); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 901 | }; |
| 902 | |
| 903 | Debug.setBreakOnUncaughtException = function() { |
| 904 | return %ChangeBreakOnException(Debug.ExceptionBreak.Uncaught, true); |
| 905 | }; |
| 906 | |
| 907 | Debug.clearBreakOnUncaughtException = function() { |
| 908 | return %ChangeBreakOnException(Debug.ExceptionBreak.Uncaught, false); |
| 909 | }; |
| 910 | |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 911 | Debug.isBreakOnUncaughtException = function() { |
| 912 | return !!%IsBreakOnException(Debug.ExceptionBreak.Uncaught); |
| 913 | }; |
| 914 | |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame^] | 915 | Debug.showBreakPoints = function(f, full, opt_position_alignment) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 916 | if (!IS_FUNCTION(f)) throw new Error('Parameters have wrong types.'); |
| 917 | var source = full ? this.scriptSource(f) : this.source(f); |
| 918 | var offset = full ? this.sourcePosition(f) : 0; |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame^] | 919 | var locations = this.breakLocations(f, opt_position_alignment); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 920 | if (!locations) return source; |
| 921 | locations.sort(function(x, y) { return x - y; }); |
| 922 | var result = ""; |
| 923 | var prev_pos = 0; |
| 924 | var pos; |
| 925 | for (var i = 0; i < locations.length; i++) { |
| 926 | pos = locations[i] - offset; |
| 927 | result += source.slice(prev_pos, pos); |
| 928 | result += "[B" + i + "]"; |
| 929 | prev_pos = pos; |
| 930 | } |
| 931 | pos = source.length; |
| 932 | result += source.substring(prev_pos, pos); |
| 933 | return result; |
| 934 | }; |
| 935 | |
| 936 | |
| 937 | // Get all the scripts currently loaded. Locating all the scripts is based on |
| 938 | // scanning the heap. |
| 939 | Debug.scripts = function() { |
| 940 | // Collect all scripts in the heap. |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 941 | return %DebugGetLoadedScripts(); |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 942 | }; |
| 943 | |
| 944 | |
| 945 | Debug.debuggerFlags = function() { |
| 946 | return debugger_flags; |
| 947 | }; |
| 948 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 949 | Debug.MakeMirror = MakeMirror; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 950 | |
| 951 | function MakeExecutionState(break_id) { |
| 952 | return new ExecutionState(break_id); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 953 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 954 | |
| 955 | function ExecutionState(break_id) { |
| 956 | this.break_id = break_id; |
| 957 | this.selected_frame = 0; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 958 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 959 | |
| 960 | ExecutionState.prototype.prepareStep = function(opt_action, opt_count) { |
| 961 | var action = Debug.StepAction.StepIn; |
| 962 | if (!IS_UNDEFINED(opt_action)) action = %ToNumber(opt_action); |
| 963 | var count = opt_count ? %ToNumber(opt_count) : 1; |
| 964 | |
| 965 | return %PrepareStep(this.break_id, action, count); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 966 | }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 967 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 968 | ExecutionState.prototype.evaluateGlobal = function(source, disable_break, |
| 969 | opt_additional_context) { |
| 970 | return MakeMirror(%DebugEvaluateGlobal(this.break_id, source, |
| 971 | Boolean(disable_break), |
| 972 | opt_additional_context)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 973 | }; |
| 974 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 975 | ExecutionState.prototype.frameCount = function() { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 976 | return %GetFrameCount(this.break_id); |
| 977 | }; |
| 978 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 979 | ExecutionState.prototype.threadCount = function() { |
| 980 | return %GetThreadCount(this.break_id); |
| 981 | }; |
| 982 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 983 | ExecutionState.prototype.frame = function(opt_index) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 984 | // If no index supplied return the selected frame. |
| 985 | if (opt_index == null) opt_index = this.selected_frame; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 986 | if (opt_index < 0 || opt_index >= this.frameCount()) { |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 987 | throw new Error('Illegal frame index.'); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 988 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 989 | return new FrameMirror(this.break_id, opt_index); |
| 990 | }; |
| 991 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 992 | ExecutionState.prototype.setSelectedFrame = function(index) { |
| 993 | var i = %ToNumber(index); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 994 | if (i < 0 || i >= this.frameCount()) throw new Error('Illegal frame index.'); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 995 | this.selected_frame = i; |
| 996 | }; |
| 997 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 998 | ExecutionState.prototype.selectedFrame = function() { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 999 | return this.selected_frame; |
| 1000 | }; |
| 1001 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1002 | ExecutionState.prototype.debugCommandProcessor = function(opt_is_running) { |
| 1003 | return new DebugCommandProcessor(this, opt_is_running); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1004 | }; |
| 1005 | |
| 1006 | |
| 1007 | function MakeBreakEvent(exec_state, break_points_hit) { |
| 1008 | return new BreakEvent(exec_state, break_points_hit); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1009 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1010 | |
| 1011 | |
| 1012 | function BreakEvent(exec_state, break_points_hit) { |
| 1013 | this.exec_state_ = exec_state; |
| 1014 | this.break_points_hit_ = break_points_hit; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1015 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1016 | |
| 1017 | |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 1018 | BreakEvent.prototype.executionState = function() { |
| 1019 | return this.exec_state_; |
| 1020 | }; |
| 1021 | |
| 1022 | |
| 1023 | BreakEvent.prototype.eventType = function() { |
| 1024 | return Debug.DebugEvent.Break; |
| 1025 | }; |
| 1026 | |
| 1027 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1028 | BreakEvent.prototype.func = function() { |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1029 | return this.exec_state_.frame(0).func(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1030 | }; |
| 1031 | |
| 1032 | |
| 1033 | BreakEvent.prototype.sourceLine = function() { |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1034 | return this.exec_state_.frame(0).sourceLine(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1035 | }; |
| 1036 | |
| 1037 | |
| 1038 | BreakEvent.prototype.sourceColumn = function() { |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1039 | return this.exec_state_.frame(0).sourceColumn(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1040 | }; |
| 1041 | |
| 1042 | |
| 1043 | BreakEvent.prototype.sourceLineText = function() { |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1044 | return this.exec_state_.frame(0).sourceLineText(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1045 | }; |
| 1046 | |
| 1047 | |
| 1048 | BreakEvent.prototype.breakPointsHit = function() { |
| 1049 | return this.break_points_hit_; |
| 1050 | }; |
| 1051 | |
| 1052 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1053 | BreakEvent.prototype.toJSONProtocol = function() { |
| 1054 | var o = { seq: next_response_seq++, |
| 1055 | type: "event", |
| 1056 | event: "break", |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1057 | body: { invocationText: this.exec_state_.frame(0).invocationText(), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1058 | } |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 1059 | }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1060 | |
| 1061 | // Add script related information to the event if available. |
| 1062 | var script = this.func().script(); |
| 1063 | if (script) { |
| 1064 | o.body.sourceLine = this.sourceLine(), |
| 1065 | o.body.sourceColumn = this.sourceColumn(), |
| 1066 | o.body.sourceLineText = this.sourceLineText(), |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1067 | o.body.script = MakeScriptObject_(script, false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1068 | } |
| 1069 | |
| 1070 | // Add an Array of break points hit if any. |
| 1071 | if (this.breakPointsHit()) { |
| 1072 | o.body.breakpoints = []; |
| 1073 | for (var i = 0; i < this.breakPointsHit().length; i++) { |
| 1074 | // Find the break point number. For break points originating from a |
| 1075 | // script break point supply the script break point number. |
| 1076 | var breakpoint = this.breakPointsHit()[i]; |
| 1077 | var script_break_point = breakpoint.script_break_point(); |
| 1078 | var number; |
| 1079 | if (script_break_point) { |
| 1080 | number = script_break_point.number(); |
| 1081 | } else { |
| 1082 | number = breakpoint.number(); |
| 1083 | } |
| 1084 | o.body.breakpoints.push(number); |
| 1085 | } |
| 1086 | } |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 1087 | return JSON.stringify(ObjectToProtocolObject_(o)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1088 | }; |
| 1089 | |
| 1090 | |
| 1091 | function MakeExceptionEvent(exec_state, exception, uncaught) { |
| 1092 | return new ExceptionEvent(exec_state, exception, uncaught); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1093 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1094 | |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 1095 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1096 | function ExceptionEvent(exec_state, exception, uncaught) { |
| 1097 | this.exec_state_ = exec_state; |
| 1098 | this.exception_ = exception; |
| 1099 | this.uncaught_ = uncaught; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1100 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1101 | |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 1102 | |
| 1103 | ExceptionEvent.prototype.executionState = function() { |
| 1104 | return this.exec_state_; |
| 1105 | }; |
| 1106 | |
| 1107 | |
| 1108 | ExceptionEvent.prototype.eventType = function() { |
| 1109 | return Debug.DebugEvent.Exception; |
| 1110 | }; |
| 1111 | |
| 1112 | |
| 1113 | ExceptionEvent.prototype.exception = function() { |
| 1114 | return this.exception_; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1115 | }; |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 1116 | |
| 1117 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1118 | ExceptionEvent.prototype.uncaught = function() { |
| 1119 | return this.uncaught_; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1120 | }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1121 | |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 1122 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1123 | ExceptionEvent.prototype.func = function() { |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1124 | return this.exec_state_.frame(0).func(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1125 | }; |
| 1126 | |
| 1127 | |
| 1128 | ExceptionEvent.prototype.sourceLine = function() { |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1129 | return this.exec_state_.frame(0).sourceLine(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1130 | }; |
| 1131 | |
| 1132 | |
| 1133 | ExceptionEvent.prototype.sourceColumn = function() { |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1134 | return this.exec_state_.frame(0).sourceColumn(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1135 | }; |
| 1136 | |
| 1137 | |
| 1138 | ExceptionEvent.prototype.sourceLineText = function() { |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1139 | return this.exec_state_.frame(0).sourceLineText(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1140 | }; |
| 1141 | |
| 1142 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1143 | ExceptionEvent.prototype.toJSONProtocol = function() { |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 1144 | var o = new ProtocolMessage(); |
| 1145 | o.event = "exception"; |
| 1146 | o.body = { uncaught: this.uncaught_, |
| 1147 | exception: MakeMirror(this.exception_) |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 1148 | }; |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 1149 | |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 1150 | // Exceptions might happen whithout any JavaScript frames. |
| 1151 | if (this.exec_state_.frameCount() > 0) { |
| 1152 | o.body.sourceLine = this.sourceLine(); |
| 1153 | o.body.sourceColumn = this.sourceColumn(); |
| 1154 | o.body.sourceLineText = this.sourceLineText(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1155 | |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 1156 | // Add script information to the event if available. |
| 1157 | var script = this.func().script(); |
| 1158 | if (script) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1159 | o.body.script = MakeScriptObject_(script, false); |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 1160 | } |
| 1161 | } else { |
| 1162 | o.body.sourceLine = -1; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1163 | } |
| 1164 | |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 1165 | return o.toJSONProtocol(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1166 | }; |
| 1167 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 1168 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 1169 | function MakeCompileEvent(exec_state, script, before) { |
| 1170 | return new CompileEvent(exec_state, script, before); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1171 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1172 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 1173 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 1174 | function CompileEvent(exec_state, script, before) { |
| 1175 | this.exec_state_ = exec_state; |
| 1176 | this.script_ = MakeMirror(script); |
| 1177 | this.before_ = before; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1178 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1179 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1180 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 1181 | CompileEvent.prototype.executionState = function() { |
| 1182 | return this.exec_state_; |
| 1183 | }; |
| 1184 | |
| 1185 | |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 1186 | CompileEvent.prototype.eventType = function() { |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 1187 | if (this.before_) { |
| 1188 | return Debug.DebugEvent.BeforeCompile; |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 1189 | } else { |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 1190 | return Debug.DebugEvent.AfterCompile; |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 1191 | } |
| 1192 | }; |
| 1193 | |
| 1194 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 1195 | CompileEvent.prototype.script = function() { |
| 1196 | return this.script_; |
| 1197 | }; |
| 1198 | |
| 1199 | |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 1200 | CompileEvent.prototype.toJSONProtocol = function() { |
| 1201 | var o = new ProtocolMessage(); |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 1202 | o.running = true; |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 1203 | if (this.before_) { |
| 1204 | o.event = "beforeCompile"; |
| 1205 | } else { |
| 1206 | o.event = "afterCompile"; |
| 1207 | } |
| 1208 | o.body = {}; |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 1209 | o.body.script = this.script_; |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 1210 | |
| 1211 | return o.toJSONProtocol(); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1212 | }; |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 1213 | |
| 1214 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1215 | function MakeNewFunctionEvent(func) { |
| 1216 | return new NewFunctionEvent(func); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1217 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1218 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 1219 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1220 | function NewFunctionEvent(func) { |
| 1221 | this.func = func; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1222 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1223 | |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 1224 | |
| 1225 | NewFunctionEvent.prototype.eventType = function() { |
| 1226 | return Debug.DebugEvent.NewFunction; |
| 1227 | }; |
| 1228 | |
| 1229 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1230 | NewFunctionEvent.prototype.name = function() { |
| 1231 | return this.func.name; |
| 1232 | }; |
| 1233 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 1234 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1235 | NewFunctionEvent.prototype.setBreakPoint = function(p) { |
| 1236 | Debug.setBreakPoint(this.func, p || 0); |
| 1237 | }; |
| 1238 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 1239 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 1240 | function MakeScriptCollectedEvent(exec_state, id) { |
| 1241 | return new ScriptCollectedEvent(exec_state, id); |
| 1242 | } |
| 1243 | |
| 1244 | |
| 1245 | function ScriptCollectedEvent(exec_state, id) { |
| 1246 | this.exec_state_ = exec_state; |
| 1247 | this.id_ = id; |
| 1248 | } |
| 1249 | |
| 1250 | |
| 1251 | ScriptCollectedEvent.prototype.id = function() { |
| 1252 | return this.id_; |
| 1253 | }; |
| 1254 | |
| 1255 | |
| 1256 | ScriptCollectedEvent.prototype.executionState = function() { |
| 1257 | return this.exec_state_; |
| 1258 | }; |
| 1259 | |
| 1260 | |
| 1261 | ScriptCollectedEvent.prototype.toJSONProtocol = function() { |
| 1262 | var o = new ProtocolMessage(); |
| 1263 | o.running = true; |
| 1264 | o.event = "scriptCollected"; |
| 1265 | o.body = {}; |
| 1266 | o.body.script = { id: this.id() }; |
| 1267 | return o.toJSONProtocol(); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1268 | }; |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 1269 | |
| 1270 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1271 | function MakeScriptObject_(script, include_source) { |
| 1272 | var o = { id: script.id(), |
| 1273 | name: script.name(), |
| 1274 | lineOffset: script.lineOffset(), |
| 1275 | columnOffset: script.columnOffset(), |
| 1276 | lineCount: script.lineCount(), |
| 1277 | }; |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1278 | if (!IS_UNDEFINED(script.data())) { |
| 1279 | o.data = script.data(); |
| 1280 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1281 | if (include_source) { |
| 1282 | o.source = script.source(); |
| 1283 | } |
| 1284 | return o; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1285 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1286 | |
| 1287 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1288 | function DebugCommandProcessor(exec_state, opt_is_running) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1289 | this.exec_state_ = exec_state; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1290 | this.running_ = opt_is_running || false; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1291 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1292 | |
| 1293 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 1294 | DebugCommandProcessor.prototype.processDebugRequest = function (request) { |
| 1295 | return this.processDebugJSONRequest(request); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1296 | }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1297 | |
| 1298 | |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 1299 | function ProtocolMessage(request) { |
| 1300 | // Update sequence number. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1301 | this.seq = next_response_seq++; |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 1302 | |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 1303 | if (request) { |
| 1304 | // If message is based on a request this is a response. Fill the initial |
| 1305 | // response from the request. |
| 1306 | this.type = 'response'; |
| 1307 | this.request_seq = request.seq; |
| 1308 | this.command = request.command; |
| 1309 | } else { |
| 1310 | // If message is not based on a request it is a dabugger generated event. |
| 1311 | this.type = 'event'; |
| 1312 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1313 | this.success = true; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1314 | // Handler may set this field to control debugger state. |
| 1315 | this.running = undefined; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1316 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1317 | |
| 1318 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1319 | ProtocolMessage.prototype.setOption = function(name, value) { |
| 1320 | if (!this.options_) { |
| 1321 | this.options_ = {}; |
| 1322 | } |
| 1323 | this.options_[name] = value; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1324 | }; |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1325 | |
| 1326 | |
mmassi@chromium.org | 49a4467 | 2012-12-04 13:52:03 +0000 | [diff] [blame] | 1327 | ProtocolMessage.prototype.failed = function(message, opt_details) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1328 | this.success = false; |
| 1329 | this.message = message; |
mmassi@chromium.org | 49a4467 | 2012-12-04 13:52:03 +0000 | [diff] [blame] | 1330 | if (IS_OBJECT(opt_details)) { |
| 1331 | this.error_details = opt_details; |
| 1332 | } |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1333 | }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1334 | |
| 1335 | |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 1336 | ProtocolMessage.prototype.toJSONProtocol = function() { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1337 | // Encode the protocol header. |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 1338 | var json = {}; |
| 1339 | json.seq= this.seq; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1340 | if (this.request_seq) { |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 1341 | json.request_seq = this.request_seq; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1342 | } |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 1343 | json.type = this.type; |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 1344 | if (this.event) { |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 1345 | json.event = this.event; |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 1346 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1347 | if (this.command) { |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 1348 | json.command = this.command; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1349 | } |
| 1350 | if (this.success) { |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 1351 | json.success = this.success; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1352 | } else { |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 1353 | json.success = false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1354 | } |
| 1355 | if (this.body) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1356 | // Encode the body part. |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 1357 | var bodyJson; |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1358 | var serializer = MakeMirrorSerializer(true, this.options_); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1359 | if (this.body instanceof Mirror) { |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 1360 | bodyJson = serializer.serializeValue(this.body); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1361 | } else if (this.body instanceof Array) { |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 1362 | bodyJson = []; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1363 | for (var i = 0; i < this.body.length; i++) { |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1364 | if (this.body[i] instanceof Mirror) { |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 1365 | bodyJson.push(serializer.serializeValue(this.body[i])); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1366 | } else { |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 1367 | bodyJson.push(ObjectToProtocolObject_(this.body[i], serializer)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1368 | } |
| 1369 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1370 | } else { |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 1371 | bodyJson = ObjectToProtocolObject_(this.body, serializer); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1372 | } |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 1373 | json.body = bodyJson; |
| 1374 | json.refs = serializer.serializeReferencedObjects(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1375 | } |
| 1376 | if (this.message) { |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 1377 | json.message = this.message; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1378 | } |
mmassi@chromium.org | 49a4467 | 2012-12-04 13:52:03 +0000 | [diff] [blame] | 1379 | if (this.error_details) { |
| 1380 | json.error_details = this.error_details; |
| 1381 | } |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1382 | json.running = this.running; |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 1383 | return JSON.stringify(json); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1384 | }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1385 | |
| 1386 | |
| 1387 | DebugCommandProcessor.prototype.createResponse = function(request) { |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 1388 | return new ProtocolMessage(request); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1389 | }; |
| 1390 | |
| 1391 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1392 | DebugCommandProcessor.prototype.processDebugJSONRequest = function( |
| 1393 | json_request) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1394 | var request; // Current request. |
| 1395 | var response; // Generated response. |
| 1396 | try { |
| 1397 | try { |
| 1398 | // Convert the JSON string to an object. |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 1399 | request = JSON.parse(json_request); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1400 | |
| 1401 | // Create an initial response. |
| 1402 | response = this.createResponse(request); |
| 1403 | |
| 1404 | if (!request.type) { |
| 1405 | throw new Error('Type not specified'); |
| 1406 | } |
| 1407 | |
| 1408 | if (request.type != 'request') { |
| 1409 | throw new Error("Illegal type '" + request.type + "' in request"); |
| 1410 | } |
| 1411 | |
| 1412 | if (!request.command) { |
| 1413 | throw new Error('Command not specified'); |
| 1414 | } |
| 1415 | |
fschneider@chromium.org | b95b98b | 2010-02-23 10:34:29 +0000 | [diff] [blame] | 1416 | if (request.arguments) { |
| 1417 | var args = request.arguments; |
| 1418 | // TODO(yurys): remove request.arguments.compactFormat check once |
| 1419 | // ChromeDevTools are switched to 'inlineRefs' |
| 1420 | if (args.inlineRefs || args.compactFormat) { |
| 1421 | response.setOption('inlineRefs', true); |
| 1422 | } |
| 1423 | if (!IS_UNDEFINED(args.maxStringLength)) { |
| 1424 | response.setOption('maxStringLength', args.maxStringLength); |
| 1425 | } |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 1426 | } |
| 1427 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1428 | if (request.command == 'continue') { |
| 1429 | this.continueRequest_(request, response); |
| 1430 | } else if (request.command == 'break') { |
| 1431 | this.breakRequest_(request, response); |
| 1432 | } else if (request.command == 'setbreakpoint') { |
| 1433 | this.setBreakPointRequest_(request, response); |
| 1434 | } else if (request.command == 'changebreakpoint') { |
| 1435 | this.changeBreakPointRequest_(request, response); |
| 1436 | } else if (request.command == 'clearbreakpoint') { |
| 1437 | this.clearBreakPointRequest_(request, response); |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 1438 | } else if (request.command == 'clearbreakpointgroup') { |
| 1439 | this.clearBreakPointGroupRequest_(request, response); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1440 | } else if (request.command == 'disconnect') { |
| 1441 | this.disconnectRequest_(request, response); |
| 1442 | } else if (request.command == 'setexceptionbreak') { |
| 1443 | this.setExceptionBreakRequest_(request, response); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 1444 | } else if (request.command == 'listbreakpoints') { |
| 1445 | this.listBreakpointsRequest_(request, response); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1446 | } else if (request.command == 'backtrace') { |
| 1447 | this.backtraceRequest_(request, response); |
| 1448 | } else if (request.command == 'frame') { |
| 1449 | this.frameRequest_(request, response); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1450 | } else if (request.command == 'scopes') { |
| 1451 | this.scopesRequest_(request, response); |
| 1452 | } else if (request.command == 'scope') { |
| 1453 | this.scopeRequest_(request, response); |
mmassi@chromium.org | 49a4467 | 2012-12-04 13:52:03 +0000 | [diff] [blame] | 1454 | } else if (request.command == 'setVariableValue') { |
| 1455 | this.setVariableValueRequest_(request, response); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1456 | } else if (request.command == 'evaluate') { |
| 1457 | this.evaluateRequest_(request, response); |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 1458 | } else if (request.command == 'lookup') { |
| 1459 | this.lookupRequest_(request, response); |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 1460 | } else if (request.command == 'references') { |
| 1461 | this.referencesRequest_(request, response); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1462 | } else if (request.command == 'source') { |
| 1463 | this.sourceRequest_(request, response); |
| 1464 | } else if (request.command == 'scripts') { |
| 1465 | this.scriptsRequest_(request, response); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1466 | } else if (request.command == 'threads') { |
| 1467 | this.threadsRequest_(request, response); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1468 | } else if (request.command == 'suspend') { |
| 1469 | this.suspendRequest_(request, response); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1470 | } else if (request.command == 'version') { |
| 1471 | this.versionRequest_(request, response); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 1472 | } else if (request.command == 'profile') { |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 1473 | this.profileRequest_(request, response); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1474 | } else if (request.command == 'changelive') { |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 1475 | this.changeLiveRequest_(request, response); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 1476 | } else if (request.command == 'restartframe') { |
| 1477 | this.restartFrameRequest_(request, response); |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 1478 | } else if (request.command == 'flags') { |
| 1479 | this.debuggerFlagsRequest_(request, response); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1480 | } else if (request.command == 'v8flags') { |
| 1481 | this.v8FlagsRequest_(request, response); |
| 1482 | |
| 1483 | // GC tools: |
| 1484 | } else if (request.command == 'gc') { |
| 1485 | this.gcRequest_(request, response); |
| 1486 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1487 | } else { |
| 1488 | throw new Error('Unknown command "' + request.command + '" in request'); |
| 1489 | } |
| 1490 | } catch (e) { |
| 1491 | // If there is no response object created one (without command). |
| 1492 | if (!response) { |
| 1493 | response = this.createResponse(); |
| 1494 | } |
| 1495 | response.success = false; |
| 1496 | response.message = %ToString(e); |
| 1497 | } |
| 1498 | |
| 1499 | // Return the response as a JSON encoded string. |
| 1500 | try { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1501 | if (!IS_UNDEFINED(response.running)) { |
| 1502 | // Response controls running state. |
| 1503 | this.running_ = response.running; |
| 1504 | } |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 1505 | response.running = this.running_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1506 | return response.toJSONProtocol(); |
| 1507 | } catch (e) { |
| 1508 | // Failed to generate response - return generic error. |
| 1509 | return '{"seq":' + response.seq + ',' + |
| 1510 | '"request_seq":' + request.seq + ',' + |
| 1511 | '"type":"response",' + |
| 1512 | '"success":false,' + |
| 1513 | '"message":"Internal error: ' + %ToString(e) + '"}'; |
| 1514 | } |
| 1515 | } catch (e) { |
| 1516 | // Failed in one of the catch blocks above - most generic error. |
| 1517 | return '{"seq":0,"type":"response","success":false,"message":"Internal error"}'; |
| 1518 | } |
| 1519 | }; |
| 1520 | |
| 1521 | |
| 1522 | DebugCommandProcessor.prototype.continueRequest_ = function(request, response) { |
| 1523 | // Check for arguments for continue. |
| 1524 | if (request.arguments) { |
| 1525 | var count = 1; |
| 1526 | var action = Debug.StepAction.StepIn; |
| 1527 | |
| 1528 | // Pull out arguments. |
| 1529 | var stepaction = request.arguments.stepaction; |
| 1530 | var stepcount = request.arguments.stepcount; |
| 1531 | |
| 1532 | // Get the stepcount argument if any. |
| 1533 | if (stepcount) { |
| 1534 | count = %ToNumber(stepcount); |
| 1535 | if (count < 0) { |
| 1536 | throw new Error('Invalid stepcount argument "' + stepcount + '".'); |
| 1537 | } |
| 1538 | } |
| 1539 | |
| 1540 | // Get the stepaction argument. |
| 1541 | if (stepaction) { |
| 1542 | if (stepaction == 'in') { |
| 1543 | action = Debug.StepAction.StepIn; |
| 1544 | } else if (stepaction == 'min') { |
| 1545 | action = Debug.StepAction.StepMin; |
| 1546 | } else if (stepaction == 'next') { |
| 1547 | action = Debug.StepAction.StepNext; |
| 1548 | } else if (stepaction == 'out') { |
| 1549 | action = Debug.StepAction.StepOut; |
| 1550 | } else { |
| 1551 | throw new Error('Invalid stepaction argument "' + stepaction + '".'); |
| 1552 | } |
| 1553 | } |
| 1554 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1555 | // Set up the VM for stepping. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1556 | this.exec_state_.prepareStep(action, count); |
| 1557 | } |
| 1558 | |
| 1559 | // VM should be running after executing this request. |
| 1560 | response.running = true; |
| 1561 | }; |
| 1562 | |
| 1563 | |
| 1564 | DebugCommandProcessor.prototype.breakRequest_ = function(request, response) { |
| 1565 | // Ignore as break command does not do anything when broken. |
| 1566 | }; |
| 1567 | |
| 1568 | |
| 1569 | DebugCommandProcessor.prototype.setBreakPointRequest_ = |
| 1570 | function(request, response) { |
| 1571 | // Check for legal request. |
| 1572 | if (!request.arguments) { |
| 1573 | response.failed('Missing arguments'); |
| 1574 | return; |
| 1575 | } |
| 1576 | |
| 1577 | // Pull out arguments. |
| 1578 | var type = request.arguments.type; |
| 1579 | var target = request.arguments.target; |
| 1580 | var line = request.arguments.line; |
| 1581 | var column = request.arguments.column; |
| 1582 | var enabled = IS_UNDEFINED(request.arguments.enabled) ? |
| 1583 | true : request.arguments.enabled; |
| 1584 | var condition = request.arguments.condition; |
| 1585 | var ignoreCount = request.arguments.ignoreCount; |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 1586 | var groupId = request.arguments.groupId; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1587 | |
| 1588 | // Check for legal arguments. |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1589 | if (!type || IS_UNDEFINED(target)) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1590 | response.failed('Missing argument "type" or "target"'); |
| 1591 | return; |
| 1592 | } |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1593 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1594 | // Either function or script break point. |
| 1595 | var break_point_number; |
| 1596 | if (type == 'function') { |
| 1597 | // Handle function break point. |
| 1598 | if (!IS_STRING(target)) { |
| 1599 | response.failed('Argument "target" is not a string value'); |
| 1600 | return; |
| 1601 | } |
| 1602 | var f; |
| 1603 | try { |
| 1604 | // Find the function through a global evaluate. |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1605 | f = this.exec_state_.evaluateGlobal(target).value(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1606 | } catch (e) { |
| 1607 | response.failed('Error: "' + %ToString(e) + |
| 1608 | '" evaluating "' + target + '"'); |
| 1609 | return; |
| 1610 | } |
| 1611 | if (!IS_FUNCTION(f)) { |
| 1612 | response.failed('"' + target + '" does not evaluate to a function'); |
| 1613 | return; |
| 1614 | } |
| 1615 | |
| 1616 | // Set function break point. |
| 1617 | break_point_number = Debug.setBreakPoint(f, line, column, condition); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1618 | } else if (type == 'handle') { |
| 1619 | // Find the object pointed by the specified handle. |
| 1620 | var handle = parseInt(target, 10); |
| 1621 | var mirror = LookupMirror(handle); |
| 1622 | if (!mirror) { |
| 1623 | return response.failed('Object #' + handle + '# not found'); |
| 1624 | } |
| 1625 | if (!mirror.isFunction()) { |
| 1626 | return response.failed('Object #' + handle + '# is not a function'); |
| 1627 | } |
| 1628 | |
| 1629 | // Set function break point. |
| 1630 | break_point_number = Debug.setBreakPoint(mirror.value(), |
| 1631 | line, column, condition); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1632 | } else if (type == 'script') { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1633 | // set script break point. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1634 | break_point_number = |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 1635 | Debug.setScriptBreakPointByName(target, line, column, condition, |
| 1636 | groupId); |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1637 | } else if (type == 'scriptId') { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1638 | break_point_number = |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 1639 | Debug.setScriptBreakPointById(target, line, column, condition, groupId); |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1640 | } else if (type == 'scriptRegExp') { |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 1641 | break_point_number = |
| 1642 | Debug.setScriptBreakPointByRegExp(target, line, column, condition, |
| 1643 | groupId); |
| 1644 | } else { |
| 1645 | response.failed('Illegal type "' + type + '"'); |
| 1646 | return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1647 | } |
| 1648 | |
| 1649 | // Set additional break point properties. |
| 1650 | var break_point = Debug.findBreakPoint(break_point_number); |
| 1651 | if (ignoreCount) { |
| 1652 | Debug.changeBreakPointIgnoreCount(break_point_number, ignoreCount); |
| 1653 | } |
| 1654 | if (!enabled) { |
| 1655 | Debug.disableBreakPoint(break_point_number); |
| 1656 | } |
| 1657 | |
| 1658 | // Add the break point number to the response. |
| 1659 | response.body = { type: type, |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1660 | breakpoint: break_point_number }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1661 | |
| 1662 | // Add break point information to the response. |
| 1663 | if (break_point instanceof ScriptBreakPoint) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1664 | if (break_point.type() == Debug.ScriptBreakPointType.ScriptId) { |
| 1665 | response.body.type = 'scriptId'; |
| 1666 | response.body.script_id = break_point.script_id(); |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 1667 | } else if (break_point.type() == Debug.ScriptBreakPointType.ScriptName) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1668 | response.body.type = 'scriptName'; |
| 1669 | response.body.script_name = break_point.script_name(); |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 1670 | } else if (break_point.type() == Debug.ScriptBreakPointType.ScriptRegExp) { |
| 1671 | response.body.type = 'scriptRegExp'; |
| 1672 | response.body.script_regexp = break_point.script_regexp_object().source; |
| 1673 | } else { |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1674 | throw new Error("Internal error: Unexpected breakpoint type: " + |
| 1675 | break_point.type()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1676 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1677 | response.body.line = break_point.line(); |
| 1678 | response.body.column = break_point.column(); |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 1679 | response.body.actual_locations = break_point.actual_locations(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1680 | } else { |
| 1681 | response.body.type = 'function'; |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 1682 | response.body.actual_locations = [break_point.actual_location]; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1683 | } |
| 1684 | }; |
| 1685 | |
| 1686 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1687 | DebugCommandProcessor.prototype.changeBreakPointRequest_ = function( |
| 1688 | request, response) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1689 | // Check for legal request. |
| 1690 | if (!request.arguments) { |
| 1691 | response.failed('Missing arguments'); |
| 1692 | return; |
| 1693 | } |
| 1694 | |
| 1695 | // Pull out arguments. |
| 1696 | var break_point = %ToNumber(request.arguments.breakpoint); |
| 1697 | var enabled = request.arguments.enabled; |
| 1698 | var condition = request.arguments.condition; |
| 1699 | var ignoreCount = request.arguments.ignoreCount; |
| 1700 | |
| 1701 | // Check for legal arguments. |
| 1702 | if (!break_point) { |
| 1703 | response.failed('Missing argument "breakpoint"'); |
| 1704 | return; |
| 1705 | } |
| 1706 | |
| 1707 | // Change enabled state if supplied. |
| 1708 | if (!IS_UNDEFINED(enabled)) { |
| 1709 | if (enabled) { |
| 1710 | Debug.enableBreakPoint(break_point); |
| 1711 | } else { |
| 1712 | Debug.disableBreakPoint(break_point); |
| 1713 | } |
| 1714 | } |
| 1715 | |
| 1716 | // Change condition if supplied |
| 1717 | if (!IS_UNDEFINED(condition)) { |
| 1718 | Debug.changeBreakPointCondition(break_point, condition); |
| 1719 | } |
| 1720 | |
| 1721 | // Change ignore count if supplied |
| 1722 | if (!IS_UNDEFINED(ignoreCount)) { |
| 1723 | Debug.changeBreakPointIgnoreCount(break_point, ignoreCount); |
| 1724 | } |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1725 | }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1726 | |
| 1727 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1728 | DebugCommandProcessor.prototype.clearBreakPointGroupRequest_ = function( |
| 1729 | request, response) { |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 1730 | // Check for legal request. |
| 1731 | if (!request.arguments) { |
| 1732 | response.failed('Missing arguments'); |
| 1733 | return; |
| 1734 | } |
| 1735 | |
| 1736 | // Pull out arguments. |
| 1737 | var group_id = request.arguments.groupId; |
| 1738 | |
| 1739 | // Check for legal arguments. |
| 1740 | if (!group_id) { |
| 1741 | response.failed('Missing argument "groupId"'); |
| 1742 | return; |
| 1743 | } |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 1744 | |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 1745 | var cleared_break_points = []; |
| 1746 | var new_script_break_points = []; |
| 1747 | for (var i = 0; i < script_break_points.length; i++) { |
| 1748 | var next_break_point = script_break_points[i]; |
| 1749 | if (next_break_point.groupId() == group_id) { |
| 1750 | cleared_break_points.push(next_break_point.number()); |
| 1751 | next_break_point.clear(); |
| 1752 | } else { |
| 1753 | new_script_break_points.push(next_break_point); |
| 1754 | } |
| 1755 | } |
| 1756 | script_break_points = new_script_break_points; |
| 1757 | |
| 1758 | // Add the cleared break point numbers to the response. |
| 1759 | response.body = { breakpoints: cleared_break_points }; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1760 | }; |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 1761 | |
| 1762 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1763 | DebugCommandProcessor.prototype.clearBreakPointRequest_ = function( |
| 1764 | request, response) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1765 | // Check for legal request. |
| 1766 | if (!request.arguments) { |
| 1767 | response.failed('Missing arguments'); |
| 1768 | return; |
| 1769 | } |
| 1770 | |
| 1771 | // Pull out arguments. |
| 1772 | var break_point = %ToNumber(request.arguments.breakpoint); |
| 1773 | |
| 1774 | // Check for legal arguments. |
| 1775 | if (!break_point) { |
| 1776 | response.failed('Missing argument "breakpoint"'); |
| 1777 | return; |
| 1778 | } |
| 1779 | |
| 1780 | // Clear break point. |
| 1781 | Debug.clearBreakPoint(break_point); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 1782 | |
| 1783 | // Add the cleared break point number to the response. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1784 | response.body = { breakpoint: break_point }; |
| 1785 | }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1786 | |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 1787 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1788 | DebugCommandProcessor.prototype.listBreakpointsRequest_ = function( |
| 1789 | request, response) { |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 1790 | var array = []; |
| 1791 | for (var i = 0; i < script_break_points.length; i++) { |
| 1792 | var break_point = script_break_points[i]; |
| 1793 | |
| 1794 | var description = { |
| 1795 | number: break_point.number(), |
| 1796 | line: break_point.line(), |
| 1797 | column: break_point.column(), |
| 1798 | groupId: break_point.groupId(), |
| 1799 | hit_count: break_point.hit_count(), |
| 1800 | active: break_point.active(), |
| 1801 | condition: break_point.condition(), |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 1802 | ignoreCount: break_point.ignoreCount(), |
| 1803 | actual_locations: break_point.actual_locations() |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1804 | }; |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 1805 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 1806 | if (break_point.type() == Debug.ScriptBreakPointType.ScriptId) { |
| 1807 | description.type = 'scriptId'; |
| 1808 | description.script_id = break_point.script_id(); |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 1809 | } else if (break_point.type() == Debug.ScriptBreakPointType.ScriptName) { |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 1810 | description.type = 'scriptName'; |
| 1811 | description.script_name = break_point.script_name(); |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 1812 | } else if (break_point.type() == Debug.ScriptBreakPointType.ScriptRegExp) { |
| 1813 | description.type = 'scriptRegExp'; |
| 1814 | description.script_regexp = break_point.script_regexp_object().source; |
| 1815 | } else { |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1816 | throw new Error("Internal error: Unexpected breakpoint type: " + |
| 1817 | break_point.type()); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 1818 | } |
| 1819 | array.push(description); |
| 1820 | } |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 1821 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1822 | response.body = { |
| 1823 | breakpoints: array, |
| 1824 | breakOnExceptions: Debug.isBreakOnException(), |
| 1825 | breakOnUncaughtExceptions: Debug.isBreakOnUncaughtException() |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1826 | }; |
| 1827 | }; |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1828 | |
| 1829 | |
| 1830 | DebugCommandProcessor.prototype.disconnectRequest_ = |
| 1831 | function(request, response) { |
| 1832 | Debug.disableAllBreakPoints(); |
| 1833 | this.continueRequest_(request, response); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1834 | }; |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1835 | |
| 1836 | |
| 1837 | DebugCommandProcessor.prototype.setExceptionBreakRequest_ = |
| 1838 | function(request, response) { |
| 1839 | // Check for legal request. |
| 1840 | if (!request.arguments) { |
| 1841 | response.failed('Missing arguments'); |
| 1842 | return; |
| 1843 | } |
| 1844 | |
| 1845 | // Pull out and check the 'type' argument: |
| 1846 | var type = request.arguments.type; |
| 1847 | if (!type) { |
| 1848 | response.failed('Missing argument "type"'); |
| 1849 | return; |
| 1850 | } |
| 1851 | |
| 1852 | // Initialize the default value of enable: |
| 1853 | var enabled; |
| 1854 | if (type == 'all') { |
| 1855 | enabled = !Debug.isBreakOnException(); |
| 1856 | } else if (type == 'uncaught') { |
| 1857 | enabled = !Debug.isBreakOnUncaughtException(); |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1858 | } |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1859 | |
| 1860 | // Pull out and check the 'enabled' argument if present: |
| 1861 | if (!IS_UNDEFINED(request.arguments.enabled)) { |
| 1862 | enabled = request.arguments.enabled; |
| 1863 | if ((enabled != true) && (enabled != false)) { |
| 1864 | response.failed('Illegal value for "enabled":"' + enabled + '"'); |
| 1865 | } |
| 1866 | } |
| 1867 | |
| 1868 | // Now set the exception break state: |
| 1869 | if (type == 'all') { |
| 1870 | %ChangeBreakOnException(Debug.ExceptionBreak.Caught, enabled); |
| 1871 | } else if (type == 'uncaught') { |
| 1872 | %ChangeBreakOnException(Debug.ExceptionBreak.Uncaught, enabled); |
| 1873 | } else { |
| 1874 | response.failed('Unknown "type":"' + type + '"'); |
| 1875 | } |
| 1876 | |
| 1877 | // Add the cleared break point number to the response. |
| 1878 | response.body = { 'type': type, 'enabled': enabled }; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1879 | }; |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 1880 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1881 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1882 | DebugCommandProcessor.prototype.backtraceRequest_ = function( |
| 1883 | request, response) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1884 | // Get the number of frames. |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1885 | var total_frames = this.exec_state_.frameCount(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1886 | |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 1887 | // Create simple response if there are no frames. |
| 1888 | if (total_frames == 0) { |
| 1889 | response.body = { |
| 1890 | totalFrames: total_frames |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1891 | }; |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 1892 | return; |
| 1893 | } |
| 1894 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1895 | // Default frame range to include in backtrace. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1896 | var from_index = 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1897 | var to_index = kDefaultBacktraceLength; |
| 1898 | |
| 1899 | // Get the range from the arguments. |
| 1900 | if (request.arguments) { |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 1901 | if (request.arguments.fromFrame) { |
| 1902 | from_index = request.arguments.fromFrame; |
| 1903 | } |
| 1904 | if (request.arguments.toFrame) { |
| 1905 | to_index = request.arguments.toFrame; |
| 1906 | } |
| 1907 | if (request.arguments.bottom) { |
| 1908 | var tmp_index = total_frames - from_index; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1909 | from_index = total_frames - to_index; |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 1910 | to_index = tmp_index; |
| 1911 | } |
| 1912 | if (from_index < 0 || to_index < 0) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1913 | return response.failed('Invalid frame number'); |
| 1914 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1915 | } |
| 1916 | |
| 1917 | // Adjust the index. |
| 1918 | to_index = Math.min(total_frames, to_index); |
| 1919 | |
| 1920 | if (to_index <= from_index) { |
| 1921 | var error = 'Invalid frame range'; |
| 1922 | return response.failed(error); |
| 1923 | } |
| 1924 | |
| 1925 | // Create the response body. |
| 1926 | var frames = []; |
| 1927 | for (var i = from_index; i < to_index; i++) { |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1928 | frames.push(this.exec_state_.frame(i)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1929 | } |
| 1930 | response.body = { |
| 1931 | fromFrame: from_index, |
| 1932 | toFrame: to_index, |
| 1933 | totalFrames: total_frames, |
| 1934 | frames: frames |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1935 | }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1936 | }; |
| 1937 | |
| 1938 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1939 | DebugCommandProcessor.prototype.frameRequest_ = function(request, response) { |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 1940 | // No frames no source. |
| 1941 | if (this.exec_state_.frameCount() == 0) { |
| 1942 | return response.failed('No frames'); |
| 1943 | } |
| 1944 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1945 | // With no arguments just keep the selected frame. |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 1946 | if (request.arguments) { |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1947 | var index = request.arguments.number; |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 1948 | if (index < 0 || this.exec_state_.frameCount() <= index) { |
| 1949 | return response.failed('Invalid frame number'); |
| 1950 | } |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 1951 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1952 | this.exec_state_.setSelectedFrame(request.arguments.number); |
| 1953 | } |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1954 | response.body = this.exec_state_.frame(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1955 | }; |
| 1956 | |
| 1957 | |
mmassi@chromium.org | 49a4467 | 2012-12-04 13:52:03 +0000 | [diff] [blame] | 1958 | DebugCommandProcessor.prototype.resolveFrameFromScopeDescription_ = |
| 1959 | function(scope_description) { |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1960 | // Get the frame for which the scope or scopes are requested. |
| 1961 | // With no frameNumber argument use the currently selected frame. |
mmassi@chromium.org | 49a4467 | 2012-12-04 13:52:03 +0000 | [diff] [blame] | 1962 | if (scope_description && !IS_UNDEFINED(scope_description.frameNumber)) { |
| 1963 | frame_index = scope_description.frameNumber; |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1964 | if (frame_index < 0 || this.exec_state_.frameCount() <= frame_index) { |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 1965 | throw new Error('Invalid frame number'); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1966 | } |
| 1967 | return this.exec_state_.frame(frame_index); |
| 1968 | } else { |
| 1969 | return this.exec_state_.frame(); |
| 1970 | } |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1971 | }; |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1972 | |
| 1973 | |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 1974 | // Gets scope host object from request. It is either a function |
| 1975 | // ('functionHandle' argument must be specified) or a stack frame |
| 1976 | // ('frameNumber' may be specified and the current frame is taken by default). |
mmassi@chromium.org | 49a4467 | 2012-12-04 13:52:03 +0000 | [diff] [blame] | 1977 | DebugCommandProcessor.prototype.resolveScopeHolder_ = |
| 1978 | function(scope_description) { |
| 1979 | if (scope_description && "functionHandle" in scope_description) { |
| 1980 | if (!IS_NUMBER(scope_description.functionHandle)) { |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 1981 | throw new Error('Function handle must be a number'); |
| 1982 | } |
mmassi@chromium.org | 49a4467 | 2012-12-04 13:52:03 +0000 | [diff] [blame] | 1983 | var function_mirror = LookupMirror(scope_description.functionHandle); |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 1984 | if (!function_mirror) { |
| 1985 | throw new Error('Failed to find function object by handle'); |
| 1986 | } |
| 1987 | if (!function_mirror.isFunction()) { |
| 1988 | throw new Error('Value of non-function type is found by handle'); |
| 1989 | } |
| 1990 | return function_mirror; |
| 1991 | } else { |
| 1992 | // No frames no scopes. |
| 1993 | if (this.exec_state_.frameCount() == 0) { |
| 1994 | throw new Error('No scopes'); |
| 1995 | } |
| 1996 | |
| 1997 | // Get the frame for which the scopes are requested. |
mmassi@chromium.org | 49a4467 | 2012-12-04 13:52:03 +0000 | [diff] [blame] | 1998 | var frame = this.resolveFrameFromScopeDescription_(scope_description); |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 1999 | return frame; |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2000 | } |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 2001 | } |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2002 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 2003 | |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 2004 | DebugCommandProcessor.prototype.scopesRequest_ = function(request, response) { |
mmassi@chromium.org | 49a4467 | 2012-12-04 13:52:03 +0000 | [diff] [blame] | 2005 | var scope_holder = this.resolveScopeHolder_(request.arguments); |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 2006 | |
| 2007 | // Fill all scopes for this frame or function. |
| 2008 | var total_scopes = scope_holder.scopeCount(); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2009 | var scopes = []; |
| 2010 | for (var i = 0; i < total_scopes; i++) { |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 2011 | scopes.push(scope_holder.scope(i)); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2012 | } |
| 2013 | response.body = { |
| 2014 | fromScope: 0, |
| 2015 | toScope: total_scopes, |
| 2016 | totalScopes: total_scopes, |
| 2017 | scopes: scopes |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2018 | }; |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2019 | }; |
| 2020 | |
| 2021 | |
| 2022 | DebugCommandProcessor.prototype.scopeRequest_ = function(request, response) { |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 2023 | // Get the frame or function for which the scope is requested. |
mmassi@chromium.org | 49a4467 | 2012-12-04 13:52:03 +0000 | [diff] [blame] | 2024 | var scope_holder = this.resolveScopeHolder_(request.arguments); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2025 | |
| 2026 | // With no scope argument just return top scope. |
| 2027 | var scope_index = 0; |
| 2028 | if (request.arguments && !IS_UNDEFINED(request.arguments.number)) { |
| 2029 | scope_index = %ToNumber(request.arguments.number); |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 2030 | if (scope_index < 0 || scope_holder.scopeCount() <= scope_index) { |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2031 | return response.failed('Invalid scope number'); |
| 2032 | } |
| 2033 | } |
| 2034 | |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 2035 | response.body = scope_holder.scope(scope_index); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2036 | }; |
| 2037 | |
| 2038 | |
mmassi@chromium.org | 49a4467 | 2012-12-04 13:52:03 +0000 | [diff] [blame] | 2039 | // Reads value from protocol description. Description may be in form of type |
| 2040 | // (for singletons), raw value (primitive types supported in JSON), |
| 2041 | // string value description plus type (for primitive values) or handle id. |
| 2042 | // Returns raw value or throws exception. |
| 2043 | DebugCommandProcessor.resolveValue_ = function(value_description) { |
| 2044 | if ("handle" in value_description) { |
| 2045 | var value_mirror = LookupMirror(value_description.handle); |
| 2046 | if (!value_mirror) { |
| 2047 | throw new Error("Failed to resolve value by handle, ' #" + |
| 2048 | mapping.handle + "# not found"); |
| 2049 | } |
| 2050 | return value_mirror.value(); |
| 2051 | } else if ("stringDescription" in value_description) { |
| 2052 | if (value_description.type == BOOLEAN_TYPE) { |
| 2053 | return Boolean(value_description.stringDescription); |
| 2054 | } else if (value_description.type == NUMBER_TYPE) { |
| 2055 | return Number(value_description.stringDescription); |
| 2056 | } if (value_description.type == STRING_TYPE) { |
| 2057 | return String(value_description.stringDescription); |
| 2058 | } else { |
| 2059 | throw new Error("Unknown type"); |
| 2060 | } |
| 2061 | } else if ("value" in value_description) { |
| 2062 | return value_description.value; |
| 2063 | } else if (value_description.type == UNDEFINED_TYPE) { |
| 2064 | return void 0; |
| 2065 | } else if (value_description.type == NULL_TYPE) { |
| 2066 | return null; |
| 2067 | } else { |
| 2068 | throw new Error("Failed to parse value description"); |
| 2069 | } |
| 2070 | }; |
| 2071 | |
| 2072 | |
| 2073 | DebugCommandProcessor.prototype.setVariableValueRequest_ = |
| 2074 | function(request, response) { |
| 2075 | if (!request.arguments) { |
| 2076 | response.failed('Missing arguments'); |
| 2077 | return; |
| 2078 | } |
| 2079 | |
| 2080 | if (IS_UNDEFINED(request.arguments.name)) { |
| 2081 | response.failed('Missing variable name'); |
| 2082 | } |
| 2083 | var variable_name = request.arguments.name; |
| 2084 | |
| 2085 | var scope_description = request.arguments.scope; |
| 2086 | |
| 2087 | // Get the frame or function for which the scope is requested. |
| 2088 | var scope_holder = this.resolveScopeHolder_(scope_description); |
| 2089 | |
| 2090 | if (IS_UNDEFINED(scope_description.number)) { |
| 2091 | response.failed('Missing scope number'); |
| 2092 | } |
| 2093 | var scope_index = %ToNumber(scope_description.number); |
| 2094 | |
| 2095 | var scope = scope_holder.scope(scope_index); |
| 2096 | |
| 2097 | var new_value = |
| 2098 | DebugCommandProcessor.resolveValue_(request.arguments.newValue); |
| 2099 | |
| 2100 | scope.setVariableValue(variable_name, new_value); |
| 2101 | |
| 2102 | var new_value_mirror = MakeMirror(new_value); |
| 2103 | |
| 2104 | response.body = { |
| 2105 | newValue: new_value_mirror |
| 2106 | }; |
| 2107 | }; |
| 2108 | |
| 2109 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2110 | DebugCommandProcessor.prototype.evaluateRequest_ = function(request, response) { |
| 2111 | if (!request.arguments) { |
| 2112 | return response.failed('Missing arguments'); |
| 2113 | } |
| 2114 | |
| 2115 | // Pull out arguments. |
| 2116 | var expression = request.arguments.expression; |
| 2117 | var frame = request.arguments.frame; |
| 2118 | var global = request.arguments.global; |
kasper.lund | bd3ec4e | 2008-07-09 11:06:54 +0000 | [diff] [blame] | 2119 | var disable_break = request.arguments.disable_break; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2120 | var additional_context = request.arguments.additional_context; |
kasper.lund | bd3ec4e | 2008-07-09 11:06:54 +0000 | [diff] [blame] | 2121 | |
| 2122 | // The expression argument could be an integer so we convert it to a |
| 2123 | // string. |
| 2124 | try { |
| 2125 | expression = String(expression); |
| 2126 | } catch(e) { |
| 2127 | return response.failed('Failed to convert expression argument to string'); |
| 2128 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2129 | |
| 2130 | // Check for legal arguments. |
| 2131 | if (!IS_UNDEFINED(frame) && global) { |
| 2132 | return response.failed('Arguments "frame" and "global" are exclusive'); |
| 2133 | } |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 2134 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2135 | var additional_context_object; |
| 2136 | if (additional_context) { |
| 2137 | additional_context_object = {}; |
| 2138 | for (var i = 0; i < additional_context.length; i++) { |
| 2139 | var mapping = additional_context[i]; |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2140 | |
| 2141 | if (!IS_STRING(mapping.name)) { |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 2142 | return response.failed("Context element #" + i + |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2143 | " doesn't contain name:string property"); |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 2144 | } |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2145 | |
| 2146 | var raw_value = DebugCommandProcessor.resolveValue_(mapping); |
| 2147 | additional_context_object[mapping.name] = raw_value; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2148 | } |
| 2149 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2150 | |
| 2151 | // Global evaluate. |
| 2152 | if (global) { |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2153 | // Evaluate in the native context. |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2154 | response.body = this.exec_state_.evaluateGlobal( |
| 2155 | expression, Boolean(disable_break), additional_context_object); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2156 | return; |
| 2157 | } |
| 2158 | |
kasper.lund | bd3ec4e | 2008-07-09 11:06:54 +0000 | [diff] [blame] | 2159 | // Default value for disable_break is true. |
| 2160 | if (IS_UNDEFINED(disable_break)) { |
| 2161 | disable_break = true; |
| 2162 | } |
| 2163 | |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 2164 | // No frames no evaluate in frame. |
| 2165 | if (this.exec_state_.frameCount() == 0) { |
| 2166 | return response.failed('No frames'); |
| 2167 | } |
| 2168 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2169 | // Check whether a frame was specified. |
| 2170 | if (!IS_UNDEFINED(frame)) { |
| 2171 | var frame_number = %ToNumber(frame); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2172 | if (frame_number < 0 || frame_number >= this.exec_state_.frameCount()) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2173 | return response.failed('Invalid frame "' + frame + '"'); |
| 2174 | } |
| 2175 | // Evaluate in the specified frame. |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2176 | response.body = this.exec_state_.frame(frame_number).evaluate( |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2177 | expression, Boolean(disable_break), additional_context_object); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2178 | return; |
| 2179 | } else { |
| 2180 | // Evaluate in the selected frame. |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2181 | response.body = this.exec_state_.frame().evaluate( |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2182 | expression, Boolean(disable_break), additional_context_object); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2183 | return; |
| 2184 | } |
| 2185 | }; |
| 2186 | |
| 2187 | |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 2188 | DebugCommandProcessor.prototype.lookupRequest_ = function(request, response) { |
| 2189 | if (!request.arguments) { |
| 2190 | return response.failed('Missing arguments'); |
| 2191 | } |
| 2192 | |
| 2193 | // Pull out arguments. |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 2194 | var handles = request.arguments.handles; |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 2195 | |
| 2196 | // Check for legal arguments. |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 2197 | if (IS_UNDEFINED(handles)) { |
| 2198 | return response.failed('Argument "handles" missing'); |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 2199 | } |
| 2200 | |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2201 | // Set 'includeSource' option for script lookup. |
| 2202 | if (!IS_UNDEFINED(request.arguments.includeSource)) { |
| 2203 | includeSource = %ToBoolean(request.arguments.includeSource); |
| 2204 | response.setOption('includeSource', includeSource); |
| 2205 | } |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 2206 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 2207 | // Lookup handles. |
| 2208 | var mirrors = {}; |
| 2209 | for (var i = 0; i < handles.length; i++) { |
| 2210 | var handle = handles[i]; |
| 2211 | var mirror = LookupMirror(handle); |
| 2212 | if (!mirror) { |
| 2213 | return response.failed('Object #' + handle + '# not found'); |
| 2214 | } |
| 2215 | mirrors[handle] = mirror; |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 2216 | } |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 2217 | response.body = mirrors; |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 2218 | }; |
| 2219 | |
| 2220 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 2221 | DebugCommandProcessor.prototype.referencesRequest_ = |
| 2222 | function(request, response) { |
| 2223 | if (!request.arguments) { |
| 2224 | return response.failed('Missing arguments'); |
| 2225 | } |
| 2226 | |
| 2227 | // Pull out arguments. |
| 2228 | var type = request.arguments.type; |
| 2229 | var handle = request.arguments.handle; |
| 2230 | |
| 2231 | // Check for legal arguments. |
| 2232 | if (IS_UNDEFINED(type)) { |
| 2233 | return response.failed('Argument "type" missing'); |
| 2234 | } |
| 2235 | if (IS_UNDEFINED(handle)) { |
| 2236 | return response.failed('Argument "handle" missing'); |
| 2237 | } |
| 2238 | if (type != 'referencedBy' && type != 'constructedBy') { |
| 2239 | return response.failed('Invalid type "' + type + '"'); |
| 2240 | } |
| 2241 | |
| 2242 | // Lookup handle and return objects with references the object. |
| 2243 | var mirror = LookupMirror(handle); |
| 2244 | if (mirror) { |
| 2245 | if (type == 'referencedBy') { |
| 2246 | response.body = mirror.referencedBy(); |
| 2247 | } else { |
| 2248 | response.body = mirror.constructedBy(); |
| 2249 | } |
| 2250 | } else { |
| 2251 | return response.failed('Object #' + handle + '# not found'); |
| 2252 | } |
| 2253 | }; |
| 2254 | |
| 2255 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2256 | DebugCommandProcessor.prototype.sourceRequest_ = function(request, response) { |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 2257 | // No frames no source. |
| 2258 | if (this.exec_state_.frameCount() == 0) { |
| 2259 | return response.failed('No source'); |
| 2260 | } |
| 2261 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2262 | var from_line; |
| 2263 | var to_line; |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2264 | var frame = this.exec_state_.frame(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2265 | if (request.arguments) { |
| 2266 | // Pull out arguments. |
| 2267 | from_line = request.arguments.fromLine; |
| 2268 | to_line = request.arguments.toLine; |
| 2269 | |
| 2270 | if (!IS_UNDEFINED(request.arguments.frame)) { |
| 2271 | var frame_number = %ToNumber(request.arguments.frame); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2272 | if (frame_number < 0 || frame_number >= this.exec_state_.frameCount()) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2273 | return response.failed('Invalid frame "' + frame + '"'); |
| 2274 | } |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2275 | frame = this.exec_state_.frame(frame_number); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2276 | } |
| 2277 | } |
| 2278 | |
| 2279 | // Get the script selected. |
| 2280 | var script = frame.func().script(); |
| 2281 | if (!script) { |
| 2282 | return response.failed('No source'); |
| 2283 | } |
| 2284 | |
| 2285 | // Get the source slice and fill it into the response. |
| 2286 | var slice = script.sourceSlice(from_line, to_line); |
| 2287 | if (!slice) { |
| 2288 | return response.failed('Invalid line interval'); |
| 2289 | } |
| 2290 | response.body = {}; |
| 2291 | response.body.source = slice.sourceText(); |
| 2292 | response.body.fromLine = slice.from_line; |
| 2293 | response.body.toLine = slice.to_line; |
| 2294 | response.body.fromPosition = slice.from_position; |
| 2295 | response.body.toPosition = slice.to_position; |
| 2296 | response.body.totalLines = script.lineCount(); |
| 2297 | }; |
| 2298 | |
| 2299 | |
| 2300 | DebugCommandProcessor.prototype.scriptsRequest_ = function(request, response) { |
| 2301 | var types = ScriptTypeFlag(Debug.ScriptType.Normal); |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 2302 | var includeSource = false; |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2303 | var idsToInclude = null; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2304 | if (request.arguments) { |
| 2305 | // Pull out arguments. |
| 2306 | if (!IS_UNDEFINED(request.arguments.types)) { |
| 2307 | types = %ToNumber(request.arguments.types); |
| 2308 | if (isNaN(types) || types < 0) { |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2309 | return response.failed('Invalid types "' + |
| 2310 | request.arguments.types + '"'); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2311 | } |
| 2312 | } |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 2313 | |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 2314 | if (!IS_UNDEFINED(request.arguments.includeSource)) { |
| 2315 | includeSource = %ToBoolean(request.arguments.includeSource); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 2316 | response.setOption('includeSource', includeSource); |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 2317 | } |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 2318 | |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2319 | if (IS_ARRAY(request.arguments.ids)) { |
| 2320 | idsToInclude = {}; |
| 2321 | var ids = request.arguments.ids; |
| 2322 | for (var i = 0; i < ids.length; i++) { |
| 2323 | idsToInclude[ids[i]] = true; |
| 2324 | } |
| 2325 | } |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2326 | |
| 2327 | var filterStr = null; |
| 2328 | var filterNum = null; |
| 2329 | if (!IS_UNDEFINED(request.arguments.filter)) { |
| 2330 | var num = %ToNumber(request.arguments.filter); |
| 2331 | if (!isNaN(num)) { |
| 2332 | filterNum = num; |
| 2333 | } |
| 2334 | filterStr = request.arguments.filter; |
| 2335 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2336 | } |
| 2337 | |
| 2338 | // Collect all scripts in the heap. |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2339 | var scripts = %DebugGetLoadedScripts(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2340 | |
| 2341 | response.body = []; |
| 2342 | |
| 2343 | for (var i = 0; i < scripts.length; i++) { |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2344 | if (idsToInclude && !idsToInclude[scripts[i].id]) { |
| 2345 | continue; |
| 2346 | } |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2347 | if (filterStr || filterNum) { |
| 2348 | var script = scripts[i]; |
| 2349 | var found = false; |
| 2350 | if (filterNum && !found) { |
| 2351 | if (script.id && script.id === filterNum) { |
| 2352 | found = true; |
| 2353 | } |
| 2354 | } |
| 2355 | if (filterStr && !found) { |
| 2356 | if (script.name && script.name.indexOf(filterStr) >= 0) { |
| 2357 | found = true; |
| 2358 | } |
| 2359 | } |
| 2360 | if (!found) continue; |
| 2361 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2362 | if (types & ScriptTypeFlag(scripts[i].type)) { |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 2363 | response.body.push(MakeMirror(scripts[i])); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2364 | } |
| 2365 | } |
| 2366 | }; |
| 2367 | |
| 2368 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2369 | DebugCommandProcessor.prototype.threadsRequest_ = function(request, response) { |
| 2370 | // Get the number of threads. |
| 2371 | var total_threads = this.exec_state_.threadCount(); |
| 2372 | |
| 2373 | // Get information for all threads. |
| 2374 | var threads = []; |
| 2375 | for (var i = 0; i < total_threads; i++) { |
| 2376 | var details = %GetThreadDetails(this.exec_state_.break_id, i); |
| 2377 | var thread_info = { current: details[0], |
| 2378 | id: details[1] |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2379 | }; |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2380 | threads.push(thread_info); |
| 2381 | } |
| 2382 | |
| 2383 | // Create the response body. |
| 2384 | response.body = { |
| 2385 | totalThreads: total_threads, |
| 2386 | threads: threads |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2387 | }; |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2388 | }; |
| 2389 | |
| 2390 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2391 | DebugCommandProcessor.prototype.suspendRequest_ = function(request, response) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2392 | response.running = false; |
| 2393 | }; |
| 2394 | |
| 2395 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2396 | DebugCommandProcessor.prototype.versionRequest_ = function(request, response) { |
| 2397 | response.body = { |
| 2398 | V8Version: %GetV8Version() |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2399 | }; |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2400 | }; |
| 2401 | |
| 2402 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 2403 | DebugCommandProcessor.prototype.profileRequest_ = function(request, response) { |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 2404 | if (request.arguments.command == 'resume') { |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 2405 | %ProfilerResume(); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 2406 | } else if (request.arguments.command == 'pause') { |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 2407 | %ProfilerPause(); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 2408 | } else { |
| 2409 | return response.failed('Unknown command'); |
| 2410 | } |
| 2411 | response.body = {}; |
| 2412 | }; |
| 2413 | |
| 2414 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2415 | DebugCommandProcessor.prototype.changeLiveRequest_ = function( |
| 2416 | request, response) { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2417 | if (!request.arguments) { |
| 2418 | return response.failed('Missing arguments'); |
| 2419 | } |
| 2420 | var script_id = request.arguments.script_id; |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 2421 | var preview_only = !!request.arguments.preview_only; |
vegorov@chromium.org | 4284196 | 2010-10-18 11:18:59 +0000 | [diff] [blame] | 2422 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2423 | var scripts = %DebugGetLoadedScripts(); |
| 2424 | |
| 2425 | var the_script = null; |
| 2426 | for (var i = 0; i < scripts.length; i++) { |
| 2427 | if (scripts[i].id == script_id) { |
| 2428 | the_script = scripts[i]; |
| 2429 | } |
| 2430 | } |
| 2431 | if (!the_script) { |
| 2432 | response.failed('Script not found'); |
| 2433 | return; |
| 2434 | } |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 2435 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2436 | var change_log = new Array(); |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 2437 | |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 2438 | if (!IS_STRING(request.arguments.new_source)) { |
| 2439 | throw "new_source argument expected"; |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 2440 | } |
| 2441 | |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 2442 | var new_source = request.arguments.new_source; |
vegorov@chromium.org | 4284196 | 2010-10-18 11:18:59 +0000 | [diff] [blame] | 2443 | |
mmassi@chromium.org | 49a4467 | 2012-12-04 13:52:03 +0000 | [diff] [blame] | 2444 | var result_description; |
| 2445 | try { |
| 2446 | result_description = Debug.LiveEdit.SetScriptSource(the_script, |
| 2447 | new_source, preview_only, change_log); |
| 2448 | } catch (e) { |
| 2449 | if (e instanceof Debug.LiveEdit.Failure && "details" in e) { |
| 2450 | response.failed(e.message, e.details); |
| 2451 | return; |
| 2452 | } |
| 2453 | throw e; |
| 2454 | } |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 2455 | response.body = {change_log: change_log, result: result_description}; |
vegorov@chromium.org | 4284196 | 2010-10-18 11:18:59 +0000 | [diff] [blame] | 2456 | |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 2457 | if (!preview_only && !this.running_ && result_description.stack_modified) { |
| 2458 | response.body.stepin_recommended = true; |
| 2459 | } |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2460 | }; |
| 2461 | |
| 2462 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 2463 | DebugCommandProcessor.prototype.restartFrameRequest_ = function( |
| 2464 | request, response) { |
| 2465 | if (!request.arguments) { |
| 2466 | return response.failed('Missing arguments'); |
| 2467 | } |
| 2468 | var frame = request.arguments.frame; |
| 2469 | |
| 2470 | // No frames to evaluate in frame. |
| 2471 | if (this.exec_state_.frameCount() == 0) { |
| 2472 | return response.failed('No frames'); |
| 2473 | } |
| 2474 | |
| 2475 | var frame_mirror; |
| 2476 | // Check whether a frame was specified. |
| 2477 | if (!IS_UNDEFINED(frame)) { |
| 2478 | var frame_number = %ToNumber(frame); |
| 2479 | if (frame_number < 0 || frame_number >= this.exec_state_.frameCount()) { |
| 2480 | return response.failed('Invalid frame "' + frame + '"'); |
| 2481 | } |
| 2482 | // Restart specified frame. |
| 2483 | frame_mirror = this.exec_state_.frame(frame_number); |
| 2484 | } else { |
| 2485 | // Restart selected frame. |
| 2486 | frame_mirror = this.exec_state_.frame(); |
| 2487 | } |
| 2488 | |
| 2489 | var result_description = Debug.LiveEdit.RestartFrame(frame_mirror); |
| 2490 | response.body = {result: result_description}; |
| 2491 | }; |
| 2492 | |
| 2493 | |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 2494 | DebugCommandProcessor.prototype.debuggerFlagsRequest_ = function(request, |
| 2495 | response) { |
| 2496 | // Check for legal request. |
| 2497 | if (!request.arguments) { |
| 2498 | response.failed('Missing arguments'); |
| 2499 | return; |
| 2500 | } |
| 2501 | |
| 2502 | // Pull out arguments. |
| 2503 | var flags = request.arguments.flags; |
| 2504 | |
| 2505 | response.body = { flags: [] }; |
| 2506 | if (!IS_UNDEFINED(flags)) { |
| 2507 | for (var i = 0; i < flags.length; i++) { |
| 2508 | var name = flags[i].name; |
| 2509 | var debugger_flag = debugger_flags[name]; |
| 2510 | if (!debugger_flag) { |
| 2511 | continue; |
| 2512 | } |
| 2513 | if ('value' in flags[i]) { |
| 2514 | debugger_flag.setValue(flags[i].value); |
| 2515 | } |
| 2516 | response.body.flags.push({ name: name, value: debugger_flag.getValue() }); |
| 2517 | } |
| 2518 | } else { |
| 2519 | for (var name in debugger_flags) { |
| 2520 | var value = debugger_flags[name].getValue(); |
| 2521 | response.body.flags.push({ name: name, value: value }); |
| 2522 | } |
| 2523 | } |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2524 | }; |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 2525 | |
| 2526 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2527 | DebugCommandProcessor.prototype.v8FlagsRequest_ = function(request, response) { |
| 2528 | var flags = request.arguments.flags; |
| 2529 | if (!flags) flags = ''; |
| 2530 | %SetFlags(flags); |
| 2531 | }; |
| 2532 | |
| 2533 | |
| 2534 | DebugCommandProcessor.prototype.gcRequest_ = function(request, response) { |
| 2535 | var type = request.arguments.type; |
| 2536 | if (!type) type = 'all'; |
| 2537 | |
| 2538 | var before = %GetHeapUsage(); |
| 2539 | %CollectGarbage(type); |
| 2540 | var after = %GetHeapUsage(); |
| 2541 | |
| 2542 | response.body = { "before": before, "after": after }; |
| 2543 | }; |
| 2544 | |
| 2545 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 2546 | // Check whether the previously processed command caused the VM to become |
| 2547 | // running. |
| 2548 | DebugCommandProcessor.prototype.isRunning = function() { |
| 2549 | return this.running_; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2550 | }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2551 | |
| 2552 | |
| 2553 | DebugCommandProcessor.prototype.systemBreak = function(cmd, args) { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2554 | return %SystemBreak(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2555 | }; |
| 2556 | |
| 2557 | |
| 2558 | function NumberToHex8Str(n) { |
| 2559 | var r = ""; |
| 2560 | for (var i = 0; i < 8; ++i) { |
| 2561 | var c = hexCharArray[n & 0x0F]; // hexCharArray is defined in uri.js |
| 2562 | r = c + r; |
| 2563 | n = n >>> 4; |
| 2564 | } |
| 2565 | return r; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2566 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2567 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2568 | |
| 2569 | /** |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2570 | * Convert an Object to its debugger protocol representation. The representation |
| 2571 | * may be serilized to a JSON object using JSON.stringify(). |
| 2572 | * This implementation simply runs through all string property names, converts |
| 2573 | * each property value to a protocol value and adds the property to the result |
| 2574 | * object. For type "object" the function will be called recursively. Note that |
| 2575 | * circular structures will cause infinite recursion. |
| 2576 | * @param {Object} object The object to format as protocol object. |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2577 | * @param {MirrorSerializer} mirror_serializer The serializer to use if any |
| 2578 | * mirror objects are encountered. |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2579 | * @return {Object} Protocol object value. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2580 | */ |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2581 | function ObjectToProtocolObject_(object, mirror_serializer) { |
| 2582 | var content = {}; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2583 | for (var key in object) { |
| 2584 | // Only consider string keys. |
| 2585 | if (typeof key == 'string') { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2586 | // Format the value based on its type. |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2587 | var property_value_json = ValueToProtocolValue_(object[key], |
| 2588 | mirror_serializer); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2589 | // Add the property if relevant. |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2590 | if (!IS_UNDEFINED(property_value_json)) { |
| 2591 | content[key] = property_value_json; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2592 | } |
| 2593 | } |
| 2594 | } |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 2595 | |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2596 | return content; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 2597 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2598 | |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2599 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2600 | /** |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2601 | * Convert an array to its debugger protocol representation. It will convert |
| 2602 | * each array element to a protocol value. |
| 2603 | * @param {Array} array The array to format as protocol array. |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2604 | * @param {MirrorSerializer} mirror_serializer The serializer to use if any |
| 2605 | * mirror objects are encountered. |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2606 | * @return {Array} Protocol array value. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2607 | */ |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2608 | function ArrayToProtocolArray_(array, mirror_serializer) { |
| 2609 | var json = []; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2610 | for (var i = 0; i < array.length; i++) { |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2611 | json.push(ValueToProtocolValue_(array[i], mirror_serializer)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2612 | } |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2613 | return json; |
| 2614 | } |
| 2615 | |
| 2616 | |
| 2617 | /** |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 2618 | * Convert a value to its debugger protocol representation. |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2619 | * @param {*} value The value to format as protocol value. |
| 2620 | * @param {MirrorSerializer} mirror_serializer The serializer to use if any |
| 2621 | * mirror objects are encountered. |
| 2622 | * @return {*} Protocol value. |
| 2623 | */ |
| 2624 | function ValueToProtocolValue_(value, mirror_serializer) { |
| 2625 | // Format the value based on its type. |
| 2626 | var json; |
| 2627 | switch (typeof value) { |
| 2628 | case 'object': |
| 2629 | if (value instanceof Mirror) { |
| 2630 | json = mirror_serializer.serializeValue(value); |
| 2631 | } else if (IS_ARRAY(value)){ |
| 2632 | json = ArrayToProtocolArray_(value, mirror_serializer); |
| 2633 | } else { |
| 2634 | json = ObjectToProtocolObject_(value, mirror_serializer); |
| 2635 | } |
| 2636 | break; |
| 2637 | |
| 2638 | case 'boolean': |
| 2639 | case 'string': |
| 2640 | case 'number': |
| 2641 | json = value; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2642 | break; |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2643 | |
| 2644 | default: |
| 2645 | json = null; |
| 2646 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2647 | return json; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 2648 | } |
mmassi@chromium.org | 49a4467 | 2012-12-04 13:52:03 +0000 | [diff] [blame] | 2649 | |
| 2650 | Debug.TestApi = { |
| 2651 | CommandProcessorResolveValue: DebugCommandProcessor.resolveValue_ |
| 2652 | }; |