Changed a few 'const char *' ==> 'const std::string &' in the MAME debugger (#2170)

This commit is contained in:
npwoods 2017-06-23 19:46:58 -04:00 committed by Vas Crabb
parent f1c043d18c
commit 2af3233101
23 changed files with 96 additions and 85 deletions

View File

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

View File

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

View File

@ -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,35 +871,31 @@ 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)
std::string buf;
// 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))
{
/* stop at the end of file */
if (feof(m_source_file))
{
fclose(m_source_file);
m_source_file = nullptr;
return;
// 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);
}
/* 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';
/* strip whitespace */
int i = (int)strlen(buf);
while((i > 0) && (isspace(u8(buf[i-1]))))
buf[--i] = '\0';
/* execute the command */
if (buf[0])
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;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -171,25 +171,39 @@ void strreplacechr(std::string& str, char ch, char newch)
}
}
static std::string internal_strtrimspace(std::string& str, bool right_only)
{
// identify the start
std::string::iterator start = str.begin();
if (!right_only)
{
start = std::find_if(
str.begin(),
str.end(),
[](char c) { return !isspace(uint8_t(c)); });
}
// 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)
{
int start = 0;
for (auto & elem : str)
{
if (!isspace(uint8_t(elem))) break;
start++;
return internal_strtrimspace(str, false);
}
int end = str.length();
if (end > 0)
std::string strtrimrightspace(std::string& str)
{
for (size_t i = str.length() - 1; i > 0; i--)
{
if (!isspace(uint8_t(str[i]))) break;
end--;
}
}
str = str.substr(start, end-start);
return str;
return internal_strtrimspace(str, true);
}
std::string strmakeupper(std::string& str)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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