Make collect_probes return an std::vector
[deliverable/binutils-gdb.git] / gdb / dtrace-probe.c
index ff7ce7d868f6259e0776f7f0b3decc8cf8a9fada..f9209ece1a571ab7e761122ffea9fad0d902af47 100644 (file)
@@ -1,6 +1,6 @@
 /* DTrace probe support for GDB.
 
-   Copyright (C) 2014-2015 Free Software Foundation, Inc.
+   Copyright (C) 2014-2017 Free Software Foundation, Inc.
 
    Contributed by Oracle, Inc.
 
@@ -313,7 +313,8 @@ struct dtrace_dof_probe
 
 static void
 dtrace_process_dof_probe (struct objfile *objfile,
-                         struct gdbarch *gdbarch, VEC (probe_p) **probesp,
+                         struct gdbarch *gdbarch,
+                         std::vector<probe *> *probesp,
                          struct dtrace_dof_hdr *dof,
                          struct dtrace_dof_probe *probe,
                          struct dtrace_dof_provider *provider,
@@ -386,8 +387,8 @@ dtrace_process_dof_probe (struct objfile *objfile,
     {
       uint32_t probe_offset
        = ((uint32_t *) offtab)[DOF_UINT (dof, probe->dofpr_offidx) + i];
-      struct dtrace_probe *ret
-       = obstack_alloc (&objfile->per_bfd->storage_obstack, sizeof (*ret));
+      struct dtrace_probe *ret =
+       XOBNEW (&objfile->per_bfd->storage_obstack, struct dtrace_probe);
 
       ret->p.pops = &dtrace_probe_ops;
       ret->p.arch = gdbarch;
@@ -413,7 +414,7 @@ dtrace_process_dof_probe (struct objfile *objfile,
       for (j = 0; j < ret->probe_argc; j++)
        {
          struct dtrace_probe_arg arg;
-         struct expression *expr;
+         expression_up expr;
 
          /* Set arg.expr to ensure all fields in expr are initialized and
             the compiler will not warn when arg is used.  */
@@ -421,7 +422,8 @@ dtrace_process_dof_probe (struct objfile *objfile,
          arg.type_str = xstrdup (p);
 
          /* Use strtab_size as a sentinel.  */
-         while (*p++ != '\0' && p - strtab < strtab_size);
+         while (*p++ != '\0' && p - strtab < strtab_size)
+           ;
 
          /* Try to parse a type expression from the type string.  If
             this does not work then we set the type to `long
@@ -434,7 +436,6 @@ dtrace_process_dof_probe (struct objfile *objfile,
            }
          CATCH (ex, RETURN_MASK_ERROR)
            {
-             expr = NULL;
            }
          END_CATCH
 
@@ -448,7 +449,7 @@ dtrace_process_dof_probe (struct objfile *objfile,
       ret->enablers = VEC_copy (dtrace_probe_enabler_s, enablers);
 
       /* Successfully created probe.  */
-      VEC_safe_push (probe_p, *probesp, (struct probe *) ret);
+      probesp->push_back ((struct probe *) ret);
     }
 
   do_cleanups (cleanup);
@@ -461,10 +462,8 @@ dtrace_process_dof_probe (struct objfile *objfile,
 
 static void
 dtrace_process_dof (asection *sect, struct objfile *objfile,
-                   VEC (probe_p) **probesp, struct dtrace_dof_hdr *dof)
+                   std::vector<probe *> *probesp, struct dtrace_dof_hdr *dof)
 {
-  bfd *abfd = objfile->obfd;
-  int size = bfd_get_arch_size (abfd) / 8;
   struct gdbarch *gdbarch = get_objfile_arch (objfile);
   struct dtrace_dof_sect *section;
   int i;
@@ -519,6 +518,14 @@ dtrace_process_dof (asection *sect, struct objfile *objfile,
        unsigned int entsize = DOF_UINT (dof, probes_s->dofs_entsize);
        int num_probes;
 
+       if (DOF_UINT (dof, section->dofs_size)
+           < sizeof (struct dtrace_dof_provider))
+         {
+           /* The section is smaller than expected, so do not use it.
+              This has been observed on x86-solaris 10.  */
+           goto invalid_dof_data;
+         }
+
        /* Very, unlikely, but could crash gdb if not handled
           properly.  */
        if (entsize == 0)
@@ -614,7 +621,7 @@ dtrace_get_arg (struct dtrace_probe *probe, unsigned n,
 /* Implementation of the get_probes method.  */
 
 static void
-dtrace_get_probes (VEC (probe_p) **probesp, struct objfile *objfile)
+dtrace_get_probes (std::vector<probe *> *probesp, struct objfile *objfile)
 {
   bfd *abfd = objfile->obfd;
   asection *sect = NULL;
@@ -902,8 +909,6 @@ info_probes_dtrace_command (char *arg, int from_tty)
   info_probes_for_ops (arg, from_tty, &dtrace_probe_ops);
 }
 
-void _initialize_dtrace_probe (void);
-
 void
 _initialize_dtrace_probe (void)
 {
This page took 0.027405 seconds and 4 git commands to generate.