Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH][gdb/tdep] Fix gdb.base/large-frame.exp for aarch64
@ 2022-08-04 13:04 Tom de Vries via Gdb-patches
  2022-08-04 13:17 ` Luis Machado via Gdb-patches
  0 siblings, 1 reply; 2+ messages in thread
From: Tom de Vries via Gdb-patches @ 2022-08-04 13:04 UTC (permalink / raw)
  To: gdb-patches

Hi,

On aarch64, I run into:
...
FAIL: gdb.base/large-frame.exp: optimize=-O0: backtrace
...

The problem is that the architecture-specific prologue analyzer fails to
handle the first two insns in the prologue properly:
...
0000000000400610 <func>:
  400610:       d2880210        mov     x16, #0x4010
  400614:       cb3063ff        sub     sp, sp, x16
  400618:       a9007bfd        stp     x29, x30, [sp]
  40061c:       910003fd        mov     x29, sp
  400620:       910043a0        add     x0, x29, #0x10
  400624:       97fffff0        bl      4005e4 <blah>
...
so we get:
...
$ gdb -q -batch ./outputs/gdb.base/large-frame/large-frame-O0 -ex "b func"
Breakpoint 1 at 0x400614
...

Fix this by:
- fixing the support for the first insn to extract the immediate operand, and
- adding support for the second insn,
such that we have:
...
Breakpoint 1 at 0x400624
...
Note that we're overshooting by one insn (0x400620 is the first insn after the
prologue), but that's a pre-existing problem.

Tested on aarch64-linux.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29408

Any comments?

Thanks,
- Tom

[gdb/tdep] Fix gdb.base/large-frame.exp for aarch64

---
 gdb/aarch64-tdep.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c
index 8670197a888..f747ebda1ab 100644
--- a/gdb/aarch64-tdep.c
+++ b/gdb/aarch64-tdep.c
@@ -340,6 +340,20 @@ aarch64_analyze_prologue (struct gdbarch *gdbarch,
 	  if (rn == AARCH64_SP_REGNUM && rd == AARCH64_FP_REGNUM)
 	    seen_stack_set = true;
 	}
+      else if (inst.opcode->iclass == addsub_ext
+	       && strcmp ("sub", inst.opcode->name) == 0)
+	{
+	  unsigned rd = inst.operands[0].reg.regno;
+	  unsigned rn = inst.operands[1].reg.regno;
+	  unsigned rm = inst.operands[2].reg.regno;
+
+	  gdb_assert (aarch64_num_of_operands (inst.opcode) == 3);
+	  gdb_assert (inst.operands[0].type == AARCH64_OPND_Rd_SP);
+	  gdb_assert (inst.operands[1].type == AARCH64_OPND_Rn_SP);
+	  gdb_assert (inst.operands[2].type == AARCH64_OPND_Rm_EXT);
+
+	  regs[rd] = pv_subtract (regs[rn], regs[rm]);
+	}
       else if (inst.opcode->iclass == pcreladdr
 	       && inst.operands[1].type == AARCH64_OPND_ADDR_ADRP)
 	{
@@ -370,14 +384,20 @@ aarch64_analyze_prologue (struct gdbarch *gdbarch,
 	}
       else if (inst.opcode->op == OP_MOVZ)
 	{
+	  unsigned rd = inst.operands[0].reg.regno;
+
+	  gdb_assert (aarch64_num_of_operands (inst.opcode) == 2);
 	  gdb_assert (inst.operands[0].type == AARCH64_OPND_Rd);
+	  gdb_assert (inst.operands[1].type == AARCH64_OPND_HALF);
+	  gdb_assert (inst.operands[1].shifter.kind == AARCH64_MOD_LSL);
 
 	  /* If this shows up before we set the stack, keep going.  Otherwise
 	     stop the analysis.  */
 	  if (seen_stack_set)
 	    break;
 
-	  regs[inst.operands[0].reg.regno] = pv_unknown ();
+	  regs[rd] = pv_constant (inst.operands[1].imm.value
+				  << inst.operands[1].shifter.amount);
 	}
       else if (inst.opcode->iclass == log_shift
 	       && strcmp (inst.opcode->name, "orr") == 0)

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

* Re: [PATCH][gdb/tdep] Fix gdb.base/large-frame.exp for aarch64
  2022-08-04 13:04 [PATCH][gdb/tdep] Fix gdb.base/large-frame.exp for aarch64 Tom de Vries via Gdb-patches
@ 2022-08-04 13:17 ` Luis Machado via Gdb-patches
  0 siblings, 0 replies; 2+ messages in thread
From: Luis Machado via Gdb-patches @ 2022-08-04 13:17 UTC (permalink / raw)
  To: Tom de Vries, gdb-patches

Hi,

Thanks for the patch. I was giving this a try before replying.

On 8/4/22 14:04, Tom de Vries wrote:
> Hi,
> 
> On aarch64, I run into:
> ...
> FAIL: gdb.base/large-frame.exp: optimize=-O0: backtrace
> ...
> 
> The problem is that the architecture-specific prologue analyzer fails to
> handle the first two insns in the prologue properly:
> ...
> 0000000000400610 <func>:
>    400610:       d2880210        mov     x16, #0x4010
>    400614:       cb3063ff        sub     sp, sp, x16
>    400618:       a9007bfd        stp     x29, x30, [sp]
>    40061c:       910003fd        mov     x29, sp
>    400620:       910043a0        add     x0, x29, #0x10
>    400624:       97fffff0        bl      4005e4 <blah>
> ...
> so we get:
> ...
> $ gdb -q -batch ./outputs/gdb.base/large-frame/large-frame-O0 -ex "b func"
> Breakpoint 1 at 0x400614
> ...
> 
> Fix this by:
> - fixing the support for the first insn to extract the immediate operand, and
> - adding support for the second insn,
> such that we have:
> ...
> Breakpoint 1 at 0x400624
> ...
> Note that we're overshooting by one insn (0x400620 is the first insn after the
> prologue), but that's a pre-existing problem.
> 
> Tested on aarch64-linux.
> 
> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29408
> 
> Any comments?
> 
> Thanks,
> - Tom
> 
> [gdb/tdep] Fix gdb.base/large-frame.exp for aarch64
> 
> ---
>   gdb/aarch64-tdep.c | 22 +++++++++++++++++++++-
>   1 file changed, 21 insertions(+), 1 deletion(-)
> 
> diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c
> index 8670197a888..f747ebda1ab 100644
> --- a/gdb/aarch64-tdep.c
> +++ b/gdb/aarch64-tdep.c
> @@ -340,6 +340,20 @@ aarch64_analyze_prologue (struct gdbarch *gdbarch,
>   	  if (rn == AARCH64_SP_REGNUM && rd == AARCH64_FP_REGNUM)
>   	    seen_stack_set = true;
>   	}
> +      else if (inst.opcode->iclass == addsub_ext
> +	       && strcmp ("sub", inst.opcode->name) == 0)
> +	{
> +	  unsigned rd = inst.operands[0].reg.regno;
> +	  unsigned rn = inst.operands[1].reg.regno;
> +	  unsigned rm = inst.operands[2].reg.regno;
> +
> +	  gdb_assert (aarch64_num_of_operands (inst.opcode) == 3);
> +	  gdb_assert (inst.operands[0].type == AARCH64_OPND_Rd_SP);
> +	  gdb_assert (inst.operands[1].type == AARCH64_OPND_Rn_SP);
> +	  gdb_assert (inst.operands[2].type == AARCH64_OPND_Rm_EXT);
> +
> +	  regs[rd] = pv_subtract (regs[rn], regs[rm]);
> +	}
>         else if (inst.opcode->iclass == pcreladdr
>   	       && inst.operands[1].type == AARCH64_OPND_ADDR_ADRP)
>   	{
> @@ -370,14 +384,20 @@ aarch64_analyze_prologue (struct gdbarch *gdbarch,
>   	}
>         else if (inst.opcode->op == OP_MOVZ)
>   	{
> +	  unsigned rd = inst.operands[0].reg.regno;
> +
> +	  gdb_assert (aarch64_num_of_operands (inst.opcode) == 2);
>   	  gdb_assert (inst.operands[0].type == AARCH64_OPND_Rd);
> +	  gdb_assert (inst.operands[1].type == AARCH64_OPND_HALF);
> +	  gdb_assert (inst.operands[1].shifter.kind == AARCH64_MOD_LSL);
>   
>   	  /* If this shows up before we set the stack, keep going.  Otherwise
>   	     stop the analysis.  */
>   	  if (seen_stack_set)
>   	    break;
>   
> -	  regs[inst.operands[0].reg.regno] = pv_unknown ();
> +	  regs[rd] = pv_constant (inst.operands[1].imm.value
> +				  << inst.operands[1].shifter.amount);
>   	}
>         else if (inst.opcode->iclass == log_shift
>   	       && strcmp (inst.opcode->name, "orr") == 0)

This looks good to me. Thanks for getting this fixed.

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

end of thread, other threads:[~2022-08-04 13:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-04 13:04 [PATCH][gdb/tdep] Fix gdb.base/large-frame.exp for aarch64 Tom de Vries via Gdb-patches
2022-08-04 13:17 ` Luis Machado via Gdb-patches

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox