]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - gdb/target-descriptions.c
gdb: remove gdbarch_info_init
[thirdparty/binutils-gdb.git] / gdb / target-descriptions.c
index 78dc89ac99fcb7eee35184748e0c35643a340795..f94ace756d4df234fe2faec56bcd44be9e17529a 100644 (file)
@@ -446,7 +446,7 @@ struct target_desc_info
   /* A flag indicating that a description has already been fetched
      from the target, so it should not be queried again.  */
 
-  bool fetched;
+  bool fetched = false;
 
   /* The description fetched from the target, or NULL if the target
      did not supply any description.  Only valid when
@@ -454,12 +454,14 @@ struct target_desc_info
      code should access this; normally, the description should be
      accessed through the gdbarch object.  */
 
-  const struct target_desc *tdesc;
+  const struct target_desc *tdesc = nullptr;
+
+  /* If not empty, the filename to read a target description from, as set by
+     "set tdesc filename ...".
 
-  /* The filename to read a target description from, as set by "set
-     tdesc filename ..."  */
+     If empty, there is not filename specified by the user.  */
 
-  char *filename;
+  std::string filename;
 };
 
 /* Get the inferior INF's target description info, allocating one on
@@ -469,7 +471,8 @@ static struct target_desc_info *
 get_tdesc_info (struct inferior *inf)
 {
   if (inf->tdesc_info == NULL)
-    inf->tdesc_info = XCNEW (struct target_desc_info);
+    inf->tdesc_info = new target_desc_info;
+
   return inf->tdesc_info;
 }
 
@@ -483,7 +486,7 @@ static struct gdbarch_data *tdesc_data;
 int
 target_desc_info_from_user_p (struct target_desc_info *info)
 {
-  return info != NULL && info->filename != NULL;
+  return info != nullptr && !info->filename.empty ();
 }
 
 /* See target-descriptions.h.  */
@@ -494,9 +497,7 @@ copy_inferior_target_desc_info (struct inferior *destinf, struct inferior *srcin
   struct target_desc_info *src = get_tdesc_info (srcinf);
   struct target_desc_info *dest = get_tdesc_info (destinf);
 
-  dest->fetched = src->fetched;
-  dest->tdesc = src->tdesc;
-  dest->filename = src->filename != NULL ? xstrdup (src->filename) : NULL;
+  *dest = *src;
 }
 
 /* See target-descriptions.h.  */
@@ -504,11 +505,7 @@ copy_inferior_target_desc_info (struct inferior *destinf, struct inferior *srcin
 void
 target_desc_info_free (struct target_desc_info *tdesc_info)
 {
-  if (tdesc_info != NULL)
-    {
-      xfree (tdesc_info->filename);
-      xfree (tdesc_info);
-    }
+  delete tdesc_info;
 }
 
 /* The string manipulated by the "set tdesc filename ..." command.  */
@@ -538,8 +535,8 @@ target_find_description (void)
   /* First try to fetch an XML description from the user-specified
      file.  */
   tdesc_info->tdesc = nullptr;
-  if (tdesc_info->filename != nullptr && *tdesc_info->filename != '\0')
-    tdesc_info->tdesc = file_read_description_xml (tdesc_info->filename);
+  if (!tdesc_info->filename.empty ())
+    tdesc_info->tdesc = file_read_description_xml (tdesc_info->filename.data ());
 
   /* Next try to read the description from the current target using
      target objects.  */
@@ -558,7 +555,6 @@ target_find_description (void)
     {
       struct gdbarch_info info;
 
-      gdbarch_info_init (&info);
       info.target_desc = tdesc_info->tdesc;
       if (!gdbarch_update_p (info))
        warning (_("Architecture rejected target-supplied description"));
@@ -595,7 +591,6 @@ target_clear_description (void)
   tdesc_info->tdesc = nullptr;
 
   gdbarch_info info;
-  gdbarch_info_init (&info);
   if (!gdbarch_update_p (info))
     internal_error (__FILE__, __LINE__,
                    _("Could not remove target-supplied description"));
@@ -1294,8 +1289,7 @@ set_tdesc_filename_cmd (const char *args, int from_tty,
 {
   target_desc_info *tdesc_info = get_tdesc_info (current_inferior ());
 
-  xfree (tdesc_info->filename);
-  tdesc_info->filename = xstrdup (tdesc_filename_cmd_string);
+  tdesc_info->filename = tdesc_filename_cmd_string;
 
   target_clear_description ();
   target_find_description ();
@@ -1306,7 +1300,7 @@ show_tdesc_filename_cmd (struct ui_file *file, int from_tty,
                         struct cmd_list_element *c,
                         const char *value)
 {
-  value = get_tdesc_info (current_inferior ())->filename;
+  value = get_tdesc_info (current_inferior ())->filename.data ();
 
   if (value != NULL && *value != '\0')
     printf_filtered (_("The target description will be read from \"%s\".\n"),
@@ -1321,8 +1315,7 @@ unset_tdesc_filename_cmd (const char *args, int from_tty)
 {
   target_desc_info *tdesc_info = get_tdesc_info (current_inferior ());
 
-  xfree (tdesc_info->filename);
-  tdesc_info->filename = nullptr;
+  tdesc_info->filename.clear ();
   target_clear_description ();
   target_find_description ();
 }
@@ -1778,7 +1771,7 @@ maint_print_c_tdesc_cmd (const char *args, int from_tty)
         initialization code will reject the new description.  */
       target_desc_info *tdesc_info = get_tdesc_info (current_inferior ());
       tdesc = tdesc_info->tdesc;
-      filename = tdesc_info->filename;
+      filename = tdesc_info->filename.data ();
     }
   else
     {
@@ -1971,15 +1964,15 @@ _initialize_target_descriptions ()
 
   add_basic_prefix_cmd ("tdesc", class_maintenance, _("\
 Set target description specific variables."),
-                       &tdesc_set_cmdlist, "set tdesc ",
+                       &tdesc_set_cmdlist,
                        0 /* allow-unknown */, &setlist);
   add_show_prefix_cmd ("tdesc", class_maintenance, _("\
 Show target description specific variables."),
-                      &tdesc_show_cmdlist, "show tdesc ",
+                      &tdesc_show_cmdlist,
                       0 /* allow-unknown */, &showlist);
   add_basic_prefix_cmd ("tdesc", class_maintenance, _("\
 Unset target description specific variables."),
-                       &tdesc_unset_cmdlist, "unset tdesc ",
+                       &tdesc_unset_cmdlist,
                        0 /* allow-unknown */, &unsetlist);
 
   add_setshow_filename_cmd ("filename", class_obscure,