public inbox for archer-commits@sourceware.org
help / color / mirror / Atom feed
* [SCM] archer-sergiodj-stap: Changing the moment we decide to parse the arguments.
@ 2011-02-28 8:50 sergiodj
0 siblings, 0 replies; only message in thread
From: sergiodj @ 2011-02-28 8:50 UTC (permalink / raw)
To: archer-commits
The branch, archer-sergiodj-stap has been updated
via d7969addbadf86ae838960b22a3c32cfcbb490bc (commit)
from 4483ce291bed02f60661284b4eeed2757d417a0f (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email.
- Log -----------------------------------------------------------------
commit d7969addbadf86ae838960b22a3c32cfcbb490bc
Author: Sergio Durigan Junior <sergiodj@redhat.com>
Date: Mon Feb 28 05:46:42 2011 -0300
Changing the moment we decide to parse the arguments.
I changed the way we store the probe's parsed arguments info. Now,
inside of every `struct stap_probe', we'll have info about the parsed
args. This will let us keep a "cache" of parsing, and only parse the
args once.
Also, I decided to call the parser for the probe's arguments right after we
have enough info about the probe, inside `elf_get_probes'. Maybe this
will slow down things; another option would be to call it from
`elf_get_probe_argument_count', but since we pass a `const struct
stap_probe' there (and we'll need to modify its ->parsed_args field
inside the parser), I've chosen for keeping the "correctness" of the
code.
-----------------------------------------------------------------------
Summary of changes:
gdb/elfread.c | 18 +++++++++---
gdb/stap-probe.c | 75 ++++++++++++++++++++++++++++++++++++++++-------------
gdb/stap-probe.h | 18 +++++++++---
3 files changed, 82 insertions(+), 29 deletions(-)
First 500 lines of diff:
diff --git a/gdb/elfread.c b/gdb/elfread.c
index fdd69ff..fe7bb41 100644
--- a/gdb/elfread.c
+++ b/gdb/elfread.c
@@ -1198,13 +1198,20 @@ elf_get_probes (struct objfile *objfile, int *num_probes)
iter;
iter = iter->next, ++n);
- ret = xmalloc (n * sizeof (struct stap_probe));
+ ret = xcalloc (1, n * sizeof (struct stap_probe));
/* Parsing each probe's information. */
for (iter = elf_tdata (obfd)->sdt_note_head, i = 0;
iter;
iter = iter->next, i++)
- handle_probe (objfile, iter, &ret[i], base);
+ {
+ /* We first have to handle all the information about the
+ probe which is present in the section. */
+ handle_probe (objfile, iter, &ret[i], base);
+
+ /* Now, we try to parse the probe's arguments. */
+ stap_parse_probe_arguments (&ret[i]);
+ }
/* Creating a cache for these probes in the objfile's registry. */
probes_per_objfile = xmalloc (sizeof (struct stap_probe_per_objfile));
@@ -1230,12 +1237,12 @@ elf_get_probe_argument_count (struct objfile *objfile,
const struct stap_probe *probe)
{
const char *pargs = probe->args;
- int count = 0;
- if (!pargs)
+ if (!pargs || !*pargs || *pargs == ':')
/* No arguments. */
return 0;
+#if 0
/* Counting the arguments. */
if (!stap_parse_probe_arguments (pargs, &count))
{
@@ -1243,8 +1250,9 @@ elf_get_probe_argument_count (struct objfile *objfile,
_("Invalid arguments for probe `%s'."), probe->name);
return 0;
}
+#endif
- return count;
+ return stap_get_probe_argument_count (probe);
}
static void
diff --git a/gdb/stap-probe.c b/gdb/stap-probe.c
index d21a138..d81f185 100644
--- a/gdb/stap-probe.c
+++ b/gdb/stap-probe.c
@@ -35,13 +35,14 @@
enum stap_arg_offset
{
+ STAP_ARG_OFFSET_UNDEFINED,
STAP_ARG_OFFSET_32BIT_UNSIGNED,
STAP_ARG_OFFSET_32BIT_SIGNED,
STAP_ARG_OFFSET_64BIT_UNSIGNED,
STAP_ARG_OFFSET_64BIT_SIGNED,
};
-struct stap_arg_info
+struct stap_probe_arg
{
/* The number of this argument. */
int number;
@@ -52,11 +53,30 @@ struct stap_arg_info
#define STAP_MAX_ARGS 10
-int
-stap_parse_probe_arguments (const char *args, int *n_args)
+struct stap_args_info
{
- struct stap_arg_info arg_info[STAP_MAX_ARGS];
- const char *cur = args;
+ /* The number of valid parsed arguments. */
+ int n_args;
+
+ /* The probe to which these arguments belong. */
+ struct stap_probe *probe;
+
+ /* Information about each argument. */
+ struct stap_probe_arg arg[STAP_MAX_ARGS];
+};
+
+/* 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. */
+static struct stap_args_info dummy_stap_args_info =
+ { 0, NULL };
+
+void
+stap_parse_probe_arguments (struct stap_probe *probe)
+{
+ struct stap_args_info *args_info = xmalloc (sizeof (struct stap_args_info));
+ struct cleanup *back_to = make_cleanup (xfree, args_info);
+ const char *cur = probe->args;
int current_arg = -1;
enum
{
@@ -65,12 +85,11 @@ stap_parse_probe_arguments (const char *args, int *n_args)
PARSE_ARG,
} current_state;
- *n_args = 0;
+ /* For now, we assume everything is not going to work. */
+ probe->parsed_args = &dummy_stap_args_info;
- if (!args || !*args)
- /* The parsing has not failed, so there is no need to return
- zero here. */
- return 1;
+ if (!cur || !*cur || *cur == ':')
+ return;
/* Ok, let's start. */
current_state = NEW_ARG;
@@ -81,11 +100,16 @@ stap_parse_probe_arguments (const char *args, int *n_args)
{
case NEW_ARG:
++current_arg;
+
if (current_arg >= STAP_MAX_ARGS)
- /* More args than we can handle. */
- return 0;
+ {
+ /*complaint*/
+ do_cleanups (back_to);
+ return;
+ }
+
current_state = OFFSET;
- arg_info[current_arg].number = current_arg;
+ args_info->arg[current_arg].number = current_arg;
break;
case OFFSET:
@@ -104,6 +128,8 @@ stap_parse_probe_arguments (const char *args, int *n_args)
&& cur[1] != '@')
{
current_state = PARSE_ARG;
+ args_info->arg[current_arg].offset
+ = STAP_ARG_OFFSET_UNDEFINED;
break;
}
@@ -121,11 +147,15 @@ stap_parse_probe_arguments (const char *args, int *n_args)
o = got_minus ? STAP_ARG_OFFSET_64BIT_SIGNED
: STAP_ARG_OFFSET_64BIT_UNSIGNED;
else
- /* We have an error, because we don't expect anything
- except 4 and 8. */
- return 1;
+ {
+ /*FIXME complaint*/
+
+ /* We have an error, because we don't expect anything
+ except 4 and 8. */
+ return;
+ }
- arg_info[current_arg].offset = o;
+ args_info->arg[current_arg].offset = o;
/* Discard the number and the `@' sign. */
cur += 2;
/* Move on. */
@@ -142,9 +172,16 @@ stap_parse_probe_arguments (const char *args, int *n_args)
}
}
- *n_args = current_arg + 1;
+ args_info->n_args = current_arg + 1;
+ args_info->probe = probe;
+
+ probe->parsed_args = args_info;
+}
- return 1;
+int
+stap_get_probe_argument_count (const struct stap_probe *probe)
+{
+ return probe->parsed_args->n_args;
}
static void
diff --git a/gdb/stap-probe.h b/gdb/stap-probe.h
index dfbe786..d34c466 100644
--- a/gdb/stap-probe.h
+++ b/gdb/stap-probe.h
@@ -20,6 +20,8 @@
#if !defined (STAP_PROBE_H)
#define STAP_PROBE_H 1
+struct stap_args_info;
+
struct stap_probe
{
/* The provider of this probe. */
@@ -39,6 +41,10 @@ struct stap_probe
should instead extract information about the arguments using the
methods provided in sym_probe_fns. */
const char *args;
+
+ /* Probe's arguments after parsing. This is an opaque structure that
+ will hold information about the arguments pointed by ARGS. */
+ struct stap_args_info *parsed_args;
};
@@ -62,10 +68,12 @@ extern const struct stap_probe *find_probe_in_objfile (struct objfile *objfile,
extern const struct stap_probe *find_probe_by_pc (CORE_ADDR pc,
struct objfile **objfile_out);
-/* Give the string ARG, which represents a probe's arguments, this
- function will parse it and return the number of arguments found
- in *N_ARGS. It returns 1 if the parsing was completed successfully,
- or 0 if there is an error. */
-extern int stap_parse_probe_arguments (const char *args, int *n_args);
+/* Given PROBE, this function will parse its arguments and fill the
+ `struct stap_args_info' with proper information about them. */
+extern void stap_parse_probe_arguments (struct stap_probe *probe);
+
+/* Given PROBE, returns the number of arguments present in that probe's
+ argument string. */
+extern int stap_get_probe_argument_count (const struct stap_probe *probe);
#endif /* !defined (STAP_PROBE_H) */
hooks/post-receive
--
Repository for Project Archer.
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2011-02-28 8:50 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-28 8:50 [SCM] archer-sergiodj-stap: Changing the moment we decide to parse the arguments 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).