| OLD | NEW |
| 1 // Copyright 2017 the V8 project authors. All rights reserved. | 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 | 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/objects/debug-objects.h" | 5 #include "src/objects/debug-objects.h" |
| 6 #include "src/objects/debug-objects-inl.h" | 6 #include "src/objects/debug-objects-inl.h" |
| 7 | 7 |
| 8 namespace v8 { | 8 namespace v8 { |
| 9 namespace internal { | 9 namespace internal { |
| 10 | 10 |
| 11 bool DebugInfo::IsEmpty() const { return flags() == kNone; } |
| 12 |
| 13 bool DebugInfo::HasBreakInfo() const { return (flags() & kHasBreakInfo) != 0; } |
| 14 |
| 15 bool DebugInfo::ClearBreakInfo() { |
| 16 Isolate* isolate = GetIsolate(); |
| 17 |
| 18 set_debug_bytecode_array(isolate->heap()->undefined_value()); |
| 19 set_break_points(isolate->heap()->empty_fixed_array()); |
| 20 |
| 21 int new_flags = flags() & ~kHasBreakInfo; |
| 22 set_flags(new_flags); |
| 23 |
| 24 return new_flags == kNone; |
| 25 } |
| 26 |
| 11 // Check if there is a break point at this source position. | 27 // Check if there is a break point at this source position. |
| 12 bool DebugInfo::HasBreakPoint(int source_position) { | 28 bool DebugInfo::HasBreakPoint(int source_position) { |
| 29 DCHECK(HasBreakInfo()); |
| 13 // Get the break point info object for this code offset. | 30 // Get the break point info object for this code offset. |
| 14 Object* break_point_info = GetBreakPointInfo(source_position); | 31 Object* break_point_info = GetBreakPointInfo(source_position); |
| 15 | 32 |
| 16 // If there is no break point info object or no break points in the break | 33 // If there is no break point info object or no break points in the break |
| 17 // point info object there is no break point at this code offset. | 34 // point info object there is no break point at this code offset. |
| 18 if (break_point_info->IsUndefined(GetIsolate())) return false; | 35 if (break_point_info->IsUndefined(GetIsolate())) return false; |
| 19 return BreakPointInfo::cast(break_point_info)->GetBreakPointCount() > 0; | 36 return BreakPointInfo::cast(break_point_info)->GetBreakPointCount() > 0; |
| 20 } | 37 } |
| 21 | 38 |
| 22 // Get the break point info object for this source position. | 39 // Get the break point info object for this source position. |
| 23 Object* DebugInfo::GetBreakPointInfo(int source_position) { | 40 Object* DebugInfo::GetBreakPointInfo(int source_position) { |
| 41 DCHECK(HasBreakInfo()); |
| 24 Isolate* isolate = GetIsolate(); | 42 Isolate* isolate = GetIsolate(); |
| 25 if (!break_points()->IsUndefined(isolate)) { | 43 if (!break_points()->IsUndefined(isolate)) { |
| 26 for (int i = 0; i < break_points()->length(); i++) { | 44 for (int i = 0; i < break_points()->length(); i++) { |
| 27 if (!break_points()->get(i)->IsUndefined(isolate)) { | 45 if (!break_points()->get(i)->IsUndefined(isolate)) { |
| 28 BreakPointInfo* break_point_info = | 46 BreakPointInfo* break_point_info = |
| 29 BreakPointInfo::cast(break_points()->get(i)); | 47 BreakPointInfo::cast(break_points()->get(i)); |
| 30 if (break_point_info->source_position() == source_position) { | 48 if (break_point_info->source_position() == source_position) { |
| 31 return break_point_info; | 49 return break_point_info; |
| 32 } | 50 } |
| 33 } | 51 } |
| 34 } | 52 } |
| 35 } | 53 } |
| 36 return isolate->heap()->undefined_value(); | 54 return isolate->heap()->undefined_value(); |
| 37 } | 55 } |
| 38 | 56 |
| 39 bool DebugInfo::ClearBreakPoint(Handle<DebugInfo> debug_info, | 57 bool DebugInfo::ClearBreakPoint(Handle<DebugInfo> debug_info, |
| 40 Handle<Object> break_point_object) { | 58 Handle<Object> break_point_object) { |
| 59 DCHECK(debug_info->HasBreakInfo()); |
| 41 Isolate* isolate = debug_info->GetIsolate(); | 60 Isolate* isolate = debug_info->GetIsolate(); |
| 42 if (debug_info->break_points()->IsUndefined(isolate)) return false; | 61 if (debug_info->break_points()->IsUndefined(isolate)) return false; |
| 43 | 62 |
| 44 for (int i = 0; i < debug_info->break_points()->length(); i++) { | 63 for (int i = 0; i < debug_info->break_points()->length(); i++) { |
| 45 if (debug_info->break_points()->get(i)->IsUndefined(isolate)) continue; | 64 if (debug_info->break_points()->get(i)->IsUndefined(isolate)) continue; |
| 46 Handle<BreakPointInfo> break_point_info = Handle<BreakPointInfo>( | 65 Handle<BreakPointInfo> break_point_info = Handle<BreakPointInfo>( |
| 47 BreakPointInfo::cast(debug_info->break_points()->get(i)), isolate); | 66 BreakPointInfo::cast(debug_info->break_points()->get(i)), isolate); |
| 48 if (BreakPointInfo::HasBreakPointObject(break_point_info, | 67 if (BreakPointInfo::HasBreakPointObject(break_point_info, |
| 49 break_point_object)) { | 68 break_point_object)) { |
| 50 BreakPointInfo::ClearBreakPoint(break_point_info, break_point_object); | 69 BreakPointInfo::ClearBreakPoint(break_point_info, break_point_object); |
| 51 return true; | 70 return true; |
| 52 } | 71 } |
| 53 } | 72 } |
| 54 return false; | 73 return false; |
| 55 } | 74 } |
| 56 | 75 |
| 57 void DebugInfo::SetBreakPoint(Handle<DebugInfo> debug_info, int source_position, | 76 void DebugInfo::SetBreakPoint(Handle<DebugInfo> debug_info, int source_position, |
| 58 Handle<Object> break_point_object) { | 77 Handle<Object> break_point_object) { |
| 78 DCHECK(debug_info->HasBreakInfo()); |
| 59 Isolate* isolate = debug_info->GetIsolate(); | 79 Isolate* isolate = debug_info->GetIsolate(); |
| 60 Handle<Object> break_point_info( | 80 Handle<Object> break_point_info( |
| 61 debug_info->GetBreakPointInfo(source_position), isolate); | 81 debug_info->GetBreakPointInfo(source_position), isolate); |
| 62 if (!break_point_info->IsUndefined(isolate)) { | 82 if (!break_point_info->IsUndefined(isolate)) { |
| 63 BreakPointInfo::SetBreakPoint( | 83 BreakPointInfo::SetBreakPoint( |
| 64 Handle<BreakPointInfo>::cast(break_point_info), break_point_object); | 84 Handle<BreakPointInfo>::cast(break_point_info), break_point_object); |
| 65 return; | 85 return; |
| 66 } | 86 } |
| 67 | 87 |
| 68 // Adding a new break point for a code offset which did not have any | 88 // Adding a new break point for a code offset which did not have any |
| (...skipping 24 matching lines...) Expand all Loading... |
| 93 | 113 |
| 94 // Allocate new BreakPointInfo object and set the break point. | 114 // Allocate new BreakPointInfo object and set the break point. |
| 95 Handle<BreakPointInfo> new_break_point_info = | 115 Handle<BreakPointInfo> new_break_point_info = |
| 96 isolate->factory()->NewBreakPointInfo(source_position); | 116 isolate->factory()->NewBreakPointInfo(source_position); |
| 97 BreakPointInfo::SetBreakPoint(new_break_point_info, break_point_object); | 117 BreakPointInfo::SetBreakPoint(new_break_point_info, break_point_object); |
| 98 debug_info->break_points()->set(index, *new_break_point_info); | 118 debug_info->break_points()->set(index, *new_break_point_info); |
| 99 } | 119 } |
| 100 | 120 |
| 101 // Get the break point objects for a source position. | 121 // Get the break point objects for a source position. |
| 102 Handle<Object> DebugInfo::GetBreakPointObjects(int source_position) { | 122 Handle<Object> DebugInfo::GetBreakPointObjects(int source_position) { |
| 123 DCHECK(HasBreakInfo()); |
| 103 Object* break_point_info = GetBreakPointInfo(source_position); | 124 Object* break_point_info = GetBreakPointInfo(source_position); |
| 104 Isolate* isolate = GetIsolate(); | 125 Isolate* isolate = GetIsolate(); |
| 105 if (break_point_info->IsUndefined(isolate)) { | 126 if (break_point_info->IsUndefined(isolate)) { |
| 106 return isolate->factory()->undefined_value(); | 127 return isolate->factory()->undefined_value(); |
| 107 } | 128 } |
| 108 return Handle<Object>( | 129 return Handle<Object>( |
| 109 BreakPointInfo::cast(break_point_info)->break_point_objects(), isolate); | 130 BreakPointInfo::cast(break_point_info)->break_point_objects(), isolate); |
| 110 } | 131 } |
| 111 | 132 |
| 112 // Get the total number of break points. | 133 // Get the total number of break points. |
| 113 int DebugInfo::GetBreakPointCount() { | 134 int DebugInfo::GetBreakPointCount() { |
| 135 DCHECK(HasBreakInfo()); |
| 114 Isolate* isolate = GetIsolate(); | 136 Isolate* isolate = GetIsolate(); |
| 115 if (break_points()->IsUndefined(isolate)) return 0; | 137 if (break_points()->IsUndefined(isolate)) return 0; |
| 116 int count = 0; | 138 int count = 0; |
| 117 for (int i = 0; i < break_points()->length(); i++) { | 139 for (int i = 0; i < break_points()->length(); i++) { |
| 118 if (!break_points()->get(i)->IsUndefined(isolate)) { | 140 if (!break_points()->get(i)->IsUndefined(isolate)) { |
| 119 BreakPointInfo* break_point_info = | 141 BreakPointInfo* break_point_info = |
| 120 BreakPointInfo::cast(break_points()->get(i)); | 142 BreakPointInfo::cast(break_points()->get(i)); |
| 121 count += break_point_info->GetBreakPointCount(); | 143 count += break_point_info->GetBreakPointCount(); |
| 122 } | 144 } |
| 123 } | 145 } |
| 124 return count; | 146 return count; |
| 125 } | 147 } |
| 126 | 148 |
| 127 Handle<Object> DebugInfo::FindBreakPointInfo( | 149 Handle<Object> DebugInfo::FindBreakPointInfo( |
| 128 Handle<DebugInfo> debug_info, Handle<Object> break_point_object) { | 150 Handle<DebugInfo> debug_info, Handle<Object> break_point_object) { |
| 151 DCHECK(debug_info->HasBreakInfo()); |
| 129 Isolate* isolate = debug_info->GetIsolate(); | 152 Isolate* isolate = debug_info->GetIsolate(); |
| 130 if (!debug_info->break_points()->IsUndefined(isolate)) { | 153 if (!debug_info->break_points()->IsUndefined(isolate)) { |
| 131 for (int i = 0; i < debug_info->break_points()->length(); i++) { | 154 for (int i = 0; i < debug_info->break_points()->length(); i++) { |
| 132 if (!debug_info->break_points()->get(i)->IsUndefined(isolate)) { | 155 if (!debug_info->break_points()->get(i)->IsUndefined(isolate)) { |
| 133 Handle<BreakPointInfo> break_point_info = Handle<BreakPointInfo>( | 156 Handle<BreakPointInfo> break_point_info = Handle<BreakPointInfo>( |
| 134 BreakPointInfo::cast(debug_info->break_points()->get(i)), isolate); | 157 BreakPointInfo::cast(debug_info->break_points()->get(i)), isolate); |
| 135 if (BreakPointInfo::HasBreakPointObject(break_point_info, | 158 if (BreakPointInfo::HasBreakPointObject(break_point_info, |
| 136 break_point_object)) { | 159 break_point_object)) { |
| 137 return break_point_info; | 160 return break_point_info; |
| 138 } | 161 } |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 // No break point. | 260 // No break point. |
| 238 if (break_point_objects()->IsUndefined(GetIsolate())) return 0; | 261 if (break_point_objects()->IsUndefined(GetIsolate())) return 0; |
| 239 // Single break point. | 262 // Single break point. |
| 240 if (!break_point_objects()->IsFixedArray()) return 1; | 263 if (!break_point_objects()->IsFixedArray()) return 1; |
| 241 // Multiple break points. | 264 // Multiple break points. |
| 242 return FixedArray::cast(break_point_objects())->length(); | 265 return FixedArray::cast(break_point_objects())->length(); |
| 243 } | 266 } |
| 244 | 267 |
| 245 } // namespace internal | 268 } // namespace internal |
| 246 } // namespace v8 | 269 } // namespace v8 |
| OLD | NEW |