along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "defs.h"
+#include "arch-utils.h"
#include "symtab.h"
#include "frame.h"
#include "gdbtypes.h"
#include "breakpoint.h"
#include "tracepoint.h"
#include "remote.h"
+extern int remote_supports_cond_tracepoints (void);
+extern char *unpack_varlen_hex (char *buff, ULONGEST *result);
#include "linespec.h"
#include "regcache.h"
#include "completer.h"
large. (400 - 31)/2 == 184 */
#define MAX_AGENT_EXPR_LEN 184
+/* A hook used to notify the UI of tracepoint operations. */
+
+void (*deprecated_trace_find_hook) (char *arg, int from_tty);
+void (*deprecated_trace_start_stop_hook) (int start, int from_tty);
extern void (*deprecated_readline_begin_hook) (char *, ...);
extern char *(*deprecated_readline_hook) (char *);
/* ======= Important global variables: ======= */
+/* The list of all trace state variables. We don't retain pointers to
+ any of these for any reason - API is by name or number only - so it
+ works to have a vector of objects. */
+
+typedef struct trace_state_variable tsv_s;
+DEF_VEC_O(tsv_s);
+
+static VEC(tsv_s) *tvariables;
+
+/* The next integer to assign to a variable. */
+
+static int next_tsv_number = 1;
+
/* Number of last traceframe collected. */
static int traceframe_number;
/* Tracing command lists */
static struct cmd_list_element *tfindlist;
+/* List of expressions to collect by default at each tracepoint hit. */
+static char *default_collect = "";
+
+static char *target_buf;
+static long target_buf_size;
+
/* ======= Important command functions: ======= */
static void trace_actions_command (char *, int);
static void trace_start_command (char *, int);
{
CORE_ADDR trace_pc;
- static struct type *func_string, *file_string;
- static struct type *func_range, *file_range;
- struct value *func_val;
- struct value *file_val;
- int len;
-
if (trace_frame == NULL) /* Cease debugging any trace buffers. */
{
traceframe_fun = 0;
|| SYMBOL_LINKAGE_NAME (traceframe_fun) == NULL)
clear_internalvar (lookup_internalvar ("trace_func"));
else
- {
- len = strlen (SYMBOL_LINKAGE_NAME (traceframe_fun));
- func_range = create_range_type (func_range,
- builtin_type_int32, 0, len - 1);
- func_string = create_array_type (func_string,
- builtin_type_true_char, func_range);
- func_val = allocate_value (func_string);
- deprecated_set_value_type (func_val, func_string);
- memcpy (value_contents_raw (func_val),
- SYMBOL_LINKAGE_NAME (traceframe_fun),
- len);
- deprecated_set_value_modifiable (func_val, 0);
- set_internalvar (lookup_internalvar ("trace_func"), func_val);
- }
+ set_internalvar_string (lookup_internalvar ("trace_func"),
+ SYMBOL_LINKAGE_NAME (traceframe_fun));
/* Save file name as "$trace_file", a debugger variable visible to
users. */
|| traceframe_sal.symtab->filename == NULL)
clear_internalvar (lookup_internalvar ("trace_file"));
else
+ set_internalvar_string (lookup_internalvar ("trace_file"),
+ traceframe_sal.symtab->filename);
+}
+
+/* Create a new trace state variable with the given name. */
+
+struct trace_state_variable *
+create_trace_state_variable (const char *name)
+{
+ struct trace_state_variable tsv;
+
+ memset (&tsv, 0, sizeof (tsv));
+ tsv.name = name;
+ tsv.number = next_tsv_number++;
+ return VEC_safe_push (tsv_s, tvariables, &tsv);
+}
+
+/* Look for a trace state variable of the given name. */
+
+struct trace_state_variable *
+find_trace_state_variable (const char *name)
+{
+ struct trace_state_variable *tsv;
+ int ix;
+
+ for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix)
+ if (strcmp (name, tsv->name) == 0)
+ return tsv;
+
+ return NULL;
+}
+
+void
+delete_trace_state_variable (const char *name)
+{
+ struct trace_state_variable *tsv;
+ int ix;
+
+ for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix)
+ if (strcmp (name, tsv->name) == 0)
+ {
+ VEC_unordered_remove (tsv_s, tvariables, ix);
+ return;
+ }
+
+ warning (_("No trace variable named \"$%s\", not deleting"), name);
+}
+
+/* The 'tvariable' command collects a name and optional expression to
+ evaluate into an initial value. */
+
+void
+trace_variable_command (char *args, int from_tty)
+{
+ struct expression *expr;
+ struct cleanup *old_chain;
+ struct internalvar *intvar = NULL;
+ LONGEST initval = 0;
+ struct trace_state_variable *tsv;
+
+ if (!args || !*args)
+ error_no_arg (_("trace state variable name"));
+
+ /* All the possible valid arguments are expressions. */
+ expr = parse_expression (args);
+ old_chain = make_cleanup (free_current_contents, &expr);
+
+ if (expr->nelts == 0)
+ error (_("No expression?"));
+
+ /* Only allow two syntaxes; "$name" and "$name=value". */
+ if (expr->elts[0].opcode == OP_INTERNALVAR)
+ {
+ intvar = expr->elts[1].internalvar;
+ }
+ else if (expr->elts[0].opcode == BINOP_ASSIGN
+ && expr->elts[1].opcode == OP_INTERNALVAR)
+ {
+ intvar = expr->elts[2].internalvar;
+ initval = value_as_long (evaluate_subexpression_type (expr, 4));
+ }
+ else
+ error (_("Syntax must be $NAME [ = EXPR ]"));
+
+ if (!intvar)
+ error (_("No name given"));
+
+ if (strlen (internalvar_name (intvar)) <= 0)
+ error (_("Must supply a non-empty variable name"));
+
+ /* If the variable already exists, just change its initial value. */
+ tsv = find_trace_state_variable (internalvar_name (intvar));
+ if (tsv)
{
- len = strlen (traceframe_sal.symtab->filename);
- file_range = create_range_type (file_range,
- builtin_type_int32, 0, len - 1);
- file_string = create_array_type (file_string,
- builtin_type_true_char, file_range);
- file_val = allocate_value (file_string);
- deprecated_set_value_type (file_val, file_string);
- memcpy (value_contents_raw (file_val),
- traceframe_sal.symtab->filename,
- len);
- deprecated_set_value_modifiable (file_val, 0);
- set_internalvar (lookup_internalvar ("trace_file"), file_val);
+ tsv->initial_value = initval;
+ printf_filtered (_("Trace state variable $%s now has initial value %s.\n"),
+ tsv->name, plongest (tsv->initial_value));
+ return;
+ }
+
+ /* Create a new variable. */
+ tsv = create_trace_state_variable (internalvar_name (intvar));
+ tsv->initial_value = initval;
+
+ printf_filtered (_("Trace state variable $%s created, with initial value %s.\n"),
+ tsv->name, plongest (tsv->initial_value));
+
+ do_cleanups (old_chain);
+}
+
+void
+delete_trace_variable_command (char *args, int from_tty)
+{
+ int i, ix;
+ char **argv;
+ struct cleanup *back_to;
+ struct trace_state_variable *tsv;
+
+ if (args == NULL)
+ {
+ if (query (_("Delete all trace state variables? ")))
+ VEC_free (tsv_s, tvariables);
+ dont_repeat ();
+ return;
+ }
+
+ argv = gdb_buildargv (args);
+ back_to = make_cleanup_freeargv (argv);
+
+ for (i = 0; argv[i] != NULL; i++)
+ {
+ if (*argv[i] == '$')
+ delete_trace_state_variable (argv[i] + 1);
+ else
+ warning (_("Name \"%s\" not prefixed with '$', ignoring"), argv[i]);
+ }
+
+ do_cleanups (back_to);
+
+ dont_repeat ();
+}
+
+/* List all the trace state variables. */
+
+static void
+tvariables_info (char *args, int from_tty)
+{
+ struct trace_state_variable *tsv;
+ int ix;
+ char *reply;
+ ULONGEST tval;
+
+ if (target_is_remote ())
+ {
+ char buf[20];
+
+ for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix)
+ {
+ /* We don't know anything about the value until we get a
+ valid packet. */
+ tsv->value_known = 0;
+ sprintf (buf, "qTV:%x", tsv->number);
+ putpkt (buf);
+ reply = remote_get_noisy_reply (&target_buf, &target_buf_size);
+ if (reply && *reply)
+ {
+ if (*reply == 'V')
+ {
+ unpack_varlen_hex (reply + 1, &tval);
+ tsv->value = (LONGEST) tval;
+ tsv->value_known = 1;
+ }
+ /* FIXME say anything about oddball replies? */
+ }
+ }
+ }
+
+ if (VEC_length (tsv_s, tvariables) == 0)
+ {
+ printf_filtered (_("No trace state variables.\n"));
+ return;
+ }
+
+ printf_filtered (_("Name\t\t Initial\tCurrent\n"));
+
+ for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix)
+ {
+ printf_filtered ("$%s", tsv->name);
+ print_spaces_filtered (17 - strlen (tsv->name), gdb_stdout);
+ printf_filtered ("%s ", plongest (tsv->initial_value));
+ print_spaces_filtered (11 - strlen (plongest (tsv->initial_value)), gdb_stdout);
+ if (tsv->value_known)
+ printf_filtered (" %s", plongest (tsv->value));
+ else if (trace_running_p || traceframe_number >= 0)
+ /* The value is/was defined, but we don't have it. */
+ printf_filtered (_(" <unknown>"));
+ else
+ /* It is not meaningful to ask about the value. */
+ printf_filtered (_(" <undefined>"));
+ printf_filtered ("\n");
}
}
static void
collect_symbol (struct collection_list *collect,
struct symbol *sym,
- long frame_regno, long frame_offset)
+ struct gdbarch *gdbarch,
+ long frame_regno, long frame_offset,
+ CORE_ADDR scope)
{
unsigned long len;
unsigned int reg;
add_memrange (collect, memrange_absolute, offset, len);
break;
case LOC_REGISTER:
- reg = SYMBOL_REGISTER_OPS (sym)->register_number (sym, current_gdbarch);
+ reg = SYMBOL_REGISTER_OPS (sym)->register_number (sym, gdbarch);
if (info_verbose)
printf_filtered ("LOC_REG[parm] %s: ",
SYMBOL_PRINT_NAME (sym));
/* Check for doubles stored in two registers. */
/* FIXME: how about larger types stored in 3 or more regs? */
if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_FLT &&
- len > register_size (current_gdbarch, reg))
+ len > register_size (gdbarch, reg))
add_register (collect, reg + 1);
break;
case LOC_REF_ARG:
printf_filtered ("%s has been optimized out of existence.\n",
SYMBOL_PRINT_NAME (sym));
break;
+
+ case LOC_COMPUTED:
+ {
+ struct agent_expr *aexpr;
+ struct cleanup *old_chain1 = NULL;
+ struct agent_reqs areqs;
+
+ aexpr = gen_trace_for_var (scope, sym);
+
+ old_chain1 = make_cleanup_free_agent_expr (aexpr);
+
+ ax_reqs (aexpr, &areqs);
+ if (areqs.flaw != agent_flaw_none)
+ error (_("malformed expression"));
+
+ if (areqs.min_height < 0)
+ error (_("gdb: Internal error: expression has min height < 0"));
+ if (areqs.max_height > 20)
+ error (_("expression too complicated, try simplifying"));
+
+ discard_cleanups (old_chain1);
+ add_aexpr (collect, aexpr);
+
+ /* take care of the registers */
+ if (areqs.reg_mask_len > 0)
+ {
+ int ndx1, ndx2;
+
+ for (ndx1 = 0; ndx1 < areqs.reg_mask_len; ndx1++)
+ {
+ QUIT; /* allow user to bail out with ^C */
+ if (areqs.reg_mask[ndx1] != 0)
+ {
+ /* assume chars have 8 bits */
+ for (ndx2 = 0; ndx2 < 8; ndx2++)
+ if (areqs.reg_mask[ndx1] & (1 << ndx2))
+ /* it's used -- record it */
+ add_register (collect,
+ ndx1 * 8 + ndx2);
+ }
+ }
+ }
+ }
+ break;
}
}
/* Add all locals (or args) symbols to collection list */
static void
-add_local_symbols (struct collection_list *collect, CORE_ADDR pc,
+add_local_symbols (struct collection_list *collect,
+ struct gdbarch *gdbarch, CORE_ADDR pc,
long frame_regno, long frame_offset, int type)
{
struct symbol *sym;
: type == 'L') /* collecting Locals */
{
count++;
- collect_symbol (collect, sym, frame_regno,
- frame_offset);
+ collect_symbol (collect, sym, gdbarch,
+ frame_regno, frame_offset, pc);
}
}
if (BLOCK_FUNCTION (block))
struct agent_expr *aexpr;
int frame_reg;
LONGEST frame_offset;
-
+ char *default_collect_line = NULL;
+ struct action_line *default_collect_action = NULL;
clear_collection_list (&tracepoint_list);
clear_collection_list (&stepping_list);
*tdp_actions = NULL;
*stepping_actions = NULL;
- gdbarch_virtual_frame_pointer (current_gdbarch,
+ gdbarch_virtual_frame_pointer (t->gdbarch,
t->loc->address, &frame_reg, &frame_offset);
- for (action = t->actions; action; action = action->next)
+ action = t->actions;
+
+ /* If there are default expressions to collect, make up a collect
+ action and prepend to the action list to encode. Note that since
+ validation is per-tracepoint (local var "xyz" might be valid for
+ one tracepoint and not another, etc), we make up the action on
+ the fly, and don't cache it. */
+ if (*default_collect)
+ {
+ char *line;
+ enum actionline_type linetype;
+
+ default_collect_line = xmalloc (12 + strlen (default_collect));
+ sprintf (default_collect_line, "collect %s", default_collect);
+ line = default_collect_line;
+ linetype = validate_actionline (&line, t);
+ if (linetype != BADLINE)
+ {
+ default_collect_action = xmalloc (sizeof (struct action_line));
+ default_collect_action->next = t->actions;
+ default_collect_action->action = line;
+ action = default_collect_action;
+ }
+ }
+
+ for (; action; action = action->next)
{
QUIT; /* allow user to bail out with ^C */
action_exp = action->action;
if (0 == strncasecmp ("$reg", action_exp, 4))
{
- for (i = 0; i < gdbarch_num_regs (current_gdbarch); i++)
+ for (i = 0; i < gdbarch_num_regs (t->gdbarch); i++)
add_register (collect, i);
action_exp = strchr (action_exp, ','); /* more? */
}
else if (0 == strncasecmp ("$arg", action_exp, 4))
{
add_local_symbols (collect,
+ t->gdbarch,
t->loc->address,
frame_reg,
frame_offset,
else if (0 == strncasecmp ("$loc", action_exp, 4))
{
add_local_symbols (collect,
+ t->gdbarch,
t->loc->address,
frame_reg,
frame_offset,
{
const char *name = &exp->elts[2].string;
- i = user_reg_map_name_to_regnum (current_gdbarch,
+ i = user_reg_map_name_to_regnum (t->gdbarch,
name, strlen (name));
if (i == -1)
internal_error (__FILE__, __LINE__,
case OP_VAR_VALUE:
collect_symbol (collect,
exp->elts[2].symbol,
+ t->gdbarch,
frame_reg,
- frame_offset);
+ frame_offset,
+ t->loc->address);
break;
default: /* full-fledged expression */
tdp_buff);
*stepping_actions = stringify_collection_list (&stepping_list,
step_buff);
+
+ xfree (default_collect_line);
+ xfree (default_collect_action);
}
static void
collect->next_aexpr_elt++;
}
-static char *target_buf;
-static long target_buf_size;
-
/* Set "transparent" memory ranges
Allow trace mechanism to treat text-like sections
static void
trace_start_command (char *args, int from_tty)
{
+ char buf[2048];
VEC(breakpoint_p) *tp_vec = NULL;
int ix;
struct breakpoint *t;
+ struct trace_state_variable *tsv;
dont_repeat (); /* Like "run", dangerous to repeat accidentally. */
}
VEC_free (breakpoint_p, tp_vec);
+ /* Init any trace state variables that start with nonzero values. */
+
+ for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix)
+ {
+ if (tsv->initial_value != 0)
+ {
+ sprintf (buf, "QTDV:%x:%s",
+ tsv->number, phex ((ULONGEST) tsv->initial_value, 8));
+ putpkt (buf);
+ remote_get_noisy_reply (&target_buf, &target_buf_size);
+ }
+ }
+
/* Tell target to treat text-like sections as transparent. */
remote_set_transparent_ranges ();
/* Now insert traps and begin collecting data. */
char **stepping_actions;
int ndx;
struct cleanup *old_chain = NULL;
+ struct agent_expr *aexpr;
+ struct cleanup *aexpr_chain = NULL;
sprintf_vma (tmp, (t->loc ? t->loc->address : 0));
sprintf (buf, "QTDP:%x:%s:%c:%lx:%x", t->number,
tmp, /* address */
(t->enable_state == bp_enabled ? 'E' : 'D'),
t->step_count, t->pass_count);
+ /* If the tracepoint has a conditional, make it into an agent
+ expression and append to the definition. */
+ if (t->loc->cond)
+ {
+ /* Only test support at download time, we may not know target
+ capabilities at definition time. */
+ if (remote_supports_cond_tracepoints ())
+ {
+ aexpr = gen_eval_for_expr (t->loc->address, t->loc->cond);
+ aexpr_chain = make_cleanup_free_agent_expr (aexpr);
+ sprintf (buf + strlen (buf), ":X%x,", aexpr->len);
+ mem2hex (aexpr->buf, buf + strlen (buf), aexpr->len);
+ do_cleanups (aexpr_chain);
+ }
+ else
+ warning (_("Target does not support conditional tracepoints, ignoring tp %d cond"), t->number);
+ }
- if (t->actions)
+ if (t->actions || *default_collect)
strcat (buf, "-");
putpkt (buf);
remote_get_noisy_reply (&target_buf, &target_buf_size);
if (strcmp (target_buf, "OK"))
error (_("Target does not support tracepoints."));
- if (!t->actions)
+ if (!t->actions && !*default_collect)
return;
encode_actions (t, &tdp_actions, &stepping_actions);
old_chain = make_cleanup (xfree, sals.sals);
if (sal.symtab == 0)
{
+ struct gdbarch *gdbarch = get_current_arch ();
+
printf_filtered ("TFIND: No line number information available");
if (sal.pc != 0)
{
have the symbolic address. */
printf_filtered (" for address ");
wrap_here (" ");
- print_address (sal.pc, gdb_stdout);
+ print_address (gdbarch, sal.pc, gdb_stdout);
printf_filtered (";\n -- will attempt to find by PC. \n");
}
else
else if (sal.line > 0
&& find_line_pc_range (sal, &start_pc, &end_pc))
{
+ struct gdbarch *gdbarch = get_objfile_arch (sal.symtab->objfile);
+
if (start_pc == end_pc)
{
printf_filtered ("Line %d of \"%s\"",
sal.line, sal.symtab->filename);
wrap_here (" ");
printf_filtered (" is at address ");
- print_address (start_pc, gdb_stdout);
+ print_address (gdbarch, start_pc, gdb_stdout);
wrap_here (" ");
printf_filtered (" but contains no code.\n");
sal = find_pc_line (start_pc, 0);
break;
case LOC_STATIC:
printf_filtered ("in static storage at address ");
- printf_filtered ("%s", paddress (SYMBOL_VALUE_ADDRESS (sym)));
+ printf_filtered ("%s", paddress (gdbarch,
+ SYMBOL_VALUE_ADDRESS (sym)));
break;
case LOC_REGISTER:
/* GDBARCH is the architecture associated with the objfile
continue;
case LOC_LABEL:
printf_filtered ("a label at address ");
- printf_filtered ("%s", paddress (SYMBOL_VALUE_ADDRESS (sym)));
+ printf_filtered ("%s", paddress (gdbarch,
+ SYMBOL_VALUE_ADDRESS (sym)));
break;
case LOC_BLOCK:
printf_filtered ("a function at address ");
- printf_filtered ("%s", paddress (BLOCK_START (SYMBOL_BLOCK_VALUE (sym))));
+ printf_filtered ("%s",
+ paddress (gdbarch, BLOCK_START (SYMBOL_BLOCK_VALUE (sym))));
break;
case LOC_UNRESOLVED:
msym = lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (sym),
else
{
printf_filtered ("static storage at address ");
- printf_filtered ("%s", paddress (SYMBOL_VALUE_ADDRESS (msym)));
+ printf_filtered ("%s",
+ paddress (gdbarch, SYMBOL_VALUE_ADDRESS (msym)));
}
break;
case LOC_OPTIMIZED_OUT:
add_com ("tdump", class_trace, trace_dump_command,
_("Print everything collected at the current tracepoint."));
+ c = add_com ("tvariable", class_trace, trace_variable_command,_("\
+Define a trace state variable.\n\
+Argument is a $-prefixed name, optionally followed\n\
+by '=' and an expression that sets the initial value\n\
+at the start of tracing."));
+ set_cmd_completer (c, expression_completer);
+
+ add_cmd ("tvariable", class_trace, delete_trace_variable_command, _("\
+Delete one or more trace state variables.\n\
+Arguments are the names of the variables to delete.\n\
+If no arguments are supplied, delete all variables."), &deletelist);
+ /* FIXME add a trace variable completer */
+
+ add_info ("tvariables", tvariables_info, _("\
+Status of trace state variables and their values.\n\
+"));
+
add_prefix_cmd ("tfind", class_trace, trace_find_command, _("\
Select a trace frame;\n\
No argument means forward by one frame; '-' means backward by one frame."),
single-stepping, or enabling/disabling other tracepoints, \n\
depending on target's capabilities."));
+ default_collect = xstrdup ("");
+ add_setshow_string_cmd ("default-collect", class_trace,
+ &default_collect, _("\
+Set the list of expressions to collect by default"), _("\
+Show the list of expressions to collect by default"), NULL,
+ NULL, NULL,
+ &setlist, &showlist);
+
target_buf_size = 2048;
target_buf = xmalloc (target_buf_size);
}