Re: [patch v9 18/23] record: add "record function-call-history" command

Jan Kratochvil
2013-03-05T20:12:12Z

On Mon, 04 Mar 2013 18:06:05 +0100, Markus Metzger wrote:
> Add command to print the function names from recorded instructions.
>
> The command supports iterating over the execution log similar to the "list"
> command.
>
> This command provides a quick high-level overview over the recorded execution
> log at function granularity without having to reverse-step.
>
> CC: Eli Zaretskii <eliz@gnu.org>
>
> 2013-03-04 Markus Metzger <markus.t.metzger@intel.com>
>
> * target.c (target_call_history, target_call_history_from,
> target_call_history_range): New.
> * target.h (target_ops) <to_call_history, to_call_history_from,
> to_call_history_range>: New fields.
> (target_call_history, target_call_history_from,
> target_call_history_range): New declaration.
> * record.c (get_call_history_modifiers, cmd_record_call_history,
> record_call_history_size): New.
> (_initialize_record): Add the "record function-call-history" command.
> Add "set/show record function-call-history-size" commands.
> * record.h (record_print_flag): New.
[...]
> --- a/gdb/record.c
> +++ b/gdb/record.c
[...]
> +/* The "record function-call-history" command. */
> +
> +static void
> +cmd_record_call_history (char *arg, int from_tty)
> +{
> + int flags, size;
> +
> + require_record_target ();
> +
> + flags = get_call_history_modifiers (&arg);
> + size = (int) record_call_history_size;
> + if (size < 0)
> + size = INT_MAX;

Again please comment, I do not understand off-hand what is the goal of this
code.

> +
> + if (arg == NULL || *arg == 0 || strcmp (arg, "+") == 0)
> + target_call_history (size, flags);
> + else if (strcmp (arg, "-") == 0)
> + target_call_history (- size, flags);

Just '-size', no space there.

> + else
> + {
> + ULONGEST begin, end;
> +
> + begin = get_insn_number (&arg);
> +
> + if (*arg == ',')
> + {
> + arg = skip_spaces (++arg);
> +
> + if (*arg == '+')
> + {
> + arg += 1;
> + size = get_context_size (&arg);
> +
> + no_chunk (arg);
> +
> + target_call_history_from (begin, size, flags);
> + }
> + else if (*arg == '-')
> + {
> + arg += 1;
> + size = get_context_size (&arg);
> +
> + no_chunk (arg);
> +
> + target_call_history_from (begin, -size, flags);
> + }
> + else
> + {
> + end = get_insn_number (&arg);
> +
> + no_chunk (arg);
> +
> + target_call_history_range (begin, end, flags);
> + }
> + }
> + else
> + {
> + no_chunk (arg);
> +
> + target_call_history_from (begin, size, flags);
> + }
> +
> + dont_repeat ();
> + }
> +}
[...]
> --- a/gdb/target.h
> +++ b/gdb/target.h
> @@ -908,6 +908,16 @@ struct target_ops
> /* Disassemble a section of the recorded execution trace. */
> void (*to_insn_history_range) (ULONGEST begin, ULONGEST end, int flags);
>
> + /* Print a function trace of the recorded execution trace. */
> + void (*to_call_history) (int size, int flags);

Please comment the rules which range will be printed depending on SIZE.

> +
> + /* Print a function trace of the recorded execution trace starting
> + at instruction FROM. */
> + void (*to_call_history_from) (ULONGEST begin, int size, int flags);

Please comment the meaning/relationship of BEGIN and SIZE.

> +
> + /* Print a function trace of an execution trace section. */

Comment whether END is inclusive or exclusive.

> + void (*to_call_history_range) (ULONGEST begin, ULONGEST end, int flags);
> +
> int to_magic;
> /* Need sub-structure for target machine related rather than comm related?
> */
> @@ -2003,4 +2013,13 @@ extern void target_insn_history_from (ULONGEST from, int size, int flags);
> /* See to_insn_history_range. */
> extern void target_insn_history_range (ULONGEST begin, ULONGEST end, int flags);
>
> +/* See to_call_history. */
> +extern void target_call_history (int size, int flags);
> +
> +/* See to_call_history_from. */
> +extern void target_call_history_from (ULONGEST begin, int size, int flags);
> +
> +/* See to_call_history_range. */
> +extern void target_call_history_range (ULONGEST begin, ULONGEST end, int flags);
> +
> #endif /* !defined (TARGET_H) */
> --
> 1.7.1

OK with the comments.

Thanks,
Jan