From 314f411b13588207d6f8bceadc2d3121b5a8b6e6 Mon Sep 17 00:00:00 2001 From: AJR Date: Sat, 16 Feb 2019 21:27:06 -0500 Subject: Eliminate qsort usage in debugger (nw) --- src/emu/debug/debugcmd.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'src/emu/debug/debugcmd.cpp') diff --git a/src/emu/debug/debugcmd.cpp b/src/emu/debug/debugcmd.cpp index 05fb6acbddd..7f650a2e356 100644 --- a/src/emu/debug/debugcmd.cpp +++ b/src/emu/debug/debugcmd.cpp @@ -21,6 +21,7 @@ #include "natkeyboard.h" #include "render.h" #include +#include #include @@ -3215,13 +3216,6 @@ void debugger_commands::execute_memdump(int ref, const std::vector execute_symlist - execute the symlist command -------------------------------------------------*/ -static int CLIB_DECL symbol_sort_compare(const void *item1, const void *item2) -{ - const char *str1 = *(const char **)item1; - const char *str2 = *(const char **)item2; - return strcmp(str1, str2); -} - void debugger_commands::execute_symlist(int ref, const std::vector ¶ms) { device_t *cpu = nullptr; @@ -3257,7 +3251,9 @@ void debugger_commands::execute_symlist(int ref, const std::vector /* sort the symbols */ if (count > 1) - qsort((void *)namelist, count, sizeof(namelist[0]), symbol_sort_compare); + std::sort(&namelist[0], &namelist[count], [](const char *item1, const char *item2) { + return strcmp(item1, item2) < 0; + }); /* iterate over symbols and print out relevant ones */ for (symnum = 0; symnum < count; symnum++) -- cgit v1.2.3 From 1a3b2ef914cbdf3a3a504d5d43aaa9d8dae1356d Mon Sep 17 00:00:00 2001 From: AJR Date: Wed, 13 Mar 2019 23:53:34 -0400 Subject: Exclude non-CPUs from numerical indexing for debugger commands --- src/emu/debug/debugcmd.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'src/emu/debug/debugcmd.cpp') diff --git a/src/emu/debug/debugcmd.cpp b/src/emu/debug/debugcmd.cpp index 7f650a2e356..72f4becbdcc 100644 --- a/src/emu/debug/debugcmd.cpp +++ b/src/emu/debug/debugcmd.cpp @@ -461,12 +461,17 @@ bool debugger_commands::validate_cpu_parameter(const char *param, device_t *&res return false; } - /* if we got a valid one, return */ - device_execute_interface *exec = execute_interface_iterator(m_machine.root_device()).byindex(cpunum); - if (exec != nullptr) + // attempt to find by numerical index + int index = 0; + for (device_execute_interface &exec : execute_interface_iterator(m_machine.root_device())) { - result = &exec->device(); - return true; + // real CPUs should have pcbase + const device_state_interface *state; + if (exec.device().interface(state) && state->state_string(STATE_GENPCBASE) != "???" && index++ == cpunum) + { + result = &exec.device(); + return true; + } } /* if out of range, complain */ -- cgit v1.2.3 From 1a66b2ff1e782447f3c7e7713e85d7532522b2fa Mon Sep 17 00:00:00 2001 From: AJR Date: Sat, 16 Mar 2019 19:46:53 -0400 Subject: distate: Expose state_find_entry (nw) --- src/emu/debug/debugcmd.cpp | 2 +- src/emu/distate.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/emu/debug/debugcmd.cpp') diff --git a/src/emu/debug/debugcmd.cpp b/src/emu/debug/debugcmd.cpp index 72f4becbdcc..66bc8578464 100644 --- a/src/emu/debug/debugcmd.cpp +++ b/src/emu/debug/debugcmd.cpp @@ -467,7 +467,7 @@ bool debugger_commands::validate_cpu_parameter(const char *param, device_t *&res { // real CPUs should have pcbase const device_state_interface *state; - if (exec.device().interface(state) && state->state_string(STATE_GENPCBASE) != "???" && index++ == cpunum) + if (exec.device().interface(state) && state->state_find_entry(STATE_GENPCBASE) != nullptr && index++ == cpunum) { result = &exec.device(); return true; diff --git a/src/emu/distate.h b/src/emu/distate.h index dc3476d5ba7..f97ec8e3c2e 100644 --- a/src/emu/distate.h +++ b/src/emu/distate.h @@ -250,6 +250,9 @@ public: void set_state_string(int index, const char *string); void set_pc(offs_t pc) { set_state_int(STATE_GENPC, pc); } + // find the entry for a given index + const device_state_entry *state_find_entry(int index) const; + // deliberately ambiguous functions; if you have the state interface // just use it directly device_state_interface &state() { return *this; } @@ -293,9 +296,6 @@ protected: // internal operation overrides virtual void interface_post_start() override; - // find the entry for a given index - const device_state_entry *state_find_entry(int index) const; - // constants static constexpr int FAST_STATE_MIN = -4; // range for fast state static constexpr int FAST_STATE_MAX = 256; // lookups -- cgit v1.2.3