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 #include "src/utils.h" | 6 #include "src/utils.h" |
7 | 7 |
| 8 #include "src/debug/debug-interface.h" |
8 #include "src/wasm/module-decoder.h" | 9 #include "src/wasm/module-decoder.h" |
9 #include "src/wasm/wasm-module.h" | 10 #include "src/wasm/wasm-module.h" |
10 #include "src/wasm/wasm-text.h" | 11 #include "src/wasm/wasm-text.h" |
11 | 12 |
12 #define TRACE(...) \ | 13 #define TRACE(...) \ |
13 do { \ | 14 do { \ |
14 if (FLAG_trace_wasm_instances) PrintF(__VA_ARGS__); \ | 15 if (FLAG_trace_wasm_instances) PrintF(__VA_ARGS__); \ |
15 } while (false) | 16 } while (false) |
16 | 17 |
17 #define TRACE_CHAIN(instance) \ | 18 #define TRACE_CHAIN(instance) \ |
(...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
645 | 646 |
646 std::ostringstream disassembly_os; | 647 std::ostringstream disassembly_os; |
647 v8::debug::WasmDisassembly::OffsetTable offset_table; | 648 v8::debug::WasmDisassembly::OffsetTable offset_table; |
648 | 649 |
649 PrintWasmText(module(), module_bytes, static_cast<uint32_t>(func_index), | 650 PrintWasmText(module(), module_bytes, static_cast<uint32_t>(func_index), |
650 disassembly_os, &offset_table); | 651 disassembly_os, &offset_table); |
651 | 652 |
652 return {disassembly_os.str(), std::move(offset_table)}; | 653 return {disassembly_os.str(), std::move(offset_table)}; |
653 } | 654 } |
654 | 655 |
| 656 bool WasmCompiledModule::GetPossibleBreakpoints( |
| 657 const v8::debug::Location& start, const v8::debug::Location& end, |
| 658 std::vector<v8::debug::Location>* locations) const { |
| 659 DisallowHeapAllocation no_gc; |
| 660 |
| 661 std::vector<WasmFunction>& functions = module()->functions; |
| 662 if (start.GetLineNumber() < 0 || start.GetColumnNumber() < 0 || |
| 663 (!end.IsEmpty() && |
| 664 (end.GetLineNumber() < 0 || end.GetColumnNumber() < 0))) |
| 665 return false; |
| 666 |
| 667 // start_func_index, start_offset and end_func_index is inclusive. |
| 668 // end_offset is exclusive. |
| 669 // start_offset and end_offset are module-relative byte offsets. |
| 670 uint32_t start_func_index = start.GetLineNumber(); |
| 671 if (start_func_index >= functions.size()) return false; |
| 672 int start_func_len = functions[start_func_index].code_end_offset - |
| 673 functions[start_func_index].code_start_offset; |
| 674 if (start.GetColumnNumber() > start_func_len) return false; |
| 675 uint32_t start_offset = |
| 676 functions[start_func_index].code_start_offset + start.GetColumnNumber(); |
| 677 uint32_t end_func_index; |
| 678 uint32_t end_offset; |
| 679 if (end.IsEmpty()) { |
| 680 // Default: everything till the end of the Script. |
| 681 end_func_index = static_cast<uint32_t>(functions.size() - 1); |
| 682 end_offset = functions[end_func_index].code_end_offset; |
| 683 } else { |
| 684 // If end is specified: Use it and check for valid input. |
| 685 end_func_index = static_cast<uint32_t>(end.GetLineNumber()); |
| 686 |
| 687 // Special case: Stop before the start of the next function. Change to: Stop |
| 688 // at the end of the function before, such that we don't disassemble the |
| 689 // next function also. |
| 690 if (end.GetColumnNumber() == 0 && end_func_index > 0) { |
| 691 --end_func_index; |
| 692 end_offset = functions[end_func_index].code_end_offset; |
| 693 } else { |
| 694 if (end_func_index >= functions.size()) return false; |
| 695 end_offset = |
| 696 functions[end_func_index].code_start_offset + end.GetColumnNumber(); |
| 697 if (end_offset > functions[end_func_index].code_end_offset) return false; |
| 698 } |
| 699 } |
| 700 |
| 701 AccountingAllocator alloc; |
| 702 Zone tmp(&alloc, ZONE_NAME); |
| 703 const byte* module_start = ptr_to_module_bytes()->GetChars(); |
| 704 |
| 705 for (uint32_t func_idx = start_func_index; func_idx <= end_func_index; |
| 706 ++func_idx) { |
| 707 WasmFunction& func = functions[func_idx]; |
| 708 if (func.code_start_offset == func.code_end_offset) continue; |
| 709 |
| 710 AstLocalDecls locals(&tmp); |
| 711 BytecodeIterator iterator(module_start + func.code_start_offset, |
| 712 module_start + func.code_end_offset, &locals); |
| 713 DCHECK_LT(0u, locals.decls_encoded_size); |
| 714 for (; iterator.has_next(); iterator.next()) { |
| 715 uint32_t offset = func.code_start_offset + iterator.pc_offset(); |
| 716 if (offset >= end_offset) { |
| 717 DCHECK_EQ(end_func_index, func_idx); |
| 718 break; |
| 719 } |
| 720 if (offset < start_offset) continue; |
| 721 locations->push_back(v8::debug::Location(func_idx, iterator.pc_offset())); |
| 722 } |
| 723 } |
| 724 return true; |
| 725 } |
| 726 |
655 Handle<WasmInstanceWrapper> WasmInstanceWrapper::New( | 727 Handle<WasmInstanceWrapper> WasmInstanceWrapper::New( |
656 Isolate* isolate, Handle<WasmInstanceObject> instance) { | 728 Isolate* isolate, Handle<WasmInstanceObject> instance) { |
657 Handle<FixedArray> array = | 729 Handle<FixedArray> array = |
658 isolate->factory()->NewFixedArray(kWrapperPropertyCount, TENURED); | 730 isolate->factory()->NewFixedArray(kWrapperPropertyCount, TENURED); |
659 Handle<WasmInstanceWrapper> instance_wrapper( | 731 Handle<WasmInstanceWrapper> instance_wrapper( |
660 reinterpret_cast<WasmInstanceWrapper*>(*array), isolate); | 732 reinterpret_cast<WasmInstanceWrapper*>(*array), isolate); |
661 instance_wrapper->set_instance_object(instance, isolate); | 733 instance_wrapper->set_instance_object(instance, isolate); |
662 return instance_wrapper; | 734 return instance_wrapper; |
663 } | 735 } |
664 | 736 |
(...skipping 10 matching lines...) Expand all Loading... |
675 !array->get(kPreviousInstanceWrapper)->IsFixedArray()) | 747 !array->get(kPreviousInstanceWrapper)->IsFixedArray()) |
676 return false; | 748 return false; |
677 return true; | 749 return true; |
678 } | 750 } |
679 | 751 |
680 void WasmInstanceWrapper::set_instance_object(Handle<JSObject> instance, | 752 void WasmInstanceWrapper::set_instance_object(Handle<JSObject> instance, |
681 Isolate* isolate) { | 753 Isolate* isolate) { |
682 Handle<WeakCell> cell = isolate->factory()->NewWeakCell(instance); | 754 Handle<WeakCell> cell = isolate->factory()->NewWeakCell(instance); |
683 set(kWrapperInstanceObject, *cell); | 755 set(kWrapperInstanceObject, *cell); |
684 } | 756 } |
OLD | NEW |