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