diff options
| author | 2013-05-09 19:20:05 +0000 | |
|---|---|---|
| committer | 2013-05-09 19:20:05 +0000 | |
| commit | 7964d924b3f34e512c904ac9542cfa1b9934dd44 (patch) | |
| tree | 17e3c6e911f9f0e0a067c505eab0981c914e2c70 /src/emu/debug/debugcmd.c | |
| parent | f57d8d2d7be23e4fb8fe1504e994caacca3b9a2f (diff) | |
Adds memory tracking to debugger. This includes two new commands: trackmem and
pcatmem(p|d|i). [Andrew Gardner]
Fixes left-click selection bug in the memory window. [Andrew Gardner]
Explanation:
------------
Call trackmem to start tracking which PC writes to which address in memory and
pcatmem(p|d|i) to query a memory region for which PC wrote to it. Users of
the QT debugger can also right click on a memory address in the memory window
to make a popup message appear with the results - right-clicking also
automatically copies the resultant PC onto the clipboard. (I'll attach an
image of this behavior in a follow-up mail).
Diffstat (limited to 'src/emu/debug/debugcmd.c')
| -rw-r--r-- | src/emu/debug/debugcmd.c | 89 |
1 files changed, 86 insertions, 3 deletions
diff --git a/src/emu/debug/debugcmd.c b/src/emu/debug/debugcmd.c index d25d2c8d00c..688c9f21914 100644 --- a/src/emu/debug/debugcmd.c +++ b/src/emu/debug/debugcmd.c @@ -143,6 +143,8 @@ static void execute_traceover(running_machine &machine, int ref, int params, con static void execute_traceflush(running_machine &machine, int ref, int params, const char **param); static void execute_history(running_machine &machine, int ref, int params, const char **param); static void execute_trackpc(running_machine &machine, int ref, int params, const char **param); +static void execute_trackmem(running_machine &machine, int ref, int params, const char **param); +static void execute_pcatmem(running_machine &machine, int ref, int params, const char **param); static void execute_snap(running_machine &machine, int ref, int params, const char **param); static void execute_source(running_machine &machine, int ref, int params, const char **param); static void execute_map(running_machine &machine, int ref, int params, const char **param); @@ -292,10 +294,10 @@ void debug_command_init(running_machine &machine) debug_console_register_command(machine, "ignore", CMDFLAG_NONE, 0, 0, MAX_COMMAND_PARAMS, execute_ignore); debug_console_register_command(machine, "observe", CMDFLAG_NONE, 0, 0, MAX_COMMAND_PARAMS, execute_observe); - debug_console_register_command(machine, "comadd", CMDFLAG_NONE, 0, 1, 2, execute_comment); + debug_console_register_command(machine, "comadd", CMDFLAG_NONE, 0, 1, 2, execute_comment); debug_console_register_command(machine, "//", CMDFLAG_NONE, 0, 1, 2, execute_comment); - debug_console_register_command(machine, "comdelete", CMDFLAG_NONE, 0, 1, 1, execute_comment_del); - debug_console_register_command(machine, "comsave", CMDFLAG_NONE, 0, 0, 0, execute_comment_save); + debug_console_register_command(machine, "comdelete", CMDFLAG_NONE, 0, 1, 1, execute_comment_del); + debug_console_register_command(machine, "comsave", CMDFLAG_NONE, 0, 0, 0, execute_comment_save); debug_console_register_command(machine, "bpset", CMDFLAG_NONE, 0, 1, 3, execute_bpset); debug_console_register_command(machine, "bp", CMDFLAG_NONE, 0, 1, 3, execute_bpset); @@ -369,6 +371,11 @@ void debug_command_init(running_machine &machine) debug_console_register_command(machine, "history", CMDFLAG_NONE, 0, 0, 2, execute_history); debug_console_register_command(machine, "trackpc", CMDFLAG_NONE, 0, 0, 3, execute_trackpc); + debug_console_register_command(machine, "trackmem", CMDFLAG_NONE, 0, 0, 3, execute_trackmem); + debug_console_register_command(machine, "pcatmemp", CMDFLAG_NONE, AS_PROGRAM, 1, 2, execute_pcatmem); + debug_console_register_command(machine, "pcatmemd", CMDFLAG_NONE, AS_DATA, 1, 2, execute_pcatmem); + debug_console_register_command(machine, "pcatmemi", CMDFLAG_NONE, AS_IO, 1, 2, execute_pcatmem); + debug_console_register_command(machine, "snap", CMDFLAG_NONE, 0, 0, 1, execute_snap); debug_console_register_command(machine, "source", CMDFLAG_NONE, 0, 1, 1, execute_source); @@ -2695,6 +2702,82 @@ static void execute_trackpc(running_machine &machine, int ref, int params, const /*------------------------------------------------- + execute_trackmem - execute the trackmem command +-------------------------------------------------*/ + +static void execute_trackmem(running_machine &machine, int ref, int params, const char *param[]) +{ + // Gather the on/off switch (if present) + UINT64 turnOn = true; + if (!debug_command_parameter_number(machine, param[0], &turnOn)) + return; + + // Gather the cpu id (if present) + device_t *cpu = NULL; + if (!debug_command_parameter_cpu(machine, (params > 1) ? param[1] : NULL, &cpu)) + return; + + // Should we clear the existing data? + UINT64 clear = false; + if (!debug_command_parameter_number(machine, param[2], &clear)) + return; + + // Get the address space for the given cpu + address_space *space; + if (!debug_command_parameter_cpu_space(machine, (params > 1) ? param[1] : NULL, AS_PROGRAM, space)) + return; + + // Inform the CPU it's time to start tracking memory writes + cpu->debug()->set_track_mem(turnOn); + + // Use the watchpoint system to catch memory writes + space->enable_write_watchpoints(true); + + // Clear out the existing data if requested + if (clear) + space->device().debug()->track_mem_data_clear(); +} + + +/*------------------------------------------------- + execute_pcatmem - execute the pcatmem command +-------------------------------------------------*/ + +static void execute_pcatmem(running_machine &machine, int ref, int params, const char *param[]) +{ + // Gather the required address parameter + UINT64 address; + if (!debug_command_parameter_number(machine, param[0], &address)) + return; + + // Gather the cpu id (if present) + device_t *cpu = NULL; + if (!debug_command_parameter_cpu(machine, (params > 1) ? param[1] : NULL, &cpu)) + return; + + // Get the address space for the given cpu + address_space *space; + if (!debug_command_parameter_cpu_space(machine, (params > 1) ? param[1] : NULL, ref, space)) + return; + + // Get the value of memory at the address + const int nativeDataWidth = space->data_width() / 8; + const UINT64 data = debug_read_memory(*space, + space->address_to_byte(address), + nativeDataWidth, + true); + + // Recover the pc & print + const address_spacenum spaceNum = (address_spacenum)ref; + const offs_t result = space->device().debug()->track_mem_pc_from_space_address_data(spaceNum, address, data); + if (result != (offs_t)(-1)) + debug_console_printf(machine, "%02x\n", result); + else + debug_console_printf(machine, "UNKNOWN PC\n"); +} + + +/*------------------------------------------------- execute_snap - execute the snapshot command -------------------------------------------------*/ |
