diff options
Diffstat (limited to 'gdb/mi')
-rw-r--r-- | gdb/mi/mi-console.c | 33 | ||||
-rw-r--r-- | gdb/mi/mi-console.h | 2 |
2 files changed, 33 insertions, 2 deletions
diff --git a/gdb/mi/mi-console.c b/gdb/mi/mi-console.c index 43d5388..248d070 100644 --- a/gdb/mi/mi-console.c +++ b/gdb/mi/mi-console.c @@ -48,6 +48,34 @@ mi_console_file::write (const char *buf, long length_buf) this->flush (); } +/* Write C to STREAM's in an async-safe way. */ + +static int +do_fputc_async_safe (int c, ui_file *stream) +{ + char ch = c; + stream->write_async_safe (&ch, 1); + return c; +} + +void +mi_console_file::write_async_safe (const char *buf, long length_buf) +{ + m_raw->write_async_safe (m_prefix, strlen (m_prefix)); + if (m_quote) + { + m_raw->write_async_safe (&m_quote, 1); + fputstrn_unfiltered (buf, length_buf, m_quote, do_fputc_async_safe, + m_raw); + m_raw->write_async_safe (&m_quote, 1); + } + else + fputstrn_unfiltered (buf, length_buf, 0, do_fputc_async_safe, m_raw); + + char nl = '\n'; + m_raw->write_async_safe (&nl, 1); +} + void mi_console_file::flush () { @@ -63,13 +91,14 @@ mi_console_file::flush () if (m_quote) { fputc_unfiltered (m_quote, m_raw); - fputstrn_unfiltered (buf, length_buf, m_quote, m_raw); + fputstrn_unfiltered (buf, length_buf, m_quote, fputc_unfiltered, + m_raw); fputc_unfiltered (m_quote, m_raw); fputc_unfiltered ('\n', m_raw); } else { - fputstrn_unfiltered (buf, length_buf, 0, m_raw); + fputstrn_unfiltered (buf, length_buf, 0, fputc_unfiltered, m_raw); fputc_unfiltered ('\n', m_raw); } gdb_flush (m_raw); diff --git a/gdb/mi/mi-console.h b/gdb/mi/mi-console.h index fbfa03b..d98a0c8 100644 --- a/gdb/mi/mi-console.h +++ b/gdb/mi/mi-console.h @@ -39,6 +39,8 @@ public: void write (const char *buf, long length_buf) override; + void write_async_safe (const char *buf, long length_buf) override; + private: /* The wrapped raw output stream. */ ui_file *m_raw; |