Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* RFA: Support memory size abbreviations
@ 2007-08-10 11:03 Nick Clifton
  2007-08-13  1:45 ` Ben Elliston
  0 siblings, 1 reply; 2+ messages in thread
From: Nick Clifton @ 2007-08-10 11:03 UTC (permalink / raw)
  To: bje, fche, bje; +Cc: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 938 bytes --]

Hi Ben, Hi Frank,

  I had occasion to use the simulator's --memory-size switch the
  other day and I found it frustrating that it did not allow me to
  specify the size in terms of megabytes.  So I developed this patch
  to support this kind of thing.  With the patch applied you can use
  suffixes to specify the size of memory. eg:

    --memory-size=4m   to specify 4 megabytes of memory
    --memory-size=12k  to specify 12 kilobytes of memory
    --memory-size=2G   to specify 2 gigabytes of memory

  May I apply this patch please ?

Cheers
  Nick

sim/common/ChangeLog
2007-08-10  Nick Clifton  <nickc@redhat.com>

	* sim-memopt.c (memory_options): Mention that the
	--memory-size switch accepts suffixes.
        (parse_size): Handle a suffix on the size value.
        * sim-options.c (standard_options): Mention that the mem-size
	switch accepts suffixes.
        (standard_option_handler): Handle a suffix on the size value.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: common.patch --]
[-- Type: text/x-patch, Size: 4034 bytes --]

Index: sim/common/sim-memopt.c
===================================================================
RCS file: /cvs/src/src/sim/common/sim-memopt.c,v
retrieving revision 1.4
diff -c -3 -p -r1.4 sim-memopt.c
*** sim/common/sim-memopt.c	9 Jan 2007 17:59:16 -0000	1.4
--- sim/common/sim-memopt.c	10 Aug 2007 10:54:01 -0000
*************** static const OPTION memory_options[] =
*** 90,97 ****
        memory_option_handler },
  
    { {"memory-size", required_argument, NULL, OPTION_MEMORY_SIZE },
!       '\0', "SIZE", "Add memory at address zero",
!       memory_option_handler },
  
    { {"memory-fill", required_argument, NULL, OPTION_MEMORY_FILL },
        '\0', "VALUE", "Fill subsequently added memory regions",
--- 90,97 ----
        memory_option_handler },
  
    { {"memory-size", required_argument, NULL, OPTION_MEMORY_SIZE },
!       '\0', "<size>[in bytes, Kb (k suffix), Mb (m suffix) or Gb (g suffix)]",
!      "Add memory at address zero", memory_option_handler },
  
    { {"memory-fill", required_argument, NULL, OPTION_MEMORY_FILL },
        '\0', "VALUE", "Fill subsequently added memory regions",
*************** parse_size (char *chp,
*** 286,296 ****
  	    address_word *nr_bytes,
  	    unsigned *modulo)
  {
!   /* <nr_bytes> [ "%" <modulo> ] */
    *nr_bytes = strtoul (chp, &chp, 0);
!   if (*chp == '%')
      {
        *modulo = strtoul (chp + 1, &chp, 0);
      }
    return chp;
  }
--- 286,313 ----
  	    address_word *nr_bytes,
  	    unsigned *modulo)
  {
!   /* <nr_bytes>[K|M|G] [ "%" <modulo> ] */
    *nr_bytes = strtoul (chp, &chp, 0);
!   switch (*chp)
      {
+     case '%':
        *modulo = strtoul (chp + 1, &chp, 0);
+       break;
+     case 'g': case 'G': /* Gigabyte suffix.  */
+       *nr_bytes <<= 10;
+       /* Fall through.  */
+     case 'm': case 'M': /* Megabyte suffix.  */
+       *nr_bytes <<= 10;
+       /* Fall through.  */
+     case 'k': case 'K': /* Kilobyte suffix.  */
+       *nr_bytes <<= 10;
+       /* Check for a modulo specifier after the suffix.  */
+       ++ chp;
+       if (* chp == 'b' || * chp == 'B')
+ 	++ chp;
+       if (* chp == '%')
+ 	*modulo = strtoul (chp + 1, &chp, 0);
+       break;
      }
    return chp;
  }
Index: sim/common/sim-options.c
===================================================================
RCS file: /cvs/src/src/sim/common/sim-options.c,v
retrieving revision 1.9
diff -c -3 -p -r1.9 sim-options.c
*** sim/common/sim-options.c	9 Jan 2007 17:59:16 -0000	1.9
--- sim/common/sim-options.c	10 Aug 2007 10:54:01 -0000
*************** static const OPTION standard_options[] =
*** 167,174 ****
  
  #ifdef SIM_HAVE_FLATMEM
    { {"mem-size", required_argument, NULL, OPTION_MEM_SIZE},
!       'm', "MEMORY SIZE", "Specify memory size",
!       standard_option_handler },
  #endif
  
    { {"do-command", required_argument, NULL, OPTION_DO_COMMAND},
--- 167,174 ----
  
  #ifdef SIM_HAVE_FLATMEM
    { {"mem-size", required_argument, NULL, OPTION_MEM_SIZE},
!      'm', "<size>[in bytes, Kb (k suffix), Mb (m suffix) or Gb (g suffix)]",
!      "Specify memory size", standard_option_handler },
  #endif
  
    { {"do-command", required_argument, NULL, OPTION_DO_COMMAND},
*************** standard_option_handler (SIM_DESC sd, si
*** 381,387 ****
  #ifdef SIM_HAVE_FLATMEM
      case OPTION_MEM_SIZE:
        {
! 	unsigned long ul = strtol (arg, NULL, 0);
  	/* 16384: some minimal amount */
  	if (! isdigit (arg[0]) || ul < 16384)
  	  {
--- 381,401 ----
  #ifdef SIM_HAVE_FLATMEM
      case OPTION_MEM_SIZE:
        {
! 	char * endp;
! 	unsigned long ul = strtol (arg, &endp, 0);
! 
! 	switch (* endp)
! 	  {
! 	  case 'k': case 'K': size <<= 10; break;
! 	  case 'm': case 'M': size <<= 20; break;
! 	  case 'g': case 'G': size <<= 30; break;
! 	  case ' ': case '\0': case '\t':  break;
! 	  default:
! 	    if (ul > 0)
! 	      sim_io_eprintf (sd, "Ignoring strange character at end of memory size: %c\n", * endp);
! 	    break;
! 	  }
! 
  	/* 16384: some minimal amount */
  	if (! isdigit (arg[0]) || ul < 16384)
  	  {

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

* Re: RFA: Support memory size abbreviations
  2007-08-10 11:03 RFA: Support memory size abbreviations Nick Clifton
@ 2007-08-13  1:45 ` Ben Elliston
  0 siblings, 0 replies; 2+ messages in thread
From: Ben Elliston @ 2007-08-13  1:45 UTC (permalink / raw)
  To: Nick Clifton; +Cc: fche, gdb-patches

On Fri, 2007-08-10 at 12:02 +0100, Nick Clifton wrote:

> sim/common/ChangeLog
> 2007-08-10  Nick Clifton  <nickc@redhat.com>
> 
> 	* sim-memopt.c (memory_options): Mention that the
> 	--memory-size switch accepts suffixes.
>         (parse_size): Handle a suffix on the size value.
>         * sim-options.c (standard_options): Mention that the mem-size
> 	switch accepts suffixes.
>         (standard_option_handler): Handle a suffix on the size value.

This looks okay to me (and I recall at one point being equally annoyed
that this feature wasn't available!)

Cheers, Ben


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

end of thread, other threads:[~2007-08-13  1:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-08-10 11:03 RFA: Support memory size abbreviations Nick Clifton
2007-08-13  1:45 ` Ben Elliston

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