[PATCH 2/4] Add ui_file::wrap_here
Tom Tromey
tom@tromey.com
Fri Dec 31 22:25:25 GMT 2021
Right now, wrap_here is a global function. In the long run, we'd like
output streams to be relatively self-contained objects, and having a
global function like this is counter to that goal. Also, existing
code freely mixes writes to some parameterized stream with calls to
wrap_here -- but wrap_here only really affects gdb_stdout, so this is
also incoherent.
This step is a patch toward making wrap_here more sane. It adds a
wrap_here method to ui_file and changes ui_out implementations to use
it.
---
gdb/cli-out.c | 2 +-
gdb/mi/mi-out.c | 2 +-
gdb/ui-file.c | 6 ++++++
gdb/ui-file.h | 17 +++++++++++++++++
4 files changed, 25 insertions(+), 2 deletions(-)
diff --git a/gdb/cli-out.c b/gdb/cli-out.c
index 68cf284cf44..02633e5bbbe 100644
--- a/gdb/cli-out.c
+++ b/gdb/cli-out.c
@@ -243,7 +243,7 @@ cli_ui_out::do_wrap_hint (int indent)
if (m_suppress_output)
return;
- wrap_here (indent);
+ m_streams.back ()->wrap_here (indent);
}
void
diff --git a/gdb/mi/mi-out.c b/gdb/mi/mi-out.c
index 6c0d2f04e48..fe58adbbad5 100644
--- a/gdb/mi/mi-out.c
+++ b/gdb/mi/mi-out.c
@@ -174,7 +174,7 @@ mi_ui_out::do_message (const ui_file_style &style,
void
mi_ui_out::do_wrap_hint (int indent)
{
- wrap_here (indent);
+ m_streams.back ()->wrap_here (indent);
}
void
diff --git a/gdb/ui-file.c b/gdb/ui-file.c
index eb1d72bf8b3..bde90a9e6ed 100644
--- a/gdb/ui-file.c
+++ b/gdb/ui-file.c
@@ -68,6 +68,12 @@ ui_file::vprintf (const char *format, va_list args)
vfprintf_unfiltered (this, format, args);
}
+void
+ui_file::wrap_here (int indent)
+{
+ ::wrap_here (indent);
+}
+
void
diff --git a/gdb/ui-file.h b/gdb/ui-file.h
index 0faf84996aa..4e72524b7f0 100644
--- a/gdb/ui-file.h
+++ b/gdb/ui-file.h
@@ -96,6 +96,23 @@ class ui_file
default. */
return false;
}
+
+ /* Indicate that if the next sequence of characters overflows the
+ line, a newline should be inserted here rather than when it hits
+ the end. If INDENT is non-zero, it is a number of spaces to be
+ printed to indent the wrapped part on the next line.
+
+ If the line is already overfull, we immediately print a newline and
+ the indentation, and disable further wrapping.
+
+ If we don't know the width of lines, but we know the page height,
+ we must not wrap words, but should still keep track of newlines
+ that were explicitly printed.
+
+ This routine is guaranteed to force out any output which has been
+ squirreled away in the wrap_buffer, so wrap_here (0) can be
+ used to force out output from the wrap_buffer. */
+ void wrap_here (int indent);
};
typedef std::unique_ptr<ui_file> ui_file_up;
--
2.31.1
More information about the Gdb-patches
mailing list