/* 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.
it. */
CORE_ADDR sem_addr;
+ /* One if the arguments have been parsed. */
unsigned int args_parsed : 1;
+
union
{
const char *text;
}
}
+/* Helper function to check for a generic list of prefixes. GDBARCH
+ is the current gdbarch being used. S is the expression being
+ analyzed. If R is not NULL, it will be used to return the found
+ prefix. PREFIXES is the list of expected prefixes.
+
+ This function does a case-insensitive match.
+
+ Return 1 if any prefix has been found, zero otherwise. */
+
+static int
+stap_is_generic_prefix (struct gdbarch *gdbarch, const char *s,
+ const char **r, const char *const *prefixes)
+{
+ const char *const *p;
+
+ if (prefixes == NULL)
+ {
+ if (r != NULL)
+ *r = "";
+
+ return 1;
+ }
+
+ for (p = prefixes; *p != NULL; ++p)
+ if (strncasecmp (s, *p, strlen (*p)) == 0)
+ {
+ if (r != NULL)
+ *r = *p;
+
+ return 1;
+ }
+
+ return 0;
+}
+
+/* Return 1 if S points to a register prefix, zero otherwise. For a
+ description of the arguments, look at stap_is_generic_prefix. */
+
+static int
+stap_is_register_prefix (struct gdbarch *gdbarch, const char *s,
+ const char **r)
+{
+ const char *const *t = gdbarch_stap_register_prefixes (gdbarch);
+
+ return stap_is_generic_prefix (gdbarch, s, r, t);
+}
+
+/* Return 1 if S points to a register indirection prefix, zero
+ otherwise. For a description of the arguments, look at
+ stap_is_generic_prefix. */
+
+static int
+stap_is_register_indirection_prefix (struct gdbarch *gdbarch, const char *s,
+ const char **r)
+{
+ const char *const *t = gdbarch_stap_register_indirection_prefixes (gdbarch);
+
+ return stap_is_generic_prefix (gdbarch, s, r, t);
+}
+
+/* Return 1 if S points to an integer prefix, zero otherwise. For a
+ description of the arguments, look at stap_is_generic_prefix.
+
+ This function takes care of analyzing whether we are dealing with
+ an expected integer prefix, or, if there is no integer prefix to be
+ expected, whether we are dealing with a digit. It does a
+ case-insensitive match. */
+
+static int
+stap_is_integer_prefix (struct gdbarch *gdbarch, const char *s,
+ const char **r)
+{
+ const char *const *t = gdbarch_stap_integer_prefixes (gdbarch);
+ const char *const *p;
+
+ if (t == NULL)
+ {
+ /* A NULL value here means that integers do not have a prefix.
+ We just check for a digit then. */
+ if (r != NULL)
+ *r = "";
+
+ return isdigit (*s);
+ }
+
+ for (p = t; *p != NULL; ++p)
+ {
+ size_t len = strlen (*p);
+
+ if ((len == 0 && isdigit (*s))
+ || (len > 0 && strncasecmp (s, *p, len) == 0))
+ {
+ /* Integers may or may not have a prefix. The "len == 0"
+ check covers the case when integers do not have a prefix
+ (therefore, we just check if we have a digit). The call
+ to "strncasecmp" covers the case when they have a
+ prefix. */
+ if (r != NULL)
+ *r = *p;
+
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+/* Helper function to check for a generic list of suffixes. If we are
+ not expecting any suffixes, then it just returns 1. If we are
+ expecting at least one suffix, then it returns 1 if a suffix has
+ been found, zero otherwise. GDBARCH is the current gdbarch being
+ used. S is the expression being analyzed. If R is not NULL, it
+ will be used to return the found suffix. SUFFIXES is the list of
+ expected suffixes. This function does a case-insensitive
+ match. */
+
+static int
+stap_generic_check_suffix (struct gdbarch *gdbarch, const char *s,
+ const char **r, const char *const *suffixes)
+{
+ const char *const *p;
+ int found = 0;
+
+ if (suffixes == NULL)
+ {
+ if (r != NULL)
+ *r = "";
+
+ return 1;
+ }
+
+ for (p = suffixes; *p != NULL; ++p)
+ if (strncasecmp (s, *p, strlen (*p)) == 0)
+ {
+ if (r != NULL)
+ *r = *p;
+
+ found = 1;
+ break;
+ }
+
+ return found;
+}
+
+/* Return 1 if S points to an integer suffix, zero otherwise. For a
+ description of the arguments, look at
+ stap_generic_check_suffix. */
+
+static int
+stap_check_integer_suffix (struct gdbarch *gdbarch, const char *s,
+ const char **r)
+{
+ const char *const *p = gdbarch_stap_integer_suffixes (gdbarch);
+
+ return stap_generic_check_suffix (gdbarch, s, r, p);
+}
+
+/* Return 1 if S points to a register suffix, zero otherwise. For a
+ description of the arguments, look at
+ stap_generic_check_suffix. */
+
+static int
+stap_check_register_suffix (struct gdbarch *gdbarch, const char *s,
+ const char **r)
+{
+ const char *const *p = gdbarch_stap_register_suffixes (gdbarch);
+
+ return stap_generic_check_suffix (gdbarch, s, r, p);
+}
+
+/* Return 1 if S points to a register indirection suffix, zero
+ otherwise. For a description of the arguments, look at
+ stap_generic_check_suffix. */
+
+static int
+stap_check_register_indirection_suffix (struct gdbarch *gdbarch, const char *s,
+ const char **r)
+{
+ const char *const *p = gdbarch_stap_register_indirection_suffixes (gdbarch);
+
+ return stap_generic_check_suffix (gdbarch, s, r, p);
+}
+
/* Function responsible for parsing a register operand according to
SystemTap parlance. Assuming:
/* 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;
char *regname;
int len;
-
- /* Prefixes for the parser. */
- const char *reg_prefix = gdbarch_stap_register_prefix (gdbarch);
- const char *reg_ind_prefix
- = gdbarch_stap_register_indirection_prefix (gdbarch);
const char *gdb_reg_prefix = gdbarch_stap_gdb_register_prefix (gdbarch);
- int reg_prefix_len = reg_prefix ? strlen (reg_prefix) : 0;
- int reg_ind_prefix_len = reg_ind_prefix ? strlen (reg_ind_prefix) : 0;
int gdb_reg_prefix_len = gdb_reg_prefix ? strlen (gdb_reg_prefix) : 0;
-
- /* Suffixes for the parser. */
- const char *reg_suffix = gdbarch_stap_register_suffix (gdbarch);
- const char *reg_ind_suffix
- = gdbarch_stap_register_indirection_suffix (gdbarch);
const char *gdb_reg_suffix = gdbarch_stap_gdb_register_suffix (gdbarch);
- int reg_suffix_len = reg_suffix ? strlen (reg_suffix) : 0;
- int reg_ind_suffix_len = reg_ind_suffix ? strlen (reg_ind_suffix) : 0;
int gdb_reg_suffix_len = gdb_reg_suffix ? strlen (gdb_reg_suffix) : 0;
+ const char *reg_prefix;
+ const char *reg_ind_prefix;
+ const char *reg_suffix;
+ const char *reg_ind_suffix;
/* Checking for a displacement argument. */
if (*p->arg == '+')
}
/* Getting rid of register indirection prefix. */
- if (reg_ind_prefix
- && strncmp (p->arg, reg_ind_prefix, reg_ind_prefix_len) == 0)
+ if (stap_is_register_indirection_prefix (gdbarch, p->arg, ®_ind_prefix))
{
indirect_p = 1;
- p->arg += reg_ind_prefix_len;
+ p->arg += strlen (reg_ind_prefix);
}
if (disp_p && !indirect_p)
p->saved_arg);
/* Getting rid of register prefix. */
- if (reg_prefix && strncmp (p->arg, reg_prefix, reg_prefix_len) == 0)
- p->arg += reg_prefix_len;
+ if (stap_is_register_prefix (gdbarch, p->arg, ®_prefix))
+ p->arg += strlen (reg_prefix);
/* Now we should have only the register name. Let's extract it and get
the associated number. */
}
/* Getting rid of the register name suffix. */
- if (reg_suffix)
- {
- if (strncmp (p->arg, reg_suffix, reg_suffix_len) != 0)
- error (_("Missing register name suffix `%s' on expression `%s'."),
- reg_suffix, p->saved_arg);
-
- p->arg += reg_suffix_len;
- }
+ if (stap_check_register_suffix (gdbarch, p->arg, ®_suffix))
+ p->arg += strlen (reg_suffix);
+ else
+ error (_("Missing register name suffix on expression `%s'."),
+ p->saved_arg);
/* Getting rid of the register indirection suffix. */
- if (indirect_p && reg_ind_suffix)
+ if (indirect_p)
{
- if (strncmp (p->arg, reg_ind_suffix, reg_ind_suffix_len) != 0)
- error (_("Missing indirection suffix `%s' on expression `%s'."),
- reg_ind_suffix, p->saved_arg);
-
- p->arg += reg_ind_suffix_len;
+ if (stap_check_register_indirection_suffix (gdbarch, p->arg,
+ ®_ind_suffix))
+ p->arg += strlen (reg_ind_suffix);
+ else
+ error (_("Missing indirection suffix on expression `%s'."),
+ p->saved_arg);
}
}
stap_parse_single_operand (struct stap_parse_info *p)
{
struct gdbarch *gdbarch = p->gdbarch;
-
- /* Prefixes for the parser. */
- const char *const_prefix = gdbarch_stap_integer_prefix (gdbarch);
- const char *reg_prefix = gdbarch_stap_register_prefix (gdbarch);
- const char *reg_ind_prefix
- = gdbarch_stap_register_indirection_prefix (gdbarch);
- int const_prefix_len = const_prefix ? strlen (const_prefix) : 0;
- int reg_prefix_len = reg_prefix ? strlen (reg_prefix) : 0;
- int reg_ind_prefix_len = reg_ind_prefix ? strlen (reg_ind_prefix) : 0;
-
- /* Suffixes for the parser. */
- const char *const_suffix = gdbarch_stap_integer_suffix (gdbarch);
- int const_suffix_len = const_suffix ? strlen (const_suffix) : 0;
+ const char *int_prefix = NULL;
/* 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 (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 (ret)
- {
- /* 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
tmp = endp;
}
- if (!reg_ind_prefix
- || strncmp (tmp, reg_ind_prefix, reg_ind_prefix_len) != 0)
+ if (!stap_is_register_indirection_prefix (gdbarch, tmp, NULL))
{
/* This is not a displacement. We skip the operator, and deal
with it later. */
char *endp;
long number;
- /* We can be dealing with a numeric constant (if `const_prefix' is
- NULL), or with a register displacement. */
+ /* We can be dealing with a numeric constant, or with a register
+ displacement. */
number = strtol (tmp, &endp, 10);
tmp = endp;
if (p->inside_paren_p)
tmp = skip_spaces_const (tmp);
- if (!const_prefix && reg_ind_prefix
- && strncmp (tmp, reg_ind_prefix, reg_ind_prefix_len) != 0)
+
+ /* If "stap_is_integer_prefix" returns true, it means we can
+ accept integers without a prefix here. But we also need to
+ check whether the next token (i.e., "tmp") is not a register
+ indirection prefix. */
+ if (stap_is_integer_prefix (gdbarch, p->arg, NULL)
+ && !stap_is_register_indirection_prefix (gdbarch, tmp, NULL))
{
+ const char *int_suffix;
+
/* We are dealing with a numeric constant. */
write_exp_elt_opcode (OP_LONG);
write_exp_elt_type (builtin_type (gdbarch)->builtin_long);
p->arg = tmp;
- if (const_suffix)
- {
- if (strncmp (p->arg, const_suffix, const_suffix_len) == 0)
- p->arg += const_suffix_len;
- else
- error (_("Invalid constant suffix on expression `%s'."),
- p->saved_arg);
- }
+ if (stap_check_integer_suffix (gdbarch, p->arg, &int_suffix))
+ p->arg += strlen (int_suffix);
+ else
+ error (_("Invalid constant suffix on expression `%s'."),
+ p->saved_arg);
}
- else if (reg_ind_prefix
- && strncmp (tmp, reg_ind_prefix, reg_ind_prefix_len) == 0)
+ else if (stap_is_register_indirection_prefix (gdbarch, tmp, NULL))
stap_parse_register_operand (p);
else
error (_("Unknown numeric token on expression `%s'."),
p->saved_arg);
}
- else if (const_prefix
- && strncmp (p->arg, const_prefix, const_prefix_len) == 0)
+ else if (stap_is_integer_prefix (gdbarch, p->arg, &int_prefix))
{
/* We are dealing with a numeric constant. */
long number;
char *endp;
+ const char *int_suffix;
- p->arg += const_prefix_len;
+ p->arg += strlen (int_prefix);
number = strtol (p->arg, &endp, 10);
p->arg = endp;
write_exp_elt_longcst (number);
write_exp_elt_opcode (OP_LONG);
- if (const_suffix)
- {
- if (strncmp (p->arg, const_suffix, const_suffix_len) == 0)
- p->arg += const_suffix_len;
- else
- error (_("Invalid constant suffix on expression `%s'."),
- p->saved_arg);
- }
+ if (stap_check_integer_suffix (gdbarch, p->arg, &int_suffix))
+ p->arg += strlen (int_suffix);
+ else
+ error (_("Invalid constant suffix on expression `%s'."),
+ p->saved_arg);
}
- else if ((reg_prefix
- && strncmp (p->arg, reg_prefix, reg_prefix_len) == 0)
- || (reg_ind_prefix
- && strncmp (p->arg, reg_ind_prefix, reg_ind_prefix_len) == 0))
+ else if (stap_is_register_prefix (gdbarch, p->arg, NULL)
+ || stap_is_register_indirection_prefix (gdbarch, p->arg, NULL))
stap_parse_register_operand (p);
else
error (_("Operator `%c' not recognized on expression `%s'."),
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))
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);
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;
/* 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;
this information. */
static void
-stap_parse_probe_arguments (struct stap_probe *probe)
+stap_parse_probe_arguments (struct stap_probe *probe, struct gdbarch *gdbarch)
{
const char *cur;
- struct gdbarch *gdbarch = get_objfile_arch (probe->p.objfile);
gdb_assert (!probe->args_parsed);
cur = probe->args_u.text;
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;
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
argument string. */
static unsigned
-stap_get_probe_argument_count (struct probe *probe_generic)
+stap_get_probe_argument_count (struct probe *probe_generic,
+ struct frame_info *frame)
{
struct stap_probe *probe = (struct stap_probe *) probe_generic;
+ struct gdbarch *gdbarch = get_frame_arch (frame);
gdb_assert (probe_generic->pops == &stap_probe_ops);
if (!probe->args_parsed)
{
- if (probe_generic->pops->can_evaluate_probe_arguments (probe_generic))
- stap_parse_probe_arguments (probe);
+ if (can_evaluate_probe_arguments (probe_generic))
+ stap_parse_probe_arguments (probe, gdbarch);
else
{
static int have_warned_stap_incomplete = 0;
}
static struct stap_probe_arg *
-stap_get_arg (struct stap_probe *probe, unsigned n)
+stap_get_arg (struct stap_probe *probe, unsigned n, struct gdbarch *gdbarch)
{
if (!probe->args_parsed)
- stap_parse_probe_arguments (probe);
+ stap_parse_probe_arguments (probe, gdbarch);
return VEC_index (stap_probe_arg_s, probe->args_u.vec, n);
}
corresponding to it. Assertion is thrown if N does not exist. */
static struct value *
-stap_evaluate_probe_argument (struct probe *probe_generic, unsigned n)
+stap_evaluate_probe_argument (struct probe *probe_generic, unsigned n,
+ struct frame_info *frame)
{
struct stap_probe *stap_probe = (struct stap_probe *) probe_generic;
+ struct gdbarch *gdbarch = get_frame_arch (frame);
struct stap_probe_arg *arg;
int pos = 0;
gdb_assert (probe_generic->pops == &stap_probe_ops);
- arg = stap_get_arg (stap_probe, n);
+ arg = stap_get_arg (stap_probe, n, gdbarch);
return evaluate_subexp_standard (arg->atype, arg->aexpr, &pos, EVAL_NORMAL);
}
gdb_assert (probe_generic->pops == &stap_probe_ops);
- arg = stap_get_arg (stap_probe, n);
+ arg = stap_get_arg (stap_probe, n, expr->gdbarch);
pc = arg->aexpr->elts;
gen_expr (arg->aexpr, &pc, expr, value);
if (pc_probe == NULL)
error (_("No SystemTap probe at PC %s"), core_addr_to_string (pc));
- n_args = get_probe_argument_count (pc_probe);
+ n_args = get_probe_argument_count (pc_probe, frame);
if (sel == -1)
return value_from_longest (builtin_type (arch)->builtin_int, n_args);
error (_("Invalid probe argument %d -- probe has %u arguments available"),
sel, n_args);
- return evaluate_probe_argument (pc_probe, sel);
+ return evaluate_probe_argument (pc_probe, sel, frame);
}
/* This is called to compile one of the $_probe_arg* convenience
struct probe *pc_probe;
const struct sym_probe_fns *pc_probe_fns;
int n_args;
+ struct frame_info *frame = get_selected_frame (NULL);
/* SEL == -1 means "_probe_argc". */
gdb_assert (sel >= -1);
if (pc_probe == NULL)
error (_("No SystemTap probe at PC %s"), core_addr_to_string (pc));
- n_args = get_probe_argument_count (pc_probe);
+ n_args = get_probe_argument_count (pc_probe, frame);
if (sel == -1)
{
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'"),
ret->p.address += (ANOFFSET (objfile->section_offsets,
SECT_OFF_TEXT (objfile))
+ base - base_ref);
- if (ret->sem_addr)
+ if (ret->sem_addr != 0)
ret->sem_addr += (ANOFFSET (objfile->section_offsets,
SECT_OFF_DATA (objfile))
+ base - base_ref);
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'"),
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'."),
return 0;
}
- if (base)
+ if (base != NULL)
*base = ret->vma;
return 1;
return;
}
- if (!elf_tdata (obfd)->sdt_note_head)
+ if (elf_tdata (obfd)->sdt_note_head == NULL)
{
/* There isn't any probe here. */
return;
}
/* 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. */
gdb_assert (probe_generic->pops == &stap_probe_ops);
probe->p.address += delta;
- if (probe->sem_addr)
+ if (probe->sem_addr != 0)
probe->sem_addr += delta;
}
gdbarch = get_objfile_arch (probe->p.objfile);
- 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);