OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 Next(); | 228 Next(); |
229 } | 229 } |
230 | 230 |
231 // Move to the break point found. | 231 // Move to the break point found. |
232 Reset(); | 232 Reset(); |
233 Next(closest_break_point); | 233 Next(closest_break_point); |
234 } | 234 } |
235 | 235 |
236 | 236 |
237 // Find the break point closest to the supplied source position. | 237 // Find the break point closest to the supplied source position. |
238 void BreakLocationIterator::FindBreakLocationFromPosition(int position, | 238 void BreakLocationIterator::FindBreakLocationFromPosition(int position) { |
239 BreakPositionAlignment alignment) { | |
240 // Run through all break points to locate the one closest to the source | 239 // Run through all break points to locate the one closest to the source |
241 // position. | 240 // position. |
242 int closest_break_point = 0; | 241 int closest_break_point = 0; |
243 int distance = kMaxInt; | 242 int distance = kMaxInt; |
244 | |
245 while (!Done()) { | 243 while (!Done()) { |
246 int next_position; | |
247 switch (alignment) { | |
248 case STATEMENT_ALIGNED: | |
249 next_position = this->statement_position(); | |
250 break; | |
251 case BREAK_POSITION_ALIGNED: | |
252 next_position = this->position(); | |
253 break; | |
254 default: | |
255 UNREACHABLE(); | |
256 next_position = this->statement_position(); | |
257 } | |
258 // Check if this break point is closer that what was previously found. | 244 // Check if this break point is closer that what was previously found. |
259 if (position <= next_position && next_position - position < distance) { | 245 if (position <= statement_position() && |
| 246 statement_position() - position < distance) { |
260 closest_break_point = break_point(); | 247 closest_break_point = break_point(); |
261 distance = next_position - position; | 248 distance = statement_position() - position; |
262 // Check whether we can't get any closer. | 249 // Check whether we can't get any closer. |
263 if (distance == 0) break; | 250 if (distance == 0) break; |
264 } | 251 } |
265 Next(); | 252 Next(); |
266 } | 253 } |
267 | 254 |
268 // Move to the break point found. | 255 // Move to the break point found. |
269 Reset(); | 256 Reset(); |
270 Next(closest_break_point); | 257 Next(closest_break_point); |
271 } | 258 } |
(...skipping 924 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1196 // Return if retrieving debug info failed. | 1183 // Return if retrieving debug info failed. |
1197 return; | 1184 return; |
1198 } | 1185 } |
1199 | 1186 |
1200 Handle<DebugInfo> debug_info = GetDebugInfo(shared); | 1187 Handle<DebugInfo> debug_info = GetDebugInfo(shared); |
1201 // Source positions starts with zero. | 1188 // Source positions starts with zero. |
1202 ASSERT(*source_position >= 0); | 1189 ASSERT(*source_position >= 0); |
1203 | 1190 |
1204 // Find the break point and change it. | 1191 // Find the break point and change it. |
1205 BreakLocationIterator it(debug_info, SOURCE_BREAK_LOCATIONS); | 1192 BreakLocationIterator it(debug_info, SOURCE_BREAK_LOCATIONS); |
1206 it.FindBreakLocationFromPosition(*source_position, STATEMENT_ALIGNED); | 1193 it.FindBreakLocationFromPosition(*source_position); |
1207 it.SetBreakPoint(break_point_object); | 1194 it.SetBreakPoint(break_point_object); |
1208 | 1195 |
1209 *source_position = it.position(); | 1196 *source_position = it.position(); |
1210 | 1197 |
1211 // At least one active break point now. | 1198 // At least one active break point now. |
1212 ASSERT(debug_info->GetBreakPointCount() > 0); | 1199 ASSERT(debug_info->GetBreakPointCount() > 0); |
1213 } | 1200 } |
1214 | 1201 |
1215 | 1202 |
1216 bool Debug::SetBreakPointForScript(Handle<Script> script, | 1203 bool Debug::SetBreakPointForScript(Handle<Script> script, |
1217 Handle<Object> break_point_object, | 1204 Handle<Object> break_point_object, |
1218 int* source_position, | 1205 int* source_position) { |
1219 BreakPositionAlignment alignment) { | |
1220 HandleScope scope(isolate_); | 1206 HandleScope scope(isolate_); |
1221 | 1207 |
1222 PrepareForBreakPoints(); | 1208 PrepareForBreakPoints(); |
1223 | 1209 |
1224 // Obtain shared function info for the function. | 1210 // Obtain shared function info for the function. |
1225 Object* result = FindSharedFunctionInfoInScript(script, *source_position); | 1211 Object* result = FindSharedFunctionInfoInScript(script, *source_position); |
1226 if (result->IsUndefined()) return false; | 1212 if (result->IsUndefined()) return false; |
1227 | 1213 |
1228 // Make sure the function has set up the debug info. | 1214 // Make sure the function has set up the debug info. |
1229 Handle<SharedFunctionInfo> shared(SharedFunctionInfo::cast(result)); | 1215 Handle<SharedFunctionInfo> shared(SharedFunctionInfo::cast(result)); |
(...skipping 10 matching lines...) Expand all Loading... |
1240 } else { | 1226 } else { |
1241 position = *source_position - shared->start_position(); | 1227 position = *source_position - shared->start_position(); |
1242 } | 1228 } |
1243 | 1229 |
1244 Handle<DebugInfo> debug_info = GetDebugInfo(shared); | 1230 Handle<DebugInfo> debug_info = GetDebugInfo(shared); |
1245 // Source positions starts with zero. | 1231 // Source positions starts with zero. |
1246 ASSERT(position >= 0); | 1232 ASSERT(position >= 0); |
1247 | 1233 |
1248 // Find the break point and change it. | 1234 // Find the break point and change it. |
1249 BreakLocationIterator it(debug_info, SOURCE_BREAK_LOCATIONS); | 1235 BreakLocationIterator it(debug_info, SOURCE_BREAK_LOCATIONS); |
1250 it.FindBreakLocationFromPosition(position, alignment); | 1236 it.FindBreakLocationFromPosition(position); |
1251 it.SetBreakPoint(break_point_object); | 1237 it.SetBreakPoint(break_point_object); |
1252 | 1238 |
1253 *source_position = it.position() + shared->start_position(); | 1239 *source_position = it.position() + shared->start_position(); |
1254 | 1240 |
1255 // At least one active break point now. | 1241 // At least one active break point now. |
1256 ASSERT(debug_info->GetBreakPointCount() > 0); | 1242 ASSERT(debug_info->GetBreakPointCount() > 0); |
1257 return true; | 1243 return true; |
1258 } | 1244 } |
1259 | 1245 |
1260 | 1246 |
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1694 } | 1680 } |
1695 } | 1681 } |
1696 | 1682 |
1697 UNREACHABLE(); | 1683 UNREACHABLE(); |
1698 return Handle<Code>::null(); | 1684 return Handle<Code>::null(); |
1699 } | 1685 } |
1700 | 1686 |
1701 | 1687 |
1702 // Simple function for returning the source positions for active break points. | 1688 // Simple function for returning the source positions for active break points. |
1703 Handle<Object> Debug::GetSourceBreakLocations( | 1689 Handle<Object> Debug::GetSourceBreakLocations( |
1704 Handle<SharedFunctionInfo> shared, | 1690 Handle<SharedFunctionInfo> shared) { |
1705 BreakPositionAlignment position_alignment) { | |
1706 Isolate* isolate = Isolate::Current(); | 1691 Isolate* isolate = Isolate::Current(); |
1707 Heap* heap = isolate->heap(); | 1692 Heap* heap = isolate->heap(); |
1708 if (!HasDebugInfo(shared)) { | 1693 if (!HasDebugInfo(shared)) { |
1709 return Handle<Object>(heap->undefined_value(), isolate); | 1694 return Handle<Object>(heap->undefined_value(), isolate); |
1710 } | 1695 } |
1711 Handle<DebugInfo> debug_info = GetDebugInfo(shared); | 1696 Handle<DebugInfo> debug_info = GetDebugInfo(shared); |
1712 if (debug_info->GetBreakPointCount() == 0) { | 1697 if (debug_info->GetBreakPointCount() == 0) { |
1713 return Handle<Object>(heap->undefined_value(), isolate); | 1698 return Handle<Object>(heap->undefined_value(), isolate); |
1714 } | 1699 } |
1715 Handle<FixedArray> locations = | 1700 Handle<FixedArray> locations = |
1716 isolate->factory()->NewFixedArray(debug_info->GetBreakPointCount()); | 1701 isolate->factory()->NewFixedArray(debug_info->GetBreakPointCount()); |
1717 int count = 0; | 1702 int count = 0; |
1718 for (int i = 0; i < debug_info->break_points()->length(); i++) { | 1703 for (int i = 0; i < debug_info->break_points()->length(); i++) { |
1719 if (!debug_info->break_points()->get(i)->IsUndefined()) { | 1704 if (!debug_info->break_points()->get(i)->IsUndefined()) { |
1720 BreakPointInfo* break_point_info = | 1705 BreakPointInfo* break_point_info = |
1721 BreakPointInfo::cast(debug_info->break_points()->get(i)); | 1706 BreakPointInfo::cast(debug_info->break_points()->get(i)); |
1722 if (break_point_info->GetBreakPointCount() > 0) { | 1707 if (break_point_info->GetBreakPointCount() > 0) { |
1723 Smi* position; | 1708 locations->set(count++, break_point_info->statement_position()); |
1724 switch (position_alignment) { | |
1725 case STATEMENT_ALIGNED: | |
1726 position = break_point_info->statement_position(); | |
1727 break; | |
1728 case BREAK_POSITION_ALIGNED: | |
1729 position = break_point_info->source_position(); | |
1730 break; | |
1731 default: | |
1732 UNREACHABLE(); | |
1733 position = break_point_info->statement_position(); | |
1734 } | |
1735 | |
1736 locations->set(count++, position); | |
1737 } | 1709 } |
1738 } | 1710 } |
1739 } | 1711 } |
1740 return locations; | 1712 return locations; |
1741 } | 1713 } |
1742 | 1714 |
1743 | 1715 |
1744 void Debug::NewBreak(StackFrame::Id break_frame_id) { | 1716 void Debug::NewBreak(StackFrame::Id break_frame_id) { |
1745 thread_local_.break_frame_id_ = break_frame_id; | 1717 thread_local_.break_frame_id_ = break_frame_id; |
1746 thread_local_.break_id_ = ++thread_local_.break_count_; | 1718 thread_local_.break_id_ = ++thread_local_.break_count_; |
(...skipping 2112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3859 { | 3831 { |
3860 Locker locker(reinterpret_cast<v8::Isolate*>(isolate_)); | 3832 Locker locker(reinterpret_cast<v8::Isolate*>(isolate_)); |
3861 isolate_->debugger()->CallMessageDispatchHandler(); | 3833 isolate_->debugger()->CallMessageDispatchHandler(); |
3862 } | 3834 } |
3863 } | 3835 } |
3864 } | 3836 } |
3865 | 3837 |
3866 #endif // ENABLE_DEBUGGER_SUPPORT | 3838 #endif // ENABLE_DEBUGGER_SUPPORT |
3867 | 3839 |
3868 } } // namespace v8::internal | 3840 } } // namespace v8::internal |
OLD | NEW |