diff options
author | 2020-05-07 16:27:29 -0400 | |
---|---|---|
committer | 2020-05-07 16:27:29 -0400 | |
commit | fd62dad94985384057e83a0853e517470ca05bd9 (patch) | |
tree | 2f8dbe452ba9f916632ede761d4b7efc1dc43ffb /src/emu/debug/debugcon.cpp | |
parent | 5cf19257895bfe7daf06365e53784bc41455a530 (diff) |
Debugger - add `-debuglog` option to log debug console output to file
When this option is specified, all console output is echoed to a log
file.
Some caveats/limitations:
- The file-open process was copied from -log, so it has the same limits
- Filename is hard-coded (debug.log)
- File is overwritten if it exists
- File is opened during emulation initialization
- Thus, the file is cleared if you invoke the "Hard Reset"
debugger command
- Probably some other details I don't know about
- Logging works as such: When a string is appended to the scrollback
buffer, it is also written to the log file.
Some commands forcibly wrap their output (e.g. `help` to 80 columns.)
Because this wrapping is done inside the scrollback buffer, the text
written to the file is not wrapped.
This can be seen with `help execution`.
Diffstat (limited to 'src/emu/debug/debugcon.cpp')
-rw-r--r-- | src/emu/debug/debugcon.cpp | 43 |
1 files changed, 39 insertions, 4 deletions
diff --git a/src/emu/debug/debugcon.cpp b/src/emu/debug/debugcon.cpp index 2c5989a8faa..55edea82c46 100644 --- a/src/emu/debug/debugcon.cpp +++ b/src/emu/debug/debugcon.cpp @@ -37,6 +37,7 @@ debugger_console::debugger_console(running_machine &machine) : m_machine(machine) , 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); @@ -47,6 +48,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()); @@ -84,6 +88,9 @@ void debugger_console::exit() /* free the command list */ m_commandlist.clear(); + + /* close the logfile, if any */ + m_logfile = nullptr; } @@ -514,6 +521,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 @@ -521,7 +556,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); @@ -529,7 +564,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); @@ -543,7 +578,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); @@ -551,7 +586,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); |