Showing the changes to src/vm/execution_table.cpp (1 of 16 files). Show all
Unified · Split
| @@ -18,6 +18,7 @@ · 17 unmodified lines | ||
| 18 | 18 | #include <exceptions.h> |
| 19 | 19 | #include <debug.h> |
| 20 | 20 | #include <builtin_module.h> |
| 21 | +#include "tool_dispatch.h" | |
| 21 | 22 | #include "execution_table.h" |
| 22 | 23 | |
| 23 | 24 | using namespace disvm; |
| @@ -186,7 +187,7 @@ namespace · 162 unmodified lines | ||
| 186 | 187 | auto buffer = std::array<char, sizeof("�2147483648")>{}; |
| 187 | 188 | |
| 188 | 189 | const auto w = vt_ref<word_t>(r.src); |
| 189 | − const auto len = ::sprintf(buffer.data(), "%d", w); | |
| 190 | + const auto len = std::sprintf(buffer.data(), "%d", w); | |
| 190 | 191 | assert(static_cast<std::size_t>(len) <= buffer.size()); |
| 191 | 192 | |
| 192 | 193 | auto new_string = new vm_string_t(len, reinterpret_cast<uint8_t *>(buffer.data())); |
| @@ -212,7 +213,7 @@ namespace · 19 unmodified lines | ||
| 212 | 213 | auto buffer = std::array<char, sizeof("-2.2250738585072014e-308")>{}; |
| 213 | 214 | |
| 214 | 215 | const auto real = vt_ref<real_t>(r.src); |
| 215 | − const auto len = ::sprintf(buffer.data(), "%g", real); | |
| 216 | + const auto len = std::sprintf(buffer.data(), "%g", real); | |
| 216 | 217 | assert(static_cast<std::size_t>(len) <= buffer.size()); |
| 217 | 218 | |
| 218 | 219 | auto new_string = new vm_string_t(len, reinterpret_cast<uint8_t *>(buffer.data())); |
| @@ -238,7 +239,7 @@ namespace · 19 unmodified lines | ||
| 238 | 239 | auto buffer = std::array<char, sizeof("-9223372036854775808")>{}; |
| 239 | 240 | |
| 240 | 241 | const auto b = vt_ref<big_t>(r.src); |
| 241 | − const auto len = ::sprintf(buffer.data(), "%lld", b); | |
| 242 | + const auto len = std::sprintf(buffer.data(), "%lld", b); | |
| 242 | 243 | assert(static_cast<std::size_t>(len) <= buffer.size()); |
| 243 | 244 | |
| 244 | 245 | auto new_string = new vm_string_t(len, reinterpret_cast<uint8_t *>(buffer.data())); |
| @@ -643,6 +644,7 @@ namespace · 398 unmodified lines | ||
| 643 | 644 | break; |
| 644 | 645 | } |
| 645 | 646 | |
| 647 | + assert(0 <= static_cast<std::size_t>(target_pc) && static_cast<std::size_t>(target_pc) < r.module_ref->code_section.size()); | |
| 646 | 648 | r.pc = target_pc; |
| 647 | 649 | } |
| 648 | 650 | |
| @@ -1036,7 +1038,7 @@ namespace · 387 unmodified lines | ||
| 1036 | 1038 | vm_registers_t &r, |
| 1037 | 1039 | const vm_t &vm, |
| 1038 | 1040 | std::shared_ptr<const type_descriptor_t> type_desc, |
| 1039 | − std::function<void(pointer_t, pointer_t, const type_descriptor_t *)> transfer) | |
| 1041 | + vm_channel_t::data_transfer_func_t transfer) | |
| 1040 | 1042 | { |
| 1041 | 1043 | auto buffer_len = word_t{ 0 }; |
| 1042 | 1044 | if (r.mid != r.dest) |
| @@ -1066,7 +1068,7 @@ namespace · 23 unmodified lines | ||
| 1066 | 1068 | { |
| 1067 | 1069 | auto memory_size = vt_ref<word_t>(r.src); |
| 1068 | 1070 | auto channel_data_type = type_descriptor_t::create(memory_size); |
| 1069 | − | |
| 1071 | + | |
| 1070 | 1072 | _newc_(r, vm, channel_data_type, _channel_movm); |
| 1071 | 1073 | } |
| 1072 | 1074 | |
| @@ -1669,6 +1671,24 @@ namespace · 596 unmodified lines | ||
| 1669 | 1671 | r.pc = handler_pc; |
| 1670 | 1672 | } |
| 1671 | 1673 | |
| 1674 | + // [SPEC] Added to support debugger. | |
| 1675 | + // The actual opcode for execution can be retrieved from the tool dispatch interface. | |
| 1676 | + // The current register state is for the real opcode, the breakpoint opcode has no inputs/outputs. | |
| 1677 | + EXEC_DECL(brkpt) | |
| 1678 | + { | |
| 1679 | + auto tool_dispatch = r.tool_dispatch.load(); | |
| 1680 | + if (tool_dispatch == nullptr) | |
| 1681 | + { | |
| 1682 | + assert(false && "Breakpoint set but no tool dispatcher found" ); | |
| 1683 | + throw vm_system_exception{ "Breakpoint set but no tool dispatcher found" }; | |
| 1684 | + } | |
| 1685 | + | |
| 1686 | + const auto original_op = tool_dispatch->on_breakpoint(r, vm); | |
| 1687 | + | |
| 1688 | + // Continue execution | |
| 1689 | + vm_exec_table[static_cast<std::size_t>(original_op)](r, vm); | |
| 1690 | + } | |
| 1691 | + | |
| 1672 | 1692 | // |
| 1673 | 1693 | // Module operations |
| 1674 | 1694 | // |
| @@ -1895,4 +1915,5 @@ const vm_exec_t disvm::runtime::vm_exec_table[static_cast<std::size_t>(opcode_t: · 220 unmodified lines | ||
| 1895 | 1915 | expl, |
| 1896 | 1916 | expf, |
| 1897 | 1917 | notimpl, // self, |
| 1918 | + brkpt, | |
| 1898 | 1919 | }; |