Remove cleanup from backtrace_command
[deliverable/binutils-gdb.git] / gdb / probe.c
index 36211eae41dfe63e593ed4d54d1f072463c7aa79..829f6d18d70d5dffff198b853e9a25e30a6cd478 100644 (file)
@@ -65,23 +65,23 @@ parse_probes_in_pspace (const struct probe_ops *probe_ops,
       const std::vector<probe *> &probes
        = objfile->sf->sym_probe_fns->sym_get_probes (objfile);
 
-      for (struct probe *probe : probes)
+      for (probe *p : probes)
        {
-         if (probe_ops != &probe_ops_any && probe->pops != probe_ops)
+         if (probe_ops != &probe_ops_any && p->pops != probe_ops)
            continue;
 
-         if (provider && strcmp (probe->provider, provider) != 0)
+         if (provider && strcmp (p->provider, provider) != 0)
            continue;
 
-         if (strcmp (probe->name, name) != 0)
+         if (strcmp (p->name, name) != 0)
            continue;
 
          symtab_and_line sal;
-         sal.pc = get_probe_address (probe, objfile);
+         sal.pc = get_probe_address (p, objfile);
          sal.explicit_pc = 1;
          sal.section = find_pc_overlay (sal.pc);
          sal.pspace = search_pspace;
-         sal.probe = probe;
+         sal.probe = p;
          sal.objfile = objfile;
 
          result->push_back (std::move (sal));
@@ -98,7 +98,6 @@ parse_probes (const struct event_location *location,
 {
   char *arg_end, *arg;
   char *objfile_namestr = NULL, *provider = NULL, *name, *p;
-  struct cleanup *cleanup;
   const struct probe_ops *probe_ops;
   const char *arg_start, *cs;
 
@@ -118,8 +117,8 @@ parse_probes (const struct event_location *location,
   arg_end = skip_to_space (arg);
 
   /* We make a copy here so we can write over parts with impunity.  */
-  arg = savestring (arg, arg_end - arg);
-  cleanup = make_cleanup (xfree, arg);
+  std::string copy (arg, arg_end - arg);
+  arg = &copy[0];
 
   /* Extract each word from the argument, separated by ":"s.  */
   p = strchr (arg, ':');
@@ -183,42 +182,37 @@ parse_probes (const struct event_location *location,
 
   if (canonical)
     {
-      char *canon;
-
-      canon = savestring (arg_start, arg_end - arg_start);
-      make_cleanup (xfree, canon);
+      std::string canon (arg_start, arg_end - arg_start);
       canonical->special_display = 1;
       canonical->pre_expanded = 1;
-      canonical->location = new_probe_location (canon);
+      canonical->location = new_probe_location (canon.c_str ());
     }
 
-  do_cleanups (cleanup);
-
   return result;
 }
 
 /* See definition in probe.h.  */
 
-VEC (probe_p) *
+std::vector<probe *>
 find_probes_in_objfile (struct objfile *objfile, const char *provider,
                        const char *name)
 {
-  VEC (probe_p) *result = NULL;
+  std::vector<probe *> result;
 
   if (!objfile->sf || !objfile->sf->sym_probe_fns)
-    return NULL;
+    return result;
 
   const std::vector<probe *> &probes
     = objfile->sf->sym_probe_fns->sym_get_probes (objfile);
-  for (struct probe *probe : probes)
+  for (probe *p : probes)
     {
-      if (strcmp (probe->provider, provider) != 0)
+      if (strcmp (p->provider, provider) != 0)
        continue;
 
-      if (strcmp (probe->name, name) != 0)
+      if (strcmp (p->name, name) != 0)
        continue;
 
-      VEC_safe_push (probe_p, result, probe);
+      result.push_back (p);
     }
 
   return result;
@@ -244,11 +238,11 @@ find_probe_by_pc (CORE_ADDR pc)
     /* If this proves too inefficient, we can replace with a hash.  */
     const std::vector<probe *> &probes
       = objfile->sf->sym_probe_fns->sym_get_probes (objfile);
-    for (struct probe *probe : probes)
-      if (get_probe_address (probe, objfile) == pc)
+    for (probe *p : probes)
+      if (get_probe_address (p, objfile) == pc)
        {
          result.objfile = objfile;
-         result.probe = probe;
+         result.probe = p;
          return result;
        }
   }
@@ -294,20 +288,20 @@ collect_probes (const std::string &objname, const std::string &provider,
       const std::vector<probe *> &probes
        = objfile->sf->sym_probe_fns->sym_get_probes (objfile);
 
-      for (struct probe *probe : probes)
+      for (probe *p : probes)
        {
-         if (pops != NULL && probe->pops != pops)
+         if (pops != NULL && p->pops != pops)
            continue;
 
          if (prov_pat
-             && prov_pat->exec (probe->provider, 0, NULL, 0) != 0)
+             && prov_pat->exec (p->provider, 0, NULL, 0) != 0)
            continue;
 
          if (probe_pat
-             && probe_pat->exec (probe->name, 0, NULL, 0) != 0)
+             && probe_pat->exec (p->name, 0, NULL, 0) != 0)
            continue;
 
-         result.emplace_back (probe, objfile);
+         result.emplace_back (p, objfile);
        }
     }
 
@@ -548,7 +542,6 @@ info_probes_for_ops (const char *arg, int from_tty,
                     const struct probe_ops *pops)
 {
   std::string provider, probe_name, objname;
-  struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
   int any_found;
   int ui_out_extra_fields = 0;
   size_t size_addr;
@@ -565,9 +558,6 @@ info_probes_for_ops (const char *arg, int from_tty,
 
   if (pops == NULL)
     {
-      const struct probe_ops *po;
-      int ix;
-
       /* If the probe_ops is NULL, it means the user has requested a "simple"
         `info probes', i.e., she wants to print all information about all
         probes.  For that, we have to identify how many extra fields we will
@@ -578,7 +568,7 @@ info_probes_for_ops (const char *arg, int from_tty,
         that number.  But note that we ignore the probe_ops for which no probes
         are defined with the given search criteria.  */
 
-      for (ix = 0; VEC_iterate (probe_ops_cp, all_probe_ops, ix, po); ++ix)
+      for (const probe_ops *po : all_probe_ops)
        if (exists_probe_with_pops (probes, po))
          ui_out_extra_fields += get_number_extra_fields (po);
     }
@@ -616,13 +606,10 @@ info_probes_for_ops (const char *arg, int from_tty,
 
     if (pops == NULL)
       {
-       const struct probe_ops *po;
-       int ix;
-
        /* We have to generate the table header for each new probe type
           that we will print.  Note that this excludes probe types not
           having any defined probe with the search criteria.  */
-       for (ix = 0; VEC_iterate (probe_ops_cp, all_probe_ops, ix, po); ++ix)
+       for (const probe_ops *po : all_probe_ops)
          if (exists_probe_with_pops (probes, po))
            gen_ui_out_table_header_info (probes, po);
       }
@@ -647,11 +634,7 @@ info_probes_for_ops (const char *arg, int from_tty,
 
        if (pops == NULL)
          {
-           const struct probe_ops *po;
-           int ix;
-
-           for (ix = 0; VEC_iterate (probe_ops_cp, all_probe_ops, ix, po);
-                ++ix)
+           for (const probe_ops *po : all_probe_ops)
              if (probe.probe->pops == po)
                print_ui_out_info (probe.probe);
              else if (exists_probe_with_pops (probes, po))
@@ -667,7 +650,6 @@ info_probes_for_ops (const char *arg, int from_tty,
 
     any_found = !probes.empty ();
   }
-  do_cleanups (cleanup);
 
   if (!any_found)
     current_uiout->message (_("No probes matched.\n"));
@@ -676,7 +658,7 @@ info_probes_for_ops (const char *arg, int from_tty,
 /* Implementation of the `info probes' command.  */
 
 static void
-info_probes_command (char *arg, int from_tty)
+info_probes_command (const char *arg, int from_tty)
 {
   info_probes_for_ops (arg, from_tty, NULL);
 }
@@ -684,10 +666,9 @@ info_probes_command (char *arg, int from_tty)
 /* Implementation of the `enable probes' command.  */
 
 static void
-enable_probes_command (char *arg, int from_tty)
+enable_probes_command (const char *arg, int from_tty)
 {
   std::string provider, probe_name, objname;
-  struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
 
   parse_probe_linespec ((const char *) arg, &provider, &probe_name, &objname);
 
@@ -696,7 +677,6 @@ enable_probes_command (char *arg, int from_tty)
   if (probes.empty ())
     {
       current_uiout->message (_("No probes matched.\n"));
-      do_cleanups (cleanup);
       return;
     }
 
@@ -716,17 +696,14 @@ enable_probes_command (char *arg, int from_tty)
        current_uiout->message (_("Probe %s:%s cannot be enabled.\n"),
                                probe.probe->provider, probe.probe->name);
     }
-
-  do_cleanups (cleanup);
 }
 
 /* Implementation of the `disable probes' command.  */
 
 static void
-disable_probes_command (char *arg, int from_tty)
+disable_probes_command (const char *arg, int from_tty)
 {
   std::string provider, probe_name, objname;
-  struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
 
   parse_probe_linespec ((const char *) arg, &provider, &probe_name, &objname);
 
@@ -735,7 +712,6 @@ disable_probes_command (char *arg, int from_tty)
   if (probes.empty ())
     {
       current_uiout->message (_("No probes matched.\n"));
-      do_cleanups (cleanup);
       return;
     }
 
@@ -755,8 +731,6 @@ disable_probes_command (char *arg, int from_tty)
        current_uiout->message (_("Probe %s:%s cannot be disabled.\n"),
                                probe.probe->provider, probe.probe->name);
     }
-
-  do_cleanups (cleanup);
 }
 
 /* See comments in probe.h.  */
@@ -816,12 +790,9 @@ probe_safe_evaluate_at_pc (struct frame_info *frame, unsigned n)
 const struct probe_ops *
 probe_linespec_to_ops (const char **linespecp)
 {
-  int ix;
-  const struct probe_ops *probe_ops;
-
-  for (ix = 0; VEC_iterate (probe_ops_cp, all_probe_ops, ix, probe_ops); ix++)
-    if (probe_ops->is_linespec (linespecp))
-      return probe_ops;
+  for (const probe_ops *ops : all_probe_ops)
+    if (ops->is_linespec (linespecp))
+      return ops;
 
   return NULL;
 }
@@ -980,12 +951,12 @@ static const struct internalvar_funcs probe_funcs =
 };
 
 
-VEC (probe_ops_cp) *all_probe_ops;
+std::vector<const probe_ops *> all_probe_ops;
 
 void
 _initialize_probe (void)
 {
-  VEC_safe_push (probe_ops_cp, all_probe_ops, &probe_ops_any);
+  all_probe_ops.push_back (&probe_ops_any);
 
   create_internalvar_type_lazy ("_probe_argc", &probe_funcs,
                                (void *) (uintptr_t) -1);
This page took 0.033608 seconds and 4 git commands to generate.