Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Daniel Jacobowitz <drow@false.org>
To: Denis PILAT <denis.pilat@st.com>
Cc: Andrew STUBBS <andrew.stubbs@st.com>,
		gdb-patches <gdb-patches@sourceware.org>,
		Ilko Iliev <iliev@ronetix.at>
Subject: Re: [rfc] Overflow in transfer-rate
Date: Sun, 01 Jul 2007 22:10:00 -0000	[thread overview]
Message-ID: <20070701221010.GA30560@caradoc.them.org> (raw)
In-Reply-To: <466D4AFD.8070409@st.com>

On Mon, Jun 11, 2007 at 03:15:41PM +0200, Denis PILAT wrote:
> Andrew STUBBS wrote:
> > Denis PILAT wrote:
> >> In symfile.c/print_transfer_performance (), an overflow can occure when 
> >> data_count (see below) is a large number.
> >>
> >> I propose either the following 1st patch, or to pass to "%llu"into the 
> >> ui_out_field_fmt functino call, see the next patch proposal.
> >
> > I might also be worth taking a look at this proposal from some time ago 
> > http://www.cygwin.com/ml/gdb-patches/2006-10/msg00184.html
> >
> Well, it sounds like an internal ST discussion but I prefer the patch in your 
> link, it avoids overflow *and* prints transfer rate in a much clever way.

How about this version, then?  I left GDB/MI behavior unchanged, so
that this does not break GUIs.

-- 
Daniel Jacobowitz
CodeSourcery

2007-07-01  Ilko Iliev  <iliev@ronetix.at>
	    Daniel Jacobowitz  <dan@codesourcery.com>

	* symfile.c (print_transfer_performance): Avoid integer overflow.
	Use larger units.

Index: symfile.c
===================================================================
RCS file: /cvs/src/src/gdb/symfile.c,v
retrieving revision 1.187
diff -u -p -r1.187 symfile.c
--- symfile.c	18 Jun 2007 15:46:38 -0000	1.187
+++ symfile.c	1 Jul 2007 22:08:46 -0000
@@ -1947,7 +1947,7 @@ print_transfer_performance (struct ui_fi
 			    const struct timeval *start_time,
 			    const struct timeval *end_time)
 {
-  unsigned long time_count;
+  ULONGEST time_count;
 
   /* Compute the elapsed time in milliseconds, as a tradeoff between
      accuracy and overflow.  */
@@ -1957,9 +1957,23 @@ print_transfer_performance (struct ui_fi
   ui_out_text (uiout, "Transfer rate: ");
   if (time_count > 0)
     {
-      ui_out_field_fmt (uiout, "transfer-rate", "%lu",
-			1000 * (data_count * 8) / time_count);
-      ui_out_text (uiout, " bits/sec");
+      unsigned long rate = ((ULONGEST) data_count * 1000) / time_count;
+
+      if (ui_out_is_mi_like_p (uiout))
+	{
+	  ui_out_field_fmt (uiout, "transfer-rate", "%lu", rate * 8);
+	  ui_out_text (uiout, " bits/sec");
+	}
+      else if (rate < 1024)
+	{
+	  ui_out_field_fmt (uiout, "transfer-rate", "%lu", rate);
+	  ui_out_text (uiout, " bytes/sec");
+	}
+      else
+	{
+	  ui_out_field_fmt (uiout, "transfer-rate", "%lu", rate / 1024);
+	  ui_out_text (uiout, " KB/sec");
+	}
     }
   else
     {


  reply	other threads:[~2007-07-01 22:10 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-06-11 12:05 Denis PILAT
2007-06-11 12:52 ` Andrew STUBBS
2007-06-11 13:15   ` Denis PILAT
2007-07-01 22:10     ` Daniel Jacobowitz [this message]
2007-07-02  7:36       ` Denis PILAT
2007-07-03 15:32         ` Daniel Jacobowitz
2007-07-04 17:19           ` Joel Brobecker
2007-07-04 18:00             ` Mark Kettenis
2007-07-04 18:15               ` Daniel Jacobowitz
2007-07-04 18:20               ` Joel Brobecker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070701221010.GA30560@caradoc.them.org \
    --to=drow@false.org \
    --cc=andrew.stubbs@st.com \
    --cc=denis.pilat@st.com \
    --cc=gdb-patches@sourceware.org \
    --cc=iliev@ronetix.at \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox