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); |
ulan@chromium.org | 19aca23 | 2013-12-30 09:24:30 +0000 | [diff] [blame^] | 2128 | Handle<Code> code = Compiler::GetCodeForDebugging(function); |
| 2129 | function->ReplaceCode(*code); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2130 | isolate_->debugger()->set_force_debugger_active( |
| 2131 | prev_force_debugger_active); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2132 | } |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2133 | |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 2134 | // Keep function code in sync with shared function info. |
| 2135 | function->set_code(shared->code()); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 2136 | } |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 2137 | |
| 2138 | RedirectActivationsToRecompiledCodeOnThread(isolate_, |
| 2139 | isolate_->thread_local_top()); |
| 2140 | |
| 2141 | ActiveFunctionsRedirector active_functions_redirector; |
| 2142 | isolate_->thread_manager()->IterateArchivedThreads( |
| 2143 | &active_functions_redirector); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2144 | } |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 2145 | } |
| 2146 | |
| 2147 | |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 2148 | Object* Debug::FindSharedFunctionInfoInScript(Handle<Script> script, |
| 2149 | int position) { |
| 2150 | // Iterate the heap looking for SharedFunctionInfo generated from the |
| 2151 | // script. The inner most SharedFunctionInfo containing the source position |
| 2152 | // for the requested break point is found. |
| 2153 | // NOTE: This might require several heap iterations. If the SharedFunctionInfo |
| 2154 | // which is found is not compiled it is compiled and the heap is iterated |
| 2155 | // again as the compilation might create inner functions from the newly |
| 2156 | // compiled function and the actual requested break point might be in one of |
| 2157 | // these functions. |
| 2158 | // NOTE: The below fix-point iteration depends on all functions that cannot be |
| 2159 | // compiled lazily without a context to not be compiled at all. Compilation |
| 2160 | // will be triggered at points where we do not need a context. |
| 2161 | bool done = false; |
| 2162 | // The current candidate for the source position: |
| 2163 | int target_start_position = RelocInfo::kNoPosition; |
| 2164 | Handle<JSFunction> target_function; |
| 2165 | Handle<SharedFunctionInfo> target; |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2166 | Heap* heap = isolate_->heap(); |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 2167 | while (!done) { |
| 2168 | { // Extra scope for iterator and no-allocation. |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2169 | heap->EnsureHeapIsIterable(); |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 2170 | DisallowHeapAllocation no_alloc_during_heap_iteration; |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2171 | HeapIterator iterator(heap); |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 2172 | for (HeapObject* obj = iterator.next(); |
| 2173 | obj != NULL; obj = iterator.next()) { |
| 2174 | bool found_next_candidate = false; |
| 2175 | Handle<JSFunction> function; |
| 2176 | Handle<SharedFunctionInfo> shared; |
| 2177 | if (obj->IsJSFunction()) { |
| 2178 | function = Handle<JSFunction>(JSFunction::cast(obj)); |
| 2179 | shared = Handle<SharedFunctionInfo>(function->shared()); |
| 2180 | ASSERT(shared->allows_lazy_compilation() || shared->is_compiled()); |
| 2181 | found_next_candidate = true; |
| 2182 | } else if (obj->IsSharedFunctionInfo()) { |
| 2183 | shared = Handle<SharedFunctionInfo>(SharedFunctionInfo::cast(obj)); |
| 2184 | // Skip functions that we cannot compile lazily without a context, |
| 2185 | // which is not available here, because there is no closure. |
| 2186 | found_next_candidate = shared->is_compiled() || |
| 2187 | shared->allows_lazy_compilation_without_context(); |
| 2188 | } |
| 2189 | if (!found_next_candidate) continue; |
| 2190 | if (shared->script() == *script) { |
| 2191 | // If the SharedFunctionInfo found has the requested script data and |
| 2192 | // contains the source position it is a candidate. |
| 2193 | int start_position = shared->function_token_position(); |
| 2194 | if (start_position == RelocInfo::kNoPosition) { |
| 2195 | start_position = shared->start_position(); |
| 2196 | } |
| 2197 | if (start_position <= position && |
| 2198 | position <= shared->end_position()) { |
| 2199 | // If there is no candidate or this function is within the current |
| 2200 | // candidate this is the new candidate. |
| 2201 | if (target.is_null()) { |
| 2202 | target_start_position = start_position; |
| 2203 | target_function = function; |
| 2204 | target = shared; |
| 2205 | } else { |
| 2206 | if (target_start_position == start_position && |
| 2207 | shared->end_position() == target->end_position()) { |
| 2208 | // If a top-level function contains only one function |
| 2209 | // declaration the source for the top-level and the function |
| 2210 | // is the same. In that case prefer the non top-level function. |
| 2211 | if (!shared->is_toplevel()) { |
| 2212 | target_start_position = start_position; |
| 2213 | target_function = function; |
| 2214 | target = shared; |
| 2215 | } |
| 2216 | } else if (target_start_position <= start_position && |
| 2217 | shared->end_position() <= target->end_position()) { |
| 2218 | // This containment check includes equality as a function |
| 2219 | // inside a top-level function can share either start or end |
| 2220 | // position with the top-level function. |
| 2221 | target_start_position = start_position; |
| 2222 | target_function = function; |
| 2223 | target = shared; |
| 2224 | } |
| 2225 | } |
| 2226 | } |
| 2227 | } |
| 2228 | } // End for loop. |
| 2229 | } // End no-allocation scope. |
| 2230 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2231 | if (target.is_null()) return heap->undefined_value(); |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 2232 | |
| 2233 | // There will be at least one break point when we are done. |
| 2234 | has_break_points_ = true; |
| 2235 | |
| 2236 | // If the candidate found is compiled we are done. |
| 2237 | done = target->is_compiled(); |
| 2238 | if (!done) { |
| 2239 | // If the candidate is not compiled, compile it to reveal any inner |
| 2240 | // functions which might contain the requested source position. This |
| 2241 | // will compile all inner functions that cannot be compiled without a |
| 2242 | // context, because Compiler::BuildFunctionInfo checks whether the |
| 2243 | // debugger is active. |
yangguo@chromium.org | 4954674 | 2013-12-23 16:17:49 +0000 | [diff] [blame] | 2244 | Handle<Code> result = target_function.is_null() |
| 2245 | ? Compiler::GetUnoptimizedCode(target) |
| 2246 | : Compiler::GetUnoptimizedCode(target_function); |
| 2247 | if (result.is_null()) return isolate_->heap()->undefined_value(); |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 2248 | } |
| 2249 | } // End while loop. |
| 2250 | |
| 2251 | return *target; |
| 2252 | } |
| 2253 | |
| 2254 | |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 2255 | // Ensures the debug information is present for shared. |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 2256 | bool Debug::EnsureDebugInfo(Handle<SharedFunctionInfo> shared, |
| 2257 | Handle<JSFunction> function) { |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 2258 | Isolate* isolate = shared->GetIsolate(); |
| 2259 | |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 2260 | // Return if we already have the debug info for shared. |
| 2261 | if (HasDebugInfo(shared)) { |
| 2262 | ASSERT(shared->is_compiled()); |
| 2263 | return true; |
| 2264 | } |
| 2265 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 2266 | // There will be at least one break point when we are done. |
| 2267 | has_break_points_ = true; |
| 2268 | |
| 2269 | // Ensure function is compiled. Return false if this failed. |
| 2270 | if (!function.is_null() && |
yangguo@chromium.org | 4954674 | 2013-12-23 16:17:49 +0000 | [diff] [blame] | 2271 | !Compiler::EnsureCompiled(function, CLEAR_EXCEPTION)) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2272 | return false; |
| 2273 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2274 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2275 | // Create the debug info object. |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 2276 | Handle<DebugInfo> debug_info = isolate->factory()->NewDebugInfo(shared); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2277 | |
| 2278 | // Add debug info to the list. |
| 2279 | DebugInfoListNode* node = new DebugInfoListNode(*debug_info); |
| 2280 | node->set_next(debug_info_list_); |
| 2281 | debug_info_list_ = node; |
| 2282 | |
kasper.lund | bd3ec4e | 2008-07-09 11:06:54 +0000 | [diff] [blame] | 2283 | return true; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2284 | } |
| 2285 | |
| 2286 | |
| 2287 | void Debug::RemoveDebugInfo(Handle<DebugInfo> debug_info) { |
| 2288 | ASSERT(debug_info_list_ != NULL); |
| 2289 | // Run through the debug info objects to find this one and remove it. |
| 2290 | DebugInfoListNode* prev = NULL; |
| 2291 | DebugInfoListNode* current = debug_info_list_; |
| 2292 | while (current != NULL) { |
| 2293 | if (*current->debug_info() == *debug_info) { |
| 2294 | // Unlink from list. If prev is NULL we are looking at the first element. |
| 2295 | if (prev == NULL) { |
| 2296 | debug_info_list_ = current->next(); |
| 2297 | } else { |
| 2298 | prev->set_next(current->next()); |
| 2299 | } |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2300 | current->debug_info()->shared()->set_debug_info( |
| 2301 | isolate_->heap()->undefined_value()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2302 | delete current; |
| 2303 | |
| 2304 | // If there are no more debug info objects there are not more break |
| 2305 | // points. |
| 2306 | has_break_points_ = debug_info_list_ != NULL; |
| 2307 | |
| 2308 | return; |
| 2309 | } |
| 2310 | // Move to next in list. |
| 2311 | prev = current; |
| 2312 | current = current->next(); |
| 2313 | } |
| 2314 | UNREACHABLE(); |
| 2315 | } |
| 2316 | |
| 2317 | |
| 2318 | void Debug::SetAfterBreakTarget(JavaScriptFrame* frame) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2319 | HandleScope scope(isolate_); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 2320 | |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 2321 | PrepareForBreakPoints(); |
| 2322 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2323 | // Get the executing function in which the debug break occurred. |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 2324 | Handle<JSFunction> function(JSFunction::cast(frame->function())); |
| 2325 | Handle<SharedFunctionInfo> shared(function->shared()); |
| 2326 | if (!EnsureDebugInfo(shared, function)) { |
kasper.lund | bd3ec4e | 2008-07-09 11:06:54 +0000 | [diff] [blame] | 2327 | // Return if we failed to retrieve the debug info. |
| 2328 | return; |
| 2329 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2330 | Handle<DebugInfo> debug_info = GetDebugInfo(shared); |
| 2331 | Handle<Code> code(debug_info->code()); |
| 2332 | Handle<Code> original_code(debug_info->original_code()); |
| 2333 | #ifdef DEBUG |
| 2334 | // Get the code which is actually executing. |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 2335 | Handle<Code> frame_code(frame->LookupCode()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2336 | ASSERT(frame_code.is_identical_to(code)); |
| 2337 | #endif |
| 2338 | |
| 2339 | // Find the call address in the running code. This address holds the call to |
| 2340 | // either a DebugBreakXXX or to the debug break return entry code if the |
| 2341 | // break point is still active after processing the break point. |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 2342 | Address addr = frame->pc() - Assembler::kPatchDebugBreakSlotReturnOffset; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2343 | |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 2344 | // 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] | 2345 | bool at_js_return = false; |
| 2346 | bool break_at_js_return_active = false; |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 2347 | bool at_debug_break_slot = false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2348 | RelocIterator it(debug_info->code()); |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 2349 | while (!it.done() && !at_js_return && !at_debug_break_slot) { |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 2350 | if (RelocInfo::IsJSReturn(it.rinfo()->rmode())) { |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 2351 | at_js_return = (it.rinfo()->pc() == |
| 2352 | addr - Assembler::kPatchReturnSequenceAddressOffset); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2353 | break_at_js_return_active = it.rinfo()->IsPatchedReturnSequence(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2354 | } |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 2355 | if (RelocInfo::IsDebugBreakSlot(it.rinfo()->rmode())) { |
| 2356 | at_debug_break_slot = (it.rinfo()->pc() == |
| 2357 | addr - Assembler::kPatchDebugBreakSlotAddressOffset); |
| 2358 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2359 | it.next(); |
| 2360 | } |
| 2361 | |
| 2362 | // Handle the jump to continue execution after break point depending on the |
| 2363 | // break location. |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 2364 | if (at_js_return) { |
| 2365 | // If the break point as return is still active jump to the corresponding |
| 2366 | // place in the original code. If not the break point was removed during |
| 2367 | // break point processing. |
| 2368 | if (break_at_js_return_active) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2369 | addr += original_code->instruction_start() - code->instruction_start(); |
| 2370 | } |
| 2371 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 2372 | // Move back to where the call instruction sequence started. |
| 2373 | thread_local_.after_break_target_ = |
| 2374 | addr - Assembler::kPatchReturnSequenceAddressOffset; |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 2375 | } else if (at_debug_break_slot) { |
| 2376 | // Address of where the debug break slot starts. |
| 2377 | addr = addr - Assembler::kPatchDebugBreakSlotAddressOffset; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2378 | |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 2379 | // Continue just after the slot. |
| 2380 | thread_local_.after_break_target_ = addr + Assembler::kDebugBreakSlotLength; |
| 2381 | } else if (IsDebugBreak(Assembler::target_address_at(addr))) { |
| 2382 | // We now know that there is still a debug break call at the target address, |
| 2383 | // so the break point is still there and the original code will hold the |
| 2384 | // address to jump to in order to complete the call which is replaced by a |
| 2385 | // call to DebugBreakXXX. |
| 2386 | |
| 2387 | // Find the corresponding address in the original code. |
| 2388 | addr += original_code->instruction_start() - code->instruction_start(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2389 | |
| 2390 | // Install jump to the call address in the original code. This will be the |
| 2391 | // call which was overwritten by the call to DebugBreakXXX. |
| 2392 | thread_local_.after_break_target_ = Assembler::target_address_at(addr); |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 2393 | } else { |
| 2394 | // There is no longer a break point present. Don't try to look in the |
| 2395 | // original code as the running code will have the right address. This takes |
| 2396 | // care of the case where the last break point is removed from the function |
| 2397 | // and therefore no "original code" is available. |
| 2398 | thread_local_.after_break_target_ = Assembler::target_address_at(addr); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2399 | } |
| 2400 | } |
| 2401 | |
| 2402 | |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 2403 | bool Debug::IsBreakAtReturn(JavaScriptFrame* frame) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2404 | HandleScope scope(isolate_); |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 2405 | |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 2406 | // If there are no break points this cannot be break at return, as |
| 2407 | // the debugger statement and stack guard bebug break cannot be at |
| 2408 | // return. |
| 2409 | if (!has_break_points_) { |
| 2410 | return false; |
| 2411 | } |
| 2412 | |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 2413 | PrepareForBreakPoints(); |
| 2414 | |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 2415 | // Get the executing function in which the debug break occurred. |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 2416 | Handle<JSFunction> function(JSFunction::cast(frame->function())); |
| 2417 | Handle<SharedFunctionInfo> shared(function->shared()); |
| 2418 | if (!EnsureDebugInfo(shared, function)) { |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 2419 | // Return if we failed to retrieve the debug info. |
| 2420 | return false; |
| 2421 | } |
| 2422 | Handle<DebugInfo> debug_info = GetDebugInfo(shared); |
| 2423 | Handle<Code> code(debug_info->code()); |
| 2424 | #ifdef DEBUG |
| 2425 | // Get the code which is actually executing. |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 2426 | Handle<Code> frame_code(frame->LookupCode()); |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 2427 | ASSERT(frame_code.is_identical_to(code)); |
| 2428 | #endif |
| 2429 | |
| 2430 | // Find the call address in the running code. |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 2431 | Address addr = frame->pc() - Assembler::kPatchDebugBreakSlotReturnOffset; |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 2432 | |
| 2433 | // Check if the location is at JS return. |
| 2434 | RelocIterator it(debug_info->code()); |
| 2435 | while (!it.done()) { |
| 2436 | if (RelocInfo::IsJSReturn(it.rinfo()->rmode())) { |
| 2437 | return (it.rinfo()->pc() == |
| 2438 | addr - Assembler::kPatchReturnSequenceAddressOffset); |
| 2439 | } |
| 2440 | it.next(); |
| 2441 | } |
| 2442 | return false; |
| 2443 | } |
| 2444 | |
| 2445 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 2446 | void Debug::FramesHaveBeenDropped(StackFrame::Id new_break_frame_id, |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 2447 | FrameDropMode mode, |
| 2448 | Object** restarter_frame_function_pointer) { |
ulan@chromium.org | d9e468a | 2012-06-25 09:47:40 +0000 | [diff] [blame] | 2449 | if (mode != CURRENTLY_SET_MODE) { |
| 2450 | thread_local_.frame_drop_mode_ = mode; |
| 2451 | } |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 2452 | thread_local_.break_frame_id_ = new_break_frame_id; |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 2453 | thread_local_.restarter_frame_function_pointer_ = |
| 2454 | restarter_frame_function_pointer; |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 2455 | } |
| 2456 | |
| 2457 | |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 2458 | const int Debug::FramePaddingLayout::kInitialSize = 1; |
| 2459 | |
| 2460 | |
| 2461 | // Any even value bigger than kInitialSize as needed for stack scanning. |
| 2462 | const int Debug::FramePaddingLayout::kPaddingValue = kInitialSize + 1; |
| 2463 | |
| 2464 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2465 | bool Debug::IsDebugGlobal(GlobalObject* global) { |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2466 | return IsLoaded() && global == debug_context()->global_object(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2467 | } |
| 2468 | |
| 2469 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2470 | void Debug::ClearMirrorCache() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2471 | PostponeInterruptsScope postpone(isolate_); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2472 | HandleScope scope(isolate_); |
| 2473 | ASSERT(isolate_->context() == *Debug::debug_context()); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2474 | |
| 2475 | // Clear the mirror cache. |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2476 | Handle<String> function_name = isolate_->factory()->InternalizeOneByteString( |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2477 | STATIC_ASCII_VECTOR("ClearMirrorCache")); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2478 | Handle<Object> fun( |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 2479 | isolate_->global_object()->GetPropertyNoExceptionThrown(*function_name), |
| 2480 | isolate_); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2481 | ASSERT(fun->IsJSFunction()); |
| 2482 | bool caught_exception; |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 2483 | Execution::TryCall(Handle<JSFunction>::cast(fun), |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2484 | Handle<JSObject>(Debug::debug_context()->global_object()), |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2485 | 0, NULL, &caught_exception); |
| 2486 | } |
| 2487 | |
| 2488 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2489 | void Debug::CreateScriptCache() { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2490 | Heap* heap = isolate_->heap(); |
| 2491 | HandleScope scope(isolate_); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2492 | |
| 2493 | // Perform two GCs to get rid of all unreferenced scripts. The first GC gets |
| 2494 | // 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] | 2495 | // scripts which are no longer referenced. The second also sweeps precisely, |
| 2496 | // 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] | 2497 | heap->CollectAllGarbage(Heap::kNoGCFlags, "Debug::CreateScriptCache"); |
| 2498 | heap->CollectAllGarbage(Heap::kMakeHeapIterableMask, |
| 2499 | "Debug::CreateScriptCache"); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2500 | |
| 2501 | ASSERT(script_cache_ == NULL); |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 2502 | script_cache_ = new ScriptCache(isolate_); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2503 | |
| 2504 | // Scan heap for Script objects. |
| 2505 | int count = 0; |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2506 | HeapIterator iterator(heap); |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 2507 | DisallowHeapAllocation no_allocation; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2508 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2509 | for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) { |
sgjesse@chromium.org | 152a0b0 | 2009-10-07 13:50:16 +0000 | [diff] [blame] | 2510 | if (obj->IsScript() && Script::cast(obj)->HasValidSource()) { |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2511 | script_cache_->Add(Handle<Script>(Script::cast(obj))); |
| 2512 | count++; |
| 2513 | } |
| 2514 | } |
| 2515 | } |
| 2516 | |
| 2517 | |
| 2518 | void Debug::DestroyScriptCache() { |
| 2519 | // Get rid of the script cache if it was created. |
| 2520 | if (script_cache_ != NULL) { |
| 2521 | delete script_cache_; |
| 2522 | script_cache_ = NULL; |
| 2523 | } |
| 2524 | } |
| 2525 | |
| 2526 | |
| 2527 | void Debug::AddScriptToScriptCache(Handle<Script> script) { |
| 2528 | if (script_cache_ != NULL) { |
| 2529 | script_cache_->Add(script); |
| 2530 | } |
| 2531 | } |
| 2532 | |
| 2533 | |
| 2534 | Handle<FixedArray> Debug::GetLoadedScripts() { |
| 2535 | // Create and fill the script cache when the loaded scripts is requested for |
| 2536 | // the first time. |
| 2537 | if (script_cache_ == NULL) { |
| 2538 | CreateScriptCache(); |
| 2539 | } |
| 2540 | |
| 2541 | // If the script cache is not active just return an empty array. |
| 2542 | ASSERT(script_cache_ != NULL); |
| 2543 | if (script_cache_ == NULL) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2544 | isolate_->factory()->NewFixedArray(0); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2545 | } |
| 2546 | |
| 2547 | // Perform GC to get unreferenced scripts evicted from the cache before |
| 2548 | // returning the content. |
rossberg@chromium.org | 994edf6 | 2012-02-06 10:12:55 +0000 | [diff] [blame] | 2549 | isolate_->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
| 2550 | "Debug::GetLoadedScripts"); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2551 | |
| 2552 | // Get the scripts from the cache. |
| 2553 | return script_cache_->GetScripts(); |
| 2554 | } |
| 2555 | |
| 2556 | |
yangguo@chromium.org | 4954674 | 2013-12-23 16:17:49 +0000 | [diff] [blame] | 2557 | void Debug::RecordEvalCaller(Handle<Script> script) { |
| 2558 | script->set_compilation_type(Script::COMPILATION_TYPE_EVAL); |
| 2559 | // For eval scripts add information on the function from which eval was |
| 2560 | // called. |
| 2561 | StackTraceFrameIterator it(script->GetIsolate()); |
| 2562 | if (!it.done()) { |
| 2563 | script->set_eval_from_shared(it.frame()->function()->shared()); |
| 2564 | Code* code = it.frame()->LookupCode(); |
| 2565 | int offset = static_cast<int>( |
| 2566 | it.frame()->pc() - code->instruction_start()); |
| 2567 | script->set_eval_from_instructions_offset(Smi::FromInt(offset)); |
| 2568 | } |
| 2569 | } |
| 2570 | |
| 2571 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2572 | void Debug::AfterGarbageCollection() { |
| 2573 | // Generate events for collected scripts. |
| 2574 | if (script_cache_ != NULL) { |
| 2575 | script_cache_->ProcessCollectedScripts(); |
| 2576 | } |
| 2577 | } |
| 2578 | |
| 2579 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2580 | Debugger::Debugger(Isolate* isolate) |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2581 | : debugger_access_(isolate->debugger_access()), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2582 | event_listener_(Handle<Object>()), |
| 2583 | event_listener_data_(Handle<Object>()), |
| 2584 | compiling_natives_(false), |
| 2585 | is_loading_debugger_(false), |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 2586 | live_edit_enabled_(true), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2587 | never_unload_debugger_(false), |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2588 | force_debugger_active_(false), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2589 | message_handler_(NULL), |
| 2590 | debugger_unload_pending_(false), |
| 2591 | host_dispatch_handler_(NULL), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2592 | debug_message_dispatch_handler_(NULL), |
| 2593 | message_dispatch_helper_thread_(NULL), |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 2594 | host_dispatch_period_(TimeDelta::FromMilliseconds(100)), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2595 | agent_(NULL), |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2596 | command_queue_(isolate->logger(), kQueueInitialSize), |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 2597 | command_received_(0), |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2598 | event_command_queue_(isolate->logger(), kQueueInitialSize), |
| 2599 | isolate_(isolate) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2600 | } |
| 2601 | |
| 2602 | |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 2603 | Debugger::~Debugger() {} |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2604 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2605 | |
| 2606 | Handle<Object> Debugger::MakeJSObject(Vector<const char> constructor_name, |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 2607 | int argc, |
| 2608 | Handle<Object> argv[], |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2609 | bool* caught_exception) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2610 | ASSERT(isolate_->context() == *isolate_->debug()->debug_context()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2611 | |
| 2612 | // Create the execution state object. |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2613 | Handle<String> constructor_str = |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2614 | isolate_->factory()->InternalizeUtf8String(constructor_name); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2615 | Handle<Object> constructor( |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 2616 | isolate_->global_object()->GetPropertyNoExceptionThrown(*constructor_str), |
| 2617 | isolate_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2618 | ASSERT(constructor->IsJSFunction()); |
| 2619 | if (!constructor->IsJSFunction()) { |
| 2620 | *caught_exception = true; |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2621 | return isolate_->factory()->undefined_value(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2622 | } |
| 2623 | Handle<Object> js_object = Execution::TryCall( |
| 2624 | Handle<JSFunction>::cast(constructor), |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2625 | Handle<JSObject>(isolate_->debug()->debug_context()->global_object()), |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 2626 | argc, |
| 2627 | argv, |
| 2628 | caught_exception); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2629 | return js_object; |
| 2630 | } |
| 2631 | |
| 2632 | |
| 2633 | Handle<Object> Debugger::MakeExecutionState(bool* caught_exception) { |
| 2634 | // Create the execution state object. |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2635 | Handle<Object> break_id = isolate_->factory()->NewNumberFromInt( |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2636 | isolate_->debug()->break_id()); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 2637 | Handle<Object> argv[] = { break_id }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2638 | return MakeJSObject(CStrVector("MakeExecutionState"), |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 2639 | ARRAY_SIZE(argv), |
| 2640 | argv, |
| 2641 | caught_exception); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2642 | } |
| 2643 | |
| 2644 | |
| 2645 | Handle<Object> Debugger::MakeBreakEvent(Handle<Object> exec_state, |
| 2646 | Handle<Object> break_points_hit, |
| 2647 | bool* caught_exception) { |
| 2648 | // Create the new break event object. |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 2649 | Handle<Object> argv[] = { exec_state, break_points_hit }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2650 | return MakeJSObject(CStrVector("MakeBreakEvent"), |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 2651 | ARRAY_SIZE(argv), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2652 | argv, |
| 2653 | caught_exception); |
| 2654 | } |
| 2655 | |
| 2656 | |
| 2657 | Handle<Object> Debugger::MakeExceptionEvent(Handle<Object> exec_state, |
| 2658 | Handle<Object> exception, |
| 2659 | bool uncaught, |
| 2660 | bool* caught_exception) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2661 | Factory* factory = isolate_->factory(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2662 | // Create the new exception event object. |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 2663 | Handle<Object> argv[] = { exec_state, |
| 2664 | exception, |
| 2665 | factory->ToBoolean(uncaught) }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2666 | return MakeJSObject(CStrVector("MakeExceptionEvent"), |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 2667 | ARRAY_SIZE(argv), |
| 2668 | argv, |
| 2669 | caught_exception); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2670 | } |
| 2671 | |
| 2672 | |
| 2673 | Handle<Object> Debugger::MakeNewFunctionEvent(Handle<Object> function, |
| 2674 | bool* caught_exception) { |
| 2675 | // Create the new function event object. |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 2676 | Handle<Object> argv[] = { function }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2677 | return MakeJSObject(CStrVector("MakeNewFunctionEvent"), |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 2678 | ARRAY_SIZE(argv), |
| 2679 | argv, |
| 2680 | caught_exception); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2681 | } |
| 2682 | |
| 2683 | |
| 2684 | Handle<Object> Debugger::MakeCompileEvent(Handle<Script> script, |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 2685 | bool before, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2686 | bool* caught_exception) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2687 | Factory* factory = isolate_->factory(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2688 | // Create the compile event object. |
| 2689 | Handle<Object> exec_state = MakeExecutionState(caught_exception); |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 2690 | Handle<Object> script_wrapper = GetScriptWrapper(script); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 2691 | Handle<Object> argv[] = { exec_state, |
| 2692 | script_wrapper, |
| 2693 | factory->ToBoolean(before) }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2694 | return MakeJSObject(CStrVector("MakeCompileEvent"), |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 2695 | ARRAY_SIZE(argv), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2696 | argv, |
| 2697 | caught_exception); |
| 2698 | } |
| 2699 | |
| 2700 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2701 | Handle<Object> Debugger::MakeScriptCollectedEvent(int id, |
| 2702 | bool* caught_exception) { |
| 2703 | // Create the script collected event object. |
| 2704 | Handle<Object> exec_state = MakeExecutionState(caught_exception); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 2705 | Handle<Object> id_object = Handle<Smi>(Smi::FromInt(id), isolate_); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 2706 | Handle<Object> argv[] = { exec_state, id_object }; |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2707 | |
| 2708 | return MakeJSObject(CStrVector("MakeScriptCollectedEvent"), |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 2709 | ARRAY_SIZE(argv), |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2710 | argv, |
| 2711 | caught_exception); |
| 2712 | } |
| 2713 | |
| 2714 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2715 | void Debugger::OnException(Handle<Object> exception, bool uncaught) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2716 | HandleScope scope(isolate_); |
| 2717 | Debug* debug = isolate_->debug(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2718 | |
| 2719 | // 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] | 2720 | if (debug->InDebugger()) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2721 | if (!Debugger::EventActive(v8::Exception)) return; |
| 2722 | |
| 2723 | // Bail out if exception breaks are not active |
| 2724 | if (uncaught) { |
| 2725 | // Uncaught exceptions are reported by either flags. |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2726 | if (!(debug->break_on_uncaught_exception() || |
| 2727 | debug->break_on_exception())) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2728 | } else { |
| 2729 | // Caught exceptions are reported is activated. |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2730 | if (!debug->break_on_exception()) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2731 | } |
| 2732 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 2733 | // Enter the debugger. |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 2734 | EnterDebugger debugger(isolate_); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 2735 | if (debugger.FailedToEnter()) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2736 | |
| 2737 | // Clear all current stepping setup. |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2738 | debug->ClearStepping(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2739 | // Create the event data object. |
| 2740 | bool caught_exception = false; |
| 2741 | Handle<Object> exec_state = MakeExecutionState(&caught_exception); |
| 2742 | Handle<Object> event_data; |
| 2743 | if (!caught_exception) { |
| 2744 | event_data = MakeExceptionEvent(exec_state, exception, uncaught, |
| 2745 | &caught_exception); |
| 2746 | } |
| 2747 | // Bail out and don't call debugger if exception. |
| 2748 | if (caught_exception) { |
| 2749 | return; |
| 2750 | } |
| 2751 | |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 2752 | // Process debug event. |
| 2753 | ProcessDebugEvent(v8::Exception, Handle<JSObject>::cast(event_data), false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2754 | // Return to continue execution from where the exception was thrown. |
| 2755 | } |
| 2756 | |
| 2757 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2758 | void Debugger::OnDebugBreak(Handle<Object> break_points_hit, |
| 2759 | bool auto_continue) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2760 | HandleScope scope(isolate_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2761 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 2762 | // Debugger has already been entered by caller. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2763 | ASSERT(isolate_->context() == *isolate_->debug()->debug_context()); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 2764 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2765 | // Bail out if there is no listener for this event |
| 2766 | if (!Debugger::EventActive(v8::Break)) return; |
| 2767 | |
| 2768 | // Debugger must be entered in advance. |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2769 | ASSERT(isolate_->context() == *isolate_->debug()->debug_context()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2770 | |
| 2771 | // Create the event data object. |
| 2772 | bool caught_exception = false; |
| 2773 | Handle<Object> exec_state = MakeExecutionState(&caught_exception); |
| 2774 | Handle<Object> event_data; |
| 2775 | if (!caught_exception) { |
| 2776 | event_data = MakeBreakEvent(exec_state, break_points_hit, |
| 2777 | &caught_exception); |
| 2778 | } |
| 2779 | // Bail out and don't call debugger if exception. |
| 2780 | if (caught_exception) { |
| 2781 | return; |
| 2782 | } |
| 2783 | |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 2784 | // Process debug event. |
| 2785 | ProcessDebugEvent(v8::Break, |
| 2786 | Handle<JSObject>::cast(event_data), |
| 2787 | auto_continue); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2788 | } |
| 2789 | |
| 2790 | |
| 2791 | void Debugger::OnBeforeCompile(Handle<Script> script) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2792 | HandleScope scope(isolate_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2793 | |
| 2794 | // 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] | 2795 | if (isolate_->debug()->InDebugger()) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2796 | if (compiling_natives()) return; |
| 2797 | if (!EventActive(v8::BeforeCompile)) return; |
| 2798 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 2799 | // Enter the debugger. |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 2800 | EnterDebugger debugger(isolate_); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 2801 | if (debugger.FailedToEnter()) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2802 | |
| 2803 | // Create the event data object. |
| 2804 | bool caught_exception = false; |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 2805 | Handle<Object> event_data = MakeCompileEvent(script, true, &caught_exception); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2806 | // Bail out and don't call debugger if exception. |
| 2807 | if (caught_exception) { |
| 2808 | return; |
| 2809 | } |
| 2810 | |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 2811 | // Process debug event. |
| 2812 | ProcessDebugEvent(v8::BeforeCompile, |
| 2813 | Handle<JSObject>::cast(event_data), |
| 2814 | true); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2815 | } |
| 2816 | |
| 2817 | |
| 2818 | // Handle debugger actions when a new script is compiled. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2819 | void Debugger::OnAfterCompile(Handle<Script> script, |
| 2820 | AfterCompileFlags after_compile_flags) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2821 | HandleScope scope(isolate_); |
| 2822 | Debug* debug = isolate_->debug(); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 2823 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2824 | // Add the newly compiled script to the script cache. |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2825 | debug->AddScriptToScriptCache(script); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2826 | |
| 2827 | // No more to do if not debugging. |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 2828 | if (!IsDebuggerActive()) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2829 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2830 | // No compile events while compiling natives. |
| 2831 | if (compiling_natives()) return; |
| 2832 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 2833 | // Store whether in debugger before entering debugger. |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2834 | bool in_debugger = debug->InDebugger(); |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 2835 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 2836 | // Enter the debugger. |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 2837 | EnterDebugger debugger(isolate_); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 2838 | if (debugger.FailedToEnter()) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2839 | |
| 2840 | // If debugging there might be script break points registered for this |
| 2841 | // script. Make sure that these break points are set. |
| 2842 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2843 | // Get the function UpdateScriptBreakPoints (defined in debug-debugger.js). |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2844 | Handle<String> update_script_break_points_string = |
| 2845 | isolate_->factory()->InternalizeOneByteString( |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2846 | STATIC_ASCII_VECTOR("UpdateScriptBreakPoints")); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2847 | Handle<Object> update_script_break_points = |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 2848 | Handle<Object>( |
| 2849 | debug->debug_context()->global_object()->GetPropertyNoExceptionThrown( |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2850 | *update_script_break_points_string), |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 2851 | isolate_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2852 | if (!update_script_break_points->IsJSFunction()) { |
| 2853 | return; |
| 2854 | } |
| 2855 | ASSERT(update_script_break_points->IsJSFunction()); |
| 2856 | |
| 2857 | // Wrap the script object in a proper JS object before passing it |
| 2858 | // to JavaScript. |
| 2859 | Handle<JSValue> wrapper = GetScriptWrapper(script); |
| 2860 | |
| 2861 | // Call UpdateScriptBreakPoints expect no exceptions. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2862 | bool caught_exception; |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 2863 | Handle<Object> argv[] = { wrapper }; |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 2864 | Execution::TryCall(Handle<JSFunction>::cast(update_script_break_points), |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 2865 | isolate_->js_builtins_object(), |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 2866 | ARRAY_SIZE(argv), |
| 2867 | argv, |
| 2868 | &caught_exception); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2869 | if (caught_exception) { |
| 2870 | return; |
| 2871 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2872 | // 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] | 2873 | if (in_debugger && (after_compile_flags & SEND_WHEN_DEBUGGING) == 0) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2874 | if (!Debugger::EventActive(v8::AfterCompile)) return; |
| 2875 | |
| 2876 | // Create the compile state object. |
| 2877 | Handle<Object> event_data = MakeCompileEvent(script, |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 2878 | false, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2879 | &caught_exception); |
| 2880 | // Bail out and don't call debugger if exception. |
| 2881 | if (caught_exception) { |
| 2882 | return; |
| 2883 | } |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 2884 | // Process debug event. |
| 2885 | ProcessDebugEvent(v8::AfterCompile, |
| 2886 | Handle<JSObject>::cast(event_data), |
| 2887 | true); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2888 | } |
| 2889 | |
| 2890 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2891 | void Debugger::OnScriptCollected(int id) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2892 | HandleScope scope(isolate_); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2893 | |
| 2894 | // No more to do if not debugging. |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2895 | if (isolate_->debug()->InDebugger()) return; |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2896 | if (!IsDebuggerActive()) return; |
| 2897 | if (!Debugger::EventActive(v8::ScriptCollected)) return; |
| 2898 | |
| 2899 | // Enter the debugger. |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 2900 | EnterDebugger debugger(isolate_); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2901 | if (debugger.FailedToEnter()) return; |
| 2902 | |
| 2903 | // Create the script collected state object. |
| 2904 | bool caught_exception = false; |
| 2905 | Handle<Object> event_data = MakeScriptCollectedEvent(id, |
| 2906 | &caught_exception); |
| 2907 | // Bail out and don't call debugger if exception. |
| 2908 | if (caught_exception) { |
| 2909 | return; |
| 2910 | } |
| 2911 | |
| 2912 | // Process debug event. |
| 2913 | ProcessDebugEvent(v8::ScriptCollected, |
| 2914 | Handle<JSObject>::cast(event_data), |
| 2915 | true); |
| 2916 | } |
| 2917 | |
| 2918 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2919 | void Debugger::ProcessDebugEvent(v8::DebugEvent event, |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 2920 | Handle<JSObject> event_data, |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2921 | bool auto_continue) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2922 | HandleScope scope(isolate_); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 2923 | |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 2924 | // Clear any pending debug break if this is a real break. |
| 2925 | if (!auto_continue) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2926 | isolate_->debug()->clear_interrupt_pending(DEBUGBREAK); |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 2927 | } |
| 2928 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2929 | // Create the execution state. |
| 2930 | bool caught_exception = false; |
| 2931 | Handle<Object> exec_state = MakeExecutionState(&caught_exception); |
| 2932 | if (caught_exception) { |
| 2933 | return; |
| 2934 | } |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 2935 | // First notify the message handler if any. |
| 2936 | if (message_handler_ != NULL) { |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 2937 | NotifyMessageHandler(event, |
| 2938 | Handle<JSObject>::cast(exec_state), |
| 2939 | event_data, |
| 2940 | auto_continue); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2941 | } |
mikhail.naganov@gmail.com | 2276287 | 2010-07-14 09:29:05 +0000 | [diff] [blame] | 2942 | // Notify registered debug event listener. This can be either a C or |
| 2943 | // a JavaScript function. Don't call event listener for v8::Break |
| 2944 | // here, if it's only a debug command -- they will be processed later. |
| 2945 | if ((event != v8::Break || !auto_continue) && !event_listener_.is_null()) { |
| 2946 | CallEventCallback(event, exec_state, event_data, NULL); |
| 2947 | } |
| 2948 | // Process pending debug commands. |
| 2949 | if (event == v8::Break) { |
| 2950 | while (!event_command_queue_.IsEmpty()) { |
| 2951 | CommandMessage command = event_command_queue_.Get(); |
| 2952 | if (!event_listener_.is_null()) { |
| 2953 | CallEventCallback(v8::BreakForCommand, |
| 2954 | exec_state, |
| 2955 | event_data, |
| 2956 | command.client_data()); |
| 2957 | } |
| 2958 | command.Dispose(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2959 | } |
| 2960 | } |
| 2961 | } |
| 2962 | |
| 2963 | |
mikhail.naganov@gmail.com | 2276287 | 2010-07-14 09:29:05 +0000 | [diff] [blame] | 2964 | void Debugger::CallEventCallback(v8::DebugEvent event, |
| 2965 | Handle<Object> exec_state, |
| 2966 | Handle<Object> event_data, |
| 2967 | v8::Debug::ClientData* client_data) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 2968 | if (event_listener_->IsForeign()) { |
mikhail.naganov@gmail.com | 2276287 | 2010-07-14 09:29:05 +0000 | [diff] [blame] | 2969 | CallCEventCallback(event, exec_state, event_data, client_data); |
| 2970 | } else { |
| 2971 | CallJSEventCallback(event, exec_state, event_data); |
| 2972 | } |
| 2973 | } |
| 2974 | |
| 2975 | |
| 2976 | void Debugger::CallCEventCallback(v8::DebugEvent event, |
| 2977 | Handle<Object> exec_state, |
| 2978 | Handle<Object> event_data, |
| 2979 | v8::Debug::ClientData* client_data) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 2980 | Handle<Foreign> callback_obj(Handle<Foreign>::cast(event_listener_)); |
mikhail.naganov@gmail.com | 2276287 | 2010-07-14 09:29:05 +0000 | [diff] [blame] | 2981 | v8::Debug::EventCallback2 callback = |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2982 | FUNCTION_CAST<v8::Debug::EventCallback2>( |
| 2983 | callback_obj->foreign_address()); |
mikhail.naganov@gmail.com | 2276287 | 2010-07-14 09:29:05 +0000 | [diff] [blame] | 2984 | EventDetailsImpl event_details( |
| 2985 | event, |
| 2986 | Handle<JSObject>::cast(exec_state), |
| 2987 | Handle<JSObject>::cast(event_data), |
| 2988 | event_listener_data_, |
| 2989 | client_data); |
| 2990 | callback(event_details); |
| 2991 | } |
| 2992 | |
| 2993 | |
| 2994 | void Debugger::CallJSEventCallback(v8::DebugEvent event, |
| 2995 | Handle<Object> exec_state, |
| 2996 | Handle<Object> event_data) { |
| 2997 | ASSERT(event_listener_->IsJSFunction()); |
| 2998 | Handle<JSFunction> fun(Handle<JSFunction>::cast(event_listener_)); |
| 2999 | |
| 3000 | // Invoke the JavaScript debug event listener. |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 3001 | Handle<Object> argv[] = { Handle<Object>(Smi::FromInt(event), isolate_), |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 3002 | exec_state, |
| 3003 | event_data, |
| 3004 | event_listener_data_ }; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3005 | bool caught_exception; |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 3006 | Execution::TryCall(fun, |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3007 | isolate_->global_object(), |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 3008 | ARRAY_SIZE(argv), |
| 3009 | argv, |
| 3010 | &caught_exception); |
mikhail.naganov@gmail.com | 2276287 | 2010-07-14 09:29:05 +0000 | [diff] [blame] | 3011 | // Silently ignore exceptions from debug event listeners. |
| 3012 | } |
| 3013 | |
| 3014 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 3015 | Handle<Context> Debugger::GetDebugContext() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3016 | never_unload_debugger_ = true; |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 3017 | EnterDebugger debugger(isolate_); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3018 | return isolate_->debug()->debug_context(); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 3019 | } |
| 3020 | |
| 3021 | |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 3022 | void Debugger::UnloadDebugger() { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3023 | Debug* debug = isolate_->debug(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3024 | |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 3025 | // Make sure that there are no breakpoints left. |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3026 | debug->ClearAllBreakPoints(); |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 3027 | |
| 3028 | // Unload the debugger if feasible. |
| 3029 | if (!never_unload_debugger_) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3030 | debug->Unload(); |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 3031 | } |
| 3032 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 3033 | // Clear the flag indicating that the debugger should be unloaded. |
| 3034 | debugger_unload_pending_ = false; |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 3035 | } |
| 3036 | |
| 3037 | |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 3038 | void Debugger::NotifyMessageHandler(v8::DebugEvent event, |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 3039 | Handle<JSObject> exec_state, |
| 3040 | Handle<JSObject> event_data, |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 3041 | bool auto_continue) { |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 3042 | v8::Isolate* isolate = reinterpret_cast<v8::Isolate*>(isolate_); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3043 | HandleScope scope(isolate_); |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 3044 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3045 | if (!isolate_->debug()->Load()) return; |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 3046 | |
| 3047 | // Process the individual events. |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 3048 | bool sendEventMessage = false; |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 3049 | switch (event) { |
| 3050 | case v8::Break: |
mikhail.naganov@gmail.com | 2276287 | 2010-07-14 09:29:05 +0000 | [diff] [blame] | 3051 | case v8::BreakForCommand: |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 3052 | sendEventMessage = !auto_continue; |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 3053 | break; |
| 3054 | case v8::Exception: |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 3055 | sendEventMessage = true; |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 3056 | break; |
| 3057 | case v8::BeforeCompile: |
| 3058 | break; |
| 3059 | case v8::AfterCompile: |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 3060 | sendEventMessage = true; |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 3061 | break; |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 3062 | case v8::ScriptCollected: |
| 3063 | sendEventMessage = true; |
| 3064 | break; |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 3065 | case v8::NewFunction: |
| 3066 | break; |
| 3067 | default: |
| 3068 | UNREACHABLE(); |
| 3069 | } |
| 3070 | |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 3071 | // The debug command interrupt flag might have been set when the command was |
| 3072 | // added. It should be enough to clear the flag only once while we are in the |
| 3073 | // debugger. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3074 | ASSERT(isolate_->debug()->InDebugger()); |
| 3075 | isolate_->stack_guard()->Continue(DEBUGCOMMAND); |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 3076 | |
| 3077 | // Notify the debugger that a debug event has occurred unless auto continue is |
| 3078 | // active in which case no event is send. |
| 3079 | if (sendEventMessage) { |
| 3080 | MessageImpl message = MessageImpl::NewEvent( |
| 3081 | event, |
| 3082 | auto_continue, |
| 3083 | Handle<JSObject>::cast(exec_state), |
| 3084 | Handle<JSObject>::cast(event_data)); |
| 3085 | InvokeMessageHandler(message); |
| 3086 | } |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 3087 | |
| 3088 | // If auto continue don't make the event cause a break, but process messages |
| 3089 | // in the queue if any. For script collected events don't even process |
| 3090 | // messages in the queue as the execution state might not be what is expected |
| 3091 | // by the client. |
ager@chromium.org | 6ffc217 | 2009-05-29 19:20:16 +0000 | [diff] [blame] | 3092 | if ((auto_continue && !HasCommands()) || event == v8::ScriptCollected) { |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 3093 | return; |
| 3094 | } |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 3095 | |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 3096 | v8::TryCatch try_catch; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 3097 | |
| 3098 | // DebugCommandProcessor goes here. |
| 3099 | v8::Local<v8::Object> cmd_processor; |
| 3100 | { |
| 3101 | v8::Local<v8::Object> api_exec_state = |
| 3102 | v8::Utils::ToLocal(Handle<JSObject>::cast(exec_state)); |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 3103 | v8::Local<v8::String> fun_name = v8::String::NewFromUtf8( |
| 3104 | isolate, "debugCommandProcessor"); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 3105 | v8::Local<v8::Function> fun = |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 3106 | 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] | 3107 | |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 3108 | 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] | 3109 | static const int kArgc = 1; |
| 3110 | v8::Handle<Value> argv[kArgc] = { running }; |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 3111 | cmd_processor = v8::Local<v8::Object>::Cast( |
| 3112 | fun->Call(api_exec_state, kArgc, argv)); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 3113 | if (try_catch.HasCaught()) { |
| 3114 | PrintLn(try_catch.Exception()); |
| 3115 | return; |
| 3116 | } |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 3117 | } |
| 3118 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 3119 | bool running = auto_continue; |
| 3120 | |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 3121 | // Process requests from the debugger. |
| 3122 | while (true) { |
| 3123 | // Wait for new command in the queue. |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 3124 | if (Debugger::host_dispatch_handler_) { |
| 3125 | // In case there is a host dispatch - do periodic dispatches. |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 3126 | if (!command_received_.WaitFor(host_dispatch_period_)) { |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 3127 | // Timout expired, do the dispatch. |
| 3128 | Debugger::host_dispatch_handler_(); |
| 3129 | continue; |
| 3130 | } |
| 3131 | } else { |
| 3132 | // In case there is no host dispatch - just wait. |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 3133 | command_received_.Wait(); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 3134 | } |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 3135 | |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 3136 | // Get the command from the queue. |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 3137 | CommandMessage command = command_queue_.Get(); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 3138 | isolate_->logger()->DebugTag( |
| 3139 | "Got request from command queue, in interactive loop."); |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 3140 | if (!Debugger::IsDebuggerActive()) { |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 3141 | // Delete command text and user data. |
| 3142 | command.Dispose(); |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 3143 | return; |
| 3144 | } |
| 3145 | |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 3146 | // Invoke JavaScript to process the debug request. |
| 3147 | v8::Local<v8::String> fun_name; |
| 3148 | v8::Local<v8::Function> fun; |
| 3149 | v8::Local<v8::Value> request; |
| 3150 | v8::TryCatch try_catch; |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 3151 | fun_name = v8::String::NewFromUtf8(isolate, "processDebugRequest"); |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 3152 | fun = v8::Local<v8::Function>::Cast(cmd_processor->Get(fun_name)); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 3153 | |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 3154 | request = v8::String::NewFromTwoByte(isolate, command.text().start(), |
| 3155 | v8::String::kNormalString, |
| 3156 | command.text().length()); |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 3157 | static const int kArgc = 1; |
| 3158 | v8::Handle<Value> argv[kArgc] = { request }; |
| 3159 | v8::Local<v8::Value> response_val = fun->Call(cmd_processor, kArgc, argv); |
| 3160 | |
| 3161 | // Get the response. |
| 3162 | v8::Local<v8::String> response; |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 3163 | if (!try_catch.HasCaught()) { |
| 3164 | // Get response string. |
| 3165 | if (!response_val->IsUndefined()) { |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 3166 | response = v8::Local<v8::String>::Cast(response_val); |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 3167 | } else { |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 3168 | response = v8::String::NewFromUtf8(isolate, ""); |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 3169 | } |
| 3170 | |
| 3171 | // Log the JSON request/response. |
| 3172 | if (FLAG_trace_debug_json) { |
| 3173 | PrintLn(request); |
| 3174 | PrintLn(response); |
| 3175 | } |
| 3176 | |
| 3177 | // Get the running state. |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 3178 | fun_name = v8::String::NewFromUtf8(isolate, "isRunning"); |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 3179 | fun = v8::Local<v8::Function>::Cast(cmd_processor->Get(fun_name)); |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 3180 | static const int kArgc = 1; |
| 3181 | v8::Handle<Value> argv[kArgc] = { response }; |
| 3182 | v8::Local<v8::Value> running_val = fun->Call(cmd_processor, kArgc, argv); |
| 3183 | if (!try_catch.HasCaught()) { |
| 3184 | running = running_val->ToBoolean()->Value(); |
| 3185 | } |
| 3186 | } else { |
| 3187 | // In case of failure the result text is the exception text. |
| 3188 | response = try_catch.Exception()->ToString(); |
| 3189 | } |
| 3190 | |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 3191 | // Return the result. |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 3192 | MessageImpl message = MessageImpl::NewResponse( |
| 3193 | event, |
| 3194 | running, |
| 3195 | Handle<JSObject>::cast(exec_state), |
| 3196 | Handle<JSObject>::cast(event_data), |
| 3197 | Handle<String>(Utils::OpenHandle(*response)), |
| 3198 | command.client_data()); |
| 3199 | InvokeMessageHandler(message); |
| 3200 | command.Dispose(); |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 3201 | |
| 3202 | // 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] | 3203 | // running state (through a continue command) or auto continue is active |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 3204 | // and there are no more commands queued. |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 3205 | if (running && !HasCommands()) { |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 3206 | return; |
| 3207 | } |
| 3208 | } |
| 3209 | } |
| 3210 | |
| 3211 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 3212 | void Debugger::SetEventListener(Handle<Object> callback, |
| 3213 | Handle<Object> data) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3214 | HandleScope scope(isolate_); |
| 3215 | GlobalHandles* global_handles = isolate_->global_handles(); |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 3216 | |
| 3217 | // Clear the global handles for the event listener and the event listener data |
| 3218 | // object. |
| 3219 | if (!event_listener_.is_null()) { |
hpayer@chromium.org | 4f99be9 | 2013-12-18 16:23:55 +0000 | [diff] [blame] | 3220 | GlobalHandles::Destroy( |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 3221 | reinterpret_cast<Object**>(event_listener_.location())); |
| 3222 | event_listener_ = Handle<Object>(); |
| 3223 | } |
| 3224 | if (!event_listener_data_.is_null()) { |
hpayer@chromium.org | 4f99be9 | 2013-12-18 16:23:55 +0000 | [diff] [blame] | 3225 | GlobalHandles::Destroy( |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 3226 | reinterpret_cast<Object**>(event_listener_data_.location())); |
| 3227 | event_listener_data_ = Handle<Object>(); |
| 3228 | } |
| 3229 | |
| 3230 | // If there is a new debug event listener register it together with its data |
| 3231 | // object. |
| 3232 | if (!callback->IsUndefined() && !callback->IsNull()) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3233 | event_listener_ = Handle<Object>::cast( |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3234 | global_handles->Create(*callback)); |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 3235 | if (data.is_null()) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3236 | data = isolate_->factory()->undefined_value(); |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 3237 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3238 | event_listener_data_ = Handle<Object>::cast( |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3239 | global_handles->Create(*data)); |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 3240 | } |
| 3241 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 3242 | ListenersChanged(); |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 3243 | } |
| 3244 | |
| 3245 | |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 3246 | void Debugger::SetMessageHandler(v8::Debug::MessageHandler2 handler) { |
jkummerow@chromium.org | dc94e19 | 2013-08-30 11:35:42 +0000 | [diff] [blame] | 3247 | LockGuard<RecursiveMutex> with(debugger_access_); |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 3248 | |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 3249 | message_handler_ = handler; |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 3250 | ListenersChanged(); |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 3251 | if (handler == NULL) { |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 3252 | // Send an empty command to the debugger if in a break to make JavaScript |
| 3253 | // run again if the debugger is closed. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3254 | if (isolate_->debug()->InDebugger()) { |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 3255 | ProcessCommand(Vector<const uint16_t>::empty()); |
| 3256 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3257 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3258 | } |
| 3259 | |
| 3260 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 3261 | void Debugger::ListenersChanged() { |
| 3262 | if (IsDebuggerActive()) { |
| 3263 | // Disable the compilation cache when the debugger is active. |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3264 | isolate_->compilation_cache()->Disable(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3265 | debugger_unload_pending_ = false; |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 3266 | } else { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3267 | isolate_->compilation_cache()->Enable(); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 3268 | // Unload the debugger if event listener and message handler cleared. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3269 | // Schedule this for later, because we may be in non-V8 thread. |
| 3270 | debugger_unload_pending_ = true; |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 3271 | } |
| 3272 | } |
| 3273 | |
| 3274 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 3275 | void Debugger::SetHostDispatchHandler(v8::Debug::HostDispatchHandler handler, |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 3276 | TimeDelta period) { |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 3277 | host_dispatch_handler_ = handler; |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 3278 | host_dispatch_period_ = period; |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 3279 | } |
| 3280 | |
| 3281 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 3282 | void Debugger::SetDebugMessageDispatchHandler( |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3283 | v8::Debug::DebugMessageDispatchHandler handler, bool provide_locker) { |
jkummerow@chromium.org | dc94e19 | 2013-08-30 11:35:42 +0000 | [diff] [blame] | 3284 | LockGuard<Mutex> lock_guard(&dispatch_handler_access_); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 3285 | debug_message_dispatch_handler_ = handler; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3286 | |
| 3287 | if (provide_locker && message_dispatch_helper_thread_ == NULL) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3288 | message_dispatch_helper_thread_ = new MessageDispatchHelperThread(isolate_); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3289 | message_dispatch_helper_thread_->Start(); |
| 3290 | } |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 3291 | } |
| 3292 | |
| 3293 | |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 3294 | // 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] | 3295 | // public API. |
| 3296 | void Debugger::InvokeMessageHandler(MessageImpl message) { |
jkummerow@chromium.org | dc94e19 | 2013-08-30 11:35:42 +0000 | [diff] [blame] | 3297 | LockGuard<RecursiveMutex> with(debugger_access_); |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 3298 | |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 3299 | if (message_handler_ != NULL) { |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 3300 | message_handler_(message); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3301 | } |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 3302 | } |
| 3303 | |
| 3304 | |
| 3305 | // Puts a command coming from the public API on the queue. Creates |
| 3306 | // a copy of the command string managed by the debugger. Up to this |
| 3307 | // point, the command data was managed by the API client. Called |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 3308 | // by the API client thread. |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 3309 | void Debugger::ProcessCommand(Vector<const uint16_t> command, |
| 3310 | v8::Debug::ClientData* client_data) { |
| 3311 | // Need to cast away const. |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 3312 | CommandMessage message = CommandMessage::New( |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 3313 | Vector<uint16_t>(const_cast<uint16_t*>(command.start()), |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 3314 | command.length()), |
| 3315 | client_data); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 3316 | isolate_->logger()->DebugTag("Put command on command_queue."); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 3317 | command_queue_.Put(message); |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 3318 | command_received_.Signal(); |
sgjesse@chromium.org | 3afc158 | 2009-04-16 22:31:44 +0000 | [diff] [blame] | 3319 | |
| 3320 | // Set the debug command break flag to have the command processed. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3321 | if (!isolate_->debug()->InDebugger()) { |
| 3322 | isolate_->stack_guard()->DebugCommand(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3323 | } |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 3324 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3325 | MessageDispatchHelperThread* dispatch_thread; |
| 3326 | { |
jkummerow@chromium.org | dc94e19 | 2013-08-30 11:35:42 +0000 | [diff] [blame] | 3327 | LockGuard<Mutex> lock_guard(&dispatch_handler_access_); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3328 | dispatch_thread = message_dispatch_helper_thread_; |
| 3329 | } |
| 3330 | |
| 3331 | if (dispatch_thread == NULL) { |
| 3332 | CallMessageDispatchHandler(); |
| 3333 | } else { |
| 3334 | dispatch_thread->Schedule(); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 3335 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3336 | } |
| 3337 | |
| 3338 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3339 | bool Debugger::HasCommands() { |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 3340 | return !command_queue_.IsEmpty(); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3341 | } |
| 3342 | |
| 3343 | |
mikhail.naganov@gmail.com | 2276287 | 2010-07-14 09:29:05 +0000 | [diff] [blame] | 3344 | void Debugger::EnqueueDebugCommand(v8::Debug::ClientData* client_data) { |
| 3345 | CommandMessage message = CommandMessage::New(Vector<uint16_t>(), client_data); |
| 3346 | event_command_queue_.Put(message); |
| 3347 | |
| 3348 | // Set the debug command break flag to have the command processed. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3349 | if (!isolate_->debug()->InDebugger()) { |
| 3350 | isolate_->stack_guard()->DebugCommand(); |
mikhail.naganov@gmail.com | 2276287 | 2010-07-14 09:29:05 +0000 | [diff] [blame] | 3351 | } |
| 3352 | } |
| 3353 | |
| 3354 | |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 3355 | bool Debugger::IsDebuggerActive() { |
jkummerow@chromium.org | dc94e19 | 2013-08-30 11:35:42 +0000 | [diff] [blame] | 3356 | LockGuard<RecursiveMutex> with(debugger_access_); |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 3357 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3358 | return message_handler_ != NULL || |
| 3359 | !event_listener_.is_null() || |
| 3360 | force_debugger_active_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3361 | } |
| 3362 | |
| 3363 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 3364 | Handle<Object> Debugger::Call(Handle<JSFunction> fun, |
| 3365 | Handle<Object> data, |
| 3366 | bool* pending_exception) { |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 3367 | // When calling functions in the debugger prevent it from beeing unloaded. |
| 3368 | Debugger::never_unload_debugger_ = true; |
| 3369 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 3370 | // Enter the debugger. |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 3371 | EnterDebugger debugger(isolate_); |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 3372 | if (debugger.FailedToEnter()) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3373 | return isolate_->factory()->undefined_value(); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 3374 | } |
| 3375 | |
| 3376 | // Create the execution state. |
| 3377 | bool caught_exception = false; |
| 3378 | Handle<Object> exec_state = MakeExecutionState(&caught_exception); |
| 3379 | if (caught_exception) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3380 | return isolate_->factory()->undefined_value(); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 3381 | } |
| 3382 | |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 3383 | Handle<Object> argv[] = { exec_state, data }; |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 3384 | Handle<Object> result = Execution::Call( |
jkummerow@chromium.org | 2c9426b | 2013-09-05 16:31:13 +0000 | [diff] [blame] | 3385 | isolate_, |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 3386 | fun, |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 3387 | Handle<Object>(isolate_->debug()->debug_context_->global_proxy(), |
| 3388 | isolate_), |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 3389 | ARRAY_SIZE(argv), |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 3390 | argv, |
| 3391 | pending_exception); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 3392 | return result; |
| 3393 | } |
| 3394 | |
| 3395 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3396 | static void StubMessageHandler2(const v8::Debug::Message& message) { |
| 3397 | // Simply ignore message. |
| 3398 | } |
| 3399 | |
| 3400 | |
| 3401 | bool Debugger::StartAgent(const char* name, int port, |
| 3402 | bool wait_for_connection) { |
| 3403 | if (wait_for_connection) { |
| 3404 | // Suspend V8 if it is already running or set V8 to suspend whenever |
| 3405 | // it starts. |
| 3406 | // Provide stub message handler; V8 auto-continues each suspend |
| 3407 | // when there is no message handler; we doesn't need it. |
| 3408 | // Once become suspended, V8 will stay so indefinitely long, until remote |
| 3409 | // debugger connects and issues "continue" command. |
| 3410 | Debugger::message_handler_ = StubMessageHandler2; |
| 3411 | v8::Debug::DebugBreak(); |
| 3412 | } |
| 3413 | |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 3414 | if (agent_ == NULL) { |
| 3415 | agent_ = new DebuggerAgent(isolate_, name, port); |
| 3416 | agent_->Start(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3417 | } |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 3418 | return true; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3419 | } |
| 3420 | |
| 3421 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3422 | void Debugger::StopAgent() { |
| 3423 | if (agent_ != NULL) { |
| 3424 | agent_->Shutdown(); |
| 3425 | agent_->Join(); |
| 3426 | delete agent_; |
| 3427 | agent_ = NULL; |
| 3428 | } |
| 3429 | } |
| 3430 | |
| 3431 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3432 | void Debugger::WaitForAgent() { |
| 3433 | if (agent_ != NULL) |
| 3434 | agent_->WaitUntilListening(); |
| 3435 | } |
| 3436 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3437 | |
| 3438 | void Debugger::CallMessageDispatchHandler() { |
| 3439 | v8::Debug::DebugMessageDispatchHandler handler; |
| 3440 | { |
jkummerow@chromium.org | dc94e19 | 2013-08-30 11:35:42 +0000 | [diff] [blame] | 3441 | LockGuard<Mutex> lock_guard(&dispatch_handler_access_); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3442 | handler = Debugger::debug_message_dispatch_handler_; |
| 3443 | } |
| 3444 | if (handler != NULL) { |
| 3445 | handler(); |
| 3446 | } |
| 3447 | } |
| 3448 | |
| 3449 | |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 3450 | EnterDebugger::EnterDebugger(Isolate* isolate) |
| 3451 | : isolate_(isolate), |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3452 | prev_(isolate_->debug()->debugger_entry()), |
| 3453 | it_(isolate_), |
| 3454 | has_js_frames_(!it_.done()), |
| 3455 | save_(isolate_) { |
| 3456 | Debug* debug = isolate_->debug(); |
| 3457 | ASSERT(prev_ != NULL || !debug->is_interrupt_pending(PREEMPT)); |
| 3458 | ASSERT(prev_ != NULL || !debug->is_interrupt_pending(DEBUGBREAK)); |
| 3459 | |
| 3460 | // Link recursive debugger entry. |
| 3461 | debug->set_debugger_entry(this); |
| 3462 | |
| 3463 | // Store the previous break id and frame id. |
| 3464 | break_id_ = debug->break_id(); |
| 3465 | break_frame_id_ = debug->break_frame_id(); |
| 3466 | |
| 3467 | // Create the new break info. If there is no JavaScript frames there is no |
| 3468 | // break frame id. |
| 3469 | if (has_js_frames_) { |
| 3470 | debug->NewBreak(it_.frame()->id()); |
| 3471 | } else { |
| 3472 | debug->NewBreak(StackFrame::NO_ID); |
| 3473 | } |
| 3474 | |
| 3475 | // Make sure that debugger is loaded and enter the debugger context. |
| 3476 | load_failed_ = !debug->Load(); |
| 3477 | if (!load_failed_) { |
| 3478 | // NOTE the member variable save which saves the previous context before |
| 3479 | // this change. |
| 3480 | isolate_->set_context(*debug->debug_context()); |
| 3481 | } |
| 3482 | } |
| 3483 | |
| 3484 | |
| 3485 | EnterDebugger::~EnterDebugger() { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3486 | Debug* debug = isolate_->debug(); |
| 3487 | |
| 3488 | // Restore to the previous break state. |
| 3489 | debug->SetBreak(break_frame_id_, break_id_); |
| 3490 | |
| 3491 | // Check for leaving the debugger. |
fschneider@chromium.org | 7d10be5 | 2012-04-10 12:30:14 +0000 | [diff] [blame] | 3492 | if (!load_failed_ && prev_ == NULL) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3493 | // Clear mirror cache when leaving the debugger. Skip this if there is a |
| 3494 | // pending exception as clearing the mirror cache calls back into |
| 3495 | // JavaScript. This can happen if the v8::Debug::Call is used in which |
| 3496 | // case the exception should end up in the calling code. |
| 3497 | if (!isolate_->has_pending_exception()) { |
| 3498 | // Try to avoid any pending debug break breaking in the clear mirror |
| 3499 | // cache JavaScript code. |
| 3500 | if (isolate_->stack_guard()->IsDebugBreak()) { |
| 3501 | debug->set_interrupts_pending(DEBUGBREAK); |
| 3502 | isolate_->stack_guard()->Continue(DEBUGBREAK); |
| 3503 | } |
| 3504 | debug->ClearMirrorCache(); |
| 3505 | } |
| 3506 | |
| 3507 | // Request preemption and debug break when leaving the last debugger entry |
| 3508 | // if any of these where recorded while debugging. |
| 3509 | if (debug->is_interrupt_pending(PREEMPT)) { |
| 3510 | // This re-scheduling of preemption is to avoid starvation in some |
| 3511 | // debugging scenarios. |
| 3512 | debug->clear_interrupt_pending(PREEMPT); |
| 3513 | isolate_->stack_guard()->Preempt(); |
| 3514 | } |
| 3515 | if (debug->is_interrupt_pending(DEBUGBREAK)) { |
| 3516 | debug->clear_interrupt_pending(DEBUGBREAK); |
| 3517 | isolate_->stack_guard()->DebugBreak(); |
| 3518 | } |
| 3519 | |
| 3520 | // If there are commands in the queue when leaving the debugger request |
| 3521 | // that these commands are processed. |
| 3522 | if (isolate_->debugger()->HasCommands()) { |
| 3523 | isolate_->stack_guard()->DebugCommand(); |
| 3524 | } |
| 3525 | |
| 3526 | // If leaving the debugger with the debugger no longer active unload it. |
| 3527 | if (!isolate_->debugger()->IsDebuggerActive()) { |
| 3528 | isolate_->debugger()->UnloadDebugger(); |
| 3529 | } |
| 3530 | } |
| 3531 | |
| 3532 | // Leaving this debugger entry. |
| 3533 | debug->set_debugger_entry(prev_); |
| 3534 | } |
| 3535 | |
| 3536 | |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 3537 | MessageImpl MessageImpl::NewEvent(DebugEvent event, |
| 3538 | bool running, |
| 3539 | Handle<JSObject> exec_state, |
| 3540 | Handle<JSObject> event_data) { |
| 3541 | MessageImpl message(true, event, running, |
| 3542 | exec_state, event_data, Handle<String>(), NULL); |
| 3543 | return message; |
| 3544 | } |
| 3545 | |
| 3546 | |
| 3547 | MessageImpl MessageImpl::NewResponse(DebugEvent event, |
| 3548 | bool running, |
| 3549 | Handle<JSObject> exec_state, |
| 3550 | Handle<JSObject> event_data, |
| 3551 | Handle<String> response_json, |
| 3552 | v8::Debug::ClientData* client_data) { |
| 3553 | MessageImpl message(false, event, running, |
| 3554 | exec_state, event_data, response_json, client_data); |
| 3555 | return message; |
| 3556 | } |
| 3557 | |
| 3558 | |
| 3559 | MessageImpl::MessageImpl(bool is_event, |
| 3560 | DebugEvent event, |
| 3561 | bool running, |
| 3562 | Handle<JSObject> exec_state, |
| 3563 | Handle<JSObject> event_data, |
| 3564 | Handle<String> response_json, |
| 3565 | v8::Debug::ClientData* client_data) |
| 3566 | : is_event_(is_event), |
| 3567 | event_(event), |
| 3568 | running_(running), |
| 3569 | exec_state_(exec_state), |
| 3570 | event_data_(event_data), |
| 3571 | response_json_(response_json), |
| 3572 | client_data_(client_data) {} |
| 3573 | |
| 3574 | |
| 3575 | bool MessageImpl::IsEvent() const { |
| 3576 | return is_event_; |
| 3577 | } |
| 3578 | |
| 3579 | |
| 3580 | bool MessageImpl::IsResponse() const { |
| 3581 | return !is_event_; |
| 3582 | } |
| 3583 | |
| 3584 | |
| 3585 | DebugEvent MessageImpl::GetEvent() const { |
| 3586 | return event_; |
| 3587 | } |
| 3588 | |
| 3589 | |
| 3590 | bool MessageImpl::WillStartRunning() const { |
| 3591 | return running_; |
| 3592 | } |
| 3593 | |
| 3594 | |
| 3595 | v8::Handle<v8::Object> MessageImpl::GetExecutionState() const { |
| 3596 | return v8::Utils::ToLocal(exec_state_); |
| 3597 | } |
| 3598 | |
| 3599 | |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 3600 | v8::Isolate* MessageImpl::GetIsolate() const { |
| 3601 | return reinterpret_cast<v8::Isolate*>(exec_state_->GetIsolate()); |
| 3602 | } |
| 3603 | |
| 3604 | |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 3605 | v8::Handle<v8::Object> MessageImpl::GetEventData() const { |
| 3606 | return v8::Utils::ToLocal(event_data_); |
| 3607 | } |
| 3608 | |
| 3609 | |
| 3610 | v8::Handle<v8::String> MessageImpl::GetJSON() const { |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 3611 | v8::EscapableHandleScope scope( |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 3612 | reinterpret_cast<v8::Isolate*>(event_data_->GetIsolate())); |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 3613 | |
| 3614 | if (IsEvent()) { |
| 3615 | // Call toJSONProtocol on the debug event object. |
| 3616 | Handle<Object> fun = GetProperty(event_data_, "toJSONProtocol"); |
| 3617 | if (!fun->IsJSFunction()) { |
| 3618 | return v8::Handle<v8::String>(); |
| 3619 | } |
| 3620 | bool caught_exception; |
| 3621 | Handle<Object> json = Execution::TryCall(Handle<JSFunction>::cast(fun), |
| 3622 | event_data_, |
| 3623 | 0, NULL, &caught_exception); |
| 3624 | if (caught_exception || !json->IsString()) { |
| 3625 | return v8::Handle<v8::String>(); |
| 3626 | } |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 3627 | return scope.Escape(v8::Utils::ToLocal(Handle<String>::cast(json))); |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 3628 | } else { |
| 3629 | return v8::Utils::ToLocal(response_json_); |
| 3630 | } |
| 3631 | } |
| 3632 | |
| 3633 | |
| 3634 | v8::Handle<v8::Context> MessageImpl::GetEventContext() const { |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 3635 | Isolate* isolate = event_data_->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3636 | v8::Handle<v8::Context> context = GetDebugEventContext(isolate); |
| 3637 | // Isolate::context() may be NULL when "script collected" event occures. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3638 | ASSERT(!context.IsEmpty() || event_ == v8::ScriptCollected); |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 3639 | return context; |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 3640 | } |
| 3641 | |
| 3642 | |
| 3643 | v8::Debug::ClientData* MessageImpl::GetClientData() const { |
| 3644 | return client_data_; |
| 3645 | } |
| 3646 | |
| 3647 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3648 | EventDetailsImpl::EventDetailsImpl(DebugEvent event, |
| 3649 | Handle<JSObject> exec_state, |
| 3650 | Handle<JSObject> event_data, |
mikhail.naganov@gmail.com | 2276287 | 2010-07-14 09:29:05 +0000 | [diff] [blame] | 3651 | Handle<Object> callback_data, |
| 3652 | v8::Debug::ClientData* client_data) |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3653 | : event_(event), |
| 3654 | exec_state_(exec_state), |
| 3655 | event_data_(event_data), |
mikhail.naganov@gmail.com | 2276287 | 2010-07-14 09:29:05 +0000 | [diff] [blame] | 3656 | callback_data_(callback_data), |
| 3657 | client_data_(client_data) {} |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3658 | |
| 3659 | |
| 3660 | DebugEvent EventDetailsImpl::GetEvent() const { |
| 3661 | return event_; |
| 3662 | } |
| 3663 | |
| 3664 | |
| 3665 | v8::Handle<v8::Object> EventDetailsImpl::GetExecutionState() const { |
| 3666 | return v8::Utils::ToLocal(exec_state_); |
| 3667 | } |
| 3668 | |
| 3669 | |
| 3670 | v8::Handle<v8::Object> EventDetailsImpl::GetEventData() const { |
| 3671 | return v8::Utils::ToLocal(event_data_); |
| 3672 | } |
| 3673 | |
| 3674 | |
| 3675 | v8::Handle<v8::Context> EventDetailsImpl::GetEventContext() const { |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 3676 | return GetDebugEventContext(exec_state_->GetIsolate()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3677 | } |
| 3678 | |
| 3679 | |
| 3680 | v8::Handle<v8::Value> EventDetailsImpl::GetCallbackData() const { |
| 3681 | return v8::Utils::ToLocal(callback_data_); |
| 3682 | } |
| 3683 | |
| 3684 | |
mikhail.naganov@gmail.com | 2276287 | 2010-07-14 09:29:05 +0000 | [diff] [blame] | 3685 | v8::Debug::ClientData* EventDetailsImpl::GetClientData() const { |
| 3686 | return client_data_; |
| 3687 | } |
| 3688 | |
| 3689 | |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 3690 | CommandMessage::CommandMessage() : text_(Vector<uint16_t>::empty()), |
| 3691 | client_data_(NULL) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3692 | } |
| 3693 | |
| 3694 | |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 3695 | CommandMessage::CommandMessage(const Vector<uint16_t>& text, |
| 3696 | v8::Debug::ClientData* data) |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 3697 | : text_(text), |
| 3698 | client_data_(data) { |
| 3699 | } |
| 3700 | |
| 3701 | |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 3702 | CommandMessage::~CommandMessage() { |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 3703 | } |
| 3704 | |
| 3705 | |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 3706 | void CommandMessage::Dispose() { |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 3707 | text_.Dispose(); |
| 3708 | delete client_data_; |
| 3709 | client_data_ = NULL; |
| 3710 | } |
| 3711 | |
| 3712 | |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 3713 | CommandMessage CommandMessage::New(const Vector<uint16_t>& command, |
| 3714 | v8::Debug::ClientData* data) { |
| 3715 | return CommandMessage(command.Clone(), data); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 3716 | } |
| 3717 | |
| 3718 | |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 3719 | CommandMessageQueue::CommandMessageQueue(int size) : start_(0), end_(0), |
| 3720 | size_(size) { |
| 3721 | messages_ = NewArray<CommandMessage>(size); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 3722 | } |
| 3723 | |
| 3724 | |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 3725 | CommandMessageQueue::~CommandMessageQueue() { |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 3726 | while (!IsEmpty()) { |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 3727 | CommandMessage m = Get(); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 3728 | m.Dispose(); |
| 3729 | } |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 3730 | DeleteArray(messages_); |
| 3731 | } |
| 3732 | |
| 3733 | |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 3734 | CommandMessage CommandMessageQueue::Get() { |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 3735 | ASSERT(!IsEmpty()); |
| 3736 | int result = start_; |
| 3737 | start_ = (start_ + 1) % size_; |
| 3738 | return messages_[result]; |
| 3739 | } |
| 3740 | |
| 3741 | |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 3742 | void CommandMessageQueue::Put(const CommandMessage& message) { |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 3743 | if ((end_ + 1) % size_ == start_) { |
| 3744 | Expand(); |
| 3745 | } |
| 3746 | messages_[end_] = message; |
| 3747 | end_ = (end_ + 1) % size_; |
| 3748 | } |
| 3749 | |
| 3750 | |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 3751 | void CommandMessageQueue::Expand() { |
| 3752 | CommandMessageQueue new_queue(size_ * 2); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 3753 | while (!IsEmpty()) { |
| 3754 | new_queue.Put(Get()); |
| 3755 | } |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 3756 | CommandMessage* array_to_free = messages_; |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 3757 | *this = new_queue; |
| 3758 | new_queue.messages_ = array_to_free; |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 3759 | // Make the new_queue empty so that it doesn't call Dispose on any messages. |
| 3760 | new_queue.start_ = new_queue.end_; |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 3761 | // Automatic destructor called on new_queue, freeing array_to_free. |
| 3762 | } |
| 3763 | |
| 3764 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 3765 | LockingCommandMessageQueue::LockingCommandMessageQueue(Logger* logger, int size) |
jkummerow@chromium.org | dc94e19 | 2013-08-30 11:35:42 +0000 | [diff] [blame] | 3766 | : logger_(logger), queue_(size) {} |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 3767 | |
| 3768 | |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 3769 | bool LockingCommandMessageQueue::IsEmpty() const { |
jkummerow@chromium.org | dc94e19 | 2013-08-30 11:35:42 +0000 | [diff] [blame] | 3770 | LockGuard<Mutex> lock_guard(&mutex_); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 3771 | return queue_.IsEmpty(); |
| 3772 | } |
| 3773 | |
| 3774 | |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 3775 | CommandMessage LockingCommandMessageQueue::Get() { |
jkummerow@chromium.org | dc94e19 | 2013-08-30 11:35:42 +0000 | [diff] [blame] | 3776 | LockGuard<Mutex> lock_guard(&mutex_); |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 3777 | CommandMessage result = queue_.Get(); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 3778 | logger_->DebugEvent("Get", result.text()); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 3779 | return result; |
| 3780 | } |
| 3781 | |
| 3782 | |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 3783 | void LockingCommandMessageQueue::Put(const CommandMessage& message) { |
jkummerow@chromium.org | dc94e19 | 2013-08-30 11:35:42 +0000 | [diff] [blame] | 3784 | LockGuard<Mutex> lock_guard(&mutex_); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 3785 | queue_.Put(message); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 3786 | logger_->DebugEvent("Put", message.text()); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 3787 | } |
| 3788 | |
| 3789 | |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 3790 | void LockingCommandMessageQueue::Clear() { |
jkummerow@chromium.org | dc94e19 | 2013-08-30 11:35:42 +0000 | [diff] [blame] | 3791 | LockGuard<Mutex> lock_guard(&mutex_); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 3792 | queue_.Clear(); |
| 3793 | } |
| 3794 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3795 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3796 | MessageDispatchHelperThread::MessageDispatchHelperThread(Isolate* isolate) |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 3797 | : Thread("v8:MsgDispHelpr"), |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 3798 | isolate_(isolate), sem_(0), |
jkummerow@chromium.org | dc94e19 | 2013-08-30 11:35:42 +0000 | [diff] [blame] | 3799 | already_signalled_(false) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3800 | } |
| 3801 | |
| 3802 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3803 | void MessageDispatchHelperThread::Schedule() { |
| 3804 | { |
jkummerow@chromium.org | dc94e19 | 2013-08-30 11:35:42 +0000 | [diff] [blame] | 3805 | LockGuard<Mutex> lock_guard(&mutex_); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3806 | if (already_signalled_) { |
| 3807 | return; |
| 3808 | } |
| 3809 | already_signalled_ = true; |
| 3810 | } |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 3811 | sem_.Signal(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3812 | } |
| 3813 | |
| 3814 | |
| 3815 | void MessageDispatchHelperThread::Run() { |
| 3816 | while (true) { |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 3817 | sem_.Wait(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3818 | { |
jkummerow@chromium.org | dc94e19 | 2013-08-30 11:35:42 +0000 | [diff] [blame] | 3819 | LockGuard<Mutex> lock_guard(&mutex_); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3820 | already_signalled_ = false; |
| 3821 | } |
| 3822 | { |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 3823 | Locker locker(reinterpret_cast<v8::Isolate*>(isolate_)); |
| 3824 | isolate_->debugger()->CallMessageDispatchHandler(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3825 | } |
| 3826 | } |
| 3827 | } |
| 3828 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 3829 | #endif // ENABLE_DEBUGGER_SUPPORT |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 3830 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3831 | } } // namespace v8::internal |