OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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/wasm/wasm-debug.h" | 5 #include "src/wasm/wasm-debug.h" |
6 | 6 |
7 #include "src/assert-scope.h" | 7 #include "src/assert-scope.h" |
8 #include "src/debug/debug.h" | 8 #include "src/debug/debug.h" |
9 #include "src/factory.h" | 9 #include "src/factory.h" |
10 #include "src/isolate.h" | 10 #include "src/isolate.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 kWasmDebugInfoNumEntries | 24 kWasmDebugInfoNumEntries |
25 }; | 25 }; |
26 | 26 |
27 ByteArray *GetOrCreateFunctionOffsetTable(Handle<WasmDebugInfo> debug_info) { | 27 ByteArray *GetOrCreateFunctionOffsetTable(Handle<WasmDebugInfo> debug_info) { |
28 Object *offset_table = debug_info->get(kWasmDebugInfoFunctionByteOffsets); | 28 Object *offset_table = debug_info->get(kWasmDebugInfoFunctionByteOffsets); |
29 Isolate *isolate = debug_info->GetIsolate(); | 29 Isolate *isolate = debug_info->GetIsolate(); |
30 if (!offset_table->IsUndefined(isolate)) return ByteArray::cast(offset_table); | 30 if (!offset_table->IsUndefined(isolate)) return ByteArray::cast(offset_table); |
31 | 31 |
32 FunctionOffsetsResult function_offsets; | 32 FunctionOffsetsResult function_offsets; |
33 { | 33 { |
34 DisallowHeapAllocation no_gc; | |
35 Handle<JSObject> wasm_object(debug_info->wasm_object(), isolate); | 34 Handle<JSObject> wasm_object(debug_info->wasm_object(), isolate); |
36 uint32_t num_imported_functions = | 35 uint32_t num_imported_functions = |
37 wasm::GetNumImportedFunctions(wasm_object); | 36 static_cast<uint32_t>(wasm::GetNumImportedFunctions(wasm_object)); |
38 SeqOneByteString *wasm_bytes = | 37 Handle<SeqOneByteString> wasm_bytes = wasm::GetWasmBytes(wasm_object); |
39 wasm::GetWasmBytes(debug_info->wasm_object()); | 38 DisallowHeapAllocation no_gc; |
40 const byte *bytes_start = wasm_bytes->GetChars(); | 39 const byte *bytes_start = wasm_bytes->GetChars(); |
41 const byte *bytes_end = bytes_start + wasm_bytes->length(); | 40 const byte *bytes_end = bytes_start + wasm_bytes->length(); |
42 function_offsets = wasm::DecodeWasmFunctionOffsets(bytes_start, bytes_end, | 41 function_offsets = wasm::DecodeWasmFunctionOffsets(bytes_start, bytes_end, |
43 num_imported_functions); | 42 num_imported_functions); |
44 } | 43 } |
45 DCHECK(function_offsets.ok()); | 44 DCHECK(function_offsets.ok()); |
46 size_t array_size = 2 * kIntSize * function_offsets.val.size(); | 45 size_t array_size = 2 * kIntSize * function_offsets.val.size(); |
47 CHECK_LE(array_size, static_cast<size_t>(kMaxInt)); | 46 CHECK_LE(array_size, static_cast<size_t>(kMaxInt)); |
48 ByteArray *arr = | 47 ByteArray *arr = |
49 *isolate->factory()->NewByteArray(static_cast<int>(array_size)); | 48 *isolate->factory()->NewByteArray(static_cast<int>(array_size)); |
(...skipping 15 matching lines...) Expand all Loading... |
65 | 64 |
66 int offset = arr->get_int(2 * func_index); | 65 int offset = arr->get_int(2 * func_index); |
67 int length = arr->get_int(2 * func_index + 1); | 66 int length = arr->get_int(2 * func_index + 1); |
68 // Assert that it's distinguishable from the "illegal function index" return. | 67 // Assert that it's distinguishable from the "illegal function index" return. |
69 DCHECK(offset > 0 && length > 0); | 68 DCHECK(offset > 0 && length > 0); |
70 return {offset, length}; | 69 return {offset, length}; |
71 } | 70 } |
72 | 71 |
73 Vector<const uint8_t> GetFunctionBytes(Handle<WasmDebugInfo> debug_info, | 72 Vector<const uint8_t> GetFunctionBytes(Handle<WasmDebugInfo> debug_info, |
74 int func_index) { | 73 int func_index) { |
75 SeqOneByteString *module_bytes = | 74 Handle<JSObject> wasm_object(debug_info->wasm_object()); |
76 wasm::GetWasmBytes(debug_info->wasm_object()); | 75 Handle<SeqOneByteString> module_bytes = wasm::GetWasmBytes(wasm_object); |
77 std::pair<int, int> offset_and_length = | 76 std::pair<int, int> offset_and_length = |
78 GetFunctionOffsetAndLength(debug_info, func_index); | 77 GetFunctionOffsetAndLength(debug_info, func_index); |
79 return Vector<const uint8_t>( | 78 return Vector<const uint8_t>( |
80 module_bytes->GetChars() + offset_and_length.first, | 79 module_bytes->GetChars() + offset_and_length.first, |
81 offset_and_length.second); | 80 offset_and_length.second); |
82 } | 81 } |
83 | 82 |
84 } // namespace | 83 } // namespace |
85 | 84 |
86 Handle<WasmDebugInfo> WasmDebugInfo::New(Handle<JSObject> wasm) { | 85 Handle<WasmDebugInfo> WasmDebugInfo::New(Handle<JSObject> wasm) { |
87 Isolate *isolate = wasm->GetIsolate(); | 86 Isolate *isolate = wasm->GetIsolate(); |
88 Factory *factory = isolate->factory(); | 87 Factory *factory = isolate->factory(); |
89 Handle<FixedArray> arr = | 88 Handle<FixedArray> arr = |
90 factory->NewFixedArray(kWasmDebugInfoNumEntries, TENURED); | 89 factory->NewFixedArray(kWasmDebugInfoNumEntries, TENURED); |
91 arr->set(kWasmDebugInfoWasmObj, *wasm); | 90 arr->set(kWasmDebugInfoWasmObj, *wasm); |
92 int hash = 0; | 91 int hash = 0; |
93 Handle<SeqOneByteString> wasm_bytes(GetWasmBytes(*wasm), isolate); | 92 Handle<SeqOneByteString> wasm_bytes = GetWasmBytes(wasm); |
94 { | 93 { |
95 DisallowHeapAllocation no_gc; | 94 DisallowHeapAllocation no_gc; |
96 hash = StringHasher::HashSequentialString( | 95 hash = StringHasher::HashSequentialString( |
97 wasm_bytes->GetChars(), wasm_bytes->length(), kZeroHashSeed); | 96 wasm_bytes->GetChars(), wasm_bytes->length(), kZeroHashSeed); |
98 } | 97 } |
99 Handle<Object> hash_obj = factory->NewNumberFromInt(hash, TENURED); | 98 Handle<Object> hash_obj = factory->NewNumberFromInt(hash, TENURED); |
100 arr->set(kWasmDebugInfoWasmBytesHash, *hash_obj); | 99 arr->set(kWasmDebugInfoWasmBytesHash, *hash_obj); |
101 | 100 |
102 return Handle<WasmDebugInfo>::cast(arr); | 101 return Handle<WasmDebugInfo>::cast(arr); |
103 } | 102 } |
(...skipping 19 matching lines...) Expand all Loading... |
123 JSObject *WasmDebugInfo::wasm_object() { | 122 JSObject *WasmDebugInfo::wasm_object() { |
124 return JSObject::cast(get(kWasmDebugInfoWasmObj)); | 123 return JSObject::cast(get(kWasmDebugInfoWasmObj)); |
125 } | 124 } |
126 | 125 |
127 Script *WasmDebugInfo::GetFunctionScript(Handle<WasmDebugInfo> debug_info, | 126 Script *WasmDebugInfo::GetFunctionScript(Handle<WasmDebugInfo> debug_info, |
128 int func_index) { | 127 int func_index) { |
129 Isolate *isolate = debug_info->GetIsolate(); | 128 Isolate *isolate = debug_info->GetIsolate(); |
130 Object *scripts_obj = debug_info->get(kWasmDebugInfoFunctionScripts); | 129 Object *scripts_obj = debug_info->get(kWasmDebugInfoFunctionScripts); |
131 Handle<FixedArray> scripts; | 130 Handle<FixedArray> scripts; |
132 if (scripts_obj->IsUndefined(isolate)) { | 131 if (scripts_obj->IsUndefined(isolate)) { |
133 int num_functions = wasm::GetNumberOfFunctions(debug_info->wasm_object()); | 132 Handle<JSObject> wasm_object(debug_info->wasm_object(), isolate); |
| 133 int num_functions = wasm::GetNumberOfFunctions(wasm_object); |
134 scripts = isolate->factory()->NewFixedArray(num_functions, TENURED); | 134 scripts = isolate->factory()->NewFixedArray(num_functions, TENURED); |
135 debug_info->set(kWasmDebugInfoFunctionScripts, *scripts); | 135 debug_info->set(kWasmDebugInfoFunctionScripts, *scripts); |
136 } else { | 136 } else { |
137 scripts = handle(FixedArray::cast(scripts_obj), isolate); | 137 scripts = handle(FixedArray::cast(scripts_obj), isolate); |
138 } | 138 } |
139 | 139 |
140 DCHECK(func_index >= 0 && func_index < scripts->length()); | 140 DCHECK(func_index >= 0 && func_index < scripts->length()); |
141 Object *script_or_undef = scripts->get(func_index); | 141 Object *script_or_undef = scripts->get(func_index); |
142 if (!script_or_undef->IsUndefined(isolate)) { | 142 if (!script_or_undef->IsUndefined(isolate)) { |
143 return Script::cast(script_or_undef); | 143 return Script::cast(script_or_undef); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 int idx = 0; | 229 int idx = 0; |
230 for (std::tuple<uint32_t, int, int> elem : offset_table_vec) { | 230 for (std::tuple<uint32_t, int, int> elem : offset_table_vec) { |
231 offset_table->set(idx++, Smi::FromInt(std::get<0>(elem))); | 231 offset_table->set(idx++, Smi::FromInt(std::get<0>(elem))); |
232 offset_table->set(idx++, Smi::FromInt(std::get<1>(elem))); | 232 offset_table->set(idx++, Smi::FromInt(std::get<1>(elem))); |
233 offset_table->set(idx++, Smi::FromInt(std::get<2>(elem))); | 233 offset_table->set(idx++, Smi::FromInt(std::get<2>(elem))); |
234 } | 234 } |
235 DCHECK_EQ(idx, offset_table->length()); | 235 DCHECK_EQ(idx, offset_table->length()); |
236 | 236 |
237 return offset_table; | 237 return offset_table; |
238 } | 238 } |
OLD | NEW |