This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[rfc 8/8] record: add "record list" 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: Thu, 14 Feb 2013 17:29:12 +0100
- Subject: [rfc 8/8] record: add "record list" command
- References: <1360859352-30399-1-git-send-email-markus.t.metzger@intel.com>
From: Markus Metzger <markus.t.metzger@intel.com>
Add a "record list" command to print a source listing of the recorded execution
log.
The command supports iterating over the execution log similar to the "list"
command.
This is useful for getting a quick overview of the recorded execution trace
without having to reverse-step.
2013-02-14 Markus Metzger <markus.t.metzger@intel.com>
* target.c (target_list_record, target_list_record_range): New.
* target.h (target_ops) <to_list_record,
to_list_record_range>: New fields.
(target_disas_record, target_disas_record_range): New declaration.
* record.c (get_list_modifiers, cmd_record_list): New.
(record_list_size): New.
(_initialize_record): Add the "record list" command.
Add "set/show record list-size" commands.
---
gdb/record.c | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
gdb/target.c | 34 +++++++++++++++++++++
gdb/target.h | 12 +++++++
3 files changed, 138 insertions(+), 0 deletions(-)
diff --git a/gdb/record.c b/gdb/record.c
index 925e4c1..16cf48a 100644
--- a/gdb/record.c
+++ b/gdb/record.c
@@ -38,6 +38,9 @@ static unsigned int record_disas_size = 10;
/* The number of functions to print in "record backtrace". */
static unsigned int record_backtrace_size = 10;
+/* The number of source lines to print in "record list". */
+static unsigned int record_list_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;
@@ -512,6 +515,75 @@ cmd_record_backtrace (char *arg, int from_tty)
}
}
+/* Read "record list" modifiers from an argument string. */
+
+static int
+get_list_modifiers (char **arg)
+{
+ int modifiers;
+ char *args;
+
+ modifiers = 0;
+ args = *arg;
+
+ if (args == NULL)
+ return 0;
+
+ while (*args == '/')
+ {
+ ++args;
+
+ if (*args == '\0')
+ error (_("Missing modifier."));
+
+ for (; *args; ++args)
+ {
+ if (isspace (*args))
+ break;
+
+ if (*args == '/')
+ continue;
+
+ switch (*args)
+ {
+ default:
+ error (_("Invalid modifier: %c."), *args);
+ }
+ }
+
+ args = skip_spaces (args);
+ }
+
+ /* Update the argument string. */
+ *arg = args;
+
+ return modifiers;
+}
+
+/* The "record list" command. */
+
+static void
+cmd_record_list (char *arg, int from_tty)
+{
+ int flags;
+
+ require_record_target ();
+
+ flags = get_list_modifiers (&arg);
+
+ if (arg == NULL || *arg == 0 || strcmp (arg, "+") == 0)
+ target_list_record ((int) record_list_size, flags);
+ else if (strcmp (arg, "-") == 0)
+ target_list_record (- (int) record_list_size, flags);
+ else
+ {
+ ULONGEST begin, end;
+
+ get_insn_range (&arg, record_list_size, &begin, &end);
+ target_list_record_range (begin, end, flags);
+ }
+}
+
/* Provide a prototype to silence -Wmissing-prototypes. */
extern initialize_file_ftype _initialize_record;
@@ -541,6 +613,13 @@ Show number of functions to print in \"record backtrace\"."),
NULL, NULL, NULL, &set_record_cmdlist,
&show_record_cmdlist);
+ add_setshow_uinteger_cmd ("list-size", no_class,
+ &record_list_size, _("\
+Set number of source lines to print in \"record list\"."), _("\
+Show number of source lines to print in \"record list\"."),
+ 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);
@@ -614,4 +693,17 @@ The number of functions to print can be defined with \"set record \
backtrace-size\"."),
&record_cmdlist);
add_alias_cmd ("bt", "backtrace", class_obscure, 1, &record_cmdlist);
+
+ add_cmd ("list", class_obscure, cmd_record_list, _("\
+Print a list of recorded source lines.\n\
+With no argument, prints ten more source lines after or around the previous \
+ten-line list.\n\
+\"list -\" prints ten source lines before a previous ten-line list.\n\
+One argument specifies an instruction, and a ten source lines list is \
+printed starting at that instruction.\n\
+Two arguments with comma between specify starting and ending instructions. \
+Prints all source lines in this range.\n\
+The number of source lines to print can be defined with \"set record \
+list-size\"."),
+ &record_cmdlist);
}
diff --git a/gdb/target.c b/gdb/target.c
index 940e6b8..0c0e8ae 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -4428,6 +4428,40 @@ target_backtrace_record_range (ULONGEST begin, ULONGEST end, int flags)
tcomplain ();
}
+/* See target.h. */
+
+void
+target_list_record (int size, int flags)
+{
+ struct target_ops *t;
+
+ for (t = current_target.beneath; t != NULL; t = t->beneath)
+ if (t->to_list_record != NULL)
+ {
+ t->to_list_record (size, flags);
+ return;
+ }
+
+ tcomplain ();
+}
+
+/* See target.h. */
+
+void
+target_list_record_range (ULONGEST begin, ULONGEST end, int flags)
+{
+ struct target_ops *t;
+
+ for (t = current_target.beneath; t != NULL; t = t->beneath)
+ if (t->to_list_record_range != NULL)
+ {
+ t->to_list_record_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 b670660..0ebb402 100644
--- a/gdb/target.h
+++ b/gdb/target.h
@@ -909,6 +909,12 @@ struct target_ops
/* Print a function trace of an execution trace section. */
void (*to_backtrace_record_range) (ULONGEST begin, ULONGEST end, int flags);
+ /* Print a source listing for the recorded execution trace. */
+ void (*to_list_record) (int size, int flags);
+
+ /* Print a source listing for an execution trace section. */
+ void (*to_list_record_range) (ULONGEST begin, ULONGEST end, int flags);
+
int to_magic;
/* Need sub-structure for target machine related rather than comm related?
*/
@@ -2008,4 +2014,10 @@ extern void target_backtrace_record (int size, int flags);
extern void target_backtrace_record_range (ULONGEST begin, ULONGEST end,
int flags);
+/* See to_list_record. */
+extern void target_list_record (int size, int flags);
+
+/* See to_list_record_range. */
+extern void target_list_record_range (ULONGEST begin, ULONGEST end, int flags);
+
#endif /* !defined (TARGET_H) */
--
1.7.1