History

Expose the loaded path of a module from the VM. Display path for the loaded module in the debugger.

arr committed 10 years ago

Commit 42194721 parent 836214e4 files · +47 −57Browse files

Showing the changes to src/vm/vm.cpp (1 of 4 files). Show all

Unified · Split

src/vm/vm.cpp+13−30
@@ -20,25 +20,6 @@ · 19 unmodified lines
20using namespace disvm;20using namespace disvm;
21using namespace disvm::runtime;21using namespace disvm::runtime;
22 22
23vm_t::loaded_module_t::loaded_module_t(std::unique_ptr<runtime::vm_string_t> origin, std::shared_ptr<runtime::vm_module_t> module)
24 : origin{ std::move(origin) }
25 , module{ module }
26{
27 assert(this->origin != nullptr);
28}
29
30vm_t::loaded_module_t::loaded_module_t(loaded_module_t &&other)
31 : origin{ std::move(other.origin) }
32 , module{ std::move(other.module) }
33{
34}
35
36vm_t::loaded_module_t::~loaded_module_t()
37{
38 if (origin != nullptr)
39 origin->release();
40}
41
42vm_t::vm_t(23vm_t::vm_t(
43 create_vm_interface_callback_t<runtime::vm_scheduler_t> create_scheduler,24 create_vm_interface_callback_t<runtime::vm_scheduler_t> create_scheduler,
44 create_vm_interface_callback_t<runtime::vm_garbage_collector_t> create_gc)25 create_vm_interface_callback_t<runtime::vm_garbage_collector_t> create_gc)
@@ -80,6 +61,13 @@ vm_t::~vm_t() · 35 unmodified lines
80 // Release the scheduler first since it could be using the gc instance.61 // Release the scheduler first since it could be using the gc instance.
81 _scheduler.reset();62 _scheduler.reset();
82 _gc.reset();63 _gc.reset();
64
65 std::lock_guard<std::mutex> lock{ _modules_lock };
66 for (auto &m : _modules)
67 {
68 if (m.origin != nullptr)
69 m.origin->release();
70 }
83}71}
84 72
85vm_version_t vm_t::get_version() const73vm_version_t vm_t::get_version() const
@@ -139,7 +127,7 @@ std::shared_ptr<runtime::vm_module_t> vm_t::load_module(const char *path) · 53 unmodified lines
139 throw vm_user_exception{ "Invalid module path" };127 throw vm_user_exception{ "Invalid module path" };
140 128
141 std::lock_guard<std::mutex> lock{ _modules_lock };129 std::lock_guard<std::mutex> lock{ _modules_lock };
142 130
143 // Check if the module is already loaded.131 // Check if the module is already loaded.
144 auto iter = std::begin(_modules);132 auto iter = std::begin(_modules);
145 while (iter != std::end(_modules))133 while (iter != std::end(_modules))
@@ -182,26 +170,21 @@ std::shared_ptr<runtime::vm_module_t> vm_t::load_module(const char *path) · 36 unmodified lines
182 _tool_dispatch->on_module_load(new_module, *path_local);170 _tool_dispatch->on_module_load(new_module, *path_local);
183 }171 }
184 172
185 _modules.push_front(std::move(loaded_module_t{ std::move(path_local), new_module }));173 _modules.push_front(std::move(loaded_vm_module_t{ std::move(path_local), new_module }));
186 174
187 debug::log_msg(debug::component_trace_t::module, debug::log_level_t::debug, "load: vm module: >>%s<<\n", path);175 debug::log_msg(debug::component_trace_t::module, debug::log_level_t::debug, "load: vm module: >>%s<<\n", path);
188 176
189 return new_module;177 return new_module;
190}178}
191 179
192std::vector<std::shared_ptr<runtime::vm_module_t>> vm_t::get_loaded_modules() const180void vm_t::enum_loaded_modules(loaded_vm_module_callback_t callback) const
193{181{
194 auto result = std::vector<std::shared_ptr<runtime::vm_module_t>>{};182 if (callback == nullptr)
183 throw vm_system_exception{ "Callback should not be null" };
195 184
196 std::lock_guard<std::mutex> lock{ _modules_lock };185 std::lock_guard<std::mutex> lock{ _modules_lock };
197 for (auto &m : _modules)186 for (auto &m : _modules)
198 {187 callback(m);
199 auto loaded_module_maybe = m.module.lock();
200 if (loaded_module_maybe != nullptr)
201 result.push_back(loaded_module_maybe);
202 }
203
204 return result;
205}188}
206 189
207runtime::vm_scheduler_control_t &vm_t::get_scheduler_control() const190runtime::vm_scheduler_control_t &vm_t::get_scheduler_control() const