aboutsummaryrefslogtreecommitdiff
path: root/gdb/mi
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2021-12-31 10:40:02 -0700
committerTom Tromey <tom@tromey.com>2022-01-05 11:01:02 -0700
commitd53fd721a18f8c827aa69ffbd15abd99641b5e20 (patch)
tree436641845129a7eb9eb38733a456656da9312366 /gdb/mi
parent28a4e64dd1b17b0d9f267c3466d7da3e8a41afd8 (diff)
downloadgdb-d53fd721a18f8c827aa69ffbd15abd99641b5e20.zip
gdb-d53fd721a18f8c827aa69ffbd15abd99641b5e20.tar.gz
gdb-d53fd721a18f8c827aa69ffbd15abd99641b5e20.tar.bz2
Implement putstr and putstrn in ui_file
In my tour of the ui_file subsystem, I found that fputstr and fputstrn can be simplified. The _filtered forms are never used (and IMO unlikely to ever be used) and so can be removed. And, the interface can be simplified by removing a callback function and moving the implementation directly to ui_file. A new self-test is included. Previously, I think nothing was testing this code. Regression tested on x86-64 Fedora 34.
Diffstat (limited to 'gdb/mi')
-rw-r--r--gdb/mi/mi-console.c20
-rw-r--r--gdb/mi/mi-main.c2
-rw-r--r--gdb/mi/mi-out.c2
3 files changed, 6 insertions, 18 deletions
diff --git a/gdb/mi/mi-console.c b/gdb/mi/mi-console.c
index 157154b..9db87fe 100644
--- a/gdb/mi/mi-console.c
+++ b/gdb/mi/mi-console.c
@@ -48,16 +48,6 @@ 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)
{
@@ -65,12 +55,11 @@ mi_console_file::write_async_safe (const char *buf, long length_buf)
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->putstrn (buf, length_buf, m_quote, true);
m_raw->write_async_safe (&m_quote, 1);
}
else
- fputstrn_unfiltered (buf, length_buf, 0, do_fputc_async_safe, m_raw);
+ m_raw->putstrn (buf, length_buf, 0, true);
char nl = '\n';
m_raw->write_async_safe (&nl, 1);
@@ -91,14 +80,13 @@ mi_console_file::flush ()
if (m_quote)
{
fputc_unfiltered (m_quote, m_raw);
- fputstrn_unfiltered (buf, length_buf, m_quote, fputc_unfiltered,
- m_raw);
+ m_raw->putstrn (buf, length_buf, m_quote);
fputc_unfiltered (m_quote, m_raw);
fputc_unfiltered ('\n', m_raw);
}
else
{
- fputstrn_unfiltered (buf, length_buf, 0, fputc_unfiltered, m_raw);
+ m_raw->putstrn (buf, length_buf, 0);
fputc_unfiltered ('\n', m_raw);
}
gdb_flush (m_raw);
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index e729a86..4860da7 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -1866,7 +1866,7 @@ mi_print_exception (const char *token, const struct gdb_exception &exception)
if (exception.message == NULL)
fputs_unfiltered ("unknown error", mi->raw_stdout);
else
- fputstr_unfiltered (exception.what (), '"', mi->raw_stdout);
+ mi->raw_stdout->putstr (exception.what (), '"');
fputs_unfiltered ("\"", mi->raw_stdout);
switch (exception.error)
diff --git a/gdb/mi/mi-out.c b/gdb/mi/mi-out.c
index e9a4443..20c6f0f 100644
--- a/gdb/mi/mi-out.c
+++ b/gdb/mi/mi-out.c
@@ -135,7 +135,7 @@ mi_ui_out::do_field_string (int fldno, int width, ui_align align,
fprintf_unfiltered (stream, "%s=", fldname);
fprintf_unfiltered (stream, "\"");
if (string)
- fputstr_unfiltered (string, '"', stream);
+ stream->putstr (string, '"');
fprintf_unfiltered (stream, "\"");
}