From ee7893306c72695ec76983b3abb1753cb4b3b119 Mon Sep 17 00:00:00 2001 From: Hailiang Date: Tue, 16 Sep 2025 15:02:56 +0800 Subject: [PATCH] Fix gdbserver assertions issue --- ...ange-LOONGARCH_FIRST_FP_REGNUM-to-35.patch | 67 +++++++++++++++++++ gdb.spec | 6 +- 2 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 gdb-LoongArch-Change-LOONGARCH_FIRST_FP_REGNUM-to-35.patch diff --git a/gdb-LoongArch-Change-LOONGARCH_FIRST_FP_REGNUM-to-35.patch b/gdb-LoongArch-Change-LOONGARCH_FIRST_FP_REGNUM-to-35.patch new file mode 100644 index 0000000..7dc65c5 --- /dev/null +++ b/gdb-LoongArch-Change-LOONGARCH_FIRST_FP_REGNUM-to-35.patch @@ -0,0 +1,67 @@ +From 1304f47d02bfd0b41ebf4c1c6758a6251c29d8a1 Mon Sep 17 00:00:00 2001 +From: Hui Li +Date: Tue, 27 Feb 2024 09:18:10 +0800 +Subject: [PATCH 1709/2674] gdb: LoongArch: Change LOONGARCH_FIRST_FP_REGNUM to + 35 + +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 +Approved-By: John Baldwin +Signed-off-by: Tiezhu Yang +--- + 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.30.2 + diff --git a/gdb.spec b/gdb.spec index 2be066e..abd33cc 100644 --- a/gdb.spec +++ b/gdb.spec @@ -1,6 +1,6 @@ Name: gdb Version: 14.1 -Release: 6 +Release: 7 License: GPLv3+ and GPLv3+ with exceptions and GPLv2+ and GPLv2+ with exceptions and GPL+ and LGPLv2+ and LGPLv3+ and BSD and Public Domain and GFDL-1.3 Source: https://ftp.gnu.org/gnu/gdb/gdb-%{version}.tar.xz @@ -60,6 +60,7 @@ Patch47: gdb-ftbs-swapped-calloc-args.patch # Fedra patch end Patch48: Fix-CVE-2025-7546.patch Patch49: gdb-rhbz2259850-list-period-crash-fix.patch +Patch50: gdb-LoongArch-Change-LOONGARCH_FIRST_FP_REGNUM-to-35.patch Patch9000: 0001-set-entry-point-when-text-segment-is-missing.patch @@ -337,6 +338,9 @@ rm -f $RPM_BUILD_ROOT%{_datadir}/gdb/python/gdb/command/backtrace.py %{_infodir}/ctf-spec.info* %changelog +* Tue Sep 16 2025 mahailiang - 14.1-7 +- Fix gdbserver assertions issue + * Mon Sep 08 2025 Deyuan Fan - 14.1-6 - gdb: fix "list ." related crash -- Gitee