/* SystemTap probe support for GDB.
- Copyright (C) 2012-2015 Free Software Foundation, Inc.
+ Copyright (C) 2012-2017 Free Software Foundation, Inc.
This file is part of GDB.
/* Forward declaration. */
-static const struct probe_ops stap_probe_ops;
+extern const struct probe_ops stap_probe_ops;
/* Should we display debug information for the probe's argument expression
parsing? */
break;
default:
- internal_error (__FILE__, __LINE__,
- _("Invalid opcode in expression `%s' for SystemTap"
- "probe"), *s);
+ error (_("Invalid opcode in expression `%s' for SystemTap"
+ "probe"), *s);
}
return op;
static struct type *
stap_get_expected_argument_type (struct gdbarch *gdbarch,
- enum stap_arg_bitness b)
+ enum stap_arg_bitness b,
+ const struct stap_probe *probe)
{
switch (b)
{
return builtin_type (gdbarch)->builtin_uint64;
default:
- internal_error (__FILE__, __LINE__,
- _("Undefined bitness for probe."));
+ error (_("Undefined bitness for probe '%s'."),
+ probe->p.name);
break;
}
}
len = p->arg - start;
- regname = alloca (len + gdb_reg_prefix_len + gdb_reg_suffix_len + 1);
+ regname = (char *) alloca (len + gdb_reg_prefix_len + gdb_reg_suffix_len + 1);
regname[0] = '\0';
/* We only add the GDB's register prefix/suffix if we are dealing with
We handle the register displacement here, and the other cases
recursively. */
if (p->inside_paren_p)
- tmp = skip_spaces_const (tmp);
+ tmp = skip_spaces (tmp);
while (isdigit (*tmp))
{
tmp = endp;
if (p->inside_paren_p)
- tmp = skip_spaces_const (tmp);
+ tmp = skip_spaces (tmp);
/* If "stap_is_integer_prefix" returns true, it means we can
accept integers without a prefix here. But we also need to
have to parse it as it was a separate expression, without
left-side or precedence. */
++p->arg;
- p->arg = skip_spaces_const (p->arg);
+ p->arg = skip_spaces (p->arg);
++p->inside_paren_p;
stap_parse_argument_1 (p, 0, STAP_OPERAND_PREC_NONE);
++p->arg;
if (p->inside_paren_p)
- p->arg = skip_spaces_const (p->arg);
+ p->arg = skip_spaces (p->arg);
}
else
error (_("Cannot parse expression `%s'."), p->saved_arg);
gdb_assert (p->arg != NULL);
if (p->inside_paren_p)
- p->arg = skip_spaces_const (p->arg);
+ p->arg = skip_spaces (p->arg);
if (!has_lhs)
{
p->arg = tmp_exp_buf;
if (p->inside_paren_p)
- p->arg = skip_spaces_const (p->arg);
+ p->arg = skip_spaces (p->arg);
/* Parse the right-side of the expression. */
stap_parse_argument_conditionally (p);
reallocate_expout (&p.pstate);
- p.arg = skip_spaces_const (p.arg);
+ p.arg = skip_spaces (p.arg);
*arg = p.arg;
/* We can safely return EXPOUT here. */
else
arg.bitness = STAP_ARG_BITNESS_UNDEFINED;
- arg.atype = stap_get_expected_argument_type (gdbarch, arg.bitness);
+ arg.atype = stap_get_expected_argument_type (gdbarch, arg.bitness,
+ probe);
expr = stap_parse_argument (&cur, arg.atype, gdbarch);
arg.aexpr = expr;
/* Start it over again. */
- cur = skip_spaces_const (cur);
+ cur = skip_spaces (cur);
VEC_safe_push (stap_probe_arg_s, probe->args_u.vec, &arg);
}
return ret;
}
+/* Return argument N of probe PROBE.
+
+ If the probe's arguments have not been parsed yet, parse them. If
+ there are no arguments, throw an exception (error). Otherwise,
+ return the requested argument. */
+
static struct stap_probe_arg *
stap_get_arg (struct stap_probe *probe, unsigned n, struct gdbarch *gdbarch)
{
if (!probe->args_parsed)
stap_parse_probe_arguments (probe, gdbarch);
+ gdb_assert (probe->args_parsed);
+ if (probe->args_u.vec == NULL)
+ internal_error (__FILE__, __LINE__,
+ _("Probe '%s' apparently does not have arguments, but \n"
+ "GDB is requesting its argument number %u anyway. "
+ "This should not happen. Please report this bug."),
+ probe->p.name, n);
+
return VEC_index (stap_probe_arg_s, probe->args_u.vec, n);
}
\f
-/* This is called to compute the value of one of the $_probe_arg*
- convenience variables. */
-
-static struct value *
-compute_probe_arg (struct gdbarch *arch, struct internalvar *ivar,
- void *data)
-{
- struct frame_info *frame = get_selected_frame (_("No frame selected"));
- CORE_ADDR pc = get_frame_pc (frame);
- int sel = (int) (uintptr_t) data;
- struct bound_probe pc_probe;
- const struct sym_probe_fns *pc_probe_fns;
- unsigned n_args;
-
- /* SEL == -1 means "_probe_argc". */
- gdb_assert (sel >= -1);
-
- pc_probe = find_probe_by_pc (pc);
- 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.probe, frame);
- if (sel == -1)
- return value_from_longest (builtin_type (arch)->builtin_int, n_args);
-
- if (sel >= n_args)
- error (_("Invalid probe argument %d -- probe has %u arguments available"),
- sel, n_args);
-
- return evaluate_probe_argument (pc_probe.probe, sel, frame);
-}
-
-/* This is called to compile one of the $_probe_arg* convenience
- variables into an agent expression. */
-
-static void
-compile_probe_arg (struct internalvar *ivar, struct agent_expr *expr,
- struct axs_value *value, void *data)
-{
- CORE_ADDR pc = expr->scope;
- int sel = (int) (uintptr_t) data;
- struct bound_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);
-
- pc_probe = find_probe_by_pc (pc);
- 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.probe, frame);
-
- if (sel == -1)
- {
- value->kind = axs_rvalue;
- value->type = builtin_type (expr->gdbarch)->builtin_int;
- ax_const_l (expr, n_args);
- return;
- }
-
- gdb_assert (sel >= 0);
- if (sel >= n_args)
- error (_("Invalid probe argument %d -- probe has %d arguments available"),
- sel, n_args);
-
- pc_probe.probe->pops->compile_to_ax (pc_probe.probe, expr, value, sel);
-}
-
-\f
-
/* Set or clear a SystemTap semaphore. ADDRESS is the semaphore's
address. SET is zero if the semaphore should be cleared, or one
if it should be set. This is a helper function for `stap_semaphore_down'
stap_modify_semaphore (addr, 0, gdbarch);
}
-/* Implementation of `$_probe_arg*' set of variables. */
-
-static const struct internalvar_funcs probe_funcs =
-{
- compute_probe_arg,
- compile_probe_arg,
- NULL
-};
-
/* Helper function that parses the information contained in a
SystemTap's probe. Basically, the information consists in:
static void
handle_stap_probe (struct objfile *objfile, struct sdt_note *el,
- VEC (probe_p) **probesp, CORE_ADDR base)
+ std::vector<probe *> *probesp, CORE_ADDR base)
{
bfd *abfd = objfile->obfd;
int size = bfd_get_arch_size (abfd) / 8;
const char *probe_args = NULL;
struct stap_probe *ret;
- ret = obstack_alloc (&objfile->per_bfd->storage_obstack, sizeof (*ret));
+ ret = XOBNEW (&objfile->per_bfd->storage_obstack, struct stap_probe);
ret->p.pops = &stap_probe_ops;
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);
+ ret->p.name = ((const char *)
+ memchr (ret->p.provider, '\0',
+ (char *) el->data + el->size - ret->p.provider));
/* Making sure there is a name. */
if (ret->p.name == NULL)
{
/* Arguments. We can only extract the argument format if there is a valid
name for this probe. */
- probe_args = memchr (ret->p.name, '\0',
- (char *) el->data + el->size - ret->p.name);
+ probe_args = ((const char*)
+ memchr (ret->p.name, '\0',
+ (char *) el->data + el->size - ret->p.name));
if (probe_args != NULL)
++probe_args;
}
ret->args_parsed = 0;
- ret->args_u.text = (void *) probe_args;
+ ret->args_u.text = probe_args;
/* Successfully created probe. */
- VEC_safe_push (probe_p, *probesp, (struct probe *) ret);
+ probesp->push_back ((struct probe *) ret);
}
/* Helper function which tries to find the base address of the SystemTap
static void
get_stap_base_address_1 (bfd *abfd, asection *sect, void *obj)
{
- asection **ret = obj;
+ asection **ret = (asection **) obj;
if ((sect->flags & (SEC_DATA | SEC_ALLOC | SEC_HAS_CONTENTS))
&& sect->name && !strcmp (sect->name, STAP_BASE_SECTION_NAME))
SystemTap probes from OBJFILE. */
static void
-stap_get_probes (VEC (probe_p) **probesp, struct objfile *objfile)
+stap_get_probes (std::vector<probe *> *probesp, struct objfile *objfile)
{
/* If we are here, then this is the first time we are parsing the
SystemTap probe's information. We basically have to count how many
bfd *obfd = objfile->obfd;
bfd_vma base;
struct sdt_note *iter;
- unsigned save_probesp_len = VEC_length (probe_p, *probesp);
+ unsigned save_probesp_len = probesp->size ();
if (objfile->separate_debug_objfile_backlink != NULL)
{
handle_stap_probe (objfile, iter, probesp, base);
}
- if (save_probesp_len == VEC_length (probe_p, *probesp))
+ if (save_probesp_len == probesp->size ())
{
/* If we are here, it means we have failed to parse every known
probe. */
}
}
+/* Implementation of the type_name method. */
+
+static const char *
+stap_type_name (struct probe *probe)
+{
+ gdb_assert (probe->pops == &stap_probe_ops);
+ return "stap";
+}
+
static int
stap_probe_is_linespec (const char **linespecp)
{
/* SystemTap probe_ops. */
-static const struct probe_ops stap_probe_ops =
+const struct probe_ops stap_probe_ops =
{
stap_probe_is_linespec,
stap_get_probes,
stap_set_semaphore,
stap_clear_semaphore,
stap_probe_destroy,
+ stap_type_name,
stap_gen_info_probes_table_header,
stap_gen_info_probes_table_values,
+ NULL, /* enable_probe */
+ NULL /* disable_probe */
};
/* Implementation of the `info probes stap' command. */
static void
-info_probes_stap_command (char *arg, int from_tty)
+info_probes_stap_command (const char *arg, int from_tty)
{
info_probes_for_ops (arg, from_tty, &stap_probe_ops);
}
-void _initialize_stap_probe (void);
-
void
_initialize_stap_probe (void)
{
- VEC_safe_push (probe_ops_cp, all_probe_ops, &stap_probe_ops);
+ all_probe_ops.push_back (&stap_probe_ops);
add_setshow_zuinteger_cmd ("stap-expression", class_maintenance,
&stap_expression_debug,
show_stapexpressiondebug,
&setdebuglist, &showdebuglist);
- create_internalvar_type_lazy ("_probe_argc", &probe_funcs,
- (void *) (uintptr_t) -1);
- create_internalvar_type_lazy ("_probe_arg0", &probe_funcs,
- (void *) (uintptr_t) 0);
- create_internalvar_type_lazy ("_probe_arg1", &probe_funcs,
- (void *) (uintptr_t) 1);
- create_internalvar_type_lazy ("_probe_arg2", &probe_funcs,
- (void *) (uintptr_t) 2);
- create_internalvar_type_lazy ("_probe_arg3", &probe_funcs,
- (void *) (uintptr_t) 3);
- create_internalvar_type_lazy ("_probe_arg4", &probe_funcs,
- (void *) (uintptr_t) 4);
- create_internalvar_type_lazy ("_probe_arg5", &probe_funcs,
- (void *) (uintptr_t) 5);
- create_internalvar_type_lazy ("_probe_arg6", &probe_funcs,
- (void *) (uintptr_t) 6);
- create_internalvar_type_lazy ("_probe_arg7", &probe_funcs,
- (void *) (uintptr_t) 7);
- create_internalvar_type_lazy ("_probe_arg8", &probe_funcs,
- (void *) (uintptr_t) 8);
- create_internalvar_type_lazy ("_probe_arg9", &probe_funcs,
- (void *) (uintptr_t) 9);
- create_internalvar_type_lazy ("_probe_arg10", &probe_funcs,
- (void *) (uintptr_t) 10);
- create_internalvar_type_lazy ("_probe_arg11", &probe_funcs,
- (void *) (uintptr_t) 11);
-
add_cmd ("stap", class_info, info_probes_stap_command,
_("\
Show information about SystemTap static probes.\n\