| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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-objects.h" | 5 #include "src/wasm/wasm-objects.h" |
| 6 | 6 |
| 7 #include "src/debug/debug-interface.h" |
| 7 #include "src/wasm/module-decoder.h" | 8 #include "src/wasm/module-decoder.h" |
| 8 #include "src/wasm/wasm-module.h" | 9 #include "src/wasm/wasm-module.h" |
| 9 | 10 |
| 10 #define TRACE(...) \ | 11 #define TRACE(...) \ |
| 11 do { \ | 12 do { \ |
| 12 if (FLAG_trace_wasm_instances) PrintF(__VA_ARGS__); \ | 13 if (FLAG_trace_wasm_instances) PrintF(__VA_ARGS__); \ |
| 13 } while (false) | 14 } while (false) |
| 14 | 15 |
| 15 #define TRACE_CHAIN(instance) \ | 16 #define TRACE_CHAIN(instance) \ |
| 16 do { \ | 17 do { \ |
| (...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 534 right = mid; | 535 right = mid; |
| 535 } | 536 } |
| 536 } | 537 } |
| 537 // There should be an entry for each position that could show up on the stack | 538 // There should be an entry for each position that could show up on the stack |
| 538 // trace: | 539 // trace: |
| 539 DCHECK_EQ(total_offset, | 540 DCHECK_EQ(total_offset, |
| 540 static_cast<uint32_t>(offset_table->get_int(2 * left))); | 541 static_cast<uint32_t>(offset_table->get_int(2 * left))); |
| 541 return offset_table->get_int(2 * left + 1); | 542 return offset_table->get_int(2 * left + 1); |
| 542 } | 543 } |
| 543 | 544 |
| 545 bool WasmCompiledModule::GetPossibleBreakpoints( |
| 546 const v8::DebugInterface::Location& start, |
| 547 const v8::DebugInterface::Location& end, |
| 548 std::vector<v8::DebugInterface::Location>* locations) const { |
| 549 std::vector<WasmFunction>& functions = module()->functions; |
| 550 if (start.GetLineNumber() < 0 || start.GetColumnNumber() < 0 || |
| 551 (!end.IsEmpty() && |
| 552 (end.GetLineNumber() < 0 || end.GetColumnNumber() < 0))) |
| 553 return false; |
| 554 |
| 555 DCHECK(!functions.empty()); |
| 556 // start_func_index, start_offset and end_func_index is inclusive. |
| 557 // end_offset is exclusive. |
| 558 // start_offset and end_offset are module-relative byte offsets. |
| 559 uint32_t start_func_index = start.GetLineNumber(); |
| 560 if (start_func_index >= functions.size()) return false; |
| 561 uint32_t start_offset = |
| 562 functions[start_func_index].code_start_offset + start.GetColumnNumber(); |
| 563 uint32_t end_func_index; |
| 564 uint32_t end_offset; |
| 565 if (end.IsEmpty()) { |
| 566 // Default: everything till the end of the Script. |
| 567 end_func_index = static_cast<uint32_t>(functions.size() - 1); |
| 568 end_offset = functions[end_func_index].code_end_offset; |
| 569 } else { |
| 570 // If end is specified: Use it and check for valid input. |
| 571 end_func_index = static_cast<uint32_t>(end.GetLineNumber()); |
| 572 |
| 573 // Special case: Stop before the start of the next function. Change to: Stop |
| 574 // at the end of the function before, such that we don't disassemble the |
| 575 // next function also. |
| 576 if (end.GetColumnNumber() == 0 && end_func_index > 0) { |
| 577 --end_func_index; |
| 578 end_offset = functions[end_func_index].code_end_offset; |
| 579 } else { |
| 580 if (end_func_index >= functions.size()) return false; |
| 581 end_offset = |
| 582 functions[end_func_index].code_start_offset + end.GetColumnNumber(); |
| 583 if (end_offset > functions[end_func_index].code_end_offset) return false; |
| 584 } |
| 585 } |
| 586 |
| 587 AccountingAllocator alloc; |
| 588 Zone tmp(&alloc, ZONE_NAME); |
| 589 const byte* module_start = module()->module_start; |
| 590 |
| 591 for (uint32_t func_idx = start_func_index; func_idx <= end_func_index; |
| 592 ++func_idx) { |
| 593 WasmFunction& func = functions[func_idx]; |
| 594 if (func.code_start_offset == func.code_end_offset) continue; |
| 595 |
| 596 AstLocalDecls locals(&tmp); |
| 597 BytecodeIterator iterator(module_start + func.code_start_offset, |
| 598 module_start + func.code_end_offset, &locals); |
| 599 DCHECK_LT(0u, locals.decls_encoded_size); |
| 600 for (; iterator.has_next(); iterator.next()) { |
| 601 uint32_t offset = func.code_start_offset + iterator.pc_offset(); |
| 602 if (offset >= end_offset) { |
| 603 DCHECK_EQ(end_func_index, func_idx); |
| 604 break; |
| 605 } |
| 606 if (offset < start_offset) continue; |
| 607 locations->push_back( |
| 608 v8::DebugInterface::Location(func_idx, iterator.pc_offset())); |
| 609 } |
| 610 } |
| 611 return true; |
| 612 } |
| 613 |
| 544 Handle<WasmInstanceWrapper> WasmInstanceWrapper::New( | 614 Handle<WasmInstanceWrapper> WasmInstanceWrapper::New( |
| 545 Isolate* isolate, Handle<WasmInstanceObject> instance) { | 615 Isolate* isolate, Handle<WasmInstanceObject> instance) { |
| 546 Handle<FixedArray> array = | 616 Handle<FixedArray> array = |
| 547 isolate->factory()->NewFixedArray(kWrapperPropertyCount, TENURED); | 617 isolate->factory()->NewFixedArray(kWrapperPropertyCount, TENURED); |
| 548 Handle<WasmInstanceWrapper> instance_wrapper( | 618 Handle<WasmInstanceWrapper> instance_wrapper( |
| 549 reinterpret_cast<WasmInstanceWrapper*>(*array), isolate); | 619 reinterpret_cast<WasmInstanceWrapper*>(*array), isolate); |
| 550 instance_wrapper->set_instance_object(instance, isolate); | 620 instance_wrapper->set_instance_object(instance, isolate); |
| 551 return instance_wrapper; | 621 return instance_wrapper; |
| 552 } | 622 } |
| 553 | 623 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 564 !array->get(kPreviousInstanceWrapper)->IsFixedArray()) | 634 !array->get(kPreviousInstanceWrapper)->IsFixedArray()) |
| 565 return false; | 635 return false; |
| 566 return true; | 636 return true; |
| 567 } | 637 } |
| 568 | 638 |
| 569 void WasmInstanceWrapper::set_instance_object(Handle<JSObject> instance, | 639 void WasmInstanceWrapper::set_instance_object(Handle<JSObject> instance, |
| 570 Isolate* isolate) { | 640 Isolate* isolate) { |
| 571 Handle<WeakCell> cell = isolate->factory()->NewWeakCell(instance); | 641 Handle<WeakCell> cell = isolate->factory()->NewWeakCell(instance); |
| 572 set(kWrapperInstanceObject, *cell); | 642 set(kWrapperInstanceObject, *cell); |
| 573 } | 643 } |
| OLD | NEW |