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
2020 using namespace disvm;
2121 using namespace disvm::runtime;
2222
23−vm_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−
30−vm_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−
36−vm_t::loaded_module_t::~loaded_module_t()
37−{
38− if (origin != nullptr)
39− origin->release();
40−}
41−
4223 vm_t::vm_t(
4324 create_vm_interface_callback_t<runtime::vm_scheduler_t> create_scheduler,
4425 create_vm_interface_callback_t<runtime::vm_garbage_collector_t> create_gc)
@@ -80,6 +61,13 @@ vm_t::~vm_t() · 35 unmodified lines
8061 // Release the scheduler first since it could be using the gc instance.
8162 _scheduler.reset();
8263 _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+ }
8371 }
8472
8573 vm_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
139127 throw vm_user_exception{ "Invalid module path" };
140128
141129 std::lock_guard<std::mutex> lock{ _modules_lock };
142−
130+
143131 // Check if the module is already loaded.
144132 auto iter = std::begin(_modules);
145133 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
182170 _tool_dispatch->on_module_load(new_module, *path_local);
183171 }
184172
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 }));
186174
187175 debug::log_msg(debug::component_trace_t::module, debug::log_level_t::debug, "load: vm module: >>%s<<\n", path);
188176
189177 return new_module;
190178 }
191179
192−std::vector<std::shared_ptr<runtime::vm_module_t>> vm_t::get_loaded_modules() const
180+void vm_t::enum_loaded_modules(loaded_vm_module_callback_t callback) const
193181 {
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" };
195184
196185 std::lock_guard<std::mutex> lock{ _modules_lock };
197186 for (auto &m : _modules)
198− {
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;
187+ callback(m);
205188 }
206189
207190 runtime::vm_scheduler_control_t &vm_t::get_scheduler_control() const