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