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

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

Issue 2404253002: [wasm] Provide better stack traces for asm.js code (Closed)
Patch Set: Fix build error on bots 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)) {
titzer 2016/10/12 08:03:05 Can you extract a helper method to materialize the
Clemens Hammacher 2016/10/12 08:17:46 Done.
246 AsmJsOffsetsResult asm_offsets;
247 {
248 Handle<JSObject> wasm_object(debug_info->wasm_object(), isolate);
249 Handle<WasmCompiledModule> compiled_module =
250 handle(GetCompiledModule(*wasm_object), isolate);
251 DCHECK(compiled_module->has_asm_js_offset_tables());
252 Handle<ByteArray> asm_offset_tables =
253 compiled_module->asm_js_offset_tables();
254 uint32_t num_imported_functions =
255 static_cast<uint32_t>(wasm::GetNumImportedFunctions(wasm_object));
256 DisallowHeapAllocation no_gc;
257 const byte *bytes_start = asm_offset_tables->GetDataStartAddress();
258 const byte *bytes_end = bytes_start + asm_offset_tables->length();
259 asm_offsets = wasm::DecodeAsmJsOffsets(bytes_start, bytes_end,
260 num_imported_functions);
261 }
262 // Wasm bytes must be valid and must contain asm.js offset table.
263 DCHECK(asm_offsets.ok());
264 DCHECK_GE(static_cast<size_t>(kMaxInt), asm_offsets.val.size());
265 int num_functions = static_cast<int>(asm_offsets.val.size());
266 DCHECK_EQ(wasm::GetNumberOfFunctions(handle(debug_info->wasm_object())),
267 num_functions);
268 Handle<FixedArray> all_tables =
269 isolate->factory()->NewFixedArray(num_functions);
270 debug_info->set(kWasmDebugInfoAsmJsOffsets, *all_tables);
271 for (int func = 0; func < num_functions; ++func) {
272 std::vector<std::pair<int, int>> &func_asm_offsets =
273 asm_offsets.val[func];
274 if (func_asm_offsets.empty()) continue;
275 size_t array_size = 2 * kIntSize * func_asm_offsets.size();
276 CHECK_LE(array_size, static_cast<size_t>(kMaxInt));
277 ByteArray *arr =
278 *isolate->factory()->NewByteArray(static_cast<int>(array_size));
279 all_tables->set(func, arr);
280 int idx = 0;
281 for (std::pair<int, int> p : func_asm_offsets) {
282 // Byte offsets must be strictly monotonously increasing:
283 DCHECK(idx == 0 || p.first > arr->get_int(idx - 2));
284 arr->set_int(idx++, p.first);
285 arr->set_int(idx++, p.second);
286 }
287 DCHECK_EQ(arr->length(), idx * kIntSize);
288 }
289 offset_tables = *all_tables;
290 }
291
292 FixedArray *offset_tables_arr = FixedArray::cast(offset_tables);
293 DCHECK_LT(func_index, offset_tables_arr->length());
294 ByteArray *offset_table = ByteArray::cast(offset_tables_arr->get(func_index));
295
296 // Binary search for the current byte offset.
297 int left = 0; // inclusive
298 int right = offset_table->length() / kIntSize / 2; // exclusive
299 DCHECK_LT(left, right);
300 while (right - left > 1) {
301 int mid = left + (right - left) / 2;
302 if (offset_table->get_int(2 * mid) < byte_offset) {
303 left = mid;
304 } else {
305 right = mid;
306 }
307 }
308 // There should be an entry for each position that could show up on the stack
309 // trace:
310 DCHECK_EQ(byte_offset, offset_table->get_int(2 * left));
311 return offset_table->get_int(2 * left + 1);
312 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698