_event_cookies.emplace(controller->subscribe_event(vm_event_t::breakpoint, [&](vm_event_t, vm_event_context_t &cxt) { auto ss = std::stringstream{}; ss << "Breakpoint hit"; if (cxt.value2.cookie != 0) ss << " [" << cxt.value2.cookie << "]"; debug_print_info(ss.str()); auto reg_str = registers_to_string(*cxt.value1.registers); debug_print_info(reg_str); prompt(*this, *cxt.value1.registers); }));} void debugger::on_unload(){ assert(controller != nullptr); for (auto ec : _event_cookies) controller->unsubscribe_event(ec); controller = nullptr;} void debugger::load_symbols(const disvm::loaded_vm_module_t &loaded_mod){ auto m = loaded_mod.module.lock(); assert(m != nullptr && "Loaded module event should have valid module reference"); auto symbol_extension = ".sbl"; std::string symbol_path_maybe{ loaded_mod.origin->str() }; const auto ext_index = symbol_path_maybe.find_last_of('.'); if (ext_index == std::string::npos) { // Module doesn't have an extension so just append the symbol extension. symbol_path_maybe.append(symbol_extension); } else { // Replace the module extension with the symbol extension. symbol_path_maybe.replace(ext_index, std::string::npos, symbol_extension); } std::ifstream sbl_file{ symbol_path_maybe, std::ifstream::in }; if (!sbl_file.is_open()) return; std::unique_ptr<symbol::symbol_data_t> symbol_data; try { symbol_data = symbol::read(sbl_file); } catch (const std::runtime_error &e) { // File with assumed symbol name/extension is not the correct format std::stringstream msg; msg << "Assumed symbol file '" << symbol_path_maybe << "' has invalid symbol format. (" << e.what() << ")"; debug_print_error(msg.str()); return; } // Check if the symbol data matches the loaded module if (0 != symbol_data->get_module_name().compare(m->module_name->str()) || symbol_data->get_instruction_count() != m->code_section.size()) { // Symbol file does not match the loaded modules - stale file? std::stringstream msg; msg << "Symbol file '" << symbol_path_maybe << "' does not match loaded module '" << loaded_mod.origin->str() << "'."; debug_print_error(msg.str()); return; } const auto vm_id = loaded_mod.vm_id; assert(_vm_id_to_symbol_debug.find(vm_id) == std::end(_vm_id_to_symbol_debug) && "Module VM ID should be unique"); _vm_id_to_symbol_debug[vm_id] = symbol_data->get_debug(); std::stringstream msg; msg << "Symbol file '" << symbol_path_maybe << "' loaded for '" << loaded_mod.origin->str() << "'."; debug_print_info(msg.str());}Lines 1001–1094 of 1094. Previous lines
_event_cookies.emplace(controller->subscribe_event(vm_event_t::breakpoint, [&](vm_event_t, vm_event_context_t &cxt) { auto ss = std::stringstream{}; ss << "Breakpoint hit"; if (cxt.value2.cookie != 0) ss << " [" << cxt.value2.cookie << "]"; debug_print_info(ss.str()); auto reg_str = registers_to_string(*cxt.value1.registers); debug_print_info(reg_str); prompt(*this, *cxt.value1.registers); })); } void debugger::on_unload() { assert(controller != nullptr); for (auto ec : _event_cookies) controller->unsubscribe_event(ec); controller = nullptr; } void debugger::load_symbols(const disvm::loaded_vm_module_t &loaded_mod) { auto m = loaded_mod.module.lock(); assert(m != nullptr && "Loaded module event should have valid module reference"); auto symbol_extension = ".sbl"; std::string symbol_path_maybe{ loaded_mod.origin->str() }; const auto ext_index = symbol_path_maybe.find_last_of('.'); if (ext_index == std::string::npos) { // Module doesn't have an extension so just append the symbol extension. symbol_path_maybe.append(symbol_extension); } else { // Replace the module extension with the symbol extension. symbol_path_maybe.replace(ext_index, std::string::npos, symbol_extension); } std::ifstream sbl_file{ symbol_path_maybe, std::ifstream::in }; if (!sbl_file.is_open()) return; std::unique_ptr<symbol::symbol_data_t> symbol_data; try { symbol_data = symbol::read(sbl_file); } catch (const std::runtime_error &e) { // File with assumed symbol name/extension is not the correct format std::stringstream msg; msg << "Assumed symbol file '" << symbol_path_maybe << "' has invalid symbol format. (" << e.what() << ")"; debug_print_error(msg.str()); return; } // Check if the symbol data matches the loaded module if (0 != symbol_data->get_module_name().compare(m->module_name->str()) || symbol_data->get_instruction_count() != m->code_section.size()) { // Symbol file does not match the loaded modules - stale file? std::stringstream msg; msg << "Symbol file '" << symbol_path_maybe << "' does not match loaded module '" << loaded_mod.origin->str() << "'."; debug_print_error(msg.str()); return; } const auto vm_id = loaded_mod.vm_id; assert(_vm_id_to_symbol_debug.find(vm_id) == std::end(_vm_id_to_symbol_debug) && "Module VM ID should be unique"); _vm_id_to_symbol_debug[vm_id] = symbol_data->get_debug(); std::stringstream msg; msg << "Symbol file '" << symbol_path_maybe << "' loaded for '" << loaded_mod.origin->str() << "'."; debug_print_info(msg.str()); }