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

Side by Side Diff: src/wasm/wasm-debug.cc

Issue 2404253002: [wasm] Provide better stack traces for asm.js code (Closed)
Patch Set: Rebase & fix paths for windows Created 4 years, 2 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
OLDNEW
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"
11 #include "src/wasm/module-decoder.h" 11 #include "src/wasm/module-decoder.h"
12 #include "src/wasm/wasm-module.h" 12 #include "src/wasm/wasm-module.h"
13 13
14 using namespace v8::internal; 14 using namespace v8::internal;
15 using namespace v8::internal::wasm; 15 using namespace v8::internal::wasm;
16 16
17 namespace { 17 namespace {
18 18
19 enum { 19 enum {
20 kWasmDebugInfoWasmObj, 20 kWasmDebugInfoWasmObj,
21 kWasmDebugInfoWasmBytesHash, 21 kWasmDebugInfoWasmBytesHash,
22 kWasmDebugInfoFunctionByteOffsets, 22 kWasmDebugInfoFunctionByteOffsets,
23 kWasmDebugInfoFunctionScripts, 23 kWasmDebugInfoFunctionScripts,
24 kWasmDebugInfoAsmJsOffsets,
24 kWasmDebugInfoNumEntries 25 kWasmDebugInfoNumEntries
25 }; 26 };
26 27
27 ByteArray *GetOrCreateFunctionOffsetTable(Handle<WasmDebugInfo> debug_info) { 28 ByteArray *GetOrCreateFunctionOffsetTable(Handle<WasmDebugInfo> debug_info) {
28 Object *offset_table = debug_info->get(kWasmDebugInfoFunctionByteOffsets); 29 Object *offset_table = debug_info->get(kWasmDebugInfoFunctionByteOffsets);
29 Isolate *isolate = debug_info->GetIsolate(); 30 Isolate *isolate = debug_info->GetIsolate();
30 if (!offset_table->IsUndefined(isolate)) return ByteArray::cast(offset_table); 31 if (!offset_table->IsUndefined(isolate)) return ByteArray::cast(offset_table);
31 32
32 FunctionOffsetsResult function_offsets; 33 FunctionOffsetsResult function_offsets;
33 { 34 {
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 int idx = 0; 230 int idx = 0;
230 for (std::tuple<uint32_t, int, int> elem : offset_table_vec) { 231 for (std::tuple<uint32_t, int, int> elem : offset_table_vec) {
231 offset_table->set(idx++, Smi::FromInt(std::get<0>(elem))); 232 offset_table->set(idx++, Smi::FromInt(std::get<0>(elem)));
232 offset_table->set(idx++, Smi::FromInt(std::get<1>(elem))); 233 offset_table->set(idx++, Smi::FromInt(std::get<1>(elem)));
233 offset_table->set(idx++, Smi::FromInt(std::get<2>(elem))); 234 offset_table->set(idx++, Smi::FromInt(std::get<2>(elem)));
234 } 235 }
235 DCHECK_EQ(idx, offset_table->length()); 236 DCHECK_EQ(idx, offset_table->length());
236 237
237 return offset_table; 238 return offset_table;
238 } 239 }
240
241 int WasmDebugInfo::GetAsmJsSourcePosition(Handle<WasmDebugInfo> debug_info,
242 int func_index, int byte_offset) {
243 Object *offset_tables = debug_info->get(kWasmDebugInfoAsmJsOffsets);
244 Isolate *isolate = debug_info->GetIsolate();
245 if (offset_tables->IsUndefined(isolate)) {
246 AsmJsOffsetsResult asm_offsets;
247 {
248 Handle<JSObject> wasm_object(debug_info->wasm_object(), isolate);
249 uint32_t num_imported_functions =
250 static_cast<uint32_t>(wasm::GetNumImportedFunctions(wasm_object));
251 Handle<SeqOneByteString> wasm_bytes = wasm::GetWasmBytes(wasm_object);
252 DisallowHeapAllocation no_gc;
253 const byte *bytes_start = wasm_bytes->GetChars();
254 const byte *bytes_end = bytes_start + wasm_bytes->length();
255 asm_offsets = wasm::DecodeAsmJsOffsets(bytes_start, bytes_end,
256 num_imported_functions);
257 }
258 // Wasm bytes must be valid and must contain asm.js offset table.
259 DCHECK(asm_offsets.ok());
260 DCHECK_GE(static_cast<size_t>(kMaxInt), asm_offsets.val.size());
261 int num_functions = static_cast<int>(asm_offsets.val.size());
262 DCHECK_EQ(wasm::GetNumberOfFunctions(handle(debug_info->wasm_object())),
263 num_functions);
264 Handle<FixedArray> all_tables =
265 isolate->factory()->NewFixedArray(num_functions);
266 debug_info->set(kWasmDebugInfoAsmJsOffsets, *all_tables);
267 for (int func = 0; func < num_functions; ++func) {
268 std::vector<std::pair<int, int>> &func_asm_offsets =
269 asm_offsets.val[func];
270 if (func_asm_offsets.empty()) continue;
271 size_t array_size = 2 * kIntSize * func_asm_offsets.size();
272 CHECK_LE(array_size, static_cast<size_t>(kMaxInt));
273 ByteArray *arr =
274 *isolate->factory()->NewByteArray(static_cast<int>(array_size));
275 all_tables->set(func, arr);
276 int idx = 0;
277 for (std::pair<int, int> p : func_asm_offsets) {
278 // Byte offsets must be strictly monotonously increasing:
279 DCHECK(idx == 0 || p.first > arr->get_int(idx - 2));
280 arr->set_int(idx++, p.first);
281 arr->set_int(idx++, p.second);
282 }
283 DCHECK_EQ(arr->length(), idx * kIntSize);
284 }
285 offset_tables = *all_tables;
286 }
287
288 FixedArray *offset_tables_arr = FixedArray::cast(offset_tables);
289 DCHECK_LT(func_index, offset_tables_arr->length());
290 ByteArray *offset_table = ByteArray::cast(offset_tables_arr->get(func_index));
291
292 // Binary search for the current byte offset.
293 int left = 0; // inclusive
294 int right = offset_table->length() / kIntSize / 2; // exclusive
295 DCHECK_LT(left, right);
296 while (right - left > 1) {
297 int mid = left + (right - left) / 2;
298 if (offset_table->get_int(2 * mid) < byte_offset) {
299 left = mid;
300 } else {
301 right = mid;
302 }
303 }
304 // There should be an entry for each position that could show up on the stack
305 // trace:
306 DCHECK_EQ(byte_offset, offset_table->get_int(2 * left));
307 return offset_table->get_int(2 * left + 1);
308 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698