public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v2 00/12] Extensions for PTWRITE
@ 2021-06-14 14:50 Felix Willgerodt
  2021-06-14 14:50 ` [PATCH v2 01/12] btrace: Introduce auxiliary instructions Felix Willgerodt
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Felix Willgerodt @ 2021-06-14 14:50 UTC (permalink / raw)
  To: markus.t.metzger, gdb-patches

This is a patch series that I tried upstreaming two years ago.
Sorry for taking so long to get back to it.

V1 can be found here:
https://sourceware.org/pipermail/gdb-patches/2019-May/157933.html

Changes compared to v1:
* New patch 7: Extended RSP. This helps when GDB is build
  with a libipt version not supporing ptwrite.
* New patch 11: Added a function to require a specific libipt version
  in the testsuite.
* I addressed all/most of the comments from Markus and Eli from back then.

Patch 1 and 2 were already approved by Markus. In patch 2 some minor
things have changed though.

Regards,
Felix

Regression tested on Fedora 32 and Ubuntu 20.04 x86_64.

Felix Willgerodt (12):
  btrace: Introduce auxiliary instructions.
  btrace: Enable auxiliary instructions in record instruction-history.
  btrace: Enable auxiliary instructions in record function-call-history.
  btrace: Handle stepping and goto for auxiliary instructions.
  python: Introduce gdb.RecordAuxiliary class.
  python: Add clear() to gdb.Record.
  btrace, gdbserver: Add ptwrite to btrace_config_pt.
  btrace, linux: Enable ptwrite packets.
  btrace, python: Enable ptwrite listener registration.
  btrace, python: Enable calling the ptwrite listener.
  gdb, testsuite, lib: Add libipt version check.
  btrace: Extend ptwrite event decoding.

 gdb/NEWS                                      |   6 +
 gdb/btrace.c                                  |  64 ++-
 gdb/btrace.h                                  |  41 +-
 gdb/data-directory/Makefile.in                |   1 +
 gdb/disasm.h                                  |   1 +
 gdb/doc/gdb.texinfo                           |  33 +-
 gdb/doc/python.texi                           | 150 ++++++
 gdb/extension-priv.h                          |   4 +
 gdb/extension.c                               |  21 +
 gdb/extension.h                               |   3 +
 gdb/features/btrace-conf.dtd                  |   1 +
 gdb/guile/guile.c                             |   1 +
 gdb/nat/linux-btrace.c                        |  29 ++
 gdb/python/lib/gdb/ptwrite.py                 |  86 ++++
 gdb/python/py-record-btrace.c                 | 180 ++++++-
 gdb/python/py-record-btrace.h                 |  14 +
 gdb/python/py-record.c                        |  89 +++-
 gdb/python/py-record.h                        |   3 +
 gdb/python/python-internal.h                  |   3 +
 gdb/python/python.c                           |   2 +
 gdb/record-btrace.c                           | 105 +++-
 gdb/record.c                                  |  10 +
 gdb/record.h                                  |   5 +-
 gdb/remote.c                                  |  30 ++
 gdb/testsuite/gdb.btrace/ptwrite.c            |  39 ++
 gdb/testsuite/gdb.btrace/ptwrite.exp          | 194 +++++++
 gdb/testsuite/gdb.btrace/x86_64-ptwrite.S     | 479 ++++++++++++++++++
 gdb/testsuite/gdb.python/py-record-btrace.exp |   6 +-
 gdb/testsuite/lib/gdb.exp                     | 151 +++++-
 gdbserver/linux-low.cc                        |   1 +
 gdbserver/server.cc                           |  16 +
 gdbsupport/btrace-common.h                    |   6 +
 32 files changed, 1733 insertions(+), 41 deletions(-)
 create mode 100644 gdb/python/lib/gdb/ptwrite.py
 create mode 100644 gdb/testsuite/gdb.btrace/ptwrite.c
 create mode 100644 gdb/testsuite/gdb.btrace/ptwrite.exp
 create mode 100644 gdb/testsuite/gdb.btrace/x86_64-ptwrite.S

-- 
2.25.4

Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva  
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2 01/12] btrace: Introduce auxiliary instructions.
  2021-06-14 14:50 [PATCH v2 00/12] Extensions for PTWRITE Felix Willgerodt
@ 2021-06-14 14:50 ` Felix Willgerodt
  2021-06-14 15:46   ` Eli Zaretskii
  2021-06-14 14:50 ` [PATCH v2 02/12] btrace: Enable auxiliary instructions in record instruction-history Felix Willgerodt
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: Felix Willgerodt @ 2021-06-14 14:50 UTC (permalink / raw)
  To: markus.t.metzger, gdb-patches

Auxiliary instructions are pseudo instructions pointing to auxiliary data.
This auxiliary data can be printed in all commands displaying (record
function-call-history, record instruction-history) or stepping through
(stepi etc.) the execution history, which will be introduced in the next
commits.

This patch is in preparation for the new ptwrite feature, which is based on
auxiliary instructions.

gdb/ChangeLog:
2021-06-14  Felix Willgerodt  <felix.willgerodt@intel.com>

	* btrace.c (btrace_clear_history): Clear aux_data.
	* btrace.h (btrace_insn_class): Add BTRACE_INSN_AUX.
	(btrace_insn): New union.
	(btrace_thread_info): New member aux_data.

gdb/doc/ChangeLog:
2021-06-14  Felix Willgerodt  <felix.willgerodt@intel.com>

	* gdb.texinfo (Process Record and Replay): Document printing of
	auxiliary information.
---
 gdb/btrace.c        |  2 ++
 gdb/btrace.h        | 24 +++++++++++++++++++++---
 gdb/doc/gdb.texinfo |  4 ++++
 3 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/gdb/btrace.c b/gdb/btrace.c
index 5e689c11d4b..9f117a5e90d 100644
--- a/gdb/btrace.c
+++ b/gdb/btrace.c
@@ -1811,6 +1811,8 @@ btrace_clear_history (struct btrace_thread_info *btinfo)
   btinfo->insn_history = NULL;
   btinfo->call_history = NULL;
   btinfo->replay = NULL;
+
+  btinfo->aux_data.clear ();
 }
 
 /* Clear the branch trace maintenance histories in BTINFO.  */
diff --git a/gdb/btrace.h b/gdb/btrace.h
index 8f6ce32103d..670c182505d 100644
--- a/gdb/btrace.h
+++ b/gdb/btrace.h
@@ -52,7 +52,10 @@ enum btrace_insn_class
   BTRACE_INSN_RETURN,
 
   /* The instruction is an unconditional jump.  */
-  BTRACE_INSN_JUMP
+  BTRACE_INSN_JUMP,
+
+  /* The instruction is a pseudo instruction containing auxiliary data.  */
+  BTRACE_INSN_AUX
 };
 
 /* Instruction flags.  */
@@ -68,8 +71,19 @@ DEF_ENUM_FLAGS_TYPE (enum btrace_insn_flag, btrace_insn_flags);
    This represents a single instruction in a branch trace.  */
 struct btrace_insn
 {
-  /* The address of this instruction.  */
-  CORE_ADDR pc;
+  union
+  {
+    /* The address of this instruction.  Applies to btrace_insn with
+       iclass == BTRACE_INSN_OTHER or
+       iclass == BTRACE_INSN_CALL or
+       iclass == BTRACE_INSN_RETURN or
+       iclass == BTRACE_INSN_JUMP.  */
+    CORE_ADDR pc;
+
+    /* Index into btrace_info::aux_data.  Applies to btrace_insn with
+       iclass == BTRACE_INSN_AUX.  */
+    uint64_t aux_data_index;
+  };
 
   /* The size of this instruction in bytes.  */
   gdb_byte size;
@@ -330,6 +344,10 @@ struct btrace_thread_info
      function segment i will be at index (i - 1).  */
   std::vector<btrace_function> functions;
 
+  /* Optional auxiliary data that is printed in all commands displaying or
+     stepping through the execution history.  */
+  std::vector<std::string> aux_data;
+
   /* The function level offset.  When added to each function's LEVEL,
      this normalizes the function levels such that the smallest level
      becomes zero.  */
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index d09b86cda95..ff4f41941d3 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -7467,6 +7467,10 @@ Moxie, PowerPC, PowerPC64, S/390, and x86 (i386/amd64) running
 GNU/Linux.  Process record and replay can be used both when native
 debugging, and when remote debugging via @code{gdbserver}.
 
+When recording an inferior, @value{GDBN} may print additional auxiliary
+information during stepping commands and commands displaying the execution
+history.
+
 For architecture environments that support process record and replay,
 @value{GDBN} provides the following commands:
 
-- 
2.25.4

Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva  
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2 02/12] btrace: Enable auxiliary instructions in record instruction-history.
  2021-06-14 14:50 [PATCH v2 00/12] Extensions for PTWRITE Felix Willgerodt
  2021-06-14 14:50 ` [PATCH v2 01/12] btrace: Introduce auxiliary instructions Felix Willgerodt
@ 2021-06-14 14:50 ` Felix Willgerodt
  2021-06-14 15:46   ` Eli Zaretskii
  2021-06-14 14:50 ` [PATCH v2 03/12] btrace: Enable auxiliary instructions in record function-call-history Felix Willgerodt
  2021-06-14 14:50 ` [PATCH v2 04/12] btrace: Handle stepping and goto for auxiliary instructions Felix Willgerodt
  3 siblings, 1 reply; 8+ messages in thread
From: Felix Willgerodt @ 2021-06-14 14:50 UTC (permalink / raw)
  To: markus.t.metzger, gdb-patches

Print the auxiliary data when a btrace_insn of type BTRACE_INSN_AUX
is encountered in the instruction-history.  Printing is active by default,
it can be silenced with the /a modifier.

This patch is in preparation for the new ptwrite feature, which is based on
auxiliary instructions.

gdb/ChangeLog:
2021-06-14  Felix Willgerodt  <felix.willgerodt@intel.com>

	* record-btrace.c (btrace_insn_history): Handle BTRACE_INSN_AUX.
	* record.c (get_insn_history_modifiers): Add /a modifier.
	* disasm.h (gdb_disassembly_flag): Add DISASSEMBLY_OMIT_AUX_INSN.

gdb/doc/ChangeLog:
2021-06-14  Felix Willgerodt  <felix.willgerodt@intel.com>

	* gdb.texinfo (record instruction history): Document /a modifier.
---
 gdb/disasm.h        |  1 +
 gdb/doc/gdb.texinfo |  3 +++
 gdb/record-btrace.c | 13 +++++++++++++
 gdb/record.c        |  5 +++++
 4 files changed, 22 insertions(+)

diff --git a/gdb/disasm.h b/gdb/disasm.h
index eb82bc3cd01..4db5bd943eb 100644
--- a/gdb/disasm.h
+++ b/gdb/disasm.h
@@ -31,6 +31,7 @@ enum gdb_disassembly_flag
     DISASSEMBLY_OMIT_PC = (0x1 << 4),
     DISASSEMBLY_SOURCE = (0x1 << 5),
     DISASSEMBLY_SPECULATIVE = (0x1 << 6),
+    DISASSEMBLY_OMIT_AUX_INSN = (0x1 << 7),
   };
 DEF_ENUM_FLAGS_TYPE (enum gdb_disassembly_flag, gdb_disassembly_flags);
 
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index ff4f41941d3..8f49a91347f 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -7883,6 +7883,9 @@ To better align the printed instructions when the trace contains
 instructions from more than one function, the function name may be
 omitted by specifying the @code{/f} modifier.
 
+Printing auxiliary information is enabled by default and can be
+omitted with the @code{/a} modifier.
+
 Speculatively executed instructions are prefixed with @samp{?}.  This
 feature is not available for all recording formats.
 
diff --git a/gdb/record-btrace.c b/gdb/record-btrace.c
index 00affb85d22..96c1b69cb0f 100644
--- a/gdb/record-btrace.c
+++ b/gdb/record-btrace.c
@@ -821,6 +821,19 @@ btrace_insn_history (struct ui_out *uiout,
 	  btrace_ui_out_decode_error (uiout, btrace_insn_get_error (&it),
 				      conf->format);
 	}
+      else if (insn->iclass == BTRACE_INSN_AUX)
+	{
+	  if ((flags & DISASSEMBLY_OMIT_AUX_INSN) != 0)
+	    continue;
+
+	  uiout->field_fmt ("insn-number", "%u", btrace_insn_number (&it));
+	  uiout->text ("\t");
+	  uiout->spaces (3);
+	  uiout->text ("[");
+	  uiout->field_fmt ("aux-data", "%s",
+			    it.btinfo->aux_data[insn->aux_data_index].c_str ());
+	  uiout->text ("]\n");
+	}
       else
 	{
 	  struct disasm_insn dinsn;
diff --git a/gdb/record.c b/gdb/record.c
index 6968c30d930..084c8a12c16 100644
--- a/gdb/record.c
+++ b/gdb/record.c
@@ -486,6 +486,9 @@ get_insn_history_modifiers (const char **arg)
 
 	  switch (*args)
 	    {
+	    case 'a':
+	      modifiers |= DISASSEMBLY_OMIT_AUX_INSN;
+	      break;
 	    case 'm':
 	    case 's':
 	      modifiers |= DISASSEMBLY_SOURCE;
@@ -854,6 +857,8 @@ With a /m or /s 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 a /p modifier, current position markers are omitted.\n\
+With a /a modifier, omits output of auxiliary data, which is enabled \
+by default.\n\
 With no argument, disassembles ten more instructions after the previous \
 disassembly.\n\
 \"record instruction-history -\" disassembles ten instructions before a \
-- 
2.25.4

Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva  
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2 03/12] btrace: Enable auxiliary instructions in record function-call-history.
  2021-06-14 14:50 [PATCH v2 00/12] Extensions for PTWRITE Felix Willgerodt
  2021-06-14 14:50 ` [PATCH v2 01/12] btrace: Introduce auxiliary instructions Felix Willgerodt
  2021-06-14 14:50 ` [PATCH v2 02/12] btrace: Enable auxiliary instructions in record instruction-history Felix Willgerodt
@ 2021-06-14 14:50 ` Felix Willgerodt
  2021-06-14 15:50   ` Eli Zaretskii
  2021-06-14 14:50 ` [PATCH v2 04/12] btrace: Handle stepping and goto for auxiliary instructions Felix Willgerodt
  3 siblings, 1 reply; 8+ messages in thread
From: Felix Willgerodt @ 2021-06-14 14:50 UTC (permalink / raw)
  To: markus.t.metzger, gdb-patches

Print the auxiliary data when a btrace_insn of type BTRACE_INSN_AUX
is encountered in the function-call-history.  Printing is
active by default, it can be silenced with the /a modifier.

This patch is in preparation for the new ptwrite feature, which is based on
auxiliary instructions.

gdb/ChangeLog:
2021-06-14  Felix Willgerodt  <felix.willgerodt@intel.com>

	* btrace.h (btrace_function_flag): Add BFUN_AUX_DECODED.
	* record-btrace.c (btrace_print_aux_insn): New function.
	(btrace_call_history): Handle BTRACE_INSN_AUX.
	* record.c: (get_call_history_modifiers): Add /a modifier.
	* record.h (record_print_flag): New value RECORD_DONT_PRINT_AUX.

gdb/doc/ChangeLog:
2021-06-14  Felix Willgerodt  <felix.willgerodt@intel.com>

	* gdb.texinfo (record function-call-history): Document /a modifier.
---
 gdb/btrace.h        |  6 +++++-
 gdb/doc/gdb.texinfo |  5 +++--
 gdb/record-btrace.c | 21 +++++++++++++++++++++
 gdb/record.c        |  5 +++++
 gdb/record.h        |  5 ++++-
 5 files changed, 38 insertions(+), 4 deletions(-)

diff --git a/gdb/btrace.h b/gdb/btrace.h
index 670c182505d..e6694551c70 100644
--- a/gdb/btrace.h
+++ b/gdb/btrace.h
@@ -105,7 +105,11 @@ enum btrace_function_flag
 
   /* The 'up' link points to a tail call.  This obviously only makes sense
      if bfun_up_links_to_ret is clear.  */
-  BFUN_UP_LINKS_TO_TAILCALL = (1 << 1)
+  BFUN_UP_LINKS_TO_TAILCALL = (1 << 1),
+
+  /* Indicates that at least one auxiliary instruction is in the current
+     function segment.  */
+  BFUN_AUX_DECODED = (1 << 2)
 };
 DEF_ENUM_FLAGS_TYPE (enum btrace_function_flag, btrace_function_flags);
 
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 8f49a91347f..5e4f8e73b7d 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -7940,8 +7940,9 @@ for this instruction sequence (if the @code{/l} modifier is
 specified), and the instructions numbers that form the sequence (if
 the @code{/i} modifier is specified).  The function names are indented
 to reflect the call stack depth if the @code{/c} modifier is
-specified.  The @code{/l}, @code{/i}, and @code{/c} modifiers can be
-given together.
+specified.  Printing auxiliary information is enabled by default and can be
+omitted with the @code{/a} modifier.  The @code{/l}, @code{/i}, @code{/a} and
+@code{/c} modifiers can be given together.
 
 @smallexample
 (@value{GDBP}) @b{list 1, 10}
diff --git a/gdb/record-btrace.c b/gdb/record-btrace.c
index 96c1b69cb0f..2fc273ca229 100644
--- a/gdb/record-btrace.c
+++ b/gdb/record-btrace.c
@@ -1152,6 +1152,23 @@ btrace_get_bfun_name (const struct btrace_function *bfun)
     return "??";
 }
 
+static void
+btrace_print_aux_insn (struct ui_out *uiout,
+		       const struct btrace_function *bfun,
+		       const struct btrace_thread_info *btinfo)
+{
+  for (const auto &i : bfun->insn)
+    {
+      if (i.iclass == BTRACE_INSN_AUX)
+	{
+	  uiout->text ("\t\t[");
+	  uiout->field_fmt ("aux-data", "%s",
+			    btinfo->aux_data[i.aux_data_index].c_str ());
+	  uiout->text ("]\n");
+	}
+    }
+}
+
 /* Disassemble a section of the recorded function trace.  */
 
 static void
@@ -1227,6 +1244,10 @@ btrace_call_history (struct ui_out *uiout,
 	}
 
       uiout->text ("\n");
+
+      if (((flags & RECORD_DONT_PRINT_AUX) == 0)
+	  && ((bfun->flags & BFUN_AUX_DECODED) != 0))
+	btrace_print_aux_insn(uiout, bfun, btinfo);
     }
 }
 
diff --git a/gdb/record.c b/gdb/record.c
index 084c8a12c16..17a3585a1a5 100644
--- a/gdb/record.c
+++ b/gdb/record.c
@@ -636,6 +636,9 @@ get_call_history_modifiers (const char **arg)
 	    case 'c':
 	      modifiers |= RECORD_PRINT_INDENT_CALLS;
 	      break;
+	    case 'a':
+	      modifiers |= RECORD_DONT_PRINT_AUX;
+	      break;
 	    default:
 	      error (_("Invalid modifier: %c."), *args);
 	    }
@@ -881,6 +884,8 @@ Without modifiers, it prints the function name.\n\
 With a /l modifier, the source file and line number range is included.\n\
 With a /i modifier, the instruction number range is included.\n\
 With a /c modifier, the output is indented based on the call stack depth.\n\
+With a /a modifier, omits output of auxiliary data, which is enabled \
+by default.\n\
 With no argument, prints ten more lines after the previous ten-line print.\n\
 \"record function-call-history -\" prints ten lines before a previous ten-line \
 print.\n\
diff --git a/gdb/record.h b/gdb/record.h
index ac3c84d20ea..3213387920b 100644
--- a/gdb/record.h
+++ b/gdb/record.h
@@ -62,7 +62,10 @@ enum record_print_flag
   RECORD_PRINT_INSN_RANGE = (1 << 1),
 
   /* Indent based on call stack depth (if applicable).  */
-  RECORD_PRINT_INDENT_CALLS = (1 << 2)
+  RECORD_PRINT_INDENT_CALLS = (1 << 2),
+
+  /* Deactivate printing auxiliary data (if applicable).  */
+  RECORD_DONT_PRINT_AUX = (1 << 3)
 };
 DEF_ENUM_FLAGS_TYPE (enum record_print_flag, record_print_flags);
 
-- 
2.25.4

Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva  
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2 04/12] btrace: Handle stepping and goto for auxiliary instructions.
  2021-06-14 14:50 [PATCH v2 00/12] Extensions for PTWRITE Felix Willgerodt
                   ` (2 preceding siblings ...)
  2021-06-14 14:50 ` [PATCH v2 03/12] btrace: Enable auxiliary instructions in record function-call-history Felix Willgerodt
@ 2021-06-14 14:50 ` Felix Willgerodt
  3 siblings, 0 replies; 8+ messages in thread
From: Felix Willgerodt @ 2021-06-14 14:50 UTC (permalink / raw)
  To: markus.t.metzger, gdb-patches

Print the auxiliary data when stepping. Don't allow to goto an auxiliary
instruction.

This patch is in preparation for the new ptwrite feature, which is based on
auxiliary instructions.

gdb/ChangeLog:
2021-06-14  Felix Willgerodt  <felix.willgerodt@intel.com>

	* record-btrace.c: (record_btrace_single_step_forward): Handle
	BTRACE_INSN_AUX.
	(record_btrace_single_step_backward): Likewise.
	(record_btrace_goto): Likewise.
---
 gdb/record-btrace.c | 66 ++++++++++++++++++++++++++++++++++++---------
 1 file changed, 53 insertions(+), 13 deletions(-)

diff --git a/gdb/record-btrace.c b/gdb/record-btrace.c
index 2fc273ca229..3d0c344e8e6 100644
--- a/gdb/record-btrace.c
+++ b/gdb/record-btrace.c
@@ -2377,6 +2377,7 @@ record_btrace_single_step_forward (struct thread_info *tp)
 {
   struct btrace_insn_iterator *replay, end, start;
   struct btrace_thread_info *btinfo;
+  struct btrace_insn next_insn;
 
   btinfo = &tp->btrace;
   replay = btinfo->replay;
@@ -2390,9 +2391,13 @@ record_btrace_single_step_forward (struct thread_info *tp)
     return btrace_step_stopped ();
 
   /* Skip gaps during replay.  If we end up at a gap (at the end of the trace),
-     jump back to the instruction at which we started.  */
+     jump back to the instruction at which we started.  If we're stepping a
+     BTRACE_INSN_AUX instruction, print the auxiliary data and skip the
+     instruction.  */
+
   start = *replay;
-  do
+
+  for (;;)
     {
       unsigned int steps;
 
@@ -2400,12 +2405,25 @@ record_btrace_single_step_forward (struct thread_info *tp)
 	 of the execution history.  */
       steps = btrace_insn_next (replay, 1);
       if (steps == 0)
+        {
+          *replay = start;
+          return btrace_step_no_history ();
+        }
+
+      const struct btrace_insn *insn = btrace_insn_get (replay);
+
+      /* If we're stepping a BTRACE_INSN_AUX instruction, print the auxiliary
+	 data and skip the instruction.  */
+      if (insn->iclass == BTRACE_INSN_AUX)
 	{
-	  *replay = start;
-	  return btrace_step_no_history ();
+	  printf_unfiltered ("[%s]\n",
+			     btinfo->aux_data[insn->aux_data_index].c_str ());
+	  continue;
 	}
+
+      if (insn != NULL)
+	break;
     }
-  while (btrace_insn_get (replay) == NULL);
 
   /* Determine the end of the instruction trace.  */
   btrace_insn_end (&end, btinfo);
@@ -2426,6 +2444,7 @@ record_btrace_single_step_backward (struct thread_info *tp)
 {
   struct btrace_insn_iterator *replay, start;
   struct btrace_thread_info *btinfo;
+  struct btrace_insn prev_insn;
 
   btinfo = &tp->btrace;
   replay = btinfo->replay;
@@ -2436,9 +2455,12 @@ record_btrace_single_step_backward (struct thread_info *tp)
 
   /* If we can't step any further, we reached the end of the history.
      Skip gaps during replay.  If we end up at a gap (at the beginning of
-     the trace), jump back to the instruction at which we started.  */
+     the trace), jump back to the instruction at which we started.
+     If we're stepping a BTRACE_INSN_AUX instruction, print the auxiliary
+     data and skip the instruction.  */
   start = *replay;
-  do
+
+  for (;;)
     {
       unsigned int steps;
 
@@ -2448,8 +2470,20 @@ record_btrace_single_step_backward (struct thread_info *tp)
 	  *replay = start;
 	  return btrace_step_no_history ();
 	}
+
+      const struct btrace_insn *insn = btrace_insn_get (replay);
+
+      /* Check if we're stepping a BTRACE_INSN_AUX instruction and skip it.  */
+      if (insn->iclass == BTRACE_INSN_AUX)
+	{
+	  printf_unfiltered ("[%s]\n",
+			     btinfo->aux_data[insn->aux_data_index].c_str ());
+	  continue;
+	}
+
+      if (insn != NULL)
+	break;
     }
-  while (btrace_insn_get (replay) == NULL);
 
   /* Check if we're stepping a breakpoint.
 
@@ -2872,25 +2906,31 @@ record_btrace_target::goto_record_end ()
 /* The goto_record method of target record-btrace.  */
 
 void
-record_btrace_target::goto_record (ULONGEST insn)
+record_btrace_target::goto_record (ULONGEST insn_number)
 {
   struct thread_info *tp;
   struct btrace_insn_iterator it;
   unsigned int number;
   int found;
 
-  number = insn;
+  number = insn_number;
 
   /* Check for wrap-arounds.  */
-  if (number != insn)
+  if (number != insn_number)
     error (_("Instruction number out of range."));
 
   tp = require_btrace_thread ();
 
   found = btrace_find_insn_by_number (&it, &tp->btrace, number);
 
-  /* Check if the instruction could not be found or is a gap.  */
-  if (found == 0 || btrace_insn_get (&it) == NULL)
+  /* Check if the instruction could not be found or is a gap or an
+     auxilliary instruction.  */
+  if (found == 0)
+    error (_("No such instruction."));
+
+  const struct btrace_insn *insn = btrace_insn_get (&it);
+
+  if ((insn == NULL) || (insn->iclass == BTRACE_INSN_AUX))
     error (_("No such instruction."));
 
   record_btrace_set_replay (tp, &it);
-- 
2.25.4

Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva  
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 02/12] btrace: Enable auxiliary instructions in record instruction-history.
  2021-06-14 14:50 ` [PATCH v2 02/12] btrace: Enable auxiliary instructions in record instruction-history Felix Willgerodt
@ 2021-06-14 15:46   ` Eli Zaretskii
  0 siblings, 0 replies; 8+ messages in thread
From: Eli Zaretskii @ 2021-06-14 15:46 UTC (permalink / raw)
  To: Felix Willgerodt; +Cc: markus.t.metzger, gdb-patches

> Date: Mon, 14 Jun 2021 16:50:15 +0200
> From: Felix Willgerodt via Gdb-patches <gdb-patches@sourceware.org>
> 
> Print the auxiliary data when a btrace_insn of type BTRACE_INSN_AUX
> is encountered in the instruction-history.  Printing is active by default,
> it can be silenced with the /a modifier.
> 
> This patch is in preparation for the new ptwrite feature, which is based on
> auxiliary instructions.
> 
> gdb/ChangeLog:
> 2021-06-14  Felix Willgerodt  <felix.willgerodt@intel.com>
> 
> 	* record-btrace.c (btrace_insn_history): Handle BTRACE_INSN_AUX.
> 	* record.c (get_insn_history_modifiers): Add /a modifier.
> 	* disasm.h (gdb_disassembly_flag): Add DISASSEMBLY_OMIT_AUX_INSN.
> 
> gdb/doc/ChangeLog:
> 2021-06-14  Felix Willgerodt  <felix.willgerodt@intel.com>
> 
> 	* gdb.texinfo (record instruction history): Document /a modifier.

Thanks, the documentation part is OK.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 01/12] btrace: Introduce auxiliary instructions.
  2021-06-14 14:50 ` [PATCH v2 01/12] btrace: Introduce auxiliary instructions Felix Willgerodt
@ 2021-06-14 15:46   ` Eli Zaretskii
  0 siblings, 0 replies; 8+ messages in thread
From: Eli Zaretskii @ 2021-06-14 15:46 UTC (permalink / raw)
  To: Felix Willgerodt; +Cc: markus.t.metzger, gdb-patches

> Date: Mon, 14 Jun 2021 16:50:14 +0200
> From: Felix Willgerodt via Gdb-patches <gdb-patches@sourceware.org>
> 
> Auxiliary instructions are pseudo instructions pointing to auxiliary data.
> This auxiliary data can be printed in all commands displaying (record
> function-call-history, record instruction-history) or stepping through
> (stepi etc.) the execution history, which will be introduced in the next
> commits.
> 
> This patch is in preparation for the new ptwrite feature, which is based on
> auxiliary instructions.
> 
> gdb/ChangeLog:
> 2021-06-14  Felix Willgerodt  <felix.willgerodt@intel.com>
> 
> 	* btrace.c (btrace_clear_history): Clear aux_data.
> 	* btrace.h (btrace_insn_class): Add BTRACE_INSN_AUX.
> 	(btrace_insn): New union.
> 	(btrace_thread_info): New member aux_data.
> 
> gdb/doc/ChangeLog:
> 2021-06-14  Felix Willgerodt  <felix.willgerodt@intel.com>
> 
> 	* gdb.texinfo (Process Record and Replay): Document printing of
> 	auxiliary information.

The documentation part is OK, thanks.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 03/12] btrace: Enable auxiliary instructions in record function-call-history.
  2021-06-14 14:50 ` [PATCH v2 03/12] btrace: Enable auxiliary instructions in record function-call-history Felix Willgerodt
@ 2021-06-14 15:50   ` Eli Zaretskii
  0 siblings, 0 replies; 8+ messages in thread
From: Eli Zaretskii @ 2021-06-14 15:50 UTC (permalink / raw)
  To: Felix Willgerodt; +Cc: markus.t.metzger, gdb-patches

> Date: Mon, 14 Jun 2021 16:50:16 +0200
> From: Felix Willgerodt via Gdb-patches <gdb-patches@sourceware.org>
> 
> Print the auxiliary data when a btrace_insn of type BTRACE_INSN_AUX
> is encountered in the function-call-history.  Printing is
> active by default, it can be silenced with the /a modifier.
> 
> This patch is in preparation for the new ptwrite feature, which is based on
> auxiliary instructions.
> 
> gdb/ChangeLog:
> 2021-06-14  Felix Willgerodt  <felix.willgerodt@intel.com>
> 
> 	* btrace.h (btrace_function_flag): Add BFUN_AUX_DECODED.
> 	* record-btrace.c (btrace_print_aux_insn): New function.
> 	(btrace_call_history): Handle BTRACE_INSN_AUX.
> 	* record.c: (get_call_history_modifiers): Add /a modifier.
> 	* record.h (record_print_flag): New value RECORD_DONT_PRINT_AUX.
> 
> gdb/doc/ChangeLog:
> 2021-06-14  Felix Willgerodt  <felix.willgerodt@intel.com>
> 
> 	* gdb.texinfo (record function-call-history): Document /a modifier.

The documentation part is OK, thanks.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-06-14 15:50 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-14 14:50 [PATCH v2 00/12] Extensions for PTWRITE Felix Willgerodt
2021-06-14 14:50 ` [PATCH v2 01/12] btrace: Introduce auxiliary instructions Felix Willgerodt
2021-06-14 15:46   ` Eli Zaretskii
2021-06-14 14:50 ` [PATCH v2 02/12] btrace: Enable auxiliary instructions in record instruction-history Felix Willgerodt
2021-06-14 15:46   ` Eli Zaretskii
2021-06-14 14:50 ` [PATCH v2 03/12] btrace: Enable auxiliary instructions in record function-call-history Felix Willgerodt
2021-06-14 15:50   ` Eli Zaretskii
2021-06-14 14:50 ` [PATCH v2 04/12] btrace: Handle stepping and goto for auxiliary instructions Felix Willgerodt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).