#include "ax.h"
#include "ax-gdb.h"
#include "memrange.h"
+#include "exceptions.h"
+#include "cli/cli-utils.h"
/* readline include files */
#include "readline/readline.h"
extern int hex2bin (const char *hex, gdb_byte *bin, int count);
extern int bin2hex (const gdb_byte *bin, char *hex, int count);
-extern void stop_tracing ();
-
/* Maximum length of an agent aexpression.
This accounts for the fact that packets are limited to 400 bytes
(which includes everything -- including the checksum), and assumes
large. (400 - 31)/2 == 184 */
#define MAX_AGENT_EXPR_LEN 184
+#define TFILE_PID (1)
+
/* A hook used to notify the UI of tracepoint operations. */
void (*deprecated_trace_find_hook) (char *arg, int from_tty);
};
struct trace_status *
-current_trace_status ()
+current_trace_status (void)
{
return &trace_status;
}
}
}
-/* Free and and clear the traceframe info cache of the current
+/* Free and clear the traceframe info cache of the current
traceframe. */
static void
{
CORE_ADDR trace_pc;
- if (trace_frame == NULL) /* Cease debugging any trace buffers. */
+ /* Save as globals for internal use. */
+ if (trace_frame != NULL
+ && get_frame_pc_if_available (trace_frame, &trace_pc))
+ {
+ traceframe_sal = find_pc_line (trace_pc, 0);
+ traceframe_fun = find_pc_function (trace_pc);
+
+ /* Save linenumber as "$trace_line", a debugger variable visible to
+ users. */
+ set_internalvar_integer (lookup_internalvar ("trace_line"),
+ traceframe_sal.line);
+ }
+ else
{
- traceframe_fun = 0;
- traceframe_sal.pc = traceframe_sal.line = 0;
- traceframe_sal.symtab = NULL;
- clear_internalvar (lookup_internalvar ("trace_func"));
- clear_internalvar (lookup_internalvar ("trace_file"));
+ init_sal (&traceframe_sal);
+ traceframe_fun = NULL;
set_internalvar_integer (lookup_internalvar ("trace_line"), -1);
- return;
}
- /* Save as globals for internal use. */
- trace_pc = get_frame_pc (trace_frame);
- traceframe_sal = find_pc_line (trace_pc, 0);
- traceframe_fun = find_pc_function (trace_pc);
-
- /* Save linenumber as "$trace_line", a debugger variable visible to
- users. */
- set_internalvar_integer (lookup_internalvar ("trace_line"),
- traceframe_sal.line);
-
/* Save func name as "$trace_func", a debugger variable visible to
users. */
if (traceframe_fun == NULL
int ix;
int count = 0;
struct cleanup *back_to;
+ struct ui_out *uiout = current_uiout;
if (VEC_length (tsv_s, tvariables) == 0 && !ui_out_is_mi_like_p (uiout))
{
error (_("This command can only be used in a tracepoint actions list."));
}
+/* Parse any collection options, such as /s for strings. */
+
+char *
+decode_agent_options (char *exp)
+{
+ struct value_print_options opts;
+
+ if (*exp != '/')
+ return exp;
+
+ /* Call this to borrow the print elements default for collection
+ size. */
+ get_user_print_options (&opts);
+
+ exp++;
+ if (*exp == 's')
+ {
+ if (target_supports_string_tracing ())
+ {
+ /* Allow an optional decimal number giving an explicit maximum
+ string length, defaulting it to the "print elements" value;
+ so "collect/s80 mystr" gets at most 80 bytes of string. */
+ trace_string_kludge = opts.print_max;
+ exp++;
+ if (*exp >= '0' && *exp <= '9')
+ trace_string_kludge = atoi (exp);
+ while (*exp >= '0' && *exp <= '9')
+ exp++;
+ }
+ else
+ error (_("Target does not support \"/s\" option for string tracing."));
+ }
+ else
+ error (_("Undefined collection format \"%c\"."), *exp);
+
+ exp = skip_spaces (exp);
+
+ return exp;
+}
+
/* Enter a list of actions for a tracepoint. */
static void
trace_actions_command (char *args, int from_tty)
{
- struct breakpoint *t;
+ struct tracepoint *t;
struct command_line *l;
- t = get_tracepoint_by_number (&args, 0, 1);
+ t = get_tracepoint_by_number (&args, NULL, 1);
if (t)
{
char *tmpbuf =
xstrprintf ("Enter actions for tracepoint %d, one per line.",
- t->number);
+ t->base.number);
struct cleanup *cleanups = make_cleanup (xfree, tmpbuf);
l = read_command_lines (tmpbuf, from_tty, 1,
check_tracepoint_command, t);
do_cleanups (cleanups);
- breakpoint_set_commands (t, l);
+ breakpoint_set_commands (&t->base, l);
}
/* else just return */
}
/* worker function */
void
-validate_actionline (char **line, struct breakpoint *t)
+validate_actionline (char **line, struct breakpoint *b)
{
struct cmd_list_element *c;
struct expression *exp = NULL;
char *p, *tmp_p;
struct bp_location *loc;
struct agent_expr *aexpr;
+ struct tracepoint *t = (struct tracepoint *) b;
/* If EOF is typed, *line is NULL. */
if (*line == NULL)
if (cmd_cfunc_eq (c, collect_pseudocommand))
{
+ trace_string_kludge = 0;
+ if (*p == '/')
+ p = decode_agent_options (p);
+
do
{ /* Repeat over a comma-separated list. */
QUIT; /* Allow user to bail out with ^C. */
if (0 == strncasecmp ("reg", p + 1, 3)
|| 0 == strncasecmp ("arg", p + 1, 3)
|| 0 == strncasecmp ("loc", p + 1, 3)
+ || 0 == strncasecmp ("_ret", p + 1, 4)
|| 0 == strncasecmp ("_sdata", p + 1, 6))
{
p = strchr (p, ',');
/* else fall thru, treat p as an expression and parse it! */
}
tmp_p = p;
- for (loc = t->loc; loc; loc = loc->next)
+ for (loc = t->base.loc; loc; loc = loc->next)
{
p = tmp_p;
exp = parse_exp_1 (&p, block_for_pc (loc->address), 1);
p++;
tmp_p = p;
- for (loc = t->loc; loc; loc = loc->next)
+ for (loc = t->base.loc; loc; loc = loc->next)
{
p = tmp_p;
/* Only expressions are allowed for this action. */
block = block_for_pc (pc);
if (block == NULL)
{
- warning (_("Can't collect args; no symbol table info available.\n"));
+ warning (_("Can't collect args; no symbol table info available."));
return;
}
if (cmd_cfunc_eq (cmd, collect_pseudocommand))
{
+ trace_string_kludge = 0;
+ if (*action_exp == '/')
+ action_exp = decode_agent_options (action_exp);
+
do
{ /* Repeat over a comma-separated list. */
QUIT; /* Allow user to bail out with ^C. */
'L');
action_exp = strchr (action_exp, ','); /* more? */
}
+ else if (0 == strncasecmp ("$_ret", action_exp, 5))
+ {
+ struct cleanup *old_chain1 = NULL;
+
+ aexpr = gen_trace_for_return_address (tloc->address,
+ t->gdbarch);
+
+ old_chain1 = make_cleanup_free_agent_expr (aexpr);
+
+ ax_reqs (aexpr);
+ report_agent_reqs_errors (aexpr);
+
+ discard_cleanups (old_chain1);
+ add_aexpr (collect, aexpr);
+
+ /* take care of the registers */
+ if (aexpr->reg_mask_len > 0)
+ {
+ int ndx1, ndx2;
+
+ for (ndx1 = 0; ndx1 < aexpr->reg_mask_len; ndx1++)
+ {
+ QUIT; /* allow user to bail out with ^C */
+ if (aexpr->reg_mask[ndx1] != 0)
+ {
+ /* assume chars have 8 bits */
+ for (ndx2 = 0; ndx2 < 8; ndx2++)
+ if (aexpr->reg_mask[ndx1] & (1 << ndx2))
+ /* it's used -- record it */
+ add_register (collect,
+ ndx1 * 8 + ndx2);
+ }
+ }
+ }
+
+ action_exp = strchr (action_exp, ','); /* more? */
+ }
else if (0 == strncasecmp ("$_sdata", action_exp, 7))
{
add_static_trace_data (collect);
{
VEC(breakpoint_p) *tp_vec = NULL;
int ix;
- struct breakpoint *t;
+ struct breakpoint *b;
struct trace_state_variable *tsv;
int any_enabled = 0, num_to_download = 0;
error (_("No tracepoints defined, not starting trace"));
}
- for (ix = 0; VEC_iterate (breakpoint_p, tp_vec, ix, t); ix++)
+ for (ix = 0; VEC_iterate (breakpoint_p, tp_vec, ix, b); ix++)
{
- if (t->enable_state == bp_enabled)
+ struct tracepoint *t = (struct tracepoint *) b;
+
+ if (b->enable_state == bp_enabled)
any_enabled = 1;
- if ((t->type == bp_fast_tracepoint
+ if ((b->type == bp_fast_tracepoint
? may_insert_fast_tracepoints
: may_insert_tracepoints))
++num_to_download;
else
warning (_("May not insert %stracepoints, skipping tracepoint %d"),
- (t->type == bp_fast_tracepoint ? "fast " : ""), t->number);
+ (b->type == bp_fast_tracepoint ? "fast " : ""), b->number);
}
- /* No point in tracing with only disabled tracepoints. */
if (!any_enabled)
{
- VEC_free (breakpoint_p, tp_vec);
- error (_("No tracepoints enabled, not starting trace"));
+ if (target_supports_enable_disable_tracepoint ())
+ warning (_("No tracepoints enabled"));
+ else
+ {
+ /* No point in tracing with only disabled tracepoints that
+ cannot be re-enabled. */
+ VEC_free (breakpoint_p, tp_vec);
+ error (_("No tracepoints enabled, not starting trace"));
+ }
}
if (num_to_download <= 0)
target_trace_init ();
- for (ix = 0; VEC_iterate (breakpoint_p, tp_vec, ix, t); ix++)
+ for (ix = 0; VEC_iterate (breakpoint_p, tp_vec, ix, b); ix++)
{
- if ((t->type == bp_fast_tracepoint
+ struct tracepoint *t = (struct tracepoint *) b;
+ struct bp_location *loc;
+
+ if ((b->type == bp_fast_tracepoint
? !may_insert_fast_tracepoints
: !may_insert_tracepoints))
continue;
t->number_on_target = 0;
- target_download_tracepoint (t);
- t->number_on_target = t->number;
+
+ for (loc = b->loc; loc; loc = loc->next)
+ {
+ /* Since tracepoint locations are never duplicated, `inserted'
+ flag should be zero. */
+ gdb_assert (!loc->inserted);
+
+ target_download_tracepoint (loc);
+
+ loc->inserted = 1;
+ }
+
+ t->number_on_target = b->number;
}
VEC_free (breakpoint_p, tp_vec);
void
trace_status_mi (int on_stop)
{
+ struct ui_out *uiout = current_uiout;
struct trace_status *ts = current_trace_status ();
int status;
{
int target_frameno = -1, target_tracept = -1;
struct frame_id old_frame_id = null_frame_id;
- struct breakpoint *tp;
+ struct tracepoint *tp;
+ struct ui_out *uiout = current_uiout;
/* Only try to get the current stack frame if we have a chance of
succeeding. In particular, if we're trying to get a first trace
target_dcache_invalidate ();
set_traceframe_num (target_frameno);
clear_traceframe_info ();
- set_tracepoint_num (tp ? tp->number : target_tracept);
+ set_tracepoint_num (tp ? tp->base.number : target_tracept);
if (target_frameno == -1)
set_traceframe_context (NULL);
else
trace_find_tracepoint_command (char *args, int from_tty)
{
int tdp;
- struct breakpoint *tp;
+ struct tracepoint *tp;
if (current_trace_status ()->running && !current_trace_status ()->from_file)
error (_("May not look at trace frames while trace is running."));
struct symbol *sym;
struct minimal_symbol *msym;
struct block *block;
- char **canonical, *symname, *save_args = args;
+ char *symname, *save_args = args;
struct dict_iterator iter;
int j, count = 0;
struct gdbarch *gdbarch;
error (_("requires an argument (function, "
"line or *addr) to define a scope"));
- sals = decode_line_1 (&args, 1, NULL, 0, &canonical, NULL);
+ sals = decode_line_1 (&args, 1, NULL, 0, NULL);
if (sals.nelts == 0)
return; /* Presumably decode_line_1 has already warned. */
STEPPING_ACTIONS should be equal. */
if (stepping_frame == stepping_actions)
{
+ if (*action_exp == '/')
+ action_exp = decode_agent_options (action_exp);
+
do
{ /* Repeat over a comma-separated list. */
QUIT; /* Allow user to bail out with ^C. */
if (0 == strncasecmp (action_exp, "$reg", 4))
registers_info (NULL, from_tty);
+ else if (0 == strncasecmp (action_exp, "$_ret", 5))
+ ;
else if (0 == strncasecmp (action_exp, "$loc", 4))
locals_info (NULL, from_tty);
else if (0 == strncasecmp (action_exp, "$arg", 4))
trace_dump_command (char *args, int from_tty)
{
struct regcache *regcache;
- struct breakpoint *t;
+ struct tracepoint *t;
int stepping_frame = 0;
struct bp_location *loc;
char *line, *default_collect_line = NULL;
frame. (FIXME this is not reliable, should record each frame's
type.) */
stepping_frame = 1;
- for (loc = t->loc; loc; loc = loc->next)
+ for (loc = t->base.loc; loc; loc = loc->next)
if (loc->address == regcache_read_pc (regcache))
stepping_frame = 0;
- actions = breakpoint_commands (t);
+ actions = breakpoint_commands (&t->base);
/* If there is a default-collect list, make up a collect command,
prepend to the tracepoint's commands, and pass the whole mess to
default_collect_line = xstrprintf ("collect %s", default_collect);
old_chain = make_cleanup (xfree, default_collect_line);
line = default_collect_line;
- validate_actionline (&line, t);
+ validate_actionline (&line, &t->base);
default_collect_action = xmalloc (sizeof (struct command_line));
make_cleanup (xfree, default_collect_action);
default_collect_action->next = actions;
trace_save (filename, target_does_save);
if (from_tty)
- printf_filtered (_("Trace data saved to file '%s'.\n"), args);
+ printf_filtered (_("Trace data saved to file '%s'.\n"), filename);
do_cleanups (back_to);
}
}
}
+/* FIXME this function is heuristic and will miss the cases where the
+ conditional is semantically identical but differs in whitespace,
+ such as "x == 0" vs "x==0". */
+
+static int
+cond_string_is_same (char *str1, char *str2)
+{
+ if (str1 == NULL || str2 == NULL)
+ return (str1 == str2);
+
+ return (strcmp (str1, str2) == 0);
+}
+
/* Look for an existing tracepoint that seems similar enough to the
uploaded one. Enablement isn't compared, because the user can
toggle that freely, and may have done so in anticipation of the
- next trace run. */
+ next trace run. Return the location of matched tracepoint. */
-struct breakpoint *
-find_matching_tracepoint (struct uploaded_tp *utp)
+struct bp_location *
+find_matching_tracepoint_location (struct uploaded_tp *utp)
{
VEC(breakpoint_p) *tp_vec = all_tracepoints ();
int ix;
- struct breakpoint *t;
+ struct breakpoint *b;
struct bp_location *loc;
- for (ix = 0; VEC_iterate (breakpoint_p, tp_vec, ix, t); ix++)
+ for (ix = 0; VEC_iterate (breakpoint_p, tp_vec, ix, b); ix++)
{
- if (t->type == utp->type
+ struct tracepoint *t = (struct tracepoint *) b;
+
+ if (b->type == utp->type
&& t->step_count == utp->step
&& t->pass_count == utp->pass
- /* FIXME also test conditionals and actions. */
+ && cond_string_is_same (t->base.cond_string, utp->cond_string)
+ /* FIXME also test actions. */
)
{
/* Scan the locations for an address match. */
- for (loc = t->loc; loc; loc = loc->next)
+ for (loc = b->loc; loc; loc = loc->next)
{
if (loc->address == utp->addr)
- return t;
+ return loc;
}
}
}
merge_uploaded_tracepoints (struct uploaded_tp **uploaded_tps)
{
struct uploaded_tp *utp;
- struct breakpoint *t;
/* Look for GDB tracepoints that match up with our uploaded versions. */
for (utp = *uploaded_tps; utp; utp = utp->next)
{
- t = find_matching_tracepoint (utp);
- if (t)
- printf_filtered (_("Assuming tracepoint %d is same "
- "as target's tracepoint %d at %s.\n"),
- t->number, utp->number,
- paddress (get_current_arch (), utp->addr));
+ struct bp_location *loc;
+ struct tracepoint *t;
+
+ loc = find_matching_tracepoint_location (utp);
+ if (loc)
+ {
+ /* Mark this location as already inserted. */
+ loc->inserted = 1;
+ t = (struct tracepoint *) loc->owner;
+ printf_filtered (_("Assuming tracepoint %d is same "
+ "as target's tracepoint %d at %s.\n"),
+ loc->owner->number, utp->number,
+ paddress (loc->gdbarch, utp->addr));
+ }
else
{
t = create_tracepoint_from_upload (utp);
if (t)
printf_filtered (_("Created tracepoint %d for "
"target's tracepoint %d at %s.\n"),
- t->number, utp->number,
+ t->base.number, utp->number,
paddress (get_current_arch (), utp->addr));
else
printf_filtered (_("Failed to create tracepoint for target's "
sprintf (buf, "%s_%d", namebase, try_num++);
/* We have an available name, create the variable. */
- tsv = create_trace_state_variable (xstrdup (buf));
+ tsv = create_trace_state_variable (buf);
tsv->initial_value = utsv->initial_value;
tsv->builtin = utsv->builtin;
static void
tfile_open (char *filename, int from_tty)
{
+ volatile struct gdb_exception ex;
char *temp;
struct cleanup *old_chain;
int flags;
discard_cleanups (old_chain); /* Don't free filename any more. */
unpush_target (&tfile_ops);
- push_target (&tfile_ops);
-
trace_filename = xstrdup (filename);
trace_fd = scratch_chan;
&& (strncmp (header + 1, "TRACE0\n", 7) == 0)))
error (_("File is not a valid trace file."));
+ push_target (&tfile_ops);
+
trace_regblock_size = 0;
ts = current_trace_status ();
/* We know we're working with a file. */
cur_traceframe_number = -1;
- /* Read through a section of newline-terminated lines that
- define things like tracepoints. */
- i = 0;
- while (1)
+ TRY_CATCH (ex, RETURN_MASK_ALL)
{
- tfile_read (&byte, 1);
-
- ++bytes;
- if (byte == '\n')
+ /* Read through a section of newline-terminated lines that
+ define things like tracepoints. */
+ i = 0;
+ while (1)
{
- /* Empty line marks end of the definition section. */
- if (i == 0)
- break;
- linebuf[i] = '\0';
- i = 0;
- tfile_interp_line (linebuf, &uploaded_tps, &uploaded_tsvs);
+ tfile_read (&byte, 1);
+
+ ++bytes;
+ if (byte == '\n')
+ {
+ /* Empty line marks end of the definition section. */
+ if (i == 0)
+ break;
+ linebuf[i] = '\0';
+ i = 0;
+ tfile_interp_line (linebuf, &uploaded_tps, &uploaded_tsvs);
+ }
+ else
+ linebuf[i++] = byte;
+ if (i >= 1000)
+ error (_("Excessively long lines in trace file"));
}
- else
- linebuf[i++] = byte;
- if (i >= 1000)
- error (_("Excessively long lines in trace file"));
+
+ /* Record the starting offset of the binary trace data. */
+ trace_frames_offset = bytes;
+
+ /* If we don't have a blocksize, we can't interpret the
+ traceframes. */
+ if (trace_regblock_size == 0)
+ error (_("No register block size recorded in trace file"));
+ }
+ if (ex.reason < 0)
+ {
+ /* Pop the partially set up target. */
+ pop_target ();
+ throw_exception (ex);
}
+ inferior_appeared (current_inferior (), TFILE_PID);
+ inferior_ptid = pid_to_ptid (TFILE_PID);
+ add_thread_silent (inferior_ptid);
+
+ if (ts->traceframe_count <= 0)
+ warning (_("No traceframes present in this file."));
+
/* Add the file's tracepoints and variables into the current mix. */
/* Get trace state variables first, they may be checked when parsing
merge_uploaded_tracepoints (&uploaded_tps);
- /* Record the starting offset of the binary trace data. */
- trace_frames_offset = bytes;
-
- /* If we don't have a blocksize, we can't interpret the
- traceframes. */
- if (trace_regblock_size == 0)
- error (_("No register block size recorded in trace file"));
- if (ts->traceframe_count <= 0)
- {
- warning (_("No traceframes present in this file."));
- return;
- }
-
-#define TFILE_PID (1)
- inferior_appeared (current_inferior (), TFILE_PID);
- inferior_ptid = pid_to_ptid (TFILE_PID);
- add_thread_silent (inferior_ptid);
-
post_create_inferior (&tfile_ops, from_tty);
-
-#if 0
- /* FIXME this will get defined in MI patch submission. */
- tfind_1 (tfind_number, 0, 0, 0, 0);
-#endif
}
/* Interpret the given line from the definitions part of the trace
close (trace_fd);
trace_fd = -1;
- if (trace_filename)
- xfree (trace_filename);
+ xfree (trace_filename);
+ trace_filename = NULL;
}
static void
{
ULONGEST addr = 0;
short tpnum;
- struct breakpoint *tp;
+ struct tracepoint *tp;
off_t saved_offset = cur_offset;
/* FIXME dig pc out of collected registers. */
tp = get_tracepoint_by_number_on_target (tpnum);
/* FIXME this is a poor heuristic if multiple locations. */
- if (tp && tp->loc)
- addr = tp->loc->address;
+ if (tp && tp->base.loc)
+ addr = tp->base.loc->address;
/* Restore our seek position. */
cur_offset = saved_offset;
short tpnum;
int tfnum = 0, found = 0;
unsigned int data_size;
- struct breakpoint *tp;
+ struct tracepoint *tp;
off_t offset, tframe_offset;
ULONGEST tfaddr;
first. */
if (type != tfind_number)
set_tfile_traceframe ();
+ else if (num == -1)
+ {
+ if (tpp)
+ *tpp = -1;
+ return -1;
+ }
lseek (trace_fd, trace_frames_offset, SEEK_SET);
offset = trace_frames_offset;
pc_regno = gdbarch_pc_regnum (gdbarch);
if (pc_regno >= 0 && (regno == -1 || regno == pc_regno))
{
- struct breakpoint *tp = get_tracepoint (tracepoint_number);
+ struct tracepoint *tp = get_tracepoint (tracepoint_number);
- if (tp && tp->loc)
+ if (tp && tp->base.loc)
{
/* But don't try to guess if tracepoint is multi-location... */
- if (tp->loc->next)
+ if (tp->base.loc->next)
{
warning (_("Tracepoint %d has multiple "
"locations, cannot infer $pc"),
- tp->number);
+ tp->base.number);
return;
}
/* ... or does while-stepping. */
{
warning (_("Tracepoint %d does while-stepping, "
"cannot infer $pc"),
- tp->number);
+ tp->base.number);
return;
}
store_unsigned_integer (regs, register_size (gdbarch, pc_regno),
gdbarch_byte_order (gdbarch),
- tp->loc->address);
+ tp->base.loc->address);
regcache_raw_supply (regcache, pc_regno, regs);
}
}
return traceframe_number != -1;
}
+static int
+tfile_thread_alive (struct target_ops *ops, ptid_t ptid)
+{
+ return 1;
+}
+
/* Callback for traceframe_walk_blocks. Builds a traceframe_info
object for the tfile target's current traceframe. */
tfile_ops.to_has_stack = tfile_has_stack;
tfile_ops.to_has_registers = tfile_has_registers;
tfile_ops.to_traceframe_info = tfile_traceframe_info;
+ tfile_ops.to_thread_alive = tfile_thread_alive;
tfile_ops.to_magic = OPS_MAGIC;
}
char wrap_indent[80];
char extra_field_indent[80];
+ struct ui_out *uiout = current_uiout;
struct ui_stream *stb = ui_out_stream_new (uiout);
struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb);
struct cleanup *bkpt_chain;
VEC(static_tracepoint_marker_p) *markers;
struct cleanup *old_chain;
struct static_tracepoint_marker *marker;
+ struct ui_out *uiout = current_uiout;
int i;
old_chain