/* 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.
struct probe p;
/* If the probe has a semaphore associated, then this is the value of
- it. */
+ it, relative to SECT_OFF_DATA. */
CORE_ADDR sem_addr;
+ /* One if the arguments have been parsed. */
unsigned int args_parsed : 1;
+
union
{
const char *text;
}
for (p = prefixes; *p != NULL; ++p)
- {
- if (strncasecmp (s, *p, strlen (*p)) == 0)
- {
- if (r != NULL)
- *r = *p;
+ if (strncasecmp (s, *p, strlen (*p)) == 0)
+ {
+ if (r != NULL)
+ *r = *p;
- return 1;
- }
- }
+ return 1;
+ }
return 0;
}
/* 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;
/* 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 (ret)
- {
- /* If the return value of the above function is not zero,
- it means it successfully parsed the special token.
+ 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 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
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;
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
}
}
+/* Implementation of the get_probe_address method. */
+
+static CORE_ADDR
+stap_get_probe_address (struct probe *probe, struct objfile *objfile)
+{
+ return probe->address + ANOFFSET (objfile->section_offsets,
+ SECT_OFF_DATA (objfile));
+}
+
/* Given PROBE, returns the number of arguments present in that probe's
argument string. */
stap_can_evaluate_probe_arguments (struct probe *probe_generic)
{
struct stap_probe *stap_probe = (struct stap_probe *) probe_generic;
- struct gdbarch *gdbarch = get_objfile_arch (stap_probe->p.objfile);
+ struct gdbarch *gdbarch = stap_probe->p.arch;
/* For SystemTap probes, we have to guarantee that the method
stap_is_single_operand is defined on gdbarch. If it is not, then it
}
/* Destroy (free) the data related to PROBE. PROBE memory itself is not feed
- as it is allocated from OBJFILE_OBSTACK. */
+ as it is allocated on an obstack. */
static void
stap_probe_destroy (struct probe *probe_generic)
struct frame_info *frame = get_selected_frame (_("No frame selected"));
CORE_ADDR pc = get_frame_pc (frame);
int sel = (int) (uintptr_t) data;
- struct probe *pc_probe;
+ struct bound_probe pc_probe;
const struct sym_probe_fns *pc_probe_fns;
unsigned n_args;
gdb_assert (sel >= -1);
pc_probe = find_probe_by_pc (pc);
- if (pc_probe == NULL)
+ 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, frame);
+ n_args = get_probe_argument_count (pc_probe.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, frame);
+ return evaluate_probe_argument (pc_probe.probe, sel, frame);
}
/* This is called to compile one of the $_probe_arg* convenience
{
CORE_ADDR pc = expr->scope;
int sel = (int) (uintptr_t) data;
- struct probe *pc_probe;
+ struct bound_probe pc_probe;
const struct sym_probe_fns *pc_probe_fns;
int n_args;
struct frame_info *frame = get_selected_frame (NULL);
gdb_assert (sel >= -1);
pc_probe = find_probe_by_pc (pc);
- if (pc_probe == NULL)
+ 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, frame);
+ n_args = get_probe_argument_count (pc_probe.probe, frame);
if (sel == -1)
{
error (_("Invalid probe argument %d -- probe has %d arguments available"),
sel, n_args);
- pc_probe->pops->compile_to_ax (pc_probe, expr, value, sel);
+ pc_probe.probe->pops->compile_to_ax (pc_probe.probe, expr, value, sel);
}
\f
the probes, but that is too rare to care. */
static void
-stap_set_semaphore (struct probe *probe_generic, struct gdbarch *gdbarch)
+stap_set_semaphore (struct probe *probe_generic, struct objfile *objfile,
+ struct gdbarch *gdbarch)
{
struct stap_probe *probe = (struct stap_probe *) probe_generic;
+ CORE_ADDR addr;
gdb_assert (probe_generic->pops == &stap_probe_ops);
- stap_modify_semaphore (probe->sem_addr, 1, gdbarch);
+ addr = (probe->sem_addr
+ + ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile)));
+ stap_modify_semaphore (addr, 1, gdbarch);
}
/* Clear a SystemTap semaphore. SEM is the semaphore's address. */
static void
-stap_clear_semaphore (struct probe *probe_generic, struct gdbarch *gdbarch)
+stap_clear_semaphore (struct probe *probe_generic, struct objfile *objfile,
+ struct gdbarch *gdbarch)
{
struct stap_probe *probe = (struct stap_probe *) probe_generic;
+ CORE_ADDR addr;
gdb_assert (probe_generic->pops == &stap_probe_ops);
- stap_modify_semaphore (probe->sem_addr, 0, gdbarch);
+ addr = (probe->sem_addr
+ + ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile)));
+ stap_modify_semaphore (addr, 0, gdbarch);
}
/* Implementation of `$_probe_arg*' set of variables. */
const char *probe_args = NULL;
struct stap_probe *ret;
- ret = obstack_alloc (&objfile->objfile_obstack, sizeof (*ret));
+ ret = obstack_alloc (&objfile->per_bfd->storage_obstack, sizeof (*ret));
ret->p.pops = &stap_probe_ops;
- ret->p.objfile = objfile;
+ 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);
/* Making sure there is a name. */
- if (!ret->p.name)
+ if (ret->p.name == NULL)
{
complaint (&symfile_complaints, _("corrupt probe name when "
"reading `%s'"),
/* Semaphore address. */
ret->sem_addr = extract_typed_address (&el->data[2 * size], ptr_type);
- ret->p.address += (ANOFFSET (objfile->section_offsets,
- SECT_OFF_TEXT (objfile))
- + base - base_ref);
- if (ret->sem_addr)
- ret->sem_addr += (ANOFFSET (objfile->section_offsets,
- SECT_OFF_DATA (objfile))
- + base - base_ref);
+ ret->p.address += base - base_ref;
+ if (ret->sem_addr != 0)
+ ret->sem_addr += base - base_ref;
/* Arguments. We can only extract the argument format if there is a valid
name for this probe. */
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. */
}
}
-static void
-stap_relocate (struct probe *probe_generic, CORE_ADDR delta)
-{
- struct stap_probe *probe = (struct stap_probe *) probe_generic;
-
- gdb_assert (probe_generic->pops == &stap_probe_ops);
-
- probe->p.address += delta;
- if (probe->sem_addr)
- probe->sem_addr += delta;
-}
-
static int
stap_probe_is_linespec (const char **linespecp)
{
gdb_assert (probe_generic->pops == &stap_probe_ops);
- gdbarch = get_objfile_arch (probe->p.objfile);
+ gdbarch = probe->p.arch;
- 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);
{
stap_probe_is_linespec,
stap_get_probes,
- stap_relocate,
+ stap_get_probe_address,
stap_get_probe_argument_count,
stap_can_evaluate_probe_arguments,
stap_evaluate_probe_argument,