History

Various work for tool support in the VM. Update some type names (i.e. _t) and alter API signatures to be more consistent.

arr committed 10 years ago

Commit e5d3f861 parent bcb413516 files · +514 −45Browse files

Showing the changes to src/include (6 of 16 files). Show all

Unified · Split

6 files
  1. src/include/debug.h +1 −0
  2. src/include/disvm.h +7 −3
  3. src/include/opcodes.h +4 −1
  4. src/include/runtime.h +37 −10
  5. src/include/utf8.h +2 −2
  6. src/include/vm_tools.h +63 −0
src/include/debug.h+1−0
@@ -24,6 +24,7 @@ namespace disvm · 23 unmodified lines
2424 stack,
2525 channel,
2626 exception,
27+ tool,
2728 memory, // Noisy component
2829 addressing, // Noisy component [DEBUG build only]
2930
src/include/disvm.h+7−3
@@ -71,6 +71,10 @@ namespace disvm · 70 unmodified lines
7171 // Load the module at the supplied path into the virtual machine
7272 std::shared_ptr<const runtime::vm_module_t> load_module(const char *path);
7373
74+ // Get a collection of all currently loaded modules.
75+ // Note this will only include modules that have been loaded by a call to vm_t::load_module.
76+ std::vector<std::shared_ptr<const runtime::vm_module_t>> get_loaded_modules() const;
77+
7478 // Access the scheduler control for this VM.
7579 runtime::vm_scheduler_control_t &get_scheduler_control() const;
7680
@@ -86,7 +90,7 @@ namespace disvm · 9 unmodified lines
8690 class loaded_module_t final
8791 {
8892 public:
89− loaded_module_t(std::unique_ptr<runtime::vm_string_t> origin, std::shared_ptr<const runtime::vm_module_t> module);
93+ loaded_module_t(std::unique_ptr<runtime::vm_string_t> origin, std::shared_ptr<runtime::vm_module_t> module);
9094 loaded_module_t(const loaded_module_t &) = delete;
9195 loaded_module_t &operator=(const loaded_module_t &) = delete;
9296
@@ -97,11 +101,11 @@ namespace disvm · 4 unmodified lines
97101 std::unique_ptr<runtime::vm_string_t> origin;
98102
99103 // Weak reference to a loaded module
100− std::weak_ptr<const runtime::vm_module_t> module;
104+ std::weak_ptr<runtime::vm_module_t> module;
101105 };
102106
103107 using loaded_modules_t = std::forward_list<loaded_module_t>;
104− std::mutex _modules_lock;
108+ mutable std::mutex _modules_lock;
105109 loaded_modules_t _modules;
106110
107111 std::unique_ptr<runtime::vm_scheduler_t> _scheduler;
src/include/opcodes.h+4−1
@@ -190,9 +190,12 @@ namespace disvm · 189 unmodified lines
190190 expf,
191191 self,
192192
193+ // [SPEC] Added opcode for debugging support.
194+ brkpt,
195+
193196 // markers
194197 first_opcode = invalid,
195− last_opcode = self
198+ last_opcode = brkpt
196199 };
197200 }
198201
src/include/runtime.h+37−10
@@ -21,7 +21,7 @@ · 20 unmodified lines
2121
2222 namespace disvm
2323 {
24− // VM forward declation
24+ // Forward declaration
2525 class vm_t;
2626
2727 namespace runtime
@@ -43,7 +43,7 @@ namespace disvm · 15 unmodified lines
4343 // VM memory management
4444 //
4545
46− // VM forward declation
46+ // Forward declaration
4747 class vm_alloc_t;
4848
4949 // Finalizer callback for allocations.
@@ -75,7 +75,7 @@ namespace disvm · 25 unmodified lines
7575 const vm_alloc_instance_finalizer_t finalizer;
7676 };
7777
78− // Access to type descriptors for VM intrinsic types.
78+ // Access to type descriptors for VM intrinsic types
7979 class intrinsic_type_desc final
8080 {
8181 public:
@@ -262,7 +262,7 @@ namespace disvm · 180 unmodified lines
262262 const bool _is_alloc;
263263 };
264264
265− // VM forward declation
265+ // Forward declaration
266266 class vm_channel_t;
267267
268268 // VM request mutex
@@ -299,10 +299,12 @@ namespace disvm · 30 unmodified lines
299299 public: //static
300300 static std::shared_ptr<const type_descriptor_t> type_desc();
301301
302+ using data_transfer_func_t = void(*)(pointer_t, pointer_t, const type_descriptor_t *);
303+
302304 public:
303305 vm_channel_t(
304306 std::shared_ptr<const type_descriptor_t> td,
305− std::function<void(pointer_t, pointer_t, const type_descriptor_t *)> transfer,
307+ data_transfer_func_t transfer,
306308 word_t buffer_len);
307309 ~vm_channel_t();
308310
@@ -331,7 +333,7 @@ namespace disvm · 22 unmodified lines
331333 private:
332334 std::mutex _data_lock;
333335 std::shared_ptr<const type_descriptor_t> _data_type;
334− std::function<void(pointer_t, pointer_t, const type_descriptor_t *)> _data_transfer;
336+ data_transfer_func_t _data_transfer;
335337
336338 vm_array_t *_data_buffer;
337339 uint32_t _data_buffer_head; // Next element to remove from buffer
@@ -406,7 +408,7 @@ namespace disvm · 68 unmodified lines
406408 using src_data_t = inst_data_generic_t;
407409 using dest_data_t = inst_data_generic_t;
408410
409− // VM forward declation
411+ // Forward declaration
410412 class vm_registers_t;
411413
412414 // Instruction execution operation
@@ -710,6 +712,7 @@ namespace disvm · 297 unmodified lines
710712
711713 // Forward declaration
712714 class vm_thread_t;
715+ class vm_tool_dispatch_t;
713716
714717 // VM registers
715718 class vm_registers_t
@@ -721,6 +724,7 @@ namespace disvm · 5 unmodified lines
721724 ~vm_registers_t();
722725
723726 const vm_thread_t &thread;
727+ std::atomic<vm_tool_dispatch_t *> tool_dispatch;
724728 vm_stack_t stack; // Frame pointer access (FP)
725729 vm_pc_t pc; // Program counter (Index into module code section)
726730 vm_alloc_t *mp_base; // Module data base pointer (MP)
@@ -752,13 +756,17 @@ namespace disvm · 25 unmodified lines
752756 uint32_t parent_thread_id);
753757 vm_thread_t(
754758 vm_module_ref_t &entry,
759+ uint32_t parent_thread_id,
755760 const vm_frame_t &initial_frame,
756− vm_pc_t start_pc,
757− uint32_t parent_thread_id);
761+ vm_pc_t start_pc);
758762
759763 ~vm_thread_t();
760764
761− vm_thread_state_t execute(vm_t &virtual_machine, const uint32_t quanta);
765+ vm_thread_state_t execute(vm_t &vm, const uint32_t quanta);
766+
767+ // There is no way to get the current dispatch value.
768+ // Setting the dispatch to 'null' detaches all tool related behavior
769+ void set_tool_dispatch(vm_tool_dispatch_t *dispatch);
762770
763771 vm_thread_state_t get_state() const;
764772
@@ -834,6 +842,25 @@ namespace disvm · 69 unmodified lines
834842
835843 // Create a garbage collector that does nothing.
836844 std::unique_ptr<vm_garbage_collector_t> create_no_op_gc(vm_t &);
845+
846+ // Forward declaration
847+ class vm_tool_controller_t;
848+
849+ // VM tool interface
850+ // Used to implement tools (e.g. debugger or profiler)
851+ class vm_tool_t
852+ {
853+ public:
854+ virtual ~vm_tool_t() = 0;
855+
856+ // Called when the tool is loaded into the VM
857+ virtual void on_load(vm_t &vm, vm_tool_controller_t &controller, std::size_t tool_id) = 0;
858+
859+ // Called when the tool is unloaded from the VM.
860+ // Note once the tool has been unloaded the vm and controller references supplied during load
861+ // should not be used as they may no longer be valid.
862+ virtual void on_unload() = 0;
863+ };
837864 }
838865 }
839866
src/include/utf8.h+2−2
@@ -33,7 +33,7 @@ namespace disvm · 32 unmodified lines
3333 // See http://bjoern.hoehrmann.de/utf-8/decoder/dfa/ for details.
3434 std::size_t count_codepoints(const uint8_t *str, const std::size_t max_len);
3535
36− enum class decode_state
36+ enum class decode_state_t
3737 {
3838 accept = 0,
3939 reject = 12
@@ -41,7 +41,7 @@ namespace disvm · 1 unmodified line
4141
4242 // Decode a byte at a time to form a codepoint.
4343 // See http://bjoern.hoehrmann.de/utf-8/decoder/dfa/ for details.
44− decode_state decode_step(decode_state &state, rune_t &codepoint, uint8_t byte);
44+ decode_state_t decode_step(decode_state_t &state, rune_t &codepoint, uint8_t byte);
4545
4646 // Decode the next codepoint in the supplied string.
4747 // Returns number of characters in string consumed.
src/include/vm_tools.h+63−0
@@ -0,0 +1,63 @@
1+//
2+// Dis VM
3+// File: vm_tools.h
4+// Author: arr
5+//
6+
7+#ifndef _DISVM_SRC_INCLUDE_VM_TOOLS_H_
8+#define _DISVM_SRC_INCLUDE_VM_TOOLS_H_
9+
10+#include <cstdint>
11+#include <vector>
12+#include <memory>
13+#include <functional>
14+#include "runtime.h"
15+
16+namespace disvm
17+{
18+ namespace runtime
19+ {
20+ union vm_context_value_t
21+ {
22+ std::size_t i;
23+ vm_t *vm;
24+ vm_module_t *module;
25+ vm_registers_t *registers;
26+ vm_alloc_t *alloc;
27+ };
28+
29+ struct vm_event_context_t
30+ {
31+ vm_context_value_t value1;
32+ vm_context_value_t value2;
33+ };
34+
35+ enum class vm_event_t
36+ {
37+ module_load, // value1: vm_module_t
38+ module_unload, // value1: vm_module_t
39+ thread_begin, // value1: vm_registers_t
40+ thread_end, // value1: vm_registers_t
41+ exception_raised, // value1: vm_registers_t value2: vm_alloc_t
42+ exception_unhandled, // value1: vm_registers_t value2: vm_alloc_t
43+ breakpoint, // value1: vm_registers_t value2: std::size_t
44+ };
45+
46+ using vm_event_callback_t = std::function<void(vm_event_t, vm_event_context_t &)>;
47+
48+ // VM tool controller
49+ class vm_tool_controller_t
50+ {
51+ public:
52+ // Call the supplied callback when the specified event occurs
53+ virtual std::size_t subscribe_event(vm_event_t, vm_event_callback_t) = 0;
54+ virtual void unsubscribe_event(std::size_t) = 0;
55+
56+ // Set a breakpoint in the supplied module at the specified PC location
57+ virtual std::size_t set_breakpoint(std::shared_ptr<const vm_module_t>, vm_pc_t) = 0;
58+ virtual void clear_breakpoint(std::size_t) = 0;
59+ };
60+ }
61+}
62+
63+#endif // _DISVM_SRC_INCLUDE_VM_TOOLS_H_

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t