[5/7] btrace: Add support for IRET events.

Message ID 20240902114949.918485-6-felix.willgerodt@intel.com
State New
Headers
Series btrace: Intel PT event tracing support |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Test passed

Commit Message

Felix Willgerodt Sept. 2, 2024, 11:49 a.m. UTC
  This is similar to the previous events that we added.
---
 gdb/btrace.c                                   | 14 ++++++++++++++
 gdb/testsuite/gdb.btrace/event-tracing-gap.exp |  4 ++++
 gdb/testsuite/gdb.btrace/event-tracing.exp     |  2 ++
 3 files changed, 20 insertions(+)
  

Comments

Metzger, Markus T Sept. 10, 2024, 2:42 p.m. UTC | #1
Hello Felix,

>     "\\\[interrupt: vector = 0x3 \\\(#bp\\\)(, ip = 0x\[0-9a-fA-F\]+)?\\\]"
>+    "\\\[iret(: ip = $hex)?\\\]"
>     "\[0-9\]+\tmain"

Wouldn't I always have an interrupt event at the end of the trace that
brought me to GDB?

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
  
Felix Willgerodt Sept. 11, 2024, 2:49 p.m. UTC | #2
> -----Original Message-----
> From: Metzger, Markus T <markus.t.metzger@intel.com>
> Sent: Dienstag, 10. September 2024 16:43
> To: Willgerodt, Felix <felix.willgerodt@intel.com>
> Cc: gdb-patches@sourceware.org
> Subject: RE: [PATCH 5/7] btrace: Add support for IRET events.
> 
> Hello Felix,
> 
> >     "\\\[interrupt: vector = 0x3 \\\(#bp\\\)(, ip = 0x\[0-9a-fA-F\]+)?\\\]"
> >+    "\\\[iret(: ip = $hex)?\\\]"
> >     "\[0-9\]+\tmain"
> 
> Wouldn't I always have an interrupt event at the end of the trace that
> brought me to GDB?
> 
> Thanks,
> Markus.

Yes you do have one here in the output, we just don't test it.

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 4b182a67c64..bcfa11444e7 100644
--- a/gdb/btrace.c
+++ b/gdb/btrace.c
@@ -1412,6 +1412,20 @@  handle_pt_insn_events (struct btrace_thread_info *btinfo,
 	    handle_pt_aux_insn (btinfo, aux_string, pc);
 	    break;
 	  }
+
+	case ptev_iret:
+	  {
+	    std::string aux_string = std::string (_("iret"));
+
+	    if (event.ip_suppressed == 0)
+	      {
+		pc = event.variant.iret.ip;
+		aux_string += std::string (": ip = ") + hex_string (pc);
+	      }
+
+	    handle_pt_aux_insn (btinfo, aux_string, pc);
+	    break;
+	  }
 #endif /* defined (LIBIPT_VERSION >= 0x201) */
 	}
     }
diff --git a/gdb/testsuite/gdb.btrace/event-tracing-gap.exp b/gdb/testsuite/gdb.btrace/event-tracing-gap.exp
index 5d470bb9d62..57e0e6d438d 100644
--- a/gdb/testsuite/gdb.btrace/event-tracing-gap.exp
+++ b/gdb/testsuite/gdb.btrace/event-tracing-gap.exp
@@ -61,13 +61,17 @@  gdb_continue_to_breakpoint "break at bp_2" ".*$srcfile:$bp_2.*"
 # gdb_test_sequence and check only for events that we can control.
 gdb_test_sequence "record function-call-history" "function-call-history" {
     "\[0-9\]+\tmain"
+    "\\\[iret(: ip = $hex)?\\\]"
     "\\\[interrupt: vector = 0x1 \\\(#db\\\)(, ip = 0x\[0-9a-fA-F\]+)?\\\]"
+    "\\\[iret(: ip = $hex)?\\\]"
     "\[0-9\]+\t\\\[non-contiguous\\\]"
     "\[0-9\]+\tsquare"
     "\\\[interrupt: vector = 0x3 \\\(#bp\\\)(, ip = 0x\[0-9a-fA-F\]+)?\\\]"
+    "\\\[iret(: ip = $hex)?\\\]"
     "\[0-9\]+\t\\\[non-contiguous\\\]"
     "\[0-9\]+\tmain"
     "\[0-9\]+\tsquare"
     "\\\[interrupt: vector = 0x3 \\\(#bp\\\)(, ip = 0x\[0-9a-fA-F\]+)?\\\]"
+    "\\\[iret(: ip = $hex)?\\\]"
     "\[0-9\]+\tmain"
 }
diff --git a/gdb/testsuite/gdb.btrace/event-tracing.exp b/gdb/testsuite/gdb.btrace/event-tracing.exp
index 1ac5d27fa81..ee3a05421cc 100644
--- a/gdb/testsuite/gdb.btrace/event-tracing.exp
+++ b/gdb/testsuite/gdb.btrace/event-tracing.exp
@@ -37,7 +37,9 @@  gdb_test "continue" "Program received signal SIGSEGV, Segmentation fault.*"
 # Test printing of at least one INTERRUPT event.
 gdb_test "record function-call-history" [multi_line \
   "$decimal\tmain" \
+  "\t  \\\[iret(: ip = $hex)?\\\]" \
   "\t  \\\[interrupt: vector = 0x1 \\\(#db\\\), ip = $hex\\\]" \
+  "\t  \\\[iret(: ip = $hex)?\\\]" \
   "$decimal\tcall1" \
   "$decimal\tmain" \
   "\t  \\\[interrupt: vector = 0xe \\\(#pf\\\), cr2 = 0x0, ip = $hex\\\]"