diff mbox

[v7] Enable tracing of pseudo-registers on ARM

Message ID 1456491775-29750-1-git-send-email-antoine.tremblay@ericsson.com
State New
Headers show

Commit Message

Antoine Tremblay Feb. 26, 2016, 1:02 p.m. UTC
In this v7:
* Fixed according to comments about the test case.
-
This patch implements the ax_pseudo_register_push_stack and
ax_pseudo_register_collect gdbarch functions so that a pseudo-register can
be traced.

No regressions, tested on ubuntu 14.04 ARMv7 and x86.
With gdbserver-{native,extended} / { -marm -mthumb }

gdb/ChangeLog:

	* arm-tdep.c (arm_pseudo_register_to_register): New function.
	(arm_ax_pseudo_register_collect): New function.
	(arm_ax_pseudo_register_push_stack): New function.
	(arm_gdbarch_init): Set
	gdbarch_ax_pseudo_register_{collect,push_stack} functions.

gdb/testsuite/ChangeLog:

	* gdb.trace/tracefile-pseudo-reg.c: Include arm_neon.h if on arm.
	(main): Add a register variable and a tracepoint label.
	* gdb.trace/tracefile-pseudo-reg.exp): Add arm pseudo register
	tracing test with s5 pseudo register.
---
 gdb/arm-tdep.c                                   | 68 ++++++++++++++++++++++++
 gdb/testsuite/gdb.trace/tracefile-pseudo-reg.c   | 14 ++++-
 gdb/testsuite/gdb.trace/tracefile-pseudo-reg.exp | 35 +++++++++---
 3 files changed, 108 insertions(+), 9 deletions(-)

Comments

Yao Qi Feb. 26, 2016, 2:14 p.m. UTC | #1
Antoine Tremblay <antoine.tremblay@ericsson.com> writes:

> gdb/testsuite/ChangeLog:
>
> 	* gdb.trace/tracefile-pseudo-reg.c: Include arm_neon.h if on arm.

arm_neon.h is not included now, but stdint.h is included.

> 	(main): Add a register variable and a tracepoint label.
> 	* gdb.trace/tracefile-pseudo-reg.exp): Add arm pseudo register
> 	tracing test with s5 pseudo register.

> diff --git a/gdb/testsuite/gdb.trace/tracefile-pseudo-reg.c b/gdb/testsuite/gdb.trace/tracefile-pseudo-reg.c
> index 3cc3ec0..33761c1 100644
> --- a/gdb/testsuite/gdb.trace/tracefile-pseudo-reg.c
> +++ b/gdb/testsuite/gdb.trace/tracefile-pseudo-reg.c
> @@ -16,11 +16,15 @@
>     along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
>  
>  /*
> - * Test program for reading target description from tfile: collects AVX
> - * registers on x86_64.
> + * Test program for reading target description from tfile: collects pseudo
> + * register on the target.
>   */

The comment format doesn't comply to GNU coding standard.  It should be

  /* Test program for reading target description from tfile: collects pseudo
      registers on the target.  */

>  
> +#if (defined __x86_64__)
>  #include <immintrin.h>
> +#elif (defined __arm__)
> +#include <stdint.h>
> +#endif
>  
>  void
>  dummy (void)
> @@ -35,6 +39,7 @@ end (void)
>  int
>  main (void)
>  {
> +#if (defined __x86_64__)
>    /* Strictly speaking, it should be ymm15 (xmm15 is 128-bit), but gcc older
>       than 4.9 doesn't recognize "ymm15" as a valid register name.  */
>    register __v8si a asm("xmm15") = {
> @@ -48,6 +53,11 @@ main (void)
>      0x12340008,
>    };
>    asm volatile ("traceme: call dummy" : : "x" (a));
> +#elif (defined __arm__)
> +  register uint32_t a asm("s5") = 0x3f800000; /* 1. */
> +  asm volatile ("traceme: bl dummy" : : "x" (a));
> +#endif
> +
>    end ();
>    return 0;
>  }
> diff --git a/gdb/testsuite/gdb.trace/tracefile-pseudo-reg.exp b/gdb/testsuite/gdb.trace/tracefile-pseudo-reg.exp
> index 4c52c64..33677a1 100644
> --- a/gdb/testsuite/gdb.trace/tracefile-pseudo-reg.exp
> +++ b/gdb/testsuite/gdb.trace/tracefile-pseudo-reg.exp
> @@ -12,8 +12,8 @@
>  # You should have received a copy of the GNU General Public License
>  # along with this program.  If not, see <http://www.gnu.org/licenses/>.
>  
> -if { ! [is_amd64_regs_target] } {
> -    verbose "Skipping tfile AVX test (target is not x86_64)."
> +if { ! [is_amd64_regs_target] && ! [istarget "arm*-*-*"] } {
> +    verbose "Skipping tracefile pseudo register tests, target is not supported."
>      return
>  }
>  
> @@ -21,8 +21,14 @@ load_lib "trace-support.exp"
>  
>  standard_testfile
>  
> +set add_flags ""
> +
> +if { [is_amd64_regs_target] } {
> + set add_flags "-mavx"
> +}
> +
>  if {[prepare_for_testing $testfile.exp $testfile $srcfile \
> -     [list debug additional_flags=-mavx]]} {
> +     [list debug additional_flags=$add_flags]]} {
>      return -1
>  }
>  
> @@ -36,20 +42,31 @@ if ![gdb_target_supports_trace] {
>      return -1
>  }
>  
> -gdb_test_multiple "print \$ymm15" "check for AVX support" {
> +if { [is_amd64_regs_target] } {
> +    set reg "\$ymm15"
> +    set reg_message "check for AVX support"
> +} elseif { [istarget "arm*-*-*"] } {
> +    set reg "\$s5"
> +    set reg_message "check for register $reg"
> +}

We can set reg_message out of the condition block,

if { [is_amd64_regs_target] } {
    set reg "\$ymm15"
} elseif { [istarget "arm*-*-*"] } {
    set reg "\$s5"
}

set reg_message "check for register $reg"
Antoine Tremblay Feb. 26, 2016, 2:57 p.m. UTC | #2
Yao Qi writes:

> Antoine Tremblay <antoine.tremblay@ericsson.com> writes:
>
>> gdb/testsuite/ChangeLog:
>>
>> 	* gdb.trace/tracefile-pseudo-reg.c: Include arm_neon.h if on arm.
>
> arm_neon.h is not included now, but stdint.h is included.

Yes this is due to the usage of uint32_t.

>
>> 	(main): Add a register variable and a tracepoint label.
>> 	* gdb.trace/tracefile-pseudo-reg.exp): Add arm pseudo register
>> 	tracing test with s5 pseudo register.
>
>> diff --git a/gdb/testsuite/gdb.trace/tracefile-pseudo-reg.c b/gdb/testsuite/gdb.trace/tracefile-pseudo-reg.c
>> index 3cc3ec0..33761c1 100644
>> --- a/gdb/testsuite/gdb.trace/tracefile-pseudo-reg.c
>> +++ b/gdb/testsuite/gdb.trace/tracefile-pseudo-reg.c
>> @@ -16,11 +16,15 @@
>>     along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
>>  
>>  /*
>> - * Test program for reading target description from tfile: collects AVX
>> - * registers on x86_64.
>> + * Test program for reading target description from tfile: collects pseudo
>> + * register on the target.
>>   */
>
> The comment format doesn't comply to GNU coding standard.  It should be
>
>   /* Test program for reading target description from tfile: collects pseudo
>       registers on the target.  */
>

Fixed.

>>  
>> +#if (defined __x86_64__)
>>  #include <immintrin.h>
>> +#elif (defined __arm__)
>> +#include <stdint.h>
>> +#endif
>>  
>>  void
>>  dummy (void)
>> @@ -35,6 +39,7 @@ end (void)
>>  int
>>  main (void)
>>  {
>> +#if (defined __x86_64__)
>>    /* Strictly speaking, it should be ymm15 (xmm15 is 128-bit), but gcc older
>>       than 4.9 doesn't recognize "ymm15" as a valid register name.  */
>>    register __v8si a asm("xmm15") = {
>> @@ -48,6 +53,11 @@ main (void)
>>      0x12340008,
>>    };
>>    asm volatile ("traceme: call dummy" : : "x" (a));
>> +#elif (defined __arm__)
>> +  register uint32_t a asm("s5") = 0x3f800000; /* 1. */
>> +  asm volatile ("traceme: bl dummy" : : "x" (a));
>> +#endif
>> +
>>    end ();
>>    return 0;
>>  }
>> diff --git a/gdb/testsuite/gdb.trace/tracefile-pseudo-reg.exp b/gdb/testsuite/gdb.trace/tracefile-pseudo-reg.exp
>> index 4c52c64..33677a1 100644
>> --- a/gdb/testsuite/gdb.trace/tracefile-pseudo-reg.exp
>> +++ b/gdb/testsuite/gdb.trace/tracefile-pseudo-reg.exp
>> @@ -12,8 +12,8 @@
>>  # You should have received a copy of the GNU General Public License
>>  # along with this program.  If not, see <http://www.gnu.org/licenses/>.
>>  
>> -if { ! [is_amd64_regs_target] } {
>> -    verbose "Skipping tfile AVX test (target is not x86_64)."
>> +if { ! [is_amd64_regs_target] && ! [istarget "arm*-*-*"] } {
>> +    verbose "Skipping tracefile pseudo register tests, target is not supported."
>>      return
>>  }
>>  
>> @@ -21,8 +21,14 @@ load_lib "trace-support.exp"
>>  
>>  standard_testfile
>>  
>> +set add_flags ""
>> +
>> +if { [is_amd64_regs_target] } {
>> + set add_flags "-mavx"
>> +}
>> +
>>  if {[prepare_for_testing $testfile.exp $testfile $srcfile \
>> -     [list debug additional_flags=-mavx]]} {
>> +     [list debug additional_flags=$add_flags]]} {
>>      return -1
>>  }
>>  
>> @@ -36,20 +42,31 @@ if ![gdb_target_supports_trace] {
>>      return -1
>>  }
>>  
>> -gdb_test_multiple "print \$ymm15" "check for AVX support" {
>> +if { [is_amd64_regs_target] } {
>> +    set reg "\$ymm15"
>> +    set reg_message "check for AVX support"
>> +} elseif { [istarget "arm*-*-*"] } {
>> +    set reg "\$s5"
>> +    set reg_message "check for register $reg"
>> +}
>
> We can set reg_message out of the condition block,
>
> if { [is_amd64_regs_target] } {
>     set reg "\$ymm15"
> } elseif { [istarget "arm*-*-*"] } {
>     set reg "\$s5"
> }
>
> set reg_message "check for register $reg"

OK.

Patch v8 follows.
diff mbox

Patch

diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index 2151ffa..6d50e9e 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -8716,6 +8716,70 @@  arm_pseudo_write (struct gdbarch *gdbarch, struct regcache *regcache,
     }
 }
 
+/* Map the pseudo register number REG to the proper register number.  */
+
+static int
+arm_pseudo_register_to_register (struct gdbarch *gdbarch, int reg)
+{
+  int double_regnum = 0;
+  int num_regs = gdbarch_num_regs (gdbarch);
+  char name_buf[4];
+
+  /* Single precision pseudo registers. s0-s31.  */
+  if (reg >= num_regs && reg < num_regs + 32)
+    {
+      xsnprintf (name_buf, sizeof (name_buf), "d%d", (reg - num_regs) / 2);
+      double_regnum = user_reg_map_name_to_regnum (gdbarch, name_buf,
+						   strlen (name_buf));
+    }
+  /* Quadruple precision pseudo regisers. q0-q15.  */
+  else if (reg >= num_regs + 32 && reg < num_regs + 32 + 16)
+    {
+      xsnprintf (name_buf, sizeof (name_buf), "d%d", (reg - num_regs - 32) * 2);
+      double_regnum = user_reg_map_name_to_regnum (gdbarch, name_buf,
+						   strlen (name_buf));
+    }
+  /* Error bad register number.  */
+  else
+    return -1;
+
+  return double_regnum;
+}
+
+/* Implementation of the ax_pseudo_register_collect gdbarch function.  */
+
+static int
+arm_ax_pseudo_register_collect (struct gdbarch *gdbarch,
+				struct agent_expr *ax, int reg)
+{
+  int rawnum = arm_pseudo_register_to_register (gdbarch, reg);
+
+  /* Error.  */
+  if (rawnum < 0)
+    return 1;
+
+  ax_reg_mask (ax, rawnum);
+
+  return 0;
+}
+
+/* Implementation of the ax_pseudo_register_push_stack gdbarch function.  */
+
+static int
+arm_ax_pseudo_register_push_stack (struct gdbarch *gdbarch,
+				   struct agent_expr *ax, int reg)
+{
+  int rawnum = arm_pseudo_register_to_register (gdbarch, reg);
+
+  /* Error.  */
+  if (rawnum < 0)
+    return 1;
+
+  ax_reg (ax, rawnum);
+
+  return 0;
+}
+
 static struct value *
 value_of_arm_user_reg (struct frame_info *frame, const void *baton)
 {
@@ -9377,6 +9441,10 @@  arm_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
       set_gdbarch_num_pseudo_regs (gdbarch, num_pseudos);
       set_gdbarch_pseudo_register_read (gdbarch, arm_pseudo_read);
       set_gdbarch_pseudo_register_write (gdbarch, arm_pseudo_write);
+      set_gdbarch_ax_pseudo_register_push_stack
+	(gdbarch, arm_ax_pseudo_register_push_stack);
+      set_gdbarch_ax_pseudo_register_collect
+	(gdbarch, arm_ax_pseudo_register_collect);
     }
 
   if (tdesc_data)
diff --git a/gdb/testsuite/gdb.trace/tracefile-pseudo-reg.c b/gdb/testsuite/gdb.trace/tracefile-pseudo-reg.c
index 3cc3ec0..33761c1 100644
--- a/gdb/testsuite/gdb.trace/tracefile-pseudo-reg.c
+++ b/gdb/testsuite/gdb.trace/tracefile-pseudo-reg.c
@@ -16,11 +16,15 @@ 
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 /*
- * Test program for reading target description from tfile: collects AVX
- * registers on x86_64.
+ * Test program for reading target description from tfile: collects pseudo
+ * register on the target.
  */
 
+#if (defined __x86_64__)
 #include <immintrin.h>
+#elif (defined __arm__)
+#include <stdint.h>
+#endif
 
 void
 dummy (void)
@@ -35,6 +39,7 @@  end (void)
 int
 main (void)
 {
+#if (defined __x86_64__)
   /* Strictly speaking, it should be ymm15 (xmm15 is 128-bit), but gcc older
      than 4.9 doesn't recognize "ymm15" as a valid register name.  */
   register __v8si a asm("xmm15") = {
@@ -48,6 +53,11 @@  main (void)
     0x12340008,
   };
   asm volatile ("traceme: call dummy" : : "x" (a));
+#elif (defined __arm__)
+  register uint32_t a asm("s5") = 0x3f800000; /* 1. */
+  asm volatile ("traceme: bl dummy" : : "x" (a));
+#endif
+
   end ();
   return 0;
 }
diff --git a/gdb/testsuite/gdb.trace/tracefile-pseudo-reg.exp b/gdb/testsuite/gdb.trace/tracefile-pseudo-reg.exp
index 4c52c64..33677a1 100644
--- a/gdb/testsuite/gdb.trace/tracefile-pseudo-reg.exp
+++ b/gdb/testsuite/gdb.trace/tracefile-pseudo-reg.exp
@@ -12,8 +12,8 @@ 
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-if { ! [is_amd64_regs_target] } {
-    verbose "Skipping tfile AVX test (target is not x86_64)."
+if { ! [is_amd64_regs_target] && ! [istarget "arm*-*-*"] } {
+    verbose "Skipping tracefile pseudo register tests, target is not supported."
     return
 }
 
@@ -21,8 +21,14 @@  load_lib "trace-support.exp"
 
 standard_testfile
 
+set add_flags ""
+
+if { [is_amd64_regs_target] } {
+ set add_flags "-mavx"
+}
+
 if {[prepare_for_testing $testfile.exp $testfile $srcfile \
-     [list debug additional_flags=-mavx]]} {
+     [list debug additional_flags=$add_flags]]} {
     return -1
 }
 
@@ -36,20 +42,31 @@  if ![gdb_target_supports_trace] {
     return -1
 }
 
-gdb_test_multiple "print \$ymm15" "check for AVX support" {
+if { [is_amd64_regs_target] } {
+    set reg "\$ymm15"
+    set reg_message "check for AVX support"
+} elseif { [istarget "arm*-*-*"] } {
+    set reg "\$s5"
+    set reg_message "check for register $reg"
+}
+
+gdb_test_multiple "print $reg" $reg_message {
     -re " = void.*$gdb_prompt $" {
-	verbose "Skipping tfile AVX test (target doesn't support AVX)."
+	verbose "Skipping tracefile pseudo register tests, target is not supported."
 	return
     }
     -re " = \\{.*}.*$gdb_prompt $" {
 	# All is well.
     }
+    -re " = 0.*$gdb_prompt $" {
+	# All is well.
+    }
 }
 
 gdb_test "trace traceme" ".*"
 
 gdb_trace_setactions "set actions for tracepoint" "" \
-	"collect \$ymm15" "^$"
+	"collect $reg" "^$"
 
 gdb_breakpoint "end"
 
@@ -70,4 +87,8 @@  gdb_test "target tfile ${tracefile}.tf" "" "change to tfile target" \
 
 gdb_test "tfind 0" "Found trace frame 0, tracepoint .*"
 
-gdb_test "print/x \$ymm15.v8_int32" " = \\{0x12340001, .*, 0x12340008}"
+if { [is_amd64_regs_target] } {
+    gdb_test "print/x \$ymm15.v8_int32" " = \\{0x12340001, .*, 0x12340008}"
+} elseif { [istarget "arm*-*-*"] } {
+    gdb_test "print \$s5" "1"
+}