History

Add support for traps in VM Add instruction trap to enable single step scenario in debugger Remote get_state() function from thread

arr committed 9 years ago

Commit cb408a11 parent eb570d98 files · +120 −40Browse files

Showing the changes to src/include (2 of 8 files). Show all

Unified · Split

2 files
  1. src/include/runtime.h +12 −6
  2. src/include/vm_tools.h +5 −0
src/include/runtime.h+12−6
@@ -709,7 +709,7 @@ namespace disvm · 708 unmodified lines
709 const vm_string_t &exception_id);709 const vm_string_t &exception_id);
710 710
711 // VM thread states711 // VM thread states
712 enum class vm_thread_state_t : uint16_t712 enum class vm_thread_state_t : uint8_t
713 {713 {
714 unknown = 0,714 unknown = 0,
715 715
@@ -729,6 +729,13 @@ namespace disvm · 13 unmodified lines
729 broken, // thread crashed - the scheduler is free to terminate the entire VM if any thread enters this state.729 broken, // thread crashed - the scheduler is free to terminate the entire VM if any thread enters this state.
730 };730 };
731 731
732 // VM trap flags
733 enum class vm_trap_flags_t : uint8_t
734 {
735 none = 0,
736 instruction = 1 << 0,
737 };
738
732 // Forward declaration739 // Forward declaration
733 class vm_thread_t;740 class vm_thread_t;
734 class vm_tool_dispatch_t;741 class vm_tool_dispatch_t;
@@ -738,11 +745,11 @@ namespace disvm · 3 unmodified lines
738 {745 {
739 public:746 public:
740 vm_registers_t(747 vm_registers_t(
741 const vm_thread_t &thread,748 vm_thread_t &thread,
742 vm_module_ref_t &entry);749 vm_module_ref_t &entry);
743 ~vm_registers_t();750 ~vm_registers_t();
744 751
745 const vm_thread_t &thread;752 vm_thread_t &thread;
746 std::atomic<vm_tool_dispatch_t *> tool_dispatch;753 std::atomic<vm_tool_dispatch_t *> tool_dispatch;
747 vm_stack_t stack; // Frame pointer access (FP)754 vm_stack_t stack; // Frame pointer access (FP)
748 vm_pc_t pc; // Current Program counter (Index into module code section)755 vm_pc_t pc; // Current Program counter (Index into module code section)
@@ -751,8 +758,9 @@ namespace disvm · 2 unmodified lines
751 vm_module_ref_t *module_ref; // Module reference758 vm_module_ref_t *module_ref; // Module reference
752 vm_request_mutex_t request_mutex;759 vm_request_mutex_t request_mutex;
753 760
754 vm_thread_state_t current_thread_state;
755 uint16_t current_thread_quanta;761 uint16_t current_thread_quanta;
762 vm_thread_state_t current_thread_state;
763 vm_trap_flags_t trap_flags;
756 764
757 pointer_t src;765 pointer_t src;
758 pointer_t mid;766 pointer_t mid;
@@ -795,8 +803,6 @@ namespace disvm · 36 unmodified lines
795 // this vm thread.803 // this vm thread.
796 void set_tool_dispatch(vm_tool_dispatch_t *dispatch);804 void set_tool_dispatch(vm_tool_dispatch_t *dispatch);
797 805
798 vm_thread_state_t get_state() const;
799
800 // This function will only return a non-null806 // This function will only return a non-null
801 // value if this thread is in the broken state.807 // value if this thread is in the broken state.
802 const char *get_error_message() const;808 const char *get_error_message() const;
src/include/vm_tools.h+5−0
@@ -23,6 +23,7 @@ namespace disvm · 22 unmodified lines
23 union vm_context_value_t23 union vm_context_value_t
24 {24 {
25 cookie_t cookie;25 cookie_t cookie;
26 vm_trap_flags_t trap;
26 std::shared_ptr<vm_module_t> *module; // Note this is a pointer to std::shared_ptr<>27 std::shared_ptr<vm_module_t> *module; // Note this is a pointer to std::shared_ptr<>
27 vm_registers_t *registers;28 vm_registers_t *registers;
28 const vm_thread_t *thread;29 const vm_thread_t *thread;
@@ -61,6 +62,9 @@ namespace disvm · 32 unmodified lines
61 62
62 breakpoint, // value1: vm_registers_t63 breakpoint, // value1: vm_registers_t
63 // value2: cookie_t - cookie of breakpoint. '0' indicates the breakpoint was inserted by the VM or compiler.64 // value2: cookie_t - cookie of breakpoint. '0' indicates the breakpoint was inserted by the VM or compiler.
65
66 trap, // value1: vm_registers_t - The trap flag is unset prior to the event be fired.
67 // value2: vm_trap_flags_t
64 };68 };
65 69
66 using vm_event_callback_t = std::function<void(vm_event_t, vm_event_context_t &)>;70 using vm_event_callback_t = std::function<void(vm_event_t, vm_event_context_t &)>;
@@ -91,6 +95,7 @@ namespace disvm · 24 unmodified lines
91 // Manipulate thread execution95 // Manipulate thread execution
92 virtual void suspend_all_threads() = 0;96 virtual void suspend_all_threads() = 0;
93 virtual void resume_all_threads() = 0;97 virtual void resume_all_threads() = 0;
98 virtual void set_thread_trap_flag(const vm_registers_t &, vm_trap_flags_t flag) = 0;
94 };99 };
95 }100 }
96}101}