* lib/mi-support.exp (mi_gdb_load): Fix typo.
[deliverable/binutils-gdb.git] / gdb / memattr.c
index 5e9e9d5c04ebc27cc76f940b71146d4e4eaea9a3..4365e62d2b59264cef610b31c658bd5afbc25b34 100644 (file)
@@ -1,4 +1,24 @@
-/* memattr.c */
+/* Memory attributes support, for GDB.
+
+   Copyright 2001, 2002 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
 #include "defs.h"
 #include "command.h"
 #include "gdbcmd.h"
 #include "language.h"
 #include "gdb_string.h"
 
-/* FIXME: While this conflicts with the enum defined in breakpoint.h,
-   I used them to be consistant with how breakpoints, tracepoints, and
-   displays are implemented.  It doesn't lose now because breakpoint.h
-   is not included.  */
-enum enable
-{
-  disabled,
-  enabled
-};
-
 const struct mem_attrib default_mem_attrib =
 {
   MEM_RW,                      /* mode */
   MEM_WIDTH_UNSPECIFIED,
-  false,                       /* hwbreak */
-  false,                       /* cache */
-  false                                /* verify */
+  0,                           /* hwbreak */
+  0,                           /* cache */
+  0                            /* verify */
 };
 
 static struct mem_region *mem_region_chain = NULL;
-static mem_number = 0;
+static int mem_number = 0;
 
 static struct mem_region *
 create_mem_region (CORE_ADDR lo, CORE_ADDR hi,
                   const struct mem_attrib *attrib)
 {
-  struct mem_region *n, *p, *new;
+  struct mem_region *n, *new;
 
-  if (lo > hi)
+  /* lo == hi is a useless empty region */
+  if (lo >= hi && hi != 0)
     {
-      printf_unfiltered ("invalid memory region\n");
+      printf_unfiltered (_("invalid memory region: low >= high\n"));
       return NULL;
     }
 
@@ -46,19 +57,21 @@ create_mem_region (CORE_ADDR lo, CORE_ADDR hi,
   while (n)
     {
       /* overlapping node */
-      if ((lo >= n->lo && lo <= n->hi) ||
-         (hi >= n->lo && hi <= n->hi))
+      if ((lo >= n->lo && (lo < n->hi || n->hi == 0)) 
+         || (hi > n->lo && (hi <= n->hi || n->hi == 0))
+         || (lo <= n->lo && (hi >= n->hi || hi == 0)))
        {
-         printf_unfiltered ("overlapping memory region\n");
+         printf_unfiltered (_("overlapping memory region\n"));
          return NULL;
        }
+      n = n->next;
     }
 
   new = xmalloc (sizeof (struct mem_region));
   new->lo = lo;
   new->hi = hi;
   new->number = ++mem_number;
-  new->status = enabled;
+  new->enabled_p = 1;
   new->attrib = *attrib;
 
   /* link in new node */
@@ -71,7 +84,7 @@ create_mem_region (CORE_ADDR lo, CORE_ADDR hi,
 static void
 delete_mem_region (struct mem_region *m)
 {
-  free (m);
+  xfree (m);
 }
 
 /*
@@ -97,9 +110,9 @@ lookup_mem_region (CORE_ADDR addr)
 
   for (m = mem_region_chain; m; m = m->next)
     {
-      if (m->status == enabled)
+      if (m->enabled_p == 1)
        {
-         if (addr >= m->lo && addr < m->hi)
+         if (addr >= m->lo && (addr < m->hi || m->hi == 0))
            return m;
 
          if (addr >= m->hi && lo < m->hi)
@@ -127,16 +140,16 @@ mem_command (char *args, int from_tty)
   struct mem_attrib attrib;
 
   if (!args)
-    error_no_arg ("No mem");
+    error_no_arg (_("No mem"));
 
   tok = strtok (args, " \t");
   if (!tok)
-    error ("no lo address");
+    error (_("no lo address"));
   lo = parse_and_eval_address (tok);
 
   tok = strtok (NULL, " \t");
   if (!tok)
-    error ("no hi address");
+    error (_("no hi address"));
   hi = parse_and_eval_address (tok);
 
   attrib = default_mem_attrib;
@@ -154,43 +167,43 @@ mem_command (char *args, int from_tty)
       else if (strcmp (tok, "16") == 0)
        {
          if ((lo % 2 != 0) || (hi % 2 != 0))
-           error ("region bounds not 16 bit aligned");
+           error (_("region bounds not 16 bit aligned"));
          attrib.width = MEM_WIDTH_16;
        }
       else if (strcmp (tok, "32") == 0)
        {
          if ((lo % 4 != 0) || (hi % 4 != 0))
-           error ("region bounds not 32 bit aligned");
+           error (_("region bounds not 32 bit aligned"));
          attrib.width = MEM_WIDTH_32;
        }
       else if (strcmp (tok, "64") == 0)
        {
          if ((lo % 8 != 0) || (hi % 8 != 0))
-           error ("region bounds not 64 bit aligned");
+           error (_("region bounds not 64 bit aligned"));
          attrib.width = MEM_WIDTH_64;
        }
 
 #if 0
       else if (strcmp (tok, "hwbreak") == 0)
-       attrib.hwbreak = true;
+       attrib.hwbreak = 1;
       else if (strcmp (tok, "swbreak") == 0)
-       attrib.hwbreak = false;
+       attrib.hwbreak = 0;
 #endif
 
       else if (strcmp (tok, "cache") == 0)
-       attrib.cache = true;
+       attrib.cache = 1;
       else if (strcmp (tok, "nocache") == 0)
-       attrib.cache = false;
+       attrib.cache = 0;
 
 #if 0
       else if (strcmp (tok, "verify") == 0)
-       attrib.verify = true;
+       attrib.verify = 1;
       else if (strcmp (tok, "noverify") == 0)
-       attrib.verify = false;
+       attrib.verify = 0;
 #endif
 
       else
-       error ("unknown attribute: %s", tok);
+       error (_("unknown attribute: %s"), tok);
     }
 
   create_mem_region (lo, hi, &attrib);
@@ -205,20 +218,50 @@ mem_info_command (char *args, int from_tty)
 
   if (!mem_region_chain)
     {
-      printf_unfiltered ("There are no memory regions defined.\n");
+      printf_unfiltered (_("There are no memory regions defined.\n"));
       return;
     }
 
-  printf_filtered ("Memory regions now in effect:\n");
+  printf_filtered ("Num ");
+  printf_filtered ("Enb ");
+  printf_filtered ("Low Addr   ");
+  if (TARGET_ADDR_BIT > 32)
+    printf_filtered ("        ");
+  printf_filtered ("High Addr  ");
+  if (TARGET_ADDR_BIT > 32)
+    printf_filtered ("        ");
+  printf_filtered ("Attrs ");
+  printf_filtered ("\n");
+
   for (m = mem_region_chain; m; m = m->next)
     {
-      printf_filtered ("%d: %c\t",
+      char *tmp;
+      printf_filtered ("%-3d %-3c\t",
                       m->number,
-                      m->status ? 'y' : 'n');
-      printf_filtered ("%s - ",
-                   local_hex_string_custom ((unsigned long) m->lo, "08l"));
-      printf_filtered ("%s\t",
-                   local_hex_string_custom ((unsigned long) m->hi, "08l"));
+                      m->enabled_p ? 'y' : 'n');
+      if (TARGET_ADDR_BIT <= 32)
+       tmp = hex_string_custom ((unsigned long) m->lo, 8);
+      else
+       tmp = hex_string_custom ((unsigned long) m->lo, 16);
+      
+      printf_filtered ("%s ", tmp);
+
+      if (TARGET_ADDR_BIT <= 32)
+       {
+       if (m->hi == 0)
+         tmp = "0x100000000";
+       else
+         tmp = hex_string_custom ((unsigned long) m->hi, 8);
+       }
+      else
+       {
+       if (m->hi == 0)
+         tmp = "0x10000000000000000";
+       else
+         tmp = hex_string_custom ((unsigned long) m->hi, 16);
+       }
+
+      printf_filtered ("%s ", tmp);
 
       /* Print a token for each attribute.
 
@@ -300,10 +343,10 @@ mem_enable (int num)
   for (m = mem_region_chain; m; m = m->next)
     if (m->number == num)
       {
-       m->status = enabled;
+       m->enabled_p = 1;
        return;
       }
-  printf_unfiltered ("No memory region number %d.\n", num);
+  printf_unfiltered (_("No memory region number %d.\n"), num);
 }
 
 static void
@@ -319,7 +362,7 @@ mem_enable_command (char *args, int from_tty)
   if (p == 0)
     {
       for (m = mem_region_chain; m; m = m->next)
-       m->status = enabled;
+       m->enabled_p = 1;
     }
   else
     while (*p)
@@ -328,7 +371,7 @@ mem_enable_command (char *args, int from_tty)
        while (*p1 >= '0' && *p1 <= '9')
          p1++;
        if (*p1 && *p1 != ' ' && *p1 != '\t')
-         error ("Arguments must be memory region numbers.");
+         error (_("Arguments must be memory region numbers."));
 
        num = atoi (p);
        mem_enable (num);
@@ -350,10 +393,10 @@ mem_disable (int num)
   for (m = mem_region_chain; m; m = m->next)
     if (m->number == num)
       {
-       m->status = disabled;
+       m->enabled_p = 0;
        return;
       }
-  printf_unfiltered ("No memory region number %d.\n", num);
+  printf_unfiltered (_("No memory region number %d.\n"), num);
 }
 
 static void
@@ -369,7 +412,7 @@ mem_disable_command (char *args, int from_tty)
   if (p == 0)
     {
       for (m = mem_region_chain; m; m = m->next)
-       m->status = disabled;
+       m->enabled_p = 0;
     }
   else
     while (*p)
@@ -378,7 +421,7 @@ mem_disable_command (char *args, int from_tty)
        while (*p1 >= '0' && *p1 <= '9')
          p1++;
        if (*p1 && *p1 != ' ' && *p1 != '\t')
-         error ("Arguments must be memory region numbers.");
+         error (_("Arguments must be memory region numbers."));
 
        num = atoi (p);
        mem_disable (num);
@@ -412,7 +455,7 @@ mem_delete (int num)
 
   if (!mem_region_chain)
     {
-      printf_unfiltered ("No memory region number %d.\n", num);
+      printf_unfiltered (_("No memory region number %d.\n"), num);
       return;
     }
 
@@ -458,7 +501,7 @@ mem_delete_command (char *args, int from_tty)
       while (*p1 >= '0' && *p1 <= '9')
        p1++;
       if (*p1 && *p1 != ' ' && *p1 != '\t')
-       error ("Arguments must be memory region numbers.");
+       error (_("Arguments must be memory region numbers."));
 
       num = atoi (p);
       mem_delete (num);
@@ -471,27 +514,36 @@ mem_delete_command (char *args, int from_tty)
   dont_repeat ();
 }
 \f
+extern initialize_file_ftype _initialize_mem; /* -Wmissing-prototype */
+
 void
-_initialize_mem ()
+_initialize_mem (void)
 {
-  add_com ("mem", class_vars, mem_command,
-          "Define attributes for memory region.");
-
-  add_cmd ("mem", class_vars, mem_enable_command,
-          "Enable memory region.\n\
+  add_com ("mem", class_vars, mem_command, _("\
+Define attributes for memory region.\n\
+Usage: mem <lo addr> <hi addr> [<mode> <width> <cache>], \n\
+where <mode>  may be rw (read/write), ro (read-only) or wo (write-only), \n\
+      <width> may be 8, 16, 32, or 64, and \n\
+      <cache> may be cache or nocache"));
+
+  add_cmd ("mem", class_vars, mem_enable_command, _("\
+Enable memory region.\n\
 Arguments are the code numbers of the memory regions to enable.\n\
-Do \"info mem\" to see current list of code numbers.", &enablelist);
+Usage: enable mem <code number>\n\
+Do \"info mem\" to see current list of code numbers."), &enablelist);
 
-  add_cmd ("mem", class_vars, mem_disable_command,
-          "Disable memory region.\n\
+  add_cmd ("mem", class_vars, mem_disable_command, _("\
+Disable memory region.\n\
 Arguments are the code numbers of the memory regions to disable.\n\
-Do \"info mem\" to see current list of code numbers.", &disablelist);
+Usage: disable mem <code number>\n\
+Do \"info mem\" to see current list of code numbers."), &disablelist);
 
-  add_cmd ("mem", class_vars, mem_delete_command,
-          "Delete memory region.\n\
+  add_cmd ("mem", class_vars, mem_delete_command, _("\
+Delete memory region.\n\
 Arguments are the code numbers of the memory regions to delete.\n\
-Do \"info mem\" to see current list of code numbers.", &deletelist);
+Usage: delete mem <code number>\n\
+Do \"info mem\" to see current list of code numbers."), &deletelist);
 
   add_info ("mem", mem_info_command,
-           "Memory region attributes");
+           _("Memory region attributes"));
 }
This page took 0.029965 seconds and 4 git commands to generate.