]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Merge with master branch
authorAaron Merey <amerey@redhat.com>
Wed, 11 May 2022 18:14:35 +0000 (14:14 -0400)
committerAaron Merey <amerey@redhat.com>
Wed, 11 May 2022 18:19:38 +0000 (14:19 -0400)
1  2 
gdb/cli-out.c
gdb/cli-out.h
gdb/debuginfod-support.c
gdb/mi/mi-out.c
gdb/mi/mi-out.h
gdb/ui-out.h

diff --cc gdb/cli-out.c
index ca1071ac31a4d88bebb5b8ff5225ef0ee7c0176a,e0802df352bb1b017f749f1afe05cdfddb8bbf34..51531d9eda23feb3cf3e4eba0d4375515801038e
@@@ -296,104 -274,69 +293,104 @@@ cli_ui_out::do_progress_start (
  */
  
  void
 -cli_ui_out::do_progress_start (const std::string &name, bool should_print)
 +cli_ui_out::do_progress_notify (const std::string &msg, double howmuch)
  {
    struct ui_file *stream = m_streams.back ();
 -  cli_progress_info meter;
 +  cli_progress_info &info (m_progress_info.back ());
  
 -  meter.last_value = 0;
 -  meter.name = name;
 -  if (!stream->isatty ())
 +  if (info.state == progress_update::START)
      {
 -      gdb_printf (stream, "%s...", meter.name.c_str ());
 +      if (!stream->isatty ())
 +      {
-         fprintf_unfiltered (stream, "%s...\n", msg.c_str ());
++        gdb_printf (stream, "%s...\n", msg.c_str ());
 +        info.state = progress_update::WORKING;
 +      }
 +      else
 +      {
-         fprintf_unfiltered (stream, "%s\n", msg.c_str ());
++        gdb_printf (stream, "%s\n", msg.c_str ());
 +        info.state = progress_update::BAR;
 +      }
 +    }
 +
 +  int chars_per_line = get_chars_per_line ();
 +  if (chars_per_line > MAX_CHARS_PER_LINE)
 +    chars_per_line = MAX_CHARS_PER_LINE;
 +
 +  if (chars_per_line <= 0
 +      || info.state == progress_update::WORKING
 +      || !stream->isatty ())
 +    return;
- /*
++
 +  if (howmuch >= 0)
 +    {
 +      int width = chars_per_line - 3;
 +      int max = width * howmuch;
 +
-       fprintf_unfiltered (stream, "\r[");
++      gdb_printf (stream, "\r[");
 +      for (int i = 0; i < width; ++i)
-       fprintf_unfiltered (stream, i < max ? "#" : " ");
-       fprintf_unfiltered (stream, "]");
++      gdb_printf (stream, i < max ? "#" : " ");
++      gdb_printf (stream, "]");
        gdb_flush (stream);
 -      meter.printing = WORKING;
      }
    else
      {
 -      /* Don't actually emit anything until the first call notifies us
 -       of progress.  This makes it so a second progress message can
 -       be started before the first one has been notified, without
 -       messy output.  */
 -      meter.printing = should_print ? START : NO_PRINT;
 +      using namespace std::chrono;
 +      milliseconds diff = duration_cast<milliseconds>
 +      (steady_clock::now () - info.last_update);
 +
-       * Advance the progress indicator at a rate of 1 tick every
-        every 0.5 seconds.  *
++      /* Advance the progress indicator at a rate of 1 tick every
++       every 0.5 seconds.  */
 +      if (diff.count () >= 500)
 +      {
 +        int width = chars_per_line - 3;
 +
-         fprintf_unfiltered (stream, "\r[");
++        gdb_printf (stream, "\r[");
 +          
 +        for (int i = 0; i < width; ++i)
 +          {
 +            if (i >= info.pos % width
 +                && i < (info.pos + 3) % width)
-               fprintf_unfiltered (stream, "#");
++              gdb_printf (stream, "#");
 +            else
-               fprintf_unfiltered (stream, " ");
++              gdb_printf (stream, " ");
 +          }   
 +
-         fprintf_unfiltered (stream, "]");
++        gdb_printf (stream, "]");
 +        gdb_flush (stream);
 +        info.last_update = steady_clock::now ();
 +        info.pos++;
 +      }
      }
- */
 -  m_meters.push_back (std::move (meter));
 +  return;
  }
  
 +/* Clear the current line of the most recent progress update.  Overwrites
 +   the current line with whitespace.  */
 +
  void
 -cli_ui_out::do_progress_notify (double howmuch)
 +cli_ui_out::clear_current_line ()
  {
    struct ui_file *stream = m_streams.back ();
 -  cli_progress_info &meter (m_meters.back ());
 -
 -  if (meter.printing == NO_PRINT)
 -    return;
 -
 -  if (meter.printing == START)
 -    {
 -      gdb_printf (stream, "%s\n", meter.name.c_str ());
 -      gdb_flush (stream);
 -      meter.printing = WORKING;
 -    }
 +  int chars_per_line = get_chars_per_line ();
  
 -  if (meter.printing == WORKING && howmuch >= 1.0)
 -    return;
 +  if (chars_per_line <= 0
 +      || chars_per_line > MAX_CHARS_PER_LINE)
 +    chars_per_line = MAX_CHARS_PER_LINE;
  
 -  if (!stream->isatty ())
 -    return;
 +  int width = chars_per_line;
  
-   fprintf_unfiltered (stream, "\r");
 -  int chars_per_line = get_chars_per_line ();
 -  if (chars_per_line > 0)
 -    {
 -      int i, max;
 -      int width = chars_per_line - 3;
++  gdb_printf (stream, "\r");
 +  for (int i = 0; i < width; ++i)
-     fprintf_unfiltered (stream, " ");
-   fprintf_unfiltered (stream, "\r");
++    gdb_printf (stream, " ");
++  gdb_printf (stream, "\r");
  
 -      max = width * howmuch;
 -      gdb_printf (stream, "\r[");
 -      for (i = 0; i < width; ++i)
 -      gdb_printf (stream, i < max ? "#" : " ");
 -      gdb_printf (stream, "]");
 -      gdb_flush (stream);
 -      meter.printing = PROGRESS;
 -    }
 +  gdb_flush (stream);
  }
  
 +/* Remove the most recent progress update from the stack and
 +   overwrite the current line with whitespace.  */
 +
  void
  cli_ui_out::do_progress_end ()
  {
diff --cc gdb/cli-out.h
Simple merge
index 2d227ba43503ce4b2c828f7b7cfe18687fc8ff50,f2a31ea1952e51b16a18da1056aff74d24c0da02..92aca018954c0870ebb7799539ef63e87d3f92a5
@@@ -78,13 -86,13 +88,13 @@@ debuginfod_exec_query (const unsigned c
  
  struct user_data
  {
-   user_data (const char *desc, std::string &fname)
+   user_data (const char *desc, const char *fname)
 -    : desc (desc), fname (fname), has_printed (false)
 +    : desc (desc), fname (fname)
    { }
  
    const char * const desc;
-   std::string & fname;
 -  const char * const fname;
 -  bool has_printed;
++  const char * fname;
 +  ui_out::progress_update progress;
  };
  
  /* Deleter for a debuginfod_client.  */
@@@ -125,16 -114,11 +135,16 @@@ progressfn (debuginfod_client *c, long 
    user_data *data = static_cast<user_data *> (debuginfod_get_user_data (c));
    gdb_assert (data != nullptr);
  
-                 data->fname.c_str ());
 +  string_file styled_fname (current_uiout->can_emit_style_escape ());
 +  fprintf_styled (&styled_fname, file_name_style.style (), "%s",
++                data->fname);
 +
    if (check_quit_flag ())
      {
-       printf_filtered ("Cancelled download of %s %s\n",
-                      data->desc, styled_fname.c_str ());
 +      current_uiout->do_progress_end (); ///?
 +
 -                data->desc,
 -                styled_string (file_name_style.style (), data->fname));
+       gdb_printf ("Cancelling download of %s %ps...\n",
++                data->desc, styled_fname.c_str ());
        return 1;
      }
  
@@@ -219,43 -233,6 +258,43 @@@ debuginfod_is_enabled (
    return true;
  }
  
-                 data.fname.c_str ());
 +/* Print the result of the most recent attempted download.  */
 +
 +static void
 +print_outcome (user_data &data, int fd)
 +{
 +  /* Clears the current line of progress output.  */
 +  current_uiout->do_progress_end ();
 +
 +  string_file styled_fname (current_uiout->can_emit_style_escape ());
 +  fprintf_styled (&styled_fname, file_name_style.style (), "%s",
-         printf_filtered (_("Retrieved %.02f %s %s %s\n"), size, unit,
-                          data.desc, styled_fname.c_str ());
++                data.fname);
 +
 +  if (debuginfod_verbose > 1 && fd >= 0)
 +    {
 +      struct stat s;
 +
 +      if (fstat (fd, &s) == 0)
 +      {
 +        double size = (double)s.st_size;
 +        const char *unit = "";
 +
 +        get_size_and_unit (&size, &unit);
-   else if (debuginfod_verbose > 0 && fd < 0 && fd != -ENOENT)
-     printf_filtered (_("Download failed: %s. " \
-                      "Continuing without %s %s.\n"),
-                    safe_strerror (-fd), data.desc,
-                    styled_fname.c_str ());
++        gdb_printf (_("Retrieved %.02f %s %s %s\n"), size, unit,
++                    data.desc, styled_fname.c_str ());
 +      }
 +      else
 +      warning (_("Retrieved %s %s but size cannot be read: %s\n"),
 +               data.desc, styled_fname.c_str (),
 +               safe_strerror (errno));
 +    }
++  else if (fd < 0 && fd != -ENOENT)
++    gdb_printf (_("Download failed: %s. " \
++              "Continuing without %s %s.\n"),
++              safe_strerror (-fd), data.desc,
++              styled_fname.c_str ());
 +}
 +
  /* See debuginfod-support.h  */
  
  scoped_fd
diff --cc gdb/mi/mi-out.c
index e5c4e3b8534abee63e7274c879ac06aa79dd040a,567ef83de9bb42b4cfeeb784c3f7bccb2b2d239d..6b3e932ffa4643de612499661cd779b36282af8c
@@@ -258,30 -258,6 +258,30 @@@ mi_ui_out::main_stream (
    return (string_file *) m_streams.back ();
  }
  
-       fprintf_unfiltered (stream, "%s\n", msg.c_str ());
 +void
 +mi_ui_out::do_progress_start ()
 +{
 +  mi_progress_info info;
 +
 +  info.state = progress_update::START;
 +  m_progress_info.push_back (std::move (info));
 +}
 +
 +/* Indicate that a task described by NAME is in progress.  */
 +
 +void
 +mi_ui_out::do_progress_notify (const std::string &msg, double howmuch)
 +{
 +  mi_progress_info &info (m_progress_info.back ());
 +
 +  if (info.state == progress_update::START)
 +    {
 +      struct ui_file *stream = gdb_stdout;
++      gdb_printf (stream, "%s\n", msg.c_str ());
 +      info.state = progress_update::WORKING;
 +    }
 +}
 +
  /* Clear the buffer.  */
  
  void
diff --cc gdb/mi/mi-out.h
Simple merge
diff --cc gdb/ui-out.h
index 175ff5fb156d50e94b198b06ef50f498bcca51af,9e6ff9a29bf0c773c7f7558003b54fbba2159e1c..21e7a2bfbe71786e5a5c871daa3307bff65bcf4b
@@@ -280,38 -277,34 +277,45 @@@ class ui_ou
       escapes.  */
    virtual bool can_emit_style_escape () const = 0;
  
 -  /* An object that starts and finishes a progress meter.  */
 -  class progress_meter
 +  /* An object that starts and finishes displaying progress updates.  */
 +  class progress_update
    {
    public:
 +    /* Represents the printing state of a progress update.  */
 +    enum state
 +    {
 +      /* Printing will start with the next update.  */
 +      START,
 +      /* Printing has already started.  */
 +      WORKING,
 +      /* Progress bar printing has already started.  */
 +      BAR,
 +      /* Printing should not be done.  */
 +      NO_PRINT
 +    };
 +
      /* SHOULD_PRINT indicates whether something should be printed for a tty.  */
 -    progress_meter (struct ui_out *uiout, const std::string &name,
 -                  bool should_print)
 -      : m_uiout (uiout)
 +    progress_update ()
      {
 -      m_uiout->do_progress_start (name, should_print);
 +      m_uiout = current_uiout;
 +      m_uiout->do_progress_start ();
      }
  
 -    ~progress_meter ()
 +    ~progress_update ()
      {
 -      m_uiout->do_progress_notify (1.0);
 -      m_uiout->do_progress_end ();
 +
      }
  
 -    progress_meter (const progress_meter &) = delete;
 -    progress_meter &operator= (const progress_meter &) = delete;
 +    progress_update (const progress_update &) = delete;
 +    progress_update &operator= (const progress_update &) = delete;
  
 -    void progress (double howmuch)
+     /* Emit some progress for this progress meter.  HOWMUCH may range
+        from 0.0 to 1.0.  */
 -      m_uiout->do_progress_notify (howmuch);
++    void progress (const std::string& msg, double howmuch)
+     {
++      m_uiout->do_progress_notify (msg, howmuch);
+     }
    private:
  
      struct ui_out *m_uiout;