Change the pager to a ui_file

This rewrites the output pager as a ui_file implementation.

A new header is introduced to declare the pager class.  The
implementation remains in utils.c for the time being, because there
are some static globals there that must be used by this code.  (This
could be cleaned up at some future date.)

I went through all the text output in gdb to ensure that this change
should be ok.  There are a few cases:

* Any existing call to printf_unfiltered is required to be avoid the
  pager.  This is ensured directly in the implementation.

* All remaining calls to the f*_unfiltered functions -- the ones that
  take an explicit ui_file -- either send to an unfiltered stream
  (e.g., gdb_stderr), which is obviously ok; or conditionally send to
  gdb_stdout

  I investigated all such calls by searching for:

    grep -e '\bf[a-z0-9_]*_unfiltered' *.[chyl] */*.[ch] | grep -v gdb_stdlog | grep -v gdb_stderr

  This yields a number of candidates to check.

  * The breakpoint _print_recreate family, and
    save_trace_state_variables.  These are used for "save" commands
    and so are fine.

  * Things printing to a temporary stream.  Obviously ok.

  * Disassembly selftests.

  * print_gdb_help - this is non-obvious, but ok because paging isn't
    yet enabled at this point during startup.

  * serial.c - doens't use gdb_stdout

  * The code in compile/.  This is all printing to a file.

  * DWARF DIE dumping - doesn't reference gdb_stdout.

* Calls to the _filtered form -- these are all clearly ok, because if
  they are using gdb_stdout, then filtering will still apply; and if
  not, then filtering never applied and still will not.

Therefore, at this point, there is no longer any distinction between
all the other _filtered and _unfiltered calls, and they can be
unified.

In this patch, take special note of the vfprintf_maybe_filtered and
ui_file::vprintf change.  This is one instance of the above idea,
erasing the distinction between filtered and unfiltered -- in this
part of the change, the "unfiltered_output" flag is never passe to
cli_ui_out.  Subsequent patches will go much further in this
direction.

Also note the can_emit_style_escape changes in ui-file.c.  Checking
against gdb_stdout or gdb_stderr was always a bit of a hack; and now
it is no longer needed, because this is decision can be more fully
delegated to the particular ui_file implementation.

ui_file::can_page is removed, because this patch removed the only call
to it.

I think this is the main part of fixing PR cli/7234.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=7234
This commit is contained in:
Tom Tromey
2022-01-01 13:18:17 -07:00
parent 0e37c0638c
commit 3cd5229387
10 changed files with 230 additions and 192 deletions

View File

@ -99,14 +99,6 @@ public:
virtual int fd () const
{ return -1; }
/* Return true if this object supports paging, false otherwise. */
virtual bool can_page () const
{
/* Almost no file supports paging, which is why this is the
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
@ -122,7 +114,9 @@ public:
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);
virtual void wrap_here (int indent)
{
}
/* Emit an ANSI style escape for STYLE. */
virtual void emit_style_escape (const ui_file_style &style);
@ -275,11 +269,6 @@ public:
int fd () const override
{ return m_fd; }
virtual bool can_page () const override
{
return m_file == stdout;
}
private:
/* Sets the internal stream to FILE, and saves the FILE's file
descriptor in M_FD. */
@ -354,11 +343,16 @@ public:
bool can_emit_style_escape () override;
void flush () override;
virtual bool can_page () const override
void emit_style_escape (const ui_file_style &style) override
{
/* If one of the underlying files can page, then we allow it
here. */
return m_one->can_page () || m_two->can_page ();
m_one->emit_style_escape (style);
m_two->emit_style_escape (style);
}
void reset_style () override
{
m_one->reset_style ();
m_two->reset_style ();
}
void puts_unfiltered (const char *str) override