NetBSD Problem Report #50773

From www@NetBSD.org  Fri Feb  5 23:42:00 2016
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.NetBSD.org [199.233.217.200])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.netbsd.org", Issuer "Postmaster NetBSD.org" (verified OK))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 224C97ACA7
	for <gnats-bugs@gnats.NetBSD.org>; Fri,  5 Feb 2016 23:42:00 +0000 (UTC)
Message-Id: <20160205234158.CD8237ACBE@mollari.NetBSD.org>
Date: Fri,  5 Feb 2016 23:41:58 +0000 (UTC)
From: okuyama@flex.phys.tohoku.ac.jp
Reply-To: okuyama@flex.phys.tohoku.ac.jp
To: gnats-bugs@NetBSD.org
Subject: GDB single stepping fails for dynamically linked binary on armbe
X-Send-Pr-Version: www-1.0

>Number:         50773
>Category:       toolchain
>Synopsis:       GDB single stepping fails for dynamically linked binary on armbe
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    toolchain-manager
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Feb 05 23:45:00 +0000 2016
>Closed-Date:    Sun Oct 04 09:59:26 +0000 2020
>Last-Modified:  Sun Oct 04 09:59:26 +0000 2020
>Originator:     Rin Okuyama
>Release:        7.99.26
>Organization:
Department of Physics, Tohoku University
>Environment:
NetBSD XXX 7.99.26 NetBSD 7.99.26 (CUBIETRUCK) #0: Sat Feb  6 00:44:25 JST 2016  rin@XXX:XXX evbarm
>Description:
On armeb, single stepping of GDB works for statically linked binaries:

  % uname -pr
  7.99.26 earmv7hfeb
  % cc -g -O0 -static -o hello_s hello.c
  % gdb ./hello_s
  ...
  Reading symbols from ./hello_s...done.
  (gdb) b main
  Breakpoint 1 at 0x103c4: file hello.c, line 7.
  (gdb) r
  Starting program: /home/rin/hello_s

  Breakpoint 1, main () at hello.c:7
  7               printf("Hello, World!\n");
  (gdb) s
  Hello, World!
  8               return 0;
  (gdb) s
  9       }
  (gdb) s
  0x00010328 in ___start ()
  (gdb) s
  Single stepping until exit from function ___start,
  which has no line number information.
  [Inferior 1 (process 573) exited normally]
  (gdb)

However, it does not work for dynamically linked binaries:

  % cc -g -O0 -o hello_d hello.c
  % gdb ./hello_d
  ...
  Reading symbols from ./hello_d...done.
  (gdb) b main
  Breakpoint 1 at 0x107a4: file hello.c, line 7.
  (gdb) r
  Starting program: /home/rin/hello_d

  Breakpoint 1, main () at hello.c:7
  7               printf("Hello, World!\n");
  (gdb) s

Then, nothing was outputted further. After interrupting by Ctrl-C,
I took backtrace, which indicates infinite recursive in ld.elf_so:

  (gdb) s
  ^C
  Program received signal SIGINT, Interrupt.
  0x7bfdc60c in atomic_cas_ulong_ni () from /usr/libexec/ld.elf_so
  (gdb) bt
  #0  0x7bfdc60c in atomic_cas_ulong_ni () from /usr/libexec/ld.elf_so
  #1  0x7bfd33d0 in _rtld_shared_enter () from /usr/libexec/ld.elf_so
  #2  0x7bfd1fd4 in _rtld_bind () from /usr/libexec/ld.elf_so
  #3  0x7bfd1b44 in _rtld_bind_start () from /usr/libexec/ld.elf_so
  #4  0x7bfd1b44 in _rtld_bind_start () from /usr/libexec/ld.elf_so
  #5  0x7bfd1b44 in _rtld_bind_start () from /usr/libexec/ld.elf_so
  ...

Note that this problem occurs both for GDB 7.9.1 and 7.10.1. I guess
this is a similar problem to toolchain/49445.
>How-To-Repeat:
described above
>Fix:
n/a

>Release-Note:

>Audit-Trail:
From: Rin Okuyama <rokuyama@rk.phys.keio.ac.jp>
To: gnats-bugs@NetBSD.org
Cc: gnats-admin@netbsd.org
Subject: Re: toolchain/50773: GDB single stepping fails for dynamically linked
 binary on armbe
Date: Thu, 2 Jun 2016 03:31:23 +0900

 I observed the exactly same problem also on armel:

    % uname -mpr
    7.99.30 evbarm earmv7hf

 The problem has nothing to do with the byte order, and the title of
 the PR turned out to be misleading. Please change it to

    "GDB single stepping fails for dynamically linked binary on arm".

 There might be problems between ld.elf_so and the shared-library
 handling in GDB on NetBSD/arm.

From: Rin Okuyama <rokuyama@rk.phys.keio.ac.jp>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: toolchain/50773: GDB single stepping fails for dynamically linked
 binary on armbe
Date: Sun, 5 Jun 2016 01:04:15 +0900

 On 2016/06/02 3:31, Rin Okuyama wrote:
 > I observed the exactly same problem also on armel:
 >
 >   % uname -mpr
 >   7.99.30 evbarm earmv7hf
 (snip)

 Finally, I got it working! We need to skip symbol from ld.elf_so,
 as in the case of OpenBSD/arm. Then, single stepping works fine
 for dynamically linked binaries. I have tested both gdb (7.10) and
 gdb.old (7.9) both on evbearmv7hf-eb and -el. Please apply the
 attached patch below.

 Thanks,
 Rin

 --- src/external/gpl3/gdb.old/dist/gdb/armnbsd-tdep.c.orig	2016-06-04 22:18:36.500300231 +0900
 +++ src/external/gpl3/gdb.old/dist/gdb/armnbsd-tdep.c	2016-06-04 23:31:38.080675054 +0900
 @@ -19,6 +19,7 @@

   #include "defs.h"
   #include "osabi.h"
 +#include "objfiles.h"

   #include "arm-tdep.h"
   #include "solib-svr4.h"
 @@ -27,6 +28,8 @@
   #define ARM_NBSD_JB_PC 24
   #define ARM_NBSD_JB_ELEMENT_SIZE INT_REGISTER_SIZE

 +CORE_ADDR armnbsd_skip_solib_resolver (struct gdbarch *, CORE_ADDR);
 +
   /* For compatibility with previous implemenations of GDB on arm/NetBSD,
      override the default little-endian breakpoint.  */
   static const gdb_byte arm_nbsd_arm_le_breakpoint[] = {0x11, 0x00, 0x00, 0xe6};
 @@ -34,6 +37,19 @@
   static const gdb_byte arm_nbsd_thumb_le_breakpoint[] = {0xfe, 0xde};
   static const gdb_byte arm_nbsd_thumb_be_breakpoint[] = {0xde, 0xfe};

 +/* from obsd-tdep.c with symbol name adjusted to ours */
 +CORE_ADDR
 +armnbsd_skip_solib_resolver (struct gdbarch *gdbarch, CORE_ADDR pc)
 +{
 +  struct bound_minimal_symbol msym;
 +
 +  msym = lookup_minimal_symbol("_rtld_bind", NULL, NULL);
 +  if (msym.minsym && BMSYMBOL_VALUE_ADDRESS (msym) == pc)
 +    return frame_unwind_caller_pc (get_current_frame ());
 +  else
 +    return find_solib_trampoline_target (get_current_frame (), pc);
 +}
 +
   static void
   arm_netbsd_init_abi_common (struct gdbarch_info info,
   			    struct gdbarch *gdbarch)
 @@ -93,6 +109,9 @@
     /* NetBSD ELF uses SVR4-style shared libraries.  */
     set_solib_svr4_fetch_link_map_offsets
       (gdbarch, svr4_ilp32_fetch_link_map_offsets);
 +
 +  /* for single stepping; see PR/50773 */
 +  set_gdbarch_skip_solib_resolver (gdbarch, armnbsd_skip_solib_resolver);
   }

   static enum gdb_osabi
 --- src/external/gpl3/gdb/dist/gdb/armnbsd-tdep.c.orig	2016-06-04 22:22:13.446960426 +0900
 +++ src/external/gpl3/gdb/dist/gdb/armnbsd-tdep.c	2016-06-04 23:30:59.155155886 +0900
 @@ -19,6 +19,7 @@

   #include "defs.h"
   #include "osabi.h"
 +#include "objfiles.h"

   #include "arm-tdep.h"
   #include "solib-svr4.h"
 @@ -27,6 +28,8 @@
   #define ARM_NBSD_JB_PC 24
   #define ARM_NBSD_JB_ELEMENT_SIZE INT_REGISTER_SIZE

 +CORE_ADDR armnbsd_skip_solib_resolver (struct gdbarch *, CORE_ADDR);
 +
   /* For compatibility with previous implemenations of GDB on arm/NetBSD,
      override the default little-endian breakpoint.  */
   static const gdb_byte arm_nbsd_arm_le_breakpoint[] = {0x11, 0x00, 0x00, 0xe6};
 @@ -34,6 +37,19 @@
   static const gdb_byte arm_nbsd_thumb_le_breakpoint[] = {0xfe, 0xde};
   static const gdb_byte arm_nbsd_thumb_be_breakpoint[] = {0xde, 0xfe};

 +/* from obsd-tdep.c with symbol name adjusted to ours */
 +CORE_ADDR
 +armnbsd_skip_solib_resolver (struct gdbarch *gdbarch, CORE_ADDR pc)
 +{
 +  struct bound_minimal_symbol msym;
 +
 +  msym = lookup_minimal_symbol("_rtld_bind", NULL, NULL);
 +  if (msym.minsym && BMSYMBOL_VALUE_ADDRESS (msym) == pc)
 +    return frame_unwind_caller_pc (get_current_frame ());
 +  else
 +    return find_solib_trampoline_target (get_current_frame (), pc);
 +}
 +
   static void
   arm_netbsd_init_abi_common (struct gdbarch_info info,
   			    struct gdbarch *gdbarch)
 @@ -93,6 +109,9 @@
     /* NetBSD ELF uses SVR4-style shared libraries.  */
     set_solib_svr4_fetch_link_map_offsets
       (gdbarch, svr4_ilp32_fetch_link_map_offsets);
 +
 +  /* for single stepping; see PR/50773 */
 +  set_gdbarch_skip_solib_resolver (gdbarch, armnbsd_skip_solib_resolver);
   }

   static enum gdb_osabi

From: "Christos Zoulas" <christos@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/50773 CVS commit: src/external/gpl3
Date: Sat, 4 Jun 2016 12:14:29 -0400

 Module Name:	src
 Committed By:	christos
 Date:		Sat Jun  4 16:14:29 UTC 2016

 Modified Files:
 	src/external/gpl3/gdb.old/dist/gdb: armnbsd-tdep.c
 	src/external/gpl3/gdb/dist/gdb: armnbsd-tdep.c

 Log Message:
 PR/50773: Rin Okuyama: Fix single stepping on dynamically linked binaries
 by skipping dynamic linker calls (from OpenBSD)


 To generate a diff of this commit:
 cvs rdiff -u -r1.3 -r1.4 src/external/gpl3/gdb.old/dist/gdb/armnbsd-tdep.c
 cvs rdiff -u -r1.3 -r1.4 src/external/gpl3/gdb/dist/gdb/armnbsd-tdep.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: David Holland <dholland-bugs@netbsd.org>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: PR/50773 CVS commit: src/external/gpl3
Date: Sun, 12 Jun 2016 20:56:46 +0000

 On Sat, Jun 04, 2016 at 04:15:01PM +0000, Christos Zoulas wrote:
  >  Log Message:
  >  PR/50773: Rin Okuyama: Fix single stepping on dynamically linked binaries
  >  by skipping dynamic linker calls (from OpenBSD)

 Does this need to be in -7, or does it apply only to the gdb from
 head?

 -- 
 David A. Holland
 dholland@netbsd.org

From: christos@zoulas.com (Christos Zoulas)
To: gnats-bugs@NetBSD.org, toolchain-manager@netbsd.org, 
	gnats-admin@netbsd.org, netbsd-bugs@netbsd.org, 
	okuyama@flex.phys.tohoku.ac.jp
Cc: 
Subject: Re: PR/50773 CVS commit: src/external/gpl3
Date: Sun, 12 Jun 2016 17:37:42 -0400

 On Jun 12,  9:00pm, dholland-bugs@netbsd.org (David Holland) wrote:
 -- Subject: Re: PR/50773 CVS commit: src/external/gpl3

 |  Does this need to be in -7, or does it apply only to the gdb from
 |  head?

 It can go to -7.

 christos

State-Changed-From-To: open->needs-pullups
State-Changed-By: dholland@NetBSD.org
State-Changed-When: Sun, 12 Jun 2016 23:13:12 +0000
State-Changed-Why:
we have a shiny new PR state for this :-)


State-Changed-From-To: needs-pullups->closed
State-Changed-By: rin@NetBSD.org
State-Changed-When: Sun, 04 Oct 2020 09:59:26 +0000
State-Changed-Why:
No release branchs are affected (netbsd-7 has been EOL'd).


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.46 2020/01/03 16:35:01 leot Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2020 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.