emu/debug: Replaced saver/loadr with more generic savem/loadm which handels both region and share memory
Some checks failed
CI (Windows) / build-windows (gcc, gcc-x64, g++, mame, MINGW64, windows-latest, mingw-w64-x86_64, mame) (push) Has been cancelled

This commit is contained in:
Andrei Holub 2025-06-01 20:57:16 -04:00
parent a44f8395b3
commit 104012a22f
4 changed files with 189 additions and 5 deletions

View File

@ -274,13 +274,15 @@ debugger_commands::debugger_commands(running_machine& machine, debugger_cpu& cpu
m_console.register_command("saved", CMDFLAG_NONE, 3, 3, std::bind(&debugger_commands::execute_save, this, AS_DATA, _1));
m_console.register_command("savei", CMDFLAG_NONE, 3, 3, std::bind(&debugger_commands::execute_save, this, AS_IO, _1));
m_console.register_command("saveo", CMDFLAG_NONE, 3, 3, std::bind(&debugger_commands::execute_save, this, AS_OPCODES, _1));
m_console.register_command("saver", CMDFLAG_NONE, 4, 4, std::bind(&debugger_commands::execute_saveregion, this, _1));
m_console.register_command("saver", CMDFLAG_NONE, 4, 4, std::bind(&debugger_commands::execute_region_deprecated, this, _1));
m_console.register_command("savem", CMDFLAG_NONE, 4, 4, std::bind(&debugger_commands::execute_savememory, this, _1));
m_console.register_command("load", CMDFLAG_NONE, 2, 3, std::bind(&debugger_commands::execute_load, this, -1, _1));
m_console.register_command("loadd", CMDFLAG_NONE, 2, 3, std::bind(&debugger_commands::execute_load, this, AS_DATA, _1));
m_console.register_command("loadi", CMDFLAG_NONE, 2, 3, std::bind(&debugger_commands::execute_load, this, AS_IO, _1));
m_console.register_command("loado", CMDFLAG_NONE, 2, 3, std::bind(&debugger_commands::execute_load, this, AS_OPCODES, _1));
m_console.register_command("loadr", CMDFLAG_NONE, 4, 4, std::bind(&debugger_commands::execute_loadregion, this, _1));
m_console.register_command("loadr", CMDFLAG_NONE, 4, 4, std::bind(&debugger_commands::execute_region_deprecated, this, _1));
m_console.register_command("loadm", CMDFLAG_NONE, 4, 4, std::bind(&debugger_commands::execute_loadmemory, this, _1));
m_console.register_command("dump", CMDFLAG_NONE, 3, 6, std::bind(&debugger_commands::execute_dump, this, -1, _1));
m_console.register_command("dumpd", CMDFLAG_NONE, 3, 6, std::bind(&debugger_commands::execute_dump, this, AS_DATA, _1));
@ -2094,6 +2096,12 @@ void debugger_commands::execute_save(int spacenum, const std::vector<std::string
}
void debugger_commands::execute_region_deprecated(const std::vector<std::string_view> &params)
{
m_console.printf("saver/loadr is deprecated, use savem/loadm instead.\n");
}
/*-------------------------------------------------
execute_saveregion - execute the save command on region memory
-------------------------------------------------*/
@ -2133,6 +2141,70 @@ void debugger_commands::execute_saveregion(const std::vector<std::string_view> &
m_console.printf("Data saved successfully\n");
}
/*-------------------------------------------------
execute_saveshare - execute the save command on share memory
-------------------------------------------------*/
void debugger_commands::execute_saveshare(const std::vector<std::string_view> &params)
{
u64 offset, length;
memory_share *share;
// validate parameters
if (!m_console.validate_number_parameter(params[1], offset))
return;
if (!m_console.validate_number_parameter(params[2], length))
return;
if (!m_console.validate_memory_share_parameter(params[3], share))
return;
if (offset >= share->bytes())
{
m_console.printf("Invalid offset\n");
return;
}
if ((length <= 0) || ((length + offset) >= share->bytes()))
length = share->bytes() - offset;
/* open the file */
std::string const filename(params[0]);
FILE *f = fopen(filename.c_str(), "wb");
if (!f)
{
m_console.printf("Error opening file '%s'\n", params[0]);
return;
}
fwrite(reinterpret_cast<u8 *>(share->ptr()) + offset, 1, length, f);
fclose(f);
m_console.printf("Data saved successfully\n");
}
/*-------------------------------------------------
execute_savememory - execute the save command on memory
-------------------------------------------------*/
void debugger_commands::execute_savememory(const std::vector<std::string_view> &params)
{
u64 offset, length;
// validate parameters
if (!m_console.validate_number_parameter(params[1], offset))
return;
if (!m_console.validate_number_parameter(params[2], length))
return;
memory_region *region;
memory_share *share;
if (m_console.validate_memory_region_parameter(params[3], region, false))
execute_saveregion(params);
else if (m_console.validate_memory_share_parameter(params[3], share, false))
execute_saveshare(params);
else
m_console.printf("No matching memory found for '%s'\n", params[3]);
}
/*-------------------------------------------------
execute_load - execute the load command
@ -2297,6 +2369,80 @@ void debugger_commands::execute_loadregion(const std::vector<std::string_view> &
}
/*-------------------------------------------------
execute_loadshare - execute the load command on share memory
-------------------------------------------------*/
void debugger_commands::execute_loadshare(const std::vector<std::string_view> &params)
{
u64 offset, length;
memory_share *share;
// validate parameters
if (!m_console.validate_number_parameter(params[1], offset))
return;
if (!m_console.validate_number_parameter(params[2], length))
return;
if (!m_console.validate_memory_share_parameter(params[3], share))
return;
if (offset >= share->bytes())
{
m_console.printf("Invalid offset\n");
return;
}
if ((length <= 0) || ((length + offset) >= share->bytes()))
length = share->bytes() - offset;
// open the file
std::string filename(params[0]);
FILE *const f = fopen(filename.c_str(), "rb");
if (!f)
{
m_console.printf("Error opening file '%s'\n", params[0]);
return;
}
fseek(f, 0L, SEEK_END);
u64 size = ftell(f);
rewind(f);
// check file size
if (length >= size)
length = size;
fread(reinterpret_cast<u8 *>(share->ptr()) + offset, 1, length, f);
fclose(f);
m_console.printf("Data loaded successfully to memory : 0x%X to 0x%X\n", offset, offset + length - 1);
}
/*-------------------------------------------------
execute_loadregion - execute the load command on memory
-------------------------------------------------*/
void debugger_commands::execute_loadmemory(const std::vector<std::string_view> &params)
{
u64 offset, length;
// validate parameters
if (!m_console.validate_number_parameter(params[1], offset))
return;
if (!m_console.validate_number_parameter(params[2], length))
return;
memory_region *region;
memory_share *share;
if (m_console.validate_memory_region_parameter(params[3], region, false))
execute_loadregion(params);
else if (m_console.validate_memory_share_parameter(params[3], share, false))
execute_loadshare(params);
else
m_console.printf("No matching memory found for '%s'\n", params[3]);
}
/*-------------------------------------------------
execute_dump - execute the dump command
-------------------------------------------------*/

View File

@ -127,9 +127,14 @@ private:
void execute_stateload(const std::vector<std::string_view> &params);
void execute_rewind(const std::vector<std::string_view> &params);
void execute_save(int spacenum, const std::vector<std::string_view> &params);
void execute_region_deprecated(const std::vector<std::string_view> &params);
void execute_saveregion(const std::vector<std::string_view> &params);
void execute_saveshare(const std::vector<std::string_view> &params);
void execute_savememory(const std::vector<std::string_view> &params);
void execute_load(int spacenum, const std::vector<std::string_view> &params);
void execute_loadregion(const std::vector<std::string_view> &params);
void execute_loadshare(const std::vector<std::string_view> &params);
void execute_loadmemory(const std::vector<std::string_view> &params);
void execute_dump(int spacenum, const std::vector<std::string_view> &params);
void execute_strdump(int spacenum, const std::vector<std::string_view> &params);
void execute_cheatrange(bool init, const std::vector<std::string_view> &params);

View File

@ -925,7 +925,7 @@ bool debugger_console::validate_target_address_parameter(std::string_view param,
/// failure.
/// \return true if the parameter refers to a memory region in the
/// current system, or false otherwise.
bool debugger_console::validate_memory_region_parameter(std::string_view param, memory_region *&result)
bool debugger_console::validate_memory_region_parameter(std::string_view param, memory_region *&result, bool print_error)
{
auto const &regions = m_machine.memory().regions();
std::string_view relative = param;
@ -938,7 +938,37 @@ bool debugger_console::validate_memory_region_parameter(std::string_view param,
}
else
{
printf("No matching memory region found for '%s'\n", param);
if (print_error)
printf("No matching memory region found for '%s'\n", param);
return false;
}
}
/// \brief Validate a parameter as a memory share
///
/// Validates a parameter as a memory share tag and retrieves the
/// specified memory share.
/// \param [in] The parameter string.
/// \param [out] result The memory share on success, or unchanged on
/// failure.
/// \return true if the parameter refers to a memory share in the
/// current system, or false otherwise.
bool debugger_console::validate_memory_share_parameter(std::string_view param, memory_share *&result, bool print_error)
{
auto const &shares = m_machine.memory().shares();
std::string_view relative = param;
device_t &base = get_device_search_base(relative);
auto const iter = shares.find(base.subtag(strmakelower(relative)));
if (shares.end() != iter)
{
result = iter->second.get();
return true;
}
else
{
if (print_error)
printf("No matching memory share found for '%s'\n", param);
return false;
}
}

View File

@ -131,7 +131,10 @@ public:
bool validate_target_address_parameter(std::string_view param, int spacenum, address_space *&space, u64 &addr);
// validates a parameter as a memory region name and retrieves the given region
bool validate_memory_region_parameter(std::string_view param, memory_region *&result);
bool validate_memory_region_parameter(std::string_view param, memory_region *&result, bool print_error = true);
// validates a parameter as a memory region name and retrieves the given share
bool validate_memory_share_parameter(std::string_view param, memory_share *&result, bool print_error = true);
// validates a parameter as a debugger expression
bool validate_expression_parameter(std::string_view param, parsed_expression &result);