Hurd: Adjust to changes to "push pruning old threads down to the target"
[deliverable/binutils-gdb.git] / gdb / memattr.c
index f8e073226c1b8b85c2fe65cce1c2b5c5d70345d2..1c5c48f65900b81ed28a9a7f18b7a19d8b374251 100644 (file)
@@ -1,13 +1,12 @@
 /* Memory attributes support, for GDB.
 
-   Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007
-   Free Software Foundation, Inc.
+   Copyright (C) 2001-2016 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
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
    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., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301, USA.  */
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "defs.h"
 #include "command.h"
 #include "gdbcmd.h"
 #include "memattr.h"
 #include "target.h"
+#include "target-dcache.h"
 #include "value.h"
 #include "language.h"
 #include "vec.h"
-#include "gdb_string.h"
+#include "breakpoint.h"
+#include "cli/cli-utils.h"
 
 const struct mem_attrib default_mem_attrib =
 {
@@ -67,7 +66,7 @@ static int target_mem_regions_valid;
 /* If this flag is set, gdb will assume that memory ranges not
    specified by the memory map have type MEM_NONE, and will
    emit errors on all accesses to that memory.  */
-static int inaccessible_by_default = 0;
+static int inaccessible_by_default = 1;
 
 static void
 show_inaccessible_by_default (struct ui_file *file, int from_tty,
@@ -75,11 +74,11 @@ show_inaccessible_by_default (struct ui_file *file, int from_tty,
                              const char *value)
 {
   if (inaccessible_by_default)
-    fprintf_filtered (file, _("\
-Unknown memory addresses will be treated as inaccessible.\n"));
+    fprintf_filtered (file, _("Unknown memory addresses will "
+                             "be treated as inaccessible.\n"));
   else
-    fprintf_filtered (file, _("\
-Unknown memory addresses will be treated as RAM.\n"));          
+    fprintf_filtered (file, _("Unknown memory addresses "
+                             "will be treated as RAM.\n"));          
 }
 
 
@@ -99,8 +98,8 @@ mem_region_lessthan (const struct mem_region *lhs,
 int
 mem_region_cmp (const void *untyped_lhs, const void *untyped_rhs)
 {
-  const struct mem_region *lhs = untyped_lhs;
-  const struct mem_region *rhs = untyped_rhs;
+  const struct mem_region *lhs = (const struct mem_region *) untyped_lhs;
+  const struct mem_region *rhs = (const struct mem_region *) untyped_rhs;
 
   if (lhs->lo < rhs->lo)
     return -1;
@@ -113,11 +112,11 @@ mem_region_cmp (const void *untyped_lhs, const void *untyped_rhs)
 /* Allocate a new memory region, with default settings.  */
 
 void
-mem_region_init (struct mem_region *new)
+mem_region_init (struct mem_region *newobj)
 {
-  memset (new, 0, sizeof (struct mem_region));
-  new->enabled_p = 1;
-  new->attrib = default_mem_attrib;
+  memset (newobj, 0, sizeof (struct mem_region));
+  newobj->enabled_p = 1;
+  newobj->attrib = default_mem_attrib;
 }
 
 /* This function should be called before any command which would
@@ -175,21 +174,21 @@ static void
 create_mem_region (CORE_ADDR lo, CORE_ADDR hi,
                   const struct mem_attrib *attrib)
 {
-  struct mem_region new;
+  struct mem_region newobj;
   int i, ix;
 
-  /* lo == hi is a useless empty region */
+  /* lo == hi is a useless empty region */
   if (lo >= hi && hi != 0)
     {
       printf_unfiltered (_("invalid memory region: low >= high\n"));
       return;
     }
 
-  mem_region_init (&new);
-  new.lo = lo;
-  new.hi = hi;
+  mem_region_init (&newobj);
+  newobj.lo = lo;
+  newobj.hi = hi;
 
-  ix = VEC_lower_bound (mem_region_s, mem_region_list, &new,
+  ix = VEC_lower_bound (mem_region_s, mem_region_list, &newobj,
                        mem_region_lessthan);
 
   /* Check for an overlapping memory region.  We only need to check
@@ -208,16 +207,16 @@ create_mem_region (CORE_ADDR lo, CORE_ADDR 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)))
+         || (lo <= n->lo && ((hi >= n->hi && n->hi != 0) || hi == 0)))
        {
          printf_unfiltered (_("overlapping memory region\n"));
          return;
        }
     }
 
-  new.number = ++mem_number;
-  new.attrib = *attrib;
-  VEC_safe_insert (mem_region_s, mem_region_list, ix, &new);
+  newobj.number = ++mem_number;
+  newobj.attrib = *attrib;
+  VEC_safe_insert (mem_region_s, mem_region_list, ix, &newobj);
 }
 
 /*
@@ -255,7 +254,8 @@ lookup_mem_region (CORE_ADDR addr)
     {
       if (m->enabled_p == 1)
        {
-         /* If the address is in the memory region, return that memory range.  */
+         /* If the address is in the memory region, return that
+            memory range.  */
          if (addr >= m->lo && (addr < m->hi || m->hi == 0))
            return m;
 
@@ -294,9 +294,6 @@ lookup_mem_region (CORE_ADDR addr)
 void
 invalidate_target_mem_regions (void)
 {
-  struct mem_region *m;
-  int ix;
-
   if (!target_mem_regions_valid)
     return;
 
@@ -306,7 +303,7 @@ invalidate_target_mem_regions (void)
     mem_region_list = NULL;
 }
 
-/* Clear memory region list */
+/* Clear memory region list */
 
 static void
 mem_clear (void)
@@ -434,10 +431,10 @@ mem_info_command (char *args, int from_tty)
   printf_filtered ("Num ");
   printf_filtered ("Enb ");
   printf_filtered ("Low Addr   ");
-  if (TARGET_ADDR_BIT > 32)
+  if (gdbarch_addr_bit (target_gdbarch ()) > 32)
     printf_filtered ("        ");
   printf_filtered ("High Addr  ");
-  if (TARGET_ADDR_BIT > 32)
+  if (gdbarch_addr_bit (target_gdbarch ()) > 32)
     printf_filtered ("        ");
   printf_filtered ("Attrs ");
   printf_filtered ("\n");
@@ -445,29 +442,30 @@ mem_info_command (char *args, int from_tty)
   for (ix = 0; VEC_iterate (mem_region_s, mem_region_list, ix, m); ix++)
     {
       char *tmp;
+
       printf_filtered ("%-3d %-3c\t",
                       m->number,
                       m->enabled_p ? 'y' : 'n');
-      if (TARGET_ADDR_BIT <= 32)
-       tmp = hex_string_custom ((unsigned long) m->lo, 8);
+      if (gdbarch_addr_bit (target_gdbarch ()) <= 32)
+       tmp = hex_string_custom (m->lo, 8);
       else
-       tmp = hex_string_custom ((unsigned long) m->lo, 16);
+       tmp = hex_string_custom (m->lo, 16);
       
       printf_filtered ("%s ", tmp);
 
-      if (TARGET_ADDR_BIT <= 32)
+      if (gdbarch_addr_bit (target_gdbarch ()) <= 32)
        {
-       if (m->hi == 0)
-         tmp = "0x100000000";
-       else
-         tmp = hex_string_custom ((unsigned long) m->hi, 8);
+         if (m->hi == 0)
+           tmp = "0x100000000";
+         else
+           tmp = hex_string_custom (m->hi, 8);
        }
       else
        {
-       if (m->hi == 0)
-         tmp = "0x10000000000000000";
-       else
-         tmp = hex_string_custom ((unsigned long) m->hi, 16);
+         if (m->hi == 0)
+           tmp = "0x10000000000000000";
+         else
+           tmp = hex_string_custom (m->hi, 16);
        }
 
       printf_filtered ("%s ", tmp);
@@ -545,7 +543,7 @@ mem_info_command (char *args, int from_tty)
 }
 \f
 
-/* Enable the memory region number NUM. */
+/* Enable the memory region number NUM.  */
 
 static void
 mem_enable (int num)
@@ -565,41 +563,32 @@ mem_enable (int num)
 static void
 mem_enable_command (char *args, int from_tty)
 {
-  char *p = args;
-  char *p1;
   int num;
   struct mem_region *m;
   int ix;
 
   require_user_regions (from_tty);
 
-  dcache_invalidate (target_dcache);
+  target_dcache_invalidate ();
 
-  if (p == 0)
-    {
+  if (args == NULL || *args == '\0')
+    { /* Enable all mem regions.  */
       for (ix = 0; VEC_iterate (mem_region_s, mem_region_list, ix, m); ix++)
        m->enabled_p = 1;
     }
   else
-    while (*p)
-      {
-       p1 = p;
-       while (*p1 >= '0' && *p1 <= '9')
-         p1++;
-       if (*p1 && *p1 != ' ' && *p1 != '\t')
-         error (_("Arguments must be memory region numbers."));
-
-       num = atoi (p);
-       mem_enable (num);
-
-       p = p1;
-       while (*p == ' ' || *p == '\t')
-         p++;
-      }
+    {
+      number_or_range_parser parser (args);
+      while (!parser.finished ())
+       {
+         num = parser.get_number ();
+         mem_enable (num);
+       }
+    }
 }
 \f
 
-/* Disable the memory region number NUM. */
+/* Disable the memory region number NUM.  */
 
 static void
 mem_disable (int num)
@@ -619,45 +608,35 @@ mem_disable (int num)
 static void
 mem_disable_command (char *args, int from_tty)
 {
-  char *p = args;
-  char *p1;
-  int num;
-  struct mem_region *m;
-  int ix;
-
   require_user_regions (from_tty);
 
-  dcache_invalidate (target_dcache);
+  target_dcache_invalidate ();
 
-  if (p == 0)
+  if (args == NULL || *args == '\0')
     {
+      struct mem_region *m;
+      int ix;
+
       for (ix = 0; VEC_iterate (mem_region_s, mem_region_list, ix, m); ix++)
        m->enabled_p = 0;
     }
   else
-    while (*p)
-      {
-       p1 = p;
-       while (*p1 >= '0' && *p1 <= '9')
-         p1++;
-       if (*p1 && *p1 != ' ' && *p1 != '\t')
-         error (_("Arguments must be memory region numbers."));
-
-       num = atoi (p);
-       mem_disable (num);
-
-       p = p1;
-       while (*p == ' ' || *p == '\t')
-         p++;
-      }
+    {
+      number_or_range_parser parser (args);
+      while (!parser.finished ())
+       {
+         int num = parser.get_number ();
+         mem_disable (num);
+       }
+    }
 }
 
-/* Delete the memory region number NUM. */
+/* Delete the memory region number NUM.  */
 
 static void
 mem_delete (int num)
 {
-  struct mem_region *m1, *m;
+  struct mem_region *m;
   int ix;
 
   if (!mem_region_list)
@@ -682,36 +661,23 @@ mem_delete (int num)
 static void
 mem_delete_command (char *args, int from_tty)
 {
-  char *p = args;
-  char *p1;
-  int num;
-
   require_user_regions (from_tty);
 
-  dcache_invalidate (target_dcache);
+  target_dcache_invalidate ();
 
-  if (p == 0)
+  if (args == NULL || *args == '\0')
     {
-      if (query ("Delete all memory regions? "))
+      if (query (_("Delete all memory regions? ")))
        mem_clear ();
       dont_repeat ();
       return;
     }
 
-  while (*p)
+  number_or_range_parser parser (args);
+  while (!parser.finished ())
     {
-      p1 = p;
-      while (*p1 >= '0' && *p1 <= '9')
-       p1++;
-      if (*p1 && *p1 != ' ' && *p1 != '\t')
-       error (_("Arguments must be memory region numbers."));
-
-      num = atoi (p);
+      int num = parser.get_number ();
       mem_delete (num);
-
-      p = p1;
-      while (*p == ' ' || *p == '\t')
-       p++;
     }
 
   dont_repeat ();
@@ -734,27 +700,27 @@ _initialize_mem (void)
 Define attributes for memory region or reset memory region handling to\n\
 target-based.\n\
 Usage: mem auto\n\
-       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\
+       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\
-Usage: enable mem <code number>\n\
+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\
 Arguments are the code numbers of the memory regions to disable.\n\
-Usage: disable mem <code number>\n\
+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\
 Arguments are the code numbers of the memory regions to delete.\n\
-Usage: delete mem <code number>\n\
+Usage: delete mem <code number>...\n\
 Do \"info mem\" to see current list of code numbers."), &deletelist);
 
   add_info ("mem", mem_info_command,
This page took 0.029814 seconds and 4 git commands to generate.