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 DCHECK(!functions.empty()); | |
titzer
2016/12/19 15:44:58
Isn't this check redundant with the check below? I
Clemens Hammacher
2016/12/19 15:59:22
True, it's not needed for the code below to work,
| |
668 // start_func_index, start_offset and end_func_index is inclusive. | |
669 // end_offset is exclusive. | |
670 // start_offset and end_offset are module-relative byte offsets. | |
671 uint32_t start_func_index = start.GetLineNumber(); | |
672 if (start_func_index >= functions.size()) return false; | |
673 int start_func_len = functions[start_func_index].code_end_offset - | |
674 functions[start_func_index].code_start_offset; | |
675 if (start.GetColumnNumber() > start_func_len) return false; | |
676 uint32_t start_offset = | |
677 functions[start_func_index].code_start_offset + start.GetColumnNumber(); | |
678 uint32_t end_func_index; | |
679 uint32_t end_offset; | |
680 if (end.IsEmpty()) { | |
681 // Default: everything till the end of the Script. | |
682 end_func_index = static_cast<uint32_t>(functions.size() - 1); | |
683 end_offset = functions[end_func_index].code_end_offset; | |
684 } else { | |
685 // If end is specified: Use it and check for valid input. | |
686 end_func_index = static_cast<uint32_t>(end.GetLineNumber()); | |
687 | |
688 // Special case: Stop before the start of the next function. Change to: Stop | |
689 // at the end of the function before, such that we don't disassemble the | |
690 // next function also. | |
691 if (end.GetColumnNumber() == 0 && end_func_index > 0) { | |
692 --end_func_index; | |
693 end_offset = functions[end_func_index].code_end_offset; | |
694 } else { | |
695 if (end_func_index >= functions.size()) return false; | |
696 end_offset = | |
697 functions[end_func_index].code_start_offset + end.GetColumnNumber(); | |
698 if (end_offset > functions[end_func_index].code_end_offset) return false; | |
699 } | |
700 } | |
701 | |
702 AccountingAllocator alloc; | |
703 Zone tmp(&alloc, ZONE_NAME); | |
704 const byte* module_start = ptr_to_module_bytes()->GetChars(); | |
705 | |
706 for (uint32_t func_idx = start_func_index; func_idx <= end_func_index; | |
707 ++func_idx) { | |
708 WasmFunction& func = functions[func_idx]; | |
709 if (func.code_start_offset == func.code_end_offset) continue; | |
710 | |
711 AstLocalDecls locals(&tmp); | |
712 BytecodeIterator iterator(module_start + func.code_start_offset, | |
713 module_start + func.code_end_offset, &locals); | |
714 DCHECK_LT(0u, locals.decls_encoded_size); | |
715 for (; iterator.has_next(); iterator.next()) { | |
716 uint32_t offset = func.code_start_offset + iterator.pc_offset(); | |
717 if (offset >= end_offset) { | |
718 DCHECK_EQ(end_func_index, func_idx); | |
719 break; | |
720 } | |
721 if (offset < start_offset) continue; | |
722 locations->push_back(v8::debug::Location(func_idx, iterator.pc_offset())); | |
723 } | |
724 } | |
725 return true; | |
726 } | |
727 | |
655 Handle<WasmInstanceWrapper> WasmInstanceWrapper::New( | 728 Handle<WasmInstanceWrapper> WasmInstanceWrapper::New( |
656 Isolate* isolate, Handle<WasmInstanceObject> instance) { | 729 Isolate* isolate, Handle<WasmInstanceObject> instance) { |
657 Handle<FixedArray> array = | 730 Handle<FixedArray> array = |
658 isolate->factory()->NewFixedArray(kWrapperPropertyCount, TENURED); | 731 isolate->factory()->NewFixedArray(kWrapperPropertyCount, TENURED); |
659 Handle<WasmInstanceWrapper> instance_wrapper( | 732 Handle<WasmInstanceWrapper> instance_wrapper( |
660 reinterpret_cast<WasmInstanceWrapper*>(*array), isolate); | 733 reinterpret_cast<WasmInstanceWrapper*>(*array), isolate); |
661 instance_wrapper->set_instance_object(instance, isolate); | 734 instance_wrapper->set_instance_object(instance, isolate); |
662 return instance_wrapper; | 735 return instance_wrapper; |
663 } | 736 } |
664 | 737 |
(...skipping 10 matching lines...) Expand all Loading... | |
675 !array->get(kPreviousInstanceWrapper)->IsFixedArray()) | 748 !array->get(kPreviousInstanceWrapper)->IsFixedArray()) |
676 return false; | 749 return false; |
677 return true; | 750 return true; |
678 } | 751 } |
679 | 752 |
680 void WasmInstanceWrapper::set_instance_object(Handle<JSObject> instance, | 753 void WasmInstanceWrapper::set_instance_object(Handle<JSObject> instance, |
681 Isolate* isolate) { | 754 Isolate* isolate) { |
682 Handle<WeakCell> cell = isolate->factory()->NewWeakCell(instance); | 755 Handle<WeakCell> cell = isolate->factory()->NewWeakCell(instance); |
683 set(kWrapperInstanceObject, *cell); | 756 set(kWrapperInstanceObject, *cell); |
684 } | 757 } |
OLD | NEW |