-/* Low level routine to set a tracepoint.
- Returns the tracepoint object so caller can set other things.
- Does not set the tracepoint number!
- Does not print anything.
-
- ==> This routine should not be called if there is a chance of later
- error(); otherwise it leaves a bogus tracepoint on the chain.
- Validate your arguments BEFORE calling this routine! */
-
-static struct tracepoint *
-set_raw_tracepoint (struct symtab_and_line sal)
-{
- struct tracepoint *t, *tc;
- struct cleanup *old_chain;
-
- t = (struct tracepoint *) xmalloc (sizeof (struct tracepoint));
- old_chain = make_cleanup (xfree, t);
- memset (t, 0, sizeof (*t));
- t->address = sal.pc;
- if (sal.symtab == NULL)
- t->source_file = NULL;
- else
- t->source_file = savestring (sal.symtab->filename,
- strlen (sal.symtab->filename));
-
- t->section = sal.section;
- t->language = current_language->la_language;
- t->input_radix = input_radix;
- t->line_number = sal.line;
- t->enabled_p = 1;
- t->next = 0;
- t->step_count = 0;
- t->pass_count = 0;
- t->addr_string = NULL;
-
- /* Add this tracepoint to the end of the chain
- so that a list of tracepoints will come out in order
- of increasing numbers. */
-
- tc = tracepoint_chain;
- if (tc == 0)
- tracepoint_chain = t;
- else
- {
- while (tc->next)
- tc = tc->next;
- tc->next = t;
- }
- discard_cleanups (old_chain);
- return t;
-}
-
-/* Set a tracepoint according to ARG (function, linenum or *address). */
-static void
-trace_command (char *arg, int from_tty)
-{
- char **canonical = (char **) NULL;
- struct symtabs_and_lines sals;
- struct symtab_and_line sal;
- struct tracepoint *t;
- char *addr_start = 0, *addr_end = 0;
- int i;
-
- if (!arg || !*arg)
- error (_("trace command requires an argument"));
-
- if (from_tty && info_verbose)
- printf_filtered ("TRACE %s\n", arg);
-
- addr_start = arg;
- sals = decode_line_1 (&arg, 1, (struct symtab *) NULL,
- 0, &canonical, NULL);
- addr_end = arg;
- if (!sals.nelts)
- return; /* ??? Presumably decode_line_1 has already warned? */
-
- /* Resolve all line numbers to PC's */
- for (i = 0; i < sals.nelts; i++)
- resolve_sal_pc (&sals.sals[i]);
-
- /* Now set all the tracepoints. */
- for (i = 0; i < sals.nelts; i++)
- {
- sal = sals.sals[i];
-
- t = set_raw_tracepoint (sal);
- set_tracepoint_count (tracepoint_count + 1);
- t->number = tracepoint_count;
-
- /* If a canonical line spec is needed use that instead of the
- command string. */
- if (canonical != (char **) NULL && canonical[i] != NULL)
- t->addr_string = canonical[i];
- else if (addr_start)
- t->addr_string = savestring (addr_start, addr_end - addr_start);
-
- trace_mention (t);
- }
-
- if (sals.nelts > 1)
- {
- printf_filtered ("Multiple tracepoints were set.\n");
- printf_filtered ("Use 'delete trace' to delete unwanted tracepoints.\n");
- }
-}
-
-/* Tell the user we have just set a tracepoint TP. */
-
-static void
-trace_mention (struct tracepoint *tp)
-{
- printf_filtered ("Tracepoint %d", tp->number);
-
- if (addressprint || (tp->source_file == NULL))
- {
- printf_filtered (" at ");
- deprecated_print_address_numeric (tp->address, 1, gdb_stdout);
- }
- if (tp->source_file)
- printf_filtered (": file %s, line %d.",
- tp->source_file, tp->line_number);
-
- printf_filtered ("\n");
-}
-
-/* Print information on tracepoint number TPNUM_EXP, or all if
- omitted. */
-
-static void
-tracepoints_info (char *tpnum_exp, int from_tty)
-{
- struct tracepoint *t;
- struct action_line *action;
- int found_a_tracepoint = 0;
- char wrap_indent[80];
- struct symbol *sym;
- int tpnum = -1;
-
- if (tpnum_exp)
- tpnum = parse_and_eval_long (tpnum_exp);
-
- ALL_TRACEPOINTS (t)
- if (tpnum == -1 || tpnum == t->number)
- {
- extern int addressprint; /* Print machine addresses? */
-
- if (!found_a_tracepoint++)
- {
- printf_filtered ("Num Enb ");
- if (addressprint)
- {
- if (TARGET_ADDR_BIT <= 32)
- printf_filtered ("Address ");
- else
- printf_filtered ("Address ");
- }
- printf_filtered ("PassC StepC What\n");
- }
- strcpy (wrap_indent, " ");
- if (addressprint)
- {
- if (TARGET_ADDR_BIT <= 32)
- strcat (wrap_indent, " ");
- else
- strcat (wrap_indent, " ");
- }
-
- printf_filtered ("%-3d %-3s ", t->number,
- t->enabled_p ? "y" : "n");
- if (addressprint)
- {
- char *tmp;
-
- if (TARGET_ADDR_BIT <= 32)
- tmp = hex_string_custom (t->address & (CORE_ADDR) 0xffffffff,
- 8);
- else
- tmp = hex_string_custom (t->address, 16);
-
- printf_filtered ("%s ", tmp);
- }
- printf_filtered ("%-5d %-5ld ", t->pass_count, t->step_count);
-
- if (t->source_file)
- {
- sym = find_pc_sect_function (t->address, t->section);
- if (sym)
- {
- fputs_filtered ("in ", gdb_stdout);
- fputs_filtered (SYMBOL_PRINT_NAME (sym), gdb_stdout);
- wrap_here (wrap_indent);
- fputs_filtered (" at ", gdb_stdout);
- }
- fputs_filtered (t->source_file, gdb_stdout);
- printf_filtered (":%d", t->line_number);
- }
- else
- print_address_symbolic (t->address, gdb_stdout, demangle, " ");
-
- printf_filtered ("\n");
- if (t->actions)
- {
- printf_filtered (" Actions for tracepoint %d: \n", t->number);
- for (action = t->actions; action; action = action->next)
- {
- printf_filtered ("\t%s\n", action->action);
- }
- }
- }
- if (!found_a_tracepoint)
- {
- if (tpnum == -1)
- printf_filtered ("No tracepoints.\n");
- else
- printf_filtered ("No tracepoint number %d.\n", tpnum);
- }
-}
-
-/* Optimization: the code to parse an enable, disable, or delete TP
- command is virtually identical except for whether it performs an
- enable, disable, or delete. Therefore I've combined them into one
- function with an opcode. */
-enum tracepoint_opcode
-{
- enable_op,
- disable_op,
- delete_op
-};
-
-/* This function implements enable, disable and delete commands. */
-static void
-tracepoint_operation (struct tracepoint *t, int from_tty,
- enum tracepoint_opcode opcode)
-{
- struct tracepoint *t2;
-
- if (t == NULL) /* no tracepoint operand */
- return;
-
- switch (opcode)
- {
- case enable_op:
- t->enabled_p = 1;
- tracepoint_modify_event (t->number);
- break;
- case disable_op:
- t->enabled_p = 0;
- tracepoint_modify_event (t->number);
- break;
- case delete_op:
- if (tracepoint_chain == t)
- tracepoint_chain = t->next;
-
- ALL_TRACEPOINTS (t2)
- if (t2->next == t)
- {
- tracepoint_delete_event (t2->number);
- t2->next = t->next;
- break;
- }
-
- if (t->addr_string)
- xfree (t->addr_string);
- if (t->source_file)
- xfree (t->source_file);
- if (t->actions)
- free_actions (t);
-
- xfree (t);
- break;
- }
-}
-
-/* Utility: parse a tracepoint number and look it up in the list.
- If MULTI_P is true, there might be a range of tracepoints in ARG.
- if OPTIONAL_P is true, then if the argument is missing, the most
- recent tracepoint (tracepoint_count) is returned. */
-struct tracepoint *
-get_tracepoint_by_number (char **arg, int multi_p, int optional_p)
-{
- struct tracepoint *t;
- int tpnum;
- char *instring = arg == NULL ? NULL : *arg;
-
- if (arg == NULL || *arg == NULL || ! **arg)
- {
- if (optional_p)
- tpnum = tracepoint_count;
- else
- error_no_arg (_("tracepoint number"));
- }
- else
- tpnum = multi_p ? get_number_or_range (arg) : get_number (arg);
-
- if (tpnum <= 0)
- {
- if (instring && *instring)
- printf_filtered ("bad tracepoint number at or near '%s'\n",
- instring);
- else
- printf_filtered ("Tracepoint argument missing and no previous tracepoint\n");
- return NULL;
- }
-
- ALL_TRACEPOINTS (t)
- if (t->number == tpnum)
- {
- return t;
- }
-
- /* FIXME: if we are in the middle of a range we don't want to give
- a message. The current interface to get_number_or_range doesn't
- allow us to discover this. */
- printf_unfiltered ("No tracepoint number %d.\n", tpnum);
- return NULL;
-}
-
-/* Utility:
- parse a list of tracepoint numbers, and call a func for each. */
-static void
-map_args_over_tracepoints (char *args, int from_tty,
- enum tracepoint_opcode opcode)
-{
- struct tracepoint *t, *tmp;
-
- if (args == 0 || *args == 0) /* do them all */
- ALL_TRACEPOINTS_SAFE (t, tmp)
- tracepoint_operation (t, from_tty, opcode);
- else
- while (*args)
- {
- QUIT; /* Give user option to bail out with ^C. */
- t = get_tracepoint_by_number (&args, 1, 0);
- tracepoint_operation (t, from_tty, opcode);
- while (*args == ' ' || *args == '\t')
- args++;
- }
-}
-
-/* The 'enable trace' command enables tracepoints.
- Not supported by all targets. */
-static void
-enable_trace_command (char *args, int from_tty)
-{
- dont_repeat ();
- map_args_over_tracepoints (args, from_tty, enable_op);
-}
-
-/* The 'disable trace' command disables tracepoints.
- Not supported by all targets. */
-static void
-disable_trace_command (char *args, int from_tty)
-{
- dont_repeat ();
- map_args_over_tracepoints (args, from_tty, disable_op);
-}
-
-/* Remove a tracepoint (or all if no argument) */
-static void
-delete_trace_command (char *args, int from_tty)
-{
- dont_repeat ();
- if (!args || !*args) /* No args implies all tracepoints; */
- if (from_tty) /* confirm only if from_tty... */
- if (tracepoint_chain) /* and if there are tracepoints to
- delete! */
- if (!query ("Delete all tracepoints? "))
- return;
-
- map_args_over_tracepoints (args, from_tty, delete_op);
-}
-
-/* Set passcount for tracepoint.
-
- First command argument is passcount, second is tracepoint number.
- If tracepoint number omitted, apply to most recently defined.
- Also accepts special argument "all". */
-
-static void
-trace_pass_command (char *args, int from_tty)
-{
- struct tracepoint *t1 = (struct tracepoint *) -1, *t2;
- unsigned int count;
- int all = 0;
-
- if (args == 0 || *args == 0)
- error (_("passcount command requires an argument (count + optional TP num)"));
-
- count = strtoul (args, &args, 10); /* Count comes first, then TP num. */
-
- while (*args && isspace ((int) *args))
- args++;
-
- if (*args && strncasecmp (args, "all", 3) == 0)
- {
- args += 3; /* Skip special argument "all". */
- all = 1;
- if (*args)
- error (_("Junk at end of arguments."));
- }
- else
- t1 = get_tracepoint_by_number (&args, 1, 1);
-
- do
- {
- if (t1)
- {
- ALL_TRACEPOINTS (t2)
- if (t1 == (struct tracepoint *) -1 || t1 == t2)
- {
- t2->pass_count = count;
- tracepoint_modify_event (t2->number);
- if (from_tty)
- printf_filtered ("Setting tracepoint %d's passcount to %d\n",
- t2->number, count);
- }
- if (! all && *args)
- t1 = get_tracepoint_by_number (&args, 1, 0);
- }
- }
- while (*args);
-}
-