Re: [patch] Implement qXfer:libraries for Linux/gdbserver

Jan Kratochvil
2011-08-08T21:10:04Z

Hi Paul,

with:
./gdbserver :1234 ~/t/pause64
../gdb ~/t/pause64 -ex 'target remote localhost:1234' -ex 'b main' -ex c

it falls back back memory-transfers as DT_DEBUG is zero initially at _start.

just to get the patch integrated on some final patches assembly.

Thanks,
Jan

gdb/gdbserver/
2011-08-08 Jan Kratochvil <jan.kratochvil@redhat.com>

Fix initial zero DT_DEBUG.
* linux-low.c (linux_add_process): Remove r_debug initialization.
(get_r_debug): Update function comment. Return -1 when DT_DEBUG is not
found.
(linux_qxfer_libraries): Call get_r_debug on -1 (not 0). Return on
both -1 or 0.

--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -264,7 +264,6 @@ linux_add_process (int pid, int attached)

proc = add_process (pid, attached);
proc->private = xcalloc (1, sizeof (*proc->private));
- proc->private->r_debug = (CORE_ADDR) -1;

if (the_low_target.new_process != NULL)
proc->private->arch_private = the_low_target.new_process ();
@@ -4863,7 +4862,8 @@ get_dynamic (const int pid, const int is_elf64)
return 0;
}

-/* Return &_r_debug in the inferior, or 0 if not present. */
+/* Return &_r_debug in the inferior, or -1 if not present. Return value
+ can be 0 if the inferior does not yet have the library list initialized. */

static CORE_ADDR
get_r_debug (const int pid, const int is_elf64)
@@ -4874,7 +4874,7 @@ get_r_debug (const int pid, const int is_elf64)

dynamic_memaddr = get_dynamic (pid, is_elf64);
if (dynamic_memaddr == 0)
- return 0;
+ return (CORE_ADDR) -1;

while (linux_read_memory (dynamic_memaddr, buf, dyn_size) == 0)
{
@@ -4981,12 +4981,10 @@ linux_qxfer_libraries (const char *annex, unsigned char *readbuf,
is_elf64 = elf_64_file_p (filename);
lmo = is_elf64 ? &lmo_64bit_offsets : &lmo_32bit_offsets;

- if (priv->r_debug == (CORE_ADDR) -1)
+ if (priv->r_debug == 0)
priv->r_debug = get_r_debug (pid, is_elf64);

- gdb_assert (priv->r_debug != (CORE_ADDR) -1);
-
- if (priv->r_debug == 0)
+ if (priv->r_debug == (CORE_ADDR) -1 || priv->r_debug == 0)
{
document = xstrdup ("<library-list/>\n");
}