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