* dwarf2read.c (read_str_index): Delete arg cu. All callers updated.
[deliverable/binutils-gdb.git] / gdb / stap-probe.c
index 1d942550fb5efbbfde15238a68711e23c7e3bc9f..986debd58c9efe7cb958aa2d9ba2f6d38cbdfeff 100644 (file)
@@ -1,6 +1,6 @@
 /* SystemTap probe support for GDB.
 
-   Copyright (C) 2012-2013 Free Software Foundation, Inc.
+   Copyright (C) 2012-2014 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -99,10 +99,12 @@ struct stap_probe
   struct probe p;
 
   /* If the probe has a semaphore associated, then this is the value of
-     it.  */
+     it, relative to SECT_OFF_DATA.  */
   CORE_ADDR sem_addr;
 
+  /* One if the arguments have been parsed.  */
   unsigned int args_parsed : 1;
+
   union
     {
       const char *text;
@@ -370,15 +372,13 @@ stap_is_generic_prefix (struct gdbarch *gdbarch, const char *s,
     }
 
   for (p = prefixes; *p != NULL; ++p)
-    {
-      if (strncasecmp (s, *p, strlen (*p)) == 0)
-       {
-         if (r != NULL)
-           *r = *p;
+    if (strncasecmp (s, *p, strlen (*p)) == 0)
+      {
+       if (r != NULL)
+         *r = *p;
 
-         return 1;
-       }
-    }
+       return 1;
+      }
 
   return 0;
 }
@@ -556,15 +556,12 @@ stap_parse_register_operand (struct stap_parse_info *p)
   /* Simple flag to indicate whether we have seen a minus signal before
      certain number.  */
   int got_minus = 0;
-
   /* Flags to indicate whether this register access is being displaced and/or
      indirected.  */
   int disp_p = 0, indirect_p = 0;
   struct gdbarch *gdbarch = p->gdbarch;
-
   /* Needed to generate the register name as a part of an expression.  */
   struct stoken str;
-
   /* Variables used to extract the register name from the probe's
      argument.  */
   const char *start;
@@ -724,27 +721,23 @@ stap_parse_single_operand (struct stap_parse_info *p)
 
   /* We first try to parse this token as a "special token".  */
   if (gdbarch_stap_parse_special_token_p (gdbarch))
-    {
-      int ret = gdbarch_stap_parse_special_token (gdbarch, p);
-
-      if (ret)
-       {
-         /* If the return value of the above function is not zero,
-            it means it successfully parsed the special token.
+    if (gdbarch_stap_parse_special_token (gdbarch, p) != 0)
+      {
+       /* If the return value of the above function is not zero,
+          it means it successfully parsed the special token.
 
-            If it is NULL, we try to parse it using our method.  */
-         return;
-       }
-    }
+          If it is NULL, we try to parse it using our method.  */
+       return;
+      }
 
   if (*p->arg == '-' || *p->arg == '~' || *p->arg == '+')
     {
       char c = *p->arg;
       int number;
-
       /* We use this variable to do a lookahead.  */
       const char *tmp = p->arg;
 
+      /* Skipping signal.  */
       ++tmp;
 
       /* This is an unary operation.  Here is a list of allowed tokens
@@ -872,6 +865,8 @@ stap_parse_single_operand (struct stap_parse_info *p)
 static void
 stap_parse_argument_conditionally (struct stap_parse_info *p)
 {
+  gdb_assert (gdbarch_stap_is_single_operand_p (p->gdbarch));
+
   if (*p->arg == '-' || *p->arg == '~' || *p->arg == '+' /* Unary.  */
       || isdigit (*p->arg)
       || gdbarch_stap_is_single_operand (p->gdbarch, p->arg))
@@ -913,6 +908,8 @@ stap_parse_argument_1 (struct stap_parse_info *p, int has_lhs,
      parse them depending on the precedence of the operators
      we find.  */
 
+  gdb_assert (p->arg != NULL);
+
   if (p->inside_paren_p)
     p->arg = skip_spaces_const (p->arg);
 
@@ -931,7 +928,7 @@ stap_parse_argument_1 (struct stap_parse_info *p, int has_lhs,
      This loop shall continue until we run out of characters in the input,
      or until we find a close-parenthesis, which means that we've reached
      the end of a sub-expression.  */
-  while (p->arg && *p->arg && *p->arg != ')' && !isspace (*p->arg))
+  while (*p->arg != '\0' && *p->arg != ')' && !isspace (*p->arg))
     {
       const char *tmp_exp_buf;
       enum exp_opcode opcode;
@@ -967,7 +964,7 @@ stap_parse_argument_1 (struct stap_parse_info *p, int has_lhs,
 
       /* While we still have operators, try to parse another
         right-side, but using the current right-side as a left-side.  */
-      while (*p->arg && stap_is_operator (p->arg))
+      while (*p->arg != '\0' && stap_is_operator (p->arg))
        {
          enum exp_opcode lookahead_opcode;
          enum stap_operand_prec lookahead_prec;
@@ -1080,10 +1077,10 @@ stap_parse_probe_arguments (struct stap_probe *probe, struct gdbarch *gdbarch)
   probe->args_parsed = 1;
   probe->args_u.vec = NULL;
 
-  if (!cur || !*cur || *cur == ':')
+  if (cur == NULL || *cur == '\0' || *cur == ':')
     return;
 
-  while (*cur)
+  while (*cur != '\0')
     {
       struct stap_probe_arg arg;
       enum stap_arg_bitness b;
@@ -1099,7 +1096,7 @@ stap_parse_probe_arguments (struct stap_probe *probe, struct gdbarch *gdbarch)
         Where `N' can be [+,-][4,8].  This is not mandatory, so
         we check it here.  If we don't find it, go to the next
         state.  */
-      if ((*cur == '-' && cur[1] && cur[2] != '@')
+      if ((*cur == '-' && cur[1] != '\0' && cur[2] != '@')
          && cur[1] != '@')
        arg.bitness = STAP_ARG_BITNESS_UNDEFINED;
       else
@@ -1154,6 +1151,15 @@ stap_parse_probe_arguments (struct stap_probe *probe, struct gdbarch *gdbarch)
     }
 }
 
+/* Implementation of the get_probe_address method.  */
+
+static CORE_ADDR
+stap_get_probe_address (struct probe *probe, struct objfile *objfile)
+{
+  return probe->address + ANOFFSET (objfile->section_offsets,
+                                   SECT_OFF_DATA (objfile));
+}
+
 /* Given PROBE, returns the number of arguments present in that probe's
    argument string.  */
 
@@ -1244,7 +1250,7 @@ static int
 stap_can_evaluate_probe_arguments (struct probe *probe_generic)
 {
   struct stap_probe *stap_probe = (struct stap_probe *) probe_generic;
-  struct gdbarch *gdbarch = get_objfile_arch (stap_probe->p.objfile);
+  struct gdbarch *gdbarch = stap_probe->p.arch;
 
   /* For SystemTap probes, we have to guarantee that the method
      stap_is_single_operand is defined on gdbarch.  If it is not, then it
@@ -1293,7 +1299,7 @@ stap_compile_to_ax (struct probe *probe_generic, struct agent_expr *expr,
 }
 
 /* Destroy (free) the data related to PROBE.  PROBE memory itself is not feed
-   as it is allocated from OBJFILE_OBSTACK.  */
+   as it is allocated on an obstack.  */
 
 static void
 stap_probe_destroy (struct probe *probe_generic)
@@ -1326,7 +1332,7 @@ compute_probe_arg (struct gdbarch *arch, struct internalvar *ivar,
   struct frame_info *frame = get_selected_frame (_("No frame selected"));
   CORE_ADDR pc = get_frame_pc (frame);
   int sel = (int) (uintptr_t) data;
-  struct probe *pc_probe;
+  struct bound_probe pc_probe;
   const struct sym_probe_fns *pc_probe_fns;
   unsigned n_args;
 
@@ -1334,10 +1340,10 @@ compute_probe_arg (struct gdbarch *arch, struct internalvar *ivar,
   gdb_assert (sel >= -1);
 
   pc_probe = find_probe_by_pc (pc);
-  if (pc_probe == NULL)
+  if (pc_probe.probe == NULL)
     error (_("No SystemTap probe at PC %s"), core_addr_to_string (pc));
 
-  n_args = get_probe_argument_count (pc_probe, frame);
+  n_args = get_probe_argument_count (pc_probe.probe, frame);
   if (sel == -1)
     return value_from_longest (builtin_type (arch)->builtin_int, n_args);
 
@@ -1345,7 +1351,7 @@ compute_probe_arg (struct gdbarch *arch, struct internalvar *ivar,
     error (_("Invalid probe argument %d -- probe has %u arguments available"),
           sel, n_args);
 
-  return evaluate_probe_argument (pc_probe, sel, frame);
+  return evaluate_probe_argument (pc_probe.probe, sel, frame);
 }
 
 /* This is called to compile one of the $_probe_arg* convenience
@@ -1357,7 +1363,7 @@ compile_probe_arg (struct internalvar *ivar, struct agent_expr *expr,
 {
   CORE_ADDR pc = expr->scope;
   int sel = (int) (uintptr_t) data;
-  struct probe *pc_probe;
+  struct bound_probe pc_probe;
   const struct sym_probe_fns *pc_probe_fns;
   int n_args;
   struct frame_info *frame = get_selected_frame (NULL);
@@ -1366,10 +1372,10 @@ compile_probe_arg (struct internalvar *ivar, struct agent_expr *expr,
   gdb_assert (sel >= -1);
 
   pc_probe = find_probe_by_pc (pc);
-  if (pc_probe == NULL)
+  if (pc_probe.probe == NULL)
     error (_("No SystemTap probe at PC %s"), core_addr_to_string (pc));
 
-  n_args = get_probe_argument_count (pc_probe, frame);
+  n_args = get_probe_argument_count (pc_probe.probe, frame);
 
   if (sel == -1)
     {
@@ -1384,7 +1390,7 @@ compile_probe_arg (struct internalvar *ivar, struct agent_expr *expr,
     error (_("Invalid probe argument %d -- probe has %d arguments available"),
           sel, n_args);
 
-  pc_probe->pops->compile_to_ax (pc_probe, expr, value, sel);
+  pc_probe.probe->pops->compile_to_ax (pc_probe.probe, expr, value, sel);
 }
 
 \f
@@ -1436,25 +1442,33 @@ stap_modify_semaphore (CORE_ADDR address, int set, struct gdbarch *gdbarch)
    the probes, but that is too rare to care.  */
 
 static void
-stap_set_semaphore (struct probe *probe_generic, struct gdbarch *gdbarch)
+stap_set_semaphore (struct probe *probe_generic, struct objfile *objfile,
+                   struct gdbarch *gdbarch)
 {
   struct stap_probe *probe = (struct stap_probe *) probe_generic;
+  CORE_ADDR addr;
 
   gdb_assert (probe_generic->pops == &stap_probe_ops);
 
-  stap_modify_semaphore (probe->sem_addr, 1, gdbarch);
+  addr = (probe->sem_addr
+         + ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile)));
+  stap_modify_semaphore (addr, 1, gdbarch);
 }
 
 /* Clear a SystemTap semaphore.  SEM is the semaphore's address.  */
 
 static void
-stap_clear_semaphore (struct probe *probe_generic, struct gdbarch *gdbarch)
+stap_clear_semaphore (struct probe *probe_generic, struct objfile *objfile,
+                     struct gdbarch *gdbarch)
 {
   struct stap_probe *probe = (struct stap_probe *) probe_generic;
+  CORE_ADDR addr;
 
   gdb_assert (probe_generic->pops == &stap_probe_ops);
 
-  stap_modify_semaphore (probe->sem_addr, 0, gdbarch);
+  addr = (probe->sem_addr
+         + ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile)));
+  stap_modify_semaphore (addr, 0, gdbarch);
 }
 
 /* Implementation of `$_probe_arg*' set of variables.  */
@@ -1492,16 +1506,16 @@ handle_stap_probe (struct objfile *objfile, struct sdt_note *el,
   const char *probe_args = NULL;
   struct stap_probe *ret;
 
-  ret = obstack_alloc (&objfile->objfile_obstack, sizeof (*ret));
+  ret = obstack_alloc (&objfile->per_bfd->storage_obstack, sizeof (*ret));
   ret->p.pops = &stap_probe_ops;
-  ret->p.objfile = objfile;
+  ret->p.arch = gdbarch;
 
   /* Provider and the name of the probe.  */
   ret->p.provider = (char *) &el->data[3 * size];
   ret->p.name = memchr (ret->p.provider, '\0',
                        (char *) el->data + el->size - ret->p.provider);
   /* Making sure there is a name.  */
-  if (!ret->p.name)
+  if (ret->p.name == NULL)
     {
       complaint (&symfile_complaints, _("corrupt probe name when "
                                        "reading `%s'"),
@@ -1523,13 +1537,9 @@ handle_stap_probe (struct objfile *objfile, struct sdt_note *el,
   /* Semaphore address.  */
   ret->sem_addr = extract_typed_address (&el->data[2 * size], ptr_type);
 
-  ret->p.address += (ANOFFSET (objfile->section_offsets,
-                              SECT_OFF_TEXT (objfile))
-                    + base - base_ref);
-  if (ret->sem_addr)
-    ret->sem_addr += (ANOFFSET (objfile->section_offsets,
-                               SECT_OFF_DATA (objfile))
-                     + base - base_ref);
+  ret->p.address += base - base_ref;
+  if (ret->sem_addr != 0)
+    ret->sem_addr += base - base_ref;
 
   /* Arguments.  We can only extract the argument format if there is a valid
      name for this probe.  */
@@ -1539,9 +1549,9 @@ handle_stap_probe (struct objfile *objfile, struct sdt_note *el,
   if (probe_args != NULL)
     ++probe_args;
 
-  if (probe_args == NULL || (memchr (probe_args, '\0',
-                                    (char *) el->data + el->size - ret->p.name)
-                            != el->data + el->size - 1))
+  if (probe_args == NULL
+      || (memchr (probe_args, '\0', (char *) el->data + el->size - ret->p.name)
+         != el->data + el->size - 1))
     {
       complaint (&symfile_complaints, _("corrupt probe argument when "
                                        "reading `%s'"),
@@ -1582,7 +1592,7 @@ get_stap_base_address (bfd *obfd, bfd_vma *base)
 
   bfd_map_over_sections (obfd, get_stap_base_address_1, (void *) &ret);
 
-  if (!ret)
+  if (ret == NULL)
     {
       complaint (&symfile_complaints, _("could not obtain base address for "
                                        "SystemTap section on objfile `%s'."),
@@ -1590,7 +1600,7 @@ get_stap_base_address (bfd *obfd, bfd_vma *base)
       return 0;
     }
 
-  if (base)
+  if (base != NULL)
     *base = ret->vma;
 
   return 1;
@@ -1617,7 +1627,7 @@ stap_get_probes (VEC (probe_p) **probesp, struct objfile *objfile)
       return;
     }
 
-  if (!elf_tdata (obfd)->sdt_note_head)
+  if (elf_tdata (obfd)->sdt_note_head == NULL)
     {
       /* There isn't any probe here.  */
       return;
@@ -1631,7 +1641,9 @@ stap_get_probes (VEC (probe_p) **probesp, struct objfile *objfile)
     }
 
   /* Parsing each probe's information.  */
-  for (iter = elf_tdata (obfd)->sdt_note_head; iter; iter = iter->next)
+  for (iter = elf_tdata (obfd)->sdt_note_head;
+       iter != NULL;
+       iter = iter->next)
     {
       /* We first have to handle all the information about the
         probe which is present in the section.  */
@@ -1648,18 +1660,6 @@ stap_get_probes (VEC (probe_p) **probesp, struct objfile *objfile)
     }
 }
 
-static void
-stap_relocate (struct probe *probe_generic, CORE_ADDR delta)
-{
-  struct stap_probe *probe = (struct stap_probe *) probe_generic;
-
-  gdb_assert (probe_generic->pops == &stap_probe_ops);
-
-  probe->p.address += delta;
-  if (probe->sem_addr)
-    probe->sem_addr += delta;
-}
-
 static int
 stap_probe_is_linespec (const char **linespecp)
 {
@@ -1689,9 +1689,9 @@ stap_gen_info_probes_table_values (struct probe *probe_generic,
 
   gdb_assert (probe_generic->pops == &stap_probe_ops);
 
-  gdbarch = get_objfile_arch (probe->p.objfile);
+  gdbarch = probe->p.arch;
 
-  if (probe->sem_addr)
+  if (probe->sem_addr != 0)
     val = print_core_address (gdbarch, probe->sem_addr);
 
   VEC_safe_push (const_char_ptr, *ret, val);
@@ -1703,7 +1703,7 @@ static const struct probe_ops stap_probe_ops =
 {
   stap_probe_is_linespec,
   stap_get_probes,
-  stap_relocate,
+  stap_get_probe_address,
   stap_get_probe_argument_count,
   stap_can_evaluate_probe_arguments,
   stap_evaluate_probe_argument,
This page took 0.029132 seconds and 4 git commands to generate.