public inbox for archer-commits@sourceware.org
help / color / mirror / Atom feed
* [SCM] archer-sergiodj-stap: Creating `struct stap_evaluation_info'.
@ 2011-03-16 5:38 sergiodj
0 siblings, 0 replies; only message in thread
From: sergiodj @ 2011-03-16 5:38 UTC (permalink / raw)
To: archer-commits
The branch, archer-sergiodj-stap has been updated
via 7224aacc06255b8a8e0d9c7a109fdbed8b6e3921 (commit)
from 676af705f67ab48edaa22ae0d4542acec38d9860 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email.
- Log -----------------------------------------------------------------
commit 7224aacc06255b8a8e0d9c7a109fdbed8b6e3921
Author: Sergio Durigan Junior <sergiodj@redhat.com>
Date: Wed Mar 16 02:37:58 2011 -0300
Creating `struct stap_evaluation_info'.
This struct helps to minimize the number of arguments necessary to pass
to each evaluation function.
-----------------------------------------------------------------------
Summary of changes:
gdb/stap-probe.c | 219 ++++++++++++++++++++++++++++++------------------------
1 files changed, 123 insertions(+), 96 deletions(-)
First 500 lines of diff:
diff --git a/gdb/stap-probe.c b/gdb/stap-probe.c
index efa6018..c0eddc9 100644
--- a/gdb/stap-probe.c
+++ b/gdb/stap-probe.c
@@ -66,6 +66,30 @@ struct stap_args_info
struct stap_probe_arg *arg;
};
+/* Struct that contains all the necessary information to evaluate
+ an expression. */
+struct stap_evaluation_info
+{
+ /* The constant pointer which holds the expression. This is primarily
+ used for printing error messages. Evaluation functions should
+ not modify this pointer directly; instead, they should use the
+ EXP_BUFFER pointer below. */
+ const char *saved_expr;
+
+ /* Modifiable version of the above pointer. */
+ char *exp_buf;
+
+ /* The pointer to the current gdbarch. */
+ struct gdbarch *gdbarch;
+
+ /* The pointer to the current frame, used when accessing registers'
+ contents. */
+ struct frame_info *frame;
+
+ /* The bitness specified for this argument. */
+ enum stap_arg_bitness bitness;
+};
+
/* This dummy variable is used when parsing a probe's argument fails.
In this case, the number of arguments for this probe is zero, so that's
why this variable is useful. */
@@ -441,11 +465,6 @@ stap_get_probe_argument_count (const struct stap_probe *probe)
return probe->parsed_args->n_args;
}
-/* This is the saved expression that we are evaluating now.
- It is used for printing clearer error messages. */
-
-static const char *stap_saved_expression;
-
/* Returns the operator precedence level of OP, or zero if the operator
code was not recognized.
The levels were taken from the gas manual. */
@@ -628,13 +647,14 @@ stap_is_operator (char *s)
or NULL otherwise. */
static struct value *
-stap_fetch_reg_value (char **p, struct gdbarch *gdbarch,
- enum stap_arg_bitness bitness,
- struct frame_info *frame,
+stap_fetch_reg_value (struct stap_evaluation_info *eval_info,
struct value *displacement)
{
const char *start;
- char *s = *p;
+ char *s = eval_info->exp_buf;
+ struct gdbarch *gdbarch = eval_info->gdbarch;
+ struct frame_info *frame = eval_info->frame;
+ enum stap_arg_bitness bitness = eval_info->bitness;
#define REG_NAME_MAX_SIZE 20
char regname[REG_NAME_MAX_SIZE + 1];
int len, regnum, indirect_p = 0;
@@ -649,7 +669,7 @@ stap_fetch_reg_value (char **p, struct gdbarch *gdbarch,
if (!*s || *s != '%'
|| (*s == '%' && !isalpha (s[1])))
error (_("Invalid register name on expression `%s'."),
- stap_saved_expression);
+ eval_info->saved_expr);
++s;
indirect_p = 1;
}
@@ -658,17 +678,17 @@ stap_fetch_reg_value (char **p, struct gdbarch *gdbarch,
++s;
if (!*s || !isalpha (*s))
error (_("Invalid register name on expression `%s'."),
- stap_saved_expression);
+ eval_info->saved_expr);
}
else
error (_("Invalid register name on expression `%s'."),
- stap_saved_expression);
+ eval_info->saved_expr);
if (displacement && !indirect_p)
/* We cannot apply displacement to non-indirect register access. */
error (_("Trying to apply displacement without indirecting register \
on expression `%s'."),
- stap_saved_expression);
+ eval_info->saved_expr);
start = s;
while (isalnum (*s))
@@ -723,30 +743,33 @@ on expression `%s'."),
if (displacement)
ret = value_ptradd (ret, value_as_long (displacement));
+
ret = value_cast (t, ret);
ret = value_ind (ret);
}
- *p = s;
+ eval_info->exp_buf = s;
return ret;
}
static struct value *
-stap_parse_single_operand (char **p, struct gdbarch *gdbarch,
- enum stap_arg_bitness bitness,
- struct frame_info *frame)
+stap_parse_single_operand (struct stap_evaluation_info *eval_info)
{
- char *s = *p;
+ struct gdbarch *gdbarch = eval_info->gdbarch;
+ struct frame_info *frame = eval_info->frame;
+ enum stap_arg_bitness bitness = eval_info->bitness;
struct value *res = NULL;
- switch (*s)
+ switch (*eval_info->exp_buf)
{
case '-':
{
- ++s;
- ep_skip_leading_whitespace (&s);
- if (*s && *s == '(' && s[1] != '%')
+ ++eval_info->exp_buf;
+ ep_skip_leading_whitespace (&eval_info->exp_buf);
+ if (*eval_info->exp_buf
+ && *eval_info->exp_buf == '('
+ && eval_info->exp_buf[1] != '%')
/* We're not dealing with a register name, but with an expression
like:
@@ -755,41 +778,48 @@ stap_parse_single_operand (char **p, struct gdbarch *gdbarch,
-1);
else
{
- if (isdigit (*s))
+ if (isdigit (*eval_info->exp_buf))
{
- int number = strtol (s, &s, 0) * -1;
+ int number = strtol (eval_info->exp_buf,
+ &eval_info->exp_buf, 0) * -1;
- ep_skip_leading_whitespace (&s);
+ ep_skip_leading_whitespace (&eval_info->exp_buf);
res
= value_from_longest (builtin_type (gdbarch)->builtin_int,
number);
- if (!*s || stap_is_operator (s))
+ if (!*eval_info->exp_buf
+ || stap_is_operator (eval_info->exp_buf))
break;
- else if (*s == '(' && s[1] == '%')
- res = stap_fetch_reg_value (&s, gdbarch, bitness,
- frame, res);
+ else if (*eval_info->exp_buf == '('
+ && eval_info->exp_buf[1] == '%')
+ res = stap_fetch_reg_value (eval_info, res);
}
}
}
break;
+ case '~':
+ {
+ }
+ break;
+
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
{
- int number = strtol (s, &s, 0);
+ int number = strtol (eval_info->exp_buf, &eval_info->exp_buf, 0);
- if (!*s || !(*s == '(' && s[1] == '%'))
+ if (!*eval_info->exp_buf
+ || !(*eval_info->exp_buf == '('
+ && eval_info->exp_buf[1] == '%'))
error (_("Invalid register access on expression `%s'."),
- stap_saved_expression);
+ eval_info->saved_expr);
- res
- = value_from_longest (builtin_type (gdbarch)->builtin_int,
- number);
+ res = value_from_longest (builtin_type (gdbarch)->builtin_int,
+ number);
- res = stap_fetch_reg_value (&s, gdbarch, bitness,
- frame, res);
+ res = stap_fetch_reg_value (eval_info, res);
}
break;
@@ -797,45 +827,42 @@ stap_parse_single_operand (char **p, struct gdbarch *gdbarch,
{
int number;
- ++s;
- ep_skip_leading_whitespace (&s);
+ ++eval_info->exp_buf;
+ ep_skip_leading_whitespace (&eval_info->exp_buf);
- number = strtol (s, &s, 0);
+ number = strtol (eval_info->exp_buf, &eval_info->exp_buf, 0);
res = value_from_longest (builtin_type (gdbarch)->builtin_int,
number);
- ep_skip_leading_whitespace (&s);
+ ep_skip_leading_whitespace (&eval_info->exp_buf);
}
break;
case '(': case '%':
{
- res = stap_fetch_reg_value (&s, gdbarch, bitness,
- frame, /*displacement=*/NULL);
+ res = stap_fetch_reg_value (eval_info, /*displacement=*/NULL);
}
break;
- }
- *p = s;
+ default:
+ {
+ error (_("Operator `%c' not recognized on expression `%s'."),
+ *eval_info->exp_buf, eval_info->saved_expr);
+ }
+ }
return res;
}
static struct value *
-stap_evaluate_probe_argument_2 (char **expr,
- struct gdbarch *gdbarch,
- struct frame_info *frame,
- enum stap_arg_bitness bitness,
- struct value *lhs,
- int prec);
+stap_evaluate_probe_argument_2 (struct stap_evaluation_info *eval_info,
+ 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)
+stap_evaluate_conditionally (struct stap_evaluation_info *eval_info)
{
- char *s = *expr;
+ char *s = eval_info->exp_buf;
struct value *ret;
if (*s == '-' || *s == '~' /* Unary operators. */
@@ -843,84 +870,80 @@ stap_evaluate_conditionally (char **expr, struct gdbarch *gdbarch,
|| (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);
+ ret = stap_parse_single_operand (eval_info);
else if (*s == '(')
{
- ++s;
- ep_skip_leading_whitespace (&s);
- ret = stap_evaluate_probe_argument_2 (&s, gdbarch, frame,
- bitness, NULL, 0);
- if (*s != ')')
+ ++eval_info->exp_buf;
+ ep_skip_leading_whitespace (&eval_info->exp_buf);
+
+ ret = stap_evaluate_probe_argument_2 (eval_info,
+ /*lhs=*/NULL, /*prec=*/0);
+
+ if (*eval_info->exp_buf != ')')
error (_("Missign close-paren on expression `%s'."),
- stap_saved_expression);
- ++s;
- ep_skip_leading_whitespace (&s);
+ eval_info->saved_expr);
+ ++eval_info->exp_buf;
+ ep_skip_leading_whitespace (&eval_info->exp_buf);
}
- *expr = s;
-
return ret;
}
static struct value *
-stap_evaluate_probe_argument_2 (char **expr,
- struct gdbarch *gdbarch,
- struct frame_info *frame,
- enum stap_arg_bitness bitness,
- struct value *lhs,
- int prec)
+stap_evaluate_probe_argument_2 (struct stap_evaluation_info *eval_info,
+ struct value *lhs, int prec)
{
struct value *rhs = NULL;
- char *s = *expr;
- ep_skip_leading_whitespace (&s);
+ ep_skip_leading_whitespace (&eval_info->exp_buf);
if (!lhs)
/* We have to evaluate the left side of this expression. */
- lhs = stap_evaluate_conditionally (&s, gdbarch, frame, bitness);
+ lhs = stap_evaluate_conditionally (eval_info);
- while (s && *s && *s != ')')
+ while (eval_info->exp_buf
+ && *eval_info->exp_buf
+ && *eval_info->exp_buf != ')')
{
enum exp_opcode opcode;
int cur_prec;
- if (!stap_is_operator (s))
+ if (!stap_is_operator (eval_info->exp_buf))
error (_("Invalid operator `%c' on expression `%s'."),
- *s, stap_saved_expression);
+ *eval_info->exp_buf, eval_info->saved_expr);
- if (*s == '(')
+ if (*eval_info->exp_buf == '(')
opcode = BINOP_MUL;
else
- stap_get_opcode (&s, &opcode);
+ stap_get_opcode (&eval_info->exp_buf, &opcode);
cur_prec = stap_get_operator_prec (opcode);
if (cur_prec < prec)
break;
- ep_skip_leading_whitespace (&s);
+ ep_skip_leading_whitespace (&eval_info->exp_buf);
- rhs = stap_evaluate_conditionally (&s, gdbarch, frame, bitness);
+ rhs = stap_evaluate_conditionally (eval_info);
- while (*s && stap_is_operator (s))
+ while (*eval_info->exp_buf
+ && stap_is_operator (eval_info->exp_buf))
{
enum exp_opcode lookahead_opcode;
int lookahead_prec;
- stap_get_opcode (&s, &lookahead_opcode);
+ stap_get_opcode (&eval_info->exp_buf, &lookahead_opcode);
lookahead_prec = stap_get_operator_prec (lookahead_opcode);
if (lookahead_prec <= prec)
break;
- rhs = stap_evaluate_probe_argument_2 (&s, gdbarch, frame,
- bitness, rhs, lookahead_prec);
+ rhs = stap_evaluate_probe_argument_2 (eval_info,
+ rhs, lookahead_prec);
}
lhs = value_binop (lhs, rhs, opcode);
}
- *expr = s;
-
return lhs;
}
@@ -931,6 +954,7 @@ stap_evaluate_probe_argument_1 (struct objfile *objfile,
struct frame_info *frame,
int n)
{
+ struct stap_evaluation_info eval_info;
struct gdbarch *gdbarch = get_objfile_arch (objfile);
char *s = (char *) probe->parsed_args->arg[n].arg_str;
struct value *res, *vs[4];
@@ -942,15 +966,20 @@ stap_evaluate_probe_argument_1 (struct objfile *objfile,
int i;
#endif
- stap_saved_expression = s;
- res = stap_evaluate_probe_argument_2 (&s, gdbarch, frame,
- probe->parsed_args->arg[n].bitness,
+ eval_info.saved_expr = s;
+ eval_info.exp_buf = s;
+ eval_info.gdbarch = get_objfile_arch (objfile);
+ eval_info.frame = frame;
+ eval_info.bitness = probe->parsed_args->arg[n].bitness;
+
+ res = stap_evaluate_probe_argument_2 (&eval_info,
/*lhs=*/NULL, /*prec=*/0);
#if TEST /* TESTING */
for (i = 0; i < 4; i++)
{
- vs[i] = stap_evaluate_probe_argument_2 ((char **) &(args[i]), gdbarch, frame,
- probe->parsed_args->arg[n].bitness,
+ eval_info.saved_expr = (const char *) args[i];
+ eval_info.exp_buf = (char *) args[i];
+ vs[i] = stap_evaluate_probe_argument_2 (&eval_info,
/*lhs=*/NULL, /*prec=*/0);
fprintf_unfiltered (gdb_stdout, "%ld\n", value_as_long (vs[i]));
@@ -959,9 +988,7 @@ stap_evaluate_probe_argument_1 (struct objfile *objfile,
if (!res)
error (_("Could not evaluate expression `%s'."),
- stap_saved_expression);
-
- stap_saved_expression = NULL;
+ eval_info.saved_expr);
return res;
}
hooks/post-receive
--
Repository for Project Archer.
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2011-03-16 5:38 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-16 5:38 [SCM] archer-sergiodj-stap: Creating `struct stap_evaluation_info' 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).