Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [RFA] symfile.c/generic_load cleanups
@ 2002-01-11 14:36 Michael Snyder
  2002-01-11 21:24 ` Elena Zannoni
  0 siblings, 1 reply; 3+ messages in thread
From: Michael Snyder @ 2002-01-11 14:36 UTC (permalink / raw)
  To: gdb-patches; +Cc: ezannoni, jimb


Change some local variables to more appropriate types
(CORE_ADDR was used rather liberally), use a bfd access method
instead of grubbing around in the bfd structure directly, and
clean up some indentation and long lines.

OK to check in?

2002-01-11  Michael Snyder  <msnyder@redhat.com>

	* symfile.c (generic_load): Whitespace and long line cleanups.
	(total_size): Not a CORE_ADDR, change to bfd_size_type.
	(total_sent): Duplicates variable "data_count".  Eliminate.
	(size): Not a CORE_ADDR, change to bfd_size_type.
	(block_size): Not a CORE_ADDR, change to bfd_size_type.
	(sent): Not a CORE_ADDR, change to bfd_size_type.
	(lma): Use bfd access method to get bfd member value.
	(len): Not a CORE_ADDR -- int is sufficient.
	(this_transfer): Not a CORE_ADDR, change to bfd_size_type.
	(print_transfer_performance): Use %lu instead of %ld for ulongs.

Index: symfile.c
===================================================================
RCS file: /cvs/src/src/gdb/symfile.c,v
retrieving revision 1.46
diff -c -3 -p -r1.46 symfile.c
*** symfile.c	2002/01/08 02:09:31	1.46
--- symfile.c	2002/01/11 22:24:13
*************** generic_load (char *args, int from_tty)
*** 1182,1189 ****
    char *filename;
    struct cleanup *old_cleanups;
    char *offptr;
!   CORE_ADDR total_size = 0;
!   CORE_ADDR total_sent = 0;
  
    /* Parse the input argument - the user can specify a load offset as
       a second argument. */
--- 1182,1188 ----
    char *filename;
    struct cleanup *old_cleanups;
    char *offptr;
!   bfd_size_type total_size = 0;
  
    /* Parse the input argument - the user can specify a load offset as
       a second argument. */
*************** generic_load (char *args, int from_tty)
*** 1194,1199 ****
--- 1193,1199 ----
    if (offptr != NULL)
      {
        char *endptr;
+ 
        load_offset = strtoul (offptr, &endptr, 0);
        if (offptr == endptr)
  	error ("Invalid download offset:%s\n", offptr);
*************** generic_load (char *args, int from_tty)
*** 1231,1246 ****
      {
        if (s->flags & SEC_LOAD)
  	{
! 	  CORE_ADDR size = bfd_get_section_size_before_reloc (s);
  	  if (size > 0)
  	    {
  	      char *buffer;
  	      struct cleanup *old_chain;
! 	      CORE_ADDR lma = s->lma + load_offset;
! 	      CORE_ADDR block_size;
  	      int err;
  	      const char *sect_name = bfd_get_section_name (loadfile_bfd, s);
! 	      CORE_ADDR sent;
  
  	      if (download_write_size > 0 && size > download_write_size)
  		block_size = download_write_size;
--- 1231,1247 ----
      {
        if (s->flags & SEC_LOAD)
  	{
! 	  bfd_size_type size = bfd_get_section_size_before_reloc (s);
! 
  	  if (size > 0)
  	    {
  	      char *buffer;
  	      struct cleanup *old_chain;
! 	      CORE_ADDR lma = bfd_section_lma (loadfile_bfd, s) + load_offset;
! 	      bfd_size_type block_size;
  	      int err;
  	      const char *sect_name = bfd_get_section_name (loadfile_bfd, s);
! 	      bfd_size_type sent;
  
  	      if (download_write_size > 0 && size > download_write_size)
  		block_size = download_write_size;
*************** generic_load (char *args, int from_tty)
*** 1253,1260 ****
  	      /* Is this really necessary?  I guess it gives the user something
  	         to look at during a long download.  */
  #ifdef UI_OUT
! 	      ui_out_message (uiout, 0, "Loading section %s, size 0x%s lma 0x%s\n",
! 			   sect_name, paddr_nz (size), paddr_nz (lma));
  #else
  	      fprintf_unfiltered (gdb_stdout,
  				  "Loading section %s, size 0x%s lma 0x%s\n",
--- 1254,1262 ----
  	      /* Is this really necessary?  I guess it gives the user something
  	         to look at during a long download.  */
  #ifdef UI_OUT
! 	      ui_out_message (uiout, 0, 
! 			      "Loading section %s, size 0x%s lma 0x%s\n",
! 			      sect_name, paddr_nz (size), paddr_nz (lma));
  #else
  	      fprintf_unfiltered (gdb_stdout,
  				  "Loading section %s, size 0x%s lma 0x%s\n",
*************** generic_load (char *args, int from_tty)
*** 1266,1273 ****
  	      sent = 0;
  	      do
  		{
! 		  CORE_ADDR len;
! 		  CORE_ADDR this_transfer = size - sent;
  		  if (this_transfer >= block_size)
  		    this_transfer = block_size;
  		  len = target_write_memory_partial (lma, buffer,
--- 1268,1276 ----
  	      sent = 0;
  	      do
  		{
! 		  int len;
! 		  bfd_size_type this_transfer = size - sent;
! 
  		  if (this_transfer >= block_size)
  		    this_transfer = block_size;
  		  len = target_write_memory_partial (lma, buffer,
*************** generic_load (char *args, int from_tty)
*** 1285,1291 ****
                           that.  remote.c could implement that method
                           using the ``qCRC'' packet.  */
  		      char *check = xmalloc (len);
! 		      struct cleanup *verify_cleanups = make_cleanup (xfree, check);
  		      if (target_read_memory (lma, check, len) != 0)
  			error ("Download verify read failed at 0x%s",
  			       paddr (lma));
--- 1288,1296 ----
                           that.  remote.c could implement that method
                           using the ``qCRC'' packet.  */
  		      char *check = xmalloc (len);
! 		      struct cleanup *verify_cleanups = make_cleanup (xfree, 
! 								      check);
! 
  		      if (target_read_memory (lma, check, len) != 0)
  			error ("Download verify read failed at 0x%s",
  			       paddr (lma));
*************** generic_load (char *args, int from_tty)
*** 1299,1317 ****
  		  buffer += len;
  		  write_count += 1;
  		  sent += len;
- 		  total_sent += len;
  		  if (quit_flag
  		      || (ui_load_progress_hook != NULL
  			  && ui_load_progress_hook (sect_name, sent)))
  		    error ("Canceled the download");
  
  		  if (show_load_progress != NULL)
! 		    show_load_progress (sect_name, sent, size, total_sent, total_size);
  		}
  	      while (sent < size);
  
  	      if (err != 0)
! 		error ("Memory access error while loading section %s.", sect_name);
  
  	      do_cleanups (old_chain);
  	    }
--- 1304,1323 ----
  		  buffer += len;
  		  write_count += 1;
  		  sent += len;
  		  if (quit_flag
  		      || (ui_load_progress_hook != NULL
  			  && ui_load_progress_hook (sect_name, sent)))
  		    error ("Canceled the download");
  
  		  if (show_load_progress != NULL)
! 		    show_load_progress (sect_name, sent, size, 
! 					data_count, total_size);
  		}
  	      while (sent < size);
  
  	      if (err != 0)
! 		error ("Memory access error while loading section %s.", 
! 		       sect_name);
  
  	      do_cleanups (old_chain);
  	    }
*************** generic_load (char *args, int from_tty)
*** 1320,1337 ****
  
    end_time = time (NULL);
    {
!     CORE_ADDR entry;
!     entry = bfd_get_start_address (loadfile_bfd);
  #ifdef UI_OUT
!    ui_out_text (uiout, "Start address ");
!    ui_out_field_fmt (uiout, "address", "0x%s" , paddr_nz (entry));
!    ui_out_text (uiout, ", load size ");
!    ui_out_field_fmt (uiout, "load-size", "%ld" , data_count);
!    ui_out_text (uiout, "\n");
  
  #else
      fprintf_unfiltered (gdb_stdout,
! 			"Start address 0x%s , load size %ld\n",
  			paddr_nz (entry), data_count);
  #endif
      /* We were doing this in remote-mips.c, I suspect it is right
--- 1326,1343 ----
  
    end_time = time (NULL);
    {
!     CORE_ADDR entry = bfd_get_start_address (loadfile_bfd);
! 
  #ifdef UI_OUT
!     ui_out_text (uiout, "Start address ");
!     ui_out_field_fmt (uiout, "address", "0x%s", paddr_nz (entry));
!     ui_out_text (uiout, ", load size ");
!     ui_out_field_fmt (uiout, "load-size", "%lu", data_count);
!     ui_out_text (uiout, "\n");
  
  #else
      fprintf_unfiltered (gdb_stdout,
! 			"Start address 0x%s, load size %lu\n",
  			paddr_nz (entry), data_count);
  #endif
      /* We were doing this in remote-mips.c, I suspect it is right
*************** void
*** 1361,1367 ****
  report_transfer_performance (unsigned long data_count, time_t start_time,
  			     time_t end_time)
  {
!   print_transfer_performance (gdb_stdout, data_count, end_time - start_time, 0);
  }
  
  void
--- 1367,1374 ----
  report_transfer_performance (unsigned long data_count, time_t start_time,
  			     time_t end_time)
  {
!   print_transfer_performance (gdb_stdout, data_count, 
! 			      end_time - start_time, 0);
  }
  
  void
*************** print_transfer_performance (struct ui_fi
*** 1374,1403 ****
    ui_out_text (uiout, "Transfer rate: ");
    if (time_count > 0)
      {
!       ui_out_field_fmt (uiout, "transfer-rate", "%ld", 
  			(data_count * 8) / time_count);
        ui_out_text (uiout, " bits/sec");
      }
    else
      {
!       ui_out_field_fmt (uiout, "transferred-bits", "%ld", (data_count * 8));
        ui_out_text (uiout, " bits in <1 sec");    
      }
    if (write_count > 0)
      {
        ui_out_text (uiout, ", ");
!       ui_out_field_fmt (uiout, "write-rate", "%ld", data_count / write_count);
        ui_out_text (uiout, " bytes/write");
      }
    ui_out_text (uiout, ".\n");
  #else
    fprintf_unfiltered (stream, "Transfer rate: ");
    if (time_count > 0)
!     fprintf_unfiltered (stream, "%ld bits/sec", (data_count * 8) / time_count);
    else
!     fprintf_unfiltered (stream, "%ld bits in <1 sec", (data_count * 8));
    if (write_count > 0)
!     fprintf_unfiltered (stream, ", %ld bytes/write", data_count / write_count);
    fprintf_unfiltered (stream, ".\n");
  #endif
  }
--- 1381,1410 ----
    ui_out_text (uiout, "Transfer rate: ");
    if (time_count > 0)
      {
!       ui_out_field_fmt (uiout, "transfer-rate", "%lu", 
  			(data_count * 8) / time_count);
        ui_out_text (uiout, " bits/sec");
      }
    else
      {
!       ui_out_field_fmt (uiout, "transferred-bits", "%lu", (data_count * 8));
        ui_out_text (uiout, " bits in <1 sec");    
      }
    if (write_count > 0)
      {
        ui_out_text (uiout, ", ");
!       ui_out_field_fmt (uiout, "write-rate", "%lu", data_count / write_count);
        ui_out_text (uiout, " bytes/write");
      }
    ui_out_text (uiout, ".\n");
  #else
    fprintf_unfiltered (stream, "Transfer rate: ");
    if (time_count > 0)
!     fprintf_unfiltered (stream, "%lu bits/sec", (data_count * 8) / time_count);
    else
!     fprintf_unfiltered (stream, "%lu bits in <1 sec", (data_count * 8));
    if (write_count > 0)
!     fprintf_unfiltered (stream, ", %lu bytes/write", data_count / write_count);
    fprintf_unfiltered (stream, ".\n");
  #endif
  }


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [RFA] symfile.c/generic_load cleanups
  2002-01-11 14:36 [RFA] symfile.c/generic_load cleanups Michael Snyder
@ 2002-01-11 21:24 ` Elena Zannoni
  2002-01-12 15:45   ` Michael Snyder
  0 siblings, 1 reply; 3+ messages in thread
From: Elena Zannoni @ 2002-01-11 21:24 UTC (permalink / raw)
  To: Michael Snyder; +Cc: gdb-patches, ezannoni, jimb

Michael Snyder writes:
 > 
 > Change some local variables to more appropriate types
 > (CORE_ADDR was used rather liberally), use a bfd access method
 > instead of grubbing around in the bfd structure directly, and
 > clean up some indentation and long lines.
 > 
 > OK to check in?
 > 

Thanks, yes. I verified that it builds with -Werror. Could you clean
up the ChangeLog entry, I don't think we want the names of the
variables mentioned like functions.

Elena


 > 2002-01-11  Michael Snyder  <msnyder@redhat.com>
 > 
 > 	* symfile.c (generic_load): Whitespace and long line cleanups.
 > 	(total_size): Not a CORE_ADDR, change to bfd_size_type.
 > 	(total_sent): Duplicates variable "data_count".  Eliminate.
 > 	(size): Not a CORE_ADDR, change to bfd_size_type.
 > 	(block_size): Not a CORE_ADDR, change to bfd_size_type.
 > 	(sent): Not a CORE_ADDR, change to bfd_size_type.
 > 	(lma): Use bfd access method to get bfd member value.
 > 	(len): Not a CORE_ADDR -- int is sufficient.
 > 	(this_transfer): Not a CORE_ADDR, change to bfd_size_type.
 > 	(print_transfer_performance): Use %lu instead of %ld for ulongs.
 > 
 > Index: symfile.c
 > ===================================================================
 > RCS file: /cvs/src/src/gdb/symfile.c,v
 > retrieving revision 1.46
 > diff -c -3 -p -r1.46 symfile.c
 > *** symfile.c	2002/01/08 02:09:31	1.46
 > --- symfile.c	2002/01/11 22:24:13
 > *************** generic_load (char *args, int from_tty)
 > *** 1182,1189 ****
 >     char *filename;
 >     struct cleanup *old_cleanups;
 >     char *offptr;
 > !   CORE_ADDR total_size = 0;
 > !   CORE_ADDR total_sent = 0;
 >   
 >     /* Parse the input argument - the user can specify a load offset as
 >        a second argument. */
 > --- 1182,1188 ----
 >     char *filename;
 >     struct cleanup *old_cleanups;
 >     char *offptr;
 > !   bfd_size_type total_size = 0;
 >   
 >     /* Parse the input argument - the user can specify a load offset as
 >        a second argument. */
 > *************** generic_load (char *args, int from_tty)
 > *** 1194,1199 ****
 > --- 1193,1199 ----
 >     if (offptr != NULL)
 >       {
 >         char *endptr;
 > + 
 >         load_offset = strtoul (offptr, &endptr, 0);
 >         if (offptr == endptr)
 >   	error ("Invalid download offset:%s\n", offptr);
 > *************** generic_load (char *args, int from_tty)
 > *** 1231,1246 ****
 >       {
 >         if (s->flags & SEC_LOAD)
 >   	{
 > ! 	  CORE_ADDR size = bfd_get_section_size_before_reloc (s);
 >   	  if (size > 0)
 >   	    {
 >   	      char *buffer;
 >   	      struct cleanup *old_chain;
 > ! 	      CORE_ADDR lma = s->lma + load_offset;
 > ! 	      CORE_ADDR block_size;
 >   	      int err;
 >   	      const char *sect_name = bfd_get_section_name (loadfile_bfd, s);
 > ! 	      CORE_ADDR sent;
 >   
 >   	      if (download_write_size > 0 && size > download_write_size)
 >   		block_size = download_write_size;
 > --- 1231,1247 ----
 >       {
 >         if (s->flags & SEC_LOAD)
 >   	{
 > ! 	  bfd_size_type size = bfd_get_section_size_before_reloc (s);
 > ! 
 >   	  if (size > 0)
 >   	    {
 >   	      char *buffer;
 >   	      struct cleanup *old_chain;
 > ! 	      CORE_ADDR lma = bfd_section_lma (loadfile_bfd, s) + load_offset;
 > ! 	      bfd_size_type block_size;
 >   	      int err;
 >   	      const char *sect_name = bfd_get_section_name (loadfile_bfd, s);
 > ! 	      bfd_size_type sent;
 >   
 >   	      if (download_write_size > 0 && size > download_write_size)
 >   		block_size = download_write_size;
 > *************** generic_load (char *args, int from_tty)
 > *** 1253,1260 ****
 >   	      /* Is this really necessary?  I guess it gives the user something
 >   	         to look at during a long download.  */
 >   #ifdef UI_OUT
 > ! 	      ui_out_message (uiout, 0, "Loading section %s, size 0x%s lma 0x%s\n",
 > ! 			   sect_name, paddr_nz (size), paddr_nz (lma));
 >   #else
 >   	      fprintf_unfiltered (gdb_stdout,
 >   				  "Loading section %s, size 0x%s lma 0x%s\n",
 > --- 1254,1262 ----
 >   	      /* Is this really necessary?  I guess it gives the user something
 >   	         to look at during a long download.  */
 >   #ifdef UI_OUT
 > ! 	      ui_out_message (uiout, 0, 
 > ! 			      "Loading section %s, size 0x%s lma 0x%s\n",
 > ! 			      sect_name, paddr_nz (size), paddr_nz (lma));
 >   #else
 >   	      fprintf_unfiltered (gdb_stdout,
 >   				  "Loading section %s, size 0x%s lma 0x%s\n",
 > *************** generic_load (char *args, int from_tty)
 > *** 1266,1273 ****
 >   	      sent = 0;
 >   	      do
 >   		{
 > ! 		  CORE_ADDR len;
 > ! 		  CORE_ADDR this_transfer = size - sent;
 >   		  if (this_transfer >= block_size)
 >   		    this_transfer = block_size;
 >   		  len = target_write_memory_partial (lma, buffer,
 > --- 1268,1276 ----
 >   	      sent = 0;
 >   	      do
 >   		{
 > ! 		  int len;
 > ! 		  bfd_size_type this_transfer = size - sent;
 > ! 
 >   		  if (this_transfer >= block_size)
 >   		    this_transfer = block_size;
 >   		  len = target_write_memory_partial (lma, buffer,
 > *************** generic_load (char *args, int from_tty)
 > *** 1285,1291 ****
 >                            that.  remote.c could implement that method
 >                            using the ``qCRC'' packet.  */
 >   		      char *check = xmalloc (len);
 > ! 		      struct cleanup *verify_cleanups = make_cleanup (xfree, check);
 >   		      if (target_read_memory (lma, check, len) != 0)
 >   			error ("Download verify read failed at 0x%s",
 >   			       paddr (lma));
 > --- 1288,1296 ----
 >                            that.  remote.c could implement that method
 >                            using the ``qCRC'' packet.  */
 >   		      char *check = xmalloc (len);
 > ! 		      struct cleanup *verify_cleanups = make_cleanup (xfree, 
 > ! 								      check);
 > ! 
 >   		      if (target_read_memory (lma, check, len) != 0)
 >   			error ("Download verify read failed at 0x%s",
 >   			       paddr (lma));
 > *************** generic_load (char *args, int from_tty)
 > *** 1299,1317 ****
 >   		  buffer += len;
 >   		  write_count += 1;
 >   		  sent += len;
 > - 		  total_sent += len;
 >   		  if (quit_flag
 >   		      || (ui_load_progress_hook != NULL
 >   			  && ui_load_progress_hook (sect_name, sent)))
 >   		    error ("Canceled the download");
 >   
 >   		  if (show_load_progress != NULL)
 > ! 		    show_load_progress (sect_name, sent, size, total_sent, total_size);
 >   		}
 >   	      while (sent < size);
 >   
 >   	      if (err != 0)
 > ! 		error ("Memory access error while loading section %s.", sect_name);
 >   
 >   	      do_cleanups (old_chain);
 >   	    }
 > --- 1304,1323 ----
 >   		  buffer += len;
 >   		  write_count += 1;
 >   		  sent += len;
 >   		  if (quit_flag
 >   		      || (ui_load_progress_hook != NULL
 >   			  && ui_load_progress_hook (sect_name, sent)))
 >   		    error ("Canceled the download");
 >   
 >   		  if (show_load_progress != NULL)
 > ! 		    show_load_progress (sect_name, sent, size, 
 > ! 					data_count, total_size);
 >   		}
 >   	      while (sent < size);
 >   
 >   	      if (err != 0)
 > ! 		error ("Memory access error while loading section %s.", 
 > ! 		       sect_name);
 >   
 >   	      do_cleanups (old_chain);
 >   	    }
 > *************** generic_load (char *args, int from_tty)
 > *** 1320,1337 ****
 >   
 >     end_time = time (NULL);
 >     {
 > !     CORE_ADDR entry;
 > !     entry = bfd_get_start_address (loadfile_bfd);
 >   #ifdef UI_OUT
 > !    ui_out_text (uiout, "Start address ");
 > !    ui_out_field_fmt (uiout, "address", "0x%s" , paddr_nz (entry));
 > !    ui_out_text (uiout, ", load size ");
 > !    ui_out_field_fmt (uiout, "load-size", "%ld" , data_count);
 > !    ui_out_text (uiout, "\n");
 >   
 >   #else
 >       fprintf_unfiltered (gdb_stdout,
 > ! 			"Start address 0x%s , load size %ld\n",
 >   			paddr_nz (entry), data_count);
 >   #endif
 >       /* We were doing this in remote-mips.c, I suspect it is right
 > --- 1326,1343 ----
 >   
 >     end_time = time (NULL);
 >     {
 > !     CORE_ADDR entry = bfd_get_start_address (loadfile_bfd);
 > ! 
 >   #ifdef UI_OUT
 > !     ui_out_text (uiout, "Start address ");
 > !     ui_out_field_fmt (uiout, "address", "0x%s", paddr_nz (entry));
 > !     ui_out_text (uiout, ", load size ");
 > !     ui_out_field_fmt (uiout, "load-size", "%lu", data_count);
 > !     ui_out_text (uiout, "\n");
 >   
 >   #else
 >       fprintf_unfiltered (gdb_stdout,
 > ! 			"Start address 0x%s, load size %lu\n",
 >   			paddr_nz (entry), data_count);
 >   #endif
 >       /* We were doing this in remote-mips.c, I suspect it is right
 > *************** void
 > *** 1361,1367 ****
 >   report_transfer_performance (unsigned long data_count, time_t start_time,
 >   			     time_t end_time)
 >   {
 > !   print_transfer_performance (gdb_stdout, data_count, end_time - start_time, 0);
 >   }
 >   
 >   void
 > --- 1367,1374 ----
 >   report_transfer_performance (unsigned long data_count, time_t start_time,
 >   			     time_t end_time)
 >   {
 > !   print_transfer_performance (gdb_stdout, data_count, 
 > ! 			      end_time - start_time, 0);
 >   }
 >   
 >   void
 > *************** print_transfer_performance (struct ui_fi
 > *** 1374,1403 ****
 >     ui_out_text (uiout, "Transfer rate: ");
 >     if (time_count > 0)
 >       {
 > !       ui_out_field_fmt (uiout, "transfer-rate", "%ld", 
 >   			(data_count * 8) / time_count);
 >         ui_out_text (uiout, " bits/sec");
 >       }
 >     else
 >       {
 > !       ui_out_field_fmt (uiout, "transferred-bits", "%ld", (data_count * 8));
 >         ui_out_text (uiout, " bits in <1 sec");    
 >       }
 >     if (write_count > 0)
 >       {
 >         ui_out_text (uiout, ", ");
 > !       ui_out_field_fmt (uiout, "write-rate", "%ld", data_count / write_count);
 >         ui_out_text (uiout, " bytes/write");
 >       }
 >     ui_out_text (uiout, ".\n");
 >   #else
 >     fprintf_unfiltered (stream, "Transfer rate: ");
 >     if (time_count > 0)
 > !     fprintf_unfiltered (stream, "%ld bits/sec", (data_count * 8) / time_count);
 >     else
 > !     fprintf_unfiltered (stream, "%ld bits in <1 sec", (data_count * 8));
 >     if (write_count > 0)
 > !     fprintf_unfiltered (stream, ", %ld bytes/write", data_count / write_count);
 >     fprintf_unfiltered (stream, ".\n");
 >   #endif
 >   }
 > --- 1381,1410 ----
 >     ui_out_text (uiout, "Transfer rate: ");
 >     if (time_count > 0)
 >       {
 > !       ui_out_field_fmt (uiout, "transfer-rate", "%lu", 
 >   			(data_count * 8) / time_count);
 >         ui_out_text (uiout, " bits/sec");
 >       }
 >     else
 >       {
 > !       ui_out_field_fmt (uiout, "transferred-bits", "%lu", (data_count * 8));
 >         ui_out_text (uiout, " bits in <1 sec");    
 >       }
 >     if (write_count > 0)
 >       {
 >         ui_out_text (uiout, ", ");
 > !       ui_out_field_fmt (uiout, "write-rate", "%lu", data_count / write_count);
 >         ui_out_text (uiout, " bytes/write");
 >       }
 >     ui_out_text (uiout, ".\n");
 >   #else
 >     fprintf_unfiltered (stream, "Transfer rate: ");
 >     if (time_count > 0)
 > !     fprintf_unfiltered (stream, "%lu bits/sec", (data_count * 8) / time_count);
 >     else
 > !     fprintf_unfiltered (stream, "%lu bits in <1 sec", (data_count * 8));
 >     if (write_count > 0)
 > !     fprintf_unfiltered (stream, ", %lu bytes/write", data_count / write_count);
 >     fprintf_unfiltered (stream, ".\n");
 >   #endif
 >   }


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [RFA] symfile.c/generic_load cleanups
  2002-01-11 21:24 ` Elena Zannoni
@ 2002-01-12 15:45   ` Michael Snyder
  0 siblings, 0 replies; 3+ messages in thread
From: Michael Snyder @ 2002-01-12 15:45 UTC (permalink / raw)
  To: Elena Zannoni; +Cc: Michael Snyder, gdb-patches, jimb

Elena Zannoni wrote:
> 
> Michael Snyder writes:
>  >
>  > Change some local variables to more appropriate types
>  > (CORE_ADDR was used rather liberally), use a bfd access method
>  > instead of grubbing around in the bfd structure directly, and
>  > clean up some indentation and long lines.
>  >
>  > OK to check in?
>  >
> 
> Thanks, yes. I verified that it builds with -Werror. Could you clean
> up the ChangeLog entry, I don't think we want the names of the
> variables mentioned like functions.

Corrected and committed.  Thanks.
 
>  > 2002-01-11  Michael Snyder  <msnyder@redhat.com>
>  >
>  >      * symfile.c (generic_load): Whitespace and long line cleanups.
>  >      (total_size): Not a CORE_ADDR, change to bfd_size_type.
>  >      (total_sent): Duplicates variable "data_count".  Eliminate.
>  >      (size): Not a CORE_ADDR, change to bfd_size_type.
>  >      (block_size): Not a CORE_ADDR, change to bfd_size_type.
>  >      (sent): Not a CORE_ADDR, change to bfd_size_type.
>  >      (lma): Use bfd access method to get bfd member value.
>  >      (len): Not a CORE_ADDR -- int is sufficient.
>  >      (this_transfer): Not a CORE_ADDR, change to bfd_size_type.
>  >      (print_transfer_performance): Use %lu instead of %ld for ulongs.
>  >
>  > Index: symfile.c
>  > ===================================================================
>  > RCS file: /cvs/src/src/gdb/symfile.c,v
>  > retrieving revision 1.46
>  > diff -c -3 -p -r1.46 symfile.c
>  > *** symfile.c        2002/01/08 02:09:31     1.46
>  > --- symfile.c        2002/01/11 22:24:13
>  > *************** generic_load (char *args, int from_tty)
>  > *** 1182,1189 ****
>  >     char *filename;
>  >     struct cleanup *old_cleanups;
>  >     char *offptr;
>  > !   CORE_ADDR total_size = 0;
>  > !   CORE_ADDR total_sent = 0;
>  >
>  >     /* Parse the input argument - the user can specify a load offset as
>  >        a second argument. */
>  > --- 1182,1188 ----
>  >     char *filename;
>  >     struct cleanup *old_cleanups;
>  >     char *offptr;
>  > !   bfd_size_type total_size = 0;
>  >
>  >     /* Parse the input argument - the user can specify a load offset as
>  >        a second argument. */
>  > *************** generic_load (char *args, int from_tty)
>  > *** 1194,1199 ****
>  > --- 1193,1199 ----
>  >     if (offptr != NULL)
>  >       {
>  >         char *endptr;
>  > +
>  >         load_offset = strtoul (offptr, &endptr, 0);
>  >         if (offptr == endptr)
>  >      error ("Invalid download offset:%s\n", offptr);
>  > *************** generic_load (char *args, int from_tty)
>  > *** 1231,1246 ****
>  >       {
>  >         if (s->flags & SEC_LOAD)
>  >      {
>  > !      CORE_ADDR size = bfd_get_section_size_before_reloc (s);
>  >        if (size > 0)
>  >          {
>  >            char *buffer;
>  >            struct cleanup *old_chain;
>  > !          CORE_ADDR lma = s->lma + load_offset;
>  > !          CORE_ADDR block_size;
>  >            int err;
>  >            const char *sect_name = bfd_get_section_name (loadfile_bfd, s);
>  > !          CORE_ADDR sent;
>  >
>  >            if (download_write_size > 0 && size > download_write_size)
>  >              block_size = download_write_size;
>  > --- 1231,1247 ----
>  >       {
>  >         if (s->flags & SEC_LOAD)
>  >      {
>  > !      bfd_size_type size = bfd_get_section_size_before_reloc (s);
>  > !
>  >        if (size > 0)
>  >          {
>  >            char *buffer;
>  >            struct cleanup *old_chain;
>  > !          CORE_ADDR lma = bfd_section_lma (loadfile_bfd, s) + load_offset;
>  > !          bfd_size_type block_size;
>  >            int err;
>  >            const char *sect_name = bfd_get_section_name (loadfile_bfd, s);
>  > !          bfd_size_type sent;
>  >
>  >            if (download_write_size > 0 && size > download_write_size)
>  >              block_size = download_write_size;
>  > *************** generic_load (char *args, int from_tty)
>  > *** 1253,1260 ****
>  >            /* Is this really necessary?  I guess it gives the user something
>  >               to look at during a long download.  */
>  >   #ifdef UI_OUT
>  > !          ui_out_message (uiout, 0, "Loading section %s, size 0x%s lma 0x%s\n",
>  > !                       sect_name, paddr_nz (size), paddr_nz (lma));
>  >   #else
>  >            fprintf_unfiltered (gdb_stdout,
>  >                                "Loading section %s, size 0x%s lma 0x%s\n",
>  > --- 1254,1262 ----
>  >            /* Is this really necessary?  I guess it gives the user something
>  >               to look at during a long download.  */
>  >   #ifdef UI_OUT
>  > !          ui_out_message (uiout, 0,
>  > !                          "Loading section %s, size 0x%s lma 0x%s\n",
>  > !                          sect_name, paddr_nz (size), paddr_nz (lma));
>  >   #else
>  >            fprintf_unfiltered (gdb_stdout,
>  >                                "Loading section %s, size 0x%s lma 0x%s\n",
>  > *************** generic_load (char *args, int from_tty)
>  > *** 1266,1273 ****
>  >            sent = 0;
>  >            do
>  >              {
>  > !              CORE_ADDR len;
>  > !              CORE_ADDR this_transfer = size - sent;
>  >                if (this_transfer >= block_size)
>  >                  this_transfer = block_size;
>  >                len = target_write_memory_partial (lma, buffer,
>  > --- 1268,1276 ----
>  >            sent = 0;
>  >            do
>  >              {
>  > !              int len;
>  > !              bfd_size_type this_transfer = size - sent;
>  > !
>  >                if (this_transfer >= block_size)
>  >                  this_transfer = block_size;
>  >                len = target_write_memory_partial (lma, buffer,
>  > *************** generic_load (char *args, int from_tty)
>  > *** 1285,1291 ****
>  >                            that.  remote.c could implement that method
>  >                            using the ``qCRC'' packet.  */
>  >                    char *check = xmalloc (len);
>  > !                  struct cleanup *verify_cleanups = make_cleanup (xfree, check);
>  >                    if (target_read_memory (lma, check, len) != 0)
>  >                      error ("Download verify read failed at 0x%s",
>  >                             paddr (lma));
>  > --- 1288,1296 ----
>  >                            that.  remote.c could implement that method
>  >                            using the ``qCRC'' packet.  */
>  >                    char *check = xmalloc (len);
>  > !                  struct cleanup *verify_cleanups = make_cleanup (xfree,
>  > !                                                                  check);
>  > !
>  >                    if (target_read_memory (lma, check, len) != 0)
>  >                      error ("Download verify read failed at 0x%s",
>  >                             paddr (lma));
>  > *************** generic_load (char *args, int from_tty)
>  > *** 1299,1317 ****
>  >                buffer += len;
>  >                write_count += 1;
>  >                sent += len;
>  > -              total_sent += len;
>  >                if (quit_flag
>  >                    || (ui_load_progress_hook != NULL
>  >                        && ui_load_progress_hook (sect_name, sent)))
>  >                  error ("Canceled the download");
>  >
>  >                if (show_load_progress != NULL)
>  > !                show_load_progress (sect_name, sent, size, total_sent, total_size);
>  >              }
>  >            while (sent < size);
>  >
>  >            if (err != 0)
>  > !            error ("Memory access error while loading section %s.", sect_name);
>  >
>  >            do_cleanups (old_chain);
>  >          }
>  > --- 1304,1323 ----
>  >                buffer += len;
>  >                write_count += 1;
>  >                sent += len;
>  >                if (quit_flag
>  >                    || (ui_load_progress_hook != NULL
>  >                        && ui_load_progress_hook (sect_name, sent)))
>  >                  error ("Canceled the download");
>  >
>  >                if (show_load_progress != NULL)
>  > !                show_load_progress (sect_name, sent, size,
>  > !                                    data_count, total_size);
>  >              }
>  >            while (sent < size);
>  >
>  >            if (err != 0)
>  > !            error ("Memory access error while loading section %s.",
>  > !                   sect_name);
>  >
>  >            do_cleanups (old_chain);
>  >          }
>  > *************** generic_load (char *args, int from_tty)
>  > *** 1320,1337 ****
>  >
>  >     end_time = time (NULL);
>  >     {
>  > !     CORE_ADDR entry;
>  > !     entry = bfd_get_start_address (loadfile_bfd);
>  >   #ifdef UI_OUT
>  > !    ui_out_text (uiout, "Start address ");
>  > !    ui_out_field_fmt (uiout, "address", "0x%s" , paddr_nz (entry));
>  > !    ui_out_text (uiout, ", load size ");
>  > !    ui_out_field_fmt (uiout, "load-size", "%ld" , data_count);
>  > !    ui_out_text (uiout, "\n");
>  >
>  >   #else
>  >       fprintf_unfiltered (gdb_stdout,
>  > !                    "Start address 0x%s , load size %ld\n",
>  >                      paddr_nz (entry), data_count);
>  >   #endif
>  >       /* We were doing this in remote-mips.c, I suspect it is right
>  > --- 1326,1343 ----
>  >
>  >     end_time = time (NULL);
>  >     {
>  > !     CORE_ADDR entry = bfd_get_start_address (loadfile_bfd);
>  > !
>  >   #ifdef UI_OUT
>  > !     ui_out_text (uiout, "Start address ");
>  > !     ui_out_field_fmt (uiout, "address", "0x%s", paddr_nz (entry));
>  > !     ui_out_text (uiout, ", load size ");
>  > !     ui_out_field_fmt (uiout, "load-size", "%lu", data_count);
>  > !     ui_out_text (uiout, "\n");
>  >
>  >   #else
>  >       fprintf_unfiltered (gdb_stdout,
>  > !                    "Start address 0x%s, load size %lu\n",
>  >                      paddr_nz (entry), data_count);
>  >   #endif
>  >       /* We were doing this in remote-mips.c, I suspect it is right
>  > *************** void
>  > *** 1361,1367 ****
>  >   report_transfer_performance (unsigned long data_count, time_t start_time,
>  >                           time_t end_time)
>  >   {
>  > !   print_transfer_performance (gdb_stdout, data_count, end_time - start_time, 0);
>  >   }
>  >
>  >   void
>  > --- 1367,1374 ----
>  >   report_transfer_performance (unsigned long data_count, time_t start_time,
>  >                           time_t end_time)
>  >   {
>  > !   print_transfer_performance (gdb_stdout, data_count,
>  > !                          end_time - start_time, 0);
>  >   }
>  >
>  >   void
>  > *************** print_transfer_performance (struct ui_fi
>  > *** 1374,1403 ****
>  >     ui_out_text (uiout, "Transfer rate: ");
>  >     if (time_count > 0)
>  >       {
>  > !       ui_out_field_fmt (uiout, "transfer-rate", "%ld",
>  >                      (data_count * 8) / time_count);
>  >         ui_out_text (uiout, " bits/sec");
>  >       }
>  >     else
>  >       {
>  > !       ui_out_field_fmt (uiout, "transferred-bits", "%ld", (data_count * 8));
>  >         ui_out_text (uiout, " bits in <1 sec");
>  >       }
>  >     if (write_count > 0)
>  >       {
>  >         ui_out_text (uiout, ", ");
>  > !       ui_out_field_fmt (uiout, "write-rate", "%ld", data_count / write_count);
>  >         ui_out_text (uiout, " bytes/write");
>  >       }
>  >     ui_out_text (uiout, ".\n");
>  >   #else
>  >     fprintf_unfiltered (stream, "Transfer rate: ");
>  >     if (time_count > 0)
>  > !     fprintf_unfiltered (stream, "%ld bits/sec", (data_count * 8) / time_count);
>  >     else
>  > !     fprintf_unfiltered (stream, "%ld bits in <1 sec", (data_count * 8));
>  >     if (write_count > 0)
>  > !     fprintf_unfiltered (stream, ", %ld bytes/write", data_count / write_count);
>  >     fprintf_unfiltered (stream, ".\n");
>  >   #endif
>  >   }
>  > --- 1381,1410 ----
>  >     ui_out_text (uiout, "Transfer rate: ");
>  >     if (time_count > 0)
>  >       {
>  > !       ui_out_field_fmt (uiout, "transfer-rate", "%lu",
>  >                      (data_count * 8) / time_count);
>  >         ui_out_text (uiout, " bits/sec");
>  >       }
>  >     else
>  >       {
>  > !       ui_out_field_fmt (uiout, "transferred-bits", "%lu", (data_count * 8));
>  >         ui_out_text (uiout, " bits in <1 sec");
>  >       }
>  >     if (write_count > 0)
>  >       {
>  >         ui_out_text (uiout, ", ");
>  > !       ui_out_field_fmt (uiout, "write-rate", "%lu", data_count / write_count);
>  >         ui_out_text (uiout, " bytes/write");
>  >       }
>  >     ui_out_text (uiout, ".\n");
>  >   #else
>  >     fprintf_unfiltered (stream, "Transfer rate: ");
>  >     if (time_count > 0)
>  > !     fprintf_unfiltered (stream, "%lu bits/sec", (data_count * 8) / time_count);
>  >     else
>  > !     fprintf_unfiltered (stream, "%lu bits in <1 sec", (data_count * 8));
>  >     if (write_count > 0)
>  > !     fprintf_unfiltered (stream, ", %lu bytes/write", data_count / write_count);
>  >     fprintf_unfiltered (stream, ".\n");
>  >   #endif
>  >   }


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2002-01-12 23:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-01-11 14:36 [RFA] symfile.c/generic_load cleanups Michael Snyder
2002-01-11 21:24 ` Elena Zannoni
2002-01-12 15:45   ` Michael Snyder

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox