From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2813 invoked by alias); 29 Sep 2011 13:56:00 -0000 Received: (qmail 2801 invoked by uid 22791); 29 Sep 2011 13:55:58 -0000 X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL,BAYES_00,RCVD_NUMERIC_HELO,RP_MATCHES_RCVD,SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from lo.gmane.org (HELO lo.gmane.org) (80.91.229.12) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 29 Sep 2011 13:55:25 +0000 Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1R9H59-0002rq-PO for gdb-patches@sources.redhat.com; Thu, 29 Sep 2011 15:55:23 +0200 Received: from 209.226.137.108 ([209.226.137.108]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 29 Sep 2011 15:55:23 +0200 Received: from aristovski by 209.226.137.108 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 29 Sep 2011 15:55:23 +0200 To: gdb-patches@sources.redhat.com From: Aleksandar Ristovski Subject: patch: solib_break from _r_debug.r_brk Date: Thu, 29 Sep 2011 13:57:00 -0000 Message-ID: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------030904090308050001030608" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:6.0.2) Gecko/20110906 Thunderbird/6.0.2 X-IsSubscribed: yes 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: 2011-09/txt/msg00536.txt.bz2 This is a multi-part message in MIME format. --------------030904090308050001030608 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 505 Hello, I have a case where gdb can not find solib break function (in our case _dl_debug_state) in cases where dynamic linker library is stripped. This patch adds new fallback method of determining solib_break address by using _r_debug symbol and r_brk field from it. Test suite did not show regressions. Thank you, Aleksandar ChangeLog: Aleksandar Ristovski * solib-svr4.c (svr4_fetch_solib_break_from_r_debug): New. (enable_break): Use new function. --------------030904090308050001030608 Content-Type: text/x-patch; name="solib_break-from-r_brk-201109290930.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="solib_break-from-r_brk-201109290930.patch" Content-length: 2131 Index: gdb/solib-svr4.c =================================================================== RCS file: /cvs/src/src/gdb/solib-svr4.c,v retrieving revision 1.154 diff -u -p -r1.154 solib-svr4.c --- gdb/solib-svr4.c 30 Aug 2011 02:48:05 -0000 1.154 +++ gdb/solib-svr4.c 29 Sep 2011 13:31:00 -0000 @@ -1181,6 +1181,39 @@ cmp_name_and_sec_flags (asymbol *sym, vo return (strcmp (sym->name, (const char *) data) == 0 && (sym->section->flags & (SEC_CODE | SEC_DATA)) != 0); } + +/* Use dynamic linker bfd and try to figure out solib break + address using _r_debug.r_brk. It is expected that at this point + it is unrelocated filled with relative address of solib + break function. This case may happen if solib break function + is defined as static in the dynamic linker, and dynmic linker + library is completely stripped. */ + +static CORE_ADDR +svr4_fetch_solib_break_from_r_debug (bfd *const tmp_bfd, + const CORE_ADDR load_addr) +{ + const CORE_ADDR r_debug_sym_addr + = gdb_bfd_lookup_symbol (tmp_bfd, cmp_name_and_sec_flags, + (void *) "_r_debug"); + const struct link_map_offsets *const lmo = svr4_fetch_link_map_offsets (); + const int ptrsz = gdbarch_ptr_bit (target_gdbarch); + gdb_byte r_brk_addr[ptrsz]; + + if (target_read_memory (load_addr + r_debug_sym_addr + lmo->r_brk_offset, + r_brk_addr, ptrsz) == 0) + { + const enum bfd_endian byte_order + = gdbarch_byte_order (target_gdbarch); + + return extract_unsigned_integer (r_brk_addr, ptrsz, byte_order); + } + return 0; +} + + + + /* Arrange for dynamic linker to hit breakpoint. Both the SunOS and the SVR4 dynamic linkers have, as part of their @@ -1435,6 +1468,11 @@ enable_break (struct svr4_info *info, in break; } + /* Failing the above methods of locating debug base, use + _r_debug.r_brk structure. */ + if (sym_addr == 0 && load_addr_found) + sym_addr = svr4_fetch_solib_break_from_r_debug (tmp_bfd, load_addr); + if (sym_addr != 0) /* Convert 'sym_addr' from a function pointer to an address. Because we pass tmp_bfd_target instead of the current --------------030904090308050001030608--