Jeremie Courreges-Anglas <j...@wxcvbn.org> writes:

> Vasily Kolobkov <polezaivs...@openmailbox.org> writes:
>
>> On Thu, Mar 10, 2016 at 01:08:36AM +0100, Jeremie Courreges-Anglas wrote:
>>> Philip Guenther <pguent...@proofpoint.com> writes:
>>> 
>>> > Broadening to ports@
>>> >
>>> > With respect to this question in my original note:
>>> >> Or maybe new gdb has some way to have ptid_get_pid() return the 
>>> >> per-thread value?
>>> >
>>> > the answer appears to be "nope, no new magic in gdb for that".
>>> 
>>> Makes sense, I only tested with an old gdb (7.9.1) so far but will take
>>> a look at -current soon.
>>> 
>>> Pascal, any objection?
>>> 
>>> >
>>> > Philip
>>> >
>>> > ---------- Forwarded message ----------
>>> > Date: Sun, 19 Apr 2015 16:18:07 -0700
>>> > From: Philip Guenther <pguent...@proofpoint.com>
>>> > To: Pascal Stumpf <pascal.stu...@cubes.de>
>>> > Cc: Mark Kettenis <kette...@openbsd.org>
>>> > Subject: ports gdb thread handling...
>>> >
>>> >
>>> > Looks like the gdb in ports needs patching to try ptid_get_lwp() before 
>>> > ptid_get_pid() when fetching/setting registers.  For example, diff below 
>>> > fixes this for amd64.  Without this it always reports the original 
>>> > thread's registers (and thus the same backtrace), but with it I can get 
>>> > distinct backtraces like:
>>> > ...
>>
>> Being haunted by seemingly the same issue, the 7.11 version did help in 
>> my case and shows correct call stacks, while 7.10.1 did not. All amd64.
>
> Heh, upstream introduced new magic, get_ptrace_pid, and jhb@freebsd
> started using it in gdb/amd64bsd-nat.c and gdb/i386bsd-nat.c.  Other
> archs were not touched.

Back to this...

here's a mechanical diff for non-x86 architectures, and a small test
case.  Running it should show different stacks for the two threads.

Attachment: egdb-testcase.tgz
Description: Binary data


Index: Makefile
===================================================================
RCS file: /cvs/ports/devel/gdb/Makefile,v
retrieving revision 1.41
diff -u -p -r1.41 Makefile
--- Makefile    7 May 2016 12:40:56 -0000       1.41
+++ Makefile    14 May 2016 23:12:09 -0000
@@ -4,7 +4,7 @@ COMMENT=        GNU debugger
 CATEGORIES=    devel
 
 DISTNAME=      gdb-7.11
-REVISION=      0
+REVISION=      1
 
 HOMEPAGE=      https://www.gnu.org/software/gdb/
 
Index: patches/patch-gdb_alphabsd-nat_c
===================================================================
RCS file: patches/patch-gdb_alphabsd-nat_c
diff -N patches/patch-gdb_alphabsd-nat_c
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ patches/patch-gdb_alphabsd-nat_c    14 May 2016 23:12:09 -0000
@@ -0,0 +1,53 @@
+$OpenBSD$
+--- gdb/alphabsd-nat.c.orig    Wed Feb 10 04:19:39 2016
++++ gdb/alphabsd-nat.c Sat May 14 22:54:35 2016
+@@ -91,7 +91,7 @@ alphabsd_fetch_inferior_registers (struct target_ops *
+     {
+       struct reg gregs;
+ 
+-      if (ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid),
++      if (ptrace (PT_GETREGS, get_ptrace_pid (inferior_ptid),
+                 (PTRACE_TYPE_ARG3) &gregs, 0) == -1)
+       perror_with_name (_("Couldn't get registers"));
+ 
+@@ -105,7 +105,7 @@ alphabsd_fetch_inferior_registers (struct target_ops *
+     {
+       struct fpreg fpregs;
+ 
+-      if (ptrace (PT_GETFPREGS, ptid_get_pid (inferior_ptid),
++      if (ptrace (PT_GETFPREGS, get_ptrace_pid (inferior_ptid),
+                 (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
+       perror_with_name (_("Couldn't get floating point status"));
+ 
+@@ -123,13 +123,13 @@ alphabsd_store_inferior_registers (struct target_ops *
+   if (regno == -1 || getregs_supplies (regno))
+     {
+       struct reg gregs;
+-      if (ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid),
++      if (ptrace (PT_GETREGS, get_ptrace_pid (inferior_ptid),
+                   (PTRACE_TYPE_ARG3) &gregs, 0) == -1)
+         perror_with_name (_("Couldn't get registers"));
+ 
+       alphabsd_fill_reg (regcache, (char *) &gregs, regno);
+ 
+-      if (ptrace (PT_SETREGS, ptid_get_pid (inferior_ptid),
++      if (ptrace (PT_SETREGS, get_ptrace_pid (inferior_ptid),
+                   (PTRACE_TYPE_ARG3) &gregs, 0) == -1)
+         perror_with_name (_("Couldn't write registers"));
+ 
+@@ -142,13 +142,13 @@ alphabsd_store_inferior_registers (struct target_ops *
+     {
+       struct fpreg fpregs;
+ 
+-      if (ptrace (PT_GETFPREGS, ptid_get_pid (inferior_ptid),
++      if (ptrace (PT_GETFPREGS, get_ptrace_pid (inferior_ptid),
+                 (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
+       perror_with_name (_("Couldn't get floating point status"));
+ 
+       alphabsd_fill_fpreg (regcache, (char *) &fpregs, regno);
+ 
+-      if (ptrace (PT_SETFPREGS, ptid_get_pid (inferior_ptid),
++      if (ptrace (PT_SETFPREGS, get_ptrace_pid (inferior_ptid),
+                 (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
+       perror_with_name (_("Couldn't write floating point status"));
+     }
Index: patches/patch-gdb_armnbsd-nat_c
===================================================================
RCS file: patches/patch-gdb_armnbsd-nat_c
diff -N patches/patch-gdb_armnbsd-nat_c
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ patches/patch-gdb_armnbsd-nat_c     14 May 2016 23:12:09 -0000
@@ -0,0 +1,93 @@
+$OpenBSD$
+--- gdb/armnbsd-nat.c.orig     Wed Feb 10 04:19:39 2016
++++ gdb/armnbsd-nat.c  Sat May 14 22:54:35 2016
+@@ -77,7 +77,7 @@ fetch_register (struct regcache *regcache, int regno)
+   struct reg inferior_registers;
+   int ret;
+ 
+-  ret = ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid),
++  ret = ptrace (PT_GETREGS, get_ptrace_pid (inferior_ptid),
+               (PTRACE_TYPE_ARG3) &inferior_registers, 0);
+ 
+   if (ret < 0)
+@@ -130,7 +130,7 @@ fetch_regs (struct regcache *regcache)
+   int ret;
+   int regno;
+ 
+-  ret = ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid),
++  ret = ptrace (PT_GETREGS, get_ptrace_pid (inferior_ptid),
+               (PTRACE_TYPE_ARG3) &inferior_registers, 0);
+ 
+   if (ret < 0)
+@@ -148,7 +148,7 @@ fetch_fp_register (struct regcache *regcache, int regn
+   struct fpreg inferior_fp_registers;
+   int ret;
+ 
+-  ret = ptrace (PT_GETFPREGS, ptid_get_pid (inferior_ptid),
++  ret = ptrace (PT_GETFPREGS, get_ptrace_pid (inferior_ptid),
+               (PTRACE_TYPE_ARG3) &inferior_fp_registers, 0);
+ 
+   if (ret < 0)
+@@ -178,7 +178,7 @@ fetch_fp_regs (struct regcache *regcache)
+   int ret;
+   int regno;
+ 
+-  ret = ptrace (PT_GETFPREGS, ptid_get_pid (inferior_ptid),
++  ret = ptrace (PT_GETFPREGS, get_ptrace_pid (inferior_ptid),
+               (PTRACE_TYPE_ARG3) &inferior_fp_registers, 0);
+ 
+   if (ret < 0)
+@@ -216,7 +216,7 @@ store_register (const struct regcache *regcache, int r
+   struct reg inferior_registers;
+   int ret;
+ 
+-  ret = ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid),
++  ret = ptrace (PT_GETREGS, get_ptrace_pid (inferior_ptid),
+               (PTRACE_TYPE_ARG3) &inferior_registers, 0);
+ 
+   if (ret < 0)
+@@ -279,7 +279,7 @@ store_register (const struct regcache *regcache, int r
+       break;
+     }
+ 
+-  ret = ptrace (PT_SETREGS, ptid_get_pid (inferior_ptid),
++  ret = ptrace (PT_SETREGS, get_ptrace_pid (inferior_ptid),
+               (PTRACE_TYPE_ARG3) &inferior_registers, 0);
+ 
+   if (ret < 0)
+@@ -327,7 +327,7 @@ store_regs (const struct regcache *regcache)
+       inferior_registers.r_pc = pc_val | psr_val;
+     }
+ 
+-  ret = ptrace (PT_SETREGS, ptid_get_pid (inferior_ptid),
++  ret = ptrace (PT_SETREGS, get_ptrace_pid (inferior_ptid),
+               (PTRACE_TYPE_ARG3) &inferior_registers, 0);
+ 
+   if (ret < 0)
+@@ -340,7 +340,7 @@ store_fp_register (const struct regcache *regcache, in
+   struct fpreg inferior_fp_registers;
+   int ret;
+ 
+-  ret = ptrace (PT_GETFPREGS, ptid_get_pid (inferior_ptid),
++  ret = ptrace (PT_GETFPREGS, get_ptrace_pid (inferior_ptid),
+               (PTRACE_TYPE_ARG3) &inferior_fp_registers, 0);
+ 
+   if (ret < 0)
+@@ -362,7 +362,7 @@ store_fp_register (const struct regcache *regcache, in
+       break;
+     }
+ 
+-  ret = ptrace (PT_SETFPREGS, ptid_get_pid (inferior_ptid),
++  ret = ptrace (PT_SETFPREGS, get_ptrace_pid (inferior_ptid),
+               (PTRACE_TYPE_ARG3) &inferior_fp_registers, 0);
+ 
+   if (ret < 0)
+@@ -384,7 +384,7 @@ store_fp_regs (const struct regcache *regcache)
+   regcache_raw_collect (regcache, ARM_FPS_REGNUM,
+                       (char *) &inferior_fp_registers.fpr_fpsr);
+ 
+-  ret = ptrace (PT_SETFPREGS, ptid_get_pid (inferior_ptid),
++  ret = ptrace (PT_SETFPREGS, get_ptrace_pid (inferior_ptid),
+               (PTRACE_TYPE_ARG3) &inferior_fp_registers, 0);
+ 
+   if (ret < 0)
Index: patches/patch-gdb_hppaobsd-nat_c
===================================================================
RCS file: patches/patch-gdb_hppaobsd-nat_c
diff -N patches/patch-gdb_hppaobsd-nat_c
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ patches/patch-gdb_hppaobsd-nat_c    14 May 2016 23:12:09 -0000
@@ -0,0 +1,53 @@
+$OpenBSD$
+--- gdb/hppaobsd-nat.c.orig    Wed Feb 10 04:19:39 2016
++++ gdb/hppaobsd-nat.c Sat May 14 22:54:35 2016
+@@ -193,7 +193,7 @@ hppaobsd_fetch_registers (struct target_ops *ops,
+     {
+       struct reg regs;
+ 
+-      if (ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid),
++      if (ptrace (PT_GETREGS, get_ptrace_pid (inferior_ptid),
+                 (PTRACE_TYPE_ARG3) &regs, 0) == -1)
+       perror_with_name (_("Couldn't get registers"));
+ 
+@@ -204,7 +204,7 @@ hppaobsd_fetch_registers (struct target_ops *ops,
+     {
+       struct fpreg fpregs;
+ 
+-      if (ptrace (PT_GETFPREGS, ptid_get_pid (inferior_ptid),
++      if (ptrace (PT_GETFPREGS, get_ptrace_pid (inferior_ptid),
+                 (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
+       perror_with_name (_("Couldn't get floating point status"));
+ 
+@@ -223,13 +223,13 @@ hppaobsd_store_registers (struct target_ops *ops,
+     {
+       struct reg regs;
+ 
+-      if (ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid),
++      if (ptrace (PT_GETREGS, get_ptrace_pid (inferior_ptid),
+                   (PTRACE_TYPE_ARG3) &regs, 0) == -1)
+         perror_with_name (_("Couldn't get registers"));
+ 
+       hppaobsd_collect_gregset (regcache, &regs, regnum);
+ 
+-      if (ptrace (PT_SETREGS, ptid_get_pid (inferior_ptid),
++      if (ptrace (PT_SETREGS, get_ptrace_pid (inferior_ptid),
+                 (PTRACE_TYPE_ARG3) &regs, 0) == -1)
+         perror_with_name (_("Couldn't write registers"));
+     }
+@@ -238,13 +238,13 @@ hppaobsd_store_registers (struct target_ops *ops,
+     {
+       struct fpreg fpregs;
+ 
+-      if (ptrace (PT_GETFPREGS, ptid_get_pid (inferior_ptid),
++      if (ptrace (PT_GETFPREGS, get_ptrace_pid (inferior_ptid),
+                 (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
+       perror_with_name (_("Couldn't get floating point status"));
+ 
+       hppaobsd_collect_fpregset (regcache, &fpregs, regnum);
+ 
+-      if (ptrace (PT_SETFPREGS, ptid_get_pid (inferior_ptid),
++      if (ptrace (PT_SETFPREGS, get_ptrace_pid (inferior_ptid),
+                 (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
+       perror_with_name (_("Couldn't write floating point status"));
+     }
Index: patches/patch-gdb_m88kbsd-nat_c
===================================================================
RCS file: patches/patch-gdb_m88kbsd-nat_c
diff -N patches/patch-gdb_m88kbsd-nat_c
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ patches/patch-gdb_m88kbsd-nat_c     14 May 2016 23:12:09 -0000
@@ -0,0 +1,28 @@
+$OpenBSD$
+--- gdb/m88kbsd-nat.c.orig     Wed Feb 10 04:19:39 2016
++++ gdb/m88kbsd-nat.c  Sat May 14 22:54:35 2016
+@@ -68,7 +68,7 @@ m88kbsd_fetch_inferior_registers (struct target_ops *o
+ {
+   struct reg regs;
+ 
+-  if (ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid),
++  if (ptrace (PT_GETREGS, get_ptrace_pid (inferior_ptid),
+             (PTRACE_TYPE_ARG3) &regs, 0) == -1)
+     perror_with_name (_("Couldn't get registers"));
+ 
+@@ -84,13 +84,13 @@ m88kbsd_store_inferior_registers (struct target_ops *o
+ {
+   struct reg regs;
+ 
+-  if (ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid),
++  if (ptrace (PT_GETREGS, get_ptrace_pid (inferior_ptid),
+             (PTRACE_TYPE_ARG3) &regs, 0) == -1)
+     perror_with_name (_("Couldn't get registers"));
+ 
+   m88kbsd_collect_gregset (regcache, &regs, regnum);
+ 
+-  if (ptrace (PT_SETREGS, ptid_get_pid (inferior_ptid),
++  if (ptrace (PT_SETREGS, get_ptrace_pid (inferior_ptid),
+             (PTRACE_TYPE_ARG3) &regs, 0) == -1)
+     perror_with_name (_("Couldn't write registers"));
+ }
Index: patches/patch-gdb_mips64obsd-nat_c
===================================================================
RCS file: patches/patch-gdb_mips64obsd-nat_c
diff -N patches/patch-gdb_mips64obsd-nat_c
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ patches/patch-gdb_mips64obsd-nat_c  14 May 2016 23:12:09 -0000
@@ -0,0 +1,28 @@
+$OpenBSD$
+--- gdb/mips64obsd-nat.c.orig  Wed Feb 10 04:19:39 2016
++++ gdb/mips64obsd-nat.c       Sat May 14 22:54:35 2016
+@@ -83,7 +83,7 @@ mips64obsd_fetch_inferior_registers (struct target_ops
+ {
+   struct reg regs;
+ 
+-  if (ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid),
++  if (ptrace (PT_GETREGS, get_ptrace_pid (inferior_ptid),
+             (PTRACE_TYPE_ARG3) &regs, 0) == -1)
+     perror_with_name (_("Couldn't get registers"));
+ 
+@@ -99,13 +99,13 @@ mips64obsd_store_inferior_registers (struct target_ops
+ {
+   struct reg regs;
+ 
+-  if (ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid),
++  if (ptrace (PT_GETREGS, get_ptrace_pid (inferior_ptid),
+             (PTRACE_TYPE_ARG3) &regs, 0) == -1)
+     perror_with_name (_("Couldn't get registers"));
+ 
+   mips64obsd_collect_gregset (regcache, &regs, regnum);
+ 
+-  if (ptrace (PT_SETREGS, ptid_get_pid (inferior_ptid),
++  if (ptrace (PT_SETREGS, get_ptrace_pid (inferior_ptid),
+             (PTRACE_TYPE_ARG3) &regs, 0) == -1)
+     perror_with_name (_("Couldn't write registers"));
+ }
Index: patches/patch-gdb_ppcobsd-nat_c
===================================================================
RCS file: patches/patch-gdb_ppcobsd-nat_c
diff -N patches/patch-gdb_ppcobsd-nat_c
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ patches/patch-gdb_ppcobsd-nat_c     14 May 2016 23:12:09 -0000
@@ -0,0 +1,56 @@
+$OpenBSD$
+--- gdb/ppcobsd-nat.c.orig     Wed Feb 10 04:19:39 2016
++++ gdb/ppcobsd-nat.c  Sat May 14 22:54:35 2016
+@@ -76,7 +76,7 @@ ppcobsd_fetch_registers (struct target_ops *ops,
+ {
+   struct reg regs;
+ 
+-  if (ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid),
++  if (ptrace (PT_GETREGS, get_ptrace_pid (inferior_ptid),
+             (PTRACE_TYPE_ARG3) &regs, 0) == -1)
+     perror_with_name (_("Couldn't get registers"));
+ 
+@@ -93,7 +93,7 @@ ppcobsd_fetch_registers (struct target_ops *ops,
+     {
+       struct fpreg fpregs;
+ 
+-      if (ptrace (PT_GETFPREGS, ptid_get_pid (inferior_ptid),
++      if (ptrace (PT_GETFPREGS, get_ptrace_pid (inferior_ptid),
+                 (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
+       perror_with_name (_("Couldn't get floating point status"));
+ 
+@@ -112,7 +112,7 @@ ppcobsd_store_registers (struct target_ops *ops,
+ {
+   struct reg regs;
+ 
+-  if (ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid),
++  if (ptrace (PT_GETREGS, get_ptrace_pid (inferior_ptid),
+             (PTRACE_TYPE_ARG3) &regs, 0) == -1)
+     perror_with_name (_("Couldn't get registers"));
+ 
+@@ -123,7 +123,7 @@ ppcobsd_store_registers (struct target_ops *ops,
+                       regnum, &regs, sizeof regs);
+ #endif
+ 
+-  if (ptrace (PT_SETREGS, ptid_get_pid (inferior_ptid),
++  if (ptrace (PT_SETREGS, get_ptrace_pid (inferior_ptid),
+             (PTRACE_TYPE_ARG3) &regs, 0) == -1)
+     perror_with_name (_("Couldn't write registers"));
+ 
+@@ -133,14 +133,14 @@ ppcobsd_store_registers (struct target_ops *ops,
+     {
+       struct fpreg fpregs;
+ 
+-      if (ptrace (PT_GETFPREGS, ptid_get_pid (inferior_ptid),
++      if (ptrace (PT_GETFPREGS, get_ptrace_pid (inferior_ptid),
+                 (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
+       perror_with_name (_("Couldn't get floating point status"));
+ 
+       ppc_collect_fpregset (&ppcobsd_fpregset, regcache,
+                           regnum, &fpregs, sizeof fpregs);
+ 
+-      if (ptrace (PT_SETFPREGS, ptid_get_pid (inferior_ptid),
++      if (ptrace (PT_SETFPREGS, get_ptrace_pid (inferior_ptid),
+                 (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
+       perror_with_name (_("Couldn't write floating point status"));
+     }
Index: patches/patch-gdb_shnbsd-nat_c
===================================================================
RCS file: patches/patch-gdb_shnbsd-nat_c
diff -N patches/patch-gdb_shnbsd-nat_c
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ patches/patch-gdb_shnbsd-nat_c      14 May 2016 23:12:09 -0000
@@ -0,0 +1,30 @@
+$OpenBSD$
+--- gdb/shnbsd-nat.c.orig      Wed Feb 10 04:19:39 2016
++++ gdb/shnbsd-nat.c   Sat May 14 22:54:35 2016
+@@ -49,7 +49,7 @@ shnbsd_fetch_inferior_registers (struct target_ops *op
+     {
+       struct reg inferior_registers;
+ 
+-      if (ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid),
++      if (ptrace (PT_GETREGS, get_ptrace_pid (inferior_ptid),
+                 (PTRACE_TYPE_ARG3) &inferior_registers, 0) == -1)
+       perror_with_name (_("Couldn't get registers"));
+ 
+@@ -70,7 +70,7 @@ shnbsd_store_inferior_registers (struct target_ops *op
+     {
+       struct reg inferior_registers;
+ 
+-      if (ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid),
++      if (ptrace (PT_GETREGS, get_ptrace_pid (inferior_ptid),
+                 (PTRACE_TYPE_ARG3) &inferior_registers, 0) == -1)
+       perror_with_name (_("Couldn't get registers"));
+ 
+@@ -78,7 +78,7 @@ shnbsd_store_inferior_registers (struct target_ops *op
+                                 (char *) &inferior_registers,
+                                 SHNBSD_SIZEOF_GREGS);
+ 
+-      if (ptrace (PT_SETREGS, ptid_get_pid (inferior_ptid),
++      if (ptrace (PT_SETREGS, get_ptrace_pid (inferior_ptid),
+                 (PTRACE_TYPE_ARG3) &inferior_registers, 0) == -1)
+       perror_with_name (_("Couldn't set registers"));
+ 


-- 
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE

Reply via email to