| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/debug/debug.h" | 5 #include "src/debug/debug.h" |
| 6 | 6 |
| 7 #include "src/api.h" | 7 #include "src/api.h" |
| 8 #include "src/arguments.h" | 8 #include "src/arguments.h" |
| 9 #include "src/bootstrapper.h" | 9 #include "src/bootstrapper.h" |
| 10 #include "src/code-stubs.h" | 10 #include "src/code-stubs.h" |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 : debug_info_(debug_info), | 79 : debug_info_(debug_info), |
| 80 code_offset_(code_offset), | 80 code_offset_(code_offset), |
| 81 type_(type), | 81 type_(type), |
| 82 position_(position), | 82 position_(position), |
| 83 statement_position_(statement_position) { | 83 statement_position_(statement_position) { |
| 84 if (type == DEBUG_BREAK_SLOT_AT_RETURN) { | 84 if (type == DEBUG_BREAK_SLOT_AT_RETURN) { |
| 85 int return_position = 0; | 85 int return_position = 0; |
| 86 SharedFunctionInfo* shared = debug_info->shared(); | 86 SharedFunctionInfo* shared = debug_info->shared(); |
| 87 if (shared->HasSourceCode()) { | 87 if (shared->HasSourceCode()) { |
| 88 return_position = | 88 return_position = |
| 89 std::max(shared->end_position() - shared->start_position() - 1, 0); | 89 std::max(shared->end_position() - 1, shared->start_position()); |
| 90 } | 90 } |
| 91 // TODO(yangguo): find out why return position is wrong for liveedit. | 91 // TODO(yangguo): find out why return position is wrong for liveedit. |
| 92 position_ = return_position; | 92 position_ = return_position; |
| 93 statement_position = return_position; | 93 statement_position_ = return_position; |
| 94 } | 94 } |
| 95 } | 95 } |
| 96 | 96 |
| 97 BreakLocation::Iterator* BreakLocation::GetIterator( | 97 BreakLocation::Iterator* BreakLocation::GetIterator( |
| 98 Handle<DebugInfo> debug_info, BreakLocatorType type) { | 98 Handle<DebugInfo> debug_info, BreakLocatorType type) { |
| 99 if (debug_info->abstract_code()->IsBytecodeArray()) { | 99 if (debug_info->abstract_code()->IsBytecodeArray()) { |
| 100 return new BytecodeArrayIterator(debug_info, type); | 100 return new BytecodeArrayIterator(debug_info, type); |
| 101 } else { | 101 } else { |
| 102 return new CodeIterator(debug_info, type); | 102 return new CodeIterator(debug_info, type); |
| 103 } | 103 } |
| 104 } | 104 } |
| 105 | 105 |
| 106 BreakLocation::Iterator::Iterator(Handle<DebugInfo> debug_info) | 106 BreakLocation::Iterator::Iterator(Handle<DebugInfo> debug_info) |
| 107 : debug_info_(debug_info), | 107 : debug_info_(debug_info), break_index_(-1) { |
| 108 break_index_(-1), | 108 position_ = debug_info->shared()->start_position(); |
| 109 position_(1), | 109 statement_position_ = position_; |
| 110 statement_position_(1) {} | 110 } |
| 111 | 111 |
| 112 BreakLocation::CodeIterator::CodeIterator(Handle<DebugInfo> debug_info, | 112 BreakLocation::CodeIterator::CodeIterator(Handle<DebugInfo> debug_info, |
| 113 BreakLocatorType type) | 113 BreakLocatorType type) |
| 114 : Iterator(debug_info), | 114 : Iterator(debug_info), |
| 115 reloc_iterator_(debug_info->abstract_code()->GetCode(), | 115 reloc_iterator_(debug_info->abstract_code()->GetCode(), |
| 116 GetModeMask(type)), | 116 GetModeMask(type)), |
| 117 source_position_iterator_( | 117 source_position_iterator_( |
| 118 debug_info->abstract_code()->GetCode()->source_position_table()), | 118 debug_info->abstract_code()->GetCode()->source_position_table()) { |
| 119 start_position_(debug_info_->shared()->start_position()) { | |
| 120 // There is at least one break location. | 119 // There is at least one break location. |
| 121 DCHECK(!Done()); | 120 DCHECK(!Done()); |
| 122 Next(); | 121 Next(); |
| 123 } | 122 } |
| 124 | 123 |
| 125 int BreakLocation::CodeIterator::GetModeMask(BreakLocatorType type) { | 124 int BreakLocation::CodeIterator::GetModeMask(BreakLocatorType type) { |
| 126 int mask = 0; | 125 int mask = 0; |
| 127 mask |= RelocInfo::ModeMask(RelocInfo::DEBUG_BREAK_SLOT_AT_RETURN); | 126 mask |= RelocInfo::ModeMask(RelocInfo::DEBUG_BREAK_SLOT_AT_RETURN); |
| 128 mask |= RelocInfo::ModeMask(RelocInfo::DEBUG_BREAK_SLOT_AT_CALL); | 127 mask |= RelocInfo::ModeMask(RelocInfo::DEBUG_BREAK_SLOT_AT_CALL); |
| 129 if (isolate()->is_tail_call_elimination_enabled()) { | 128 if (isolate()->is_tail_call_elimination_enabled()) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 143 // Iterate through reloc info stopping at each breakable code target. | 142 // Iterate through reloc info stopping at each breakable code target. |
| 144 bool first = break_index_ == -1; | 143 bool first = break_index_ == -1; |
| 145 | 144 |
| 146 if (!first) reloc_iterator_.next(); | 145 if (!first) reloc_iterator_.next(); |
| 147 first = false; | 146 first = false; |
| 148 if (Done()) return; | 147 if (Done()) return; |
| 149 | 148 |
| 150 int offset = code_offset(); | 149 int offset = code_offset(); |
| 151 while (!source_position_iterator_.done() && | 150 while (!source_position_iterator_.done() && |
| 152 source_position_iterator_.code_offset() <= offset) { | 151 source_position_iterator_.code_offset() <= offset) { |
| 153 position_ = source_position_iterator_.source_position() - start_position_; | 152 position_ = source_position_iterator_.source_position(); |
| 154 if (source_position_iterator_.is_statement()) { | 153 if (source_position_iterator_.is_statement()) { |
| 155 statement_position_ = position_; | 154 statement_position_ = position_; |
| 156 } | 155 } |
| 157 source_position_iterator_.Advance(); | 156 source_position_iterator_.Advance(); |
| 158 } | 157 } |
| 159 | 158 |
| 160 DCHECK(RelocInfo::IsDebugBreakSlot(rmode()) || | 159 DCHECK(RelocInfo::IsDebugBreakSlot(rmode()) || |
| 161 RelocInfo::IsDebuggerStatement(rmode())); | 160 RelocInfo::IsDebuggerStatement(rmode())); |
| 162 break_index_++; | 161 break_index_++; |
| 163 } | 162 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 182 return BreakLocation(debug_info_, type, code_offset(), position(), | 181 return BreakLocation(debug_info_, type, code_offset(), position(), |
| 183 statement_position()); | 182 statement_position()); |
| 184 } | 183 } |
| 185 | 184 |
| 186 BreakLocation::BytecodeArrayIterator::BytecodeArrayIterator( | 185 BreakLocation::BytecodeArrayIterator::BytecodeArrayIterator( |
| 187 Handle<DebugInfo> debug_info, BreakLocatorType type) | 186 Handle<DebugInfo> debug_info, BreakLocatorType type) |
| 188 : Iterator(debug_info), | 187 : Iterator(debug_info), |
| 189 source_position_iterator_(debug_info->abstract_code() | 188 source_position_iterator_(debug_info->abstract_code() |
| 190 ->GetBytecodeArray() | 189 ->GetBytecodeArray() |
| 191 ->source_position_table()), | 190 ->source_position_table()), |
| 192 break_locator_type_(type), | 191 break_locator_type_(type) { |
| 193 start_position_(debug_info->shared()->start_position()) { | |
| 194 // There is at least one break location. | 192 // There is at least one break location. |
| 195 DCHECK(!Done()); | 193 DCHECK(!Done()); |
| 196 Next(); | 194 Next(); |
| 197 } | 195 } |
| 198 | 196 |
| 199 void BreakLocation::BytecodeArrayIterator::Next() { | 197 void BreakLocation::BytecodeArrayIterator::Next() { |
| 200 DisallowHeapAllocation no_gc; | 198 DisallowHeapAllocation no_gc; |
| 201 DCHECK(!Done()); | 199 DCHECK(!Done()); |
| 202 bool first = break_index_ == -1; | 200 bool first = break_index_ == -1; |
| 203 while (!Done()) { | 201 while (!Done()) { |
| 204 if (!first) source_position_iterator_.Advance(); | 202 if (!first) source_position_iterator_.Advance(); |
| 205 first = false; | 203 first = false; |
| 206 if (Done()) return; | 204 if (Done()) return; |
| 207 position_ = source_position_iterator_.source_position() - start_position_; | 205 position_ = source_position_iterator_.source_position(); |
| 208 if (source_position_iterator_.is_statement()) { | 206 if (source_position_iterator_.is_statement()) { |
| 209 statement_position_ = position_; | 207 statement_position_ = position_; |
| 210 } | 208 } |
| 211 DCHECK(position_ >= 0); | 209 DCHECK(position_ >= 0); |
| 212 DCHECK(statement_position_ >= 0); | 210 DCHECK(statement_position_ >= 0); |
| 213 | 211 |
| 214 enum DebugBreakType type = GetDebugBreakType(); | 212 enum DebugBreakType type = GetDebugBreakType(); |
| 215 if (type == NOT_DEBUG_BREAK) continue; | 213 if (type == NOT_DEBUG_BREAK) continue; |
| 216 | 214 |
| 217 if (break_locator_type_ == ALL_BREAK_LOCATIONS) break; | 215 if (break_locator_type_ == ALL_BREAK_LOCATIONS) break; |
| (...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 799 | 797 |
| 800 // Make sure the function has set up the debug info. | 798 // Make sure the function has set up the debug info. |
| 801 Handle<SharedFunctionInfo> shared = Handle<SharedFunctionInfo>::cast(result); | 799 Handle<SharedFunctionInfo> shared = Handle<SharedFunctionInfo>::cast(result); |
| 802 if (!EnsureDebugInfo(shared, Handle<JSFunction>::null())) { | 800 if (!EnsureDebugInfo(shared, Handle<JSFunction>::null())) { |
| 803 // Return if retrieving debug info failed. | 801 // Return if retrieving debug info failed. |
| 804 return false; | 802 return false; |
| 805 } | 803 } |
| 806 | 804 |
| 807 // Find position within function. The script position might be before the | 805 // Find position within function. The script position might be before the |
| 808 // source position of the first function. | 806 // source position of the first function. |
| 809 int position; | |
| 810 if (shared->start_position() > *source_position) { | 807 if (shared->start_position() > *source_position) { |
| 811 position = 0; | 808 *source_position = shared->start_position(); |
| 812 } else { | |
| 813 position = *source_position - shared->start_position(); | |
| 814 } | 809 } |
| 815 | 810 |
| 816 Handle<DebugInfo> debug_info(shared->GetDebugInfo()); | 811 Handle<DebugInfo> debug_info(shared->GetDebugInfo()); |
| 817 // Source positions starts with zero. | |
| 818 DCHECK(position >= 0); | |
| 819 | 812 |
| 820 // Find the break point and change it. | 813 // Find the break point and change it. |
| 821 BreakLocation location = | 814 BreakLocation location = |
| 822 BreakLocation::FromPosition(debug_info, position, alignment); | 815 BreakLocation::FromPosition(debug_info, *source_position, alignment); |
| 823 location.SetBreakPoint(break_point_object); | 816 location.SetBreakPoint(break_point_object); |
| 824 | 817 |
| 825 feature_tracker()->Track(DebugFeatureTracker::kBreakPoint); | 818 feature_tracker()->Track(DebugFeatureTracker::kBreakPoint); |
| 826 | 819 |
| 827 position = (alignment == STATEMENT_ALIGNED) ? location.statement_position() | 820 *source_position = (alignment == STATEMENT_ALIGNED) |
| 828 : location.position(); | 821 ? location.statement_position() |
| 829 | 822 : location.position(); |
| 830 *source_position = position + shared->start_position(); | |
| 831 | 823 |
| 832 // At least one active break point now. | 824 // At least one active break point now. |
| 833 DCHECK(debug_info->GetBreakPointCount() > 0); | 825 DCHECK(debug_info->GetBreakPointCount() > 0); |
| 834 return true; | 826 return true; |
| 835 } | 827 } |
| 836 | 828 |
| 837 | 829 |
| 838 void Debug::ClearBreakPoint(Handle<Object> break_point_object) { | 830 void Debug::ClearBreakPoint(Handle<Object> break_point_object) { |
| 839 HandleScope scope(isolate_); | 831 HandleScope scope(isolate_); |
| 840 | 832 |
| (...skipping 1751 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2592 } | 2584 } |
| 2593 | 2585 |
| 2594 | 2586 |
| 2595 void LockingCommandMessageQueue::Clear() { | 2587 void LockingCommandMessageQueue::Clear() { |
| 2596 base::LockGuard<base::Mutex> lock_guard(&mutex_); | 2588 base::LockGuard<base::Mutex> lock_guard(&mutex_); |
| 2597 queue_.Clear(); | 2589 queue_.Clear(); |
| 2598 } | 2590 } |
| 2599 | 2591 |
| 2600 } // namespace internal | 2592 } // namespace internal |
| 2601 } // namespace v8 | 2593 } // namespace v8 |
| OLD | NEW |