On Sat, Nov 09, 2024 at 11:50:12AM +0100, Jeremie Courreges-Anglas wrote:
> On Sat, Nov 09, 2024 at 12:57:56AM -0500, George Koehler wrote:
> > On Fri, 8 Nov 2024 14:03:17 +0100
> > Jeremie Courreges-Anglas <j...@wxcvbn.org> wrote:
> > 
> > > I can't infer from gkoehler's report and yours whether 32 bits powerpc
> > > support is fine.
> > 
> > It was fine until I tried switching threads.  gdb-13.2 on powerpc gets
> > registers from only the 1st thread, so thread switches have the wrong
> > registers and backtrace.  A fix might be to change
> >     regcache->ptid ().pid()
> > to
> >     get_ptrace_pid (regcache->ptid ())
> > to match other archs, which I will try later, when I have a few hours
> > to rebuild gdb.
> 
> Ah, yes, that's definitely something we want to fix on all platforms.
> But that's not a regression introduced by 13.2, and I suggest you
> handle this in a subsequent commit.

Diff below adds similar fixes for arm, hppa and mips64.  The hppa code
didn't build anyway.

> > On powerpc64, gdb-13.2 refusing to run programs or load core dumps was
> > a regression from 9.2.  I have edited my ppc64-obsd-*.c and my 13.2 now
> > works about as well as 9.2, so I will mail my patches later.
> 
> That's great.  As far as I know, besides arm native support, it is the
> last missing piece for this update.  I propose I commit this update,
> and then you add your runtime fix for powerpc64 on top.  And I'll
> handle arm later, as time permits.
> 
> kettenis@ has confirmed that using the latest diff, gdb compiles on arm
> but with no runtime support.

The diff below re-adds native process support for arm
(patches/patch-gdb_configure_nat).  Single stepping seems to be
broken, but that's also the case with gdb-9.2.  The Makefile diff
overrides a dumb and broken gnulib check so that our malloc is used
instead of a useless wrapper.

ok?


Index: Makefile
===================================================================
RCS file: /cvs/ports/devel/gdb/Makefile,v
diff -u -p -r1.87 Makefile
--- Makefile    11 Nov 2024 00:15:33 -0000      1.87
+++ Makefile    13 Nov 2024 21:34:14 -0000
@@ -2,7 +2,7 @@ COMMENT=        GNU debugger
 CATEGORIES=    devel
 
 DISTNAME=      gdb-13.2
-REVISION=      0
+REVISION=      1
 
 HOMEPAGE=      https://www.gnu.org/software/gdb/
 
@@ -42,6 +42,8 @@ CONFIGURE_ARGS=       --program-prefix=e \
 
 USE_GMAKE=     Yes
 MAKE_FLAGS=    V=1 LDFLAGS="-L${LOCALBASE}/lib ${LDFLAGS}"
+# Avoid using malloc replacement for no good reason
+MAKE_ENV=      gl_cv_malloc_ptrdiff=yes
 
 MODULES +=     lang/python
 
Index: patches/patch-gdb_arm-obsd-nat_c
===================================================================
RCS file: /cvs/ports/devel/gdb/patches/patch-gdb_arm-obsd-nat_c,v
diff -u -p -r1.1 patch-gdb_arm-obsd-nat_c
--- patches/patch-gdb_arm-obsd-nat_c    9 Nov 2024 13:33:19 -0000       1.1
+++ patches/patch-gdb_arm-obsd-nat_c    13 Nov 2024 21:34:14 -0000
@@ -1,10 +1,9 @@
-
-TODO Reinstate OpenBSD/arm native support.
+Add OpenBSD/arm native support.
 
 Index: gdb/arm-obsd-nat.c
 --- gdb/arm-obsd-nat.c.orig
 +++ gdb/arm-obsd-nat.c
-@@ -0,0 +1,421 @@
+@@ -0,0 +1,427 @@
 +/* Native-dependent code for BSD Unix running on ARM's, for GDB.
 +
 +   Copyright (C) 1988-2020 Free Software Foundation, Inc.
@@ -89,8 +88,9 @@ Index: gdb/arm-obsd-nat.c
 +{
 +  struct reg inferior_registers;
 +  int ret;
++  pid_t pid = get_ptrace_pid (regcache->ptid ());
 +
-+  ret = ptrace (PT_GETREGS, regcache->ptid ().pid (),
++  ret = ptrace (PT_GETREGS, pid,
 +              (PTRACE_TYPE_ARG3) &inferior_registers, 0);
 +
 +  if (ret < 0)
@@ -138,8 +138,9 @@ Index: gdb/arm-obsd-nat.c
 +  struct reg inferior_registers;
 +  int ret;
 +  int regno;
++  pid_t pid = get_ptrace_pid (regcache->ptid ());
 +
-+  ret = ptrace (PT_GETREGS, regcache->ptid ().pid (),
++  ret = ptrace (PT_GETREGS, pid,
 +              (PTRACE_TYPE_ARG3) &inferior_registers, 0);
 +
 +  if (ret < 0)
@@ -156,8 +157,9 @@ Index: gdb/arm-obsd-nat.c
 +{
 +  struct fpreg inferior_fp_registers;
 +  int ret;
++  pid_t pid = get_ptrace_pid (regcache->ptid ());
 +
-+  ret = ptrace (PT_GETFPREGS, regcache->ptid ().pid (),
++  ret = ptrace (PT_GETFPREGS, pid,
 +              (PTRACE_TYPE_ARG3) &inferior_fp_registers, 0);
 +
 +  if (ret < 0)
@@ -186,8 +188,9 @@ Index: gdb/arm-obsd-nat.c
 +  struct fpreg inferior_fp_registers;
 +  int ret;
 +  int regno;
++  pid_t pid = get_ptrace_pid (regcache->ptid ());
 +
-+  ret = ptrace (PT_GETFPREGS, regcache->ptid ().pid (),
++  ret = ptrace (PT_GETFPREGS, pid,
 +              (PTRACE_TYPE_ARG3) &inferior_fp_registers, 0);
 +
 +  if (ret < 0)
@@ -223,8 +226,9 @@ Index: gdb/arm-obsd-nat.c
 +  gdbarch *gdbarch = regcache->arch ();
 +  struct reg inferior_registers;
 +  int ret;
++  pid_t pid = get_ptrace_pid (regcache->ptid ());
 +
-+  ret = ptrace (PT_GETREGS, regcache->ptid ().pid (),
++  ret = ptrace (PT_GETREGS, pid,
 +              (PTRACE_TYPE_ARG3) &inferior_registers, 0);
 +
 +  if (ret < 0)
@@ -282,7 +286,7 @@ Index: gdb/arm-obsd-nat.c
 +      break;
 +    }
 +
-+  ret = ptrace (PT_SETREGS, regcache->ptid ().pid (),
++  ret = ptrace (PT_SETREGS, pid,
 +              (PTRACE_TYPE_ARG3) &inferior_registers, 0);
 +
 +  if (ret < 0)
@@ -296,7 +300,7 @@ Index: gdb/arm-obsd-nat.c
 +  struct reg inferior_registers;
 +  int ret;
 +  int regno;
-+
++  pid_t pid = get_ptrace_pid (regcache->ptid ());
 +
 +  for (regno = ARM_A1_REGNUM; regno < ARM_SP_REGNUM; regno++)
 +    regcache->raw_collect (regno, (char *) &inferior_registers.r[regno]);
@@ -324,7 +328,7 @@ Index: gdb/arm-obsd-nat.c
 +      inferior_registers.r_pc = pc_val | psr_val;
 +    }
 +
-+  ret = ptrace (PT_SETREGS, regcache->ptid ().pid (),
++  ret = ptrace (PT_SETREGS, pid,
 +              (PTRACE_TYPE_ARG3) &inferior_registers, 0);
 +
 +  if (ret < 0)
@@ -336,8 +340,9 @@ Index: gdb/arm-obsd-nat.c
 +{
 +  struct fpreg inferior_fp_registers;
 +  int ret;
++  pid_t pid = get_ptrace_pid (regcache->ptid ());
 +
-+  ret = ptrace (PT_GETFPREGS, regcache->ptid ().pid (),
++  ret = ptrace (PT_GETFPREGS, pid,
 +              (PTRACE_TYPE_ARG3) &inferior_fp_registers, 0);
 +
 +  if (ret < 0)
@@ -359,7 +364,7 @@ Index: gdb/arm-obsd-nat.c
 +      break;
 +    }
 +
-+  ret = ptrace (PT_SETFPREGS, regcache->ptid ().pid (),
++  ret = ptrace (PT_SETFPREGS, pid,
 +              (PTRACE_TYPE_ARG3) &inferior_fp_registers, 0);
 +
 +  if (ret < 0)
@@ -372,7 +377,7 @@ Index: gdb/arm-obsd-nat.c
 +  struct fpreg inferior_fp_registers;
 +  int ret;
 +  int regno;
-+
++  pid_t pid = get_ptrace_pid (regcache->ptid ());
 +
 +  for (regno = ARM_F0_REGNUM; regno <= ARM_F7_REGNUM; regno++)
 +    regcache->raw_collect
@@ -381,7 +386,7 @@ Index: gdb/arm-obsd-nat.c
 +  regcache->raw_collect (ARM_FPS_REGNUM,
 +                       (char *) &inferior_fp_registers.fp_scr);
 +
-+  ret = ptrace (PT_SETFPREGS, regcache->ptid ().pid (),
++  ret = ptrace (PT_SETFPREGS, pid,
 +              (PTRACE_TYPE_ARG3) &inferior_fp_registers, 0);
 +
 +  if (ret < 0)
Index: patches/patch-gdb_configure_nat
===================================================================
RCS file: /cvs/ports/devel/gdb/patches/patch-gdb_configure_nat,v
diff -u -p -r1.3 patch-gdb_configure_nat
--- patches/patch-gdb_configure_nat     9 Nov 2024 13:33:19 -0000       1.3
+++ patches/patch-gdb_configure_nat     13 Nov 2024 21:34:15 -0000
@@ -1,6 +1,6 @@
 All our targets need obsd-nat.o and kvm etc -> dedup.
 Add aarch64, powerpc64 and riscv64 support.
-Use OpenBSD-specific files for arm. (TBD)
+Use OpenBSD-specific files for arm.
 
 Index: gdb/configure.nat
 --- gdb/configure.nat.orig
@@ -28,8 +28,8 @@ Index: gdb/configure.nat
      obsd)
        case ${gdb_host_cpu} in
 +          arm)
-+              # Host: OpenBSD/arm XXX TODO
-+              #NATDEPFILES="${NATDEPFILES} arm-obsd-nat.o"
++              # Host: OpenBSD/arm
++              NATDEPFILES="${NATDEPFILES} arm-obsd-nat.o"
 +              ;;
            i386)
                # Host: OpenBSD/i386 ELF
Index: patches/patch-gdb_hppa-obsd-nat_c
===================================================================
RCS file: patches/patch-gdb_hppa-obsd-nat_c
diff -N patches/patch-gdb_hppa-obsd-nat_c
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ patches/patch-gdb_hppa-obsd-nat_c   13 Nov 2024 21:34:15 -0000
@@ -0,0 +1,24 @@
+Add support for threads.
+Fix build (undefined variable).
+
+Index: gdb/hppa-obsd-nat.c
+--- gdb/hppa-obsd-nat.c.orig
++++ gdb/hppa-obsd-nat.c
+@@ -196,7 +196,7 @@ hppaobsd_collect_fpregset (struct regcache *regcache,
+ void
+ hppa_obsd_nat_target::fetch_registers (struct regcache *regcache, int regnum)
+ {
+-  pid_t pid = regcache->ptid ().pid ();
++  pid_t pid = get_ptrace_pid (regcache->ptid ());
+ 
+   if (regnum == -1 || hppaobsd_gregset_supplies_p (regnum))
+     {
+@@ -225,6 +225,8 @@ hppa_obsd_nat_target::fetch_registers (struct regcache
+ void
+ hppa_obsd_nat_target::store_registers (struct regcache *regcache, int regnum)
+ {
++  pid_t pid = get_ptrace_pid (regcache->ptid ());
++
+   if (regnum == -1 || hppaobsd_gregset_supplies_p (regnum))
+     {
+       struct reg regs;
Index: patches/patch-gdb_mips64-obsd-nat_c
===================================================================
RCS file: /cvs/ports/devel/gdb/patches/patch-gdb_mips64-obsd-nat_c,v
diff -u -p -r1.2 patch-gdb_mips64-obsd-nat_c
--- patches/patch-gdb_mips64-obsd-nat_c 11 Mar 2022 18:50:04 -0000      1.2
+++ patches/patch-gdb_mips64-obsd-nat_c 13 Nov 2024 21:34:15 -0000
@@ -1,3 +1,6 @@
+Fix build errors.
+Add support for threads.
+
 Index: gdb/mips64-obsd-nat.c
 --- gdb/mips64-obsd-nat.c.orig
 +++ gdb/mips64-obsd-nat.c
@@ -19,7 +22,16 @@ Index: gdb/mips64-obsd-nat.c
    int i;
  
    for (i = MIPS_ZERO_REGNUM; i <= MIPS_PC_REGNUM; i++)
-@@ -100,7 +100,7 @@ mips64_obsd_nat_target::fetch_registers (struct regcac
+@@ -89,7 +89,7 @@ void
+ mips64_obsd_nat_target::fetch_registers (struct regcache *regcache, int 
regnum)
+ {
+   struct reg regs;
+-  pid_t pid = regcache->ptid ().pid ();
++  pid_t pid = get_ptrace_pid (regcache->ptid ());
+ 
+   if (ptrace (PT_GETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
+     perror_with_name (_("Couldn't get registers"));
+@@ -100,11 +100,11 @@ mips64_obsd_nat_target::fetch_registers (struct regcac
  /* Store register REGNUM back into the inferior.  If REGNUM is -1, do
     this for all registers.  */
  
@@ -28,3 +40,8 @@ Index: gdb/mips64-obsd-nat.c
  mips64_obsd_nat_target::store_registers (struct regcache *regcache, int 
regnum)
  {
    struct reg regs;
+-  pid_t pid = regcache->ptid ().pid ();
++  pid_t pid = get_ptrace_pid (regcache->ptid ());
+ 
+   if (ptrace (PT_GETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
+     perror_with_name (_("Couldn't get registers"));
-- 
jca

Reply via email to