From 9224c862b2c4c42b375fd58b7d99077439cbe635 Mon Sep 17 00:00:00 2001 From: Vas Crabb Date: Tue, 1 Mar 2016 18:57:06 +1100 Subject: [PATCH] Move more things to type-safe printf --- src/emu/debug/debugcon.cpp | 44 ++++++++++++-------------------------- src/emu/debug/debugcon.h | 35 ++++++++++++++++++++---------- src/emu/debug/debugcpu.cpp | 7 ++---- src/emu/debug/debugcpu.h | 8 ++++++- src/lib/util/corestr.cpp | 10 --------- src/lib/util/corestr.h | 1 - 6 files changed, 47 insertions(+), 58 deletions(-) diff --git a/src/emu/debug/debugcon.cpp b/src/emu/debug/debugcon.cpp index 7bf80dd6118..8aebfd1d979 100644 --- a/src/emu/debug/debugcon.cpp +++ b/src/emu/debug/debugcon.cpp @@ -466,21 +466,22 @@ const char *debug_cmderr_to_string(CMDERR error) ***************************************************************************/ /*------------------------------------------------- - debug_console_printf - printfs the given + debug_console_vprintf - vprintfs the given arguments using the format to the debug console -------------------------------------------------*/ -void CLIB_DECL debug_console_printf(running_machine &machine, const char *format, ...) +void debug_console_vprintf(running_machine &machine, util::format_argument_pack const &args) { - std::string buffer; - va_list arg; + text_buffer_print(console_textbuf, util::string_format(args).c_str()); - va_start(arg, format); - strvprintf(buffer, format, arg); - va_end(arg); + /* force an update of any console views */ + machine.debug_view().update_all(DVT_CONSOLE); +} - text_buffer_print(console_textbuf, buffer.c_str()); +void debug_console_vprintf(running_machine &machine, util::format_argument_pack &&args) +{ + text_buffer_print(console_textbuf, util::string_format(std::move(args)).c_str()); /* force an update of any console views */ machine.debug_view().update_all(DVT_CONSOLE); @@ -488,39 +489,22 @@ void CLIB_DECL debug_console_printf(running_machine &machine, const char *format /*------------------------------------------------- - debug_console_vprintf - printfs the given + debug_console_vprintf_wrap - vprintfs the given arguments using the format to the debug console -------------------------------------------------*/ -void CLIB_DECL debug_console_vprintf(running_machine &machine, const char *format, va_list args) +void debug_console_vprintf_wrap(running_machine &machine, int wrapcol, util::format_argument_pack const &args) { - std::string buffer; - - strvprintf(buffer, format, args); - text_buffer_print(console_textbuf, buffer.c_str()); + text_buffer_print_wrap(console_textbuf, util::string_format(args).c_str(), wrapcol); /* force an update of any console views */ machine.debug_view().update_all(DVT_CONSOLE); } - -/*------------------------------------------------- - debug_console_printf_wrap - printfs the given - arguments using the format to the debug - console --------------------------------------------------*/ - -void CLIB_DECL debug_console_printf_wrap(running_machine &machine, int wrapcol, const char *format, ...) +void debug_console_vprintf_wrap(running_machine &machine, int wrapcol, util::format_argument_pack &&args) { - std::string buffer; - va_list arg; - - va_start(arg, format); - strvprintf(buffer, format, arg); - va_end(arg); - - text_buffer_print_wrap(console_textbuf, buffer.c_str(), wrapcol); + text_buffer_print_wrap(console_textbuf, util::string_format(std::move(args)).c_str(), wrapcol); /* force an update of any console views */ machine.debug_view().update_all(DVT_CONSOLE); diff --git a/src/emu/debug/debugcon.h b/src/emu/debug/debugcon.h index 7c688332ed4..c15874184af 100644 --- a/src/emu/debug/debugcon.h +++ b/src/emu/debug/debugcon.h @@ -74,22 +74,35 @@ typedef UINT32 CMDERR; ***************************************************************************/ /* initialization */ -void debug_console_init(running_machine &machine); +void debug_console_init(running_machine &machine); /* command handling */ -CMDERR debug_console_execute_command(running_machine &machine, const char *command, int echo); -CMDERR debug_console_validate_command(running_machine &machine, const char *command); -void debug_console_register_command(running_machine &machine, const char *command, UINT32 flags, int ref, int minparams, int maxparams, void (*handler)(running_machine &machine, int ref, int params, const char **param)); -const char * debug_cmderr_to_string(CMDERR error); +CMDERR debug_console_execute_command(running_machine &machine, const char *command, int echo); +CMDERR debug_console_validate_command(running_machine &machine, const char *command); +void debug_console_register_command(running_machine &machine, const char *command, UINT32 flags, int ref, int minparams, int maxparams, void (*handler)(running_machine &machine, int ref, int params, const char **param)); +const char * debug_cmderr_to_string(CMDERR error); /* console management */ -void CLIB_DECL debug_console_printf(running_machine &machine, const char *format, ...) ATTR_PRINTF(2,3); -void CLIB_DECL debug_console_vprintf(running_machine &machine, const char *format, va_list args); -void CLIB_DECL debug_console_printf_wrap(running_machine &machine, int wrapcol, const char *format, ...) ATTR_PRINTF(3,4); -text_buffer * debug_console_get_textbuf(void); +void debug_console_vprintf(running_machine &machine, util::format_argument_pack const &args); +void debug_console_vprintf(running_machine &machine, util::format_argument_pack &&args); +void debug_console_vprintf_wrap(running_machine &machine, int wrapcol, util::format_argument_pack const &args); +void debug_console_vprintf_wrap(running_machine &machine, int wrapcol, util::format_argument_pack &&args); +text_buffer * debug_console_get_textbuf(void); /* errorlog management */ -void debug_errorlog_write_line(const running_machine &machine, const char *line); -text_buffer * debug_errorlog_get_textbuf(void); +void debug_errorlog_write_line(const running_machine &machine, const char *line); +text_buffer * debug_errorlog_get_textbuf(void); + +/* convenience templates */ +template +inline void debug_console_printf(running_machine &machine, Format &&fmt, Params &&...args) +{ + debug_console_vprintf(machine, util::make_format_argument_pack(std::forward(fmt), std::forward(args)...)); +} +template +inline void debug_console_printf_wrap(running_machine &machine, int wrapcol, Format &&fmt, Params &&...args) +{ + debug_console_vprintf_wrap(machine, wrapcol, util::make_format_argument_pack(std::forward(fmt), std::forward(args)...)); +} #endif diff --git a/src/emu/debug/debugcpu.cpp b/src/emu/debug/debugcpu.cpp index 4bcb66588a9..2b8595b3c30 100644 --- a/src/emu/debug/debugcpu.cpp +++ b/src/emu/debug/debugcpu.cpp @@ -2231,10 +2231,9 @@ void device_debug::go_next_device() // debugger on the next instruction //------------------------------------------------- -void device_debug::halt_on_next_instruction(const char *fmt, ...) +void device_debug::halt_on_next_instruction_impl(util::format_argument_pack &&args) { debugcpu_private *global = m_device.machine().debugcpu_data; - va_list arg; assert(m_exec != nullptr); @@ -2243,9 +2242,7 @@ void device_debug::halt_on_next_instruction(const char *fmt, ...) return; // output the message to the console - va_start(arg, fmt); - debug_console_vprintf(m_device.machine(), fmt, arg); - va_end(arg); + debug_console_vprintf(m_device.machine(), std::move(args)); // if we are live, stop now, otherwise note that we want to break there if (&m_device == global->livecpu) diff --git a/src/emu/debug/debugcpu.h b/src/emu/debug/debugcpu.h index 754411cb3f0..5222c1c6ab5 100644 --- a/src/emu/debug/debugcpu.h +++ b/src/emu/debug/debugcpu.h @@ -209,7 +209,11 @@ public: void go_exception(int exception); void go_milliseconds(UINT64 milliseconds); void go_next_device(); - void halt_on_next_instruction(const char *fmt, ...) ATTR_PRINTF(2,3); + template + void halt_on_next_instruction(Format &&fmt, Params &&... args) + { + halt_on_next_instruction_impl(util::make_format_argument_pack(std::forward(fmt), std::forward(args)...)); + } // breakpoints breakpoint *breakpoint_first() const { return m_bplist; } @@ -275,6 +279,8 @@ public: static const int HISTORY_SIZE = 256; private: + void halt_on_next_instruction_impl(util::format_argument_pack &&args); + // internal helpers void compute_debug_flags(); void prepare_for_step_overout(offs_t pc); diff --git a/src/lib/util/corestr.cpp b/src/lib/util/corestr.cpp index 3c65bcb3db6..2f39bc06ad9 100644 --- a/src/lib/util/corestr.cpp +++ b/src/lib/util/corestr.cpp @@ -198,16 +198,6 @@ char *core_i64_format(UINT64 value, UINT8 mindigits, bool is_octal) #include -int strvprintf(std::string &str, const char *format, va_list args) -{ - char tempbuf[4096]; - int result = vsprintf(tempbuf, format, args); - - // set the result - str.assign(tempbuf); - return result; -} - int strcatvprintf(std::string &str, const char *format, va_list args) { char tempbuf[4096]; diff --git a/src/lib/util/corestr.h b/src/lib/util/corestr.h index 209cde389e1..cfd30d2c653 100644 --- a/src/lib/util/corestr.h +++ b/src/lib/util/corestr.h @@ -66,7 +66,6 @@ char *core_i64_format(UINT64 value, UINT8 mindigits, bool is_octal); char *core_i64_hex_format(UINT64 value, UINT8 mindigits); char *core_i64_oct_format(UINT64 value, UINT8 mindigits); -int strvprintf(std::string &str, const char *format, va_list args); int strcatvprintf(std::string &str, const char *format, va_list args); void strdelchr(std::string& str, char chr);