From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19156 invoked by alias); 12 Sep 2007 21:18:14 -0000 Received: (qmail 19134 invoked by uid 22791); 12 Sep 2007 21:18:13 -0000 X-Spam-Check-By: sourceware.org Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.31) with ESMTP; Wed, 12 Sep 2007 21:18:09 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id E1A152AAF61 for ; Wed, 12 Sep 2007 17:18:07 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id TFUhvZKp1kjX for ; Wed, 12 Sep 2007 17:18:07 -0400 (EDT) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id 745D72AAF5D for ; Wed, 12 Sep 2007 17:18:07 -0400 (EDT) Received: by joel.gnat.com (Postfix, from userid 1000) id 1FBDEE7B58; Wed, 12 Sep 2007 17:18:05 -0400 (EDT) Date: Wed, 12 Sep 2007 21:18:00 -0000 From: Joel Brobecker To: gdb-patches@sourceware.org Subject: [RFA/solib-svr4] use AT_BASE auxiliary entry to compute load base address Message-ID: <20070912211805.GF10540@adacore.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="ZmUaFz6apKcXQszQ" Content-Disposition: inline User-Agent: Mutt/1.4.2.2i Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2007-09/txt/msg00167.txt.bz2 --ZmUaFz6apKcXQszQ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 1220 Hello, I came across an unexpected issue on sparc-solaris 2.9, where I tried to attach to an Ada program. When I later did a "continue", the debugger error'ed out saying: (gdb) c Continuing. Warning: Cannot insert breakpoint -1. Error accessing memory address 0xff36159c: I/O error. Breakpoint -1 here corresponds to the shlib breakpoint: (gdb) maintenance info breakpoints Num Type Disp Enb Address What -1 shlib events keep y 0xff36159c I think that the problem is that we're computing the wrong base load address in solib-svr4.c. As it turned out, there was a "TODO" hint added by Daniel that suggested using the AT_BASE auxiliary entry. The attached patch attempts to do that. 2007-09-12 Joel Brobecker * solib-svr4.c: Add include of "auxv.h". (enable_break): Use the AT_BASE auxiliary entry if available. * Makefile.in (solib-svr4.o): Update dependencies. Tested on x86-linux, no regression. Currently testing on sparc-solaris, but it's taking a loooong time because sigstep is keeps timing out to death. It fixes the issue above, and I'm confident the results will be OK. OK to apply? Thanks, -- Joel --ZmUaFz6apKcXQszQ Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="solib-svr4.diff" Content-length: 2653 Index: solib-svr4.c =================================================================== RCS file: /cvs/src/src/gdb/solib-svr4.c,v retrieving revision 1.75 diff -u -p -r1.75 solib-svr4.c --- solib-svr4.c 23 Aug 2007 18:08:38 -0000 1.75 +++ solib-svr4.c 12 Sep 2007 21:03:39 -0000 @@ -41,6 +41,7 @@ #include "bfd-target.h" #include "elf-bfd.h" #include "exec.h" +#include "auxv.h" static struct link_map_offsets *svr4_fetch_link_map_offsets (void); static int svr4_have_link_map_offsets (void); @@ -1008,11 +1009,6 @@ enable_break (void) be trivial on GNU/Linux). Therefore, we have to try an alternate mechanism to find the dynamic linker's base address. */ - /* TODO drow/2006-09-12: This is somewhat fragile, because it - relies on read_pc. On both Solaris and GNU/Linux we can use - the AT_BASE auxilliary entry, which GDB now knows how to - access, to find the base address. */ - tmp_fd = solib_open (buf, &tmp_pathname); if (tmp_fd >= 0) tmp_bfd = bfd_fopen (tmp_pathname, gnutarget, FOPEN_RB, tmp_fd); @@ -1048,9 +1044,19 @@ enable_break (void) so = so->next; } + /* If we were not able to find the base address of the loader + from our so_list, then try using the AT_BASE auxilliary entry. */ + if (!load_addr_found) + if (target_auxv_search (¤t_target, AT_BASE, &load_addr) > 0) + load_addr_found = 1; + /* Otherwise we find the dynamic linker's base address by examining the current pc (which should point at the entry point for the - dynamic linker) and subtracting the offset of the entry point. */ + dynamic linker) and subtracting the offset of the entry point. + + This is more fragile than the previous approaches, but is a good + fallback method because it has actually been working well in + most cases. */ if (!load_addr_found) { load_addr = (read_pc () Index: Makefile.in =================================================================== RCS file: /cvs/src/src/gdb/Makefile.in,v retrieving revision 1.936 diff -u -p -r1.936 Makefile.in --- Makefile.in 5 Sep 2007 00:14:02 -0000 1.936 +++ Makefile.in 12 Sep 2007 21:03:07 -0000 @@ -2622,7 +2622,7 @@ solib-svr4.o: solib-svr4.c $(defs_h) $(e $(elf_mips_h) $(symtab_h) $(bfd_h) $(symfile_h) $(objfiles_h) \ $(gdbcore_h) $(target_h) $(inferior_h) $(gdb_assert_h) \ $(solist_h) $(solib_h) $(solib_svr4_h) $(bfd_target_h) $(elf_bfd_h) \ - $(exec_h) + $(exec_h) $(auxv_h) solib-target.o: solib-target.c $(defs_h) $(objfiles_h) $(solist_h) \ $(symtab_h) $(symfile_h) $(target_h) $(vec_h) $(xml_support_h) \ $(gdb_string_h) --ZmUaFz6apKcXQszQ--