[v11,01/10] btrace: Introduce auxiliary instructions.

Message ID 20240725090937.3997414-2-felix.willgerodt@intel.com
State New
Headers
Series Extensions for PTWRITE |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-arm fail Build failed
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 fail Build failed

Commit Message

Willgerodt, Felix July 25, 2024, 9:09 a.m. UTC
  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.

Approved-By: Markus Metzger <markus.t.metzger@intel.com>
Reviewed-By: Eli Zaretskii <eliz@gnu.org>
---
 gdb/btrace.c        |  5 +++++
 gdb/btrace.h        | 24 +++++++++++++++++++++---
 gdb/doc/gdb.texinfo |  3 +++
 3 files changed, 29 insertions(+), 3 deletions(-)
  

Comments

Eli Zaretskii July 25, 2024, 10:54 a.m. UTC | #1
> From: Felix Willgerodt <felix.willgerodt@intel.com>
> Date: Thu, 25 Jul 2024 11:09:28 +0200
> 
> 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.
> 
> Approved-By: Markus Metzger <markus.t.metzger@intel.com>
> Reviewed-By: Eli Zaretskii <eliz@gnu.org>
> ---
>  gdb/btrace.c        |  5 +++++
>  gdb/btrace.h        | 24 +++++++++++++++++++++---
>  gdb/doc/gdb.texinfo |  3 +++
>  3 files changed, 29 insertions(+), 3 deletions(-)

Thanks, the gdb.texinfo part of this is okay.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
  
Metzger, Markus T July 25, 2024, 2:01 p.m. UTC | #2
Hello Felix,

>+  if (insn.iclass == BTRACE_INSN_AUX)
>+    bfun->flags |= BFUN_CONTAINS_AUX;

Looks like we're introducing BFUN_CONTAINS_AUX in patch 3.

Could you check the series for intermittent build (and gdb.btrace test) fails?

Thanks,
Markus.
Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de
Managing Directors: Sean Fennelly, Jeffrey Schneiderman, Tiffany Doon Silva
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928
  
Willgerodt, Felix July 26, 2024, 8:36 a.m. UTC | #3
> -----Original Message-----
> From: Metzger, Markus T <markus.t.metzger@intel.com>
> Sent: Donnerstag, 25. Juli 2024 16:01
> To: Willgerodt, Felix <felix.willgerodt@intel.com>
> Cc: gdb-patches@sourceware.org
> Subject: RE: [PATCH v11 01/10] btrace: Introduce auxiliary instructions.
> 
> Hello Felix,
> 
> >+  if (insn.iclass == BTRACE_INSN_AUX)
> >+    bfun->flags |= BFUN_CONTAINS_AUX;
> 
> Looks like we're introducing BFUN_CONTAINS_AUX in patch 3.
> 
> Could you check the series for intermittent build (and gdb.btrace test) fails?
> 
> Thanks,
> Markus.

My bad, seems like I chose the wrong fixup target. I will add it to Patch 3.
And I have build and tested all 10 patches now by hand,
I didn't see any other such problem.

Thanks,
Felix
Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de
Managing Directors: Sean Fennelly, Jeffrey Schneiderman, Tiffany Doon Silva
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928
  

Patch

diff --git a/gdb/btrace.c b/gdb/btrace.c
index 66f20ee3fad..e6b94dd7c62 100644
--- a/gdb/btrace.c
+++ b/gdb/btrace.c
@@ -665,6 +665,9 @@  ftrace_update_insns (struct btrace_function *bfun, const btrace_insn &insn)
 {
   bfun->insn.push_back (insn);
 
+  if (insn.iclass == BTRACE_INSN_AUX)
+    bfun->flags |= BFUN_CONTAINS_AUX;
+
   if (record_debug > 1)
     ftrace_debug (bfun, "update insn");
 }
@@ -1820,6 +1823,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 f05ec2bca04..0086759257f 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 information 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 147b8d4c24e..b5bae5077d7 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -7784,6 +7784,9 @@  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 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: