OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "src/objects/debug-info.h" |
| 6 |
| 7 #include "src/objects-inl.h" |
| 8 |
| 9 namespace v8 { |
| 10 namespace internal { |
| 11 |
| 12 // Check if there is a break point at this source position. |
| 13 bool DebugInfo::HasBreakPoint(int source_position) { |
| 14 // Get the break point info object for this code offset. |
| 15 Object* break_point_info = GetBreakPointInfo(source_position); |
| 16 |
| 17 // If there is no break point info object or no break points in the break |
| 18 // point info object there is no break point at this code offset. |
| 19 if (break_point_info->IsUndefined(GetIsolate())) return false; |
| 20 return BreakPointInfo::cast(break_point_info)->GetBreakPointCount() > 0; |
| 21 } |
| 22 |
| 23 // Get the break point info object for this source position. |
| 24 Object* DebugInfo::GetBreakPointInfo(int source_position) { |
| 25 Isolate* isolate = GetIsolate(); |
| 26 if (!break_points()->IsUndefined(isolate)) { |
| 27 for (int i = 0; i < break_points()->length(); i++) { |
| 28 if (!break_points()->get(i)->IsUndefined(isolate)) { |
| 29 BreakPointInfo* break_point_info = |
| 30 BreakPointInfo::cast(break_points()->get(i)); |
| 31 if (break_point_info->source_position() == source_position) { |
| 32 return break_point_info; |
| 33 } |
| 34 } |
| 35 } |
| 36 } |
| 37 return isolate->heap()->undefined_value(); |
| 38 } |
| 39 |
| 40 bool DebugInfo::ClearBreakPoint(Handle<DebugInfo> debug_info, |
| 41 Handle<Object> break_point_object) { |
| 42 Isolate* isolate = debug_info->GetIsolate(); |
| 43 if (debug_info->break_points()->IsUndefined(isolate)) return false; |
| 44 |
| 45 for (int i = 0; i < debug_info->break_points()->length(); i++) { |
| 46 if (debug_info->break_points()->get(i)->IsUndefined(isolate)) continue; |
| 47 Handle<BreakPointInfo> break_point_info = Handle<BreakPointInfo>( |
| 48 BreakPointInfo::cast(debug_info->break_points()->get(i)), isolate); |
| 49 if (BreakPointInfo::HasBreakPointObject(break_point_info, |
| 50 break_point_object)) { |
| 51 BreakPointInfo::ClearBreakPoint(break_point_info, break_point_object); |
| 52 return true; |
| 53 } |
| 54 } |
| 55 return false; |
| 56 } |
| 57 |
| 58 void DebugInfo::SetBreakPoint(Handle<DebugInfo> debug_info, int source_position, |
| 59 Handle<Object> break_point_object) { |
| 60 Isolate* isolate = debug_info->GetIsolate(); |
| 61 Handle<Object> break_point_info( |
| 62 debug_info->GetBreakPointInfo(source_position), isolate); |
| 63 if (!break_point_info->IsUndefined(isolate)) { |
| 64 BreakPointInfo::SetBreakPoint( |
| 65 Handle<BreakPointInfo>::cast(break_point_info), break_point_object); |
| 66 return; |
| 67 } |
| 68 |
| 69 // Adding a new break point for a code offset which did not have any |
| 70 // break points before. Try to find a free slot. |
| 71 static const int kNoBreakPointInfo = -1; |
| 72 int index = kNoBreakPointInfo; |
| 73 for (int i = 0; i < debug_info->break_points()->length(); i++) { |
| 74 if (debug_info->break_points()->get(i)->IsUndefined(isolate)) { |
| 75 index = i; |
| 76 break; |
| 77 } |
| 78 } |
| 79 if (index == kNoBreakPointInfo) { |
| 80 // No free slot - extend break point info array. |
| 81 Handle<FixedArray> old_break_points = Handle<FixedArray>( |
| 82 FixedArray::cast(debug_info->break_points()), isolate); |
| 83 Handle<FixedArray> new_break_points = isolate->factory()->NewFixedArray( |
| 84 old_break_points->length() + |
| 85 DebugInfo::kEstimatedNofBreakPointsInFunction); |
| 86 |
| 87 debug_info->set_break_points(*new_break_points); |
| 88 for (int i = 0; i < old_break_points->length(); i++) { |
| 89 new_break_points->set(i, old_break_points->get(i)); |
| 90 } |
| 91 index = old_break_points->length(); |
| 92 } |
| 93 DCHECK(index != kNoBreakPointInfo); |
| 94 |
| 95 // Allocate new BreakPointInfo object and set the break point. |
| 96 Handle<BreakPointInfo> new_break_point_info = |
| 97 isolate->factory()->NewBreakPointInfo(source_position); |
| 98 BreakPointInfo::SetBreakPoint(new_break_point_info, break_point_object); |
| 99 debug_info->break_points()->set(index, *new_break_point_info); |
| 100 } |
| 101 |
| 102 // Get the break point objects for a source position. |
| 103 Handle<Object> DebugInfo::GetBreakPointObjects(int source_position) { |
| 104 Object* break_point_info = GetBreakPointInfo(source_position); |
| 105 Isolate* isolate = GetIsolate(); |
| 106 if (break_point_info->IsUndefined(isolate)) { |
| 107 return isolate->factory()->undefined_value(); |
| 108 } |
| 109 return Handle<Object>( |
| 110 BreakPointInfo::cast(break_point_info)->break_point_objects(), isolate); |
| 111 } |
| 112 |
| 113 // Get the total number of break points. |
| 114 int DebugInfo::GetBreakPointCount() { |
| 115 Isolate* isolate = GetIsolate(); |
| 116 if (break_points()->IsUndefined(isolate)) return 0; |
| 117 int count = 0; |
| 118 for (int i = 0; i < break_points()->length(); i++) { |
| 119 if (!break_points()->get(i)->IsUndefined(isolate)) { |
| 120 BreakPointInfo* break_point_info = |
| 121 BreakPointInfo::cast(break_points()->get(i)); |
| 122 count += break_point_info->GetBreakPointCount(); |
| 123 } |
| 124 } |
| 125 return count; |
| 126 } |
| 127 |
| 128 Handle<Object> DebugInfo::FindBreakPointInfo( |
| 129 Handle<DebugInfo> debug_info, Handle<Object> break_point_object) { |
| 130 Isolate* isolate = debug_info->GetIsolate(); |
| 131 if (!debug_info->break_points()->IsUndefined(isolate)) { |
| 132 for (int i = 0; i < debug_info->break_points()->length(); i++) { |
| 133 if (!debug_info->break_points()->get(i)->IsUndefined(isolate)) { |
| 134 Handle<BreakPointInfo> break_point_info = Handle<BreakPointInfo>( |
| 135 BreakPointInfo::cast(debug_info->break_points()->get(i)), isolate); |
| 136 if (BreakPointInfo::HasBreakPointObject(break_point_info, |
| 137 break_point_object)) { |
| 138 return break_point_info; |
| 139 } |
| 140 } |
| 141 } |
| 142 } |
| 143 return isolate->factory()->undefined_value(); |
| 144 } |
| 145 |
| 146 } // namespace internal |
| 147 } // namespace v8 |
OLD | NEW |