This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH 2/2] record: add "record function-call-history" command
- From: markus dot t dot metzger at intel dot com
- To: jan dot kratochvil at redhat dot com
- Cc: gdb-patches at sourceware dot org, markus dot t dot metzger at gmail dot com, Markus Metzger <markus dot t dot metzger at intel dot com>
- Date: Fri, 22 Feb 2013 13:17:17 +0100
- Subject: [PATCH 2/2] record: add "record function-call-history" command
- References: <1361535437-22493-1-git-send-email-markus.t.metzger@intel.com>
From: Markus Metzger <markus.t.metzger@intel.com>
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 without having to reverse-step.
2013-02-22 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,
get_context_size, 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.
---
gdb/record.c | 149 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
gdb/record.h | 7 +++
gdb/target.c | 51 ++++++++++++++++++++
gdb/target.h | 19 +++++++
4 files changed, 226 insertions(+), 0 deletions(-)
diff --git a/gdb/record.c b/gdb/record.c
index 6ac0c8c..8bfd356 100644
--- a/gdb/record.c
+++ b/gdb/record.c
@@ -35,6 +35,9 @@ unsigned int record_debug = 0;
/* The number of instructions to print in "record instruction-history". */
static unsigned int record_insn_history_size = 10;
+/* The number of functions to print in "record function-call-history". */
+static unsigned int record_call_history_size = 10;
+
struct cmd_list_element *record_cmdlist = NULL;
struct cmd_list_element *set_record_cmdlist = NULL;
struct cmd_list_element *show_record_cmdlist = NULL;
@@ -317,6 +320,27 @@ get_insn_number (char **arg)
return number;
}
+/* Read a context size from an argument string. */
+
+static int
+get_context_size (char **arg)
+{
+ char *begin, *end, *pos;
+ int number;
+
+ begin = *arg;
+ pos = skip_spaces (begin);
+
+ if (!isdigit (*pos))
+ error (_("Expected positive number, got: %s."), pos);
+
+ number = strtol (pos, &end, 10);
+
+ *arg += (end - begin);
+
+ return number;
+}
+
/* Read instruction-history modifiers from an argument string. */
static int
@@ -442,6 +466,106 @@ cmd_record_insn_history (char *arg, int from_tty)
}
}
+/* Read function-call-history modifiers from an argument string. */
+
+static int
+get_call_history_modifiers (char **arg)
+{
+ int modifiers;
+ char *args;
+
+ modifiers = 0;
+ args = *arg;
+
+ if (args == NULL)
+ return modifiers;
+
+ while (*args == '/')
+ {
+ ++args;
+
+ if (*args == '\0')
+ error (_("Missing modifier."));
+
+ for (; *args; ++args)
+ {
+ if (isspace (*args))
+ break;
+
+ if (*args == '/')
+ continue;
+
+ switch (*args)
+ {
+ case 'l':
+ modifiers |= record_print_src_line;
+ break;
+ default:
+ error (_("Invalid modifier: %c."), *args);
+ }
+ }
+
+ args = skip_spaces (args);
+ }
+
+ /* Update the argument string. */
+ *arg = args;
+
+ return modifiers;
+}
+
+/* The "record function-call-history" command. */
+
+static void
+cmd_record_call_history (char *arg, int from_tty)
+{
+ int flags;
+
+ require_record_target ();
+
+ flags = get_call_history_modifiers (&arg);
+
+ if (arg == NULL || *arg == 0 || strcmp (arg, "+") == 0)
+ target_call_history ((int) record_call_history_size, flags);
+ else if (strcmp (arg, "-") == 0)
+ target_call_history (- (int) record_call_history_size, flags);
+ else
+ {
+ ULONGEST begin, end;
+ int size;
+
+ begin = get_insn_number (&arg);
+
+ if (*arg == ',')
+ {
+ arg = skip_spaces (++arg);
+
+ if (*arg == '+')
+ {
+ ++arg;
+ size = get_context_size (&arg);
+
+ target_call_history_from (begin, size, flags);
+ }
+ else if (*arg == '-')
+ {
+ ++arg;
+ size = get_context_size (&arg);
+
+ target_call_history_from (begin, -size, flags);
+ }
+ else
+ {
+ end = get_insn_number (&arg);
+
+ target_call_history_range (begin, end, flags);
+ }
+ }
+ else
+ target_call_history_from (begin, (int) record_call_history_size, flags);
+ }
+}
+
/* Provide a prototype to silence -Wmissing-prototypes. */
extern initialize_file_ftype _initialize_record;
@@ -465,6 +589,13 @@ Show number of instructions to print in \"record instruction-history\"."),
NULL, NULL, NULL, &set_record_cmdlist,
&show_record_cmdlist);
+ add_setshow_uinteger_cmd ("function-call-history-size", no_class,
+ &record_call_history_size, _("\
+Set number of function to print in \"record function-call-history\"."), _("\
+Show number of functions to print in \"record function-call-history\"."),
+ NULL, NULL, NULL, &set_record_cmdlist,
+ &show_record_cmdlist);
+
c = add_prefix_cmd ("record", class_obscure, cmd_record_start,
_("Start recording."),
&record_cmdlist, "record ", 0, &cmdlist);
@@ -525,4 +656,22 @@ from the first argument.\n\
The number of instructions to disassemble can be defined with \"set record \
instruction-history-size\"."),
&record_cmdlist);
+
+ add_cmd ("function-call-history", class_obscure, cmd_record_call_history, _("\
+Print function names for instructions stored in the execution log.\n\
+With a /l modifier, the source file and line number is included.\n\
+With no argument, prints ten more function names after or around the previous \
+function name print.\n\
+\"record function-call-history -\" prints ten function namess before a \
+previous function name print.\n\
+One argument specifies an instruction number as shown by 'info record', and \
+ten function names are printed for instructions starting at that instruction \
+number.\n\
+Two arguments with comma between specify starting and ending instruction \
+numbers. Prints all function namess for instructions in this range.\n\
+If the second argument is preceded by '+' or '-', it specifies the distance \
+from the first argument.\n\
+The number of functions to print can be defined with \"set record \
+function-call-history-size\"."),
+ &record_cmdlist);
}
diff --git a/gdb/record.h b/gdb/record.h
index 04d6b4a..e9d4bcd 100644
--- a/gdb/record.h
+++ b/gdb/record.h
@@ -32,6 +32,13 @@ extern struct cmd_list_element *set_record_cmdlist;
extern struct cmd_list_element *show_record_cmdlist;
extern struct cmd_list_element *info_record_cmdlist;
+/* A list of flags specifying what record target methods should print. */
+enum record_print_flag
+ {
+ /* Print the source file and line (if applicable). */
+ record_print_src_line = (1 << 0)
+ };
+
/* Wrapper for target_read_memory that prints a debug message if
reading memory fails. */
extern int record_read_memory (struct gdbarch *gdbarch,
diff --git a/gdb/target.c b/gdb/target.c
index 7643d6a..60fa220 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -4394,6 +4394,57 @@ target_insn_history_range (ULONGEST begin, ULONGEST end, int flags)
tcomplain ();
}
+/* See target.h. */
+
+void
+target_call_history (int size, int flags)
+{
+ struct target_ops *t;
+
+ for (t = current_target.beneath; t != NULL; t = t->beneath)
+ if (t->to_call_history != NULL)
+ {
+ t->to_call_history (size, flags);
+ return;
+ }
+
+ tcomplain ();
+}
+
+/* See target.h. */
+
+void
+target_call_history_from (ULONGEST begin, int size, int flags)
+{
+ struct target_ops *t;
+
+ for (t = current_target.beneath; t != NULL; t = t->beneath)
+ if (t->to_call_history_from != NULL)
+ {
+ t->to_call_history_from (begin, size, flags);
+ return;
+ }
+
+ tcomplain ();
+}
+
+/* See target.h. */
+
+void
+target_call_history_range (ULONGEST begin, ULONGEST end, int flags)
+{
+ struct target_ops *t;
+
+ for (t = current_target.beneath; t != NULL; t = t->beneath)
+ if (t->to_call_history_range != NULL)
+ {
+ t->to_call_history_range (begin, end, flags);
+ return;
+ }
+
+ tcomplain ();
+}
+
static void
debug_to_prepare_to_store (struct regcache *regcache)
{
diff --git a/gdb/target.h b/gdb/target.h
index d5551aa..b190cf1 100644
--- a/gdb/target.h
+++ b/gdb/target.h
@@ -904,6 +904,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);
+
+ /* Print a function trace of the recorded execution trace starting
+ at instruction FROM. */
+ void (*to_call_history_from) (ULONGEST begin, int size, int flags);
+
+ /* Print a function trace of an execution trace section. */
+ 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?
*/
@@ -1996,4 +2006,13 @@ extern void target_insn_history (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