Move more things to type-safe printf

This commit is contained in:
Vas Crabb 2016-03-01 18:57:06 +11:00
parent 529f4dd341
commit 9224c862b2
6 changed files with 47 additions and 58 deletions

View File

@ -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<std::ostream> 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<std::ostream> &&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<std::ostream> 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<std::ostream> &&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);

View File

@ -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<std::ostream> const &args);
void debug_console_vprintf(running_machine &machine, util::format_argument_pack<std::ostream> &&args);
void debug_console_vprintf_wrap(running_machine &machine, int wrapcol, util::format_argument_pack<std::ostream> const &args);
void debug_console_vprintf_wrap(running_machine &machine, int wrapcol, util::format_argument_pack<std::ostream> &&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 <typename Format, typename... Params>
inline void debug_console_printf(running_machine &machine, Format &&fmt, Params &&...args)
{
debug_console_vprintf(machine, util::make_format_argument_pack(std::forward<Format>(fmt), std::forward<Params>(args)...));
}
template <typename Format, typename... Params>
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<Format>(fmt), std::forward<Params>(args)...));
}
#endif

View File

@ -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<std::ostream> &&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)

View File

@ -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 <typename Format, typename... Params>
void halt_on_next_instruction(Format &&fmt, Params &&... args)
{
halt_on_next_instruction_impl(util::make_format_argument_pack(std::forward<Format>(fmt), std::forward<Params>(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<std::ostream> &&args);
// internal helpers
void compute_debug_flags();
void prepare_for_step_overout(offs_t pc);

View File

@ -198,16 +198,6 @@ char *core_i64_format(UINT64 value, UINT8 mindigits, bool is_octal)
#include <algorithm>
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];

View File

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