Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Markus Metzger <markus.t.metzger@intel.com>
To: jan.kratochvil@redhat.com
Cc: gdb-patches@sourceware.org, markus.t.metzger@gmail.com,
	       Eli Zaretskii <eliz@gnu.org>
Subject: [patch v9 17/23] record: add "record instruction-history" command
Date: Mon, 04 Mar 2013 17:09:00 -0000	[thread overview]
Message-ID: <1362416770-19750-18-git-send-email-markus.t.metzger@intel.com> (raw)
In-Reply-To: <1362416770-19750-1-git-send-email-markus.t.metzger@intel.com>

Add a command to provide a disassembly of the execution trace log.

The command iterates over the execution trace log similar to the
"list" command.

CC: Eli Zaretskii <eliz@gnu.org>

2013-03-04  Markus Metzger  <markus.t.metzger@intel.com>

	* target.h (target_ops) <to_insn_history, to_insn_history_from,
	to_insn_history_range>: New fields.
	(target_insn_history): New.
	(target_insn_history_from): New.
	(target_insn_history_range): New.
	* target.c (target_insn_history): New.
	(target_insn_history_from): New.
	(target_insn_history_range): New.
	* record.c: Include cli/cli-utils.h, disasm.h, ctype.h.
	(record_insn_history_size): New.
	(get_insn_number): New.
	(get_context_size): New.
	(no_chunk): New.
	(get_insn_history_modifiers): New.
	(cmd_record_insn_history): New.
	(_initialize_record): Add "set/show record instruction-history-size"
	command. Add "record instruction-history" command.


---
 gdb/record.c |  200 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 gdb/target.c |   51 +++++++++++++++
 gdb/target.h |   20 ++++++
 3 files changed, 271 insertions(+), 0 deletions(-)

diff --git a/gdb/record.c b/gdb/record.c
index abd8216..4c5f3f0 100644
--- a/gdb/record.c
+++ b/gdb/record.c
@@ -24,10 +24,17 @@
 #include "observer.h"
 #include "inferior.h"
 #include "common/common-utils.h"
+#include "cli/cli-utils.h"
+#include "disasm.h"
+
+#include <ctype.h>
 
 /* This is the debug switch for process record.  */
 unsigned int record_debug = 0;
 
+/* The number of instructions to print in "record instruction-history".  */
+static unsigned int record_insn_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;
@@ -289,6 +296,173 @@ cmd_record_goto (char *arg, int from_tty)
     }
 }
 
+/* Read an instruction number from an argument string.  */
+
+static ULONGEST
+get_insn_number (char **arg)
+{
+  ULONGEST number;
+  const char *begin, *end, *pos;
+
+  begin = *arg;
+  pos = skip_spaces_const (begin);
+
+  if (!isdigit (*pos))
+    error (_("Expected positive number, got: %s."), pos);
+
+  number = strtoulst (pos, &end, 10);
+
+  *arg += (end - begin);
+
+  return number;
+}
+
+/* Read a context size from an argument string.  */
+
+static int
+get_context_size (char **arg)
+{
+  char *pos;
+  int number;
+
+  pos = skip_spaces (*arg);
+
+  if (!isdigit (*pos))
+    error (_("Expected positive number, got: %s."), pos);
+
+  return strtol (pos, arg, 10);
+}
+
+/* Complain about junk at the end of an argument string.  */
+
+static void
+no_chunk (char *arg)
+{
+  if (*arg != 0)
+    error (_("Junk after argument: %s."), arg);
+}
+
+/* Read instruction-history modifiers from an argument string.  */
+
+static int
+get_insn_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 'm':
+	      modifiers |= DISASSEMBLY_SOURCE;
+	      modifiers |= DISASSEMBLY_FILENAME;
+	      break;
+	    case 'r':
+	      modifiers |= DISASSEMBLY_RAW_INSN;
+	      break;
+	    case 'f':
+	      modifiers |= DISASSEMBLY_OMIT_FNAME;
+	      break;
+	    default:
+	      error (_("Invalid modifier: %c."), *args);
+	    }
+	}
+
+      args = skip_spaces (args);
+    }
+
+  /* Update the argument string.  */
+  *arg = args;
+
+  return modifiers;
+}
+
+/* The "record instruction-history" command.  */
+
+static void
+cmd_record_insn_history (char *arg, int from_tty)
+{
+  int flags, size;
+
+  require_record_target ();
+
+  flags = get_insn_history_modifiers (&arg);
+  size = (int) record_insn_history_size;
+  if (size < 0)
+    size = INT_MAX;
+
+  if (arg == NULL || *arg == 0 || strcmp (arg, "+") == 0)
+    target_insn_history (size, flags);
+  else if (strcmp (arg, "-") == 0)
+    target_insn_history (- size, flags);
+  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_insn_history_from (begin, size, flags);
+	    }
+	  else if (*arg == '-')
+	    {
+	      arg += 1;
+	      size = get_context_size (&arg);
+
+	      no_chunk (arg);
+
+	      target_insn_history_from (begin, - size, flags);
+	    }
+	  else
+	    {
+	      end = get_insn_number (&arg);
+
+	      no_chunk (arg);
+
+	      target_insn_history_range (begin, end, flags);
+	    }
+	}
+      else
+	{
+	  no_chunk (arg);
+
+	  target_insn_history_from (begin, size, flags);
+	}
+
+      dont_repeat ();
+    }
+}
+
 /* Provide a prototype to silence -Wmissing-prototypes.  */
 extern initialize_file_ftype _initialize_record;
 
@@ -305,6 +479,13 @@ _initialize_record (void)
 			     NULL, show_record_debug, &setdebuglist,
 			     &showdebuglist);
 
+  add_setshow_uinteger_cmd ("instruction-history-size", no_class,
+			    &record_insn_history_size, _("\
+Set number of instructions to print in \"record instruction-history\"."), _("\
+Show number of instructions to print in \"record instruction-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);
@@ -346,4 +527,23 @@ Default filename is 'gdb_record.<process_id>'."),
 Restore the program to its state at instruction number N.\n\
 Argument is instruction number, as shown by 'info record'."),
 	   &record_cmdlist);
+
+  add_cmd ("instruction-history", class_obscure, cmd_record_insn_history, _("\
+Print disassembled instructions stored in the execution log.\n\
+With a /m modifier, source lines are included (if available).\n\
+With a /r modifier, raw instructions in hex are included.\n\
+With a /f modifier, function names are omitted.\n\
+With no argument, disassembles ten more instructions after the previous \
+disassembly.\n\
+\"record instruction-history -\" disassembles ten instructions before a \
+previous disassembly.\n\
+One argument specifies an instruction number as shown by 'info record', and \
+ten instructions are disassembled after that instruction.\n\
+Two arguments with comma between specify starting and ending instruction \
+numbers to disassemble.\n\
+If the second argument is preceded by '+' or '-', it specifies the distance \
+from the first argument.\n\
+The number of instructions to disassemble can be defined with \"set record \
+instruction-history-size\"."),
+           &record_cmdlist);
 }
diff --git a/gdb/target.c b/gdb/target.c
index 8512ae5..e9d70b7 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -4360,6 +4360,57 @@ target_goto_record (ULONGEST insn)
   tcomplain ();
 }
 
+/* See target.h.  */
+
+void
+target_insn_history (int size, int flags)
+{
+  struct target_ops *t;
+
+  for (t = current_target.beneath; t != NULL; t = t->beneath)
+    if (t->to_insn_history != NULL)
+      {
+	t->to_insn_history (size, flags);
+	return;
+      }
+
+  tcomplain ();
+}
+
+/* See target.h.  */
+
+void
+target_insn_history_from (ULONGEST from, int size, int flags)
+{
+  struct target_ops *t;
+
+  for (t = current_target.beneath; t != NULL; t = t->beneath)
+    if (t->to_insn_history_from != NULL)
+      {
+	t->to_insn_history_from (from, size, flags);
+	return;
+      }
+
+  tcomplain ();
+}
+
+/* See target.h.  */
+
+void
+target_insn_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_insn_history_range != NULL)
+      {
+	t->to_insn_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 d416193..4ecb6e2 100644
--- a/gdb/target.h
+++ b/gdb/target.h
@@ -897,6 +897,17 @@ struct target_ops
     /* Go to a specific location in the recorded execution trace.  */
     void (*to_goto_record) (ULONGEST insn);
 
+    /* Disassemble SIZE instructions in the recorded execution trace from
+       the current position.  */
+    void (*to_insn_history) (int size, int flags);
+
+    /* Disassemble SIZE instructions in the recorded execution trace around
+       FROM.  */
+    void (*to_insn_history_from) (ULONGEST FROM, int size, int flags);
+
+    /* Disassemble a section of the recorded execution trace.  */
+    void (*to_insn_history_range) (ULONGEST begin, ULONGEST end, int flags);
+
     int to_magic;
     /* Need sub-structure for target machine related rather than comm related?
      */
@@ -1983,4 +1994,13 @@ extern void target_goto_record_end (void);
 /* See to_goto_record in struct target_ops.  */
 extern void target_goto_record (ULONGEST insn);
 
+/* See to_insn_history.  */
+extern void target_insn_history (int size, int flags);
+
+/* See to_insn_history_from.  */
+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);
+
 #endif /* !defined (TARGET_H) */
-- 
1.7.1


  parent reply	other threads:[~2013-03-04 17:08 UTC|newest]

Thread overview: 102+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-04 17:07 [patch v9 00/23] branch tracing support for Atom Markus Metzger
2013-03-04 17:07 ` [patch v9 16/23] record: default target methods Markus Metzger
2013-03-05 20:10   ` Jan Kratochvil
2013-03-04 17:07 ` [patch v9 05/23] remote, btrace: add branch trace remote ops Markus Metzger
2013-03-05 20:07   ` Jan Kratochvil
2013-03-06  9:00     ` Metzger, Markus T
2013-03-04 17:07 ` [patch v9 03/23] linux, i386, amd64: enable btrace for 32bit and 64bit linux native Markus Metzger
2013-03-05 20:06   ` Jan Kratochvil
2013-03-04 17:07 ` [patch v9 08/23] gdbserver, linux, btrace: add btrace support for linux-low Markus Metzger
2013-03-05 20:09   ` Jan Kratochvil
2013-03-06  9:17     ` Metzger, Markus T
2013-03-06 13:33   ` Jan Kratochvil
2013-03-04 17:07 ` [patch v9 01/23] thread, btrace: add generic branch trace support Markus Metzger
2013-03-05 20:06   ` Jan Kratochvil
2013-03-05 22:02     ` Tom Tromey
2013-03-06 21:11   ` Doug Evans
2013-03-07  7:50     ` Metzger, Markus T
2013-03-07 22:57       ` Doug Evans
2013-03-04 17:07 ` [patch v9 02/23] linux, btrace: perf_event based branch tracing Markus Metzger
2013-03-05 20:06   ` Jan Kratochvil
2013-03-06 10:11   ` Mark Kettenis
2013-03-06 10:29     ` Metzger, Markus T
2013-03-04 17:07 ` [patch v9 04/23] xml, btrace: define btrace xml document style Markus Metzger
2013-03-05 20:07   ` Jan Kratochvil
2013-03-04 17:07 ` [patch v9 07/23] gdbserver, btrace: add generic btrace support Markus Metzger
2013-03-05 20:08   ` Jan Kratochvil
2013-03-06  9:15     ` Metzger, Markus T
2013-03-06 13:22   ` Jan Kratochvil
2013-03-04 17:07 ` [patch v9 10/23] remote, btrace: add branch tracing protocol to Qbtrace packet Markus Metzger
2013-03-05 20:09   ` Jan Kratochvil
2013-03-06  9:19     ` Metzger, Markus T
2013-03-04 17:08 ` [patch v9 19/23] record, btrace: add record-btrace target Markus Metzger
2013-03-05 20:13   ` Jan Kratochvil
2013-03-06  9:57     ` Metzger, Markus T
2013-03-06 13:35       ` Jan Kratochvil
2013-03-06 14:01         ` Metzger, Markus T
2013-03-06 16:28   ` Jan Kratochvil
2013-03-04 17:08 ` [patch v9 09/23] btrace, x86: disable on some processors Markus Metzger
2013-03-05 20:09   ` Jan Kratochvil
2013-03-04 17:08 ` [patch v9 20/23] record-btrace, disas: omit pc prefix Markus Metzger
2013-03-05 20:13   ` Jan Kratochvil
2013-03-04 17:08 ` [patch v9 11/23] target: add add_deprecated_target_alias Markus Metzger
2013-03-05 20:09   ` Jan Kratochvil
2013-03-04 17:08 ` [patch v9 22/23] testsuite, gdb.btrace: add btrace tests Markus Metzger
2013-03-04 19:47   ` Jan Kratochvil
2013-03-05  6:39     ` Metzger, Markus T
2013-03-05 20:14   ` Jan Kratochvil
2013-03-06 15:32     ` christian.himpel
2013-03-06 16:35       ` Jan Kratochvil
2013-03-04 17:08 ` [patch v9 06/23] btrace, doc: document remote serial protocol Markus Metzger
2013-03-04 18:08   ` Eli Zaretskii
2013-03-05 20:08   ` Jan Kratochvil
2013-03-06  9:06     ` Metzger, Markus T
2013-03-06  9:50       ` Jan Kratochvil
2013-03-06 10:01         ` Metzger, Markus T
2013-03-06 12:07           ` Jan Kratochvil
2013-03-06 12:13             ` Metzger, Markus T
2013-03-06 12:17               ` Jan Kratochvil
2013-03-04 17:09 ` [patch v9 23/23] btrace, remote: drop qbtrace packet Markus Metzger
2013-03-04 18:15   ` Eli Zaretskii
2013-03-05 20:15   ` Jan Kratochvil
2013-03-04 17:09 ` [patch v9 21/23] doc, record: document record changes Markus Metzger
2013-03-04 18:13   ` Eli Zaretskii
2013-03-05 20:13   ` Jan Kratochvil
2013-03-04 17:09 ` [patch v9 18/23] record: add "record function-call-history" command Markus Metzger
2013-03-04 18:07   ` Eli Zaretskii
2013-03-05 20:12   ` Jan Kratochvil
2013-03-04 17:09 ` [patch v9 14/23] record-full.c: rename record_ in record_full_ Markus Metzger
2013-03-05 20:10   ` Jan Kratochvil
2013-03-04 17:09 ` [patch v9 13/23] record: make it build again Markus Metzger
2013-03-05 20:10   ` Jan Kratochvil
2013-03-04 17:09 ` [patch v9 15/23] record-full.h: rename record_ into record_full_ Markus Metzger
2013-03-05 20:10   ` Jan Kratochvil
2013-03-04 17:09 ` Markus Metzger [this message]
2013-03-04 18:14   ` [patch v9 17/23] record: add "record instruction-history" command Eli Zaretskii
2013-03-05 20:11   ` Jan Kratochvil
2013-03-04 17:10 ` [patch v9 12/23] record: split record Markus Metzger
2013-03-05 20:09   ` Jan Kratochvil
2013-03-06 12:43 ` Crash of GDB with gdbserver btrace enabled [Re: [patch v9 00/23] branch tracing support for Atom] Jan Kratochvil
2013-03-06 14:40   ` Metzger, Markus T
2013-03-06 15:31     ` Metzger, Markus T
2013-03-06 17:06       ` Jan Kratochvil
2013-03-06 18:08         ` Metzger, Markus T
2013-03-07  9:06           ` Jan Kratochvil
2013-03-07  9:41             ` Metzger, Markus T
2013-03-07 10:00               ` Metzger, Markus T
2013-03-07 10:14                 ` Jan Kratochvil
2013-03-07 10:33                   ` Metzger, Markus T
2013-03-07 12:07                     ` Jan Kratochvil
2013-03-07 12:33                       ` Metzger, Markus T
2013-03-07 14:45                         ` Jan Kratochvil
2013-03-07 15:22                           ` Metzger, Markus T
2013-03-07 15:46                             ` Jan Kratochvil
2013-03-07 15:12                         ` Pedro Alves
2013-03-07 15:33                           ` Metzger, Markus T
2013-03-07 15:39                             ` Jan Kratochvil
2013-03-07 15:41                             ` Pedro Alves
     [not found]                           ` <20130318170643.GA15625@host2.jankratochvil.net>
     [not found]                             ` <514758DA.2060905@redhat.com>
2013-03-20 15:52                               ` [commit] [patch] Code cleanup: Remove parameter quitting [Re: Crash of GDB with gdbserver btrace enabled] Jan Kratochvil
     [not found]                               ` <20130318192604.GA2786@host2.jankratochvil.net>
     [not found]                                 ` <51477828.30000@redhat.com>
2013-03-26  0:15                                   ` Jan Kratochvil
2013-04-03 18:05                                     ` Pedro Alves
2013-03-07 10:08               ` Crash of GDB with gdbserver btrace enabled [Re: [patch v9 00/23] branch tracing support for Atom] Jan Kratochvil
2013-03-06 15:41   ` Jan Kratochvil

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1362416770-19750-18-git-send-email-markus.t.metzger@intel.com \
    --to=markus.t.metzger@intel.com \
    --cc=eliz@gnu.org \
    --cc=gdb-patches@sourceware.org \
    --cc=jan.kratochvil@redhat.com \
    --cc=markus.t.metzger@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox