[gdb/testsuite] Fix gdb.arch/arm-pseudo-unwind.exp with unix/mthumb

Message ID 20240717113409.10915-1-tdevries@suse.de
State Committed
Headers
Series [gdb/testsuite] Fix gdb.arch/arm-pseudo-unwind.exp with unix/mthumb |

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-arm success Test passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 warning Patch is already merged

Commit Message

Tom de Vries July 17, 2024, 11:34 a.m. UTC
  When running test-case gdb.arch/arm-pseudo-unwind.exp with target board
unix/mthumb, we run into:
...
(gdb) continue^M
Continuing.^M
^M
Program received signal SIGILL, Illegal instruction.^M
0x00400f38 in ?? ()^M
(gdb) FAIL: $exp: continue to breakpoint: continue to callee
...

The test-case attempts to force arm-pseudo-unwind.c to be compiled in arm mode
using additional_flags=-marm, but that's overridden by using target board
unix/mthumb.

This causes function main to be in thumb mode, and consequently function
caller (which is called from main) is is executed as if it's in thumb mode,
while it's actually in arm mode.

Fix this by adding an intermediate function caller_trampoline in
arm-pseudo-unwind.c, and hardcoding it to arm mode using
__attribute__((target("arm"))).

Likewise for test-case gdb.arch/arm-pseudo-unwind-legacy.exp.

Tested on arm-linux.
---
 gdb/testsuite/gdb.arch/arm-pseudo-unwind-legacy.c | 9 ++++++++-
 gdb/testsuite/gdb.arch/arm-pseudo-unwind.c        | 9 ++++++++-
 2 files changed, 16 insertions(+), 2 deletions(-)


base-commit: dfeb912e160b3eae596a4fd92cc14d0f5e90ee68
  

Comments

Luis Machado July 17, 2024, 12:35 p.m. UTC | #1
On 7/17/24 12:34, Tom de Vries wrote:
> When running test-case gdb.arch/arm-pseudo-unwind.exp with target board
> unix/mthumb, we run into:
> ...
> (gdb) continue^M
> Continuing.^M
> ^M
> Program received signal SIGILL, Illegal instruction.^M
> 0x00400f38 in ?? ()^M
> (gdb) FAIL: $exp: continue to breakpoint: continue to callee
> ...
> 
> The test-case attempts to force arm-pseudo-unwind.c to be compiled in arm mode
> using additional_flags=-marm, but that's overridden by using target board
> unix/mthumb.
> 
> This causes function main to be in thumb mode, and consequently function
> caller (which is called from main) is is executed as if it's in thumb mode,
> while it's actually in arm mode.
> 
> Fix this by adding an intermediate function caller_trampoline in
> arm-pseudo-unwind.c, and hardcoding it to arm mode using
> __attribute__((target("arm"))).
> 
> Likewise for test-case gdb.arch/arm-pseudo-unwind-legacy.exp.
> 
> Tested on arm-linux.
> ---
>  gdb/testsuite/gdb.arch/arm-pseudo-unwind-legacy.c | 9 ++++++++-
>  gdb/testsuite/gdb.arch/arm-pseudo-unwind.c        | 9 ++++++++-
>  2 files changed, 16 insertions(+), 2 deletions(-)
> 
> diff --git a/gdb/testsuite/gdb.arch/arm-pseudo-unwind-legacy.c b/gdb/testsuite/gdb.arch/arm-pseudo-unwind-legacy.c
> index 49b0553ade4..adda4b8b298 100644
> --- a/gdb/testsuite/gdb.arch/arm-pseudo-unwind-legacy.c
> +++ b/gdb/testsuite/gdb.arch/arm-pseudo-unwind-legacy.c
> @@ -24,10 +24,17 @@ break_here_c (uint64_t value)
>  {
>  }
>  
> +__attribute__((target("arm")))
> +uint64_t
> +caller_trampoline (void)
> +{
> +  return caller ();
> +}
> +
>  int
>  main (void)
>  {
> -  uint64_t value = caller ();
> +  uint64_t value = caller_trampoline ();
>    break_here_c (value);
>    return 0;
>  }
> diff --git a/gdb/testsuite/gdb.arch/arm-pseudo-unwind.c b/gdb/testsuite/gdb.arch/arm-pseudo-unwind.c
> index 49b0553ade4..adda4b8b298 100644
> --- a/gdb/testsuite/gdb.arch/arm-pseudo-unwind.c
> +++ b/gdb/testsuite/gdb.arch/arm-pseudo-unwind.c
> @@ -24,10 +24,17 @@ break_here_c (uint64_t value)
>  {
>  }
>  
> +__attribute__((target("arm")))
> +uint64_t
> +caller_trampoline (void)
> +{
> +  return caller ();
> +}
> +
>  int
>  main (void)
>  {
> -  uint64_t value = caller ();
> +  uint64_t value = caller_trampoline ();
>    break_here_c (value);
>    return 0;
>  }
> 
> base-commit: dfeb912e160b3eae596a4fd92cc14d0f5e90ee68

Thanks, this is OK.

Approved-By: Luis Machado <luis.machado@arm.com>
  

Patch

diff --git a/gdb/testsuite/gdb.arch/arm-pseudo-unwind-legacy.c b/gdb/testsuite/gdb.arch/arm-pseudo-unwind-legacy.c
index 49b0553ade4..adda4b8b298 100644
--- a/gdb/testsuite/gdb.arch/arm-pseudo-unwind-legacy.c
+++ b/gdb/testsuite/gdb.arch/arm-pseudo-unwind-legacy.c
@@ -24,10 +24,17 @@  break_here_c (uint64_t value)
 {
 }
 
+__attribute__((target("arm")))
+uint64_t
+caller_trampoline (void)
+{
+  return caller ();
+}
+
 int
 main (void)
 {
-  uint64_t value = caller ();
+  uint64_t value = caller_trampoline ();
   break_here_c (value);
   return 0;
 }
diff --git a/gdb/testsuite/gdb.arch/arm-pseudo-unwind.c b/gdb/testsuite/gdb.arch/arm-pseudo-unwind.c
index 49b0553ade4..adda4b8b298 100644
--- a/gdb/testsuite/gdb.arch/arm-pseudo-unwind.c
+++ b/gdb/testsuite/gdb.arch/arm-pseudo-unwind.c
@@ -24,10 +24,17 @@  break_here_c (uint64_t value)
 {
 }
 
+__attribute__((target("arm")))
+uint64_t
+caller_trampoline (void)
+{
+  return caller ();
+}
+
 int
 main (void)
 {
-  uint64_t value = caller ();
+  uint64_t value = caller_trampoline ();
   break_here_c (value);
   return 0;
 }