This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[patchv2] Ignore the first entry returned by svr4_current_sos_via_xfer_libraries for dynamically linked programs
- From: Jan Kratochvil <jan dot kratochvil at redhat dot com>
- To: Ben Cheng <bccheng at google dot com>
- Cc: gdb-patches at sourceware dot org
- Date: Wed, 5 Jun 2013 13:38:00 +0200
- Subject: [patchv2] Ignore the first entry returned by svr4_current_sos_via_xfer_libraries for dynamically linked programs
- References: <CAPk6zkCTrkS960JAG70PdTaTAE=FQ1y4V2CneiNutSu6CG8rwA at mail dot gmail dot com> <20130604180722 dot GA23588 at host2 dot jankratochvil dot net> <CAPk6zkAcnGG4Jg=S_N_zBXefsaW0QjMc-m3B7Z-riQgZfkL24Q at mail dot gmail dot com> <20130604202301 dot GA8999 at host2 dot jankratochvil dot net> <CAPk6zkC0a-9DrKpDfn4d5mxQ1Tgm0hJ9pLMfoFhZr6OGJa34yQ at mail dot gmail dot com> <CAPk6zkB9aaTp097EcTX97UqhwQ1UasLcBcOYXsox_p2cv681rg at mail dot gmail dot com> <20130604205700 dot GA10677 at host2 dot jankratochvil dot net> <CAPk6zkBgXrkXWddho=WLXW1qVOMSdQE55pYVS7CbowCJbLQt+w at mail dot gmail dot com>
On Tue, 04 Jun 2013 23:21:36 +0200, Ben Cheng wrote:
> If you don't mind I'll let you take care of it. :)
I will check it in in some time.
Regards,
Jan
gdb/gdbserver/
2013-06-05 Jan Kratochvil <jan.kratochvil@redhat.com>
Fix compatibility with Android Bionic.
* linux-low.c (linux_qxfer_libraries_svr4): Ignore first entry even if
it is not empty.
diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
index 03ac469..0f3e0f0 100644
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -5829,45 +5829,54 @@ linux_qxfer_libraries_svr4 (const char *annex, unsigned char *readbuf,
break;
}
- /* Not checking for error because reading may stop before
- we've got PATH_MAX worth of characters. */
- libname[0] = '\0';
- linux_read_memory (l_name, libname, sizeof (libname) - 1);
- libname[sizeof (libname) - 1] = '\0';
- if (libname[0] != '\0')
+ /* Ignore the first entry even if it has valid name as the first entry
+ corresponds to the main executable. The first entry should not be
+ skipped if the dynamic loader was loaded late by a static executable
+ (see solib-svr4.c parameter ignore_first). But in such case the main
+ executable does not have PT_DYNAMIC present and this function already
+ exited above due to failed get_r_debug. */
+ if (lm_prev == 0)
{
- /* 6x the size for xml_escape_text below. */
- size_t len = 6 * strlen ((char *) libname);
- char *name;
-
- if (!header_done)
+ sprintf (p, " main-lm=\"0x%lx\"", (unsigned long) lm_addr);
+ p = p + strlen (p);
+ }
+ else
+ {
+ /* Not checking for error because reading may stop before
+ we've got PATH_MAX worth of characters. */
+ libname[0] = '\0';
+ linux_read_memory (l_name, libname, sizeof (libname) - 1);
+ libname[sizeof (libname) - 1] = '\0';
+ if (libname[0] != '\0')
{
- /* Terminate `<library-list-svr4'. */
- *p++ = '>';
- header_done = 1;
- }
+ /* 6x the size for xml_escape_text below. */
+ size_t len = 6 * strlen ((char *) libname);
+ char *name;
- while (allocated < p - document + len + 200)
- {
- /* Expand to guarantee sufficient storage. */
- uintptr_t document_len = p - document;
+ if (!header_done)
+ {
+ /* Terminate `<library-list-svr4'. */
+ *p++ = '>';
+ header_done = 1;
+ }
- document = xrealloc (document, 2 * allocated);
- allocated *= 2;
- p = document + document_len;
- }
+ while (allocated < p - document + len + 200)
+ {
+ /* Expand to guarantee sufficient storage. */
+ uintptr_t document_len = p - document;
- name = xml_escape_text ((char *) libname);
- p += sprintf (p, "<library name=\"%s\" lm=\"0x%lx\" "
- "l_addr=\"0x%lx\" l_ld=\"0x%lx\"/>",
- name, (unsigned long) lm_addr,
- (unsigned long) l_addr, (unsigned long) l_ld);
- free (name);
- }
- else if (lm_prev == 0)
- {
- sprintf (p, " main-lm=\"0x%lx\"", (unsigned long) lm_addr);
- p = p + strlen (p);
+ document = xrealloc (document, 2 * allocated);
+ allocated *= 2;
+ p = document + document_len;
+ }
+
+ name = xml_escape_text ((char *) libname);
+ p += sprintf (p, "<library name=\"%s\" lm=\"0x%lx\" "
+ "l_addr=\"0x%lx\" l_ld=\"0x%lx\"/>",
+ name, (unsigned long) lm_addr,
+ (unsigned long) l_addr, (unsigned long) l_ld);
+ free (name);
+ }
}
lm_prev = lm_addr;