summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author AJR <ajrhacker@users.noreply.github.com>2018-07-26 14:41:14 -0400
committer AJR <ajrhacker@users.noreply.github.com>2018-07-26 14:41:14 -0400
commit8de41654fafdf4311034331e48a7e2723a3ea3ca (patch)
treeb6a07258c35f189f137dbfe29a5034c89800bd88
parent6024c958b978b9d470ac7261257e5d2312f92178 (diff)
debugcpu.cpp: Move scripting functions down into console (nw)
-rw-r--r--src/emu/debug/debugcmd.cpp4
-rw-r--r--src/emu/debug/debugcon.cpp66
-rw-r--r--src/emu/debug/debugcon.h4
-rw-r--r--src/emu/debug/debugcpu.cpp72
-rw-r--r--src/emu/debug/debugcpu.h9
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<std::string> &pa
void debugger_commands::execute_source(int ref, const std::vector<std::string> &params)
{
- 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 <ctype.h>
+#include <fstream>
/***************************************************************************
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<std::ifstream>(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<void(int, const std::vector<std::string> &)> handler);
+ void source_script(const char *file);
+ void process_source_file();
/* console management */
void vprintf(util::format_argument_pack<std::ostream> const &args);
@@ -132,6 +134,8 @@ private:
text_buffer *m_errorlog_textbuf;
debug_command *m_commandlist;
+
+ std::unique_ptr<std::istream> 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 <ctype.h>
-#include <fstream>
-
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<std::ifstream>(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<std::ostream> &&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<std::istream> m_source_file; // script source file
-
std::unique_ptr<symbol_table> m_symtable; // global symbol table
bool m_within_instruction_hook;