summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author npwoods <npwoods@alumni.cmu.edu>2017-06-23 19:46:58 -0400
committer Vas Crabb <cuavas@users.noreply.github.com>2017-06-24 09:46:58 +1000
commit2af3233101b109a6ebcb1087d2c47ebce3c4c978 (patch)
tree3ec211a11853626cfd00a13f3148ff5cc8cf96f5
parentf1c043d18c6882930b4c00877c5d1773c527f998 (diff)
Changed a few 'const char *' ==> 'const std::string &' in the MAME debugger (#2170)
-rw-r--r--src/emu/debug/debugcon.cpp10
-rw-r--r--src/emu/debug/debugcon.h4
-rw-r--r--src/emu/debug/debugcpu.cpp76
-rw-r--r--src/emu/debug/debugcpu.h4
-rw-r--r--src/emu/debug/debugvw.h2
-rw-r--r--src/emu/debug/dvdisasm.cpp2
-rw-r--r--src/emu/debug/dvdisasm.h2
-rw-r--r--src/emu/debug/dvmemory.cpp2
-rw-r--r--src/emu/debug/dvmemory.h2
-rw-r--r--src/emu/debug/dvwpoints.cpp2
-rw-r--r--src/lib/util/corestr.cpp44
-rw-r--r--src/lib/util/corestr.h1
-rw-r--r--src/osd/modules/debugger/win/consolewininfo.cpp4
-rw-r--r--src/osd/modules/debugger/win/consolewininfo.h2
-rw-r--r--src/osd/modules/debugger/win/disasmviewinfo.cpp2
-rw-r--r--src/osd/modules/debugger/win/disasmviewinfo.h2
-rw-r--r--src/osd/modules/debugger/win/disasmwininfo.cpp2
-rw-r--r--src/osd/modules/debugger/win/disasmwininfo.h2
-rw-r--r--src/osd/modules/debugger/win/editwininfo.h4
-rw-r--r--src/osd/modules/debugger/win/memoryviewinfo.cpp2
-rw-r--r--src/osd/modules/debugger/win/memoryviewinfo.h2
-rw-r--r--src/osd/modules/debugger/win/memorywininfo.cpp2
-rw-r--r--src/osd/modules/debugger/win/memorywininfo.h2
23 files changed, 94 insertions, 83 deletions
diff --git a/src/emu/debug/debugcon.cpp b/src/emu/debug/debugcon.cpp
index fa4ac6a7a5e..8b0cd786bff 100644
--- a/src/emu/debug/debugcon.cpp
+++ b/src/emu/debug/debugcon.cpp
@@ -231,7 +231,7 @@ CMDERR debugger_console::internal_execute_command(bool execute, int params, char
and either executes or just validates it
-------------------------------------------------*/
-CMDERR debugger_console::internal_parse_command(const char *original_command, bool execute)
+CMDERR debugger_console::internal_parse_command(const std::string &original_command, bool execute)
{
char command[MAX_COMMAND_LENGTH], parens[MAX_COMMAND_LENGTH];
char *params[MAX_COMMAND_PARAMS] = { nullptr };
@@ -240,7 +240,7 @@ CMDERR debugger_console::internal_parse_command(const char *original_command, bo
char *p, c = 0;
/* make a copy of the command */
- strcpy(command, original_command);
+ strcpy(command, original_command.c_str());
/* loop over all semicolon-separated stuff */
for (p = command; *p != 0; )
@@ -327,13 +327,13 @@ CMDERR debugger_console::internal_parse_command(const char *original_command, bo
execute_command - execute a command string
-------------------------------------------------*/
-CMDERR debugger_console::execute_command(const char *command, bool echo)
+CMDERR debugger_console::execute_command(const std::string &command, bool echo)
{
CMDERR result;
/* echo if requested */
if (echo)
- printf(">%s\n", command);
+ printf(">%s\n", command.c_str());
/* parse and execute */
result = internal_parse_command(command, true);
@@ -342,7 +342,7 @@ CMDERR debugger_console::execute_command(const char *command, bool echo)
if (result != CMDERR_NONE)
{
if (!echo)
- printf(">%s\n", command);
+ printf(">%s\n", command.c_str());
printf(" %*s^\n", CMDERR_ERROR_OFFSET(result), "");
printf("%s\n", cmderr_to_string(result));
}
diff --git a/src/emu/debug/debugcon.h b/src/emu/debug/debugcon.h
index 31de5bb5b51..54bc3bf6772 100644
--- a/src/emu/debug/debugcon.h
+++ b/src/emu/debug/debugcon.h
@@ -77,7 +77,7 @@ public:
debugger_console(running_machine &machine);
/* command handling */
- CMDERR execute_command(const char *command, bool echo);
+ 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);
@@ -111,7 +111,7 @@ private:
void trim_parameter(char **paramptr, bool keep_quotes);
CMDERR internal_execute_command(bool execute, int params, char **param);
- CMDERR internal_parse_command(const char *original_command, bool execute);
+ CMDERR internal_parse_command(const std::string &original_command, bool execute);
struct debug_command
{
diff --git a/src/emu/debug/debugcpu.cpp b/src/emu/debug/debugcpu.cpp
index 143159936bf..2773c66fda5 100644
--- a/src/emu/debug/debugcpu.cpp
+++ b/src/emu/debug/debugcpu.cpp
@@ -2,7 +2,7 @@
// copyright-holders:Aaron Giles
/*********************************************************************
- debugcpu.c
+ debugcpu.cpp
Debugger CPU/memory interface engine.
@@ -25,6 +25,7 @@
#include "xmlfile.h"
#include <ctype.h>
+#include <fstream>
enum
@@ -45,7 +46,6 @@ debugger_cpu::debugger_cpu(running_machine &machine)
, m_livecpu(nullptr)
, m_visiblecpu(nullptr)
, m_breakcpu(nullptr)
- , m_source_file(nullptr)
, m_symtable(nullptr)
, m_execution_state(EXECUTION_STATE_STOPPED)
, m_bpindex(1)
@@ -189,24 +189,24 @@ symbol_table* debugger_cpu::get_visible_symtable()
void debugger_cpu::source_script(const char *file)
{
- /* close any existing source file */
- if (m_source_file != nullptr)
- {
- fclose(m_source_file);
- m_source_file = nullptr;
- }
+ // close any existing source file
+ m_source_file.reset();
- /* open a new one if requested */
+ // open a new one if requested
if (file != nullptr)
{
- m_source_file = fopen(file, "r");
- if (!m_source_file)
+ 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);
+ }
}
}
@@ -871,36 +871,32 @@ void debugger_cpu::reset_transient_flags()
void debugger_cpu::process_source_file()
{
- /* loop until the file is exhausted or until we are executing again */
- while (m_source_file != nullptr && m_execution_state == EXECUTION_STATE_STOPPED)
- {
- /* stop at the end of file */
- if (feof(m_source_file))
- {
- fclose(m_source_file);
- m_source_file = nullptr;
- return;
- }
+ std::string buf;
- /* fetch the next line */
- char buf[512];
- memset(buf, 0, sizeof(buf));
- fgets(buf, sizeof(buf), m_source_file);
-
- /* strip out comments (text after '//') */
- char *s = strstr(buf, "//");
- if (s)
- *s = '\0';
+ // loop until the file is exhausted or until we are executing again
+ while (m_execution_state == EXECUTION_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 */
- int i = (int)strlen(buf);
- while((i > 0) && (isspace(u8(buf[i-1]))))
- buf[--i] = '\0';
+ // strip whitespace
+ strtrimrightspace(buf);
- /* execute the command */
- if (buf[0])
+ // 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->fail())
+ m_machine.debugger().console().printf("I/O error, script processing terminated\n");
+ m_source_file.reset();
+ }
}
@@ -2755,7 +2751,7 @@ void device_debug::breakpoint_check(offs_t pc)
// if we hit, evaluate the action
if (!bp->m_action.empty())
- m_device.machine().debugger().console().execute_command(bp->m_action.c_str(), false);
+ m_device.machine().debugger().console().execute_command(bp->m_action, false);
// print a notification, unless the action made us go again
if (debugcpu.execution_state() == EXECUTION_STATE_STOPPED)
@@ -2774,7 +2770,7 @@ void device_debug::breakpoint_check(offs_t pc)
// if we hit, evaluate the action
if (!rp->m_action.empty())
{
- m_device.machine().debugger().console().execute_command(rp->m_action.c_str(), false);
+ m_device.machine().debugger().console().execute_command(rp->m_action, false);
}
// print a notification, unless the action made us go again
@@ -2887,7 +2883,7 @@ void debugger_cpu::watchpoint_check(address_space& space, int type, offs_t addre
m_execution_state = EXECUTION_STATE_STOPPED;
// if we hit, evaluate the action
- if (strlen(wp->action()) > 0)
+ if (!wp->action().empty())
m_machine.debugger().console().execute_command(wp->action(), false);
// print a notification, unless the action made us go again
@@ -3336,7 +3332,7 @@ void device_debug::tracer::update(offs_t pc)
// execute any trace actions first
if (!m_action.empty())
- m_debug.m_device.machine().debugger().console().execute_command(m_action.c_str(), false);
+ m_debug.m_device.machine().debugger().console().execute_command(m_action, false);
// print the address
std::string buffer;
diff --git a/src/emu/debug/debugcpu.h b/src/emu/debug/debugcpu.h
index ff5a4f186b0..1cc50740249 100644
--- a/src/emu/debug/debugcpu.h
+++ b/src/emu/debug/debugcpu.h
@@ -110,7 +110,7 @@ public:
offs_t address() const { return m_address; }
offs_t length() const { return m_length; }
const char *condition() const { return m_condition.original_string(); }
- const char *action() const { return m_action.c_str(); }
+ const std::string &action() const { return m_action; }
// setters
void setEnabled(bool value) { m_enabled = value; }
@@ -599,7 +599,7 @@ private:
device_t * m_visiblecpu;
device_t * m_breakcpu;
- FILE * m_source_file; // script source file
+ std::unique_ptr<std::istream> m_source_file; // script source file
std::unique_ptr<symbol_table> m_symtable; // global symbol table
diff --git a/src/emu/debug/debugvw.h b/src/emu/debug/debugvw.h
index 142f5d3170d..d456eacdbeb 100644
--- a/src/emu/debug/debugvw.h
+++ b/src/emu/debug/debugvw.h
@@ -262,7 +262,7 @@ public:
// setters
void mark_dirty() { m_dirty = true; }
- void set_string(const char *string) { m_string.assign(string); m_dirty = true; }
+ template <typename... Params> void set_string(Params &&... args) { m_string.assign(std::forward<Params>(args)...); m_dirty = true; }
void set_context(symbol_table *context);
private:
diff --git a/src/emu/debug/dvdisasm.cpp b/src/emu/debug/dvdisasm.cpp
index 9c46010985b..c06dd6cfac6 100644
--- a/src/emu/debug/dvdisasm.cpp
+++ b/src/emu/debug/dvdisasm.cpp
@@ -637,7 +637,7 @@ offs_t debug_view_disasm::selected_address()
// describing the home address
//-------------------------------------------------
-void debug_view_disasm::set_expression(const char *expression)
+void debug_view_disasm::set_expression(const std::string &expression)
{
begin_update();
m_expression.set_string(expression);
diff --git a/src/emu/debug/dvdisasm.h b/src/emu/debug/dvdisasm.h
index 295e23ffa0a..b945041676d 100644
--- a/src/emu/debug/dvdisasm.h
+++ b/src/emu/debug/dvdisasm.h
@@ -75,7 +75,7 @@ public:
offs_t selected_address();
// setters
- void set_expression(const char *expression);
+ void set_expression(const std::string &expression);
void set_right_column(disasm_right_column contents);
void set_backward_steps(u32 steps);
void set_disasm_width(u32 width);
diff --git a/src/emu/debug/dvmemory.cpp b/src/emu/debug/dvmemory.cpp
index 21db62e5dfd..7505e68222e 100644
--- a/src/emu/debug/dvmemory.cpp
+++ b/src/emu/debug/dvmemory.cpp
@@ -873,7 +873,7 @@ void debug_view_memory::write(u8 size, offs_t offs, u64 data)
// describing the home address
//-------------------------------------------------
-void debug_view_memory::set_expression(const char *expression)
+void debug_view_memory::set_expression(const std::string &expression)
{
begin_update();
m_expression.set_string(expression);
diff --git a/src/emu/debug/dvmemory.h b/src/emu/debug/dvmemory.h
index 3f00fc83d29..1927e030d2b 100644
--- a/src/emu/debug/dvmemory.h
+++ b/src/emu/debug/dvmemory.h
@@ -65,7 +65,7 @@ public:
offs_t addressAtCursorPosition(const debug_view_xy& pos) { return get_cursor_pos(pos).m_address; }
// setters
- void set_expression(const char *expression);
+ void set_expression(const std::string &expression);
void set_chunks_per_row(u32 rowchunks);
void set_data_format(int format); // 1-8 current values 9 32bit floating point
void set_reverse(bool reverse);
diff --git a/src/emu/debug/dvwpoints.cpp b/src/emu/debug/dvwpoints.cpp
index d3eb7a00de7..5609d3559b5 100644
--- a/src/emu/debug/dvwpoints.cpp
+++ b/src/emu/debug/dvwpoints.cpp
@@ -103,7 +103,7 @@ static int cActionAscending(const void* a, const void* b)
{
const device_debug::watchpoint* left = *(device_debug::watchpoint**)a;
const device_debug::watchpoint* right = *(device_debug::watchpoint**)b;
- return strcmp(left->action(), right->action());
+ return left->action().compare(right->action());
}
static int cActionDescending(const void* a, const void* b)
diff --git a/src/lib/util/corestr.cpp b/src/lib/util/corestr.cpp
index 66b12f6ee04..c8775f1cec0 100644
--- a/src/lib/util/corestr.cpp
+++ b/src/lib/util/corestr.cpp
@@ -171,27 +171,41 @@ void strreplacechr(std::string& str, char ch, char newch)
}
}
-std::string strtrimspace(std::string& str)
+static std::string internal_strtrimspace(std::string& str, bool right_only)
{
- int start = 0;
- for (auto & elem : str)
- {
- if (!isspace(uint8_t(elem))) break;
- start++;
- }
- int end = str.length();
- if (end > 0)
+ // identify the start
+ std::string::iterator start = str.begin();
+ if (!right_only)
{
- for (size_t i = str.length() - 1; i > 0; i--)
- {
- if (!isspace(uint8_t(str[i]))) break;
- end--;
- }
+ start = std::find_if(
+ str.begin(),
+ str.end(),
+ [](char c) { return !isspace(uint8_t(c)); });
}
- str = str.substr(start, end-start);
+
+ // identify the end
+ std::string::iterator end = std::find_if(
+ str.rbegin(),
+ std::string::reverse_iterator(start),
+ [](char c) { return !isspace(uint8_t(c)); }).base();
+
+ // extract the string
+ str = end > start
+ ? str.substr(start - str.begin(), end - start)
+ : "";
return str;
}
+std::string strtrimspace(std::string& str)
+{
+ return internal_strtrimspace(str, false);
+}
+
+std::string strtrimrightspace(std::string& str)
+{
+ return internal_strtrimspace(str, true);
+}
+
std::string strmakeupper(std::string& str)
{
std::transform(str.begin(), str.end(), str.begin(), ::toupper);
diff --git a/src/lib/util/corestr.h b/src/lib/util/corestr.h
index 9a9bce23e99..d31c1e5f8df 100644
--- a/src/lib/util/corestr.h
+++ b/src/lib/util/corestr.h
@@ -67,6 +67,7 @@ int strcatvprintf(std::string &str, const char *format, va_list args);
void strdelchr(std::string& str, char chr);
void strreplacechr(std::string& str, char ch, char newch);
std::string strtrimspace(std::string& str);
+std::string strtrimrightspace(std::string& str);
std::string strmakeupper(std::string& str);
std::string strmakelower(std::string& str);
int strreplace(std::string &str, const std::string& search, const std::string& replace);
diff --git a/src/osd/modules/debugger/win/consolewininfo.cpp b/src/osd/modules/debugger/win/consolewininfo.cpp
index 079cf631049..6da9c67f040 100644
--- a/src/osd/modules/debugger/win/consolewininfo.cpp
+++ b/src/osd/modules/debugger/win/consolewininfo.cpp
@@ -453,9 +453,9 @@ bool consolewin_info::handle_command(WPARAM wparam, LPARAM lparam)
}
-void consolewin_info::process_string(char const *string)
+void consolewin_info::process_string(std::string const &string)
{
- if (string[0] == 0) // an empty string is a single step
+ if (string.empty()) // an empty string is a single step
machine().debugger().cpu().get_visible_cpu()->debug()->single_step();
else // otherwise, just process the command
machine().debugger().console().execute_command(string, true);
diff --git a/src/osd/modules/debugger/win/consolewininfo.h b/src/osd/modules/debugger/win/consolewininfo.h
index 6ab434a4e4c..3811a9029c2 100644
--- a/src/osd/modules/debugger/win/consolewininfo.h
+++ b/src/osd/modules/debugger/win/consolewininfo.h
@@ -42,7 +42,7 @@ private:
DEVOPTION_MAX
};
- virtual void process_string(char const *string) override;
+ virtual void process_string(std::string const &string) override;
static void build_generic_filter(device_image_interface *img, bool is_save, std::string &filter);
static void add_filter_entry(std::string &dest, char const *description, char const *extensions);
diff --git a/src/osd/modules/debugger/win/disasmviewinfo.cpp b/src/osd/modules/debugger/win/disasmviewinfo.cpp
index ade4267a68a..8884bee5195 100644
--- a/src/osd/modules/debugger/win/disasmviewinfo.cpp
+++ b/src/osd/modules/debugger/win/disasmviewinfo.cpp
@@ -33,7 +33,7 @@ offs_t disasmview_info::selected_address() const
}
-void disasmview_info::set_expression(char const *string)
+void disasmview_info::set_expression(const std::string &string)
{
view<debug_view_disasm>()->set_expression(string);
}
diff --git a/src/osd/modules/debugger/win/disasmviewinfo.h b/src/osd/modules/debugger/win/disasmviewinfo.h
index 011748517c0..d1e7090ef2f 100644
--- a/src/osd/modules/debugger/win/disasmviewinfo.h
+++ b/src/osd/modules/debugger/win/disasmviewinfo.h
@@ -25,7 +25,7 @@ public:
disasm_right_column right_column() const;
offs_t selected_address() const;
- void set_expression(const char *expression);
+ void set_expression(const std::string &expression);
void set_right_column(disasm_right_column contents);
};
diff --git a/src/osd/modules/debugger/win/disasmwininfo.cpp b/src/osd/modules/debugger/win/disasmwininfo.cpp
index 6a86a6da397..b94eadbba03 100644
--- a/src/osd/modules/debugger/win/disasmwininfo.cpp
+++ b/src/osd/modules/debugger/win/disasmwininfo.cpp
@@ -126,7 +126,7 @@ void disasmwin_info::draw_contents(HDC dc)
}
-void disasmwin_info::process_string(char const *string)
+void disasmwin_info::process_string(const std::string &string)
{
// set the string to the disasm view
downcast<disasmview_info *>(m_views[0].get())->set_expression(string);
diff --git a/src/osd/modules/debugger/win/disasmwininfo.h b/src/osd/modules/debugger/win/disasmwininfo.h
index 6297b628168..34e8275f2f9 100644
--- a/src/osd/modules/debugger/win/disasmwininfo.h
+++ b/src/osd/modules/debugger/win/disasmwininfo.h
@@ -26,7 +26,7 @@ protected:
virtual void draw_contents(HDC dc) override;
private:
- virtual void process_string(char const *string) override;
+ virtual void process_string(const std::string &string) override;
void update_caption();
diff --git a/src/osd/modules/debugger/win/editwininfo.h b/src/osd/modules/debugger/win/editwininfo.h
index 4a1e42371e1..1aaee55f1e9 100644
--- a/src/osd/modules/debugger/win/editwininfo.h
+++ b/src/osd/modules/debugger/win/editwininfo.h
@@ -34,14 +34,14 @@ protected:
void set_editwnd_bounds(RECT const &bounds);
void set_editwnd_text(char const *text);
void editwnd_select_all();
- void set_edit_defstr(char const *string) { m_edit_defstr = string; }
+ void set_edit_defstr(const std::string &string) { m_edit_defstr = string; }
virtual void draw_contents(HDC dc) override;
private:
typedef std::deque<std::basic_string<TCHAR> > history_deque;
- virtual void process_string(char const *string) = 0;
+ virtual void process_string(const std::string &string) = 0;
LRESULT edit_proc(UINT message, WPARAM wparam, LPARAM lparam);
diff --git a/src/osd/modules/debugger/win/memoryviewinfo.cpp b/src/osd/modules/debugger/win/memoryviewinfo.cpp
index 3bfe3e3ed8c..423679f26a9 100644
--- a/src/osd/modules/debugger/win/memoryviewinfo.cpp
+++ b/src/osd/modules/debugger/win/memoryviewinfo.cpp
@@ -47,7 +47,7 @@ bool memoryview_info::physical() const
}
-void memoryview_info::set_expression(char const *string)
+void memoryview_info::set_expression(const std::string &string)
{
view<debug_view_memory>()->set_expression(string);
}
diff --git a/src/osd/modules/debugger/win/memoryviewinfo.h b/src/osd/modules/debugger/win/memoryviewinfo.h
index dd4cd557222..2ab810654f3 100644
--- a/src/osd/modules/debugger/win/memoryviewinfo.h
+++ b/src/osd/modules/debugger/win/memoryviewinfo.h
@@ -25,7 +25,7 @@ public:
bool reverse() const;
bool physical() const;
- void set_expression(char const *string);
+ void set_expression(const std::string &string);
void set_data_format(uint8_t dataformat);
void set_chunks_per_row(uint32_t rowchunks);
void set_reverse(bool reverse);
diff --git a/src/osd/modules/debugger/win/memorywininfo.cpp b/src/osd/modules/debugger/win/memorywininfo.cpp
index fbd7e853203..6f461295ec2 100644
--- a/src/osd/modules/debugger/win/memorywininfo.cpp
+++ b/src/osd/modules/debugger/win/memorywininfo.cpp
@@ -283,7 +283,7 @@ void memorywin_info::draw_contents(HDC dc)
}
-void memorywin_info::process_string(char const *string)
+void memorywin_info::process_string(const std::string &string)
{
// set the string to the memory view
downcast<memoryview_info *>(m_views[0].get())->set_expression(string);
diff --git a/src/osd/modules/debugger/win/memorywininfo.h b/src/osd/modules/debugger/win/memorywininfo.h
index f0fe535cf16..501d7acc76f 100644
--- a/src/osd/modules/debugger/win/memorywininfo.h
+++ b/src/osd/modules/debugger/win/memorywininfo.h
@@ -29,7 +29,7 @@ protected:
virtual void draw_contents(HDC dc) override;
private:
- virtual void process_string(char const *string) override;
+ virtual void process_string(const std::string &string) override;
void update_caption();