Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: src/debug.cc

Issue 18349004: Debug: support breakpoints set in the middle of statement (try #2 after rollback) (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/debug.h ('k') | src/debug-debugger.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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) {
239 // Run through all break points to locate the one closest to the source 240 // Run through all break points to locate the one closest to the source
240 // position. 241 // position.
241 int closest_break_point = 0; 242 int closest_break_point = 0;
242 int distance = kMaxInt; 243 int distance = kMaxInt;
244
243 while (!Done()) { 245 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 }
244 // Check if this break point is closer that what was previously found. 258 // Check if this break point is closer that what was previously found.
245 if (position <= statement_position() && 259 if (position <= next_position && next_position - position < distance) {
246 statement_position() - position < distance) {
247 closest_break_point = break_point(); 260 closest_break_point = break_point();
248 distance = statement_position() - position; 261 distance = next_position - position;
249 // Check whether we can't get any closer. 262 // Check whether we can't get any closer.
250 if (distance == 0) break; 263 if (distance == 0) break;
251 } 264 }
252 Next(); 265 Next();
253 } 266 }
254 267
255 // Move to the break point found. 268 // Move to the break point found.
256 Reset(); 269 Reset();
257 Next(closest_break_point); 270 Next(closest_break_point);
258 } 271 }
(...skipping 924 matching lines...) Expand 10 before | Expand all | Expand 10 after
1183 // Return if retrieving debug info failed. 1196 // Return if retrieving debug info failed.
1184 return; 1197 return;
1185 } 1198 }
1186 1199
1187 Handle<DebugInfo> debug_info = GetDebugInfo(shared); 1200 Handle<DebugInfo> debug_info = GetDebugInfo(shared);
1188 // Source positions starts with zero. 1201 // Source positions starts with zero.
1189 ASSERT(*source_position >= 0); 1202 ASSERT(*source_position >= 0);
1190 1203
1191 // Find the break point and change it. 1204 // Find the break point and change it.
1192 BreakLocationIterator it(debug_info, SOURCE_BREAK_LOCATIONS); 1205 BreakLocationIterator it(debug_info, SOURCE_BREAK_LOCATIONS);
1193 it.FindBreakLocationFromPosition(*source_position); 1206 it.FindBreakLocationFromPosition(*source_position, STATEMENT_ALIGNED);
1194 it.SetBreakPoint(break_point_object); 1207 it.SetBreakPoint(break_point_object);
1195 1208
1196 *source_position = it.position(); 1209 *source_position = it.position();
1197 1210
1198 // At least one active break point now. 1211 // At least one active break point now.
1199 ASSERT(debug_info->GetBreakPointCount() > 0); 1212 ASSERT(debug_info->GetBreakPointCount() > 0);
1200 } 1213 }
1201 1214
1202 1215
1203 bool Debug::SetBreakPointForScript(Handle<Script> script, 1216 bool Debug::SetBreakPointForScript(Handle<Script> script,
1204 Handle<Object> break_point_object, 1217 Handle<Object> break_point_object,
1205 int* source_position) { 1218 int* source_position,
1219 BreakPositionAlignment alignment) {
1206 HandleScope scope(isolate_); 1220 HandleScope scope(isolate_);
1207 1221
1208 PrepareForBreakPoints(); 1222 PrepareForBreakPoints();
1209 1223
1210 // Obtain shared function info for the function. 1224 // Obtain shared function info for the function.
1211 Object* result = FindSharedFunctionInfoInScript(script, *source_position); 1225 Object* result = FindSharedFunctionInfoInScript(script, *source_position);
1212 if (result->IsUndefined()) return false; 1226 if (result->IsUndefined()) return false;
1213 1227
1214 // Make sure the function has set up the debug info. 1228 // Make sure the function has set up the debug info.
1215 Handle<SharedFunctionInfo> shared(SharedFunctionInfo::cast(result)); 1229 Handle<SharedFunctionInfo> shared(SharedFunctionInfo::cast(result));
(...skipping 10 matching lines...) Expand all
1226 } else { 1240 } else {
1227 position = *source_position - shared->start_position(); 1241 position = *source_position - shared->start_position();
1228 } 1242 }
1229 1243
1230 Handle<DebugInfo> debug_info = GetDebugInfo(shared); 1244 Handle<DebugInfo> debug_info = GetDebugInfo(shared);
1231 // Source positions starts with zero. 1245 // Source positions starts with zero.
1232 ASSERT(position >= 0); 1246 ASSERT(position >= 0);
1233 1247
1234 // Find the break point and change it. 1248 // Find the break point and change it.
1235 BreakLocationIterator it(debug_info, SOURCE_BREAK_LOCATIONS); 1249 BreakLocationIterator it(debug_info, SOURCE_BREAK_LOCATIONS);
1236 it.FindBreakLocationFromPosition(position); 1250 it.FindBreakLocationFromPosition(position, alignment);
1237 it.SetBreakPoint(break_point_object); 1251 it.SetBreakPoint(break_point_object);
1238 1252
1239 *source_position = it.position() + shared->start_position(); 1253 *source_position = it.position() + shared->start_position();
1240 1254
1241 // At least one active break point now. 1255 // At least one active break point now.
1242 ASSERT(debug_info->GetBreakPointCount() > 0); 1256 ASSERT(debug_info->GetBreakPointCount() > 0);
1243 return true; 1257 return true;
1244 } 1258 }
1245 1259
1246 1260
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
1680 } 1694 }
1681 } 1695 }
1682 1696
1683 UNREACHABLE(); 1697 UNREACHABLE();
1684 return Handle<Code>::null(); 1698 return Handle<Code>::null();
1685 } 1699 }
1686 1700
1687 1701
1688 // Simple function for returning the source positions for active break points. 1702 // Simple function for returning the source positions for active break points.
1689 Handle<Object> Debug::GetSourceBreakLocations( 1703 Handle<Object> Debug::GetSourceBreakLocations(
1690 Handle<SharedFunctionInfo> shared) { 1704 Handle<SharedFunctionInfo> shared,
1705 BreakPositionAlignment position_alignment) {
1691 Isolate* isolate = Isolate::Current(); 1706 Isolate* isolate = Isolate::Current();
1692 Heap* heap = isolate->heap(); 1707 Heap* heap = isolate->heap();
1693 if (!HasDebugInfo(shared)) { 1708 if (!HasDebugInfo(shared)) {
1694 return Handle<Object>(heap->undefined_value(), isolate); 1709 return Handle<Object>(heap->undefined_value(), isolate);
1695 } 1710 }
1696 Handle<DebugInfo> debug_info = GetDebugInfo(shared); 1711 Handle<DebugInfo> debug_info = GetDebugInfo(shared);
1697 if (debug_info->GetBreakPointCount() == 0) { 1712 if (debug_info->GetBreakPointCount() == 0) {
1698 return Handle<Object>(heap->undefined_value(), isolate); 1713 return Handle<Object>(heap->undefined_value(), isolate);
1699 } 1714 }
1700 Handle<FixedArray> locations = 1715 Handle<FixedArray> locations =
1701 isolate->factory()->NewFixedArray(debug_info->GetBreakPointCount()); 1716 isolate->factory()->NewFixedArray(debug_info->GetBreakPointCount());
1702 int count = 0; 1717 int count = 0;
1703 for (int i = 0; i < debug_info->break_points()->length(); i++) { 1718 for (int i = 0; i < debug_info->break_points()->length(); i++) {
1704 if (!debug_info->break_points()->get(i)->IsUndefined()) { 1719 if (!debug_info->break_points()->get(i)->IsUndefined()) {
1705 BreakPointInfo* break_point_info = 1720 BreakPointInfo* break_point_info =
1706 BreakPointInfo::cast(debug_info->break_points()->get(i)); 1721 BreakPointInfo::cast(debug_info->break_points()->get(i));
1707 if (break_point_info->GetBreakPointCount() > 0) { 1722 if (break_point_info->GetBreakPointCount() > 0) {
1708 locations->set(count++, break_point_info->statement_position()); 1723 Smi* 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);
1709 } 1737 }
1710 } 1738 }
1711 } 1739 }
1712 return locations; 1740 return locations;
1713 } 1741 }
1714 1742
1715 1743
1716 void Debug::NewBreak(StackFrame::Id break_frame_id) { 1744 void Debug::NewBreak(StackFrame::Id break_frame_id) {
1717 thread_local_.break_frame_id_ = break_frame_id; 1745 thread_local_.break_frame_id_ = break_frame_id;
1718 thread_local_.break_id_ = ++thread_local_.break_count_; 1746 thread_local_.break_id_ = ++thread_local_.break_count_;
(...skipping 2112 matching lines...) Expand 10 before | Expand all | Expand 10 after
3831 { 3859 {
3832 Locker locker(reinterpret_cast<v8::Isolate*>(isolate_)); 3860 Locker locker(reinterpret_cast<v8::Isolate*>(isolate_));
3833 isolate_->debugger()->CallMessageDispatchHandler(); 3861 isolate_->debugger()->CallMessageDispatchHandler();
3834 } 3862 }
3835 } 3863 }
3836 } 3864 }
3837 3865
3838 #endif // ENABLE_DEBUGGER_SUPPORT 3866 #endif // ENABLE_DEBUGGER_SUPPORT
3839 3867
3840 } } // namespace v8::internal 3868 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/debug.h ('k') | src/debug-debugger.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698