Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* patch: solib_break from _r_debug.r_brk
@ 2011-09-29 13:57 Aleksandar Ristovski
  2011-09-29 14:04 ` Marek Polacek
  2011-10-12 21:16 ` Jan Kratochvil
  0 siblings, 2 replies; 11+ messages in thread
From: Aleksandar Ristovski @ 2011-09-29 13:57 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 505 bytes --]

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:

<date>  Aleksandar Ristovski  <aristovski@qnx.com>

     * solib-svr4.c (svr4_fetch_solib_break_from_r_debug): New.
     (enable_break): Use new function.


[-- Attachment #2: solib_break-from-r_brk-201109290930.patch --]
[-- Type: text/x-patch, Size: 2131 bytes --]

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

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2011-10-12 21:16 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-29 13:57 patch: solib_break from _r_debug.r_brk Aleksandar Ristovski
2011-09-29 14:04 ` Marek Polacek
2011-09-29 14:32   ` Aleksandar Ristovski
2011-09-29 15:15     ` Aleksandar Ristovski
2011-10-03 19:51       ` Aleksandar Ristovski
2011-10-03 20:12       ` Tom Tromey
2011-10-03 20:40         ` Aleksandar Ristovski
2011-10-04 16:58           ` Tom Tromey
2011-10-04 17:59             ` Aleksandar Ristovski
2011-10-10  2:32           ` Daniel Jacobowitz
2011-10-12 21:16 ` Jan Kratochvil

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox