History

Debugger supports breakpoints (set/clear/list) Clean up usage of final and override on various classes Distinguish tool events for vm loading module and thread loading module

arr committed 10 years ago

Commit e2f8e251 parent d8c9a3314 files · +382 −177Browse files

Showing the changes to src/include (4 of 14 files). Show all

Unified · Split

4 files
  1. src/include/disvm.h +4 −1
  2. src/include/runtime.h +4 −5
  3. src/include/vm_memory.h +13 −11
  4. src/include/vm_tools.h +23 −8
src/include/disvm.h+4−1
@@ -39,6 +39,8 @@ namespace disvm · 38 unmodified lines
3939 class loaded_vm_module_t final
4040 {
4141 public:
42+ std::size_t load_id;
43+
4244 // Origin of module
4345 std::unique_ptr<runtime::vm_string_t> origin;
4446
@@ -46,7 +48,8 @@ namespace disvm · 1 unmodified line
4648 std::weak_ptr<runtime::vm_module_t> module;
4749 };
4850
49− using loaded_vm_module_callback_t = std::function<void(const loaded_vm_module_t&)>;
51+ // Callback for enumerating loaded modules - return 'false' to stop enumeration, otherwise 'true'
52+ using loaded_vm_module_callback_t = std::function<bool(const loaded_vm_module_t&)>;
5053
5154 // Virtual machine
5255 class vm_t final
src/include/runtime.h+4−5
@@ -824,13 +824,12 @@ namespace disvm · 823 unmodified lines
824824 virtual void set_tool_dispatch_on_all_threads(vm_tool_dispatch_t *dispatch) = 0;
825825 };
826826
827+ // The supplied allocation is guaranteed to be valid for the lifetime of the callback.
828+ using vm_alloc_callback_t = std::function<void(const vm_alloc_t *)>;
829+
827830 // VM garbage collector interface
828831 class vm_garbage_collector_t
829832 {
830− public:
831− // The supplied allocation is guaranteed to be valid for the lifetime of the callback.
832− using vm_alloc_callback_t = std::function<void(const vm_alloc_t *)>;
833−
834833 public:
835834 virtual ~vm_garbage_collector_t() = 0;
836835
@@ -862,7 +861,7 @@ namespace disvm · 25 unmodified lines
862861 virtual ~vm_tool_t() = 0;
863862
864863 // Called when the tool is loaded into the VM
865− virtual void on_load(vm_t &vm, vm_tool_controller_t &controller, std::size_t tool_id) = 0;
864+ virtual void on_load(vm_tool_controller_t &controller, std::size_t tool_id) = 0;
866865
867866 // Called when the tool is unloaded from the VM.
868867 // Note once the tool has been unloaded the vm and controller references supplied during load
src/include/vm_memory.h+13−11
@@ -70,10 +70,11 @@ namespace disvm · 69 unmodified lines
7070 // Increment the ref count of all points in the supplied memory allocation
7171 void inc_ref_count_in_memory(const type_descriptor_t &type_desc, void *data);
7272
73− // Decrement the ref count and if 0 free the allocation.
73+ // Decrement the ref count and if 0 free the allocation
7474 void dec_ref_count_and_free(vm_alloc_t *alloc);
7575
76− using pointer_field_callback_t = std::function<void(pointer_t)>;
76+ // Callback for a pointer field supplying the pointer and byte offset
77+ using pointer_field_callback_t = std::function<void(pointer_t, std::size_t)>;
7778
7879 // The callback will be called on all non-null pointer fields.
7980 inline void enum_pointer_fields(const type_descriptor_t &type_desc, void *data, pointer_field_callback_t callback)
@@ -82,8 +83,9 @@ namespace disvm · 2 unmodified lines
8283 if (type_desc.size_in_bytes == 0)
8384 return;
8485
86+ auto offset_accum = std::size_t{ 0 };
8587 auto memory = reinterpret_cast<word_t *>(data);
86− for (auto i = word_t{ 0 }; i < type_desc.map_in_bytes; ++i, memory += 8)
88+ for (auto i = word_t{ 0 }; i < type_desc.map_in_bytes; ++i, memory += 8, offset_accum += 8)
8789 {
8890 const auto words8 = type_desc.pointer_map[i];
8991 if (words8 != 0)
@@ -91,14 +93,14 @@ namespace disvm · 1 unmodified line
9193 const auto flags = std::bitset<sizeof(words8) * 8>{ words8 };
9294
9395 // Enumerating the flags in reverse order so memory access is sequential.
94− if (flags[7] && (memory[0] != runtime_constants::nil)) callback(reinterpret_cast<pointer_t>(memory[0]));
95− if (flags[6] && (memory[1] != runtime_constants::nil)) callback(reinterpret_cast<pointer_t>(memory[1]));
96− if (flags[5] && (memory[2] != runtime_constants::nil)) callback(reinterpret_cast<pointer_t>(memory[2]));
97− if (flags[4] && (memory[3] != runtime_constants::nil)) callback(reinterpret_cast<pointer_t>(memory[3]));
98− if (flags[3] && (memory[4] != runtime_constants::nil)) callback(reinterpret_cast<pointer_t>(memory[4]));
99− if (flags[2] && (memory[5] != runtime_constants::nil)) callback(reinterpret_cast<pointer_t>(memory[5]));
100− if (flags[1] && (memory[6] != runtime_constants::nil)) callback(reinterpret_cast<pointer_t>(memory[6]));
101− if (flags[0] && (memory[7] != runtime_constants::nil)) callback(reinterpret_cast<pointer_t>(memory[7]));
96+ if (flags[7] && (memory[0] != runtime_constants::nil)) callback(reinterpret_cast<pointer_t>(memory[0]), offset_accum);
97+ if (flags[6] && (memory[1] != runtime_constants::nil)) callback(reinterpret_cast<pointer_t>(memory[1]), offset_accum + (1 * sizeof(pointer_t)));
98+ if (flags[5] && (memory[2] != runtime_constants::nil)) callback(reinterpret_cast<pointer_t>(memory[2]), offset_accum + (2 * sizeof(pointer_t)));
99+ if (flags[4] && (memory[3] != runtime_constants::nil)) callback(reinterpret_cast<pointer_t>(memory[3]), offset_accum + (3 * sizeof(pointer_t)));
100+ if (flags[3] && (memory[4] != runtime_constants::nil)) callback(reinterpret_cast<pointer_t>(memory[4]), offset_accum + (4 * sizeof(pointer_t)));
101+ if (flags[2] && (memory[5] != runtime_constants::nil)) callback(reinterpret_cast<pointer_t>(memory[5]), offset_accum + (5 * sizeof(pointer_t)));
102+ if (flags[1] && (memory[6] != runtime_constants::nil)) callback(reinterpret_cast<pointer_t>(memory[6]), offset_accum + (6 * sizeof(pointer_t)));
103+ if (flags[0] && (memory[7] != runtime_constants::nil)) callback(reinterpret_cast<pointer_t>(memory[7]), offset_accum + (7 * sizeof(pointer_t)));
102104 }
103105 }
104106 }
src/include/vm_tools.h+23−8
@@ -17,10 +17,12 @@ namespace disvm · 16 unmodified lines
1717 {
1818 namespace runtime
1919 {
20+ using cookie_t = std::size_t;
21+
2022 // Value in event context
2123 union vm_context_value_t
2224 {
23− std::size_t i;
25+ cookie_t cookie;
2426 std::shared_ptr<vm_module_t> *module; // Note this is a pointer to std::shared_ptr<>
2527 vm_registers_t *registers;
2628 const vm_thread_t *thread;
@@ -39,8 +41,11 @@ namespace disvm · 12 unmodified lines
3941 // List of possible events
4042 enum class vm_event_t
4143 {
42− module_load, // value1: std::shared_ptr<vm_module_t>
43− // value2: const vm_string_t - path
44+ module_vm_load, // value1: std::shared_ptr<vm_module_t>
45+ // value2: const vm_string_t - path on disk
46+
47+ module_thread_load, // value1: vm_registers_t
48+ // value2: std::shared_ptr<vm_module_t>
4449
4550 thread_begin, // value1: const vm_thread_t
4651 thread_end, // value1: const vm_thread_t
@@ -54,22 +59,32 @@ namespace disvm · 7 unmodified lines
5459 // value3: const vm_alloc_t - object raised
5560
5661 breakpoint, // value1: vm_registers_t
57− // value2: std::size_t - cookie of breakpoint. '0' indicates the breakpoint was inserted by the VM or compiler.
62+ // value2: cookie_t - cookie of breakpoint. '0' indicates the breakpoint was inserted by the VM or compiler.
5863 };
5964
6065 using vm_event_callback_t = std::function<void(vm_event_t, vm_event_context_t &)>;
6166
67+ struct breakpoint_details_t final
68+ {
69+ std::shared_ptr<vm_module_t> module;
70+ vm_pc_t pc;
71+ };
72+
6273 // VM tool controller
6374 class vm_tool_controller_t
6475 {
6576 public:
77+ // The current vm instance
78+ virtual vm_t& get_vm_instance() const = 0;
79+
6680 // Call the supplied callback when the specified event occurs
67− virtual std::size_t subscribe_event(vm_event_t, vm_event_callback_t) = 0;
68− virtual void unsubscribe_event(std::size_t) = 0;
81+ virtual cookie_t subscribe_event(vm_event_t, vm_event_callback_t) = 0;
82+ virtual void unsubscribe_event(cookie_t) = 0;
6983
7084 // Set a breakpoint in the supplied module at the specified PC location
71− virtual std::size_t set_breakpoint(std::shared_ptr<vm_module_t>, vm_pc_t) = 0;
72− virtual void clear_breakpoint(std::size_t) = 0;
85+ virtual cookie_t set_breakpoint(std::shared_ptr<vm_module_t>, vm_pc_t) = 0;
86+ virtual breakpoint_details_t get_breakpoint_details(cookie_t) const = 0;
87+ virtual void clear_breakpoint(cookie_t) = 0;
7388 };
7489 }
7590 }