public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v2] gdb: LoongArch: Change LOONGARCH_FIRST_FP_REGNUM to 35
@ 2024-02-27  1:18 Hui Li
  2024-03-01  6:21 ` Hui Li
  0 siblings, 1 reply; 4+ messages in thread
From: Hui Li @ 2024-02-27  1:18 UTC (permalink / raw)
  To: gdb-patches

There is an assertion error "gdb_assert (n < tdesc->reg_defs.size ())"
in find_register_by_number() when gdb connects to gdbserver, this
is because the value of LOONGARCH_LINUX_NUM_GREGSET (45, which contains
10 reserved regs) is different with the number of regs (35, which not
contains 10 reserved regs) in file gdb/features/loongarch/base64.xml.
Add a new macro LOONGARCH_USED_NUM_GREGSET which is defined as 35 to
keep consistent with the gdb/features/loongarch/base64.xml, and then
define LOONGARCH_FIRST_FP_REGNUM as LOONGARCH_USED_NUM_GREGSET so that
all the reg numbers in regcache are consistent with tdesc reg numbers.

without this patch:

Execute on the target machine:

  $ gdbserver 192.168.1.123:5678 ./test

Execute on the host machine:

  $ gdb ./test
  (gdb) target remote 192.168.1.123:5678

Output on the target machine:

  Process ./test created; pid = 67683
  Listening on port 5678
  Remote debugging from host 192.168.1.136, port 6789
  gdbserver/regcache.cc:205: A problem internal to GDBserver has been detected.
  find_register_by_number: Assertion 'n < tdesc->reg_defs.size ()' failed.

Output on the host machine:

  Remote debugging using 192.168.1.123:5678
  Remote connection closed

Signed-off-by: Hui Li <lihui@loongson.cn>
---
 gdb/arch/loongarch.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gdb/arch/loongarch.h b/gdb/arch/loongarch.h
index 4b7ab054ea0..7056d506bf4 100644
--- a/gdb/arch/loongarch.h
+++ b/gdb/arch/loongarch.h
@@ -33,10 +33,11 @@ enum loongarch_regnum
   LOONGARCH_ORIG_A0_REGNUM = 32,	/* Syscall's original arg0.  */
   LOONGARCH_PC_REGNUM = 33,		/* Program Counter.  */
   LOONGARCH_BADV_REGNUM = 34,		/* Bad Vaddr for Addressing Exception.  */
+  LOONGARCH_USED_NUM_GREGSET = 35,	/* 32 GPR, ORIG_A0, PC, BADV.  */
   LOONGARCH_LINUX_NUM_GREGSET = 45,	/* 32 GPR, ORIG_A0, PC, BADV, RESERVED 10.  */
   LOONGARCH_ARG_REGNUM = 8,            /* r4-r11: general-purpose argument registers.
 					  f0-f7: floating-point argument registers.  */
-  LOONGARCH_FIRST_FP_REGNUM = LOONGARCH_LINUX_NUM_GREGSET,
+  LOONGARCH_FIRST_FP_REGNUM = LOONGARCH_USED_NUM_GREGSET,
   LOONGARCH_LINUX_NUM_FPREGSET = 32,
   LOONGARCH_FIRST_FCC_REGNUM = LOONGARCH_FIRST_FP_REGNUM + LOONGARCH_LINUX_NUM_FPREGSET,
   LOONGARCH_LINUX_NUM_FCC = 8,
-- 
2.38.1


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

* Re: [PATCH v2] gdb: LoongArch: Change LOONGARCH_FIRST_FP_REGNUM to 35
  2024-02-27  1:18 [PATCH v2] gdb: LoongArch: Change LOONGARCH_FIRST_FP_REGNUM to 35 Hui Li
@ 2024-03-01  6:21 ` Hui Li
  2024-03-01 21:11   ` John Baldwin
  0 siblings, 1 reply; 4+ messages in thread
From: Hui Li @ 2024-03-01  6:21 UTC (permalink / raw)
  To: gdb-patches; +Cc: John Baldwin



On 2024/2/27 上午9:18, Hui Li wrote:
> There is an assertion error "gdb_assert (n < tdesc->reg_defs.size ())"
> in find_register_by_number() when gdb connects to gdbserver, this
> is because the value of LOONGARCH_LINUX_NUM_GREGSET (45, which contains
> 10 reserved regs) is different with the number of regs (35, which not
> contains 10 reserved regs) in file gdb/features/loongarch/base64.xml.
> Add a new macro LOONGARCH_USED_NUM_GREGSET which is defined as 35 to
> keep consistent with the gdb/features/loongarch/base64.xml, and then
> define LOONGARCH_FIRST_FP_REGNUM as LOONGARCH_USED_NUM_GREGSET so that
> all the reg numbers in regcache are consistent with tdesc reg numbers.
> 
> without this patch:
> 
> Execute on the target machine:
> 
>    $ gdbserver 192.168.1.123:5678 ./test
> 
> Execute on the host machine:
> 
>    $ gdb ./test
>    (gdb) target remote 192.168.1.123:5678
> 
> Output on the target machine:
> 
>    Process ./test created; pid = 67683
>    Listening on port 5678
>    Remote debugging from host 192.168.1.136, port 6789
>    gdbserver/regcache.cc:205: A problem internal to GDBserver has been detected.
>    find_register_by_number: Assertion 'n < tdesc->reg_defs.size ()' failed.
> 
> Output on the host machine:
> 
>    Remote debugging using 192.168.1.123:5678
>    Remote connection closed
> 
> Signed-off-by: Hui Li <lihui@loongson.cn>
> ---
>   gdb/arch/loongarch.h | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/gdb/arch/loongarch.h b/gdb/arch/loongarch.h
> index 4b7ab054ea0..7056d506bf4 100644
> --- a/gdb/arch/loongarch.h
> +++ b/gdb/arch/loongarch.h
> @@ -33,10 +33,11 @@ enum loongarch_regnum
>     LOONGARCH_ORIG_A0_REGNUM = 32,	/* Syscall's original arg0.  */
>     LOONGARCH_PC_REGNUM = 33,		/* Program Counter.  */
>     LOONGARCH_BADV_REGNUM = 34,		/* Bad Vaddr for Addressing Exception.  */
> +  LOONGARCH_USED_NUM_GREGSET = 35,	/* 32 GPR, ORIG_A0, PC, BADV.  */
>     LOONGARCH_LINUX_NUM_GREGSET = 45,	/* 32 GPR, ORIG_A0, PC, BADV, RESERVED 10.  */
>     LOONGARCH_ARG_REGNUM = 8,            /* r4-r11: general-purpose argument registers.
>   					  f0-f7: floating-point argument registers.  */
> -  LOONGARCH_FIRST_FP_REGNUM = LOONGARCH_LINUX_NUM_GREGSET,
> +  LOONGARCH_FIRST_FP_REGNUM = LOONGARCH_USED_NUM_GREGSET,
>     LOONGARCH_LINUX_NUM_FPREGSET = 32,
>     LOONGARCH_FIRST_FCC_REGNUM = LOONGARCH_FIRST_FP_REGNUM + LOONGARCH_LINUX_NUM_FPREGSET,
>     LOONGARCH_LINUX_NUM_FCC = 8,
> 

Hi John,

Are you ok for this version?

Thanks,
Hui


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

* Re: [PATCH v2] gdb: LoongArch: Change LOONGARCH_FIRST_FP_REGNUM to 35
  2024-03-01  6:21 ` Hui Li
@ 2024-03-01 21:11   ` John Baldwin
  2024-03-02 11:16     ` Tiezhu Yang
  0 siblings, 1 reply; 4+ messages in thread
From: John Baldwin @ 2024-03-01 21:11 UTC (permalink / raw)
  To: Hui Li, gdb-patches

On 2/29/24 10:21 PM, Hui Li wrote:
> 
> 
> On 2024/2/27 上午9:18, Hui Li wrote:
>> There is an assertion error "gdb_assert (n < tdesc->reg_defs.size ())"
>> in find_register_by_number() when gdb connects to gdbserver, this
>> is because the value of LOONGARCH_LINUX_NUM_GREGSET (45, which contains
>> 10 reserved regs) is different with the number of regs (35, which not
>> contains 10 reserved regs) in file gdb/features/loongarch/base64.xml.
>> Add a new macro LOONGARCH_USED_NUM_GREGSET which is defined as 35 to
>> keep consistent with the gdb/features/loongarch/base64.xml, and then
>> define LOONGARCH_FIRST_FP_REGNUM as LOONGARCH_USED_NUM_GREGSET so that
>> all the reg numbers in regcache are consistent with tdesc reg numbers.
>>
>> without this patch:
>>
>> Execute on the target machine:
>>
>>     $ gdbserver 192.168.1.123:5678 ./test
>>
>> Execute on the host machine:
>>
>>     $ gdb ./test
>>     (gdb) target remote 192.168.1.123:5678
>>
>> Output on the target machine:
>>
>>     Process ./test created; pid = 67683
>>     Listening on port 5678
>>     Remote debugging from host 192.168.1.136, port 6789
>>     gdbserver/regcache.cc:205: A problem internal to GDBserver has been detected.
>>     find_register_by_number: Assertion 'n < tdesc->reg_defs.size ()' failed.
>>
>> Output on the host machine:
>>
>>     Remote debugging using 192.168.1.123:5678
>>     Remote connection closed
>>
>> Signed-off-by: Hui Li <lihui@loongson.cn>
>> ---
>>    gdb/arch/loongarch.h | 3 ++-
>>    1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/gdb/arch/loongarch.h b/gdb/arch/loongarch.h
>> index 4b7ab054ea0..7056d506bf4 100644
>> --- a/gdb/arch/loongarch.h
>> +++ b/gdb/arch/loongarch.h
>> @@ -33,10 +33,11 @@ enum loongarch_regnum
>>      LOONGARCH_ORIG_A0_REGNUM = 32,	/* Syscall's original arg0.  */
>>      LOONGARCH_PC_REGNUM = 33,		/* Program Counter.  */
>>      LOONGARCH_BADV_REGNUM = 34,		/* Bad Vaddr for Addressing Exception.  */
>> +  LOONGARCH_USED_NUM_GREGSET = 35,	/* 32 GPR, ORIG_A0, PC, BADV.  */
>>      LOONGARCH_LINUX_NUM_GREGSET = 45,	/* 32 GPR, ORIG_A0, PC, BADV, RESERVED 10.  */
>>      LOONGARCH_ARG_REGNUM = 8,            /* r4-r11: general-purpose argument registers.
>>    					  f0-f7: floating-point argument registers.  */
>> -  LOONGARCH_FIRST_FP_REGNUM = LOONGARCH_LINUX_NUM_GREGSET,
>> +  LOONGARCH_FIRST_FP_REGNUM = LOONGARCH_USED_NUM_GREGSET,
>>      LOONGARCH_LINUX_NUM_FPREGSET = 32,
>>      LOONGARCH_FIRST_FCC_REGNUM = LOONGARCH_FIRST_FP_REGNUM + LOONGARCH_LINUX_NUM_FPREGSET,
>>      LOONGARCH_LINUX_NUM_FCC = 8,
>>
> 
> Hi John,
> 
> Are you ok for this version?

Yes, I'm ok with this version.  I guess Linux's ptrace note just has 10 spare register slots
that aren't used?

Approved-By: John Baldwin <jhb@FreeBSD.org>

-- 
John Baldwin


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

* Re: [PATCH v2] gdb: LoongArch: Change LOONGARCH_FIRST_FP_REGNUM to 35
  2024-03-01 21:11   ` John Baldwin
@ 2024-03-02 11:16     ` Tiezhu Yang
  0 siblings, 0 replies; 4+ messages in thread
From: Tiezhu Yang @ 2024-03-02 11:16 UTC (permalink / raw)
  To: John Baldwin, Hui Li, gdb-patches

On 3/2/24 05:11, John Baldwin wrote:
> On 2/29/24 10:21 PM, Hui Li wrote:
>>
>>
>> On 2024/2/27 上午9:18, Hui Li wrote:
>>> There is an assertion error "gdb_assert (n < tdesc->reg_defs.size ())"
>>> in find_register_by_number() when gdb connects to gdbserver, this
>>> is because the value of LOONGARCH_LINUX_NUM_GREGSET (45, which contains
>>> 10 reserved regs) is different with the number of regs (35, which not
>>> contains 10 reserved regs) in file gdb/features/loongarch/base64.xml.
>>> Add a new macro LOONGARCH_USED_NUM_GREGSET which is defined as 35 to
>>> keep consistent with the gdb/features/loongarch/base64.xml, and then
>>> define LOONGARCH_FIRST_FP_REGNUM as LOONGARCH_USED_NUM_GREGSET so that
>>> all the reg numbers in regcache are consistent with tdesc reg numbers.

...

>> Hi John,
>>
>> Are you ok for this version?
> 
> Yes, I'm ok with this version. > I guess Linux's ptrace note just has 10 spare register slots
> that aren't used?

Yes, here is the related kernel code:

static int gpr_get(struct task_struct *target,
		   const struct user_regset *regset,
		   struct membuf to)
{
	int r;
	struct pt_regs *regs = task_pt_regs(target);

	r = membuf_write(&to, &regs->regs, sizeof(u64) * GPR_NUM);
	r = membuf_write(&to, &regs->orig_a0, sizeof(u64));
	r = membuf_write(&to, &regs->csr_era, sizeof(u64));
	r = membuf_write(&to, &regs->csr_badvaddr, sizeof(u64));

	return r;
}

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/loongarch/kernel/ptrace.c#n75

> 
> Approved-By: John Baldwin <jhb@FreeBSD.org>

Thank you, pushed.

Thanks,
Tiezhu


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

end of thread, other threads:[~2024-03-02 11:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-27  1:18 [PATCH v2] gdb: LoongArch: Change LOONGARCH_FIRST_FP_REGNUM to 35 Hui Li
2024-03-01  6:21 ` Hui Li
2024-03-01 21:11   ` John Baldwin
2024-03-02 11:16     ` Tiezhu Yang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).