From 8de41654fafdf4311034331e48a7e2723a3ea3ca Mon Sep 17 00:00:00 2001 From: AJR Date: Thu, 26 Jul 2018 14:41:14 -0400 Subject: [PATCH] debugcpu.cpp: Move scripting functions down into console (nw) --- src/emu/debug/debugcmd.cpp | 4 +-- src/emu/debug/debugcon.cpp | 66 ++++++++++++++++++++++++++++++++++ src/emu/debug/debugcon.h | 4 +++ src/emu/debug/debugcpu.cpp | 72 ++------------------------------------ src/emu/debug/debugcpu.h | 9 ----- 5 files changed, 74 insertions(+), 81 deletions(-) diff --git a/src/emu/debug/debugcmd.cpp b/src/emu/debug/debugcmd.cpp index f253235f714..4dc4844ae6c 100644 --- a/src/emu/debug/debugcmd.cpp +++ b/src/emu/debug/debugcmd.cpp @@ -294,7 +294,7 @@ debugger_commands::debugger_commands(running_machine& machine, debugger_cpu& cpu /* set up the initial debugscript if specified */ const char* name = m_machine.options().debug_script(); if (name[0] != 0) - m_cpu.source_script(name); + m_console.source_script(name); m_cheat.cpu[0] = m_cheat.cpu[1] = 0; } @@ -3094,7 +3094,7 @@ void debugger_commands::execute_snap(int ref, const std::vector &pa void debugger_commands::execute_source(int ref, const std::vector ¶ms) { - m_cpu.source_script(params[0].c_str()); + m_console.source_script(params[0].c_str()); } diff --git a/src/emu/debug/debugcon.cpp b/src/emu/debug/debugcon.cpp index 3b0f2e98b6b..e19d23e6b55 100644 --- a/src/emu/debug/debugcon.cpp +++ b/src/emu/debug/debugcon.cpp @@ -15,6 +15,7 @@ #include "textbuf.h" #include "debugger.h" #include +#include /*************************************************************************** CONSTANTS @@ -392,6 +393,71 @@ void debugger_console::register_command(const char *command, u32 flags, int ref, } +//------------------------------------------------- +// source_script - specifies a debug command +// script to execute +//------------------------------------------------- + +void debugger_console::source_script(const char *file) +{ + // close any existing source file + m_source_file.reset(); + + // open a new one if requested + if (file != nullptr) + { + auto source_file = std::make_unique(file, std::ifstream::in); + if (source_file->fail()) + { + if (m_machine.phase() == machine_phase::RUNNING) + printf("Cannot open command file '%s'\n", file); + else + fatalerror("Cannot open command file '%s'\n", file); + } + else + { + m_source_file = std::move(source_file); + } + } +} + + +//------------------------------------------------- +// process_source_file - executes commands from +// a source file +//------------------------------------------------- + +void debugger_console::process_source_file() +{ + std::string buf; + + // loop until the file is exhausted or until we are executing again + while (m_machine.debugger().cpu().is_stopped() + && m_source_file + && std::getline(*m_source_file, buf)) + { + // strip out comments (text after '//') + size_t pos = buf.find("//"); + if (pos != std::string::npos) + buf.resize(pos); + + // strip whitespace + strtrimrightspace(buf); + + // execute the command + if (!buf.empty()) + execute_command(buf, true); + } + + if (m_source_file && !m_source_file->good()) + { + if (!m_source_file->eof()) + printf("I/O error, script processing terminated\n"); + m_source_file.reset(); + } +} + + /*************************************************************************** diff --git a/src/emu/debug/debugcon.h b/src/emu/debug/debugcon.h index 7cc1231d4c9..a64238ed8c6 100644 --- a/src/emu/debug/debugcon.h +++ b/src/emu/debug/debugcon.h @@ -80,6 +80,8 @@ public: CMDERR execute_command(const std::string &command, bool echo); CMDERR validate_command(const char *command); void register_command(const char *command, u32 flags, int ref, int minparams, int maxparams, std::function &)> handler); + void source_script(const char *file); + void process_source_file(); /* console management */ void vprintf(util::format_argument_pack const &args); @@ -132,6 +134,8 @@ private: text_buffer *m_errorlog_textbuf; debug_command *m_commandlist; + + std::unique_ptr m_source_file; // script source file }; #endif // MAME_EMU_DEBUG_DEBUGCON_H diff --git a/src/emu/debug/debugcpu.cpp b/src/emu/debug/debugcpu.cpp index cd17a1e40f7..bdb0928f926 100644 --- a/src/emu/debug/debugcpu.cpp +++ b/src/emu/debug/debugcpu.cpp @@ -25,9 +25,6 @@ #include "osdepend.h" #include "xmlfile.h" -#include -#include - const size_t debugger_cpu::NUM_TEMP_VARIABLES = 10; @@ -152,42 +149,13 @@ symbol_table* debugger_cpu::get_visible_symtable() } -/*------------------------------------------------- - source_script - specifies a debug command - script to execute --------------------------------------------------*/ - -void debugger_cpu::source_script(const char *file) -{ - // close any existing source file - m_source_file.reset(); - - // open a new one if requested - if (file != nullptr) - { - auto source_file = std::make_unique(file, std::ifstream::in); - if (source_file->fail()) - { - if (m_machine.phase() == machine_phase::RUNNING) - m_machine.debugger().console().printf("Cannot open command file '%s'\n", file); - else - fatalerror("Cannot open command file '%s'\n", file); - } - else - { - m_source_file = std::move(source_file); - } - } -} - - //************************************************************************** // MEMORY AND DISASSEMBLY HELPERS //************************************************************************** //------------------------------------------------- -// omment_save - save all comments for the given +// comment_save - save all comments for the given // machine //------------------------------------------------- @@ -641,42 +609,6 @@ void debugger_cpu::reset_transient_flags() } -/*------------------------------------------------- - process_source_file - executes commands from - a source file --------------------------------------------------*/ - -void debugger_cpu::process_source_file() -{ - std::string buf; - - // loop until the file is exhausted or until we are executing again - while (m_execution_state == exec_state::STOPPED - && m_source_file - && std::getline(*m_source_file, buf)) - { - // strip out comments (text after '//') - size_t pos = buf.find("//"); - if (pos != std::string::npos) - buf.resize(pos); - - // strip whitespace - strtrimrightspace(buf); - - // execute the command - if (!buf.empty()) - m_machine.debugger().console().execute_command(buf, true); - } - - if (m_source_file && !m_source_file->good()) - { - if (!m_source_file->eof()) - m_machine.debugger().console().printf("I/O error, script processing terminated\n"); - m_source_file.reset(); - } -} - - /*************************************************************************** EXPRESSION HANDLERS @@ -1718,7 +1650,7 @@ void device_debug::instruction_hook(offs_t curpc) } // check for commands in the source file - machine.debugger().cpu().process_source_file(); + machine.debugger().console().process_source_file(); // if an event got scheduled, resume if (machine.scheduled_event_pending()) diff --git a/src/emu/debug/debugcpu.h b/src/emu/debug/debugcpu.h index f3e8f68a408..2244b6ccb42 100644 --- a/src/emu/debug/debugcpu.h +++ b/src/emu/debug/debugcpu.h @@ -504,12 +504,6 @@ public: symbol_table *get_visible_symtable(); - /* ----- misc debugger functions ----- */ - - /* specifies a debug command script to execute */ - void source_script(const char *file); - - /* ----- debugger comment helpers ----- */ // save all comments for a given machine @@ -581,7 +575,6 @@ public: void halt_on_next_instruction(device_t *device, util::format_argument_pack &&args); void ensure_comments_loaded(); void reset_transient_flags(); - void process_source_file(); private: static const size_t NUM_TEMP_VARIABLES; @@ -611,8 +604,6 @@ private: device_t * m_visiblecpu; device_t * m_breakcpu; - std::unique_ptr m_source_file; // script source file - std::unique_ptr m_symtable; // global symbol table bool m_within_instruction_hook;