From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22300 invoked by alias); 1 Jul 2007 22:10:45 -0000 Received: (qmail 22287 invoked by uid 22791); 1 Jul 2007 22:10:44 -0000 X-Spam-Check-By: sourceware.org Received: from NaN.false.org (HELO nan.false.org) (208.75.86.248) by sourceware.org (qpsmtpd/0.31) with ESMTP; Sun, 01 Jul 2007 22:10:42 +0000 Received: from nan.false.org (localhost [127.0.0.1]) by nan.false.org (Postfix) with ESMTP id 29C4C982B8; Sun, 1 Jul 2007 22:10:41 +0000 (GMT) Received: from caradoc.them.org (22.svnf5.xdsl.nauticom.net [209.195.183.55]) by nan.false.org (Postfix) with ESMTP id A56CA98299; Sun, 1 Jul 2007 22:10:40 +0000 (GMT) Received: from drow by caradoc.them.org with local (Exim 4.67) (envelope-from ) id 1I57cQ-0008Ek-CN; Sun, 01 Jul 2007 18:10:10 -0400 Date: Sun, 01 Jul 2007 22:10:00 -0000 From: Daniel Jacobowitz To: Denis PILAT Cc: Andrew STUBBS , gdb-patches , Ilko Iliev Subject: Re: [rfc] Overflow in transfer-rate Message-ID: <20070701221010.GA30560@caradoc.them.org> Mail-Followup-To: Denis PILAT , Andrew STUBBS , gdb-patches , Ilko Iliev References: <466D3A7D.9030101@st.com> <466D456F.5070406@st.com> <466D4AFD.8070409@st.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <466D4AFD.8070409@st.com> User-Agent: Mutt/1.5.15 (2007-04-09) X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2007-07/txt/msg00015.txt.bz2 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 Daniel Jacobowitz * 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 {