ODR warning for "enum string_repr_result"
[binutils-gdb.git] / gdb / memattr.c
index 04986646db88b5a7325ab1292c9aae3e797138e2..fbcbe1ddd9f3ad50b7a11b19f4b2a5657f8b69a0 100644 (file)
@@ -1,6 +1,6 @@
 /* Memory attributes support, for GDB.
 
-   Copyright (C) 2001-2017 Free Software Foundation, Inc.
+   Copyright (C) 2001-2022 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
 #include "target-dcache.h"
 #include "value.h"
 #include "language.h"
-#include "vec.h"
 #include "breakpoint.h"
 #include "cli/cli-utils.h"
 #include <algorithm>
+#include "gdbarch.h"
 
 static std::vector<mem_region> user_mem_region_list, target_mem_region_list;
 static std::vector<mem_region> *mem_region_list = &target_mem_region_list;
@@ -52,7 +52,7 @@ static bool 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 = 1;
+static bool inaccessible_by_default = true;
 
 static void
 show_inaccessible_by_default (struct ui_file *file, int from_tty,
@@ -60,11 +60,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"));
+    gdb_printf (file, _("Unknown memory addresses will "
+                       "be treated as inaccessible.\n"));
   else
-    fprintf_filtered (file, _("Unknown memory addresses "
-                             "will be treated as RAM.\n"));          
+    gdb_printf (file, _("Unknown memory addresses "
+                       "will be treated as RAM.\n"));          
 }
 
 /* This function should be called before any command which would
@@ -74,9 +74,6 @@ show_inaccessible_by_default (struct ui_file *file, int from_tty,
 static void
 require_user_regions (int from_tty)
 {
-  struct mem_region *m;
-  int ix, length;
-
   /* If we're already using a user-provided list, nothing to do.  */
   if (!mem_use_target ())
     return;
@@ -124,7 +121,7 @@ create_user_mem_region (CORE_ADDR lo, CORE_ADDR hi,
   /* lo == hi is a useless empty region.  */
   if (lo >= hi && hi != 0)
     {
-      printf_unfiltered (_("invalid memory region: low >= high\n"));
+      gdb_printf (_("invalid memory region: low >= high\n"));
       return;
     }
 
@@ -136,7 +133,7 @@ create_user_mem_region (CORE_ADDR lo, CORE_ADDR hi,
   int ix = std::distance (user_mem_region_list.begin (), it);
 
   /* Check for an overlapping memory region.  We only need to check
-     in the vicinity - at most one before and one after the
+     in the vincinity - at most one before and one after the
      insertion point.  */
   for (int i = ix - 1; i < ix + 1; i++)
     {
@@ -151,7 +148,7 @@ create_user_mem_region (CORE_ADDR lo, CORE_ADDR hi,
          || (hi > n.lo && (hi <= n.hi || n.hi == 0))
          || (lo <= n.lo && ((hi >= n.hi && n.hi != 0) || hi == 0)))
        {
-         printf_unfiltered (_("overlapping memory region\n"));
+         gdb_printf (_("overlapping memory region\n"));
          return;
        }
     }
@@ -166,10 +163,8 @@ struct mem_region *
 lookup_mem_region (CORE_ADDR addr)
 {
   static struct mem_region region (0, 0);
-  struct mem_region *m;
   CORE_ADDR lo;
   CORE_ADDR hi;
-  int ix;
 
   require_target_regions ();
 
@@ -341,45 +336,45 @@ mem_command (const char *args, int from_tty)
 \f
 
 static void
-info_mem_command (char *args, int from_tty)
+info_mem_command (const char *args, int from_tty)
 {
   if (mem_use_target ())
-    printf_filtered (_("Using memory regions provided by the target.\n"));
+    gdb_printf (_("Using memory regions provided by the target.\n"));
   else
-    printf_filtered (_("Using user-defined memory regions.\n"));
+    gdb_printf (_("Using user-defined memory regions.\n"));
 
   require_target_regions ();
 
   if (mem_region_list->empty ())
     {
-      printf_unfiltered (_("There are no memory regions defined.\n"));
+      gdb_printf (_("There are no memory regions defined.\n"));
       return;
     }
 
-  printf_filtered ("Num ");
-  printf_filtered ("Enb ");
-  printf_filtered ("Low Addr   ");
+  gdb_printf ("Num ");
+  gdb_printf ("Enb ");
+  gdb_printf ("Low Addr   ");
   if (gdbarch_addr_bit (target_gdbarch ()) > 32)
-    printf_filtered ("        ");
-  printf_filtered ("High Addr  ");
+    gdb_printf ("        ");
+  gdb_printf ("High Addr  ");
   if (gdbarch_addr_bit (target_gdbarch ()) > 32)
-    printf_filtered ("        ");
-  printf_filtered ("Attrs ");
-  printf_filtered ("\n");
+    gdb_printf ("        ");
+  gdb_printf ("Attrs ");
+  gdb_printf ("\n");
 
   for (const mem_region &m : *mem_region_list)
     {
       const char *tmp;
 
-      printf_filtered ("%-3d %-3c\t",
-                      m.number,
-                      m.enabled_p ? 'y' : 'n');
+      gdb_printf ("%-3d %-3c\t",
+                 m.number,
+                 m.enabled_p ? 'y' : 'n');
       if (gdbarch_addr_bit (target_gdbarch ()) <= 32)
        tmp = hex_string_custom (m.lo, 8);
       else
        tmp = hex_string_custom (m.lo, 16);
       
-      printf_filtered ("%s ", tmp);
+      gdb_printf ("%s ", tmp);
 
       if (gdbarch_addr_bit (target_gdbarch ()) <= 32)
        {
@@ -396,7 +391,7 @@ info_mem_command (char *args, int from_tty)
            tmp = hex_string_custom (m.hi, 16);
        }
 
-      printf_filtered ("%s ", tmp);
+      gdb_printf ("%s ", tmp);
 
       /* Print a token for each attribute.
 
@@ -413,32 +408,32 @@ info_mem_command (char *args, int from_tty)
       switch (m.attrib.mode)
        {
        case MEM_RW:
-         printf_filtered ("rw ");
+         gdb_printf ("rw ");
          break;
        case MEM_RO:
-         printf_filtered ("ro ");
+         gdb_printf ("ro ");
          break;
        case MEM_WO:
-         printf_filtered ("wo ");
+         gdb_printf ("wo ");
          break;
        case MEM_FLASH:
-         printf_filtered ("flash blocksize 0x%x ", m.attrib.blocksize);
+         gdb_printf ("flash blocksize 0x%x ", m.attrib.blocksize);
          break;
        }
 
       switch (m.attrib.width)
        {
        case MEM_WIDTH_8:
-         printf_filtered ("8 ");
+         gdb_printf ("8 ");
          break;
        case MEM_WIDTH_16:
-         printf_filtered ("16 ");
+         gdb_printf ("16 ");
          break;
        case MEM_WIDTH_32:
-         printf_filtered ("32 ");
+         gdb_printf ("32 ");
          break;
        case MEM_WIDTH_64:
-         printf_filtered ("64 ");
+         gdb_printf ("64 ");
          break;
        case MEM_WIDTH_UNSPECIFIED:
          break;
@@ -446,26 +441,24 @@ info_mem_command (char *args, int from_tty)
 
 #if 0
       if (attrib->hwbreak)
-       printf_filtered ("hwbreak");
+       gdb_printf ("hwbreak");
       else
-       printf_filtered ("swbreak");
+       gdb_printf ("swbreak");
 #endif
 
       if (m.attrib.cache)
-       printf_filtered ("cache ");
+       gdb_printf ("cache ");
       else
-       printf_filtered ("nocache ");
+       gdb_printf ("nocache ");
 
 #if 0
       if (attrib->verify)
-       printf_filtered ("verify ");
+       gdb_printf ("verify ");
       else
-       printf_filtered ("noverify ");
+       gdb_printf ("noverify ");
 #endif
 
-      printf_filtered ("\n");
-
-      gdb_flush (gdb_stdout);
+      gdb_printf ("\n");
     }
 }
 \f
@@ -481,7 +474,7 @@ mem_enable (int num)
        m.enabled_p = 1;
        return;
       }
-  printf_unfiltered (_("No memory region number %d.\n"), num);
+  gdb_printf (_("No memory region number %d.\n"), num);
 }
 
 static void
@@ -519,7 +512,7 @@ mem_disable (int num)
        m.enabled_p = 0;
        return;
       }
-  printf_unfiltered (_("No memory region number %d.\n"), num);
+  gdb_printf (_("No memory region number %d.\n"), num);
 }
 
 static void
@@ -531,9 +524,6 @@ disable_mem_command (const char *args, int from_tty)
 
   if (args == NULL || *args == '\0')
     {
-      struct mem_region *m;
-      int ix;
-
       for (mem_region &m : *mem_region_list)
        m.enabled_p = false;
     }
@@ -553,12 +543,9 @@ disable_mem_command (const char *args, int from_tty)
 static void
 mem_delete (int num)
 {
-  struct mem_region *m;
-  int ix;
-
   if (!mem_region_list)
     {
-      printf_unfiltered (_("No memory region number %d.\n"), num);
+      gdb_printf (_("No memory region number %d.\n"), num);
       return;
     }
 
@@ -571,7 +558,7 @@ mem_delete (int num)
   if (it != mem_region_list->end ())
     mem_region_list->erase (it);
   else
-    printf_unfiltered (_("No memory region number %d.\n"), num);
+    gdb_printf (_("No memory region number %d.\n"), num);
 }
 
 static void
@@ -599,55 +586,48 @@ delete_mem_command (const char *args, int from_tty)
   dont_repeat ();
 }
 
-static void
-dummy_cmd (const char *args, int from_tty)
-{
-}
-
 static struct cmd_list_element *mem_set_cmdlist;
 static struct cmd_list_element *mem_show_cmdlist;
 
+void _initialize_mem ();
 void
-_initialize_mem (void)
+_initialize_mem ()
 {
   add_com ("mem", class_vars, mem_command, _("\
-Define attributes for memory region or reset memory region handling to\n\
-target-based.\n\
+Define attributes for memory region or reset memory region handling to "
+"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\
-      <cache> may be cache or nocache"));
+       mem LOW HIGH [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, enable_mem_command, _("\
 Enable memory region.\n\
-Arguments are the code numbers of the memory regions to enable.\n\
-Usage: enable mem <code number>...\n\
-Do \"info mem\" to see current list of code numbers."), &enablelist);
+Arguments are the IDs of the memory regions to enable.\n\
+Usage: enable mem [ID]...\n\
+Do \"info mem\" to see current list of IDs."), &enablelist);
 
   add_cmd ("mem", class_vars, disable_mem_command, _("\
 Disable memory region.\n\
-Arguments are the code numbers of the memory regions to disable.\n\
-Usage: disable mem <code number>...\n\
-Do \"info mem\" to see current list of code numbers."), &disablelist);
+Arguments are the IDs of the memory regions to disable.\n\
+Usage: disable mem [ID]...\n\
+Do \"info mem\" to see current list of IDs."), &disablelist);
 
   add_cmd ("mem", class_vars, delete_mem_command, _("\
 Delete memory region.\n\
-Arguments are the code numbers of the memory regions to delete.\n\
-Usage: delete mem <code number>...\n\
-Do \"info mem\" to see current list of code numbers."), &deletelist);
+Arguments are the IDs of the memory regions to delete.\n\
+Usage: delete mem [ID]...\n\
+Do \"info mem\" to see current list of IDs."), &deletelist);
 
   add_info ("mem", info_mem_command,
-           _("Memory region attributes"));
-
-  add_prefix_cmd ("mem", class_vars, dummy_cmd, _("\
-Memory regions settings"),
-                 &mem_set_cmdlist, "set mem ",
-                 0/* allow-unknown */, &setlist);
-  add_prefix_cmd ("mem", class_vars, dummy_cmd, _("\
-Memory regions settings"),
-                 &mem_show_cmdlist, "show mem  ",
-                 0/* allow-unknown */, &showlist);
+           _("Memory region attributes."));
+
+  add_setshow_prefix_cmd ("mem", class_vars,
+                         _("Memory regions settings."),
+                         _("Memory regions settings."),
+                         &mem_set_cmdlist, &mem_show_cmdlist,
+                         &setlist, &showlist);
 
   add_setshow_boolean_cmd ("inaccessible-by-default", no_class,
                                  &inaccessible_by_default, _("\