]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - gdb/dtrace-probe.c
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / dtrace-probe.c
index f80db713813593a352e50d4199a150747f3c31a7..9805b8a8e781ba130a7366637009290ffd6857ac 100644 (file)
@@ -1,6 +1,6 @@
 /* DTrace probe support for GDB.
 
-   Copyright (C) 2014-2019 Free Software Foundation, Inc.
+   Copyright (C) 2014-2023 Free Software Foundation, Inc.
 
    Contributed by Oracle, Inc.
 
@@ -21,7 +21,6 @@
 
 #include "defs.h"
 #include "probe.h"
-#include "common/vec.h"
 #include "elf-bfd.h"
 #include "gdbtypes.h"
 #include "obstack.h"
@@ -33,6 +32,7 @@
 #include "language.h"
 #include "parser-defs.h"
 #include "inferior.h"
+#include "expop.h"
 
 /* The type of the ELF sections where we will find the DOF programs
    with information about probes.  */
@@ -81,7 +81,7 @@ public:
   bool is_linespec (const char **linespecp) const override;
 
   /* See probe.h.  */
-  void get_probes (std::vector<probe *> *probesp,
+  void get_probes (std::vector<std::unique_ptr<probe>> *probesp,
                   struct objfile *objfile) const override;
 
   /* See probe.h.  */
@@ -122,14 +122,14 @@ public:
   CORE_ADDR get_relocated_address (struct objfile *objfile) override;
 
   /* See probe.h.  */
-  unsigned get_argument_count (struct frame_info *frame) override;
+  unsigned get_argument_count (struct gdbarch *gdbarch) override;
 
   /* See probe.h.  */
   bool can_evaluate_arguments () const override;
 
   /* See probe.h.  */
   struct value *evaluate_argument (unsigned n,
-                                  struct frame_info *frame) override;
+                                  frame_info_ptr frame) override;
 
   /* See probe.h.  */
   void compile_to_ax (struct agent_expr *aexpr,
@@ -152,7 +152,7 @@ public:
   struct dtrace_probe_arg *get_arg_by_number (unsigned n,
                                              struct gdbarch *gdbarch);
 
-  /* Build the GDB internal expressiosn that, once evaluated, will
+  /* Build the GDB internal expression that, once evaluated, will
      calculate the values of the arguments of the probe.  */
   void build_arg_exprs (struct gdbarch *gdbarch);
 
@@ -380,7 +380,7 @@ struct dtrace_dof_probe
 static void
 dtrace_process_dof_probe (struct objfile *objfile,
                          struct gdbarch *gdbarch,
-                         std::vector<probe *> *probesp,
+                         std::vector<std::unique_ptr<probe>> *probesp,
                          struct dtrace_dof_hdr *dof,
                          struct dtrace_dof_probe *probe,
                          struct dtrace_dof_provider *provider,
@@ -463,8 +463,8 @@ dtrace_process_dof_probe (struct objfile *objfile,
       int probe_argc = DOF_UINT (dof, probe->dofpr_nargc);
 
       /* Store argument type descriptions.  A description of the type
-         of the argument is in the (J+1)th null-terminated string
-         starting at 'strtab' + 'probe->dofpr_nargv'.  */
+        of the argument is in the (J+1)th null-terminated string
+        starting at 'strtab' + 'probe->dofpr_nargv'.  */
       std::vector<struct dtrace_probe_arg> args;
       p = strtab + DOF_UINT (dof, probe->dofpr_nargv);
       for (j = 0; j < probe_argc; j++)
@@ -482,20 +482,19 @@ dtrace_process_dof_probe (struct objfile *objfile,
          /* Try to parse a type expression from the type string.  If
             this does not work then we set the type to `long
             int'.  */
-          struct type *type = builtin_type (gdbarch)->builtin_long;
+         struct type *type = builtin_type (gdbarch)->builtin_long;
 
-         TRY
+         try
            {
              expr = parse_expression_with_language (type_str.c_str (),
                                                     language_c);
            }
-         CATCH (ex, RETURN_MASK_ERROR)
+         catch (const gdb_exception_error &ex)
            {
            }
-         END_CATCH
 
-         if (expr != NULL && expr.get ()->elts[0].opcode == OP_TYPE)
-           type = expr.get ()->elts[1].type;
+         if (expr != NULL && expr->first_opcode () == OP_TYPE)
+           type = value_type (evaluate_type (expr.get ()));
 
          args.emplace_back (type, std::move (type_str), std::move (expr));
        }
@@ -508,7 +507,7 @@ dtrace_process_dof_probe (struct objfile *objfile,
                                            std::move (enablers_copy));
 
       /* Successfully created probe.  */
-      probesp->push_back (ret);
+      probesp->emplace_back (ret);
     }
 }
 
@@ -519,9 +518,10 @@ dtrace_process_dof_probe (struct objfile *objfile,
 
 static void
 dtrace_process_dof (asection *sect, struct objfile *objfile,
-                   std::vector<probe *> *probesp, struct dtrace_dof_hdr *dof)
+                   std::vector<std::unique_ptr<probe>> *probesp,
+                   struct dtrace_dof_hdr *dof)
 {
-  struct gdbarch *gdbarch = get_objfile_arch (objfile);
+  struct gdbarch *gdbarch = objfile->arch ();
   struct dtrace_dof_sect *section;
   int i;
 
@@ -624,27 +624,24 @@ dtrace_probe::build_arg_exprs (struct gdbarch *gdbarch)
      value of the argument when executed at the PC of the probe.  */
   for (dtrace_probe_arg &arg : m_args)
     {
-      /* Initialize the expression buffer in the parser state.  The
-        language does not matter, since we are using our own
-        parser.  */
-      parser_state pstate (current_language, gdbarch);
+      /* Initialize the expression builder.  The language does not
+        matter, since we are using our own parser.  */
+      expr_builder builder (current_language, gdbarch);
 
       /* The argument value, which is ABI dependent and casted to
         `long int'.  */
-      gdbarch_dtrace_parse_probe_argument (gdbarch, &pstate, argc);
+      expr::operation_up op = gdbarch_dtrace_parse_probe_argument (gdbarch,
+                                                                  argc);
 
       /* Casting to the expected type, but only if the type was
         recognized at probe load time.  Otherwise the argument will
         be evaluated as the long integer passed to the probe.  */
       if (arg.type != NULL)
-       {
-         write_exp_elt_opcode (&pstate, UNOP_CAST);
-         write_exp_elt_type (&pstate, arg.type);
-         write_exp_elt_opcode (&pstate, UNOP_CAST);
-       }
+       op = expr::make_operation<expr::unop_cast_operation> (std::move (op),
+                                                             arg.type);
 
-      arg.expr = pstate.release ();
-      prefixify_expression (arg.expr.get ());
+      builder.set_operation (std::move (op));
+      arg.expr = builder.release ();
       ++argc;
     }
 }
@@ -658,8 +655,7 @@ dtrace_probe::get_arg_by_number (unsigned n, struct gdbarch *gdbarch)
     this->build_arg_exprs (gdbarch);
 
   if (n > m_args.size ())
-    internal_error (__FILE__, __LINE__,
-                   _("Probe '%s' has %d arguments, but GDB is requesting\n"
+    internal_error (_("Probe '%s' has %d arguments, but GDB is requesting\n"
                      "argument %u.  This should not happen.  Please\n"
                      "report this bug."),
                    this->get_name ().c_str (),
@@ -687,14 +683,13 @@ dtrace_probe::is_enabled () const
 CORE_ADDR
 dtrace_probe::get_relocated_address (struct objfile *objfile)
 {
-  return this->get_address () + ANOFFSET (objfile->section_offsets,
-                                         SECT_OFF_DATA (objfile));
+  return this->get_address () + objfile->text_section_offset ();
 }
 
 /* Implementation of the get_argument_count method.  */
 
 unsigned
-dtrace_probe::get_argument_count (struct frame_info *frame)
+dtrace_probe::get_argument_count (struct gdbarch *gdbarch)
 {
   return m_args.size ();
 }
@@ -713,15 +708,13 @@ dtrace_probe::can_evaluate_arguments () const
 
 struct value *
 dtrace_probe::evaluate_argument (unsigned n,
-                                struct frame_info *frame)
+                                frame_info_ptr frame)
 {
   struct gdbarch *gdbarch = this->get_gdbarch ();
   struct dtrace_probe_arg *arg;
-  int pos = 0;
 
   arg = this->get_arg_by_number (n, gdbarch);
-  return evaluate_subexp_standard (arg->type, arg->expr.get (), &pos,
-                                  EVAL_NORMAL);
+  return evaluate_expression (arg->expr.get (), arg->type);
 }
 
 /* Implementation of the compile_to_ax method.  */
@@ -731,12 +724,9 @@ dtrace_probe::compile_to_ax (struct agent_expr *expr, struct axs_value *value,
                             unsigned n)
 {
   struct dtrace_probe_arg *arg;
-  union exp_element *pc;
 
   arg = this->get_arg_by_number (n, expr->gdbarch);
-
-  pc = arg->expr->elts;
-  gen_expr (arg->expr.get (), &pc, expr, value);
+  arg->expr->op->generate_ax (arg->expr.get (), expr, value);
 
   require_rvalue (expr, value);
   value->type = arg->type;
@@ -835,10 +825,11 @@ dtrace_static_probe_ops::is_linespec (const char **linespecp) const
 /* Implementation of the get_probes method.  */
 
 void
-dtrace_static_probe_ops::get_probes (std::vector<probe *> *probesp,
-                                    struct objfile *objfile) const
+dtrace_static_probe_ops::get_probes
+  (std::vector<std::unique_ptr<probe>> *probesp,
+   struct objfile *objfile) const
 {
-  bfd *abfd = objfile->obfd;
+  bfd *abfd = objfile->obfd.get ();
   asection *sect = NULL;
 
   /* Do nothing in case this is a .debug file, instead of the objfile
@@ -856,13 +847,14 @@ dtrace_static_probe_ops::get_probes (std::vector<probe *> *probesp,
 
          /* Read the contents of the DOF section and then process it to
             extract the information of any probe defined into it.  */
-         if (!bfd_malloc_and_get_section (abfd, sect, &dof))
+         if (bfd_malloc_and_get_section (abfd, sect, &dof) && dof != NULL)
+           dtrace_process_dof (sect, objfile, probesp,
+                               (struct dtrace_dof_hdr *) dof);
+         else
            complaint (_("could not obtain the contents of"
                         "section '%s' in objfile `%s'."),
-                      sect->name, abfd->filename);
-      
-         dtrace_process_dof (sect, objfile, probesp,
-                             (struct dtrace_dof_hdr *) dof);
+                      bfd_section_name (sect), bfd_get_filename (abfd));
+
          xfree (dof);
        }
     }
@@ -897,8 +889,9 @@ info_probes_dtrace_command (const char *arg, int from_tty)
   info_probes_for_spops (arg, from_tty, &dtrace_static_probe_ops);
 }
 
+void _initialize_dtrace_probe ();
 void
-_initialize_dtrace_probe (void)
+_initialize_dtrace_probe ()
 {
   all_static_probe_ops.push_back (&dtrace_static_probe_ops);