diff options
author | 2020-05-30 08:34:30 -0400 | |
---|---|---|
committer | 2020-05-30 08:34:30 -0400 | |
commit | a3a14014ac625f4176a4d50ce1b2b7efbe82078d (patch) | |
tree | 9a5dbe5e54a7bb6fa3756e6af7fb6cd4f6539719 | |
parent | bdf4e2cc930d0d2596cb8c6c9de944fcd0dcf7d7 (diff) | |
parent | fd62dad94985384057e83a0853e517470ca05bd9 (diff) |
Merge pull request #6660 from Stevie-O/debug-console-logging
Debugger - add `-debuglog` option to log debug console output to file
-rw-r--r-- | src/emu/debug/debugcon.cpp | 43 | ||||
-rw-r--r-- | src/emu/debug/debugcon.h | 4 | ||||
-rw-r--r-- | src/emu/emuopts.cpp | 1 | ||||
-rw-r--r-- | src/emu/emuopts.h | 2 | ||||
-rw-r--r-- | src/emu/machine.cpp | 10 | ||||
-rw-r--r-- | src/emu/machine.h | 7 |
6 files changed, 61 insertions, 6 deletions
diff --git a/src/emu/debug/debugcon.cpp b/src/emu/debug/debugcon.cpp index e9c08268338..692c7945445 100644 --- a/src/emu/debug/debugcon.cpp +++ b/src/emu/debug/debugcon.cpp @@ -38,6 +38,7 @@ debugger_console::debugger_console(running_machine &machine) , m_visiblecpu(nullptr) , m_console_textbuf(nullptr) , m_errorlog_textbuf(nullptr) + , m_logfile(nullptr) { /* allocate text buffers */ m_console_textbuf = text_buffer_alloc(CONSOLE_BUF_SIZE, CONSOLE_MAX_LINES); @@ -48,6 +49,9 @@ debugger_console::debugger_console(running_machine &machine) if (!m_errorlog_textbuf) return; + /* due to initialization order, @machine is holding our debug.log handle */ + m_logfile = machine.steal_debuglogfile(); + /* print the opening lines */ printf("%s debugger version %s\n", emulator_info::get_appname(), emulator_info::get_build_version()); printf("Currently targeting %s (%s)\n", m_machine.system().name, m_machine.system().type.fullname()); @@ -96,6 +100,9 @@ void debugger_console::exit() /* free the command list */ m_commandlist.clear(); + + /* close the logfile, if any */ + m_logfile = nullptr; } @@ -538,6 +545,34 @@ std::string debugger_console::cmderr_to_string(CMDERR error) ***************************************************************************/ + +/*------------------------------------------------- + print_core - write preformatted text + to the debug console +-------------------------------------------------*/ + +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); + if (m_logfile) + m_logfile->write(text, strlen(text)); +} + +/*------------------------------------------------- + print_core_wrap - write preformatted text + to the debug console, with wrapping +-------------------------------------------------*/ + +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); + if (m_logfile) + m_logfile->write(text, strlen(text)); +} + /*------------------------------------------------- vprintf - vprintfs the given arguments using the format to the debug console @@ -545,7 +580,7 @@ std::string debugger_console::cmderr_to_string(CMDERR error) void debugger_console::vprintf(util::format_argument_pack<std::ostream> const &args) { - text_buffer_print(m_console_textbuf, util::string_format(args).c_str()); + print_core(util::string_format(args).c_str()); /* force an update of any console views */ m_machine.debug_view().update_all(DVT_CONSOLE); @@ -553,7 +588,7 @@ void debugger_console::vprintf(util::format_argument_pack<std::ostream> const &a void debugger_console::vprintf(util::format_argument_pack<std::ostream> &&args) { - text_buffer_print(m_console_textbuf, util::string_format(std::move(args)).c_str()); + print_core(util::string_format(std::move(args)).c_str()); /* force an update of any console views */ m_machine.debug_view().update_all(DVT_CONSOLE); @@ -567,7 +602,7 @@ void debugger_console::vprintf(util::format_argument_pack<std::ostream> &&args) void debugger_console::vprintf_wrap(int wrapcol, util::format_argument_pack<std::ostream> const &args) { - text_buffer_print_wrap(m_console_textbuf, util::string_format(args).c_str(), wrapcol); + print_core_wrap(util::string_format(args).c_str(), wrapcol); /* force an update of any console views */ m_machine.debug_view().update_all(DVT_CONSOLE); @@ -575,7 +610,7 @@ void debugger_console::vprintf_wrap(int wrapcol, util::format_argument_pack<std: void debugger_console::vprintf_wrap(int wrapcol, util::format_argument_pack<std::ostream> &&args) { - text_buffer_print_wrap(m_console_textbuf, util::string_format(std::move(args)).c_str(), wrapcol); + print_core_wrap(util::string_format(std::move(args)).c_str(), wrapcol); /* force an update of any console views */ m_machine.debug_view().update_all(DVT_CONSOLE); diff --git a/src/emu/debug/debugcon.h b/src/emu/debug/debugcon.h index cabff196d9f..3979393f836 100644 --- a/src/emu/debug/debugcon.h +++ b/src/emu/debug/debugcon.h @@ -122,6 +122,9 @@ private: CMDERR internal_execute_command(bool execute, int params, char **param); CMDERR internal_parse_command(const std::string &original_command, bool execute); + void print_core(const char *text); // core text output + void print_core_wrap(const char *text, int wrapcol); // core text output + struct debug_command { debug_command(const char *_command, u32 _flags, int _ref, int _minparams, int _maxparams, std::function<void(int, const std::vector<std::string> &)> _handler); @@ -147,6 +150,7 @@ private: std::forward_list<debug_command> m_commandlist; std::unique_ptr<std::istream> m_source_file; // script source file + std::unique_ptr<emu_file> m_logfile; // logfile for debug console output }; #endif // MAME_EMU_DEBUG_DEBUGCON_H diff --git a/src/emu/emuopts.cpp b/src/emu/emuopts.cpp index a48a4f80811..a0ff529462e 100644 --- a/src/emu/emuopts.cpp +++ b/src/emu/emuopts.cpp @@ -176,6 +176,7 @@ const options_entry emu_options::s_option_entries[] = { OPTION_DEBUG ";d", "0", OPTION_BOOLEAN, "enable/disable debugger" }, { OPTION_UPDATEINPAUSE, "0", OPTION_BOOLEAN, "keep calling video updates while in pause" }, { OPTION_DEBUGSCRIPT, nullptr, OPTION_STRING, "script for debugger" }, + { OPTION_DEBUGLOG, "0", OPTION_BOOLEAN, "write debug console output to debug.log" }, // comm options { nullptr, nullptr, OPTION_HEADER, "CORE COMM OPTIONS" }, diff --git a/src/emu/emuopts.h b/src/emu/emuopts.h index a1a23e77a2b..5a4bc3f118b 100644 --- a/src/emu/emuopts.h +++ b/src/emu/emuopts.h @@ -154,6 +154,7 @@ #define OPTION_OSLOG "oslog" #define OPTION_UPDATEINPAUSE "update_in_pause" #define OPTION_DEBUGSCRIPT "debugscript" +#define OPTION_DEBUGLOG "debuglog" // core misc options #define OPTION_DRC "drc" @@ -430,6 +431,7 @@ public: bool oslog() const { return bool_value(OPTION_OSLOG); } const char *debug_script() const { return value(OPTION_DEBUGSCRIPT); } bool update_in_pause() const { return bool_value(OPTION_UPDATEINPAUSE); } + bool debuglog() const { return bool_value(OPTION_DEBUGLOG); } // core misc options bool drc() const { return bool_value(OPTION_DRC); } diff --git a/src/emu/machine.cpp b/src/emu/machine.cpp index 7b86af34925..8955446ec3c 100644 --- a/src/emu/machine.cpp +++ b/src/emu/machine.cpp @@ -314,12 +314,20 @@ int running_machine::run(bool quiet) m_logfile = std::make_unique<emu_file>(OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS); osd_file::error filerr = m_logfile->open("error.log"); if (filerr != osd_file::error::NONE) - throw emu_fatalerror("running_machine::run: unable to open log file"); + throw emu_fatalerror("running_machine::run: unable to open error.log file"); using namespace std::placeholders; add_logerror_callback(std::bind(&running_machine::logfile_callback, this, _1)); } + if (options().debug() && options().debuglog()) + { + m_debuglogfile = std::make_unique<emu_file>(OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS); + osd_file::error filerr = m_debuglogfile->open("debug.log"); + if (filerr != osd_file::error::NONE) + throw emu_fatalerror("running_machine::run: unable to open debug.log file"); + } + // then finish setting up our local machine start(); diff --git a/src/emu/machine.h b/src/emu/machine.h index 205988fbbe6..53ebe7f5f87 100644 --- a/src/emu/machine.h +++ b/src/emu/machine.h @@ -264,6 +264,10 @@ private: public: // debugger-related information u32 debug_flags; // the current debug flags + bool debug_enabled() { return (debug_flags & DEBUG_FLAG_ENABLED) != 0; } + + // used by debug_console to take ownership of the debug.log file + std::unique_ptr<emu_file> steal_debuglogfile() { return std::move(m_debuglogfile); } private: class side_effects_disabler { @@ -346,7 +350,8 @@ private: time_t m_base_time; // real time at initial emulation time std::string m_basename; // basename used for game-related paths int m_sample_rate; // the digital audio sample rate - std::unique_ptr<emu_file> m_logfile; // pointer to the active log file + std::unique_ptr<emu_file> m_logfile; // pointer to the active error.log file + std::unique_ptr<emu_file> m_debuglogfile; // pointer to the active debug.log file // load/save management enum class saveload_schedule |