fschneider@chromium.org | 7d10be5 | 2012-04-10 12:30:14 +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 | #include "v8.h" |
| 29 | |
| 30 | #include "api.h" |
| 31 | #include "arguments.h" |
| 32 | #include "bootstrapper.h" |
| 33 | #include "code-stubs.h" |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 34 | #include "codegen.h" |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 35 | #include "compilation-cache.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 36 | #include "compiler.h" |
| 37 | #include "debug.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 38 | #include "deoptimizer.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 39 | #include "execution.h" |
yangguo@chromium.org | a7d3df9 | 2012-02-27 11:46:55 +0000 | [diff] [blame] | 40 | #include "full-codegen.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 41 | #include "global-handles.h" |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 42 | #include "ic.h" |
| 43 | #include "ic-inl.h" |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 44 | #include "isolate-inl.h" |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 45 | #include "list.h" |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 46 | #include "messages.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 47 | #include "natives.h" |
| 48 | #include "stub-cache.h" |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 49 | #include "log.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 50 | |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 51 | #include "../include/v8-debug.h" |
| 52 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 53 | namespace v8 { |
| 54 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 55 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 56 | #ifdef ENABLE_DEBUGGER_SUPPORT |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 57 | |
| 58 | |
| 59 | Debug::Debug(Isolate* isolate) |
| 60 | : has_break_points_(false), |
| 61 | script_cache_(NULL), |
| 62 | debug_info_list_(NULL), |
| 63 | disable_break_(false), |
| 64 | break_on_exception_(false), |
| 65 | break_on_uncaught_exception_(false), |
| 66 | debug_break_return_(NULL), |
| 67 | debug_break_slot_(NULL), |
| 68 | isolate_(isolate) { |
| 69 | memset(registers_, 0, sizeof(JSCallerSavedBuffer)); |
| 70 | } |
| 71 | |
| 72 | |
| 73 | Debug::~Debug() { |
| 74 | } |
| 75 | |
| 76 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 77 | static void PrintLn(v8::Local<v8::Value> value) { |
| 78 | v8::Local<v8::String> s = value->ToString(); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 79 | ScopedVector<char> data(s->Utf8Length() + 1); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 80 | if (data.start() == NULL) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 81 | V8::FatalProcessOutOfMemory("PrintLn"); |
| 82 | return; |
| 83 | } |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 84 | s->WriteUtf8(data.start()); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 85 | PrintF("%s\n", data.start()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 89 | static v8::Handle<v8::Context> GetDebugEventContext(Isolate* isolate) { |
| 90 | Handle<Context> context = isolate->debug()->debugger_entry()->GetContext(); |
| 91 | // Isolate::context() may have been NULL when "script collected" event |
| 92 | // occured. |
| 93 | if (context.is_null()) return v8::Local<v8::Context>(); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 94 | Handle<Context> native_context(context->native_context()); |
| 95 | return v8::Utils::ToLocal(native_context); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 99 | BreakLocationIterator::BreakLocationIterator(Handle<DebugInfo> debug_info, |
| 100 | BreakLocatorType type) { |
| 101 | debug_info_ = debug_info; |
| 102 | type_ = type; |
| 103 | reloc_iterator_ = NULL; |
| 104 | reloc_iterator_original_ = NULL; |
| 105 | Reset(); // Initialize the rest of the member variables. |
| 106 | } |
| 107 | |
| 108 | |
| 109 | BreakLocationIterator::~BreakLocationIterator() { |
| 110 | ASSERT(reloc_iterator_ != NULL); |
| 111 | ASSERT(reloc_iterator_original_ != NULL); |
| 112 | delete reloc_iterator_; |
| 113 | delete reloc_iterator_original_; |
| 114 | } |
| 115 | |
| 116 | |
| 117 | void BreakLocationIterator::Next() { |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 118 | DisallowHeapAllocation no_gc; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 119 | ASSERT(!RinfoDone()); |
| 120 | |
| 121 | // Iterate through reloc info for code and original code stopping at each |
| 122 | // breakable code target. |
| 123 | bool first = break_point_ == -1; |
| 124 | while (!RinfoDone()) { |
| 125 | if (!first) RinfoNext(); |
| 126 | first = false; |
| 127 | if (RinfoDone()) return; |
| 128 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 129 | // Whenever a statement position or (plain) position is passed update the |
| 130 | // current value of these. |
| 131 | if (RelocInfo::IsPosition(rmode())) { |
| 132 | if (RelocInfo::IsStatementPosition(rmode())) { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 133 | statement_position_ = static_cast<int>( |
| 134 | rinfo()->data() - debug_info_->shared()->start_position()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 135 | } |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 136 | // Always update the position as we don't want that to be before the |
| 137 | // statement position. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 138 | position_ = static_cast<int>( |
| 139 | rinfo()->data() - debug_info_->shared()->start_position()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 140 | ASSERT(position_ >= 0); |
| 141 | ASSERT(statement_position_ >= 0); |
| 142 | } |
| 143 | |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 144 | if (IsDebugBreakSlot()) { |
| 145 | // There is always a possible break point at a debug break slot. |
| 146 | break_point_++; |
| 147 | return; |
| 148 | } else if (RelocInfo::IsCodeTarget(rmode())) { |
| 149 | // Check for breakable code target. Look in the original code as setting |
| 150 | // break points can cause the code targets in the running (debugged) code |
| 151 | // to be of a different kind than in the original code. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 152 | Address target = original_rinfo()->target_address(); |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 153 | Code* code = Code::GetCodeFromTargetAddress(target); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 154 | if ((code->is_inline_cache_stub() && |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 155 | !code->is_binary_op_stub() && |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 156 | !code->is_compare_ic_stub() && |
| 157 | !code->is_to_boolean_ic_stub()) || |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 158 | RelocInfo::IsConstructCall(rmode())) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 159 | break_point_++; |
| 160 | return; |
| 161 | } |
| 162 | if (code->kind() == Code::STUB) { |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 163 | if (IsDebuggerStatement()) { |
| 164 | break_point_++; |
| 165 | return; |
| 166 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 167 | if (type_ == ALL_BREAK_LOCATIONS) { |
| 168 | if (Debug::IsBreakStub(code)) { |
| 169 | break_point_++; |
| 170 | return; |
| 171 | } |
| 172 | } else { |
| 173 | ASSERT(type_ == SOURCE_BREAK_LOCATIONS); |
| 174 | if (Debug::IsSourceBreakStub(code)) { |
| 175 | break_point_++; |
| 176 | return; |
| 177 | } |
| 178 | } |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | // Check for break at return. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 183 | if (RelocInfo::IsJSReturn(rmode())) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 184 | // Set the positions to the end of the function. |
| 185 | if (debug_info_->shared()->HasSourceCode()) { |
| 186 | position_ = debug_info_->shared()->end_position() - |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 187 | debug_info_->shared()->start_position() - 1; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 188 | } else { |
| 189 | position_ = 0; |
| 190 | } |
| 191 | statement_position_ = position_; |
| 192 | break_point_++; |
| 193 | return; |
| 194 | } |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | |
| 199 | void BreakLocationIterator::Next(int count) { |
| 200 | while (count > 0) { |
| 201 | Next(); |
| 202 | count--; |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 207 | // Find the break point at the supplied address, or the closest one before |
| 208 | // the address. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 209 | void BreakLocationIterator::FindBreakLocationFromAddress(Address pc) { |
| 210 | // Run through all break points to locate the one closest to the address. |
| 211 | int closest_break_point = 0; |
| 212 | int distance = kMaxInt; |
| 213 | while (!Done()) { |
| 214 | // Check if this break point is closer that what was previously found. |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 215 | if (this->pc() <= pc && pc - this->pc() < distance) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 216 | closest_break_point = break_point(); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 217 | distance = static_cast<int>(pc - this->pc()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 218 | // Check whether we can't get any closer. |
| 219 | if (distance == 0) break; |
| 220 | } |
| 221 | Next(); |
| 222 | } |
| 223 | |
| 224 | // Move to the break point found. |
| 225 | Reset(); |
| 226 | Next(closest_break_point); |
| 227 | } |
| 228 | |
| 229 | |
| 230 | // Find the break point closest to the supplied source position. |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame] | 231 | void BreakLocationIterator::FindBreakLocationFromPosition(int position, |
| 232 | BreakPositionAlignment alignment) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 233 | // Run through all break points to locate the one closest to the source |
| 234 | // position. |
| 235 | int closest_break_point = 0; |
| 236 | int distance = kMaxInt; |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame] | 237 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 238 | while (!Done()) { |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame] | 239 | int next_position; |
| 240 | switch (alignment) { |
| 241 | case STATEMENT_ALIGNED: |
| 242 | next_position = this->statement_position(); |
| 243 | break; |
| 244 | case BREAK_POSITION_ALIGNED: |
| 245 | next_position = this->position(); |
| 246 | break; |
| 247 | default: |
| 248 | UNREACHABLE(); |
| 249 | next_position = this->statement_position(); |
| 250 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 251 | // Check if this break point is closer that what was previously found. |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame] | 252 | if (position <= next_position && next_position - position < distance) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 253 | closest_break_point = break_point(); |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame] | 254 | distance = next_position - position; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 255 | // Check whether we can't get any closer. |
| 256 | if (distance == 0) break; |
| 257 | } |
| 258 | Next(); |
| 259 | } |
| 260 | |
| 261 | // Move to the break point found. |
| 262 | Reset(); |
| 263 | Next(closest_break_point); |
| 264 | } |
| 265 | |
| 266 | |
| 267 | void BreakLocationIterator::Reset() { |
| 268 | // Create relocation iterators for the two code objects. |
| 269 | if (reloc_iterator_ != NULL) delete reloc_iterator_; |
| 270 | if (reloc_iterator_original_ != NULL) delete reloc_iterator_original_; |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 271 | reloc_iterator_ = new RelocIterator( |
| 272 | debug_info_->code(), |
| 273 | ~RelocInfo::ModeMask(RelocInfo::CODE_AGE_SEQUENCE)); |
| 274 | reloc_iterator_original_ = new RelocIterator( |
| 275 | debug_info_->original_code(), |
| 276 | ~RelocInfo::ModeMask(RelocInfo::CODE_AGE_SEQUENCE)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 277 | |
| 278 | // Position at the first break point. |
| 279 | break_point_ = -1; |
| 280 | position_ = 1; |
| 281 | statement_position_ = 1; |
| 282 | Next(); |
| 283 | } |
| 284 | |
| 285 | |
| 286 | bool BreakLocationIterator::Done() const { |
| 287 | return RinfoDone(); |
| 288 | } |
| 289 | |
| 290 | |
| 291 | void BreakLocationIterator::SetBreakPoint(Handle<Object> break_point_object) { |
| 292 | // If there is not already a real break point here patch code with debug |
| 293 | // break. |
| 294 | if (!HasBreakPoint()) { |
| 295 | SetDebugBreak(); |
| 296 | } |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 297 | ASSERT(IsDebugBreak() || IsDebuggerStatement()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 298 | // Set the break point information. |
| 299 | DebugInfo::SetBreakPoint(debug_info_, code_position(), |
| 300 | position(), statement_position(), |
| 301 | break_point_object); |
| 302 | } |
| 303 | |
| 304 | |
| 305 | void BreakLocationIterator::ClearBreakPoint(Handle<Object> break_point_object) { |
| 306 | // Clear the break point information. |
| 307 | DebugInfo::ClearBreakPoint(debug_info_, code_position(), break_point_object); |
| 308 | // If there are no more break points here remove the debug break. |
| 309 | if (!HasBreakPoint()) { |
| 310 | ClearDebugBreak(); |
| 311 | ASSERT(!IsDebugBreak()); |
| 312 | } |
| 313 | } |
| 314 | |
| 315 | |
| 316 | void BreakLocationIterator::SetOneShot() { |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 317 | // Debugger statement always calls debugger. No need to modify it. |
| 318 | if (IsDebuggerStatement()) { |
| 319 | return; |
| 320 | } |
| 321 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 322 | // If there is a real break point here no more to do. |
| 323 | if (HasBreakPoint()) { |
| 324 | ASSERT(IsDebugBreak()); |
| 325 | return; |
| 326 | } |
| 327 | |
| 328 | // Patch code with debug break. |
| 329 | SetDebugBreak(); |
| 330 | } |
| 331 | |
| 332 | |
| 333 | void BreakLocationIterator::ClearOneShot() { |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 334 | // Debugger statement always calls debugger. No need to modify it. |
| 335 | if (IsDebuggerStatement()) { |
| 336 | return; |
| 337 | } |
| 338 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 339 | // If there is a real break point here no more to do. |
| 340 | if (HasBreakPoint()) { |
| 341 | ASSERT(IsDebugBreak()); |
| 342 | return; |
| 343 | } |
| 344 | |
| 345 | // Patch code removing debug break. |
| 346 | ClearDebugBreak(); |
| 347 | ASSERT(!IsDebugBreak()); |
| 348 | } |
| 349 | |
| 350 | |
| 351 | void BreakLocationIterator::SetDebugBreak() { |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 352 | // Debugger statement always calls debugger. No need to modify it. |
| 353 | if (IsDebuggerStatement()) { |
| 354 | return; |
| 355 | } |
| 356 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 357 | // If there is already a break point here just return. This might happen if |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 358 | // the same code is flooded with break points twice. Flooding the same |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 359 | // function twice might happen when stepping in a function with an exception |
| 360 | // handler as the handler and the function is the same. |
| 361 | if (IsDebugBreak()) { |
| 362 | return; |
| 363 | } |
| 364 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 365 | if (RelocInfo::IsJSReturn(rmode())) { |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 366 | // Patch the frame exit code with a break point. |
| 367 | SetDebugBreakAtReturn(); |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 368 | } else if (IsDebugBreakSlot()) { |
| 369 | // Patch the code in the break slot. |
| 370 | SetDebugBreakAtSlot(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 371 | } else { |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 372 | // Patch the IC call. |
| 373 | SetDebugBreakAtIC(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 374 | } |
| 375 | ASSERT(IsDebugBreak()); |
| 376 | } |
| 377 | |
| 378 | |
| 379 | void BreakLocationIterator::ClearDebugBreak() { |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 380 | // Debugger statement always calls debugger. No need to modify it. |
| 381 | if (IsDebuggerStatement()) { |
| 382 | return; |
| 383 | } |
| 384 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 385 | if (RelocInfo::IsJSReturn(rmode())) { |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 386 | // Restore the frame exit code. |
| 387 | ClearDebugBreakAtReturn(); |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 388 | } else if (IsDebugBreakSlot()) { |
| 389 | // Restore the code in the break slot. |
| 390 | ClearDebugBreakAtSlot(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 391 | } else { |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 392 | // Patch the IC call. |
| 393 | ClearDebugBreakAtIC(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 394 | } |
| 395 | ASSERT(!IsDebugBreak()); |
| 396 | } |
| 397 | |
| 398 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 399 | bool BreakLocationIterator::IsStepInLocation(Isolate* isolate) { |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 400 | if (RelocInfo::IsConstructCall(original_rmode())) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 401 | return true; |
| 402 | } else if (RelocInfo::IsCodeTarget(rmode())) { |
| 403 | HandleScope scope(debug_info_->GetIsolate()); |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 404 | Address target = original_rinfo()->target_address(); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 405 | Handle<Code> target_code(Code::GetCodeFromTargetAddress(target)); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 406 | if (target_code->kind() == Code::STUB) { |
| 407 | return target_code->major_key() == CodeStub::CallFunction; |
| 408 | } |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 409 | } |
machenbach@chromium.org | a03ba1e | 2014-02-01 08:54:43 +0000 | [diff] [blame] | 410 | return false; |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 414 | void BreakLocationIterator::PrepareStepIn(Isolate* isolate) { |
machenbach@chromium.org | a03ba1e | 2014-02-01 08:54:43 +0000 | [diff] [blame] | 415 | #ifdef DEBUG |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 416 | HandleScope scope(isolate); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 417 | // Step in can only be prepared if currently positioned on an IC call, |
| 418 | // construct call or CallFunction stub call. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 419 | Address target = rinfo()->target_address(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 420 | Handle<Code> target_code(Code::GetCodeFromTargetAddress(target)); |
machenbach@chromium.org | a03ba1e | 2014-02-01 08:54:43 +0000 | [diff] [blame] | 421 | // All the following stuff is needed only for assertion checks so the code |
| 422 | // is wrapped in ifdef. |
| 423 | Handle<Code> maybe_call_function_stub = target_code; |
| 424 | if (IsDebugBreak()) { |
| 425 | Address original_target = original_rinfo()->target_address(); |
| 426 | maybe_call_function_stub = |
| 427 | Handle<Code>(Code::GetCodeFromTargetAddress(original_target)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 428 | } |
machenbach@chromium.org | a03ba1e | 2014-02-01 08:54:43 +0000 | [diff] [blame] | 429 | bool is_call_function_stub = |
| 430 | (maybe_call_function_stub->kind() == Code::STUB && |
| 431 | maybe_call_function_stub->major_key() == CodeStub::CallFunction); |
| 432 | |
| 433 | // Step in through construct call requires no changes to the running code. |
| 434 | // Step in through getters/setters should already be prepared as well |
| 435 | // because caller of this function (Debug::PrepareStep) is expected to |
| 436 | // flood the top frame's function with one shot breakpoints. |
| 437 | // Step in through CallFunction stub should also be prepared by caller of |
| 438 | // this function (Debug::PrepareStep) which should flood target function |
| 439 | // with breakpoints. |
| 440 | ASSERT(RelocInfo::IsConstructCall(rmode()) || |
| 441 | target_code->is_inline_cache_stub() || |
| 442 | is_call_function_stub); |
| 443 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | |
| 447 | // Check whether the break point is at a position which will exit the function. |
| 448 | bool BreakLocationIterator::IsExit() const { |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 449 | return (RelocInfo::IsJSReturn(rmode())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | |
| 453 | bool BreakLocationIterator::HasBreakPoint() { |
| 454 | return debug_info_->HasBreakPoint(code_position()); |
| 455 | } |
| 456 | |
| 457 | |
| 458 | // Check whether there is a debug break at the current position. |
| 459 | bool BreakLocationIterator::IsDebugBreak() { |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 460 | if (RelocInfo::IsJSReturn(rmode())) { |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 461 | return IsDebugBreakAtReturn(); |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 462 | } else if (IsDebugBreakSlot()) { |
| 463 | return IsDebugBreakAtSlot(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 464 | } else { |
| 465 | return Debug::IsDebugBreak(rinfo()->target_address()); |
| 466 | } |
| 467 | } |
| 468 | |
| 469 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 470 | void BreakLocationIterator::SetDebugBreakAtIC() { |
| 471 | // Patch the original code with the current address as the current address |
| 472 | // might have changed by the inline caching since the code was copied. |
| 473 | original_rinfo()->set_target_address(rinfo()->target_address()); |
| 474 | |
| 475 | RelocInfo::Mode mode = rmode(); |
| 476 | if (RelocInfo::IsCodeTarget(mode)) { |
| 477 | Address target = rinfo()->target_address(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 478 | Handle<Code> target_code(Code::GetCodeFromTargetAddress(target)); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 479 | |
| 480 | // Patch the code to invoke the builtin debug break function matching the |
| 481 | // calling convention used by the call site. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 482 | Handle<Code> dbgbrk_code(Debug::FindDebugBreak(target_code, mode)); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 483 | rinfo()->set_target_address(dbgbrk_code->entry()); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 484 | } |
| 485 | } |
| 486 | |
| 487 | |
| 488 | void BreakLocationIterator::ClearDebugBreakAtIC() { |
| 489 | // Patch the code to the original invoke. |
| 490 | rinfo()->set_target_address(original_rinfo()->target_address()); |
| 491 | } |
| 492 | |
| 493 | |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 494 | bool BreakLocationIterator::IsDebuggerStatement() { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 495 | return RelocInfo::DEBUG_BREAK == rmode(); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 499 | bool BreakLocationIterator::IsDebugBreakSlot() { |
| 500 | return RelocInfo::DEBUG_BREAK_SLOT == rmode(); |
| 501 | } |
| 502 | |
| 503 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 504 | Object* BreakLocationIterator::BreakPointObjects() { |
| 505 | return debug_info_->GetBreakPointObjects(code_position()); |
| 506 | } |
| 507 | |
| 508 | |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 509 | // Clear out all the debug break code. This is ONLY supposed to be used when |
| 510 | // shutting down the debugger as it will leave the break point information in |
| 511 | // DebugInfo even though the code is patched back to the non break point state. |
| 512 | void BreakLocationIterator::ClearAllDebugBreak() { |
| 513 | while (!Done()) { |
| 514 | ClearDebugBreak(); |
| 515 | Next(); |
| 516 | } |
| 517 | } |
| 518 | |
| 519 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 520 | bool BreakLocationIterator::RinfoDone() const { |
| 521 | ASSERT(reloc_iterator_->done() == reloc_iterator_original_->done()); |
| 522 | return reloc_iterator_->done(); |
| 523 | } |
| 524 | |
| 525 | |
| 526 | void BreakLocationIterator::RinfoNext() { |
| 527 | reloc_iterator_->next(); |
| 528 | reloc_iterator_original_->next(); |
| 529 | #ifdef DEBUG |
| 530 | ASSERT(reloc_iterator_->done() == reloc_iterator_original_->done()); |
| 531 | if (!reloc_iterator_->done()) { |
| 532 | ASSERT(rmode() == original_rmode()); |
| 533 | } |
| 534 | #endif |
| 535 | } |
| 536 | |
| 537 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 538 | // Threading support. |
| 539 | void Debug::ThreadInit() { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 540 | thread_local_.break_count_ = 0; |
| 541 | thread_local_.break_id_ = 0; |
| 542 | thread_local_.break_frame_id_ = StackFrame::NO_ID; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 543 | thread_local_.last_step_action_ = StepNone; |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 544 | thread_local_.last_statement_position_ = RelocInfo::kNoPosition; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 545 | thread_local_.step_count_ = 0; |
| 546 | thread_local_.last_fp_ = 0; |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 547 | thread_local_.queued_step_count_ = 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 548 | thread_local_.step_into_fp_ = 0; |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 549 | thread_local_.step_out_fp_ = 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 550 | thread_local_.after_break_target_ = 0; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 551 | // TODO(isolates): frames_are_dropped_? |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 552 | thread_local_.debugger_entry_ = NULL; |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 553 | thread_local_.pending_interrupts_ = 0; |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 554 | thread_local_.restarter_frame_function_pointer_ = NULL; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 555 | } |
| 556 | |
| 557 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 558 | char* Debug::ArchiveDebug(char* storage) { |
| 559 | char* to = storage; |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 560 | OS::MemCopy(to, reinterpret_cast<char*>(&thread_local_), sizeof(ThreadLocal)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 561 | to += sizeof(ThreadLocal); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 562 | OS::MemCopy(to, reinterpret_cast<char*>(®isters_), sizeof(registers_)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 563 | ThreadInit(); |
| 564 | ASSERT(to <= storage + ArchiveSpacePerThread()); |
| 565 | return storage + ArchiveSpacePerThread(); |
| 566 | } |
| 567 | |
| 568 | |
| 569 | char* Debug::RestoreDebug(char* storage) { |
| 570 | char* from = storage; |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 571 | OS::MemCopy( |
| 572 | reinterpret_cast<char*>(&thread_local_), from, sizeof(ThreadLocal)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 573 | from += sizeof(ThreadLocal); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 574 | OS::MemCopy(reinterpret_cast<char*>(®isters_), from, sizeof(registers_)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 575 | ASSERT(from <= storage + ArchiveSpacePerThread()); |
| 576 | return storage + ArchiveSpacePerThread(); |
| 577 | } |
| 578 | |
| 579 | |
| 580 | int Debug::ArchiveSpacePerThread() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 581 | return sizeof(ThreadLocal) + sizeof(JSCallerSavedBuffer); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 585 | // Frame structure (conforms InternalFrame structure): |
| 586 | // -- code |
| 587 | // -- SMI maker |
| 588 | // -- function (slot is called "context") |
| 589 | // -- frame base |
| 590 | Object** Debug::SetUpFrameDropperFrame(StackFrame* bottom_js_frame, |
| 591 | Handle<Code> code) { |
| 592 | ASSERT(bottom_js_frame->is_java_script()); |
| 593 | |
| 594 | Address fp = bottom_js_frame->fp(); |
| 595 | |
| 596 | // Move function pointer into "context" slot. |
| 597 | Memory::Object_at(fp + StandardFrameConstants::kContextOffset) = |
| 598 | Memory::Object_at(fp + JavaScriptFrameConstants::kFunctionOffset); |
| 599 | |
| 600 | Memory::Object_at(fp + InternalFrameConstants::kCodeOffset) = *code; |
| 601 | Memory::Object_at(fp + StandardFrameConstants::kMarkerOffset) = |
| 602 | Smi::FromInt(StackFrame::INTERNAL); |
| 603 | |
| 604 | return reinterpret_cast<Object**>(&Memory::Object_at( |
| 605 | fp + StandardFrameConstants::kContextOffset)); |
| 606 | } |
| 607 | |
| 608 | const int Debug::kFrameDropperFrameSize = 4; |
| 609 | |
| 610 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 611 | void ScriptCache::Add(Handle<Script> script) { |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 612 | GlobalHandles* global_handles = isolate_->global_handles(); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 613 | // Create an entry in the hash map for the script. |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 614 | int id = script->id()->value(); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 615 | HashMap::Entry* entry = |
| 616 | HashMap::Lookup(reinterpret_cast<void*>(id), Hash(id), true); |
| 617 | if (entry->value != NULL) { |
| 618 | ASSERT(*script == *reinterpret_cast<Script**>(entry->value)); |
| 619 | return; |
| 620 | } |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 621 | // Globalize the script object, make it weak and use the location of the |
| 622 | // global handle as the value in the hash map. |
| 623 | Handle<Script> script_ = |
hpayer@chromium.org | 4f99be9 | 2013-12-18 16:23:55 +0000 | [diff] [blame] | 624 | Handle<Script>::cast(global_handles->Create(*script)); |
| 625 | GlobalHandles::MakeWeak(reinterpret_cast<Object**>(script_.location()), |
| 626 | this, |
| 627 | ScriptCache::HandleWeakScript); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 628 | entry->value = script_.location(); |
| 629 | } |
| 630 | |
| 631 | |
| 632 | Handle<FixedArray> ScriptCache::GetScripts() { |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 633 | Factory* factory = isolate_->factory(); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 634 | Handle<FixedArray> instances = factory->NewFixedArray(occupancy()); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 635 | int count = 0; |
| 636 | for (HashMap::Entry* entry = Start(); entry != NULL; entry = Next(entry)) { |
| 637 | ASSERT(entry->value != NULL); |
| 638 | if (entry->value != NULL) { |
| 639 | instances->set(count, *reinterpret_cast<Script**>(entry->value)); |
| 640 | count++; |
| 641 | } |
| 642 | } |
| 643 | return instances; |
| 644 | } |
| 645 | |
| 646 | |
| 647 | void ScriptCache::ProcessCollectedScripts() { |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 648 | Debugger* debugger = isolate_->debugger(); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 649 | for (int i = 0; i < collected_scripts_.length(); i++) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 650 | debugger->OnScriptCollected(collected_scripts_[i]); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 651 | } |
| 652 | collected_scripts_.Clear(); |
| 653 | } |
| 654 | |
| 655 | |
| 656 | void ScriptCache::Clear() { |
| 657 | // Iterate the script cache to get rid of all the weak handles. |
| 658 | for (HashMap::Entry* entry = Start(); entry != NULL; entry = Next(entry)) { |
| 659 | ASSERT(entry != NULL); |
| 660 | Object** location = reinterpret_cast<Object**>(entry->value); |
| 661 | ASSERT((*location)->IsScript()); |
hpayer@chromium.org | 4f99be9 | 2013-12-18 16:23:55 +0000 | [diff] [blame] | 662 | GlobalHandles::ClearWeakness(location); |
| 663 | GlobalHandles::Destroy(location); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 664 | } |
| 665 | // Clear the content of the hash map. |
| 666 | HashMap::Clear(); |
| 667 | } |
| 668 | |
| 669 | |
hpayer@chromium.org | 4f99be9 | 2013-12-18 16:23:55 +0000 | [diff] [blame] | 670 | void ScriptCache::HandleWeakScript( |
| 671 | const v8::WeakCallbackData<v8::Value, void>& data) { |
| 672 | // Retrieve the script identifier. |
| 673 | Handle<Object> object = Utils::OpenHandle(*data.GetValue()); |
| 674 | int id = Handle<Script>::cast(object)->id()->value(); |
| 675 | void* key = reinterpret_cast<void*>(id); |
| 676 | uint32_t hash = Hash(id); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 677 | |
hpayer@chromium.org | 4f99be9 | 2013-12-18 16:23:55 +0000 | [diff] [blame] | 678 | // Remove the corresponding entry from the cache. |
| 679 | ScriptCache* script_cache = |
| 680 | reinterpret_cast<ScriptCache*>(data.GetParameter()); |
| 681 | HashMap::Entry* entry = script_cache->Lookup(key, hash, false); |
| 682 | Object** location = reinterpret_cast<Object**>(entry->value); |
| 683 | script_cache->Remove(key, hash); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 684 | script_cache->collected_scripts_.Add(id); |
| 685 | |
| 686 | // Clear the weak handle. |
hpayer@chromium.org | 4f99be9 | 2013-12-18 16:23:55 +0000 | [diff] [blame] | 687 | GlobalHandles::Destroy(location); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 688 | } |
| 689 | |
| 690 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 691 | void Debug::SetUp(bool create_heap_objects) { |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 692 | ThreadInit(); |
| 693 | if (create_heap_objects) { |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 694 | // Get code to handle debug break on return. |
| 695 | debug_break_return_ = |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 696 | isolate_->builtins()->builtin(Builtins::kReturn_DebugBreak); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 697 | ASSERT(debug_break_return_->IsCode()); |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 698 | // Get code to handle debug break in debug break slots. |
| 699 | debug_break_slot_ = |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 700 | isolate_->builtins()->builtin(Builtins::kSlot_DebugBreak); |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 701 | ASSERT(debug_break_slot_->IsCode()); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 702 | } |
| 703 | } |
| 704 | |
| 705 | |
hpayer@chromium.org | 4f99be9 | 2013-12-18 16:23:55 +0000 | [diff] [blame] | 706 | void Debug::HandleWeakDebugInfo( |
| 707 | const v8::WeakCallbackData<v8::Value, void>& data) { |
| 708 | Debug* debug = reinterpret_cast<Isolate*>(data.GetIsolate())->debug(); |
| 709 | DebugInfoListNode* node = |
| 710 | reinterpret_cast<DebugInfoListNode*>(data.GetParameter()); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 711 | // We need to clear all breakpoints associated with the function to restore |
| 712 | // original code and avoid patching the code twice later because |
| 713 | // the function will live in the heap until next gc, and can be found by |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 714 | // Debug::FindSharedFunctionInfoInScript. |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 715 | BreakLocationIterator it(node->debug_info(), ALL_BREAK_LOCATIONS); |
| 716 | it.ClearAllDebugBreak(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 717 | debug->RemoveDebugInfo(node->debug_info()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 718 | #ifdef DEBUG |
hpayer@chromium.org | 4f99be9 | 2013-12-18 16:23:55 +0000 | [diff] [blame] | 719 | for (DebugInfoListNode* n = debug->debug_info_list_; |
| 720 | n != NULL; |
| 721 | n = n->next()) { |
| 722 | ASSERT(n != node); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 723 | } |
| 724 | #endif |
| 725 | } |
| 726 | |
| 727 | |
| 728 | DebugInfoListNode::DebugInfoListNode(DebugInfo* debug_info): next_(NULL) { |
| 729 | // Globalize the request debug info object and make it weak. |
hpayer@chromium.org | 4f99be9 | 2013-12-18 16:23:55 +0000 | [diff] [blame] | 730 | GlobalHandles* global_handles = debug_info->GetIsolate()->global_handles(); |
| 731 | debug_info_ = Handle<DebugInfo>::cast(global_handles->Create(debug_info)); |
| 732 | GlobalHandles::MakeWeak(reinterpret_cast<Object**>(debug_info_.location()), |
| 733 | this, |
| 734 | Debug::HandleWeakDebugInfo); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 735 | } |
| 736 | |
| 737 | |
| 738 | DebugInfoListNode::~DebugInfoListNode() { |
hpayer@chromium.org | 4f99be9 | 2013-12-18 16:23:55 +0000 | [diff] [blame] | 739 | GlobalHandles::Destroy(reinterpret_cast<Object**>(debug_info_.location())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 740 | } |
| 741 | |
| 742 | |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 743 | bool Debug::CompileDebuggerScript(Isolate* isolate, int index) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 744 | Factory* factory = isolate->factory(); |
| 745 | HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 746 | |
kasper.lund | 4451067 | 2008-07-25 07:37:58 +0000 | [diff] [blame] | 747 | // Bail out if the index is invalid. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 748 | if (index == -1) { |
| 749 | return false; |
| 750 | } |
kasper.lund | 4451067 | 2008-07-25 07:37:58 +0000 | [diff] [blame] | 751 | |
| 752 | // Find source and name for the requested script. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 753 | Handle<String> source_code = |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 754 | isolate->bootstrapper()->NativesSourceLookup(index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 755 | Vector<const char> name = Natives::GetScriptName(index); |
machenbach@chromium.org | 8496027 | 2014-04-18 00:05:16 +0000 | [diff] [blame^] | 756 | Handle<String> script_name = |
| 757 | factory->NewStringFromAscii(name).ToHandleChecked(); |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 758 | Handle<Context> context = isolate->native_context(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 759 | |
| 760 | // Compile the script. |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 761 | Handle<SharedFunctionInfo> function_info; |
yangguo@chromium.org | 4954674 | 2013-12-23 16:17:49 +0000 | [diff] [blame] | 762 | function_info = Compiler::CompileScript(source_code, |
| 763 | script_name, 0, 0, |
| 764 | false, |
| 765 | context, |
machenbach@chromium.org | 69f64b1 | 2014-03-20 01:04:55 +0000 | [diff] [blame] | 766 | NULL, NULL, NO_CACHED_DATA, |
yangguo@chromium.org | 4954674 | 2013-12-23 16:17:49 +0000 | [diff] [blame] | 767 | NATIVES_CODE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 768 | |
| 769 | // Silently ignore stack overflows during compilation. |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 770 | if (function_info.is_null()) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 771 | ASSERT(isolate->has_pending_exception()); |
| 772 | isolate->clear_pending_exception(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 773 | return false; |
| 774 | } |
| 775 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 776 | // Execute the shared function in the debugger context. |
kasper.lund | 4451067 | 2008-07-25 07:37:58 +0000 | [diff] [blame] | 777 | Handle<JSFunction> function = |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 778 | factory->NewFunctionFromSharedFunctionInfo(function_info, context); |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 779 | |
machenbach@chromium.org | 2ebef18 | 2014-04-14 00:05:03 +0000 | [diff] [blame] | 780 | Handle<Object> exception; |
| 781 | MaybeHandle<Object> result = |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 782 | Execution::TryCall(function, |
| 783 | Handle<Object>(context->global_object(), isolate), |
| 784 | 0, |
| 785 | NULL, |
machenbach@chromium.org | 2ebef18 | 2014-04-14 00:05:03 +0000 | [diff] [blame] | 786 | &exception); |
kasper.lund | 4451067 | 2008-07-25 07:37:58 +0000 | [diff] [blame] | 787 | |
| 788 | // Check for caught exceptions. |
machenbach@chromium.org | 2ebef18 | 2014-04-14 00:05:03 +0000 | [diff] [blame] | 789 | if (result.is_null()) { |
fschneider@chromium.org | 7d10be5 | 2012-04-10 12:30:14 +0000 | [diff] [blame] | 790 | ASSERT(!isolate->has_pending_exception()); |
| 791 | MessageLocation computed_location; |
| 792 | isolate->ComputeLocation(&computed_location); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 793 | Handle<Object> message = MessageHandler::MakeMessageObject( |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 794 | isolate, "error_loading_debugger", &computed_location, |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 795 | Vector<Handle<Object> >::empty(), Handle<JSArray>()); |
fschneider@chromium.org | 7d10be5 | 2012-04-10 12:30:14 +0000 | [diff] [blame] | 796 | ASSERT(!isolate->has_pending_exception()); |
mmassi@chromium.org | 49a4467 | 2012-12-04 13:52:03 +0000 | [diff] [blame] | 797 | if (!exception.is_null()) { |
| 798 | isolate->set_pending_exception(*exception); |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 799 | MessageHandler::ReportMessage(isolate, NULL, message); |
mmassi@chromium.org | 49a4467 | 2012-12-04 13:52:03 +0000 | [diff] [blame] | 800 | isolate->clear_pending_exception(); |
| 801 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 802 | return false; |
| 803 | } |
| 804 | |
kasper.lund | 4451067 | 2008-07-25 07:37:58 +0000 | [diff] [blame] | 805 | // Mark this script as native and return successfully. |
| 806 | Handle<Script> script(Script::cast(function->shared()->script())); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 807 | script->set_type(Smi::FromInt(Script::TYPE_NATIVE)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 808 | return true; |
| 809 | } |
| 810 | |
| 811 | |
| 812 | bool Debug::Load() { |
| 813 | // Return if debugger is already loaded. |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 814 | if (IsLoaded()) return true; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 815 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 816 | Debugger* debugger = isolate_->debugger(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 817 | |
kasper.lund | 4451067 | 2008-07-25 07:37:58 +0000 | [diff] [blame] | 818 | // Bail out if we're already in the process of compiling the native |
| 819 | // JavaScript source code for the debugger. |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 820 | if (debugger->compiling_natives() || |
| 821 | debugger->is_loading_debugger()) |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 822 | return false; |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 823 | debugger->set_loading_debugger(true); |
kasper.lund | 4451067 | 2008-07-25 07:37:58 +0000 | [diff] [blame] | 824 | |
| 825 | // Disable breakpoints and interrupts while compiling and running the |
| 826 | // debugger scripts including the context creation code. |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 827 | DisableBreak disable(isolate_, true); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 828 | PostponeInterruptsScope postpone(isolate_); |
kasper.lund | 4451067 | 2008-07-25 07:37:58 +0000 | [diff] [blame] | 829 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 830 | // Create the debugger context. |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 831 | HandleScope scope(isolate_); |
machenbach@chromium.org | 26ca35c | 2014-01-16 08:22:55 +0000 | [diff] [blame] | 832 | ExtensionConfiguration no_extensions; |
kasper.lund | 4451067 | 2008-07-25 07:37:58 +0000 | [diff] [blame] | 833 | Handle<Context> context = |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 834 | isolate_->bootstrapper()->CreateEnvironment( |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 835 | Handle<Object>::null(), |
| 836 | v8::Handle<ObjectTemplate>(), |
machenbach@chromium.org | 26ca35c | 2014-01-16 08:22:55 +0000 | [diff] [blame] | 837 | &no_extensions); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 838 | |
fschneider@chromium.org | 7d10be5 | 2012-04-10 12:30:14 +0000 | [diff] [blame] | 839 | // Fail if no context could be created. |
| 840 | if (context.is_null()) return false; |
| 841 | |
kasper.lund | 4451067 | 2008-07-25 07:37:58 +0000 | [diff] [blame] | 842 | // Use the debugger context. |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 843 | SaveContext save(isolate_); |
| 844 | isolate_->set_context(*context); |
kasper.lund | 4451067 | 2008-07-25 07:37:58 +0000 | [diff] [blame] | 845 | |
| 846 | // Expose the builtins object in the debugger context. |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 847 | Handle<String> key = isolate_->factory()->InternalizeOneByteString( |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 848 | STATIC_ASCII_VECTOR("builtins")); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 849 | Handle<GlobalObject> global = Handle<GlobalObject>(context->global_object()); |
machenbach@chromium.org | 8f8fe81 | 2014-04-07 00:05:03 +0000 | [diff] [blame] | 850 | RETURN_ON_EXCEPTION_VALUE( |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 851 | isolate_, |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 852 | JSReceiver::SetProperty(global, |
| 853 | key, |
| 854 | Handle<Object>(global->builtins(), isolate_), |
| 855 | NONE, |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 856 | SLOPPY), |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 857 | false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 858 | |
| 859 | // Compile the JavaScript for the debugger in the debugger context. |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 860 | debugger->set_compiling_natives(true); |
kasper.lund | 4451067 | 2008-07-25 07:37:58 +0000 | [diff] [blame] | 861 | bool caught_exception = |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 862 | !CompileDebuggerScript(isolate_, Natives::GetIndex("mirror")) || |
| 863 | !CompileDebuggerScript(isolate_, Natives::GetIndex("debug")); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 864 | |
| 865 | if (FLAG_enable_liveedit) { |
| 866 | caught_exception = caught_exception || |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 867 | !CompileDebuggerScript(isolate_, Natives::GetIndex("liveedit")); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 868 | } |
| 869 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 870 | debugger->set_compiling_natives(false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 871 | |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 872 | // Make sure we mark the debugger as not loading before we might |
| 873 | // return. |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 874 | debugger->set_loading_debugger(false); |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 875 | |
kasper.lund | 4451067 | 2008-07-25 07:37:58 +0000 | [diff] [blame] | 876 | // Check for caught exceptions. |
| 877 | if (caught_exception) return false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 878 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 879 | // Debugger loaded, create debugger context global handle. |
| 880 | debug_context_ = Handle<Context>::cast( |
| 881 | isolate_->global_handles()->Create(*context)); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 882 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 883 | return true; |
| 884 | } |
| 885 | |
| 886 | |
| 887 | void Debug::Unload() { |
| 888 | // Return debugger is not loaded. |
| 889 | if (!IsLoaded()) { |
| 890 | return; |
| 891 | } |
| 892 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 893 | // Clear the script cache. |
| 894 | DestroyScriptCache(); |
| 895 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 896 | // Clear debugger context global handle. |
hpayer@chromium.org | 4f99be9 | 2013-12-18 16:23:55 +0000 | [diff] [blame] | 897 | GlobalHandles::Destroy(reinterpret_cast<Object**>(debug_context_.location())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 898 | debug_context_ = Handle<Context>(); |
| 899 | } |
| 900 | |
| 901 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 902 | // Set the flag indicating that preemption happened during debugging. |
| 903 | void Debug::PreemptionWhileInDebugger() { |
| 904 | ASSERT(InDebugger()); |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 905 | Debug::set_interrupts_pending(PREEMPT); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 906 | } |
| 907 | |
| 908 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 909 | void Debug::Iterate(ObjectVisitor* v) { |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 910 | v->VisitPointer(BitCast<Object**>(&(debug_break_return_))); |
| 911 | v->VisitPointer(BitCast<Object**>(&(debug_break_slot_))); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 912 | } |
| 913 | |
| 914 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 915 | Object* Debug::Break(Arguments args) { |
| 916 | Heap* heap = isolate_->heap(); |
| 917 | HandleScope scope(isolate_); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 918 | ASSERT(args.length() == 0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 919 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 920 | thread_local_.frame_drop_mode_ = FRAMES_UNTOUCHED; |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 921 | |
kasper.lund | bd3ec4e | 2008-07-09 11:06:54 +0000 | [diff] [blame] | 922 | // Get the top-most JavaScript frame. |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 923 | JavaScriptFrameIterator it(isolate_); |
kasper.lund | bd3ec4e | 2008-07-09 11:06:54 +0000 | [diff] [blame] | 924 | JavaScriptFrame* frame = it.frame(); |
| 925 | |
| 926 | // Just continue if breaks are disabled or debugger cannot be loaded. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 927 | if (disable_break() || !Load()) { |
| 928 | SetAfterBreakTarget(frame); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 929 | return heap->undefined_value(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 930 | } |
| 931 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 932 | // Enter the debugger. |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 933 | EnterDebugger debugger(isolate_); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 934 | if (debugger.FailedToEnter()) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 935 | return heap->undefined_value(); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 936 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 937 | |
kasper.lund | 4451067 | 2008-07-25 07:37:58 +0000 | [diff] [blame] | 938 | // Postpone interrupt during breakpoint processing. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 939 | PostponeInterruptsScope postpone(isolate_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 940 | |
| 941 | // Get the debug info (create it if it does not exist). |
| 942 | Handle<SharedFunctionInfo> shared = |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 943 | Handle<SharedFunctionInfo>(frame->function()->shared()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 944 | Handle<DebugInfo> debug_info = GetDebugInfo(shared); |
| 945 | |
| 946 | // Find the break point where execution has stopped. |
| 947 | BreakLocationIterator break_location_iterator(debug_info, |
| 948 | ALL_BREAK_LOCATIONS); |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 949 | // pc points to the instruction after the current one, possibly a break |
| 950 | // location as well. So the "- 1" to exclude it from the search. |
| 951 | break_location_iterator.FindBreakLocationFromAddress(frame->pc() - 1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 952 | |
| 953 | // Check whether step next reached a new statement. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 954 | if (!StepNextContinue(&break_location_iterator, frame)) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 955 | // Decrease steps left if performing multiple steps. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 956 | if (thread_local_.step_count_ > 0) { |
| 957 | thread_local_.step_count_--; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 958 | } |
| 959 | } |
| 960 | |
| 961 | // If there is one or more real break points check whether any of these are |
| 962 | // triggered. |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 963 | Handle<Object> break_points_hit(heap->undefined_value(), isolate_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 964 | if (break_location_iterator.HasBreakPoint()) { |
| 965 | Handle<Object> break_point_objects = |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 966 | Handle<Object>(break_location_iterator.BreakPointObjects(), isolate_); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 967 | break_points_hit = CheckBreakPoints(break_point_objects); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 968 | } |
| 969 | |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 970 | // If step out is active skip everything until the frame where we need to step |
| 971 | // out to is reached, unless real breakpoint is hit. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 972 | if (StepOutActive() && frame->fp() != step_out_fp() && |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 973 | break_points_hit->IsUndefined() ) { |
| 974 | // Step count should always be 0 for StepOut. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 975 | ASSERT(thread_local_.step_count_ == 0); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 976 | } else if (!break_points_hit->IsUndefined() || |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 977 | (thread_local_.last_step_action_ != StepNone && |
| 978 | thread_local_.step_count_ == 0)) { |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 979 | // Notify debugger if a real break point is triggered or if performing |
| 980 | // single stepping with no more steps to perform. Otherwise do another step. |
| 981 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 982 | // Clear all current stepping setup. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 983 | ClearStepping(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 984 | |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 985 | if (thread_local_.queued_step_count_ > 0) { |
| 986 | // Perform queued steps |
| 987 | int step_count = thread_local_.queued_step_count_; |
| 988 | |
| 989 | // Clear queue |
| 990 | thread_local_.queued_step_count_ = 0; |
| 991 | |
dslomov@chromium.org | 639bac0 | 2013-09-09 11:58:54 +0000 | [diff] [blame] | 992 | PrepareStep(StepNext, step_count, StackFrame::NO_ID); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 993 | } else { |
| 994 | // Notify the debug event listeners. |
| 995 | isolate_->debugger()->OnDebugBreak(break_points_hit, false); |
| 996 | } |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 997 | } else if (thread_local_.last_step_action_ != StepNone) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 998 | // Hold on to last step action as it is cleared by the call to |
| 999 | // ClearStepping. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1000 | StepAction step_action = thread_local_.last_step_action_; |
| 1001 | int step_count = thread_local_.step_count_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1002 | |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1003 | // If StepNext goes deeper in code, StepOut until original frame |
| 1004 | // and keep step count queued up in the meantime. |
| 1005 | if (step_action == StepNext && frame->fp() < thread_local_.last_fp_) { |
| 1006 | // Count frames until target frame |
| 1007 | int count = 0; |
| 1008 | JavaScriptFrameIterator it(isolate_); |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 1009 | while (!it.done() && it.frame()->fp() < thread_local_.last_fp_) { |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1010 | count++; |
| 1011 | it.Advance(); |
| 1012 | } |
| 1013 | |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 1014 | // Check that we indeed found the frame we are looking for. |
| 1015 | CHECK(!it.done() && (it.frame()->fp() == thread_local_.last_fp_)); |
| 1016 | if (step_count > 1) { |
| 1017 | // Save old count and action to continue stepping after StepOut. |
| 1018 | thread_local_.queued_step_count_ = step_count - 1; |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 1019 | } |
| 1020 | |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 1021 | // Set up for StepOut to reach target frame. |
| 1022 | step_action = StepOut; |
| 1023 | step_count = count; |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1024 | } |
| 1025 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1026 | // Clear all current stepping setup. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1027 | ClearStepping(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1028 | |
| 1029 | // Set up for the remaining steps. |
dslomov@chromium.org | 639bac0 | 2013-09-09 11:58:54 +0000 | [diff] [blame] | 1030 | PrepareStep(step_action, step_count, StackFrame::NO_ID); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1031 | } |
| 1032 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1033 | if (thread_local_.frame_drop_mode_ == FRAMES_UNTOUCHED) { |
| 1034 | SetAfterBreakTarget(frame); |
| 1035 | } else if (thread_local_.frame_drop_mode_ == |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1036 | FRAME_DROPPED_IN_IC_CALL) { |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1037 | // We must have been calling IC stub. Do not go there anymore. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1038 | Code* plain_return = isolate_->builtins()->builtin( |
| 1039 | Builtins::kPlainReturn_LiveEdit); |
| 1040 | thread_local_.after_break_target_ = plain_return->entry(); |
| 1041 | } else if (thread_local_.frame_drop_mode_ == |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1042 | FRAME_DROPPED_IN_DEBUG_SLOT_CALL) { |
| 1043 | // Debug break slot stub does not return normally, instead it manually |
| 1044 | // cleans the stack and jumps. We should patch the jump address. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1045 | Code* plain_return = isolate_->builtins()->builtin( |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1046 | Builtins::kFrameDropper_LiveEdit); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1047 | thread_local_.after_break_target_ = plain_return->entry(); |
| 1048 | } else if (thread_local_.frame_drop_mode_ == |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1049 | FRAME_DROPPED_IN_DIRECT_CALL) { |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1050 | // Nothing to do, after_break_target is not used here. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1051 | } else if (thread_local_.frame_drop_mode_ == |
| 1052 | FRAME_DROPPED_IN_RETURN_CALL) { |
| 1053 | Code* plain_return = isolate_->builtins()->builtin( |
| 1054 | Builtins::kFrameDropper_LiveEdit); |
| 1055 | thread_local_.after_break_target_ = plain_return->entry(); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1056 | } else { |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1057 | UNREACHABLE(); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1058 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1059 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1060 | return heap->undefined_value(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1061 | } |
| 1062 | |
| 1063 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1064 | RUNTIME_FUNCTION(Object*, Debug_Break) { |
| 1065 | return isolate->debug()->Break(args); |
| 1066 | } |
| 1067 | |
| 1068 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1069 | // Check the break point objects for whether one or more are actually |
| 1070 | // triggered. This function returns a JSArray with the break point objects |
| 1071 | // which is triggered. |
| 1072 | Handle<Object> Debug::CheckBreakPoints(Handle<Object> break_point_objects) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1073 | Factory* factory = isolate_->factory(); |
| 1074 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 1075 | // Count the number of break points hit. If there are multiple break points |
| 1076 | // they are in a FixedArray. |
| 1077 | Handle<FixedArray> break_points_hit; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1078 | int break_points_hit_count = 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1079 | ASSERT(!break_point_objects->IsUndefined()); |
| 1080 | if (break_point_objects->IsFixedArray()) { |
| 1081 | Handle<FixedArray> array(FixedArray::cast(*break_point_objects)); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1082 | break_points_hit = factory->NewFixedArray(array->length()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1083 | for (int i = 0; i < array->length(); i++) { |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 1084 | Handle<Object> o(array->get(i), isolate_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1085 | if (CheckBreakPoint(o)) { |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 1086 | break_points_hit->set(break_points_hit_count++, *o); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1087 | } |
| 1088 | } |
| 1089 | } else { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1090 | break_points_hit = factory->NewFixedArray(1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1091 | if (CheckBreakPoint(break_point_objects)) { |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 1092 | break_points_hit->set(break_points_hit_count++, *break_point_objects); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1093 | } |
| 1094 | } |
| 1095 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1096 | // Return undefined if no break points were triggered. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1097 | if (break_points_hit_count == 0) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1098 | return factory->undefined_value(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1099 | } |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 1100 | // Return break points hit as a JSArray. |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1101 | Handle<JSArray> result = factory->NewJSArrayWithElements(break_points_hit); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 1102 | result->set_length(Smi::FromInt(break_points_hit_count)); |
| 1103 | return result; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1104 | } |
| 1105 | |
| 1106 | |
| 1107 | // Check whether a single break point object is triggered. |
| 1108 | bool Debug::CheckBreakPoint(Handle<Object> break_point_object) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1109 | Factory* factory = isolate_->factory(); |
| 1110 | HandleScope scope(isolate_); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 1111 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1112 | // Ignore check if break point object is not a JSObject. |
| 1113 | if (!break_point_object->IsJSObject()) return true; |
| 1114 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 1115 | // Get the function IsBreakPointTriggered (defined in debug-debugger.js). |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1116 | Handle<String> is_break_point_triggered_string = |
| 1117 | factory->InternalizeOneByteString( |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1118 | STATIC_ASCII_VECTOR("IsBreakPointTriggered")); |
machenbach@chromium.org | 5b08056 | 2014-04-10 00:05:02 +0000 | [diff] [blame] | 1119 | Handle<GlobalObject> debug_global(debug_context()->global_object()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1120 | Handle<JSFunction> check_break_point = |
machenbach@chromium.org | 2ebef18 | 2014-04-14 00:05:03 +0000 | [diff] [blame] | 1121 | Handle<JSFunction>::cast(Object::GetProperty( |
| 1122 | debug_global, is_break_point_triggered_string).ToHandleChecked()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1123 | |
| 1124 | // Get the break id as an object. |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1125 | Handle<Object> break_id = factory->NewNumberFromInt(Debug::break_id()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1126 | |
| 1127 | // Call HandleBreakPointx. |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 1128 | Handle<Object> argv[] = { break_id, break_point_object }; |
machenbach@chromium.org | 2ebef18 | 2014-04-14 00:05:03 +0000 | [diff] [blame] | 1129 | Handle<Object> result; |
machenbach@chromium.org | e9fd658 | 2014-04-16 00:05:02 +0000 | [diff] [blame] | 1130 | if (!Execution::TryCall(check_break_point, |
| 1131 | isolate_->js_builtins_object(), |
| 1132 | ARRAY_SIZE(argv), |
| 1133 | argv).ToHandle(&result)) { |
| 1134 | return false; |
| 1135 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1136 | |
| 1137 | // Return whether the break point is triggered. |
machenbach@chromium.org | 2ebef18 | 2014-04-14 00:05:03 +0000 | [diff] [blame] | 1138 | return result->IsTrue(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1139 | } |
| 1140 | |
| 1141 | |
| 1142 | // Check whether the function has debug information. |
| 1143 | bool Debug::HasDebugInfo(Handle<SharedFunctionInfo> shared) { |
| 1144 | return !shared->debug_info()->IsUndefined(); |
| 1145 | } |
| 1146 | |
| 1147 | |
kasper.lund | bd3ec4e | 2008-07-09 11:06:54 +0000 | [diff] [blame] | 1148 | // Return the debug info for this function. EnsureDebugInfo must be called |
| 1149 | // prior to ensure the debug info has been generated for shared. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1150 | Handle<DebugInfo> Debug::GetDebugInfo(Handle<SharedFunctionInfo> shared) { |
kasper.lund | bd3ec4e | 2008-07-09 11:06:54 +0000 | [diff] [blame] | 1151 | ASSERT(HasDebugInfo(shared)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1152 | return Handle<DebugInfo>(DebugInfo::cast(shared->debug_info())); |
| 1153 | } |
| 1154 | |
| 1155 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 1156 | void Debug::SetBreakPoint(Handle<JSFunction> function, |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 1157 | Handle<Object> break_point_object, |
| 1158 | int* source_position) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1159 | HandleScope scope(isolate_); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 1160 | |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1161 | PrepareForBreakPoints(); |
| 1162 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 1163 | // Make sure the function is compiled and has set up the debug info. |
| 1164 | Handle<SharedFunctionInfo> shared(function->shared()); |
| 1165 | if (!EnsureDebugInfo(shared, function)) { |
kasper.lund | bd3ec4e | 2008-07-09 11:06:54 +0000 | [diff] [blame] | 1166 | // Return if retrieving debug info failed. |
| 1167 | return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1168 | } |
| 1169 | |
kasper.lund | bd3ec4e | 2008-07-09 11:06:54 +0000 | [diff] [blame] | 1170 | Handle<DebugInfo> debug_info = GetDebugInfo(shared); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1171 | // Source positions starts with zero. |
danno@chromium.org | bf0c820 | 2011-12-27 10:09:42 +0000 | [diff] [blame] | 1172 | ASSERT(*source_position >= 0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1173 | |
| 1174 | // Find the break point and change it. |
| 1175 | BreakLocationIterator it(debug_info, SOURCE_BREAK_LOCATIONS); |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame] | 1176 | it.FindBreakLocationFromPosition(*source_position, STATEMENT_ALIGNED); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1177 | it.SetBreakPoint(break_point_object); |
| 1178 | |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 1179 | *source_position = it.position(); |
| 1180 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1181 | // At least one active break point now. |
| 1182 | ASSERT(debug_info->GetBreakPointCount() > 0); |
| 1183 | } |
| 1184 | |
| 1185 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 1186 | bool Debug::SetBreakPointForScript(Handle<Script> script, |
| 1187 | Handle<Object> break_point_object, |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame] | 1188 | int* source_position, |
| 1189 | BreakPositionAlignment alignment) { |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 1190 | HandleScope scope(isolate_); |
| 1191 | |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 1192 | PrepareForBreakPoints(); |
| 1193 | |
| 1194 | // Obtain shared function info for the function. |
| 1195 | Object* result = FindSharedFunctionInfoInScript(script, *source_position); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 1196 | if (result->IsUndefined()) return false; |
| 1197 | |
| 1198 | // Make sure the function has set up the debug info. |
| 1199 | Handle<SharedFunctionInfo> shared(SharedFunctionInfo::cast(result)); |
| 1200 | if (!EnsureDebugInfo(shared, Handle<JSFunction>::null())) { |
| 1201 | // Return if retrieving debug info failed. |
| 1202 | return false; |
| 1203 | } |
| 1204 | |
| 1205 | // Find position within function. The script position might be before the |
| 1206 | // source position of the first function. |
| 1207 | int position; |
| 1208 | if (shared->start_position() > *source_position) { |
| 1209 | position = 0; |
| 1210 | } else { |
| 1211 | position = *source_position - shared->start_position(); |
| 1212 | } |
| 1213 | |
| 1214 | Handle<DebugInfo> debug_info = GetDebugInfo(shared); |
| 1215 | // Source positions starts with zero. |
| 1216 | ASSERT(position >= 0); |
| 1217 | |
| 1218 | // Find the break point and change it. |
| 1219 | BreakLocationIterator it(debug_info, SOURCE_BREAK_LOCATIONS); |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame] | 1220 | it.FindBreakLocationFromPosition(position, alignment); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 1221 | it.SetBreakPoint(break_point_object); |
| 1222 | |
| 1223 | *source_position = it.position() + shared->start_position(); |
| 1224 | |
| 1225 | // At least one active break point now. |
| 1226 | ASSERT(debug_info->GetBreakPointCount() > 0); |
| 1227 | return true; |
| 1228 | } |
| 1229 | |
| 1230 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1231 | void Debug::ClearBreakPoint(Handle<Object> break_point_object) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1232 | HandleScope scope(isolate_); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 1233 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1234 | DebugInfoListNode* node = debug_info_list_; |
| 1235 | while (node != NULL) { |
| 1236 | Object* result = DebugInfo::FindBreakPointInfo(node->debug_info(), |
| 1237 | break_point_object); |
| 1238 | if (!result->IsUndefined()) { |
| 1239 | // Get information in the break point. |
| 1240 | BreakPointInfo* break_point_info = BreakPointInfo::cast(result); |
| 1241 | Handle<DebugInfo> debug_info = node->debug_info(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1242 | |
| 1243 | // Find the break point and clear it. |
| 1244 | BreakLocationIterator it(debug_info, SOURCE_BREAK_LOCATIONS); |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 1245 | it.FindBreakLocationFromAddress(debug_info->code()->entry() + |
| 1246 | break_point_info->code_position()->value()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1247 | it.ClearBreakPoint(break_point_object); |
| 1248 | |
| 1249 | // If there are no more break points left remove the debug info for this |
| 1250 | // function. |
| 1251 | if (debug_info->GetBreakPointCount() == 0) { |
| 1252 | RemoveDebugInfo(debug_info); |
| 1253 | } |
| 1254 | |
| 1255 | return; |
| 1256 | } |
| 1257 | node = node->next(); |
| 1258 | } |
| 1259 | } |
| 1260 | |
| 1261 | |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 1262 | void Debug::ClearAllBreakPoints() { |
| 1263 | DebugInfoListNode* node = debug_info_list_; |
| 1264 | while (node != NULL) { |
| 1265 | // Remove all debug break code. |
| 1266 | BreakLocationIterator it(node->debug_info(), ALL_BREAK_LOCATIONS); |
| 1267 | it.ClearAllDebugBreak(); |
| 1268 | node = node->next(); |
| 1269 | } |
| 1270 | |
| 1271 | // Remove all debug info. |
| 1272 | while (debug_info_list_ != NULL) { |
| 1273 | RemoveDebugInfo(debug_info_list_->debug_info()); |
| 1274 | } |
| 1275 | } |
| 1276 | |
| 1277 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 1278 | void Debug::FloodWithOneShot(Handle<JSFunction> function) { |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1279 | PrepareForBreakPoints(); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 1280 | |
| 1281 | // Make sure the function is compiled and has set up the debug info. |
| 1282 | Handle<SharedFunctionInfo> shared(function->shared()); |
| 1283 | if (!EnsureDebugInfo(shared, function)) { |
kasper.lund | bd3ec4e | 2008-07-09 11:06:54 +0000 | [diff] [blame] | 1284 | // Return if we failed to retrieve the debug info. |
| 1285 | return; |
| 1286 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1287 | |
| 1288 | // Flood the function with break points. |
kasper.lund | bd3ec4e | 2008-07-09 11:06:54 +0000 | [diff] [blame] | 1289 | BreakLocationIterator it(GetDebugInfo(shared), ALL_BREAK_LOCATIONS); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1290 | while (!it.Done()) { |
| 1291 | it.SetOneShot(); |
| 1292 | it.Next(); |
| 1293 | } |
| 1294 | } |
| 1295 | |
| 1296 | |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 1297 | void Debug::FloodBoundFunctionWithOneShot(Handle<JSFunction> function) { |
| 1298 | Handle<FixedArray> new_bindings(function->function_bindings()); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 1299 | Handle<Object> bindee(new_bindings->get(JSFunction::kBoundFunctionIndex), |
| 1300 | isolate_); |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 1301 | |
| 1302 | if (!bindee.is_null() && bindee->IsJSFunction() && |
| 1303 | !JSFunction::cast(*bindee)->IsBuiltin()) { |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 1304 | Handle<JSFunction> bindee_function(JSFunction::cast(*bindee)); |
| 1305 | Debug::FloodWithOneShot(bindee_function); |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 1306 | } |
| 1307 | } |
| 1308 | |
| 1309 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1310 | void Debug::FloodHandlerWithOneShot() { |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 1311 | // Iterate through the JavaScript stack looking for handlers. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1312 | StackFrame::Id id = break_frame_id(); |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 1313 | if (id == StackFrame::NO_ID) { |
| 1314 | // If there is no JavaScript stack don't do anything. |
| 1315 | return; |
| 1316 | } |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 1317 | for (JavaScriptFrameIterator it(isolate_, id); !it.done(); it.Advance()) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1318 | JavaScriptFrame* frame = it.frame(); |
| 1319 | if (frame->HasHandler()) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1320 | // Flood the function with the catch block with break points |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 1321 | FloodWithOneShot(Handle<JSFunction>(frame->function())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1322 | return; |
| 1323 | } |
| 1324 | } |
| 1325 | } |
| 1326 | |
| 1327 | |
| 1328 | void Debug::ChangeBreakOnException(ExceptionBreakType type, bool enable) { |
| 1329 | if (type == BreakUncaughtException) { |
| 1330 | break_on_uncaught_exception_ = enable; |
| 1331 | } else { |
| 1332 | break_on_exception_ = enable; |
| 1333 | } |
| 1334 | } |
| 1335 | |
| 1336 | |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 1337 | bool Debug::IsBreakOnException(ExceptionBreakType type) { |
| 1338 | if (type == BreakUncaughtException) { |
| 1339 | return break_on_uncaught_exception_; |
| 1340 | } else { |
| 1341 | return break_on_exception_; |
| 1342 | } |
| 1343 | } |
| 1344 | |
| 1345 | |
dslomov@chromium.org | 639bac0 | 2013-09-09 11:58:54 +0000 | [diff] [blame] | 1346 | void Debug::PrepareStep(StepAction step_action, |
| 1347 | int step_count, |
| 1348 | StackFrame::Id frame_id) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1349 | HandleScope scope(isolate_); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1350 | |
| 1351 | PrepareForBreakPoints(); |
| 1352 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1353 | ASSERT(Debug::InDebugger()); |
| 1354 | |
| 1355 | // Remember this step action and count. |
| 1356 | thread_local_.last_step_action_ = step_action; |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1357 | if (step_action == StepOut) { |
| 1358 | // For step out target frame will be found on the stack so there is no need |
| 1359 | // to set step counter for it. It's expected to always be 0 for StepOut. |
| 1360 | thread_local_.step_count_ = 0; |
| 1361 | } else { |
| 1362 | thread_local_.step_count_ = step_count; |
| 1363 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1364 | |
| 1365 | // Get the frame where the execution has stopped and skip the debug frame if |
| 1366 | // any. The debug frame will only be present if execution was stopped due to |
| 1367 | // hitting a break point. In other situations (e.g. unhandled exception) the |
| 1368 | // debug frame is not present. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1369 | StackFrame::Id id = break_frame_id(); |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 1370 | if (id == StackFrame::NO_ID) { |
| 1371 | // If there is no JavaScript stack don't do anything. |
| 1372 | return; |
| 1373 | } |
dslomov@chromium.org | 639bac0 | 2013-09-09 11:58:54 +0000 | [diff] [blame] | 1374 | if (frame_id != StackFrame::NO_ID) { |
| 1375 | id = frame_id; |
| 1376 | } |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 1377 | JavaScriptFrameIterator frames_it(isolate_, id); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1378 | JavaScriptFrame* frame = frames_it.frame(); |
| 1379 | |
| 1380 | // First of all ensure there is one-shot break points in the top handler |
| 1381 | // if any. |
| 1382 | FloodHandlerWithOneShot(); |
| 1383 | |
| 1384 | // If the function on the top frame is unresolved perform step out. This will |
| 1385 | // be the case when calling unknown functions and having the debugger stopped |
| 1386 | // in an unhandled exception. |
| 1387 | if (!frame->function()->IsJSFunction()) { |
| 1388 | // Step out: Find the calling JavaScript frame and flood it with |
| 1389 | // breakpoints. |
| 1390 | frames_it.Advance(); |
| 1391 | // Fill the function to return to with one-shot break points. |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 1392 | JSFunction* function = frames_it.frame()->function(); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 1393 | FloodWithOneShot(Handle<JSFunction>(function)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1394 | return; |
| 1395 | } |
| 1396 | |
| 1397 | // Get the debug info (create it if it does not exist). |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 1398 | Handle<JSFunction> function(frame->function()); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 1399 | Handle<SharedFunctionInfo> shared(function->shared()); |
| 1400 | if (!EnsureDebugInfo(shared, function)) { |
kasper.lund | bd3ec4e | 2008-07-09 11:06:54 +0000 | [diff] [blame] | 1401 | // Return if ensuring debug info failed. |
| 1402 | return; |
| 1403 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1404 | Handle<DebugInfo> debug_info = GetDebugInfo(shared); |
| 1405 | |
| 1406 | // Find the break location where execution has stopped. |
| 1407 | BreakLocationIterator it(debug_info, ALL_BREAK_LOCATIONS); |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 1408 | // pc points to the instruction after the current one, possibly a break |
| 1409 | // location as well. So the "- 1" to exclude it from the search. |
| 1410 | it.FindBreakLocationFromAddress(frame->pc() - 1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1411 | |
| 1412 | // Compute whether or not the target is a call target. |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 1413 | bool is_load_or_store = false; |
| 1414 | bool is_inline_cache_stub = false; |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 1415 | bool is_at_restarted_function = false; |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1416 | Handle<Code> call_function_stub; |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1417 | |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 1418 | if (thread_local_.restarter_frame_function_pointer_ == NULL) { |
| 1419 | if (RelocInfo::IsCodeTarget(it.rinfo()->rmode())) { |
| 1420 | bool is_call_target = false; |
| 1421 | Address target = it.rinfo()->target_address(); |
| 1422 | Code* code = Code::GetCodeFromTargetAddress(target); |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 1423 | if (code->is_inline_cache_stub()) { |
| 1424 | is_inline_cache_stub = true; |
| 1425 | is_load_or_store = !is_call_target; |
| 1426 | } |
| 1427 | |
| 1428 | // Check if target code is CallFunction stub. |
| 1429 | Code* maybe_call_function_stub = code; |
| 1430 | // If there is a breakpoint at this line look at the original code to |
| 1431 | // check if it is a CallFunction stub. |
| 1432 | if (it.IsDebugBreak()) { |
| 1433 | Address original_target = it.original_rinfo()->target_address(); |
| 1434 | maybe_call_function_stub = |
| 1435 | Code::GetCodeFromTargetAddress(original_target); |
| 1436 | } |
| 1437 | if (maybe_call_function_stub->kind() == Code::STUB && |
| 1438 | maybe_call_function_stub->major_key() == CodeStub::CallFunction) { |
| 1439 | // Save reference to the code as we may need it to find out arguments |
| 1440 | // count for 'step in' later. |
| 1441 | call_function_stub = Handle<Code>(maybe_call_function_stub); |
| 1442 | } |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1443 | } |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 1444 | } else { |
| 1445 | is_at_restarted_function = true; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1446 | } |
| 1447 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1448 | // If this is the last break code target step out is the only possibility. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1449 | if (it.IsExit() || step_action == StepOut) { |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1450 | if (step_action == StepOut) { |
| 1451 | // Skip step_count frames starting with the current one. |
| 1452 | while (step_count-- > 0 && !frames_it.done()) { |
| 1453 | frames_it.Advance(); |
| 1454 | } |
| 1455 | } else { |
| 1456 | ASSERT(it.IsExit()); |
| 1457 | frames_it.Advance(); |
| 1458 | } |
| 1459 | // Skip builtin functions on the stack. |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 1460 | while (!frames_it.done() && frames_it.frame()->function()->IsBuiltin()) { |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1461 | frames_it.Advance(); |
| 1462 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1463 | // Step out: If there is a JavaScript caller frame, we need to |
| 1464 | // flood it with breakpoints. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1465 | if (!frames_it.done()) { |
| 1466 | // Fill the function to return to with one-shot break points. |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 1467 | JSFunction* function = frames_it.frame()->function(); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 1468 | FloodWithOneShot(Handle<JSFunction>(function)); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1469 | // Set target frame pointer. |
| 1470 | ActivateStepOut(frames_it.frame()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1471 | } |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1472 | } else if (!(is_inline_cache_stub || RelocInfo::IsConstructCall(it.rmode()) || |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 1473 | !call_function_stub.is_null() || is_at_restarted_function) |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 1474 | || step_action == StepNext || step_action == StepMin) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1475 | // Step next or step min. |
| 1476 | |
| 1477 | // Fill the current function with one-shot break points. |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 1478 | FloodWithOneShot(function); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1479 | |
| 1480 | // Remember source position and frame to handle step next. |
| 1481 | thread_local_.last_statement_position_ = |
| 1482 | debug_info->code()->SourceStatementPosition(frame->pc()); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1483 | thread_local_.last_fp_ = frame->UnpaddedFP(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1484 | } else { |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 1485 | // If there's restarter frame on top of the stack, just get the pointer |
| 1486 | // to function which is going to be restarted. |
| 1487 | if (is_at_restarted_function) { |
| 1488 | Handle<JSFunction> restarted_function( |
| 1489 | JSFunction::cast(*thread_local_.restarter_frame_function_pointer_)); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 1490 | FloodWithOneShot(restarted_function); |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 1491 | } else if (!call_function_stub.is_null()) { |
| 1492 | // If it's CallFunction stub ensure target function is compiled and flood |
| 1493 | // it with one shot breakpoints. |
| 1494 | |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1495 | // Find out number of arguments from the stub minor key. |
| 1496 | // Reverse lookup required as the minor key cannot be retrieved |
| 1497 | // from the code object. |
| 1498 | Handle<Object> obj( |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1499 | isolate_->heap()->code_stubs()->SlowReverseLookup( |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 1500 | *call_function_stub), |
| 1501 | isolate_); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1502 | ASSERT(!obj.is_null()); |
| 1503 | ASSERT(!(*obj)->IsUndefined()); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1504 | ASSERT(obj->IsSmi()); |
| 1505 | // Get the STUB key and extract major and minor key. |
| 1506 | uint32_t key = Smi::cast(*obj)->value(); |
| 1507 | // Argc in the stub is the number of arguments passed - not the |
| 1508 | // expected arguments of the called function. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1509 | int call_function_arg_count = |
| 1510 | CallFunctionStub::ExtractArgcFromMinorKey( |
| 1511 | CodeStub::MinorKeyFromKey(key)); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1512 | ASSERT(call_function_stub->major_key() == |
| 1513 | CodeStub::MajorKeyFromKey(key)); |
| 1514 | |
| 1515 | // Find target function on the expression stack. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1516 | // Expression stack looks like this (top to bottom): |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1517 | // argN |
| 1518 | // ... |
| 1519 | // arg0 |
| 1520 | // Receiver |
| 1521 | // Function to call |
| 1522 | int expressions_count = frame->ComputeExpressionsCount(); |
| 1523 | ASSERT(expressions_count - 2 - call_function_arg_count >= 0); |
| 1524 | Object* fun = frame->GetExpression( |
| 1525 | expressions_count - 2 - call_function_arg_count); |
machenbach@chromium.org | a03ba1e | 2014-02-01 08:54:43 +0000 | [diff] [blame] | 1526 | |
| 1527 | // Flood the actual target of call/apply. |
| 1528 | if (fun->IsJSFunction()) { |
| 1529 | Isolate* isolate = JSFunction::cast(fun)->GetIsolate(); |
| 1530 | Code* apply = isolate->builtins()->builtin(Builtins::kFunctionApply); |
| 1531 | Code* call = isolate->builtins()->builtin(Builtins::kFunctionCall); |
| 1532 | while (fun->IsJSFunction()) { |
| 1533 | Code* code = JSFunction::cast(fun)->shared()->code(); |
| 1534 | if (code != apply && code != call) break; |
| 1535 | fun = frame->GetExpression( |
| 1536 | expressions_count - 1 - call_function_arg_count); |
| 1537 | } |
| 1538 | } |
| 1539 | |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1540 | if (fun->IsJSFunction()) { |
| 1541 | Handle<JSFunction> js_function(JSFunction::cast(fun)); |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 1542 | if (js_function->shared()->bound()) { |
| 1543 | Debug::FloodBoundFunctionWithOneShot(js_function); |
| 1544 | } else if (!js_function->IsBuiltin()) { |
| 1545 | // Don't step into builtins. |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1546 | // It will also compile target function if it's not compiled yet. |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 1547 | FloodWithOneShot(js_function); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1548 | } |
| 1549 | } |
| 1550 | } |
| 1551 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1552 | // Fill the current function with one-shot break points even for step in on |
| 1553 | // a call target as the function called might be a native function for |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 1554 | // which step in will not stop. It also prepares for stepping in |
| 1555 | // getters/setters. |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 1556 | FloodWithOneShot(function); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1557 | |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 1558 | if (is_load_or_store) { |
| 1559 | // Remember source position and frame to handle step in getter/setter. If |
| 1560 | // there is a custom getter/setter it will be handled in |
| 1561 | // Object::Get/SetPropertyWithCallback, otherwise the step action will be |
| 1562 | // propagated on the next Debug::Break. |
| 1563 | thread_local_.last_statement_position_ = |
| 1564 | debug_info->code()->SourceStatementPosition(frame->pc()); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1565 | thread_local_.last_fp_ = frame->UnpaddedFP(); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 1566 | } |
| 1567 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1568 | // Step in or Step in min |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 1569 | it.PrepareStepIn(isolate_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1570 | ActivateStepIn(frame); |
| 1571 | } |
| 1572 | } |
| 1573 | |
| 1574 | |
| 1575 | // Check whether the current debug break should be reported to the debugger. It |
| 1576 | // is used to have step next and step in only report break back to the debugger |
| 1577 | // if on a different frame or in a different statement. In some situations |
| 1578 | // there will be several break points in the same statement when the code is |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1579 | // flooded with one-shot break points. This function helps to perform several |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1580 | // steps before reporting break back to the debugger. |
| 1581 | bool Debug::StepNextContinue(BreakLocationIterator* break_location_iterator, |
| 1582 | JavaScriptFrame* frame) { |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1583 | // StepNext and StepOut shouldn't bring us deeper in code, so last frame |
| 1584 | // shouldn't be a parent of current frame. |
| 1585 | if (thread_local_.last_step_action_ == StepNext || |
| 1586 | thread_local_.last_step_action_ == StepOut) { |
| 1587 | if (frame->fp() < thread_local_.last_fp_) return true; |
| 1588 | } |
| 1589 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1590 | // If the step last action was step next or step in make sure that a new |
| 1591 | // statement is hit. |
| 1592 | if (thread_local_.last_step_action_ == StepNext || |
| 1593 | thread_local_.last_step_action_ == StepIn) { |
| 1594 | // Never continue if returning from function. |
| 1595 | if (break_location_iterator->IsExit()) return false; |
| 1596 | |
| 1597 | // Continue if we are still on the same frame and in the same statement. |
| 1598 | int current_statement_position = |
| 1599 | break_location_iterator->code()->SourceStatementPosition(frame->pc()); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1600 | return thread_local_.last_fp_ == frame->UnpaddedFP() && |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1601 | thread_local_.last_statement_position_ == current_statement_position; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1602 | } |
| 1603 | |
| 1604 | // No step next action - don't continue. |
| 1605 | return false; |
| 1606 | } |
| 1607 | |
| 1608 | |
| 1609 | // Check whether the code object at the specified address is a debug break code |
| 1610 | // object. |
| 1611 | bool Debug::IsDebugBreak(Address addr) { |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 1612 | Code* code = Code::GetCodeFromTargetAddress(addr); |
verwaest@chromium.org | ec6855e | 2013-08-22 12:26:58 +0000 | [diff] [blame] | 1613 | return code->is_debug_stub() && code->extra_ic_state() == DEBUG_BREAK; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1614 | } |
| 1615 | |
| 1616 | |
| 1617 | // Check whether a code stub with the specified major key is a possible break |
| 1618 | // point location when looking for source break locations. |
| 1619 | bool Debug::IsSourceBreakStub(Code* code) { |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1620 | CodeStub::Major major_key = CodeStub::GetMajorKey(code); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1621 | return major_key == CodeStub::CallFunction; |
| 1622 | } |
| 1623 | |
| 1624 | |
| 1625 | // Check whether a code stub with the specified major key is a possible break |
| 1626 | // location. |
| 1627 | bool Debug::IsBreakStub(Code* code) { |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1628 | CodeStub::Major major_key = CodeStub::GetMajorKey(code); |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 1629 | return major_key == CodeStub::CallFunction; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1630 | } |
| 1631 | |
| 1632 | |
| 1633 | // Find the builtin to use for invoking the debug break |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1634 | Handle<Code> Debug::FindDebugBreak(Handle<Code> code, RelocInfo::Mode mode) { |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 1635 | Isolate* isolate = code->GetIsolate(); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 1636 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1637 | // Find the builtin debug break function matching the calling convention |
| 1638 | // used by the call site. |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1639 | if (code->is_inline_cache_stub()) { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1640 | switch (code->kind()) { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1641 | case Code::LOAD_IC: |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 1642 | return isolate->builtins()->LoadIC_DebugBreak(); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1643 | |
| 1644 | case Code::STORE_IC: |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 1645 | return isolate->builtins()->StoreIC_DebugBreak(); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1646 | |
| 1647 | case Code::KEYED_LOAD_IC: |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 1648 | return isolate->builtins()->KeyedLoadIC_DebugBreak(); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1649 | |
| 1650 | case Code::KEYED_STORE_IC: |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 1651 | return isolate->builtins()->KeyedStoreIC_DebugBreak(); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1652 | |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 1653 | case Code::COMPARE_NIL_IC: |
| 1654 | return isolate->builtins()->CompareNilIC_DebugBreak(); |
| 1655 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1656 | default: |
| 1657 | UNREACHABLE(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1658 | } |
| 1659 | } |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1660 | if (RelocInfo::IsConstructCall(mode)) { |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 1661 | if (code->has_function_cache()) { |
| 1662 | return isolate->builtins()->CallConstructStub_Recording_DebugBreak(); |
| 1663 | } else { |
| 1664 | return isolate->builtins()->CallConstructStub_DebugBreak(); |
| 1665 | } |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1666 | } |
| 1667 | if (code->kind() == Code::STUB) { |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 1668 | ASSERT(code->major_key() == CodeStub::CallFunction); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 1669 | if (code->has_function_cache()) { |
| 1670 | return isolate->builtins()->CallFunctionStub_Recording_DebugBreak(); |
| 1671 | } else { |
| 1672 | return isolate->builtins()->CallFunctionStub_DebugBreak(); |
| 1673 | } |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1674 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1675 | |
| 1676 | UNREACHABLE(); |
| 1677 | return Handle<Code>::null(); |
| 1678 | } |
| 1679 | |
| 1680 | |
| 1681 | // Simple function for returning the source positions for active break points. |
| 1682 | Handle<Object> Debug::GetSourceBreakLocations( |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame] | 1683 | Handle<SharedFunctionInfo> shared, |
| 1684 | BreakPositionAlignment position_alignment) { |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 1685 | Isolate* isolate = shared->GetIsolate(); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1686 | Heap* heap = isolate->heap(); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 1687 | if (!HasDebugInfo(shared)) { |
| 1688 | return Handle<Object>(heap->undefined_value(), isolate); |
| 1689 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1690 | Handle<DebugInfo> debug_info = GetDebugInfo(shared); |
| 1691 | if (debug_info->GetBreakPointCount() == 0) { |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 1692 | return Handle<Object>(heap->undefined_value(), isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1693 | } |
| 1694 | Handle<FixedArray> locations = |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1695 | isolate->factory()->NewFixedArray(debug_info->GetBreakPointCount()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1696 | int count = 0; |
| 1697 | for (int i = 0; i < debug_info->break_points()->length(); i++) { |
| 1698 | if (!debug_info->break_points()->get(i)->IsUndefined()) { |
| 1699 | BreakPointInfo* break_point_info = |
| 1700 | BreakPointInfo::cast(debug_info->break_points()->get(i)); |
| 1701 | if (break_point_info->GetBreakPointCount() > 0) { |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame] | 1702 | Smi* position; |
| 1703 | switch (position_alignment) { |
| 1704 | case STATEMENT_ALIGNED: |
| 1705 | position = break_point_info->statement_position(); |
| 1706 | break; |
| 1707 | case BREAK_POSITION_ALIGNED: |
| 1708 | position = break_point_info->source_position(); |
| 1709 | break; |
| 1710 | default: |
| 1711 | UNREACHABLE(); |
| 1712 | position = break_point_info->statement_position(); |
| 1713 | } |
| 1714 | |
| 1715 | locations->set(count++, position); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1716 | } |
| 1717 | } |
| 1718 | } |
| 1719 | return locations; |
| 1720 | } |
| 1721 | |
| 1722 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1723 | void Debug::NewBreak(StackFrame::Id break_frame_id) { |
| 1724 | thread_local_.break_frame_id_ = break_frame_id; |
| 1725 | thread_local_.break_id_ = ++thread_local_.break_count_; |
| 1726 | } |
| 1727 | |
| 1728 | |
| 1729 | void Debug::SetBreak(StackFrame::Id break_frame_id, int break_id) { |
| 1730 | thread_local_.break_frame_id_ = break_frame_id; |
| 1731 | thread_local_.break_id_ = break_id; |
| 1732 | } |
| 1733 | |
| 1734 | |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 1735 | // Handle stepping into a function. |
| 1736 | void Debug::HandleStepIn(Handle<JSFunction> function, |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1737 | Handle<Object> holder, |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 1738 | Address fp, |
| 1739 | bool is_constructor) { |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 1740 | Isolate* isolate = function->GetIsolate(); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 1741 | // If the frame pointer is not supplied by the caller find it. |
| 1742 | if (fp == 0) { |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 1743 | StackFrameIterator it(isolate); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 1744 | it.Advance(); |
| 1745 | // For constructor functions skip another frame. |
| 1746 | if (is_constructor) { |
| 1747 | ASSERT(it.frame()->is_construct()); |
| 1748 | it.Advance(); |
| 1749 | } |
| 1750 | fp = it.frame()->fp(); |
| 1751 | } |
| 1752 | |
| 1753 | // Flood the function with one-shot break points if it is called from where |
| 1754 | // step into was requested. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1755 | if (fp == step_in_fp()) { |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 1756 | if (function->shared()->bound()) { |
| 1757 | // Handle Function.prototype.bind |
| 1758 | Debug::FloodBoundFunctionWithOneShot(function); |
| 1759 | } else if (!function->IsBuiltin()) { |
| 1760 | // Don't allow step into functions in the native context. |
kasperl@chromium.org | acae378 | 2009-04-11 09:17:08 +0000 | [diff] [blame] | 1761 | if (function->shared()->code() == |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 1762 | isolate->builtins()->builtin(Builtins::kFunctionApply) || |
kasperl@chromium.org | acae378 | 2009-04-11 09:17:08 +0000 | [diff] [blame] | 1763 | function->shared()->code() == |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 1764 | isolate->builtins()->builtin(Builtins::kFunctionCall)) { |
kasperl@chromium.org | acae378 | 2009-04-11 09:17:08 +0000 | [diff] [blame] | 1765 | // Handle function.apply and function.call separately to flood the |
| 1766 | // function to be called and not the code for Builtins::FunctionApply or |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1767 | // Builtins::FunctionCall. The receiver of call/apply is the target |
| 1768 | // function. |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 1769 | if (!holder.is_null() && holder->IsJSFunction()) { |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 1770 | Handle<JSFunction> js_function = Handle<JSFunction>::cast(holder); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 1771 | if (!js_function->IsBuiltin()) { |
| 1772 | Debug::FloodWithOneShot(js_function); |
| 1773 | } else if (js_function->shared()->bound()) { |
| 1774 | // Handle Function.prototype.bind |
| 1775 | Debug::FloodBoundFunctionWithOneShot(js_function); |
| 1776 | } |
kasperl@chromium.org | acae378 | 2009-04-11 09:17:08 +0000 | [diff] [blame] | 1777 | } |
| 1778 | } else { |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 1779 | Debug::FloodWithOneShot(function); |
kasperl@chromium.org | acae378 | 2009-04-11 09:17:08 +0000 | [diff] [blame] | 1780 | } |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 1781 | } |
| 1782 | } |
| 1783 | } |
| 1784 | |
| 1785 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1786 | void Debug::ClearStepping() { |
| 1787 | // Clear the various stepping setup. |
| 1788 | ClearOneShot(); |
| 1789 | ClearStepIn(); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1790 | ClearStepOut(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1791 | ClearStepNext(); |
| 1792 | |
| 1793 | // Clear multiple step counter. |
| 1794 | thread_local_.step_count_ = 0; |
| 1795 | } |
| 1796 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 1797 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1798 | // Clears all the one-shot break points that are currently set. Normally this |
| 1799 | // function is called each time a break point is hit as one shot break points |
| 1800 | // are used to support stepping. |
| 1801 | void Debug::ClearOneShot() { |
| 1802 | // The current implementation just runs through all the breakpoints. When the |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1803 | // last break point for a function is removed that function is automatically |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1804 | // removed from the list. |
| 1805 | |
| 1806 | DebugInfoListNode* node = debug_info_list_; |
| 1807 | while (node != NULL) { |
| 1808 | BreakLocationIterator it(node->debug_info(), ALL_BREAK_LOCATIONS); |
| 1809 | while (!it.Done()) { |
| 1810 | it.ClearOneShot(); |
| 1811 | it.Next(); |
| 1812 | } |
| 1813 | node = node->next(); |
| 1814 | } |
| 1815 | } |
| 1816 | |
| 1817 | |
| 1818 | void Debug::ActivateStepIn(StackFrame* frame) { |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1819 | ASSERT(!StepOutActive()); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1820 | thread_local_.step_into_fp_ = frame->UnpaddedFP(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1821 | } |
| 1822 | |
| 1823 | |
| 1824 | void Debug::ClearStepIn() { |
| 1825 | thread_local_.step_into_fp_ = 0; |
| 1826 | } |
| 1827 | |
| 1828 | |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1829 | void Debug::ActivateStepOut(StackFrame* frame) { |
| 1830 | ASSERT(!StepInActive()); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1831 | thread_local_.step_out_fp_ = frame->UnpaddedFP(); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1832 | } |
| 1833 | |
| 1834 | |
| 1835 | void Debug::ClearStepOut() { |
| 1836 | thread_local_.step_out_fp_ = 0; |
| 1837 | } |
| 1838 | |
| 1839 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1840 | void Debug::ClearStepNext() { |
| 1841 | thread_local_.last_step_action_ = StepNone; |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1842 | thread_local_.last_statement_position_ = RelocInfo::kNoPosition; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1843 | thread_local_.last_fp_ = 0; |
| 1844 | } |
| 1845 | |
| 1846 | |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 1847 | static void CollectActiveFunctionsFromThread( |
| 1848 | Isolate* isolate, |
| 1849 | ThreadLocalTop* top, |
| 1850 | List<Handle<JSFunction> >* active_functions, |
| 1851 | Object* active_code_marker) { |
| 1852 | // Find all non-optimized code functions with activation frames |
| 1853 | // on the stack. This includes functions which have optimized |
| 1854 | // activations (including inlined functions) on the stack as the |
| 1855 | // non-optimized code is needed for the lazy deoptimization. |
| 1856 | for (JavaScriptFrameIterator it(isolate, top); !it.done(); it.Advance()) { |
| 1857 | JavaScriptFrame* frame = it.frame(); |
| 1858 | if (frame->is_optimized()) { |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 1859 | List<JSFunction*> functions(FLAG_max_inlining_levels + 1); |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 1860 | frame->GetFunctions(&functions); |
| 1861 | for (int i = 0; i < functions.length(); i++) { |
| 1862 | JSFunction* function = functions[i]; |
| 1863 | active_functions->Add(Handle<JSFunction>(function)); |
| 1864 | function->shared()->code()->set_gc_metadata(active_code_marker); |
| 1865 | } |
| 1866 | } else if (frame->function()->IsJSFunction()) { |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 1867 | JSFunction* function = frame->function(); |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 1868 | ASSERT(frame->LookupCode()->kind() == Code::FUNCTION); |
| 1869 | active_functions->Add(Handle<JSFunction>(function)); |
| 1870 | function->shared()->code()->set_gc_metadata(active_code_marker); |
| 1871 | } |
| 1872 | } |
| 1873 | } |
| 1874 | |
| 1875 | |
| 1876 | static void RedirectActivationsToRecompiledCodeOnThread( |
| 1877 | Isolate* isolate, |
| 1878 | ThreadLocalTop* top) { |
| 1879 | for (JavaScriptFrameIterator it(isolate, top); !it.done(); it.Advance()) { |
| 1880 | JavaScriptFrame* frame = it.frame(); |
| 1881 | |
| 1882 | if (frame->is_optimized() || !frame->function()->IsJSFunction()) continue; |
| 1883 | |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 1884 | JSFunction* function = frame->function(); |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 1885 | |
| 1886 | ASSERT(frame->LookupCode()->kind() == Code::FUNCTION); |
| 1887 | |
| 1888 | Handle<Code> frame_code(frame->LookupCode()); |
| 1889 | if (frame_code->has_debug_break_slots()) continue; |
| 1890 | |
| 1891 | Handle<Code> new_code(function->shared()->code()); |
| 1892 | if (new_code->kind() != Code::FUNCTION || |
| 1893 | !new_code->has_debug_break_slots()) { |
| 1894 | continue; |
| 1895 | } |
| 1896 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 1897 | // Iterate over the RelocInfo in the original code to compute the sum of the |
machenbach@chromium.org | 97b98c9 | 2014-03-13 03:05:00 +0000 | [diff] [blame] | 1898 | // constant pools and veneer pools sizes. (See Assembler::CheckConstPool() |
| 1899 | // and Assembler::CheckVeneerPool()) |
| 1900 | // Note that this is only useful for architectures using constant pools or |
| 1901 | // veneer pools. |
| 1902 | int pool_mask = RelocInfo::ModeMask(RelocInfo::CONST_POOL) | |
| 1903 | RelocInfo::ModeMask(RelocInfo::VENEER_POOL); |
| 1904 | int frame_pool_size = 0; |
| 1905 | for (RelocIterator it(*frame_code, pool_mask); !it.done(); it.next()) { |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 1906 | RelocInfo* info = it.rinfo(); |
| 1907 | if (info->pc() >= frame->pc()) break; |
machenbach@chromium.org | 97b98c9 | 2014-03-13 03:05:00 +0000 | [diff] [blame] | 1908 | frame_pool_size += static_cast<int>(info->data()); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 1909 | } |
| 1910 | intptr_t frame_offset = |
machenbach@chromium.org | 97b98c9 | 2014-03-13 03:05:00 +0000 | [diff] [blame] | 1911 | frame->pc() - frame_code->instruction_start() - frame_pool_size; |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 1912 | |
| 1913 | // Iterate over the RelocInfo for new code to find the number of bytes |
| 1914 | // generated for debug slots and constant pools. |
| 1915 | int debug_break_slot_bytes = 0; |
machenbach@chromium.org | 97b98c9 | 2014-03-13 03:05:00 +0000 | [diff] [blame] | 1916 | int new_code_pool_size = 0; |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 1917 | int mask = RelocInfo::ModeMask(RelocInfo::DEBUG_BREAK_SLOT) | |
machenbach@chromium.org | 97b98c9 | 2014-03-13 03:05:00 +0000 | [diff] [blame] | 1918 | RelocInfo::ModeMask(RelocInfo::CONST_POOL) | |
| 1919 | RelocInfo::ModeMask(RelocInfo::VENEER_POOL); |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 1920 | for (RelocIterator it(*new_code, mask); !it.done(); it.next()) { |
| 1921 | // Check if the pc in the new code with debug break |
| 1922 | // slots is before this slot. |
| 1923 | RelocInfo* info = it.rinfo(); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 1924 | intptr_t new_offset = info->pc() - new_code->instruction_start() - |
machenbach@chromium.org | 97b98c9 | 2014-03-13 03:05:00 +0000 | [diff] [blame] | 1925 | new_code_pool_size - debug_break_slot_bytes; |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 1926 | if (new_offset >= frame_offset) { |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 1927 | break; |
| 1928 | } |
| 1929 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 1930 | if (RelocInfo::IsDebugBreakSlot(info->rmode())) { |
| 1931 | debug_break_slot_bytes += Assembler::kDebugBreakSlotLength; |
| 1932 | } else { |
| 1933 | ASSERT(RelocInfo::IsConstPool(info->rmode())); |
machenbach@chromium.org | 97b98c9 | 2014-03-13 03:05:00 +0000 | [diff] [blame] | 1934 | // The size of the pools is encoded in the data. |
| 1935 | new_code_pool_size += static_cast<int>(info->data()); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 1936 | } |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 1937 | } |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 1938 | |
| 1939 | // Compute the equivalent pc in the new code. |
| 1940 | byte* new_pc = new_code->instruction_start() + frame_offset + |
machenbach@chromium.org | 97b98c9 | 2014-03-13 03:05:00 +0000 | [diff] [blame] | 1941 | debug_break_slot_bytes + new_code_pool_size; |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 1942 | |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 1943 | if (FLAG_trace_deopt) { |
| 1944 | PrintF("Replacing code %08" V8PRIxPTR " - %08" V8PRIxPTR " (%d) " |
| 1945 | "with %08" V8PRIxPTR " - %08" V8PRIxPTR " (%d) " |
| 1946 | "for debugging, " |
| 1947 | "changing pc from %08" V8PRIxPTR " to %08" V8PRIxPTR "\n", |
| 1948 | reinterpret_cast<intptr_t>( |
| 1949 | frame_code->instruction_start()), |
| 1950 | reinterpret_cast<intptr_t>( |
| 1951 | frame_code->instruction_start()) + |
| 1952 | frame_code->instruction_size(), |
| 1953 | frame_code->instruction_size(), |
| 1954 | reinterpret_cast<intptr_t>(new_code->instruction_start()), |
| 1955 | reinterpret_cast<intptr_t>(new_code->instruction_start()) + |
| 1956 | new_code->instruction_size(), |
| 1957 | new_code->instruction_size(), |
| 1958 | reinterpret_cast<intptr_t>(frame->pc()), |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 1959 | reinterpret_cast<intptr_t>(new_pc)); |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 1960 | } |
| 1961 | |
| 1962 | // Patch the return address to return into the code with |
| 1963 | // debug break slots. |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 1964 | frame->set_pc(new_pc); |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 1965 | } |
| 1966 | } |
| 1967 | |
| 1968 | |
| 1969 | class ActiveFunctionsCollector : public ThreadVisitor { |
| 1970 | public: |
| 1971 | explicit ActiveFunctionsCollector(List<Handle<JSFunction> >* active_functions, |
| 1972 | Object* active_code_marker) |
| 1973 | : active_functions_(active_functions), |
| 1974 | active_code_marker_(active_code_marker) { } |
| 1975 | |
| 1976 | void VisitThread(Isolate* isolate, ThreadLocalTop* top) { |
| 1977 | CollectActiveFunctionsFromThread(isolate, |
| 1978 | top, |
| 1979 | active_functions_, |
| 1980 | active_code_marker_); |
| 1981 | } |
| 1982 | |
| 1983 | private: |
| 1984 | List<Handle<JSFunction> >* active_functions_; |
| 1985 | Object* active_code_marker_; |
| 1986 | }; |
| 1987 | |
| 1988 | |
| 1989 | class ActiveFunctionsRedirector : public ThreadVisitor { |
| 1990 | public: |
| 1991 | void VisitThread(Isolate* isolate, ThreadLocalTop* top) { |
| 1992 | RedirectActivationsToRecompiledCodeOnThread(isolate, top); |
| 1993 | } |
| 1994 | }; |
| 1995 | |
| 1996 | |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1997 | void Debug::PrepareForBreakPoints() { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1998 | // If preparing for the first break point make sure to deoptimize all |
| 1999 | // functions as debugging does not work with optimized code. |
| 2000 | if (!has_break_points_) { |
machenbach@chromium.org | 9af454f | 2013-11-20 09:25:57 +0000 | [diff] [blame] | 2001 | if (isolate_->concurrent_recompilation_enabled()) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 2002 | isolate_->optimizing_compiler_thread()->Flush(); |
| 2003 | } |
| 2004 | |
svenpanne@chromium.org | 876cca8 | 2013-03-18 14:43:20 +0000 | [diff] [blame] | 2005 | Deoptimizer::DeoptimizeAll(isolate_); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 2006 | |
yangguo@chromium.org | 4954674 | 2013-12-23 16:17:49 +0000 | [diff] [blame] | 2007 | Handle<Code> lazy_compile = isolate_->builtins()->CompileUnoptimized(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2008 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 2009 | // There will be at least one break point when we are done. |
| 2010 | has_break_points_ = true; |
| 2011 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2012 | // Keep the list of activated functions in a handlified list as it |
| 2013 | // is used both in GC and non-GC code. |
| 2014 | List<Handle<JSFunction> > active_functions(100); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 2015 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2016 | { |
| 2017 | // We are going to iterate heap to find all functions without |
| 2018 | // debug break slots. |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2019 | Heap* heap = isolate_->heap(); |
| 2020 | heap->CollectAllGarbage(Heap::kMakeHeapIterableMask, |
| 2021 | "preparing for breakpoints"); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2022 | |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 2023 | // Ensure no GC in this scope as we are going to use gc_metadata |
| 2024 | // field in the Code object to mark active functions. |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 2025 | DisallowHeapAllocation no_allocation; |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2026 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2027 | Object* active_code_marker = heap->the_hole_value(); |
svenpanne@chromium.org | ecb9dd6 | 2011-12-01 08:22:35 +0000 | [diff] [blame] | 2028 | |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 2029 | CollectActiveFunctionsFromThread(isolate_, |
| 2030 | isolate_->thread_local_top(), |
| 2031 | &active_functions, |
| 2032 | active_code_marker); |
| 2033 | ActiveFunctionsCollector active_functions_collector(&active_functions, |
| 2034 | active_code_marker); |
| 2035 | isolate_->thread_manager()->IterateArchivedThreads( |
| 2036 | &active_functions_collector); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2037 | |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 2038 | // Scan the heap for all non-optimized functions which have no |
| 2039 | // debug break slots and are not active or inlined into an active |
| 2040 | // function and mark them for lazy compilation. |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2041 | HeapIterator iterator(heap); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2042 | HeapObject* obj = NULL; |
| 2043 | while (((obj = iterator.next()) != NULL)) { |
| 2044 | if (obj->IsJSFunction()) { |
| 2045 | JSFunction* function = JSFunction::cast(obj); |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 2046 | SharedFunctionInfo* shared = function->shared(); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2047 | |
| 2048 | if (!shared->allows_lazy_compilation()) continue; |
| 2049 | if (!shared->script()->IsScript()) continue; |
bmeurer@chromium.org | c9913f0 | 2013-10-24 06:31:36 +0000 | [diff] [blame] | 2050 | if (function->IsBuiltin()) continue; |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2051 | if (shared->code()->gc_metadata() == active_code_marker) continue; |
| 2052 | |
| 2053 | Code::Kind kind = function->code()->kind(); |
| 2054 | if (kind == Code::FUNCTION && |
| 2055 | !function->code()->has_debug_break_slots()) { |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 2056 | function->set_code(*lazy_compile); |
| 2057 | function->shared()->set_code(*lazy_compile); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2058 | } else if (kind == Code::BUILTIN && |
yangguo@chromium.org | 4954674 | 2013-12-23 16:17:49 +0000 | [diff] [blame] | 2059 | (function->IsInOptimizationQueue() || |
| 2060 | function->IsMarkedForOptimization() || |
| 2061 | function->IsMarkedForConcurrentOptimization())) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2062 | // Abort in-flight compilation. |
| 2063 | Code* shared_code = function->shared()->code(); |
| 2064 | if (shared_code->kind() == Code::FUNCTION && |
| 2065 | shared_code->has_debug_break_slots()) { |
| 2066 | function->set_code(shared_code); |
| 2067 | } else { |
| 2068 | function->set_code(*lazy_compile); |
| 2069 | function->shared()->set_code(*lazy_compile); |
| 2070 | } |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2071 | } |
| 2072 | } |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 2073 | } |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 2074 | |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 2075 | // Clear gc_metadata field. |
| 2076 | for (int i = 0; i < active_functions.length(); i++) { |
| 2077 | Handle<JSFunction> function = active_functions[i]; |
| 2078 | function->shared()->code()->set_gc_metadata(Smi::FromInt(0)); |
| 2079 | } |
| 2080 | } |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2081 | |
| 2082 | // Now recompile all functions with activation frames and and |
| 2083 | // patch the return address to run in the new compiled code. |
| 2084 | for (int i = 0; i < active_functions.length(); i++) { |
| 2085 | Handle<JSFunction> function = active_functions[i]; |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2086 | Handle<SharedFunctionInfo> shared(function->shared()); |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 2087 | |
| 2088 | if (function->code()->kind() == Code::FUNCTION && |
| 2089 | function->code()->has_debug_break_slots()) { |
| 2090 | // Nothing to do. Function code already had debug break slots. |
| 2091 | continue; |
| 2092 | } |
| 2093 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2094 | // If recompilation is not possible just skip it. |
| 2095 | if (shared->is_toplevel() || |
| 2096 | !shared->allows_lazy_compilation() || |
| 2097 | shared->code()->kind() == Code::BUILTIN) { |
| 2098 | continue; |
| 2099 | } |
| 2100 | |
| 2101 | // Make sure that the shared full code is compiled with debug |
| 2102 | // break slots. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2103 | if (!shared->code()->has_debug_break_slots()) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2104 | // Try to compile the full code with debug break slots. If it |
| 2105 | // fails just keep the current code. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2106 | bool prev_force_debugger_active = |
| 2107 | isolate_->debugger()->force_debugger_active(); |
| 2108 | isolate_->debugger()->set_force_debugger_active(true); |
ulan@chromium.org | 19aca23 | 2013-12-30 09:24:30 +0000 | [diff] [blame] | 2109 | Handle<Code> code = Compiler::GetCodeForDebugging(function); |
| 2110 | function->ReplaceCode(*code); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2111 | isolate_->debugger()->set_force_debugger_active( |
| 2112 | prev_force_debugger_active); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2113 | } |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2114 | |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 2115 | // Keep function code in sync with shared function info. |
| 2116 | function->set_code(shared->code()); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 2117 | } |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 2118 | |
| 2119 | RedirectActivationsToRecompiledCodeOnThread(isolate_, |
| 2120 | isolate_->thread_local_top()); |
| 2121 | |
| 2122 | ActiveFunctionsRedirector active_functions_redirector; |
| 2123 | isolate_->thread_manager()->IterateArchivedThreads( |
| 2124 | &active_functions_redirector); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2125 | } |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 2126 | } |
| 2127 | |
| 2128 | |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 2129 | Object* Debug::FindSharedFunctionInfoInScript(Handle<Script> script, |
| 2130 | int position) { |
| 2131 | // Iterate the heap looking for SharedFunctionInfo generated from the |
| 2132 | // script. The inner most SharedFunctionInfo containing the source position |
| 2133 | // for the requested break point is found. |
| 2134 | // NOTE: This might require several heap iterations. If the SharedFunctionInfo |
| 2135 | // which is found is not compiled it is compiled and the heap is iterated |
| 2136 | // again as the compilation might create inner functions from the newly |
| 2137 | // compiled function and the actual requested break point might be in one of |
| 2138 | // these functions. |
| 2139 | // NOTE: The below fix-point iteration depends on all functions that cannot be |
| 2140 | // compiled lazily without a context to not be compiled at all. Compilation |
| 2141 | // will be triggered at points where we do not need a context. |
| 2142 | bool done = false; |
| 2143 | // The current candidate for the source position: |
| 2144 | int target_start_position = RelocInfo::kNoPosition; |
| 2145 | Handle<JSFunction> target_function; |
| 2146 | Handle<SharedFunctionInfo> target; |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2147 | Heap* heap = isolate_->heap(); |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 2148 | while (!done) { |
| 2149 | { // Extra scope for iterator and no-allocation. |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2150 | heap->EnsureHeapIsIterable(); |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 2151 | DisallowHeapAllocation no_alloc_during_heap_iteration; |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2152 | HeapIterator iterator(heap); |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 2153 | for (HeapObject* obj = iterator.next(); |
| 2154 | obj != NULL; obj = iterator.next()) { |
| 2155 | bool found_next_candidate = false; |
| 2156 | Handle<JSFunction> function; |
| 2157 | Handle<SharedFunctionInfo> shared; |
| 2158 | if (obj->IsJSFunction()) { |
| 2159 | function = Handle<JSFunction>(JSFunction::cast(obj)); |
| 2160 | shared = Handle<SharedFunctionInfo>(function->shared()); |
| 2161 | ASSERT(shared->allows_lazy_compilation() || shared->is_compiled()); |
| 2162 | found_next_candidate = true; |
| 2163 | } else if (obj->IsSharedFunctionInfo()) { |
| 2164 | shared = Handle<SharedFunctionInfo>(SharedFunctionInfo::cast(obj)); |
| 2165 | // Skip functions that we cannot compile lazily without a context, |
| 2166 | // which is not available here, because there is no closure. |
| 2167 | found_next_candidate = shared->is_compiled() || |
| 2168 | shared->allows_lazy_compilation_without_context(); |
| 2169 | } |
| 2170 | if (!found_next_candidate) continue; |
| 2171 | if (shared->script() == *script) { |
| 2172 | // If the SharedFunctionInfo found has the requested script data and |
| 2173 | // contains the source position it is a candidate. |
| 2174 | int start_position = shared->function_token_position(); |
| 2175 | if (start_position == RelocInfo::kNoPosition) { |
| 2176 | start_position = shared->start_position(); |
| 2177 | } |
| 2178 | if (start_position <= position && |
| 2179 | position <= shared->end_position()) { |
| 2180 | // If there is no candidate or this function is within the current |
| 2181 | // candidate this is the new candidate. |
| 2182 | if (target.is_null()) { |
| 2183 | target_start_position = start_position; |
| 2184 | target_function = function; |
| 2185 | target = shared; |
| 2186 | } else { |
| 2187 | if (target_start_position == start_position && |
| 2188 | shared->end_position() == target->end_position()) { |
| 2189 | // If a top-level function contains only one function |
| 2190 | // declaration the source for the top-level and the function |
| 2191 | // is the same. In that case prefer the non top-level function. |
| 2192 | if (!shared->is_toplevel()) { |
| 2193 | target_start_position = start_position; |
| 2194 | target_function = function; |
| 2195 | target = shared; |
| 2196 | } |
| 2197 | } else if (target_start_position <= start_position && |
| 2198 | shared->end_position() <= target->end_position()) { |
| 2199 | // This containment check includes equality as a function |
| 2200 | // inside a top-level function can share either start or end |
| 2201 | // position with the top-level function. |
| 2202 | target_start_position = start_position; |
| 2203 | target_function = function; |
| 2204 | target = shared; |
| 2205 | } |
| 2206 | } |
| 2207 | } |
| 2208 | } |
| 2209 | } // End for loop. |
| 2210 | } // End no-allocation scope. |
| 2211 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2212 | if (target.is_null()) return heap->undefined_value(); |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 2213 | |
| 2214 | // There will be at least one break point when we are done. |
| 2215 | has_break_points_ = true; |
| 2216 | |
| 2217 | // If the candidate found is compiled we are done. |
| 2218 | done = target->is_compiled(); |
| 2219 | if (!done) { |
| 2220 | // If the candidate is not compiled, compile it to reveal any inner |
| 2221 | // functions which might contain the requested source position. This |
| 2222 | // will compile all inner functions that cannot be compiled without a |
| 2223 | // context, because Compiler::BuildFunctionInfo checks whether the |
| 2224 | // debugger is active. |
yangguo@chromium.org | 4954674 | 2013-12-23 16:17:49 +0000 | [diff] [blame] | 2225 | Handle<Code> result = target_function.is_null() |
| 2226 | ? Compiler::GetUnoptimizedCode(target) |
| 2227 | : Compiler::GetUnoptimizedCode(target_function); |
| 2228 | if (result.is_null()) return isolate_->heap()->undefined_value(); |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 2229 | } |
| 2230 | } // End while loop. |
| 2231 | |
| 2232 | return *target; |
| 2233 | } |
| 2234 | |
| 2235 | |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 2236 | // Ensures the debug information is present for shared. |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 2237 | bool Debug::EnsureDebugInfo(Handle<SharedFunctionInfo> shared, |
| 2238 | Handle<JSFunction> function) { |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 2239 | Isolate* isolate = shared->GetIsolate(); |
| 2240 | |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 2241 | // Return if we already have the debug info for shared. |
| 2242 | if (HasDebugInfo(shared)) { |
| 2243 | ASSERT(shared->is_compiled()); |
| 2244 | return true; |
| 2245 | } |
| 2246 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 2247 | // There will be at least one break point when we are done. |
| 2248 | has_break_points_ = true; |
| 2249 | |
| 2250 | // Ensure function is compiled. Return false if this failed. |
| 2251 | if (!function.is_null() && |
yangguo@chromium.org | 4954674 | 2013-12-23 16:17:49 +0000 | [diff] [blame] | 2252 | !Compiler::EnsureCompiled(function, CLEAR_EXCEPTION)) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2253 | return false; |
| 2254 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2255 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2256 | // Create the debug info object. |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 2257 | Handle<DebugInfo> debug_info = isolate->factory()->NewDebugInfo(shared); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2258 | |
| 2259 | // Add debug info to the list. |
| 2260 | DebugInfoListNode* node = new DebugInfoListNode(*debug_info); |
| 2261 | node->set_next(debug_info_list_); |
| 2262 | debug_info_list_ = node; |
| 2263 | |
kasper.lund | bd3ec4e | 2008-07-09 11:06:54 +0000 | [diff] [blame] | 2264 | return true; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2265 | } |
| 2266 | |
| 2267 | |
| 2268 | void Debug::RemoveDebugInfo(Handle<DebugInfo> debug_info) { |
| 2269 | ASSERT(debug_info_list_ != NULL); |
| 2270 | // Run through the debug info objects to find this one and remove it. |
| 2271 | DebugInfoListNode* prev = NULL; |
| 2272 | DebugInfoListNode* current = debug_info_list_; |
| 2273 | while (current != NULL) { |
| 2274 | if (*current->debug_info() == *debug_info) { |
| 2275 | // Unlink from list. If prev is NULL we are looking at the first element. |
| 2276 | if (prev == NULL) { |
| 2277 | debug_info_list_ = current->next(); |
| 2278 | } else { |
| 2279 | prev->set_next(current->next()); |
| 2280 | } |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2281 | current->debug_info()->shared()->set_debug_info( |
| 2282 | isolate_->heap()->undefined_value()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2283 | delete current; |
| 2284 | |
| 2285 | // If there are no more debug info objects there are not more break |
| 2286 | // points. |
| 2287 | has_break_points_ = debug_info_list_ != NULL; |
| 2288 | |
| 2289 | return; |
| 2290 | } |
| 2291 | // Move to next in list. |
| 2292 | prev = current; |
| 2293 | current = current->next(); |
| 2294 | } |
| 2295 | UNREACHABLE(); |
| 2296 | } |
| 2297 | |
| 2298 | |
| 2299 | void Debug::SetAfterBreakTarget(JavaScriptFrame* frame) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2300 | HandleScope scope(isolate_); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 2301 | |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 2302 | PrepareForBreakPoints(); |
| 2303 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2304 | // Get the executing function in which the debug break occurred. |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 2305 | Handle<JSFunction> function(JSFunction::cast(frame->function())); |
| 2306 | Handle<SharedFunctionInfo> shared(function->shared()); |
| 2307 | if (!EnsureDebugInfo(shared, function)) { |
kasper.lund | bd3ec4e | 2008-07-09 11:06:54 +0000 | [diff] [blame] | 2308 | // Return if we failed to retrieve the debug info. |
| 2309 | return; |
| 2310 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2311 | Handle<DebugInfo> debug_info = GetDebugInfo(shared); |
| 2312 | Handle<Code> code(debug_info->code()); |
| 2313 | Handle<Code> original_code(debug_info->original_code()); |
| 2314 | #ifdef DEBUG |
| 2315 | // Get the code which is actually executing. |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 2316 | Handle<Code> frame_code(frame->LookupCode()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2317 | ASSERT(frame_code.is_identical_to(code)); |
| 2318 | #endif |
| 2319 | |
| 2320 | // Find the call address in the running code. This address holds the call to |
| 2321 | // either a DebugBreakXXX or to the debug break return entry code if the |
| 2322 | // break point is still active after processing the break point. |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 2323 | Address addr = frame->pc() - Assembler::kPatchDebugBreakSlotReturnOffset; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2324 | |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 2325 | // Check if the location is at JS exit or debug break slot. |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 2326 | bool at_js_return = false; |
| 2327 | bool break_at_js_return_active = false; |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 2328 | bool at_debug_break_slot = false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2329 | RelocIterator it(debug_info->code()); |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 2330 | while (!it.done() && !at_js_return && !at_debug_break_slot) { |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 2331 | if (RelocInfo::IsJSReturn(it.rinfo()->rmode())) { |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 2332 | at_js_return = (it.rinfo()->pc() == |
| 2333 | addr - Assembler::kPatchReturnSequenceAddressOffset); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2334 | break_at_js_return_active = it.rinfo()->IsPatchedReturnSequence(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2335 | } |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 2336 | if (RelocInfo::IsDebugBreakSlot(it.rinfo()->rmode())) { |
| 2337 | at_debug_break_slot = (it.rinfo()->pc() == |
| 2338 | addr - Assembler::kPatchDebugBreakSlotAddressOffset); |
| 2339 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2340 | it.next(); |
| 2341 | } |
| 2342 | |
| 2343 | // Handle the jump to continue execution after break point depending on the |
| 2344 | // break location. |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 2345 | if (at_js_return) { |
| 2346 | // If the break point as return is still active jump to the corresponding |
| 2347 | // place in the original code. If not the break point was removed during |
| 2348 | // break point processing. |
| 2349 | if (break_at_js_return_active) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2350 | addr += original_code->instruction_start() - code->instruction_start(); |
| 2351 | } |
| 2352 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 2353 | // Move back to where the call instruction sequence started. |
| 2354 | thread_local_.after_break_target_ = |
| 2355 | addr - Assembler::kPatchReturnSequenceAddressOffset; |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 2356 | } else if (at_debug_break_slot) { |
| 2357 | // Address of where the debug break slot starts. |
| 2358 | addr = addr - Assembler::kPatchDebugBreakSlotAddressOffset; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2359 | |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 2360 | // Continue just after the slot. |
| 2361 | thread_local_.after_break_target_ = addr + Assembler::kDebugBreakSlotLength; |
machenbach@chromium.org | 97b98c9 | 2014-03-13 03:05:00 +0000 | [diff] [blame] | 2362 | } else if (IsDebugBreak(Assembler::target_address_at(addr, *code))) { |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 2363 | // We now know that there is still a debug break call at the target address, |
| 2364 | // so the break point is still there and the original code will hold the |
| 2365 | // address to jump to in order to complete the call which is replaced by a |
| 2366 | // call to DebugBreakXXX. |
| 2367 | |
| 2368 | // Find the corresponding address in the original code. |
| 2369 | addr += original_code->instruction_start() - code->instruction_start(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2370 | |
| 2371 | // Install jump to the call address in the original code. This will be the |
| 2372 | // call which was overwritten by the call to DebugBreakXXX. |
machenbach@chromium.org | 97b98c9 | 2014-03-13 03:05:00 +0000 | [diff] [blame] | 2373 | thread_local_.after_break_target_ = |
| 2374 | Assembler::target_address_at(addr, *original_code); |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 2375 | } else { |
| 2376 | // There is no longer a break point present. Don't try to look in the |
| 2377 | // original code as the running code will have the right address. This takes |
| 2378 | // care of the case where the last break point is removed from the function |
| 2379 | // and therefore no "original code" is available. |
machenbach@chromium.org | 97b98c9 | 2014-03-13 03:05:00 +0000 | [diff] [blame] | 2380 | thread_local_.after_break_target_ = |
| 2381 | Assembler::target_address_at(addr, *code); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2382 | } |
| 2383 | } |
| 2384 | |
| 2385 | |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 2386 | bool Debug::IsBreakAtReturn(JavaScriptFrame* frame) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2387 | HandleScope scope(isolate_); |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 2388 | |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 2389 | // If there are no break points this cannot be break at return, as |
| 2390 | // the debugger statement and stack guard bebug break cannot be at |
| 2391 | // return. |
| 2392 | if (!has_break_points_) { |
| 2393 | return false; |
| 2394 | } |
| 2395 | |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 2396 | PrepareForBreakPoints(); |
| 2397 | |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 2398 | // Get the executing function in which the debug break occurred. |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 2399 | Handle<JSFunction> function(JSFunction::cast(frame->function())); |
| 2400 | Handle<SharedFunctionInfo> shared(function->shared()); |
| 2401 | if (!EnsureDebugInfo(shared, function)) { |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 2402 | // Return if we failed to retrieve the debug info. |
| 2403 | return false; |
| 2404 | } |
| 2405 | Handle<DebugInfo> debug_info = GetDebugInfo(shared); |
| 2406 | Handle<Code> code(debug_info->code()); |
| 2407 | #ifdef DEBUG |
| 2408 | // Get the code which is actually executing. |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 2409 | Handle<Code> frame_code(frame->LookupCode()); |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 2410 | ASSERT(frame_code.is_identical_to(code)); |
| 2411 | #endif |
| 2412 | |
| 2413 | // Find the call address in the running code. |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 2414 | Address addr = frame->pc() - Assembler::kPatchDebugBreakSlotReturnOffset; |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 2415 | |
| 2416 | // Check if the location is at JS return. |
| 2417 | RelocIterator it(debug_info->code()); |
| 2418 | while (!it.done()) { |
| 2419 | if (RelocInfo::IsJSReturn(it.rinfo()->rmode())) { |
| 2420 | return (it.rinfo()->pc() == |
| 2421 | addr - Assembler::kPatchReturnSequenceAddressOffset); |
| 2422 | } |
| 2423 | it.next(); |
| 2424 | } |
| 2425 | return false; |
| 2426 | } |
| 2427 | |
| 2428 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 2429 | void Debug::FramesHaveBeenDropped(StackFrame::Id new_break_frame_id, |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 2430 | FrameDropMode mode, |
| 2431 | Object** restarter_frame_function_pointer) { |
ulan@chromium.org | d9e468a | 2012-06-25 09:47:40 +0000 | [diff] [blame] | 2432 | if (mode != CURRENTLY_SET_MODE) { |
| 2433 | thread_local_.frame_drop_mode_ = mode; |
| 2434 | } |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 2435 | thread_local_.break_frame_id_ = new_break_frame_id; |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 2436 | thread_local_.restarter_frame_function_pointer_ = |
| 2437 | restarter_frame_function_pointer; |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 2438 | } |
| 2439 | |
| 2440 | |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 2441 | const int Debug::FramePaddingLayout::kInitialSize = 1; |
| 2442 | |
| 2443 | |
| 2444 | // Any even value bigger than kInitialSize as needed for stack scanning. |
| 2445 | const int Debug::FramePaddingLayout::kPaddingValue = kInitialSize + 1; |
| 2446 | |
| 2447 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2448 | bool Debug::IsDebugGlobal(GlobalObject* global) { |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2449 | return IsLoaded() && global == debug_context()->global_object(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2450 | } |
| 2451 | |
| 2452 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2453 | void Debug::ClearMirrorCache() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2454 | PostponeInterruptsScope postpone(isolate_); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2455 | HandleScope scope(isolate_); |
| 2456 | ASSERT(isolate_->context() == *Debug::debug_context()); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2457 | |
| 2458 | // Clear the mirror cache. |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2459 | Handle<String> function_name = isolate_->factory()->InternalizeOneByteString( |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2460 | STATIC_ASCII_VECTOR("ClearMirrorCache")); |
machenbach@chromium.org | 2ebef18 | 2014-04-14 00:05:03 +0000 | [diff] [blame] | 2461 | Handle<Object> fun = Object::GetProperty( |
| 2462 | isolate_->global_object(), function_name).ToHandleChecked(); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2463 | ASSERT(fun->IsJSFunction()); |
machenbach@chromium.org | 2ebef18 | 2014-04-14 00:05:03 +0000 | [diff] [blame] | 2464 | Execution::TryCall( |
| 2465 | Handle<JSFunction>::cast(fun), |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2466 | Handle<JSObject>(Debug::debug_context()->global_object()), |
machenbach@chromium.org | 2ebef18 | 2014-04-14 00:05:03 +0000 | [diff] [blame] | 2467 | 0, |
| 2468 | NULL); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2469 | } |
| 2470 | |
| 2471 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2472 | void Debug::CreateScriptCache() { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2473 | Heap* heap = isolate_->heap(); |
| 2474 | HandleScope scope(isolate_); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2475 | |
| 2476 | // Perform two GCs to get rid of all unreferenced scripts. The first GC gets |
| 2477 | // rid of all the cached script wrappers and the second gets rid of the |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2478 | // scripts which are no longer referenced. The second also sweeps precisely, |
| 2479 | // which saves us doing yet another GC to make the heap iterable. |
rossberg@chromium.org | 994edf6 | 2012-02-06 10:12:55 +0000 | [diff] [blame] | 2480 | heap->CollectAllGarbage(Heap::kNoGCFlags, "Debug::CreateScriptCache"); |
| 2481 | heap->CollectAllGarbage(Heap::kMakeHeapIterableMask, |
| 2482 | "Debug::CreateScriptCache"); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2483 | |
| 2484 | ASSERT(script_cache_ == NULL); |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 2485 | script_cache_ = new ScriptCache(isolate_); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2486 | |
| 2487 | // Scan heap for Script objects. |
| 2488 | int count = 0; |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2489 | HeapIterator iterator(heap); |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 2490 | DisallowHeapAllocation no_allocation; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2491 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2492 | for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) { |
sgjesse@chromium.org | 152a0b0 | 2009-10-07 13:50:16 +0000 | [diff] [blame] | 2493 | if (obj->IsScript() && Script::cast(obj)->HasValidSource()) { |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2494 | script_cache_->Add(Handle<Script>(Script::cast(obj))); |
| 2495 | count++; |
| 2496 | } |
| 2497 | } |
| 2498 | } |
| 2499 | |
| 2500 | |
| 2501 | void Debug::DestroyScriptCache() { |
| 2502 | // Get rid of the script cache if it was created. |
| 2503 | if (script_cache_ != NULL) { |
| 2504 | delete script_cache_; |
| 2505 | script_cache_ = NULL; |
| 2506 | } |
| 2507 | } |
| 2508 | |
| 2509 | |
| 2510 | void Debug::AddScriptToScriptCache(Handle<Script> script) { |
| 2511 | if (script_cache_ != NULL) { |
| 2512 | script_cache_->Add(script); |
| 2513 | } |
| 2514 | } |
| 2515 | |
| 2516 | |
| 2517 | Handle<FixedArray> Debug::GetLoadedScripts() { |
| 2518 | // Create and fill the script cache when the loaded scripts is requested for |
| 2519 | // the first time. |
| 2520 | if (script_cache_ == NULL) { |
| 2521 | CreateScriptCache(); |
| 2522 | } |
| 2523 | |
| 2524 | // If the script cache is not active just return an empty array. |
| 2525 | ASSERT(script_cache_ != NULL); |
| 2526 | if (script_cache_ == NULL) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2527 | isolate_->factory()->NewFixedArray(0); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2528 | } |
| 2529 | |
| 2530 | // Perform GC to get unreferenced scripts evicted from the cache before |
| 2531 | // returning the content. |
rossberg@chromium.org | 994edf6 | 2012-02-06 10:12:55 +0000 | [diff] [blame] | 2532 | isolate_->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
| 2533 | "Debug::GetLoadedScripts"); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2534 | |
| 2535 | // Get the scripts from the cache. |
| 2536 | return script_cache_->GetScripts(); |
| 2537 | } |
| 2538 | |
| 2539 | |
yangguo@chromium.org | 4954674 | 2013-12-23 16:17:49 +0000 | [diff] [blame] | 2540 | void Debug::RecordEvalCaller(Handle<Script> script) { |
| 2541 | script->set_compilation_type(Script::COMPILATION_TYPE_EVAL); |
| 2542 | // For eval scripts add information on the function from which eval was |
| 2543 | // called. |
| 2544 | StackTraceFrameIterator it(script->GetIsolate()); |
| 2545 | if (!it.done()) { |
| 2546 | script->set_eval_from_shared(it.frame()->function()->shared()); |
| 2547 | Code* code = it.frame()->LookupCode(); |
| 2548 | int offset = static_cast<int>( |
| 2549 | it.frame()->pc() - code->instruction_start()); |
| 2550 | script->set_eval_from_instructions_offset(Smi::FromInt(offset)); |
| 2551 | } |
| 2552 | } |
| 2553 | |
| 2554 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2555 | void Debug::AfterGarbageCollection() { |
| 2556 | // Generate events for collected scripts. |
| 2557 | if (script_cache_ != NULL) { |
| 2558 | script_cache_->ProcessCollectedScripts(); |
| 2559 | } |
| 2560 | } |
| 2561 | |
| 2562 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2563 | Debugger::Debugger(Isolate* isolate) |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2564 | : debugger_access_(isolate->debugger_access()), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2565 | event_listener_(Handle<Object>()), |
| 2566 | event_listener_data_(Handle<Object>()), |
| 2567 | compiling_natives_(false), |
| 2568 | is_loading_debugger_(false), |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 2569 | live_edit_enabled_(true), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2570 | never_unload_debugger_(false), |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2571 | force_debugger_active_(false), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2572 | message_handler_(NULL), |
| 2573 | debugger_unload_pending_(false), |
| 2574 | host_dispatch_handler_(NULL), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2575 | debug_message_dispatch_handler_(NULL), |
| 2576 | message_dispatch_helper_thread_(NULL), |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 2577 | host_dispatch_period_(TimeDelta::FromMilliseconds(100)), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2578 | agent_(NULL), |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2579 | command_queue_(isolate->logger(), kQueueInitialSize), |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 2580 | command_received_(0), |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2581 | event_command_queue_(isolate->logger(), kQueueInitialSize), |
| 2582 | isolate_(isolate) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2583 | } |
| 2584 | |
| 2585 | |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 2586 | Debugger::~Debugger() {} |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2587 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2588 | |
machenbach@chromium.org | 2ebef18 | 2014-04-14 00:05:03 +0000 | [diff] [blame] | 2589 | MaybeHandle<Object> Debugger::MakeJSObject( |
| 2590 | Vector<const char> constructor_name, |
| 2591 | int argc, |
| 2592 | Handle<Object> argv[]) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2593 | ASSERT(isolate_->context() == *isolate_->debug()->debug_context()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2594 | |
| 2595 | // Create the execution state object. |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2596 | Handle<String> constructor_str = |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2597 | isolate_->factory()->InternalizeUtf8String(constructor_name); |
machenbach@chromium.org | b5ed930 | 2014-03-25 13:44:35 +0000 | [diff] [blame] | 2598 | ASSERT(!constructor_str.is_null()); |
machenbach@chromium.org | 2ebef18 | 2014-04-14 00:05:03 +0000 | [diff] [blame] | 2599 | Handle<Object> constructor = Object::GetProperty( |
| 2600 | isolate_->global_object(), constructor_str).ToHandleChecked(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2601 | ASSERT(constructor->IsJSFunction()); |
machenbach@chromium.org | 2ebef18 | 2014-04-14 00:05:03 +0000 | [diff] [blame] | 2602 | if (!constructor->IsJSFunction()) return MaybeHandle<Object>(); |
| 2603 | return Execution::TryCall( |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2604 | Handle<JSFunction>::cast(constructor), |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2605 | Handle<JSObject>(isolate_->debug()->debug_context()->global_object()), |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 2606 | argc, |
machenbach@chromium.org | 2ebef18 | 2014-04-14 00:05:03 +0000 | [diff] [blame] | 2607 | argv); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2608 | } |
| 2609 | |
| 2610 | |
machenbach@chromium.org | 2ebef18 | 2014-04-14 00:05:03 +0000 | [diff] [blame] | 2611 | MaybeHandle<Object> Debugger::MakeExecutionState() { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2612 | // Create the execution state object. |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2613 | Handle<Object> break_id = isolate_->factory()->NewNumberFromInt( |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2614 | isolate_->debug()->break_id()); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 2615 | Handle<Object> argv[] = { break_id }; |
machenbach@chromium.org | 2ebef18 | 2014-04-14 00:05:03 +0000 | [diff] [blame] | 2616 | return MakeJSObject(CStrVector("MakeExecutionState"), ARRAY_SIZE(argv), argv); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2617 | } |
| 2618 | |
| 2619 | |
machenbach@chromium.org | 2ebef18 | 2014-04-14 00:05:03 +0000 | [diff] [blame] | 2620 | MaybeHandle<Object> Debugger::MakeBreakEvent(Handle<Object> break_points_hit) { |
| 2621 | Handle<Object> exec_state; |
machenbach@chromium.org | e9fd658 | 2014-04-16 00:05:02 +0000 | [diff] [blame] | 2622 | if (!MakeExecutionState().ToHandle(&exec_state)) return MaybeHandle<Object>(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2623 | // Create the new break event object. |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 2624 | Handle<Object> argv[] = { exec_state, break_points_hit }; |
machenbach@chromium.org | 2ebef18 | 2014-04-14 00:05:03 +0000 | [diff] [blame] | 2625 | return MakeJSObject(CStrVector("MakeBreakEvent"), ARRAY_SIZE(argv), argv); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2626 | } |
| 2627 | |
| 2628 | |
machenbach@chromium.org | 2ebef18 | 2014-04-14 00:05:03 +0000 | [diff] [blame] | 2629 | MaybeHandle<Object> Debugger::MakeExceptionEvent(Handle<Object> exception, |
| 2630 | bool uncaught) { |
| 2631 | Handle<Object> exec_state; |
machenbach@chromium.org | e9fd658 | 2014-04-16 00:05:02 +0000 | [diff] [blame] | 2632 | if (!MakeExecutionState().ToHandle(&exec_state)) return MaybeHandle<Object>(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2633 | // Create the new exception event object. |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 2634 | Handle<Object> argv[] = { exec_state, |
| 2635 | exception, |
machenbach@chromium.org | 2ebef18 | 2014-04-14 00:05:03 +0000 | [diff] [blame] | 2636 | isolate_->factory()->ToBoolean(uncaught) }; |
| 2637 | return MakeJSObject(CStrVector("MakeExceptionEvent"), ARRAY_SIZE(argv), argv); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2638 | } |
| 2639 | |
| 2640 | |
machenbach@chromium.org | 2ebef18 | 2014-04-14 00:05:03 +0000 | [diff] [blame] | 2641 | MaybeHandle<Object> Debugger::MakeCompileEvent(Handle<Script> script, |
| 2642 | bool before) { |
machenbach@chromium.org | 2ebef18 | 2014-04-14 00:05:03 +0000 | [diff] [blame] | 2643 | Handle<Object> exec_state; |
machenbach@chromium.org | e9fd658 | 2014-04-16 00:05:02 +0000 | [diff] [blame] | 2644 | if (!MakeExecutionState().ToHandle(&exec_state)) return MaybeHandle<Object>(); |
| 2645 | // Create the compile event object. |
machenbach@chromium.org | 9fa6195 | 2014-04-17 00:05:12 +0000 | [diff] [blame] | 2646 | Handle<Object> script_wrapper = Script::GetWrapper(script); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 2647 | Handle<Object> argv[] = { exec_state, |
| 2648 | script_wrapper, |
machenbach@chromium.org | e9fd658 | 2014-04-16 00:05:02 +0000 | [diff] [blame] | 2649 | isolate_->factory()->ToBoolean(before) }; |
machenbach@chromium.org | 2ebef18 | 2014-04-14 00:05:03 +0000 | [diff] [blame] | 2650 | return MakeJSObject(CStrVector("MakeCompileEvent"), ARRAY_SIZE(argv), argv); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2651 | } |
| 2652 | |
| 2653 | |
machenbach@chromium.org | 2ebef18 | 2014-04-14 00:05:03 +0000 | [diff] [blame] | 2654 | MaybeHandle<Object> Debugger::MakeScriptCollectedEvent(int id) { |
machenbach@chromium.org | 2ebef18 | 2014-04-14 00:05:03 +0000 | [diff] [blame] | 2655 | Handle<Object> exec_state; |
machenbach@chromium.org | e9fd658 | 2014-04-16 00:05:02 +0000 | [diff] [blame] | 2656 | if (!MakeExecutionState().ToHandle(&exec_state)) return MaybeHandle<Object>(); |
| 2657 | // Create the script collected event object. |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 2658 | Handle<Object> id_object = Handle<Smi>(Smi::FromInt(id), isolate_); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 2659 | Handle<Object> argv[] = { exec_state, id_object }; |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2660 | |
machenbach@chromium.org | 2ebef18 | 2014-04-14 00:05:03 +0000 | [diff] [blame] | 2661 | return MakeJSObject( |
| 2662 | CStrVector("MakeScriptCollectedEvent"), ARRAY_SIZE(argv), argv); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2663 | } |
| 2664 | |
| 2665 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2666 | void Debugger::OnException(Handle<Object> exception, bool uncaught) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2667 | HandleScope scope(isolate_); |
| 2668 | Debug* debug = isolate_->debug(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2669 | |
| 2670 | // Bail out based on state or if there is no listener for this event |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2671 | if (debug->InDebugger()) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2672 | if (!Debugger::EventActive(v8::Exception)) return; |
| 2673 | |
| 2674 | // Bail out if exception breaks are not active |
| 2675 | if (uncaught) { |
| 2676 | // Uncaught exceptions are reported by either flags. |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2677 | if (!(debug->break_on_uncaught_exception() || |
| 2678 | debug->break_on_exception())) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2679 | } else { |
| 2680 | // Caught exceptions are reported is activated. |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2681 | if (!debug->break_on_exception()) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2682 | } |
| 2683 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 2684 | // Enter the debugger. |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 2685 | EnterDebugger debugger(isolate_); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 2686 | if (debugger.FailedToEnter()) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2687 | |
| 2688 | // Clear all current stepping setup. |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2689 | debug->ClearStepping(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2690 | // Create the event data object. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2691 | Handle<Object> event_data; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2692 | // Bail out and don't call debugger if exception. |
machenbach@chromium.org | e9fd658 | 2014-04-16 00:05:02 +0000 | [diff] [blame] | 2693 | if (!MakeExceptionEvent(exception, uncaught).ToHandle(&event_data)) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2694 | |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 2695 | // Process debug event. |
| 2696 | ProcessDebugEvent(v8::Exception, Handle<JSObject>::cast(event_data), false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2697 | // Return to continue execution from where the exception was thrown. |
| 2698 | } |
| 2699 | |
| 2700 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2701 | void Debugger::OnDebugBreak(Handle<Object> break_points_hit, |
| 2702 | bool auto_continue) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2703 | HandleScope scope(isolate_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2704 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 2705 | // Debugger has already been entered by caller. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2706 | ASSERT(isolate_->context() == *isolate_->debug()->debug_context()); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 2707 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2708 | // Bail out if there is no listener for this event |
| 2709 | if (!Debugger::EventActive(v8::Break)) return; |
| 2710 | |
| 2711 | // Debugger must be entered in advance. |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2712 | ASSERT(isolate_->context() == *isolate_->debug()->debug_context()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2713 | |
| 2714 | // Create the event data object. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2715 | Handle<Object> event_data; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2716 | // Bail out and don't call debugger if exception. |
machenbach@chromium.org | e9fd658 | 2014-04-16 00:05:02 +0000 | [diff] [blame] | 2717 | if (!MakeBreakEvent(break_points_hit).ToHandle(&event_data)) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2718 | |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 2719 | // Process debug event. |
| 2720 | ProcessDebugEvent(v8::Break, |
| 2721 | Handle<JSObject>::cast(event_data), |
| 2722 | auto_continue); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2723 | } |
| 2724 | |
| 2725 | |
| 2726 | void Debugger::OnBeforeCompile(Handle<Script> script) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2727 | HandleScope scope(isolate_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2728 | |
| 2729 | // Bail out based on state or if there is no listener for this event |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2730 | if (isolate_->debug()->InDebugger()) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2731 | if (compiling_natives()) return; |
| 2732 | if (!EventActive(v8::BeforeCompile)) return; |
| 2733 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 2734 | // Enter the debugger. |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 2735 | EnterDebugger debugger(isolate_); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 2736 | if (debugger.FailedToEnter()) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2737 | |
| 2738 | // Create the event data object. |
machenbach@chromium.org | 2ebef18 | 2014-04-14 00:05:03 +0000 | [diff] [blame] | 2739 | Handle<Object> event_data; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2740 | // Bail out and don't call debugger if exception. |
machenbach@chromium.org | e9fd658 | 2014-04-16 00:05:02 +0000 | [diff] [blame] | 2741 | if (!MakeCompileEvent(script, true).ToHandle(&event_data)) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2742 | |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 2743 | // Process debug event. |
| 2744 | ProcessDebugEvent(v8::BeforeCompile, |
| 2745 | Handle<JSObject>::cast(event_data), |
| 2746 | true); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2747 | } |
| 2748 | |
| 2749 | |
| 2750 | // Handle debugger actions when a new script is compiled. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2751 | void Debugger::OnAfterCompile(Handle<Script> script, |
| 2752 | AfterCompileFlags after_compile_flags) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2753 | HandleScope scope(isolate_); |
| 2754 | Debug* debug = isolate_->debug(); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 2755 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2756 | // Add the newly compiled script to the script cache. |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2757 | debug->AddScriptToScriptCache(script); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2758 | |
| 2759 | // No more to do if not debugging. |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 2760 | if (!IsDebuggerActive()) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2761 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2762 | // No compile events while compiling natives. |
| 2763 | if (compiling_natives()) return; |
| 2764 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 2765 | // Store whether in debugger before entering debugger. |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2766 | bool in_debugger = debug->InDebugger(); |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 2767 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 2768 | // Enter the debugger. |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 2769 | EnterDebugger debugger(isolate_); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 2770 | if (debugger.FailedToEnter()) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2771 | |
| 2772 | // If debugging there might be script break points registered for this |
| 2773 | // script. Make sure that these break points are set. |
| 2774 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2775 | // Get the function UpdateScriptBreakPoints (defined in debug-debugger.js). |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2776 | Handle<String> update_script_break_points_string = |
| 2777 | isolate_->factory()->InternalizeOneByteString( |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2778 | STATIC_ASCII_VECTOR("UpdateScriptBreakPoints")); |
machenbach@chromium.org | 5b08056 | 2014-04-10 00:05:02 +0000 | [diff] [blame] | 2779 | Handle<GlobalObject> debug_global(debug->debug_context()->global_object()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2780 | Handle<Object> update_script_break_points = |
machenbach@chromium.org | 2ebef18 | 2014-04-14 00:05:03 +0000 | [diff] [blame] | 2781 | Object::GetProperty( |
| 2782 | debug_global, update_script_break_points_string).ToHandleChecked(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2783 | if (!update_script_break_points->IsJSFunction()) { |
| 2784 | return; |
| 2785 | } |
| 2786 | ASSERT(update_script_break_points->IsJSFunction()); |
| 2787 | |
| 2788 | // Wrap the script object in a proper JS object before passing it |
| 2789 | // to JavaScript. |
machenbach@chromium.org | 9fa6195 | 2014-04-17 00:05:12 +0000 | [diff] [blame] | 2790 | Handle<Object> wrapper = Script::GetWrapper(script); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2791 | |
| 2792 | // Call UpdateScriptBreakPoints expect no exceptions. |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 2793 | Handle<Object> argv[] = { wrapper }; |
machenbach@chromium.org | 2ebef18 | 2014-04-14 00:05:03 +0000 | [diff] [blame] | 2794 | if (Execution::TryCall(Handle<JSFunction>::cast(update_script_break_points), |
| 2795 | isolate_->js_builtins_object(), |
| 2796 | ARRAY_SIZE(argv), |
| 2797 | argv).is_null()) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2798 | return; |
| 2799 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2800 | // Bail out based on state or if there is no listener for this event |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2801 | if (in_debugger && (after_compile_flags & SEND_WHEN_DEBUGGING) == 0) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2802 | if (!Debugger::EventActive(v8::AfterCompile)) return; |
| 2803 | |
| 2804 | // Create the compile state object. |
machenbach@chromium.org | 2ebef18 | 2014-04-14 00:05:03 +0000 | [diff] [blame] | 2805 | Handle<Object> event_data; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2806 | // Bail out and don't call debugger if exception. |
machenbach@chromium.org | e9fd658 | 2014-04-16 00:05:02 +0000 | [diff] [blame] | 2807 | if (!MakeCompileEvent(script, false).ToHandle(&event_data)) return; |
machenbach@chromium.org | 2ebef18 | 2014-04-14 00:05:03 +0000 | [diff] [blame] | 2808 | |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 2809 | // Process debug event. |
machenbach@chromium.org | 2ebef18 | 2014-04-14 00:05:03 +0000 | [diff] [blame] | 2810 | ProcessDebugEvent(v8::AfterCompile, Handle<JSObject>::cast(event_data), true); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2811 | } |
| 2812 | |
| 2813 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2814 | void Debugger::OnScriptCollected(int id) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2815 | HandleScope scope(isolate_); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2816 | |
| 2817 | // No more to do if not debugging. |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2818 | if (isolate_->debug()->InDebugger()) return; |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2819 | if (!IsDebuggerActive()) return; |
| 2820 | if (!Debugger::EventActive(v8::ScriptCollected)) return; |
| 2821 | |
| 2822 | // Enter the debugger. |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 2823 | EnterDebugger debugger(isolate_); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2824 | if (debugger.FailedToEnter()) return; |
| 2825 | |
| 2826 | // Create the script collected state object. |
machenbach@chromium.org | 2ebef18 | 2014-04-14 00:05:03 +0000 | [diff] [blame] | 2827 | Handle<Object> event_data; |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2828 | // Bail out and don't call debugger if exception. |
machenbach@chromium.org | e9fd658 | 2014-04-16 00:05:02 +0000 | [diff] [blame] | 2829 | if (!MakeScriptCollectedEvent(id).ToHandle(&event_data)) return; |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2830 | |
| 2831 | // Process debug event. |
| 2832 | ProcessDebugEvent(v8::ScriptCollected, |
| 2833 | Handle<JSObject>::cast(event_data), |
| 2834 | true); |
| 2835 | } |
| 2836 | |
| 2837 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2838 | void Debugger::ProcessDebugEvent(v8::DebugEvent event, |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 2839 | Handle<JSObject> event_data, |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2840 | bool auto_continue) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2841 | HandleScope scope(isolate_); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 2842 | |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 2843 | // Clear any pending debug break if this is a real break. |
| 2844 | if (!auto_continue) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2845 | isolate_->debug()->clear_interrupt_pending(DEBUGBREAK); |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 2846 | } |
| 2847 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2848 | // Create the execution state. |
machenbach@chromium.org | 2ebef18 | 2014-04-14 00:05:03 +0000 | [diff] [blame] | 2849 | Handle<Object> exec_state; |
| 2850 | // Bail out and don't call debugger if exception. |
machenbach@chromium.org | e9fd658 | 2014-04-16 00:05:02 +0000 | [diff] [blame] | 2851 | if (!MakeExecutionState().ToHandle(&exec_state)) return; |
| 2852 | |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 2853 | // First notify the message handler if any. |
| 2854 | if (message_handler_ != NULL) { |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 2855 | NotifyMessageHandler(event, |
| 2856 | Handle<JSObject>::cast(exec_state), |
| 2857 | event_data, |
| 2858 | auto_continue); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2859 | } |
mikhail.naganov@gmail.com | 2276287 | 2010-07-14 09:29:05 +0000 | [diff] [blame] | 2860 | // Notify registered debug event listener. This can be either a C or |
| 2861 | // a JavaScript function. Don't call event listener for v8::Break |
| 2862 | // here, if it's only a debug command -- they will be processed later. |
| 2863 | if ((event != v8::Break || !auto_continue) && !event_listener_.is_null()) { |
| 2864 | CallEventCallback(event, exec_state, event_data, NULL); |
| 2865 | } |
| 2866 | // Process pending debug commands. |
| 2867 | if (event == v8::Break) { |
| 2868 | while (!event_command_queue_.IsEmpty()) { |
| 2869 | CommandMessage command = event_command_queue_.Get(); |
| 2870 | if (!event_listener_.is_null()) { |
| 2871 | CallEventCallback(v8::BreakForCommand, |
| 2872 | exec_state, |
| 2873 | event_data, |
| 2874 | command.client_data()); |
| 2875 | } |
| 2876 | command.Dispose(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2877 | } |
| 2878 | } |
| 2879 | } |
| 2880 | |
| 2881 | |
mikhail.naganov@gmail.com | 2276287 | 2010-07-14 09:29:05 +0000 | [diff] [blame] | 2882 | void Debugger::CallEventCallback(v8::DebugEvent event, |
| 2883 | Handle<Object> exec_state, |
| 2884 | Handle<Object> event_data, |
| 2885 | v8::Debug::ClientData* client_data) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 2886 | if (event_listener_->IsForeign()) { |
mikhail.naganov@gmail.com | 2276287 | 2010-07-14 09:29:05 +0000 | [diff] [blame] | 2887 | CallCEventCallback(event, exec_state, event_data, client_data); |
| 2888 | } else { |
| 2889 | CallJSEventCallback(event, exec_state, event_data); |
| 2890 | } |
| 2891 | } |
| 2892 | |
| 2893 | |
| 2894 | void Debugger::CallCEventCallback(v8::DebugEvent event, |
| 2895 | Handle<Object> exec_state, |
| 2896 | Handle<Object> event_data, |
| 2897 | v8::Debug::ClientData* client_data) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 2898 | Handle<Foreign> callback_obj(Handle<Foreign>::cast(event_listener_)); |
mikhail.naganov@gmail.com | 2276287 | 2010-07-14 09:29:05 +0000 | [diff] [blame] | 2899 | v8::Debug::EventCallback2 callback = |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2900 | FUNCTION_CAST<v8::Debug::EventCallback2>( |
| 2901 | callback_obj->foreign_address()); |
mikhail.naganov@gmail.com | 2276287 | 2010-07-14 09:29:05 +0000 | [diff] [blame] | 2902 | EventDetailsImpl event_details( |
| 2903 | event, |
| 2904 | Handle<JSObject>::cast(exec_state), |
| 2905 | Handle<JSObject>::cast(event_data), |
| 2906 | event_listener_data_, |
| 2907 | client_data); |
| 2908 | callback(event_details); |
| 2909 | } |
| 2910 | |
| 2911 | |
| 2912 | void Debugger::CallJSEventCallback(v8::DebugEvent event, |
| 2913 | Handle<Object> exec_state, |
| 2914 | Handle<Object> event_data) { |
| 2915 | ASSERT(event_listener_->IsJSFunction()); |
| 2916 | Handle<JSFunction> fun(Handle<JSFunction>::cast(event_listener_)); |
| 2917 | |
| 2918 | // Invoke the JavaScript debug event listener. |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 2919 | Handle<Object> argv[] = { Handle<Object>(Smi::FromInt(event), isolate_), |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 2920 | exec_state, |
| 2921 | event_data, |
| 2922 | event_listener_data_ }; |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 2923 | Execution::TryCall(fun, |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2924 | isolate_->global_object(), |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 2925 | ARRAY_SIZE(argv), |
machenbach@chromium.org | 2ebef18 | 2014-04-14 00:05:03 +0000 | [diff] [blame] | 2926 | argv); |
mikhail.naganov@gmail.com | 2276287 | 2010-07-14 09:29:05 +0000 | [diff] [blame] | 2927 | // Silently ignore exceptions from debug event listeners. |
| 2928 | } |
| 2929 | |
| 2930 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 2931 | Handle<Context> Debugger::GetDebugContext() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2932 | never_unload_debugger_ = true; |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 2933 | EnterDebugger debugger(isolate_); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2934 | return isolate_->debug()->debug_context(); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 2935 | } |
| 2936 | |
| 2937 | |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 2938 | void Debugger::UnloadDebugger() { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2939 | Debug* debug = isolate_->debug(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2940 | |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 2941 | // Make sure that there are no breakpoints left. |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2942 | debug->ClearAllBreakPoints(); |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 2943 | |
| 2944 | // Unload the debugger if feasible. |
| 2945 | if (!never_unload_debugger_) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2946 | debug->Unload(); |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 2947 | } |
| 2948 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2949 | // Clear the flag indicating that the debugger should be unloaded. |
| 2950 | debugger_unload_pending_ = false; |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 2951 | } |
| 2952 | |
| 2953 | |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 2954 | void Debugger::NotifyMessageHandler(v8::DebugEvent event, |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 2955 | Handle<JSObject> exec_state, |
| 2956 | Handle<JSObject> event_data, |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 2957 | bool auto_continue) { |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 2958 | v8::Isolate* isolate = reinterpret_cast<v8::Isolate*>(isolate_); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2959 | HandleScope scope(isolate_); |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 2960 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2961 | if (!isolate_->debug()->Load()) return; |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 2962 | |
| 2963 | // Process the individual events. |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 2964 | bool sendEventMessage = false; |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 2965 | switch (event) { |
| 2966 | case v8::Break: |
mikhail.naganov@gmail.com | 2276287 | 2010-07-14 09:29:05 +0000 | [diff] [blame] | 2967 | case v8::BreakForCommand: |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 2968 | sendEventMessage = !auto_continue; |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 2969 | break; |
| 2970 | case v8::Exception: |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 2971 | sendEventMessage = true; |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 2972 | break; |
| 2973 | case v8::BeforeCompile: |
| 2974 | break; |
| 2975 | case v8::AfterCompile: |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 2976 | sendEventMessage = true; |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 2977 | break; |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2978 | case v8::ScriptCollected: |
| 2979 | sendEventMessage = true; |
| 2980 | break; |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 2981 | case v8::NewFunction: |
| 2982 | break; |
| 2983 | default: |
| 2984 | UNREACHABLE(); |
| 2985 | } |
| 2986 | |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 2987 | // The debug command interrupt flag might have been set when the command was |
| 2988 | // added. It should be enough to clear the flag only once while we are in the |
| 2989 | // debugger. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2990 | ASSERT(isolate_->debug()->InDebugger()); |
| 2991 | isolate_->stack_guard()->Continue(DEBUGCOMMAND); |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 2992 | |
| 2993 | // Notify the debugger that a debug event has occurred unless auto continue is |
| 2994 | // active in which case no event is send. |
| 2995 | if (sendEventMessage) { |
| 2996 | MessageImpl message = MessageImpl::NewEvent( |
| 2997 | event, |
| 2998 | auto_continue, |
| 2999 | Handle<JSObject>::cast(exec_state), |
| 3000 | Handle<JSObject>::cast(event_data)); |
| 3001 | InvokeMessageHandler(message); |
| 3002 | } |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 3003 | |
| 3004 | // If auto continue don't make the event cause a break, but process messages |
| 3005 | // in the queue if any. For script collected events don't even process |
| 3006 | // messages in the queue as the execution state might not be what is expected |
| 3007 | // by the client. |
ager@chromium.org | 6ffc217 | 2009-05-29 19:20:16 +0000 | [diff] [blame] | 3008 | if ((auto_continue && !HasCommands()) || event == v8::ScriptCollected) { |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 3009 | return; |
| 3010 | } |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 3011 | |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 3012 | v8::TryCatch try_catch; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 3013 | |
| 3014 | // DebugCommandProcessor goes here. |
| 3015 | v8::Local<v8::Object> cmd_processor; |
| 3016 | { |
| 3017 | v8::Local<v8::Object> api_exec_state = |
| 3018 | v8::Utils::ToLocal(Handle<JSObject>::cast(exec_state)); |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 3019 | v8::Local<v8::String> fun_name = v8::String::NewFromUtf8( |
| 3020 | isolate, "debugCommandProcessor"); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 3021 | v8::Local<v8::Function> fun = |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 3022 | v8::Local<v8::Function>::Cast(api_exec_state->Get(fun_name)); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 3023 | |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 3024 | v8::Handle<v8::Boolean> running = v8::Boolean::New(isolate, auto_continue); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 3025 | static const int kArgc = 1; |
| 3026 | v8::Handle<Value> argv[kArgc] = { running }; |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 3027 | cmd_processor = v8::Local<v8::Object>::Cast( |
| 3028 | fun->Call(api_exec_state, kArgc, argv)); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 3029 | if (try_catch.HasCaught()) { |
| 3030 | PrintLn(try_catch.Exception()); |
| 3031 | return; |
| 3032 | } |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 3033 | } |
| 3034 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 3035 | bool running = auto_continue; |
| 3036 | |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 3037 | // Process requests from the debugger. |
| 3038 | while (true) { |
| 3039 | // Wait for new command in the queue. |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 3040 | if (Debugger::host_dispatch_handler_) { |
| 3041 | // In case there is a host dispatch - do periodic dispatches. |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 3042 | if (!command_received_.WaitFor(host_dispatch_period_)) { |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 3043 | // Timout expired, do the dispatch. |
| 3044 | Debugger::host_dispatch_handler_(); |
| 3045 | continue; |
| 3046 | } |
| 3047 | } else { |
| 3048 | // In case there is no host dispatch - just wait. |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 3049 | command_received_.Wait(); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 3050 | } |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 3051 | |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 3052 | // Get the command from the queue. |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 3053 | CommandMessage command = command_queue_.Get(); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 3054 | isolate_->logger()->DebugTag( |
| 3055 | "Got request from command queue, in interactive loop."); |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 3056 | if (!Debugger::IsDebuggerActive()) { |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 3057 | // Delete command text and user data. |
| 3058 | command.Dispose(); |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 3059 | return; |
| 3060 | } |
| 3061 | |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 3062 | // Invoke JavaScript to process the debug request. |
| 3063 | v8::Local<v8::String> fun_name; |
| 3064 | v8::Local<v8::Function> fun; |
| 3065 | v8::Local<v8::Value> request; |
| 3066 | v8::TryCatch try_catch; |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 3067 | fun_name = v8::String::NewFromUtf8(isolate, "processDebugRequest"); |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 3068 | fun = v8::Local<v8::Function>::Cast(cmd_processor->Get(fun_name)); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 3069 | |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 3070 | request = v8::String::NewFromTwoByte(isolate, command.text().start(), |
| 3071 | v8::String::kNormalString, |
| 3072 | command.text().length()); |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 3073 | static const int kArgc = 1; |
| 3074 | v8::Handle<Value> argv[kArgc] = { request }; |
| 3075 | v8::Local<v8::Value> response_val = fun->Call(cmd_processor, kArgc, argv); |
| 3076 | |
| 3077 | // Get the response. |
| 3078 | v8::Local<v8::String> response; |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 3079 | if (!try_catch.HasCaught()) { |
| 3080 | // Get response string. |
| 3081 | if (!response_val->IsUndefined()) { |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 3082 | response = v8::Local<v8::String>::Cast(response_val); |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 3083 | } else { |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 3084 | response = v8::String::NewFromUtf8(isolate, ""); |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 3085 | } |
| 3086 | |
| 3087 | // Log the JSON request/response. |
| 3088 | if (FLAG_trace_debug_json) { |
| 3089 | PrintLn(request); |
| 3090 | PrintLn(response); |
| 3091 | } |
| 3092 | |
| 3093 | // Get the running state. |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 3094 | fun_name = v8::String::NewFromUtf8(isolate, "isRunning"); |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 3095 | fun = v8::Local<v8::Function>::Cast(cmd_processor->Get(fun_name)); |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 3096 | static const int kArgc = 1; |
| 3097 | v8::Handle<Value> argv[kArgc] = { response }; |
| 3098 | v8::Local<v8::Value> running_val = fun->Call(cmd_processor, kArgc, argv); |
| 3099 | if (!try_catch.HasCaught()) { |
| 3100 | running = running_val->ToBoolean()->Value(); |
| 3101 | } |
| 3102 | } else { |
| 3103 | // In case of failure the result text is the exception text. |
| 3104 | response = try_catch.Exception()->ToString(); |
| 3105 | } |
| 3106 | |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 3107 | // Return the result. |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 3108 | MessageImpl message = MessageImpl::NewResponse( |
| 3109 | event, |
| 3110 | running, |
| 3111 | Handle<JSObject>::cast(exec_state), |
| 3112 | Handle<JSObject>::cast(event_data), |
| 3113 | Handle<String>(Utils::OpenHandle(*response)), |
| 3114 | command.client_data()); |
| 3115 | InvokeMessageHandler(message); |
| 3116 | command.Dispose(); |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 3117 | |
| 3118 | // Return from debug event processing if either the VM is put into the |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3119 | // running state (through a continue command) or auto continue is active |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 3120 | // and there are no more commands queued. |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 3121 | if (running && !HasCommands()) { |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 3122 | return; |
| 3123 | } |
| 3124 | } |
| 3125 | } |
| 3126 | |
| 3127 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 3128 | void Debugger::SetEventListener(Handle<Object> callback, |
| 3129 | Handle<Object> data) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3130 | HandleScope scope(isolate_); |
| 3131 | GlobalHandles* global_handles = isolate_->global_handles(); |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 3132 | |
| 3133 | // Clear the global handles for the event listener and the event listener data |
| 3134 | // object. |
| 3135 | if (!event_listener_.is_null()) { |
hpayer@chromium.org | 4f99be9 | 2013-12-18 16:23:55 +0000 | [diff] [blame] | 3136 | GlobalHandles::Destroy( |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 3137 | reinterpret_cast<Object**>(event_listener_.location())); |
| 3138 | event_listener_ = Handle<Object>(); |
| 3139 | } |
| 3140 | if (!event_listener_data_.is_null()) { |
hpayer@chromium.org | 4f99be9 | 2013-12-18 16:23:55 +0000 | [diff] [blame] | 3141 | GlobalHandles::Destroy( |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 3142 | reinterpret_cast<Object**>(event_listener_data_.location())); |
| 3143 | event_listener_data_ = Handle<Object>(); |
| 3144 | } |
| 3145 | |
| 3146 | // If there is a new debug event listener register it together with its data |
| 3147 | // object. |
| 3148 | if (!callback->IsUndefined() && !callback->IsNull()) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3149 | event_listener_ = Handle<Object>::cast( |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3150 | global_handles->Create(*callback)); |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 3151 | if (data.is_null()) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3152 | data = isolate_->factory()->undefined_value(); |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 3153 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3154 | event_listener_data_ = Handle<Object>::cast( |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3155 | global_handles->Create(*data)); |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 3156 | } |
| 3157 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 3158 | ListenersChanged(); |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 3159 | } |
| 3160 | |
| 3161 | |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 3162 | void Debugger::SetMessageHandler(v8::Debug::MessageHandler2 handler) { |
jkummerow@chromium.org | dc94e19 | 2013-08-30 11:35:42 +0000 | [diff] [blame] | 3163 | LockGuard<RecursiveMutex> with(debugger_access_); |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 3164 | |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 3165 | message_handler_ = handler; |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 3166 | ListenersChanged(); |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 3167 | if (handler == NULL) { |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 3168 | // Send an empty command to the debugger if in a break to make JavaScript |
| 3169 | // run again if the debugger is closed. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3170 | if (isolate_->debug()->InDebugger()) { |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 3171 | ProcessCommand(Vector<const uint16_t>::empty()); |
| 3172 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3173 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3174 | } |
| 3175 | |
| 3176 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 3177 | void Debugger::ListenersChanged() { |
| 3178 | if (IsDebuggerActive()) { |
| 3179 | // Disable the compilation cache when the debugger is active. |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3180 | isolate_->compilation_cache()->Disable(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3181 | debugger_unload_pending_ = false; |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 3182 | } else { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3183 | isolate_->compilation_cache()->Enable(); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 3184 | // Unload the debugger if event listener and message handler cleared. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3185 | // Schedule this for later, because we may be in non-V8 thread. |
| 3186 | debugger_unload_pending_ = true; |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 3187 | } |
| 3188 | } |
| 3189 | |
| 3190 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 3191 | void Debugger::SetHostDispatchHandler(v8::Debug::HostDispatchHandler handler, |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 3192 | TimeDelta period) { |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 3193 | host_dispatch_handler_ = handler; |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 3194 | host_dispatch_period_ = period; |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 3195 | } |
| 3196 | |
| 3197 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 3198 | void Debugger::SetDebugMessageDispatchHandler( |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3199 | v8::Debug::DebugMessageDispatchHandler handler, bool provide_locker) { |
jkummerow@chromium.org | dc94e19 | 2013-08-30 11:35:42 +0000 | [diff] [blame] | 3200 | LockGuard<Mutex> lock_guard(&dispatch_handler_access_); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 3201 | debug_message_dispatch_handler_ = handler; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3202 | |
| 3203 | if (provide_locker && message_dispatch_helper_thread_ == NULL) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3204 | message_dispatch_helper_thread_ = new MessageDispatchHelperThread(isolate_); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3205 | message_dispatch_helper_thread_->Start(); |
| 3206 | } |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 3207 | } |
| 3208 | |
| 3209 | |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 3210 | // Calls the registered debug message handler. This callback is part of the |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 3211 | // public API. |
| 3212 | void Debugger::InvokeMessageHandler(MessageImpl message) { |
jkummerow@chromium.org | dc94e19 | 2013-08-30 11:35:42 +0000 | [diff] [blame] | 3213 | LockGuard<RecursiveMutex> with(debugger_access_); |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 3214 | |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 3215 | if (message_handler_ != NULL) { |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 3216 | message_handler_(message); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3217 | } |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 3218 | } |
| 3219 | |
| 3220 | |
| 3221 | // Puts a command coming from the public API on the queue. Creates |
| 3222 | // a copy of the command string managed by the debugger. Up to this |
| 3223 | // point, the command data was managed by the API client. Called |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 3224 | // by the API client thread. |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 3225 | void Debugger::ProcessCommand(Vector<const uint16_t> command, |
| 3226 | v8::Debug::ClientData* client_data) { |
| 3227 | // Need to cast away const. |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 3228 | CommandMessage message = CommandMessage::New( |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 3229 | Vector<uint16_t>(const_cast<uint16_t*>(command.start()), |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 3230 | command.length()), |
| 3231 | client_data); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 3232 | isolate_->logger()->DebugTag("Put command on command_queue."); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 3233 | command_queue_.Put(message); |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 3234 | command_received_.Signal(); |
sgjesse@chromium.org | 3afc158 | 2009-04-16 22:31:44 +0000 | [diff] [blame] | 3235 | |
| 3236 | // Set the debug command break flag to have the command processed. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3237 | if (!isolate_->debug()->InDebugger()) { |
| 3238 | isolate_->stack_guard()->DebugCommand(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3239 | } |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 3240 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3241 | MessageDispatchHelperThread* dispatch_thread; |
| 3242 | { |
jkummerow@chromium.org | dc94e19 | 2013-08-30 11:35:42 +0000 | [diff] [blame] | 3243 | LockGuard<Mutex> lock_guard(&dispatch_handler_access_); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3244 | dispatch_thread = message_dispatch_helper_thread_; |
| 3245 | } |
| 3246 | |
| 3247 | if (dispatch_thread == NULL) { |
| 3248 | CallMessageDispatchHandler(); |
| 3249 | } else { |
| 3250 | dispatch_thread->Schedule(); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 3251 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3252 | } |
| 3253 | |
| 3254 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3255 | bool Debugger::HasCommands() { |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 3256 | return !command_queue_.IsEmpty(); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3257 | } |
| 3258 | |
| 3259 | |
mikhail.naganov@gmail.com | 2276287 | 2010-07-14 09:29:05 +0000 | [diff] [blame] | 3260 | void Debugger::EnqueueDebugCommand(v8::Debug::ClientData* client_data) { |
| 3261 | CommandMessage message = CommandMessage::New(Vector<uint16_t>(), client_data); |
| 3262 | event_command_queue_.Put(message); |
| 3263 | |
| 3264 | // Set the debug command break flag to have the command processed. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3265 | if (!isolate_->debug()->InDebugger()) { |
| 3266 | isolate_->stack_guard()->DebugCommand(); |
mikhail.naganov@gmail.com | 2276287 | 2010-07-14 09:29:05 +0000 | [diff] [blame] | 3267 | } |
| 3268 | } |
| 3269 | |
| 3270 | |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 3271 | bool Debugger::IsDebuggerActive() { |
jkummerow@chromium.org | dc94e19 | 2013-08-30 11:35:42 +0000 | [diff] [blame] | 3272 | LockGuard<RecursiveMutex> with(debugger_access_); |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 3273 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3274 | return message_handler_ != NULL || |
| 3275 | !event_listener_.is_null() || |
| 3276 | force_debugger_active_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3277 | } |
| 3278 | |
| 3279 | |
machenbach@chromium.org | 2ebef18 | 2014-04-14 00:05:03 +0000 | [diff] [blame] | 3280 | MaybeHandle<Object> Debugger::Call(Handle<JSFunction> fun, |
| 3281 | Handle<Object> data) { |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 3282 | // When calling functions in the debugger prevent it from beeing unloaded. |
| 3283 | Debugger::never_unload_debugger_ = true; |
| 3284 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 3285 | // Enter the debugger. |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 3286 | EnterDebugger debugger(isolate_); |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 3287 | if (debugger.FailedToEnter()) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3288 | return isolate_->factory()->undefined_value(); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 3289 | } |
| 3290 | |
| 3291 | // Create the execution state. |
machenbach@chromium.org | 2ebef18 | 2014-04-14 00:05:03 +0000 | [diff] [blame] | 3292 | Handle<Object> exec_state; |
machenbach@chromium.org | e9fd658 | 2014-04-16 00:05:02 +0000 | [diff] [blame] | 3293 | if (!MakeExecutionState().ToHandle(&exec_state)) { |
| 3294 | return isolate_->factory()->undefined_value(); |
| 3295 | } |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 3296 | |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 3297 | Handle<Object> argv[] = { exec_state, data }; |
machenbach@chromium.org | 2ebef18 | 2014-04-14 00:05:03 +0000 | [diff] [blame] | 3298 | return Execution::Call( |
jkummerow@chromium.org | 2c9426b | 2013-09-05 16:31:13 +0000 | [diff] [blame] | 3299 | isolate_, |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 3300 | fun, |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 3301 | Handle<Object>(isolate_->debug()->debug_context_->global_proxy(), |
| 3302 | isolate_), |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 3303 | ARRAY_SIZE(argv), |
machenbach@chromium.org | 2ebef18 | 2014-04-14 00:05:03 +0000 | [diff] [blame] | 3304 | argv); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 3305 | } |
| 3306 | |
| 3307 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3308 | static void StubMessageHandler2(const v8::Debug::Message& message) { |
| 3309 | // Simply ignore message. |
| 3310 | } |
| 3311 | |
| 3312 | |
| 3313 | bool Debugger::StartAgent(const char* name, int port, |
| 3314 | bool wait_for_connection) { |
| 3315 | if (wait_for_connection) { |
| 3316 | // Suspend V8 if it is already running or set V8 to suspend whenever |
| 3317 | // it starts. |
| 3318 | // Provide stub message handler; V8 auto-continues each suspend |
| 3319 | // when there is no message handler; we doesn't need it. |
| 3320 | // Once become suspended, V8 will stay so indefinitely long, until remote |
| 3321 | // debugger connects and issues "continue" command. |
| 3322 | Debugger::message_handler_ = StubMessageHandler2; |
machenbach@chromium.org | e9fd658 | 2014-04-16 00:05:02 +0000 | [diff] [blame] | 3323 | v8::Debug::DebugBreak(reinterpret_cast<v8::Isolate*>(isolate_)); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3324 | } |
| 3325 | |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 3326 | if (agent_ == NULL) { |
| 3327 | agent_ = new DebuggerAgent(isolate_, name, port); |
| 3328 | agent_->Start(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3329 | } |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 3330 | return true; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3331 | } |
| 3332 | |
| 3333 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3334 | void Debugger::StopAgent() { |
| 3335 | if (agent_ != NULL) { |
| 3336 | agent_->Shutdown(); |
| 3337 | agent_->Join(); |
| 3338 | delete agent_; |
| 3339 | agent_ = NULL; |
| 3340 | } |
| 3341 | } |
| 3342 | |
| 3343 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3344 | void Debugger::WaitForAgent() { |
| 3345 | if (agent_ != NULL) |
| 3346 | agent_->WaitUntilListening(); |
| 3347 | } |
| 3348 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3349 | |
| 3350 | void Debugger::CallMessageDispatchHandler() { |
| 3351 | v8::Debug::DebugMessageDispatchHandler handler; |
| 3352 | { |
jkummerow@chromium.org | dc94e19 | 2013-08-30 11:35:42 +0000 | [diff] [blame] | 3353 | LockGuard<Mutex> lock_guard(&dispatch_handler_access_); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3354 | handler = Debugger::debug_message_dispatch_handler_; |
| 3355 | } |
| 3356 | if (handler != NULL) { |
| 3357 | handler(); |
| 3358 | } |
| 3359 | } |
| 3360 | |
| 3361 | |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 3362 | EnterDebugger::EnterDebugger(Isolate* isolate) |
| 3363 | : isolate_(isolate), |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3364 | prev_(isolate_->debug()->debugger_entry()), |
| 3365 | it_(isolate_), |
| 3366 | has_js_frames_(!it_.done()), |
| 3367 | save_(isolate_) { |
| 3368 | Debug* debug = isolate_->debug(); |
| 3369 | ASSERT(prev_ != NULL || !debug->is_interrupt_pending(PREEMPT)); |
| 3370 | ASSERT(prev_ != NULL || !debug->is_interrupt_pending(DEBUGBREAK)); |
| 3371 | |
| 3372 | // Link recursive debugger entry. |
| 3373 | debug->set_debugger_entry(this); |
| 3374 | |
| 3375 | // Store the previous break id and frame id. |
| 3376 | break_id_ = debug->break_id(); |
| 3377 | break_frame_id_ = debug->break_frame_id(); |
| 3378 | |
| 3379 | // Create the new break info. If there is no JavaScript frames there is no |
| 3380 | // break frame id. |
| 3381 | if (has_js_frames_) { |
| 3382 | debug->NewBreak(it_.frame()->id()); |
| 3383 | } else { |
| 3384 | debug->NewBreak(StackFrame::NO_ID); |
| 3385 | } |
| 3386 | |
| 3387 | // Make sure that debugger is loaded and enter the debugger context. |
| 3388 | load_failed_ = !debug->Load(); |
| 3389 | if (!load_failed_) { |
| 3390 | // NOTE the member variable save which saves the previous context before |
| 3391 | // this change. |
| 3392 | isolate_->set_context(*debug->debug_context()); |
| 3393 | } |
| 3394 | } |
| 3395 | |
| 3396 | |
| 3397 | EnterDebugger::~EnterDebugger() { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3398 | Debug* debug = isolate_->debug(); |
| 3399 | |
| 3400 | // Restore to the previous break state. |
| 3401 | debug->SetBreak(break_frame_id_, break_id_); |
| 3402 | |
| 3403 | // Check for leaving the debugger. |
fschneider@chromium.org | 7d10be5 | 2012-04-10 12:30:14 +0000 | [diff] [blame] | 3404 | if (!load_failed_ && prev_ == NULL) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3405 | // Clear mirror cache when leaving the debugger. Skip this if there is a |
| 3406 | // pending exception as clearing the mirror cache calls back into |
| 3407 | // JavaScript. This can happen if the v8::Debug::Call is used in which |
| 3408 | // case the exception should end up in the calling code. |
| 3409 | if (!isolate_->has_pending_exception()) { |
| 3410 | // Try to avoid any pending debug break breaking in the clear mirror |
| 3411 | // cache JavaScript code. |
| 3412 | if (isolate_->stack_guard()->IsDebugBreak()) { |
| 3413 | debug->set_interrupts_pending(DEBUGBREAK); |
| 3414 | isolate_->stack_guard()->Continue(DEBUGBREAK); |
| 3415 | } |
| 3416 | debug->ClearMirrorCache(); |
| 3417 | } |
| 3418 | |
| 3419 | // Request preemption and debug break when leaving the last debugger entry |
| 3420 | // if any of these where recorded while debugging. |
| 3421 | if (debug->is_interrupt_pending(PREEMPT)) { |
| 3422 | // This re-scheduling of preemption is to avoid starvation in some |
| 3423 | // debugging scenarios. |
| 3424 | debug->clear_interrupt_pending(PREEMPT); |
| 3425 | isolate_->stack_guard()->Preempt(); |
| 3426 | } |
| 3427 | if (debug->is_interrupt_pending(DEBUGBREAK)) { |
| 3428 | debug->clear_interrupt_pending(DEBUGBREAK); |
| 3429 | isolate_->stack_guard()->DebugBreak(); |
| 3430 | } |
| 3431 | |
| 3432 | // If there are commands in the queue when leaving the debugger request |
| 3433 | // that these commands are processed. |
| 3434 | if (isolate_->debugger()->HasCommands()) { |
| 3435 | isolate_->stack_guard()->DebugCommand(); |
| 3436 | } |
| 3437 | |
| 3438 | // If leaving the debugger with the debugger no longer active unload it. |
| 3439 | if (!isolate_->debugger()->IsDebuggerActive()) { |
| 3440 | isolate_->debugger()->UnloadDebugger(); |
| 3441 | } |
| 3442 | } |
| 3443 | |
| 3444 | // Leaving this debugger entry. |
| 3445 | debug->set_debugger_entry(prev_); |
| 3446 | } |
| 3447 | |
| 3448 | |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 3449 | MessageImpl MessageImpl::NewEvent(DebugEvent event, |
| 3450 | bool running, |
| 3451 | Handle<JSObject> exec_state, |
| 3452 | Handle<JSObject> event_data) { |
| 3453 | MessageImpl message(true, event, running, |
| 3454 | exec_state, event_data, Handle<String>(), NULL); |
| 3455 | return message; |
| 3456 | } |
| 3457 | |
| 3458 | |
| 3459 | MessageImpl MessageImpl::NewResponse(DebugEvent event, |
| 3460 | bool running, |
| 3461 | Handle<JSObject> exec_state, |
| 3462 | Handle<JSObject> event_data, |
| 3463 | Handle<String> response_json, |
| 3464 | v8::Debug::ClientData* client_data) { |
| 3465 | MessageImpl message(false, event, running, |
| 3466 | exec_state, event_data, response_json, client_data); |
| 3467 | return message; |
| 3468 | } |
| 3469 | |
| 3470 | |
| 3471 | MessageImpl::MessageImpl(bool is_event, |
| 3472 | DebugEvent event, |
| 3473 | bool running, |
| 3474 | Handle<JSObject> exec_state, |
| 3475 | Handle<JSObject> event_data, |
| 3476 | Handle<String> response_json, |
| 3477 | v8::Debug::ClientData* client_data) |
| 3478 | : is_event_(is_event), |
| 3479 | event_(event), |
| 3480 | running_(running), |
| 3481 | exec_state_(exec_state), |
| 3482 | event_data_(event_data), |
| 3483 | response_json_(response_json), |
| 3484 | client_data_(client_data) {} |
| 3485 | |
| 3486 | |
| 3487 | bool MessageImpl::IsEvent() const { |
| 3488 | return is_event_; |
| 3489 | } |
| 3490 | |
| 3491 | |
| 3492 | bool MessageImpl::IsResponse() const { |
| 3493 | return !is_event_; |
| 3494 | } |
| 3495 | |
| 3496 | |
| 3497 | DebugEvent MessageImpl::GetEvent() const { |
| 3498 | return event_; |
| 3499 | } |
| 3500 | |
| 3501 | |
| 3502 | bool MessageImpl::WillStartRunning() const { |
| 3503 | return running_; |
| 3504 | } |
| 3505 | |
| 3506 | |
| 3507 | v8::Handle<v8::Object> MessageImpl::GetExecutionState() const { |
| 3508 | return v8::Utils::ToLocal(exec_state_); |
| 3509 | } |
| 3510 | |
| 3511 | |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 3512 | v8::Isolate* MessageImpl::GetIsolate() const { |
| 3513 | return reinterpret_cast<v8::Isolate*>(exec_state_->GetIsolate()); |
| 3514 | } |
| 3515 | |
| 3516 | |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 3517 | v8::Handle<v8::Object> MessageImpl::GetEventData() const { |
| 3518 | return v8::Utils::ToLocal(event_data_); |
| 3519 | } |
| 3520 | |
| 3521 | |
| 3522 | v8::Handle<v8::String> MessageImpl::GetJSON() const { |
machenbach@chromium.org | 2ebef18 | 2014-04-14 00:05:03 +0000 | [diff] [blame] | 3523 | Isolate* isolate = event_data_->GetIsolate(); |
| 3524 | v8::EscapableHandleScope scope(reinterpret_cast<v8::Isolate*>(isolate)); |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 3525 | |
| 3526 | if (IsEvent()) { |
| 3527 | // Call toJSONProtocol on the debug event object. |
machenbach@chromium.org | 9fa6195 | 2014-04-17 00:05:12 +0000 | [diff] [blame] | 3528 | Handle<Object> fun = Object::GetProperty( |
| 3529 | isolate, event_data_, "toJSONProtocol").ToHandleChecked(); |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 3530 | if (!fun->IsJSFunction()) { |
| 3531 | return v8::Handle<v8::String>(); |
| 3532 | } |
machenbach@chromium.org | 2ebef18 | 2014-04-14 00:05:03 +0000 | [diff] [blame] | 3533 | |
| 3534 | MaybeHandle<Object> maybe_json = |
| 3535 | Execution::TryCall(Handle<JSFunction>::cast(fun), event_data_, 0, NULL); |
| 3536 | Handle<Object> json; |
| 3537 | if (!maybe_json.ToHandle(&json) || !json->IsString()) { |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 3538 | return v8::Handle<v8::String>(); |
| 3539 | } |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 3540 | return scope.Escape(v8::Utils::ToLocal(Handle<String>::cast(json))); |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 3541 | } else { |
| 3542 | return v8::Utils::ToLocal(response_json_); |
| 3543 | } |
| 3544 | } |
| 3545 | |
| 3546 | |
| 3547 | v8::Handle<v8::Context> MessageImpl::GetEventContext() const { |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 3548 | Isolate* isolate = event_data_->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3549 | v8::Handle<v8::Context> context = GetDebugEventContext(isolate); |
| 3550 | // Isolate::context() may be NULL when "script collected" event occures. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3551 | ASSERT(!context.IsEmpty() || event_ == v8::ScriptCollected); |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 3552 | return context; |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 3553 | } |
| 3554 | |
| 3555 | |
| 3556 | v8::Debug::ClientData* MessageImpl::GetClientData() const { |
| 3557 | return client_data_; |
| 3558 | } |
| 3559 | |
| 3560 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3561 | EventDetailsImpl::EventDetailsImpl(DebugEvent event, |
| 3562 | Handle<JSObject> exec_state, |
| 3563 | Handle<JSObject> event_data, |
mikhail.naganov@gmail.com | 2276287 | 2010-07-14 09:29:05 +0000 | [diff] [blame] | 3564 | Handle<Object> callback_data, |
| 3565 | v8::Debug::ClientData* client_data) |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3566 | : event_(event), |
| 3567 | exec_state_(exec_state), |
| 3568 | event_data_(event_data), |
mikhail.naganov@gmail.com | 2276287 | 2010-07-14 09:29:05 +0000 | [diff] [blame] | 3569 | callback_data_(callback_data), |
| 3570 | client_data_(client_data) {} |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3571 | |
| 3572 | |
| 3573 | DebugEvent EventDetailsImpl::GetEvent() const { |
| 3574 | return event_; |
| 3575 | } |
| 3576 | |
| 3577 | |
| 3578 | v8::Handle<v8::Object> EventDetailsImpl::GetExecutionState() const { |
| 3579 | return v8::Utils::ToLocal(exec_state_); |
| 3580 | } |
| 3581 | |
| 3582 | |
| 3583 | v8::Handle<v8::Object> EventDetailsImpl::GetEventData() const { |
| 3584 | return v8::Utils::ToLocal(event_data_); |
| 3585 | } |
| 3586 | |
| 3587 | |
| 3588 | v8::Handle<v8::Context> EventDetailsImpl::GetEventContext() const { |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 3589 | return GetDebugEventContext(exec_state_->GetIsolate()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3590 | } |
| 3591 | |
| 3592 | |
| 3593 | v8::Handle<v8::Value> EventDetailsImpl::GetCallbackData() const { |
| 3594 | return v8::Utils::ToLocal(callback_data_); |
| 3595 | } |
| 3596 | |
| 3597 | |
mikhail.naganov@gmail.com | 2276287 | 2010-07-14 09:29:05 +0000 | [diff] [blame] | 3598 | v8::Debug::ClientData* EventDetailsImpl::GetClientData() const { |
| 3599 | return client_data_; |
| 3600 | } |
| 3601 | |
| 3602 | |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 3603 | CommandMessage::CommandMessage() : text_(Vector<uint16_t>::empty()), |
| 3604 | client_data_(NULL) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3605 | } |
| 3606 | |
| 3607 | |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 3608 | CommandMessage::CommandMessage(const Vector<uint16_t>& text, |
| 3609 | v8::Debug::ClientData* data) |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 3610 | : text_(text), |
| 3611 | client_data_(data) { |
| 3612 | } |
| 3613 | |
| 3614 | |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 3615 | CommandMessage::~CommandMessage() { |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 3616 | } |
| 3617 | |
| 3618 | |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 3619 | void CommandMessage::Dispose() { |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 3620 | text_.Dispose(); |
| 3621 | delete client_data_; |
| 3622 | client_data_ = NULL; |
| 3623 | } |
| 3624 | |
| 3625 | |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 3626 | CommandMessage CommandMessage::New(const Vector<uint16_t>& command, |
| 3627 | v8::Debug::ClientData* data) { |
| 3628 | return CommandMessage(command.Clone(), data); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 3629 | } |
| 3630 | |
| 3631 | |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 3632 | CommandMessageQueue::CommandMessageQueue(int size) : start_(0), end_(0), |
| 3633 | size_(size) { |
| 3634 | messages_ = NewArray<CommandMessage>(size); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 3635 | } |
| 3636 | |
| 3637 | |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 3638 | CommandMessageQueue::~CommandMessageQueue() { |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 3639 | while (!IsEmpty()) { |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 3640 | CommandMessage m = Get(); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 3641 | m.Dispose(); |
| 3642 | } |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 3643 | DeleteArray(messages_); |
| 3644 | } |
| 3645 | |
| 3646 | |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 3647 | CommandMessage CommandMessageQueue::Get() { |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 3648 | ASSERT(!IsEmpty()); |
| 3649 | int result = start_; |
| 3650 | start_ = (start_ + 1) % size_; |
| 3651 | return messages_[result]; |
| 3652 | } |
| 3653 | |
| 3654 | |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 3655 | void CommandMessageQueue::Put(const CommandMessage& message) { |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 3656 | if ((end_ + 1) % size_ == start_) { |
| 3657 | Expand(); |
| 3658 | } |
| 3659 | messages_[end_] = message; |
| 3660 | end_ = (end_ + 1) % size_; |
| 3661 | } |
| 3662 | |
| 3663 | |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 3664 | void CommandMessageQueue::Expand() { |
| 3665 | CommandMessageQueue new_queue(size_ * 2); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 3666 | while (!IsEmpty()) { |
| 3667 | new_queue.Put(Get()); |
| 3668 | } |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 3669 | CommandMessage* array_to_free = messages_; |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 3670 | *this = new_queue; |
| 3671 | new_queue.messages_ = array_to_free; |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 3672 | // Make the new_queue empty so that it doesn't call Dispose on any messages. |
| 3673 | new_queue.start_ = new_queue.end_; |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 3674 | // Automatic destructor called on new_queue, freeing array_to_free. |
| 3675 | } |
| 3676 | |
| 3677 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 3678 | LockingCommandMessageQueue::LockingCommandMessageQueue(Logger* logger, int size) |
jkummerow@chromium.org | dc94e19 | 2013-08-30 11:35:42 +0000 | [diff] [blame] | 3679 | : logger_(logger), queue_(size) {} |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 3680 | |
| 3681 | |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 3682 | bool LockingCommandMessageQueue::IsEmpty() const { |
jkummerow@chromium.org | dc94e19 | 2013-08-30 11:35:42 +0000 | [diff] [blame] | 3683 | LockGuard<Mutex> lock_guard(&mutex_); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 3684 | return queue_.IsEmpty(); |
| 3685 | } |
| 3686 | |
| 3687 | |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 3688 | CommandMessage LockingCommandMessageQueue::Get() { |
jkummerow@chromium.org | dc94e19 | 2013-08-30 11:35:42 +0000 | [diff] [blame] | 3689 | LockGuard<Mutex> lock_guard(&mutex_); |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 3690 | CommandMessage result = queue_.Get(); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 3691 | logger_->DebugEvent("Get", result.text()); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 3692 | return result; |
| 3693 | } |
| 3694 | |
| 3695 | |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 3696 | void LockingCommandMessageQueue::Put(const CommandMessage& message) { |
jkummerow@chromium.org | dc94e19 | 2013-08-30 11:35:42 +0000 | [diff] [blame] | 3697 | LockGuard<Mutex> lock_guard(&mutex_); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 3698 | queue_.Put(message); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 3699 | logger_->DebugEvent("Put", message.text()); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 3700 | } |
| 3701 | |
| 3702 | |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 3703 | void LockingCommandMessageQueue::Clear() { |
jkummerow@chromium.org | dc94e19 | 2013-08-30 11:35:42 +0000 | [diff] [blame] | 3704 | LockGuard<Mutex> lock_guard(&mutex_); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 3705 | queue_.Clear(); |
| 3706 | } |
| 3707 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3708 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3709 | MessageDispatchHelperThread::MessageDispatchHelperThread(Isolate* isolate) |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 3710 | : Thread("v8:MsgDispHelpr"), |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 3711 | isolate_(isolate), sem_(0), |
jkummerow@chromium.org | dc94e19 | 2013-08-30 11:35:42 +0000 | [diff] [blame] | 3712 | already_signalled_(false) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3713 | } |
| 3714 | |
| 3715 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3716 | void MessageDispatchHelperThread::Schedule() { |
| 3717 | { |
jkummerow@chromium.org | dc94e19 | 2013-08-30 11:35:42 +0000 | [diff] [blame] | 3718 | LockGuard<Mutex> lock_guard(&mutex_); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3719 | if (already_signalled_) { |
| 3720 | return; |
| 3721 | } |
| 3722 | already_signalled_ = true; |
| 3723 | } |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 3724 | sem_.Signal(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3725 | } |
| 3726 | |
| 3727 | |
| 3728 | void MessageDispatchHelperThread::Run() { |
| 3729 | while (true) { |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 3730 | sem_.Wait(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3731 | { |
jkummerow@chromium.org | dc94e19 | 2013-08-30 11:35:42 +0000 | [diff] [blame] | 3732 | LockGuard<Mutex> lock_guard(&mutex_); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3733 | already_signalled_ = false; |
| 3734 | } |
| 3735 | { |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 3736 | Locker locker(reinterpret_cast<v8::Isolate*>(isolate_)); |
| 3737 | isolate_->debugger()->CallMessageDispatchHandler(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3738 | } |
| 3739 | } |
| 3740 | } |
| 3741 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 3742 | #endif // ENABLE_DEBUGGER_SUPPORT |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 3743 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3744 | } } // namespace v8::internal |