This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: patch: solib_break from _r_debug.r_brk
I have to re-post the patch afterall.
In recoding it from my internal repository to current HEAD, I replaced
hard coded pointer size with the wrong function: gdbarch_ptr_bit, but
what I really wanted is simply target pointer size:
+ const unsigned ptrsz
+ = builtin_type (target_gdbarch)->builtin_func_ptr->length;
Thanks,
Aleksandar
Change log is still the same:
<date> Aleksandar Ristovski <aristovski@qnx.com>
* solib-svr4.c (svr4_fetch_solib_break_from_r_debug): New.
(enable_break): Use new function.
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 15:01:36 -0000
@@ -1181,6 +1181,40 @@ 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 dynamic 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 unsigned ptrsz
+ = builtin_type (target_gdbarch)->builtin_func_ptr->length;
+ 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 +1469,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