Blame SOURCES/gdb-dlopen-stap-probe-3of9.patch

861f93
http://sourceware.org/ml/gdb-cvs/2013-06/msg00014.html
861f93
861f93
### src/gdb/gdbserver/ChangeLog	2013/05/31 19:14:33	1.720
861f93
### src/gdb/gdbserver/ChangeLog	2013/06/04 12:59:20	1.721
861f93
## -1,3 +1,12 @@
861f93
+2013-06-04  Gary Benson  <gbenson@redhat.com>
861f93
+
861f93
+	* server.c (handle_query): Add "augmented-libraries-svr4-read+"
861f93
+	to qSupported response when appropriate.
861f93
+	(handle_qxfer_libraries_svr4): Allow qXfer:libraries-svr4:read
861f93
+	with nonzero-length annex.
861f93
+	* linux-low.c (linux_qxfer_libraries_svr4): Parse and handle
861f93
+	arguments supplied in annex.
861f93
+
861f93
 2013-05-31  Doug Evans  <dje@google.com>
861f93
 
861f93
 	* linux-x86-low.c (ps_get_thread_area): Properly extend address to
861f93
--- src/gdb/gdbserver/linux-low.c	2013/05/23 17:17:50	1.237
861f93
+++ src/gdb/gdbserver/linux-low.c	2013/06/04 12:59:21	1.238
861f93
@@ -5728,6 +5728,12 @@
861f93
     };
861f93
   const struct link_map_offsets *lmo;
861f93
   unsigned int machine;
861f93
+  int ptr_size;
861f93
+  CORE_ADDR lm_addr = 0, lm_prev = 0;
861f93
+  int allocated = 1024;
861f93
+  char *p;
861f93
+  CORE_ADDR l_name, l_addr, l_ld, l_next, l_prev;
861f93
+  int header_done = 0;
861f93
 
861f93
   if (writebuf != NULL)
861f93
     return -2;
861f93
@@ -5738,128 +5744,144 @@
861f93
   xsnprintf (filename, sizeof filename, "/proc/%d/exe", pid);
861f93
   is_elf64 = elf_64_file_p (filename, &machine);
861f93
   lmo = is_elf64 ? &lmo_64bit_offsets : &lmo_32bit_offsets;
861f93
+  ptr_size = is_elf64 ? 8 : 4;
861f93
 
861f93
-  if (priv->r_debug == 0)
861f93
-    priv->r_debug = get_r_debug (pid, is_elf64);
861f93
-
861f93
-  /* We failed to find DT_DEBUG.  Such situation will not change for this
861f93
-     inferior - do not retry it.  Report it to GDB as E01, see for the reasons
861f93
-     at the GDB solib-svr4.c side.  */
861f93
-  if (priv->r_debug == (CORE_ADDR) -1)
861f93
-    return -1;
861f93
-
861f93
-  if (priv->r_debug == 0)
861f93
+  while (annex[0] != '\0')
861f93
     {
861f93
-      document = xstrdup ("<library-list-svr4 version=\"1.0\"/>\n");
861f93
+      const char *sep;
861f93
+      CORE_ADDR *addrp;
861f93
+      int len;
861f93
+
861f93
+      sep = strchr (annex, '=');
861f93
+      if (sep == NULL)
861f93
+	break;
861f93
+
861f93
+      len = sep - annex;
861f93
+      if (len == 5 && strncmp (annex, "start", 5) == 0)
861f93
+	addrp = &lm_addr;
861f93
+      else if (len == 4 && strncmp (annex, "prev", 4) == 0)
861f93
+	addrp = &lm_prev;
861f93
+      else
861f93
+	{
861f93
+	  annex = strchr (sep, ';');
861f93
+	  if (annex == NULL)
861f93
+	    break;
861f93
+	  annex++;
861f93
+	  continue;
861f93
+	}
861f93
+
861f93
+      annex = decode_address_to_semicolon (addrp, sep + 1);
861f93
     }
861f93
-  else
861f93
+
861f93
+  if (lm_addr == 0)
861f93
     {
861f93
-      int allocated = 1024;
861f93
-      char *p;
861f93
-      const int ptr_size = is_elf64 ? 8 : 4;
861f93
-      CORE_ADDR lm_addr, lm_prev, l_name, l_addr, l_ld, l_next, l_prev;
861f93
-      int r_version, header_done = 0;
861f93
-
861f93
-      document = xmalloc (allocated);
861f93
-      strcpy (document, "
861f93
-      p = document + strlen (document);
861f93
-
861f93
-      r_version = 0;
861f93
-      if (linux_read_memory (priv->r_debug + lmo->r_version_offset,
861f93
-			     (unsigned char *) &r_version,
861f93
-			     sizeof (r_version)) != 0
861f93
-	  || r_version != 1)
861f93
+      int r_version = 0;
861f93
+
861f93
+      if (priv->r_debug == 0)
861f93
+	priv->r_debug = get_r_debug (pid, is_elf64);
861f93
+
861f93
+      /* We failed to find DT_DEBUG.  Such situation will not change
861f93
+	 for this inferior - do not retry it.  Report it to GDB as
861f93
+	 E01, see for the reasons at the GDB solib-svr4.c side.  */
861f93
+      if (priv->r_debug == (CORE_ADDR) -1)
861f93
+	return -1;
861f93
+
861f93
+      if (priv->r_debug != 0)
861f93
 	{
861f93
-	  warning ("unexpected r_debug version %d", r_version);
861f93
-	  goto done;
861f93
+	  if (linux_read_memory (priv->r_debug + lmo->r_version_offset,
861f93
+				 (unsigned char *) &r_version,
861f93
+				 sizeof (r_version)) != 0
861f93
+	      || r_version != 1)
861f93
+	    {
861f93
+	      warning ("unexpected r_debug version %d", r_version);
861f93
+	    }
861f93
+	  else if (read_one_ptr (priv->r_debug + lmo->r_map_offset,
861f93
+				 &lm_addr, ptr_size) != 0)
861f93
+	    {
861f93
+	      warning ("unable to read r_map from 0x%lx",
861f93
+		       (long) priv->r_debug + lmo->r_map_offset);
861f93
+	    }
861f93
 	}
861f93
+    }
861f93
+
861f93
+  document = xmalloc (allocated);
861f93
+  strcpy (document, "
861f93
+  p = document + strlen (document);
861f93
+
861f93
+  while (lm_addr
861f93
+	 && read_one_ptr (lm_addr + lmo->l_name_offset,
861f93
+			  &l_name, ptr_size) == 0
861f93
+	 && read_one_ptr (lm_addr + lmo->l_addr_offset,
861f93
+			  &l_addr, ptr_size) == 0
861f93
+	 && read_one_ptr (lm_addr + lmo->l_ld_offset,
861f93
+			  &l_ld, ptr_size) == 0
861f93
+	 && read_one_ptr (lm_addr + lmo->l_prev_offset,
861f93
+			  &l_prev, ptr_size) == 0
861f93
+	 && read_one_ptr (lm_addr + lmo->l_next_offset,
861f93
+			  &l_next, ptr_size) == 0)
861f93
+    {
861f93
+      unsigned char libname[PATH_MAX];
861f93
 
861f93
-      if (read_one_ptr (priv->r_debug + lmo->r_map_offset,
861f93
-			&lm_addr, ptr_size) != 0)
861f93
+      if (lm_prev != l_prev)
861f93
 	{
861f93
-	  warning ("unable to read r_map from 0x%lx",
861f93
-		   (long) priv->r_debug + lmo->r_map_offset);
861f93
-	  goto done;
861f93
+	  warning ("Corrupted shared library list: 0x%lx != 0x%lx",
861f93
+		   (long) lm_prev, (long) l_prev);
861f93
+	  break;
861f93
 	}
861f93
 
861f93
-      lm_prev = 0;
861f93
-      while (read_one_ptr (lm_addr + lmo->l_name_offset,
861f93
-			   &l_name, ptr_size) == 0
861f93
-	     && read_one_ptr (lm_addr + lmo->l_addr_offset,
861f93
-			      &l_addr, ptr_size) == 0
861f93
-	     && read_one_ptr (lm_addr + lmo->l_ld_offset,
861f93
-			      &l_ld, ptr_size) == 0
861f93
-	     && read_one_ptr (lm_addr + lmo->l_prev_offset,
861f93
-			      &l_prev, ptr_size) == 0
861f93
-	     && read_one_ptr (lm_addr + lmo->l_next_offset,
861f93
-			      &l_next, ptr_size) == 0)
861f93
+      /* Not checking for error because reading may stop before
861f93
+	 we've got PATH_MAX worth of characters.  */
861f93
+      libname[0] = '\0';
861f93
+      linux_read_memory (l_name, libname, sizeof (libname) - 1);
861f93
+      libname[sizeof (libname) - 1] = '\0';
861f93
+      if (libname[0] != '\0')
861f93
 	{
861f93
-	  unsigned char libname[PATH_MAX];
861f93
+	  /* 6x the size for xml_escape_text below.  */
861f93
+	  size_t len = 6 * strlen ((char *) libname);
861f93
+	  char *name;
861f93
 
861f93
-	  if (lm_prev != l_prev)
861f93
+	  if (!header_done)
861f93
 	    {
861f93
-	      warning ("Corrupted shared library list: 0x%lx != 0x%lx",
861f93
-		       (long) lm_prev, (long) l_prev);
861f93
-	      break;
861f93
+	      /* Terminate `
861f93
+	      *p++ = '>';
861f93
+	      header_done = 1;
861f93
 	    }
861f93
 
861f93
-	  /* Not checking for error because reading may stop before
861f93
-	     we've got PATH_MAX worth of characters.  */
861f93
-	  libname[0] = '\0';
861f93
-	  linux_read_memory (l_name, libname, sizeof (libname) - 1);
861f93
-	  libname[sizeof (libname) - 1] = '\0';
861f93
-	  if (libname[0] != '\0')
861f93
+	  while (allocated < p - document + len + 200)
861f93
 	    {
861f93
-	      /* 6x the size for xml_escape_text below.  */
861f93
-	      size_t len = 6 * strlen ((char *) libname);
861f93
-	      char *name;
861f93
-
861f93
-	      if (!header_done)
861f93
-		{
861f93
-		  /* Terminate `
861f93
-		  *p++ = '>';
861f93
-		  header_done = 1;
861f93
-		}
861f93
-
861f93
-	      while (allocated < p - document + len + 200)
861f93
-		{
861f93
-		  /* Expand to guarantee sufficient storage.  */
861f93
-		  uintptr_t document_len = p - document;
861f93
-
861f93
-		  document = xrealloc (document, 2 * allocated);
861f93
-		  allocated *= 2;
861f93
-		  p = document + document_len;
861f93
-		}
861f93
-
861f93
-	      name = xml_escape_text ((char *) libname);
861f93
-	      p += sprintf (p, "
861f93
-			       "l_addr=\"0x%lx\" l_ld=\"0x%lx\"/>",
861f93
-			    name, (unsigned long) lm_addr,
861f93
-			    (unsigned long) l_addr, (unsigned long) l_ld);
861f93
-	      free (name);
861f93
-	    }
861f93
-	  else if (lm_prev == 0)
861f93
-	    {
861f93
-	      sprintf (p, " main-lm=\"0x%lx\"", (unsigned long) lm_addr);
861f93
-	      p = p + strlen (p);
861f93
-	    }
861f93
+	      /* Expand to guarantee sufficient storage.  */
861f93
+	      uintptr_t document_len = p - document;
861f93
 
861f93
-	  if (l_next == 0)
861f93
-	    break;
861f93
+	      document = xrealloc (document, 2 * allocated);
861f93
+	      allocated *= 2;
861f93
+	      p = document + document_len;
861f93
+	    }
861f93
 
861f93
-	  lm_prev = lm_addr;
861f93
-	  lm_addr = l_next;
861f93
+	  name = xml_escape_text ((char *) libname);
861f93
+	  p += sprintf (p, "
861f93
+			"l_addr=\"0x%lx\" l_ld=\"0x%lx\"/>",
861f93
+			name, (unsigned long) lm_addr,
861f93
+			(unsigned long) l_addr, (unsigned long) l_ld);
861f93
+	  free (name);
861f93
 	}
861f93
-    done:
861f93
-      if (!header_done)
861f93
+      else if (lm_prev == 0)
861f93
 	{
861f93
-	  /* Empty list; terminate `
861f93
-	  strcpy (p, "/>");
861f93
+	  sprintf (p, " main-lm=\"0x%lx\"", (unsigned long) lm_addr);
861f93
+	  p = p + strlen (p);
861f93
 	}
861f93
-      else
861f93
-	strcpy (p, "</library-list-svr4>");
861f93
+
861f93
+      lm_prev = lm_addr;
861f93
+      lm_addr = l_next;
861f93
     }
861f93
 
861f93
+  if (!header_done)
861f93
+    {
861f93
+      /* Empty list; terminate `
861f93
+      strcpy (p, "/>");
861f93
+    }
861f93
+  else
861f93
+    strcpy (p, "</library-list-svr4>");
861f93
+
861f93
   document_len = strlen (document);
861f93
   if (offset < document_len)
861f93
     document_len -= offset;
861f93
--- src/gdb/gdbserver/server.c	2013/05/24 11:28:06	1.191
861f93
+++ src/gdb/gdbserver/server.c	2013/06/04 12:59:21	1.192
861f93
@@ -1115,8 +1115,7 @@
861f93
   if (writebuf != NULL)
861f93
     return -2;
861f93
 
861f93
-  if (annex[0] != '\0' || !target_running ()
861f93
-      || the_target->qxfer_libraries_svr4 == NULL)
861f93
+  if (!target_running () || the_target->qxfer_libraries_svr4 == NULL)
861f93
     return -1;
861f93
 
861f93
   return the_target->qxfer_libraries_svr4 (annex, readbuf, writebuf, offset, len);
861f93
@@ -1743,7 +1742,8 @@
861f93
 	       PBUFSIZ - 1);
861f93
 
861f93
       if (the_target->qxfer_libraries_svr4 != NULL)
861f93
-	strcat (own_buf, ";qXfer:libraries-svr4:read+");
861f93
+	strcat (own_buf, ";qXfer:libraries-svr4:read+"
861f93
+		";augmented-libraries-svr4-read+");
861f93
       else
861f93
 	{
861f93
 	  /* We do not have any hook to indicate whether the non-SVR4 target