public inbox for archer-commits@sourceware.org
help / color / mirror / Atom feed
* [SCM]  archer-sergiodj-stap: Error messages for register fetching.
@ 2011-03-15 19:46 sergiodj
  0 siblings, 0 replies; only message in thread
From: sergiodj @ 2011-03-15 19:46 UTC (permalink / raw)
  To: archer-commits

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 12433 bytes --]

The branch, archer-sergiodj-stap has been updated
       via  539bfe42f84f1fc3b568758505b012b3c0956083 (commit)
       via  1e15b5bd590e745d9698d7743a24a45cc2957788 (commit)
      from  72132021253495d6a38ae1f238809af344aaaa39 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit 539bfe42f84f1fc3b568758505b012b3c0956083
Author: Sergio Durigan Junior <sergiodj@redhat.com>
Date:   Tue Mar 15 16:45:42 2011 -0300

    Error messages for register fetching.

commit 1e15b5bd590e745d9698d7743a24a45cc2957788
Author: Sergio Durigan Junior <sergiodj@redhat.com>
Date:   Tue Mar 15 16:32:11 2011 -0300

    Cleanups, comments and error messages.
    
    I've made some cleanups on the code, wrote some comments and error
    messages.

-----------------------------------------------------------------------

Summary of changes:
 gdb/stap-probe.c |  469 ++++++++++++++----------------------------------------
 1 files changed, 118 insertions(+), 351 deletions(-)

First 500 lines of diff:
diff --git a/gdb/stap-probe.c b/gdb/stap-probe.c
index 12316a7..da06db9 100644
--- a/gdb/stap-probe.c
+++ b/gdb/stap-probe.c
@@ -50,9 +50,6 @@ struct stap_probe_arg
 
   /* The string representing this argument.  */
   char *arg_str;
-
-  /* The evaluated value of this argument.  */
-  struct value *val;
 };
 
 #define STAP_MAX_ARGS 10
@@ -290,7 +287,6 @@ stap_free_args_info (void *args_info_ptr)
   for (i = 0; i < STAP_MAX_ARGS; i++)
     {
       xfree (a->arg->arg_str);
-      xfree (a->arg->val);
     }
 
   xfree (a->arg);
@@ -445,287 +441,14 @@ stap_get_probe_argument_count (const struct stap_probe *probe)
   return probe->parsed_args->n_args;
 }
 
-#define REG_NAME_MAX_SIZE 20
-
-#if 0
-
-static struct value *
-stap_get_register_value (char **s)
-{
-}
-
-static struct value *
-stap_evaluate_unary_op (char **unary_ptr)
-{
-  struct value *tmp_res = NULL;
-  char *s = *unary_ptr;
-  char sign = *s;
-
-  gdb_assert (*s == '+' || *s == '-');
-  ++s;
-  ep_skip_leading_whitespace (&s);
-
-  if (isdigit (*s))
-    {
-      int number = (int) strtol (s, &s, 0);
-
-      tmp_res
-	= value_from_longest (builtin_type (gdbarch)->builtin_int,
-			      number);
-    }
-  else if (*s == '%')
-    tmp_res = stap_get_register_value (&s);
-
-  if (tmp_res && sign == '-')
-    tmp_res = value_neg (tmp_res);
-
-  ep_skip_leading_whitespace (&s);
-
-  *unary_ptr = s;
-
-  return tmp_res;
-}
-
-static enum exp_opcode
-stap_binary_expr_opcode (char **s)
-{
-  switch (**s)
-    {
-    case '+':
-      *s += 1;
-      return BINOP_ADD;
-
-    case '-':
-      *s += 1;
-      return BINOP_SUB;
-
-    case '*':
-      *s += 1;
-      return BINOP_MUL;
-
-    case '/':
-      *s += 1;
-      return BINOP_DIV;
-
-    case '%':
-      *s += 1;
-      return BINOP_REM;
-
-    case '&':
-      *s += 1;
-      if (**s == '&')
-	return BINOP_LOGICAL_AND;
-      return BINOP_BITWISE_AND;
-
-    case '|':
-      *s += 1;
-      if (**s == '|')
-	return BINOP_LOGICAL_OR;
-      return BINOP_BITWISE_IOR;
-
-    default:
-      /*ERROR*/
-      return 0;
-    }
-}
-
-static void
-stap_evaluate_probe_argument_1 (struct objfile *objfile,
-				const struct stap_probe *probe,
-				struct frame_info *frame,
-				int n)
-{
-  struct gdbarch *gdbarch = get_objfile_arch (objfile);
-  char *s = (char *) probe->parsed_args->arg[n].arg_str;
-  struct value *final_res = NULL;
-  enum
-    {
-      EVAL_INIT,
-      EVAL_INDIRECT_REG,
-      EVAL_REGISTER,
-      EVAL_PAREN,
-      EVAL_UNOP,
-      EVAL_BINOP,
-    } eval_arg_state;
-
-  eval_arg_state = EVAL_INIT;
-
-  probe->parsed_args->arg[n].val = NULL;
-
-  while (*s)
-    {
-      switch (eval_arg_state)
-	{
-	  /* Ideia: Fazer um parser que dê conta de exprs.
-
-	     Por ex: -2+(4-(23+3))
-
-	     a ideia eh pegar primeiro o -, ver que eh unario,
-	     criar um value pro -2, depois ver o + (sem consumir),
-	     chamar uma fcao pra avaliar a segunda parte do binario,
-	     depois chamar uma fcao pra avaliar
-	     parenteses, depois pegar o 4, ver que eh binario e salvar
-	     esse value, chamar fcao pra avaliar parent, ver que eh bin, avaliar
-	     e retornar o value, e ir retornando em cascata.  */
-
-	case EVAL_INIT:
-	  {
-	    switch (*s)
-	      {
-	      case '+': case '-':
-		eval_arg_state = EVAL_UNOP;
-		break;
-
-	      case '(':
-		if (s[1] == '%')
-		  eval_arg_state = EVAL_REGISTER;
-		else
-		  eval_arg_state = EVAL_PAREN;
-		break;
-
-	      case '0': case '1': case '2': case '3': case '4':
-	      case '5': case '6': case '7': case '8': case '9':
-		eval_arg_state = EVAL_BINOP;
-		break;
-	      }
-	  }
-	break;
-
-	case EVAL_UNOP:
-	  {
-	    final_res = stap_evaluate_unary_op (&s);
-
-	    if (!final_res)
-	      ; /* ERROR */
-
-	    if (stap_is_binary_op (*s))
-	      eval_arg_state = EVAL_BINOP;
-//	    else if (*s == '(')
-//	      eval_arg_state = EVAL_PAREN;
-	    else if (*s)
-	      ; /* ERROR */
-	  }
-	break;
-
-	case EVAL_BINOP:
-	  {
-	    struct value *tmp_res = NULL;
-	    enum exp_opcode opcode;
-
-	    gdb_assert (stap_is_binary_op (s));
-
-	    opcode = stap_binary_expr_opcode (&s);
-
-	    ++s;
-	    ep_skip_leading_whitespace (&s);
-
-	    switch (*s)
-	      {
-	      case '+': case '-':
-		{
-		  tmp_res = stap_evaluate_unary_op (&s);
-
-		  if (!tmp_res)
-		    ; /*ERROR*/
-		}
-	      break;
-
-	      case '(':
-		{
-		  tmp_res = stap_evaluate_paren (&s);
-
-		  if (!tmp_res)
-		    ; /*ERROR*/
-		}
-	      break;
-	      }
-
-	    final_res = value_binop (final_res, tmp_res, opcode);
-
-	    ep_skip_leading_whitespace (&s);
-	  }
-	break;
-#if 0
-	case '+': case '-':
-	  {
-	    /* This is the beginning of an unary operator.  */
-	    struct value *unary_res;
-	    char c = *s;
-
-	    ++s;
-	    ep_skip_leading_whitespace (&s);
-	    if (isdigit (*s))
-	      {
-		int number = (int) strtol (s, &s, 0);
-		struct value *tmp_res;
-
-		if (c == '-')
-		  number *= -1;
-
-		tmp_res
-		  = value_from_longest (builtin_type (gdbarch)->builtin_int,
-					number);
-
-		ep_skip_leading_whitespace (&s);
+/* This is the saved expression that we are evaluating now.
+   It is used for printing clearer error messages.  */
 
-		if (*s == '(' && s[1] == '%')
-		  {
-		    struct value *regval;
+static const char *stap_saved_expression;
 
-		    ++s;
-		    regval = stap_get_register_value (&s);
-
-		    /* Now indirect the register's value.  */
-		  }
-	      }
-	    else if (*s == '(')
-	      {
-		char *start = s;
-
-		ep_skip_leading_whitespace (&s);
-
-		if (*s == '%')
-		  stap_get_register_value (s);
-	      }
-	  }
-	break;
-
-	case '(':
-	  {
-	    ++s;
-
-	    if (*s == '%')
-	      {
-		char regname[REG_NAME_MAX_SIZE + 1];
-		const char *start;
-		int len, regnum;
-
-		/* This is a register name.  */
-		++s;
-		start = s;
-		while (isalnum (*s))
-		  ++s;
-
-		if (*s != ')')
-		  return;
-
-		len = s - start;
-
-		if (len >= REG_NAME_MAX_SIZE)
-		  return;
-
-		strncpy (regname, start, len);
-		regname[len] = '\0';
-
-		regnum = user_reg_map_name_to_regnum (gdbarch, regname, len);
-	      }
-	  }
-	break;
-#endif
-	}
-    }
-}
-#endif
+/* Returns the operator precedence level of OP, or zero if the operator
+   code was not recognized.
+   The levels were taken from the gas manual.  */
 
 static int
 stap_get_operator_prec (enum exp_opcode op)
@@ -757,10 +480,15 @@ stap_get_operator_prec (enum exp_opcode op)
     }
 }
 
+/* Given S, this function reads the operator in it and fills the OP
+   pointer with its code.  Returns 1 on success, zero if the operator
+   was not recognized.  */
+
 static int
 stap_get_opcode (char **s, enum exp_opcode *op)
 {
   char c = **s;
+  int ret = 1;
 
   *s += 1;
 
@@ -777,8 +505,11 @@ stap_get_opcode (char **s, enum exp_opcode *op)
     case '%':
       {
 	if (isalpha (**s))
-	  /* Dealing with a register name.  */
-	  break;
+	  {
+	    /* Dealing with a register name.  */
+	    ret = 0;
+	    break;
+	  }
 
 	*op = BINOP_REM;
       }
@@ -853,7 +584,10 @@ stap_get_opcode (char **s, enum exp_opcode *op)
 
     case '=':
       if (**s != '=')
-	;/*ERROR*/
+	{
+	  ret = 0;
+	  break;
+	}
       *op = BINOP_EQUAL;
       break;
 
@@ -863,9 +597,11 @@ stap_get_opcode (char **s, enum exp_opcode *op)
       return 0;
     }
 
-  return 1;
+  return ret;
 }
 
+/* Returns 1 if *S is an operator, zero otherwise.  */
+
 static int
 stap_is_operator (char *s)
 {
@@ -885,6 +621,12 @@ stap_is_operator (char *s)
 	  || op == '|' || op == '&' || op == '%' || op == '=');
 }
 
+/* Given **P, this function fetches the value of the register whose
+   name starts in **P.  It also applies any register displacements
+   (e.g., `-4(%eax)'), and indirects the contents of the register
+   (e.g., `(%eax)').  It returns RET if the operation has succeeded,
+   or NULL otherwise.  */
+
 static struct value *
 stap_fetch_reg_value (char **p, struct gdbarch *gdbarch,
 		      enum stap_arg_bitness bitness,
@@ -893,6 +635,7 @@ stap_fetch_reg_value (char **p, struct gdbarch *gdbarch,
 {
   const char *start;
   char *s = *p;
+#define REG_NAME_MAX_SIZE 20
   char regname[REG_NAME_MAX_SIZE + 1];
   int len, regnum, indirect_p = 0;
   struct value *ret;
@@ -905,7 +648,8 @@ stap_fetch_reg_value (char **p, struct gdbarch *gdbarch,
       ++s;
       if (!*s || *s != '%'
 	  || (*s == '%' && !isalpha (s[1])))
-	return NULL; /* ERROR */
+	error (_("Invalid register name on expression `%s'."),
+	       stap_saved_expression);
       ++s;
       indirect_p = 1;
     }
@@ -913,14 +657,18 @@ stap_fetch_reg_value (char **p, struct gdbarch *gdbarch,
     {
       ++s;
       if (!*s || !isalpha (*s))
-	return NULL; /* ERROR */
+	error (_("Invalid register name on expression `%s'."),
+	       stap_saved_expression);
     }
   else
-    return NULL; /*ERRROR*/
+    error (_("Invalid register name on expression `%s'."),
+	   stap_saved_expression);
 
   if (displacement && !indirect_p)
     /* We cannot apply displacement to non-indirect register access.  */
-    return NULL; /*ERROR*/
+    error (_("Trying to apply displacement without indirecting register \
+on expression `%s'."),
+	   stap_saved_expression);
 
   start = s;
   while (isalnum (*s))
@@ -932,7 +680,7 @@ stap_fetch_reg_value (char **p, struct gdbarch *gdbarch,
     ++s;
 
   if (len >= REG_NAME_MAX_SIZE)
-    return NULL; /* ERROR */
+    return NULL;
 
   strncpy (regname, start, len);
   regname[len] = '\0';
@@ -990,7 +738,7 @@ stap_parse_single_operand (char **p, struct gdbarch *gdbarch,
 			   struct frame_info *frame)
 {
   char *s = *p;
-  struct value *res;
+  struct value *res = NULL;
 
   switch (*s)
     {
@@ -1032,13 +780,27 @@ stap_parse_single_operand (char **p, struct gdbarch *gdbarch,
       {
 	int number = strtol (s, &s, 0);
 
+	if (!*s || !(*s == '(' && s[1] == '%'))
+	  ; /* ERROR */
+
+	res = stap_fetch_reg_value (&s, gdbarch, bitness,
+				    frame, res);
+      }
+    break;
+
+    case '$':
+      {
+	int number;
+
+	++s;
+	ep_skip_leading_whitespace (&s);
+
+	number = strtol (s, &s, 0);
+
 	res = value_from_longest (builtin_type (gdbarch)->builtin_int,
 				  number);
 
 	ep_skip_leading_whitespace (&s);
-	if (*s && *s == '(' && s[1] == '%')
-	  res = stap_fetch_reg_value (&s, gdbarch, bitness,
-				      frame, res);
       }
     break;
 
@@ -1061,6 +823,46 @@ stap_evaluate_probe_argument_2 (char **expr,
 				struct frame_info *frame,
 				enum stap_arg_bitness bitness,
 				struct value *lhs,
+				int prec);
+
+static struct value *
+stap_evaluate_conditionally (char **expr, struct gdbarch *gdbarch,
+			     struct frame_info *frame,
+			     enum stap_arg_bitness bitness)
+{
+  char *s = *expr;
+  struct value *ret;
+
+  if (*s == '-' || *s == '~' /* Unary operators.  */
+      || *s == '$' /* Number (integer constant).  */
+      || (isdigit (*s) && s[1] == '(' && s[2] == '%') /* Displacement.  */
+      || (*s == '(' && s[1] == '%') /* Register indirection.  */
+      || (*s == '%' && isalpha (s[1]))) /* Register value.  */
+    ret = stap_parse_single_operand (&s, gdbarch, bitness, frame);
+  else if (*s == '(')
+    {
+      ++s;
+      ep_skip_leading_whitespace (&s);
+      ret = stap_evaluate_probe_argument_2 (&s, gdbarch, frame,
+					    bitness, NULL, 0);
+      if (*s != ')')


hooks/post-receive
--
Repository for Project Archer.


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2011-03-15 19:46 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-15 19:46 [SCM] archer-sergiodj-stap: Error messages for register fetching sergiodj

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).