summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/emu/debug/debugcmd.cpp4
-rw-r--r--src/emu/debug/debugcon.cpp98
-rw-r--r--src/emu/debug/debugcon.h93
-rw-r--r--src/emu/debug/dvtext.cpp39
-rw-r--r--src/emu/debug/dvtext.h13
-rw-r--r--src/emu/debug/textbuf.cpp154
-rw-r--r--src/emu/debug/textbuf.h61
-rw-r--r--src/frontend/mame/luaengine.cpp2
-rw-r--r--src/lib/util/nanosvg.h4
-rw-r--r--src/osd/modules/debugger/debuggdbstub.cpp2
10 files changed, 224 insertions, 246 deletions
diff --git a/src/emu/debug/debugcmd.cpp b/src/emu/debug/debugcmd.cpp
index a620d5555d3..acc25e9ab8f 100644
--- a/src/emu/debug/debugcmd.cpp
+++ b/src/emu/debug/debugcmd.cpp
@@ -650,12 +650,12 @@ bool debugger_commands::debug_command_parameter_command(const char *param)
/* validate the comment; success if no error */
CMDERR err = m_console.validate_command(param);
- if (err == CMDERR_NONE)
+ if (err.ERROR_CLASS() == CMDERR::NONE)
return true;
/* output an error */
m_console.printf("Error in command: %s\n", param);
- m_console.printf(" %*s^", CMDERR_ERROR_OFFSET(err), "");
+ m_console.printf(" %*s^", err.ERROR_OFFSET(), "");
m_console.printf("%s\n", debugger_console::cmderr_to_string(err));
return 0;
}
diff --git a/src/emu/debug/debugcon.cpp b/src/emu/debug/debugcon.cpp
index b547b1b536c..a8f93e598f3 100644
--- a/src/emu/debug/debugcon.cpp
+++ b/src/emu/debug/debugcon.cpp
@@ -86,24 +86,15 @@ debugger_console::debugger_console(running_machine &machine)
void debugger_console::exit()
{
- /* free allocated memory */
- if (m_console_textbuf)
- {
- text_buffer_free(m_console_textbuf);
- }
- m_console_textbuf = nullptr;
-
- if (m_errorlog_textbuf)
- {
- text_buffer_free(m_errorlog_textbuf);
- }
- m_errorlog_textbuf = nullptr;
+ // free allocated memory
+ m_console_textbuf.reset();
+ m_errorlog_textbuf.reset();
- /* free the command list */
+ // free the command list
m_commandlist.clear();
- /* close the logfile, if any */
- m_logfile = nullptr;
+ // close the logfile, if any
+ m_logfile.reset();
}
@@ -167,7 +158,7 @@ void debugger_console::execute_condump(int ref, const std::vector<std::string>&
return;
}
- for (auto line_info : text_buffer_get_lines(m_console_textbuf))
+ for (auto line_info : text_buffer_lines(*m_console_textbuf))
{
fwrite(line_info.text, sizeof(char), line_info.length, f);
fputc('\n', f);
@@ -259,7 +250,7 @@ CMDERR debugger_console::internal_execute_command(bool execute, int params, char
/* no params is an error */
if (params == 0)
- return CMDERR_NONE;
+ return CMDERR(CMDERR::NONE, 0);
/* the first parameter has the command and the real first parameter; separate them */
for (p = param[0]; *p && isspace(u8(*p)); p++) { }
@@ -296,9 +287,9 @@ CMDERR debugger_console::internal_execute_command(bool execute, int params, char
/* error if not found */
if (!found)
- return MAKE_CMDERR_UNKNOWN_COMMAND(0);
+ return CMDERR::MAKE_UNKNOWN_COMMAND(0);
if (foundcount > 1)
- return MAKE_CMDERR_AMBIGUOUS_COMMAND(0);
+ return CMDERR::MAKE_AMBIGUOUS_COMMAND(0);
/* NULL-terminate and trim space around all the parameters */
for (i = 1; i < params; i++)
@@ -310,9 +301,9 @@ CMDERR debugger_console::internal_execute_command(bool execute, int params, char
/* see if we have the right number of parameters */
if (params < found->minparams)
- return MAKE_CMDERR_NOT_ENOUGH_PARAMS(0);
+ return CMDERR::MAKE_NOT_ENOUGH_PARAMS(0);
if (params > found->maxparams)
- return MAKE_CMDERR_TOO_MANY_PARAMS(0);
+ return CMDERR::MAKE_TOO_MANY_PARAMS(0);
/* execute the handler */
if (execute)
@@ -320,7 +311,7 @@ CMDERR debugger_console::internal_execute_command(bool execute, int params, char
std::vector<std::string> params_vec(param, param + params);
found->handler(found->ref, params_vec);
}
- return CMDERR_NONE;
+ return CMDERR(CMDERR::NONE, 0);
}
@@ -333,7 +324,6 @@ CMDERR debugger_console::internal_parse_command(const std::string &original_comm
{
char command[MAX_COMMAND_LENGTH], parens[MAX_COMMAND_LENGTH];
char *params[MAX_COMMAND_PARAMS] = { nullptr };
- CMDERR result;
char *command_start;
char *p, c = 0;
@@ -363,9 +353,9 @@ CMDERR debugger_console::internal_parse_command(const std::string &original_comm
case '(':
case '[':
case '{': parens[parendex++] = c; break;
- case ')': if (parendex == 0 || parens[--parendex] != '(') return MAKE_CMDERR_UNBALANCED_PARENS(p - command); break;
- case ']': if (parendex == 0 || parens[--parendex] != '[') return MAKE_CMDERR_UNBALANCED_PARENS(p - command); break;
- case '}': if (parendex == 0 || parens[--parendex] != '{') return MAKE_CMDERR_UNBALANCED_PARENS(p - command); break;
+ case ')': if (parendex == 0 || parens[--parendex] != '(') return CMDERR::MAKE_UNBALANCED_PARENS(p - command); break;
+ case ']': if (parendex == 0 || parens[--parendex] != '[') return CMDERR::MAKE_UNBALANCED_PARENS(p - command); break;
+ case '}': if (parendex == 0 || parens[--parendex] != '{') return CMDERR::MAKE_UNBALANCED_PARENS(p - command); break;
case ',': if (parendex == 0) params[paramcount++] = p; break;
case ';': if (parendex == 0) foundend = true; break;
case '-': if (parendex == 0 && paramcount == 1 && p[1] == '-') isexpr = true; *p = c; break;
@@ -379,9 +369,9 @@ CMDERR debugger_console::internal_parse_command(const std::string &original_comm
/* check for unbalanced parentheses or quotes */
if (instring)
- return MAKE_CMDERR_UNBALANCED_QUOTES(p - command);
+ return CMDERR::MAKE_UNBALANCED_QUOTES(p - command);
if (parendex != 0)
- return MAKE_CMDERR_UNBALANCED_PARENS(p - command);
+ return CMDERR::MAKE_UNBALANCED_PARENS(p - command);
/* NULL-terminate if we ended in a semicolon */
p--;
@@ -406,17 +396,17 @@ CMDERR debugger_console::internal_parse_command(const std::string &original_comm
}
catch (expression_error &err)
{
- return MAKE_CMDERR_EXPRESSION_ERROR(err);
+ return CMDERR::MAKE_EXPRESSION_ERROR(err);
}
}
else
{
- result = internal_execute_command(execute, paramcount, &params[0]);
- if (result != CMDERR_NONE)
- return MAKE_CMDERR(CMDERR_ERROR_CLASS(result), command_start - command);
+ const CMDERR result = internal_execute_command(execute, paramcount, &params[0]);
+ if (result.ERROR_CLASS() != CMDERR::NONE)
+ return CMDERR(result.ERROR_CLASS(), command_start - command);
}
}
- return CMDERR_NONE;
+ return CMDERR(CMDERR::NONE, 0);
}
@@ -426,21 +416,19 @@ CMDERR debugger_console::internal_parse_command(const std::string &original_comm
CMDERR debugger_console::execute_command(const std::string &command, bool echo)
{
- CMDERR result;
-
/* echo if requested */
if (echo)
printf(">%s\n", command.c_str());
/* parse and execute */
- result = internal_parse_command(command, true);
+ const CMDERR result = internal_parse_command(command, true);
/* display errors */
- if (result != CMDERR_NONE)
+ if (result.ERROR_CLASS() != CMDERR::NONE)
{
if (!echo)
printf(">%s\n", command.c_str());
- printf(" %*s^\n", CMDERR_ERROR_OFFSET(result), "");
+ printf(" %*s^\n", result.ERROR_OFFSET(), "");
printf("%s\n", cmderr_to_string(result).c_str());
}
@@ -559,16 +547,16 @@ void debugger_console::process_source_file()
std::string debugger_console::cmderr_to_string(CMDERR error)
{
- int offset = CMDERR_ERROR_OFFSET(error);
- switch (CMDERR_ERROR_CLASS(error))
+ const int offset = error.ERROR_OFFSET();
+ switch (error.ERROR_CLASS())
{
- case CMDERR_UNKNOWN_COMMAND: return "unknown command";
- case CMDERR_AMBIGUOUS_COMMAND: return "ambiguous command";
- case CMDERR_UNBALANCED_PARENS: return "unbalanced parentheses";
- case CMDERR_UNBALANCED_QUOTES: return "unbalanced quotes";
- case CMDERR_NOT_ENOUGH_PARAMS: return "not enough parameters for command";
- case CMDERR_TOO_MANY_PARAMS: return "too many parameters for command";
- case CMDERR_EXPRESSION_ERROR: return string_format("error in assignment expression: %s",
+ case CMDERR::UNKNOWN_COMMAND: return "unknown command";
+ case CMDERR::AMBIGUOUS_COMMAND: return "ambiguous command";
+ case CMDERR::UNBALANCED_PARENS: return "unbalanced parentheses";
+ case CMDERR::UNBALANCED_QUOTES: return "unbalanced quotes";
+ case CMDERR::NOT_ENOUGH_PARAMS: return "not enough parameters for command";
+ case CMDERR::TOO_MANY_PARAMS: return "too many parameters for command";
+ case CMDERR::EXPRESSION_ERROR: return string_format("error in assignment expression: %s",
expression_error(static_cast<expression_error::error_code>(offset)).code_string());
default: return "unknown error";
}
@@ -591,7 +579,7 @@ std::string debugger_console::cmderr_to_string(CMDERR error)
void debugger_console::print_core(const char *text)
{
// FIXME: this invokes strlen() twice; compute it once and pass it to text_buffer_print
- text_buffer_print(m_console_textbuf, text);
+ text_buffer_print(*m_console_textbuf, text);
if (m_logfile)
m_logfile->write(text, strlen(text));
}
@@ -605,7 +593,7 @@ void debugger_console::print_core_wrap(const char *text, int wrapcol)
{
// FIXME: this invokes strlen() twice; compute it once and pass it to text_buffer_print
// FIXME: also look into honoring wrapcol for the logfile
- text_buffer_print_wrap(m_console_textbuf, text, wrapcol);
+ text_buffer_print_wrap(*m_console_textbuf, text, wrapcol);
if (m_logfile)
m_logfile->write(text, strlen(text));
}
@@ -627,7 +615,7 @@ void debugger_console::vprintf(util::format_argument_pack<std::ostream> &&args)
{
print_core(util::string_format(std::move(args)).c_str());
- /* force an update of any console views */
+ // force an update of any console views
m_machine.debug_view().update_all(DVT_CONSOLE);
}
@@ -641,7 +629,7 @@ void debugger_console::vprintf_wrap(int wrapcol, util::format_argument_pack<std:
{
print_core_wrap(util::string_format(args).c_str(), wrapcol);
- /* force an update of any console views */
+ // force an update of any console views
m_machine.debug_view().update_all(DVT_CONSOLE);
}
@@ -649,7 +637,7 @@ void debugger_console::vprintf_wrap(int wrapcol, util::format_argument_pack<std:
{
print_core_wrap(util::string_format(std::move(args)).c_str(), wrapcol);
- /* force an update of any console views */
+ // force an update of any console views
m_machine.debug_view().update_all(DVT_CONSOLE);
}
@@ -662,10 +650,8 @@ void debugger_console::vprintf_wrap(int wrapcol, util::format_argument_pack<std:
void debugger_console::errorlog_write_line(const char *line)
{
if (m_errorlog_textbuf)
- {
- text_buffer_print(m_errorlog_textbuf, line);
- }
+ text_buffer_print(*m_errorlog_textbuf, line);
- /* force an update of any log views */
+ // force an update of any log views
m_machine.debug_view().update_all(DVT_LOG);
}
diff --git a/src/emu/debug/debugcon.h b/src/emu/debug/debugcon.h
index 949b236774a..38d1bc4f367 100644
--- a/src/emu/debug/debugcon.h
+++ b/src/emu/debug/debugcon.h
@@ -25,20 +25,10 @@
#define MAX_COMMAND_LENGTH 4096
#define MAX_COMMAND_PARAMS 128
-/* flags for command parsing */
-#define CMDFLAG_NONE (0x0000)
-#define CMDFLAG_KEEP_QUOTES (0x0001)
-#define CMDFLAG_CUSTOM_HELP (0x0002)
-
-/* values for the error code in a command error */
-#define CMDERR_NONE (0)
-#define CMDERR_UNKNOWN_COMMAND (1)
-#define CMDERR_AMBIGUOUS_COMMAND (2)
-#define CMDERR_UNBALANCED_PARENS (3)
-#define CMDERR_UNBALANCED_QUOTES (4)
-#define CMDERR_NOT_ENOUGH_PARAMS (5)
-#define CMDERR_TOO_MANY_PARAMS (6)
-#define CMDERR_EXPRESSION_ERROR (7)
+// flags for command parsing
+constexpr u32 CMDFLAG_NONE = 0x0000;
+constexpr u32 CMDFLAG_KEEP_QUOTES = 0x0001;
+constexpr u32 CMDFLAG_CUSTOM_HELP = 0x0002;
/* parameter separator macros */
#define CMDPARAM_SEPARATOR "\0"
@@ -47,53 +37,62 @@
/***************************************************************************
- MACROS
-***************************************************************************/
-
-/* command error assembly/disassembly macros */
-#define CMDERR_ERROR_CLASS(x) ((x) >> 16)
-#define CMDERR_ERROR_OFFSET(x) ((x) & 0xffff)
-#define MAKE_CMDERR(a,b) (((a) << 16) | ((b) & 0xffff))
-
-/* macros to assemble specific error conditions */
-#define MAKE_CMDERR_UNKNOWN_COMMAND(x) MAKE_CMDERR(CMDERR_UNKNOWN_COMMAND, (x))
-#define MAKE_CMDERR_AMBIGUOUS_COMMAND(x) MAKE_CMDERR(CMDERR_AMBIGUOUS_COMMAND, (x))
-#define MAKE_CMDERR_UNBALANCED_PARENS(x) MAKE_CMDERR(CMDERR_UNBALANCED_PARENS, (x))
-#define MAKE_CMDERR_UNBALANCED_QUOTES(x) MAKE_CMDERR(CMDERR_UNBALANCED_QUOTES, (x))
-#define MAKE_CMDERR_NOT_ENOUGH_PARAMS(x) MAKE_CMDERR(CMDERR_NOT_ENOUGH_PARAMS, (x))
-#define MAKE_CMDERR_TOO_MANY_PARAMS(x) MAKE_CMDERR(CMDERR_TOO_MANY_PARAMS, (x))
-#define MAKE_CMDERR_EXPRESSION_ERROR(x) MAKE_CMDERR(CMDERR_EXPRESSION_ERROR, (x))
-
-
-/***************************************************************************
TYPE DEFINITIONS
***************************************************************************/
-/* CMDERR is an error code for command evaluation */
-typedef u32 CMDERR;
+// CMDERR is an error code for command evaluation
+struct CMDERR
+{
+ // values for the error code in a command error
+ static constexpr u32 NONE = 0;
+ static constexpr u32 UNKNOWN_COMMAND = 1;
+ static constexpr u32 AMBIGUOUS_COMMAND = 2;
+ static constexpr u32 UNBALANCED_PARENS = 3;
+ static constexpr u32 UNBALANCED_QUOTES = 4;
+ static constexpr u32 NOT_ENOUGH_PARAMS = 5;
+ static constexpr u32 TOO_MANY_PARAMS = 6;
+ static constexpr u32 EXPRESSION_ERROR = 7;
+
+ u32 val;
+
+ // command error assembly/disassembly
+ constexpr CMDERR(u32 a, u32 b) : val((a << 16) | (b & 0xffff)) { }
+ constexpr u32 ERROR_CLASS() const { return val >> 16; }
+ constexpr u32 ERROR_OFFSET() const { return val & 0xffff; }
+
+ // assemble specific error conditions
+ static constexpr CMDERR MAKE_UNKNOWN_COMMAND(u32 x) { return CMDERR(UNKNOWN_COMMAND, x); }
+ static constexpr CMDERR MAKE_AMBIGUOUS_COMMAND(u32 x) { return CMDERR(AMBIGUOUS_COMMAND, x); }
+ static constexpr CMDERR MAKE_UNBALANCED_PARENS(u32 x) { return CMDERR(UNBALANCED_PARENS, x); }
+ static constexpr CMDERR MAKE_UNBALANCED_QUOTES(u32 x) { return CMDERR(UNBALANCED_QUOTES, x); }
+ static constexpr CMDERR MAKE_NOT_ENOUGH_PARAMS(u32 x) { return CMDERR(NOT_ENOUGH_PARAMS, x); }
+ static constexpr CMDERR MAKE_TOO_MANY_PARAMS(u32 x) { return CMDERR(TOO_MANY_PARAMS, x); }
+ static constexpr CMDERR MAKE_EXPRESSION_ERROR(u32 x) { return CMDERR(EXPRESSION_ERROR, x); }
+};
+
class debugger_console
{
public:
debugger_console(running_machine &machine);
- /* command handling */
+ // command handling
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);
- void vprintf(util::format_argument_pack<std::ostream> &&args);
- void vprintf_wrap(int wrapcol, util::format_argument_pack<std::ostream> const &args);
- void vprintf_wrap(int wrapcol, util::format_argument_pack<std::ostream> &&args);
- text_buffer * get_console_textbuf() const { return m_console_textbuf; }
+ // console management
+ void vprintf(util::format_argument_pack<std::ostream> const &args);
+ void vprintf(util::format_argument_pack<std::ostream> &&args);
+ void vprintf_wrap(int wrapcol, util::format_argument_pack<std::ostream> const &args);
+ void vprintf_wrap(int wrapcol, util::format_argument_pack<std::ostream> &&args);
+ text_buffer &get_console_textbuf() const { return *m_console_textbuf; }
/* errorlog management */
- void errorlog_write_line(const char *line);
- text_buffer * get_errorlog_textbuf() const { return m_errorlog_textbuf; }
+ void errorlog_write_line(const char *line);
+ text_buffer &get_errorlog_textbuf() const { return *m_errorlog_textbuf; }
/* convenience templates */
template <typename Format, typename... Params>
@@ -143,10 +142,10 @@ private:
running_machine &m_machine;
// visible CPU device (the one that commands should apply to)
- device_t *m_visiblecpu;
+ device_t *m_visiblecpu;
- text_buffer *m_console_textbuf;
- text_buffer *m_errorlog_textbuf;
+ text_buffer_ptr m_console_textbuf;
+ text_buffer_ptr m_errorlog_textbuf;
std::forward_list<debug_command> m_commandlist;
diff --git a/src/emu/debug/dvtext.cpp b/src/emu/debug/dvtext.cpp
index 63ad674ec10..6a4d2893562 100644
--- a/src/emu/debug/dvtext.cpp
+++ b/src/emu/debug/dvtext.cpp
@@ -9,10 +9,12 @@
***************************************************************************/
#include "emu.h"
-#include "debugvw.h"
#include "dvtext.h"
+
#include "debugcon.h"
#include "debugger.h"
+#include "debugvw.h"
+
//**************************************************************************
// DEBUG VIEW TEXTBUF
@@ -22,11 +24,16 @@
// debug_view_textbuf - constructor
//-------------------------------------------------
-debug_view_textbuf::debug_view_textbuf(running_machine &machine, debug_view_type type, debug_view_osd_update_func osdupdate, void *osdprivate, text_buffer &textbuf)
- : debug_view(machine, type, osdupdate, osdprivate),
- m_textbuf(textbuf),
- m_at_bottom(true),
- m_topseq(0)
+debug_view_textbuf::debug_view_textbuf(
+ running_machine &machine,
+ debug_view_type type,
+ debug_view_osd_update_func osdupdate,
+ void *osdprivate,
+ text_buffer &textbuf)
+ : debug_view(machine, type, osdupdate, osdprivate)
+ , m_textbuf(textbuf)
+ , m_at_bottom(true)
+ , m_topseq(0)
{
}
@@ -47,7 +54,7 @@ debug_view_textbuf::~debug_view_textbuf()
void debug_view_textbuf::clear()
{
begin_update();
- text_buffer_clear(&m_textbuf);
+ text_buffer_clear(m_textbuf);
m_at_bottom = true;
m_topseq = 0;
end_update();
@@ -61,8 +68,8 @@ void debug_view_textbuf::clear()
void debug_view_textbuf::view_update()
{
// update the console info
- m_total.x = text_buffer_max_width(&m_textbuf);
- m_total.y = text_buffer_num_lines(&m_textbuf);
+ m_total.x = text_buffer_max_width(m_textbuf);
+ m_total.y = text_buffer_num_lines(m_textbuf);
if (m_total.x < 80)
m_total.x = 80;
@@ -71,24 +78,24 @@ void debug_view_textbuf::view_update()
if (!m_at_bottom)
{
curseq = m_topseq;
- if (!text_buffer_get_seqnum_line(&m_textbuf, curseq))
+ if (!text_buffer_get_seqnum_line(m_textbuf, curseq))
m_at_bottom = true;
}
if (m_at_bottom)
{
- curseq = text_buffer_line_index_to_seqnum(&m_textbuf, m_total.y - 1);
+ curseq = text_buffer_line_index_to_seqnum(m_textbuf, m_total.y - 1);
if (m_total.y < m_visible.y)
curseq -= m_total.y - 1;
else
curseq -= m_visible.y - 1;
}
- m_topleft.y = curseq - text_buffer_line_index_to_seqnum(&m_textbuf, 0);
+ m_topleft.y = curseq - text_buffer_line_index_to_seqnum(m_textbuf, 0);
// loop over visible rows
debug_view_char *dest = &m_viewdata[0];
for (u32 row = 0; row < m_visible.y; row++)
{
- const char *line = text_buffer_get_seqnum_line(&m_textbuf, curseq++);
+ const char *line = text_buffer_get_seqnum_line(m_textbuf, curseq++);
u32 col = 0;
// if this visible row is valid, add it to the buffer
@@ -133,7 +140,7 @@ void debug_view_textbuf::view_notify(debug_view_notification type)
/* otherwise, track the seqence number of the top line */
if (!m_at_bottom)
- m_topseq = text_buffer_line_index_to_seqnum(&m_textbuf, m_topleft.y);
+ m_topseq = text_buffer_line_index_to_seqnum(m_textbuf, m_topleft.y);
}
}
@@ -148,7 +155,7 @@ void debug_view_textbuf::view_notify(debug_view_notification type)
//-------------------------------------------------
debug_view_console::debug_view_console(running_machine &machine, debug_view_osd_update_func osdupdate, void *osdprivate)
- : debug_view_textbuf(machine, DVT_CONSOLE, osdupdate, osdprivate, *machine.debugger().console().get_console_textbuf())
+ : debug_view_textbuf(machine, DVT_CONSOLE, osdupdate, osdprivate, machine.debugger().console().get_console_textbuf())
{
}
@@ -163,6 +170,6 @@ debug_view_console::debug_view_console(running_machine &machine, debug_view_osd_
//-------------------------------------------------
debug_view_log::debug_view_log(running_machine &machine, debug_view_osd_update_func osdupdate, void *osdprivate)
- : debug_view_textbuf(machine, DVT_LOG, osdupdate, osdprivate, *machine.debugger().console().get_errorlog_textbuf())
+ : debug_view_textbuf(machine, DVT_LOG, osdupdate, osdprivate, machine.debugger().console().get_errorlog_textbuf())
{
}
diff --git a/src/emu/debug/dvtext.h b/src/emu/debug/dvtext.h
index 14a323794db..e6b65c137b3 100644
--- a/src/emu/debug/dvtext.h
+++ b/src/emu/debug/dvtext.h
@@ -31,7 +31,12 @@ public:
protected:
// construction/destruction
- debug_view_textbuf(running_machine &machine, debug_view_type type, debug_view_osd_update_func osdupdate, void *osdprivate, text_buffer &textbuf);
+ debug_view_textbuf(
+ running_machine &machine,
+ debug_view_type type,
+ debug_view_osd_update_func osdupdate,
+ void *osdprivate,
+ text_buffer &textbuf);
virtual ~debug_view_textbuf();
protected:
@@ -41,9 +46,9 @@ protected:
private:
// internal state
- text_buffer & m_textbuf; /* pointer to the text buffer */
- bool m_at_bottom; /* are we tracking new stuff being added? */
- u32 m_topseq; /* sequence number of the top line */
+ text_buffer & m_textbuf; // pointer to the text buffer
+ bool m_at_bottom; // are we tracking new stuff being added?
+ u32 m_topseq; // sequence number of the top line
};
diff --git a/src/emu/debug/textbuf.cpp b/src/emu/debug/textbuf.cpp
index 395a58482a7..ab7bf6505b3 100644
--- a/src/emu/debug/textbuf.cpp
+++ b/src/emu/debug/textbuf.cpp
@@ -35,24 +35,17 @@ struct text_buffer
, linesize(lineoffs ? lines : 0)
{
}
- ~text_buffer()
- {
- if (buffer)
- delete [] buffer;
- if (lineoffs)
- delete [] lineoffs;
- }
- char *const buffer;
- s32 *const lineoffs;
- s32 const bufsize;
- s32 bufstart = 0;
- s32 bufend = 0;
- s32 const linesize;
- s32 linestart = 0;
- s32 lineend = 0;
- u32 linestartseq = 0;
- s32 maxwidth = 0;
+ std::unique_ptr<char []> const buffer;
+ std::unique_ptr<s32 []> const lineoffs;
+ s32 const bufsize;
+ s32 bufstart = 0;
+ s32 bufend = 0;
+ s32 const linesize;
+ s32 linestart = 0;
+ s32 lineend = 0;
+ u32 linestartseq = 0;
+ s32 maxwidth = 0;
/*-------------------------------------------------
buffer_used - return the number of bytes
@@ -88,22 +81,19 @@ struct text_buffer
text_buffer_alloc - allocate a new text buffer
-------------------------------------------------*/
-text_buffer *text_buffer_alloc(u32 bytes, u32 lines)
+text_buffer_ptr text_buffer_alloc(u32 bytes, u32 lines)
{
// allocate memory for the text buffer object
- text_buffer *const text(new (std::nothrow) text_buffer(bytes, lines));
+ text_buffer_ptr text(new (std::nothrow) text_buffer(bytes, lines));
if (!text)
return nullptr;
if (!text->buffer || !text->lineoffs)
- {
- delete text;
return nullptr;
- }
// initialize the buffer description
- text_buffer_clear(text);
+ text_buffer_clear(*text);
return text;
}
@@ -114,7 +104,7 @@ text_buffer *text_buffer_alloc(u32 bytes, u32 lines)
text buffer
-------------------------------------------------*/
-void text_buffer_free(text_buffer *text)
+void text_buffer_deleter::operator()(text_buffer *text) const
{
delete text;
}
@@ -124,21 +114,21 @@ void text_buffer_free(text_buffer *text)
text_buffer_clear - clear a text buffer
-------------------------------------------------*/
-void text_buffer_clear(text_buffer *text)
+void text_buffer_clear(text_buffer &text)
{
- /* reset all the buffer pointers and other bits */
- text->bufstart = 0;
- text->bufend = 0;
+ // reset all the buffer pointers and other bits
+ text.bufstart = 0;
+ text.bufend = 0;
- text->linestart = 0;
- text->lineend = 0;
- text->linestartseq = 0;
+ text.linestart = 0;
+ text.lineend = 0;
+ text.linestartseq = 0;
- text->maxwidth = 0;
+ text.maxwidth = 0;
- /* create the initial line */
- text->lineoffs[0] = 0;
- text->buffer[text->lineoffs[0]] = 0;
+ // create the initial line
+ text.lineoffs[0] = 0;
+ text.buffer[text.lineoffs[0]] = 0;
}
@@ -154,9 +144,9 @@ void text_buffer_clear(text_buffer *text)
buffer
-------------------------------------------------*/
-void text_buffer_print(text_buffer *text, const char *data)
+void text_buffer_print(text_buffer &text, const char *data)
{
- text_buffer_print_wrap(text, data, 10000);
+ text_buffer_print_wrap(text, data, MAX_LINE_LENGTH);
}
@@ -166,21 +156,21 @@ void text_buffer_print(text_buffer *text, const char *data)
column
-------------------------------------------------*/
-void text_buffer_print_wrap(text_buffer *text, const char *data, int wrapcol)
+void text_buffer_print_wrap(text_buffer &text, const char *data, int wrapcol)
{
- s32 stopcol = (wrapcol < MAX_LINE_LENGTH) ? wrapcol : MAX_LINE_LENGTH;
+ s32 const stopcol = (wrapcol < MAX_LINE_LENGTH) ? wrapcol : MAX_LINE_LENGTH;
s32 needed_space;
/* we need to ensure there is enough space for this string plus enough for the max line length */
needed_space = s32(strlen(data)) + MAX_LINE_LENGTH;
/* make space in the buffer if we need to */
- while (text->buffer_space() < needed_space && text->linestart != text->lineend)
+ while (text.buffer_space() < needed_space && text.linestart != text.lineend)
{
- text->linestartseq++;
- if (++text->linestart >= text->linesize)
- text->linestart = 0;
- text->bufstart = text->lineoffs[text->linestart];
+ text.linestartseq++;
+ if (++text.linestart >= text.linesize)
+ text.linestart = 0;
+ text.bufstart = text.lineoffs[text.linestart];
}
/* now add the data */
@@ -191,14 +181,14 @@ void text_buffer_print_wrap(text_buffer *text, const char *data, int wrapcol)
/* a CR resets our position */
if (ch == '\r')
- text->bufend = text->lineoffs[text->lineend];
+ text.bufend = text.lineoffs[text.lineend];
/* non-CR data is just characters */
else if (ch != '\n')
- text->buffer[text->bufend++] = ch;
+ text.buffer[text.bufend++] = ch;
/* an explicit newline or line-too-long condition inserts a newline */
- linelen = text->bufend - text->lineoffs[text->lineend];
+ linelen = text.bufend - text.lineoffs[text.lineend];
if (ch == '\n' || linelen >= stopcol)
{
int overflow = 0;
@@ -208,7 +198,7 @@ void text_buffer_print_wrap(text_buffer *text, const char *data, int wrapcol)
{
/* scan backwards, removing characters along the way */
overflow = 1;
- while (overflow < linelen && text->buffer[text->bufend - overflow] != ' ')
+ while (overflow < linelen && text.buffer[text.bufend - overflow] != ' ')
overflow++;
/* if we found a space, take it; otherwise, reset and pretend we didn't try */
@@ -219,39 +209,39 @@ void text_buffer_print_wrap(text_buffer *text, const char *data, int wrapcol)
}
/* did we beat the max width */
- if (linelen > text->maxwidth)
- text->maxwidth = linelen;
+ if (linelen > text.maxwidth)
+ text.maxwidth = linelen;
/* append a terminator */
if (overflow == 0)
- text->buffer[text->bufend++] = 0;
+ text.buffer[text.bufend++] = 0;
else
- text->buffer[text->bufend - overflow] = 0;
+ text.buffer[text.bufend - overflow] = 0;
/* determine what the next line will be */
- if (++text->lineend >= text->linesize)
- text->lineend = 0;
+ if (++text.lineend >= text.linesize)
+ text.lineend = 0;
/* if we're out of lines, consume the next one */
- if (text->lineend == text->linestart)
+ if (text.lineend == text.linestart)
{
- text->linestartseq++;
- if (++text->linestart >= text->linesize)
- text->linestart = 0;
- text->bufstart = text->lineoffs[text->linestart];
+ text.linestartseq++;
+ if (++text.linestart >= text.linesize)
+ text.linestart = 0;
+ text.bufstart = text.lineoffs[text.linestart];
}
/* if we don't have enough room in the buffer for a max line, wrap to the start */
- if (text->bufend + MAX_LINE_LENGTH + 1 >= text->bufsize)
- text->bufend = 0;
+ if (text.bufend + MAX_LINE_LENGTH + 1 >= text.bufsize)
+ text.bufend = 0;
/* create a new empty line */
- text->lineoffs[text->lineend] = text->bufend - (overflow ? (overflow - 1) : 0);
+ text.lineoffs[text.lineend] = text.bufend - (overflow ? (overflow - 1) : 0);
}
}
/* nullptr terminate what we have on this line */
- text->buffer[text->bufend] = 0;
+ text.buffer[text.bufend] = 0;
}
@@ -267,9 +257,9 @@ void text_buffer_print_wrap(text_buffer *text, const char *data, int wrapcol)
width of all lines seen so far
-------------------------------------------------*/
-u32 text_buffer_max_width(text_buffer *text)
+u32 text_buffer_max_width(text_buffer const &text)
{
- return text->maxwidth;
+ return text.maxwidth;
}
@@ -278,12 +268,10 @@ u32 text_buffer_max_width(text_buffer *text)
lines in the text buffer
-------------------------------------------------*/
-u32 text_buffer_num_lines(text_buffer *text)
+u32 text_buffer_num_lines(text_buffer const &text)
{
- s32 lines = text->lineend + 1 - text->linestart;
- if (lines <= 0)
- lines += text->linesize;
- return lines;
+ s32 const lines = text.lineend + 1 - text.linestart;
+ return (lines <= 0) ? (lines + text.linesize) : lines;
}
@@ -292,9 +280,9 @@ u32 text_buffer_num_lines(text_buffer *text)
line index into a sequence number
-------------------------------------------------*/
-u32 text_buffer_line_index_to_seqnum(text_buffer *text, u32 index)
+u32 text_buffer_line_index_to_seqnum(text_buffer const &text, u32 index)
{
- return text->linestartseq + index;
+ return text.linestartseq + index;
}
@@ -303,18 +291,13 @@ u32 text_buffer_line_index_to_seqnum(text_buffer *text, u32 index)
an indexed line in the buffer
-------------------------------------------------*/
-const char *text_buffer_get_seqnum_line(text_buffer *text, u32 seqnum)
+const char *text_buffer_get_seqnum_line(text_buffer const &text, u32 seqnum)
{
- u32 numlines = text_buffer_num_lines(text);
- u32 index = seqnum - text->linestartseq;
+ u32 const numlines = text_buffer_num_lines(text);
+ u32 const index = seqnum - text.linestartseq;
if (index >= numlines)
return nullptr;
- return &text->buffer[text->lineoffs[(text->linestart + index) % text->linesize]];
-}
-
-text_buffer_lines text_buffer_get_lines(text_buffer *text)
-{
- return text_buffer_lines(*text);
+ return &text.buffer[text.lineoffs[(text.linestart + index) % text.linesize]];
}
/*---------------------------------------------------------------------
@@ -324,22 +307,21 @@ text_buffer_lines text_buffer_get_lines(text_buffer *text)
text_buffer_line text_buffer_lines::text_buffer_line_iterator::operator*() const
{
- const char *line = &m_buffer.buffer[m_buffer.lineoffs[m_lineptr]];
+ char const *const line = &m_buffer.buffer[m_buffer.lineoffs[m_lineptr]];
auto next_lineptr = m_lineptr + 1;
if (next_lineptr == m_buffer.linesize)
next_lineptr = 0;
- const char *nextline = &m_buffer.buffer[m_buffer.lineoffs[next_lineptr]];
-
- /* -1 for the '\0' at the end of line */
+ char const *const nextline = &m_buffer.buffer[m_buffer.lineoffs[next_lineptr]];
+ // -1 for the '\0' at the end of line
ptrdiff_t difference = (nextline - line) - 1;
if (difference < 0)
difference += m_buffer.bufsize;
- return text_buffer_line{ line, (size_t)difference };
+ return text_buffer_line{ line, size_t(difference) };
}
/*---------------------------------------------------------------------
diff --git a/src/emu/debug/textbuf.h b/src/emu/debug/textbuf.h
index f7514701eec..20ad94139bb 100644
--- a/src/emu/debug/textbuf.h
+++ b/src/emu/debug/textbuf.h
@@ -11,8 +11,11 @@
#ifndef MAME_EMU_DEBUG_TEXTBUF_H
#define MAME_EMU_DEBUG_TEXTBUF_H
+#include <memory>
+
#include "emucore.h"
+
/***************************************************************************
TYPE DEFINITIONS
***************************************************************************/
@@ -25,29 +28,27 @@ struct text_buffer_line
size_t length;
};
-/* helper class that makes it possible to iterate over the lines of a text_buffer */
+// helper class for iterating over the lines of a text_buffer
class text_buffer_lines
{
private:
- text_buffer &m_buffer;
+ const text_buffer &m_buffer;
public:
- text_buffer_lines(text_buffer& buffer) : m_buffer(buffer) { }
+ text_buffer_lines(const text_buffer& buffer) : m_buffer(buffer) { }
class text_buffer_line_iterator
{
- text_buffer &m_buffer;
+ const text_buffer &m_buffer;
s32 m_lineptr;
public:
- text_buffer_line_iterator(text_buffer &buffer, s32 lineptr) :
+ text_buffer_line_iterator(const text_buffer &buffer, s32 lineptr) :
m_buffer(buffer),
m_lineptr(lineptr)
{
}
- /* technically this isn't a valid forward iterator, because
- * operator * doesn't return a reference
- */
+ // technically this isn't a valid forward iterator, because operator * doesn't return a reference
text_buffer_line operator*() const;
text_buffer_line_iterator &operator++();
@@ -55,7 +56,7 @@ public:
{
return m_lineptr != rhs.m_lineptr;
}
- /* according to C++ spec, only != is needed; == is present for completeness. */
+ // according to C++ spec, only != is needed; == is present for completeness.
bool operator==(const text_buffer_line_iterator& rhs) { return !operator!=(rhs); }
};
@@ -70,34 +71,32 @@ public:
FUNCTION PROTOTYPES
***************************************************************************/
-/* allocate a new text buffer */
-text_buffer *text_buffer_alloc(u32 bytes, u32 lines);
-
-/* free a text buffer */
-void text_buffer_free(text_buffer *text);
+// free a text buffer
+struct text_buffer_deleter { void operator()(text_buffer *text) const; };
+using text_buffer_ptr = std::unique_ptr<text_buffer, text_buffer_deleter>;
-/* clear a text buffer */
-void text_buffer_clear(text_buffer *text);
+// allocate a new text buffer
+text_buffer_ptr text_buffer_alloc(u32 bytes, u32 lines);
-/* "print" data to a text buffer */
-void text_buffer_print(text_buffer *text, const char *data);
+// clear a text buffer
+void text_buffer_clear(text_buffer &text);
-/* "print" data to a text buffer with word wrapping to a given column */
-void text_buffer_print_wrap(text_buffer *text, const char *data, int wrapcol);
+// "print" data to a text buffer
+void text_buffer_print(text_buffer &text, const char *data);
-/* get the maximum width of lines seen so far */
-u32 text_buffer_max_width(text_buffer *text);
+// "print" data to a text buffer with word wrapping to a given column
+void text_buffer_print_wrap(text_buffer &text, const char *data, int wrapcol);
-/* get the current number of lines in the buffer */
-u32 text_buffer_num_lines(text_buffer *text);
+// get the maximum width of lines seen so far
+u32 text_buffer_max_width(const text_buffer &text);
-/* get an absolute sequence number for a given line */
-u32 text_buffer_line_index_to_seqnum(text_buffer *text, u32 index);
+// get the current number of lines in the buffer
+u32 text_buffer_num_lines(const text_buffer &text);
-/* get a sequenced line from the text buffer */
-const char *text_buffer_get_seqnum_line(text_buffer *text, u32 seqnum);
+// get an absolute sequence number for a given line
+u32 text_buffer_line_index_to_seqnum(const text_buffer &text, u32 index);
-/* get an iterable container of the lines in the buffer */
-text_buffer_lines text_buffer_get_lines(text_buffer* text);
+// get a sequenced line from the text buffer
+const char *text_buffer_get_seqnum_line(const text_buffer &text, u32 seqnum);
-#endif /* MAME_EMU_DEBUG_TEXTBUF_H */
+#endif // MAME_EMU_DEBUG_TEXTBUF_H
diff --git a/src/frontend/mame/luaengine.cpp b/src/frontend/mame/luaengine.cpp
index 4f44c3ad9d4..9afe6827cfd 100644
--- a/src/frontend/mame/luaengine.cpp
+++ b/src/frontend/mame/luaengine.cpp
@@ -1570,7 +1570,7 @@ void lua_engine::initialize()
* debugger.execution_state - accessor for active cpu run state
*/
- struct wrap_textbuf { wrap_textbuf(text_buffer *buf) { textbuf = buf; }; text_buffer *textbuf; };
+ struct wrap_textbuf { wrap_textbuf(const text_buffer &buf) : textbuf(buf) { } std::reference_wrapper<const text_buffer> textbuf; };
auto debugger_type = sol().registry().create_simple_usertype<debugger_manager>("new", sol::no_constructor);
debugger_type.set("command", [](debugger_manager &debug, const std::string &cmd) { debug.console().execute_command(cmd, false); });
diff --git a/src/lib/util/nanosvg.h b/src/lib/util/nanosvg.h
index 6be55cdae32..49940f0b9be 100644
--- a/src/lib/util/nanosvg.h
+++ b/src/lib/util/nanosvg.h
@@ -20,8 +20,8 @@ namespace util {
struct nsvg_deleter
{
- void operator()(NSVGimage *ptr) { nsvgDelete(ptr); }
- void operator()(NSVGrasterizer *ptr) { nsvgDeleteRasterizer(ptr); }
+ void operator()(NSVGimage *ptr) const { nsvgDelete(ptr); }
+ void operator()(NSVGrasterizer *ptr) const { nsvgDeleteRasterizer(ptr); }
};
diff --git a/src/osd/modules/debugger/debuggdbstub.cpp b/src/osd/modules/debugger/debuggdbstub.cpp
index b8c0bbe7b80..80e808ed38f 100644
--- a/src/osd/modules/debugger/debuggdbstub.cpp
+++ b/src/osd/modules/debugger/debuggdbstub.cpp
@@ -889,7 +889,7 @@ debug_gdbstub::cmd_reply debug_gdbstub::handle_q(const char *buf)
if ( !hex_decode(&data, buf, strlen(buf) / 2) )
return REPLY_ENN;
std::string command(data.begin(), data.end());
- text_buffer *textbuf = m_debugger_console->get_console_textbuf();
+ text_buffer &textbuf = m_debugger_console->get_console_textbuf();
text_buffer_clear(textbuf);
m_debugger_console->execute_command(command, false);
uint32_t nlines = text_buffer_num_lines(textbuf);