debugcpu.cpp: Move scripting functions down into console (nw)

This commit is contained in:
AJR 2018-07-26 14:41:14 -04:00
parent 6024c958b9
commit 8de41654fa
5 changed files with 74 additions and 81 deletions

View File

@ -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());
}

View File

@ -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();
}
}
/***************************************************************************

View File

@ -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

View File

@ -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())

View File

@ -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;