public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Markus Metzger <markus.t.metzger@intel.com>
To: gdb-patches@sourceware.org
Subject: [PATCH v5 05/15] gdb, gdbserver: extend RSP to support namespaces
Date: Thu,  2 Jun 2022 15:25:04 +0200	[thread overview]
Message-ID: <20220602132514.957983-6-markus.t.metzger@intel.com> (raw)
In-Reply-To: <20220602132514.957983-1-markus.t.metzger@intel.com>

Introduce a new qXfer:libraries-svr4:read annex key/value pair

    lmid=<namespace identifier>

to be used together with start and prev to provide the namespace of start
and prev to gdbserver.

Unknown key/value pairs are ignored by gdbserver so no new supports check
is needed.

Introduce a new library-list-svr4 library attribute

    lmid

to provide the namespace of a library entry to GDB.

This implementation uses the address of a namespace's r_debug object as
namespace identifier.

This should have incremented the minor version but since unknown XML
attributes are ignored, anyway, and since changing the version results in
a warning from GDB, the version is left at 1.0.
---
 gdb/doc/gdb.texinfo                | 16 +++++++++++--
 gdb/features/library-list-svr4.dtd |  4 ++++
 gdb/solib-svr4.c                   | 38 +++++++++++++++++++++++++++---
 gdbserver/linux-low.cc             | 26 +++++++++++++-------
 4 files changed, 70 insertions(+), 14 deletions(-)

diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 5f09f3a1433..e2f430feb7e 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -43334,6 +43334,12 @@ specified by the @samp{start} argument.  If unset or zero then
 the remote stub will expect that no @samp{struct link_map}
 exists prior to the starting point.
 
+@item lmid=@var{lmid}
+A hexadecimal number specifying a namespace identifier.  This is
+currently only used together with @samp{start} to provide the
+namespace identifier back to @value{GDBN} in the response.
+@value{GDBN} will only provide values that were previously reported to
+it.  If unset, the response will include @samp{lmid="0x0"}.
 @end table
 
 Arguments that are not understood by the remote stub will be silently
@@ -45872,6 +45878,11 @@ memory address.  It is a displacement of absolute memory address against
 address the file was prelinked to during the library load.
 @item
 @code{l_ld}, which is memory address of the @code{PT_DYNAMIC} segment
+@item
+@code{lmid}, which is an identifier for a linker namespace, such as
+the memory address of the @code{r_debug} object that contains this
+namespace's load map or the namespace identifier returned by
+@code{dlinfo (3)}.
 @end itemize
 
 Additionally the single @code{main-lm} attribute specifies address of
@@ -45887,9 +45898,9 @@ looks like this:
 @smallexample
 <library-list-svr4 version="1.0" main-lm="0xe4f8f8">
   <library name="/lib/ld-linux.so.2" lm="0xe4f51c" l_addr="0xe2d000"
-           l_ld="0xe4eefc"/>
+           l_ld="0xe4eefc" lmid="0xfffe0"/>
   <library name="/lib/libc.so.6" lm="0xe4fbe8" l_addr="0x154000"
-           l_ld="0x152350"/>
+           l_ld="0x152350" lmid="0xfffe0"/>
 </library-list-svr>
 @end smallexample
 
@@ -45905,6 +45916,7 @@ The format of an SVR4 library list is described by this DTD:
 <!ATTLIST library            lm      CDATA   #REQUIRED>
 <!ATTLIST library            l_addr  CDATA   #REQUIRED>
 <!ATTLIST library            l_ld    CDATA   #REQUIRED>
+<!ATTLIST library            lmid    CDATA   #IMPLIED>
 @end smallexample
 
 @node Memory Map Format
diff --git a/gdb/features/library-list-svr4.dtd b/gdb/features/library-list-svr4.dtd
index 7d62354c34c..e869ff1349e 100644
--- a/gdb/features/library-list-svr4.dtd
+++ b/gdb/features/library-list-svr4.dtd
@@ -14,3 +14,7 @@
 <!ATTLIST library            lm      CDATA   #REQUIRED>
 <!ATTLIST library            l_addr  CDATA   #REQUIRED>
 <!ATTLIST library            l_ld    CDATA   #REQUIRED>
+<!-- added lmid attribute to what should have become version 1.1 but
+     since this generates a warning in GDB and since unknown attributes
+     are ignored, anyway, leaving the version at 1.0. -->
+<!ATTLIST library            lmid    CDATA   #IMPLIED>
diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
index 1f2abcf16ef..ca396acf24f 100644
--- a/gdb/solib-svr4.c
+++ b/gdb/solib-svr4.c
@@ -1068,8 +1068,37 @@ library_list_start_library (struct gdb_xml_parser *parser,
   new_elem->so_name[sizeof (new_elem->so_name) - 1] = 0;
   strcpy (new_elem->so_original_name, new_elem->so_name);
 
-  *list->tailp = new_elem;
-  list->tailp = &new_elem->next;
+  /* Older versions did not supply lmid.  Put the element into the flat
+     list of the special namespace zero in that case.  */
+  gdb_xml_value *at_lmid = xml_find_attribute (attributes, "lmid");
+  if (at_lmid == nullptr)
+    {
+      *list->tailp = new_elem;
+      list->tailp = &new_elem->next;
+    }
+  else
+    {
+      ULONGEST lmid = *(ULONGEST *) at_lmid->value.get ();
+
+      /* Ensure that the element is actually initialized.  */
+      if (list->solib_lists.find (lmid) == list->solib_lists.end ())
+	list->solib_lists[lmid] = nullptr;
+
+      so_list **psolist = &list->solib_lists[lmid];
+      so_list **pnext = psolist;
+
+      /* Walk to the end of the list if we have one.  */
+      so_list *solist = *psolist;
+      if (solist != nullptr)
+	{
+	  for (; solist->next != nullptr; solist = solist->next)
+	    /* Nothing.  */;
+
+	  pnext = &solist->next;
+	}
+
+      *pnext = new_elem;
+    }
 }
 
 /* Handle the start of a <library-list-svr4> element.  */
@@ -1109,6 +1138,7 @@ static const struct gdb_xml_attribute svr4_library_attributes[] =
   { "lm", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL },
   { "l_addr", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL },
   { "l_ld", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL },
+  { "lmid", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL },
   { NULL, GDB_XML_AF_NONE, NULL, NULL }
 };
 
@@ -1866,7 +1896,9 @@ solist_update_incremental (svr4_info *info, CORE_ADDR debug_base,
       struct svr4_library_list library_list;
       char annex[64];
 
-      xsnprintf (annex, sizeof (annex), "start=%s;prev=%s",
+      /* Unknown key=value pairs are ignored by the gdbstub.  */
+      xsnprintf (annex, sizeof (annex), "lmid=%s;start=%s;prev=%s",
+		 phex_nz (debug_base, sizeof (debug_base)),
 		 phex_nz (lm, sizeof (lm)),
 		 phex_nz (prev_lm, sizeof (prev_lm)));
       if (!svr4_current_sos_via_xfer_libraries (&library_list, annex))
diff --git a/gdbserver/linux-low.cc b/gdbserver/linux-low.cc
index 4b4d38b75bc..f54551f2eca 100644
--- a/gdbserver/linux-low.cc
+++ b/gdbserver/linux-low.cc
@@ -6481,8 +6481,8 @@ static const link_map_offsets lmo_64bit_offsets =
 /* Get the loaded shared libraries from one namespace.  */
 
 static void
-read_link_map (std::string &document, CORE_ADDR lm_addr, CORE_ADDR lm_prev,
-	       int ptr_size, const link_map_offsets *lmo)
+read_link_map (std::string &document, CORE_ADDR lmid, CORE_ADDR lm_addr,
+	       CORE_ADDR lm_prev, int ptr_size, const link_map_offsets *lmo)
 {
   CORE_ADDR l_name, l_addr, l_ld, l_next, l_prev;
 
@@ -6517,9 +6517,9 @@ read_link_map (std::string &document, CORE_ADDR lm_addr, CORE_ADDR lm_prev,
 	  string_appendf (document, "<library name=\"");
 	  xml_escape_text_append (&document, (char *) libname);
 	  string_appendf (document, "\" lm=\"0x%s\" l_addr=\"0x%s\" "
-			  "l_ld=\"0x%s\"/>",
+			  "l_ld=\"0x%s\" lmid=\"0x%s\"/>",
 			  paddress (lm_addr), paddress (l_addr),
-			  paddress (l_ld));
+			  paddress (l_ld), paddress (lmid));
 	}
 
       lm_prev = lm_addr;
@@ -6539,7 +6539,7 @@ linux_process_target::qxfer_libraries_svr4 (const char *annex,
   char filename[PATH_MAX];
   int pid, is_elf64;
   unsigned int machine;
-  CORE_ADDR lm_addr = 0, lm_prev = 0;
+  CORE_ADDR lmid = 0, lm_addr = 0, lm_prev = 0;
 
   if (writebuf != NULL)
     return -2;
@@ -6573,7 +6573,9 @@ linux_process_target::qxfer_libraries_svr4 (const char *annex,
 	break;
 
       name_len = sep - annex;
-      if (name_len == 5 && startswith (annex, "start"))
+      if (name_len == 4 && startswith (annex, "lmid"))
+	addrp = &lmid;
+      else if (name_len == 5 && startswith (annex, "start"))
 	addrp = &lm_addr;
       else if (name_len == 4 && startswith (annex, "prev"))
 	addrp = &lm_prev;
@@ -6592,19 +6594,25 @@ linux_process_target::qxfer_libraries_svr4 (const char *annex,
   std::string document = "<library-list-svr4 version=\"1.0\"";
 
   /* When the starting LM_ADDR is passed in the annex, only traverse that
-     namespace.
+     namespace, which is assumed to be identified by LMID.
 
      Otherwise, start with R_DEBUG and traverse all namespaces we find.  */
   if (lm_addr != 0)
     {
       document += ">";
-      read_link_map (document, lm_addr, lm_prev, ptr_size, lmo);
+      read_link_map (document, lmid, lm_addr, lm_prev, ptr_size, lmo);
     }
   else
     {
       if (lm_prev != 0)
 	warning ("ignoring prev=0x%s without start", paddress (lm_prev));
 
+      /* We could interpret LMID as 'provide only the libraries for this
+	 namespace' but GDB is currently only providing lmid, start, and
+	 prev, or nothing.  */
+      if (lmid != 0)
+	warning ("ignoring lmid=0x%s without start", paddress (lmid));
+
       CORE_ADDR r_debug = priv->r_debug;
       if (r_debug == 0)
 	r_debug = priv->r_debug = get_r_debug (pid, is_elf64);
@@ -6670,7 +6678,7 @@ linux_process_target::qxfer_libraries_svr4 (const char *annex,
 		}
 	    }
 
-	  read_link_map (document, lm_addr, lm_prev, ptr_size, lmo);
+	  read_link_map (document, r_debug, lm_addr, lm_prev, ptr_size, lmo);
 
 	  if (r_version < 2)
 	    break;
-- 
2.35.3

Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva  
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928


  parent reply	other threads:[~2022-06-02 14:29 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-02 13:24 [PATCH v5 00/15] basic linker namespace support Markus Metzger
2022-06-02 13:25 ` [PATCH v5 01/15] gdb, testsuite: extend gdb_test_multiple checks Markus Metzger
2022-06-13  1:28   ` Kevin Buettner
2022-06-02 13:25 ` [PATCH v5 02/15] gdb, solib-svr4: remove locate_base() Markus Metzger
2022-06-02 23:04   ` Kevin Buettner
2022-06-02 13:25 ` [PATCH v5 03/15] gdb, gdbserver: support dlmopen() Markus Metzger
2022-06-19  4:02   ` Kevin Buettner
2022-06-27 12:55     ` Metzger, Markus T
2022-06-30 22:35       ` Kevin Buettner
2022-06-02 13:25 ` [PATCH v5 04/15] gdbserver: move main_lm handling into caller Markus Metzger
2022-06-19  4:22   ` Kevin Buettner
2022-06-02 13:25 ` Markus Metzger [this message]
2022-06-02 16:09   ` [PATCH v5 05/15] gdb, gdbserver: extend RSP to support namespaces Eli Zaretskii
2022-06-19  4:32   ` Kevin Buettner
2022-06-02 13:25 ` [PATCH v5 06/15] gdb, compile: unlink objfile stored in module Markus Metzger
2022-06-23 17:20   ` Kevin Buettner
2022-06-02 13:25 ` [PATCH v5 07/15] gdb, python: use gdbarch_iterate_over_objfiles_in_search_order Markus Metzger
2022-06-24 17:18   ` Kevin Buettner
2022-06-02 13:25 ` [PATCH v5 08/15] gdb, ada: collect standard exceptions in all objfiles Markus Metzger
2022-06-24 17:26   ` Kevin Buettner
2022-07-18 16:49     ` Tom Tromey
2022-07-18  5:35   ` Metzger, Markus T
2022-09-14  8:19     ` Metzger, Markus T
2022-09-14  8:37       ` Joel Brobecker
2022-09-14  8:45         ` Metzger, Markus T
2022-06-02 13:25 ` [PATCH v5 09/15] gdb, ada: update ada_lookup_simple_minsym Markus Metzger
2022-06-24 23:42   ` Kevin Buettner
2022-07-18 17:02   ` Tom Tromey
2022-07-19  7:14     ` Metzger, Markus T
2022-09-14  8:19       ` Metzger, Markus T
2022-09-21 16:11         ` Tom Tromey
2022-06-02 13:25 ` [PATCH v5 10/15] gdb, ada: update ada_add_all_symbols Markus Metzger
2022-06-24 23:53   ` Kevin Buettner
2022-07-18  5:36   ` Metzger, Markus T
2022-07-18 16:56   ` Tom Tromey
2022-07-19  7:13     ` Metzger, Markus T
2022-07-19 12:23       ` Tom Tromey
2022-07-19 13:49         ` Metzger, Markus T
2022-06-02 13:25 ` [PATCH v5 11/15] gdb, cp: update add_symbol_overload_list_qualified Markus Metzger
2022-06-24 23:59   ` Kevin Buettner
2022-06-02 13:25 ` [PATCH v5 12/15] gdb, hppa: remove unused hppa_lookup_stub_minimal_symbol Markus Metzger
2022-06-25  0:01   ` Kevin Buettner
2022-06-02 13:25 ` [PATCH v5 13/15] gdb, symtab: inline find_quick_global_symbol_language Markus Metzger
2022-06-25  0:16   ` Kevin Buettner
2022-06-02 13:25 ` [PATCH v5 14/15] gdb: update gnu ifunc resolve Markus Metzger
2022-06-25  0:34   ` Kevin Buettner
2022-06-02 13:25 ` [PATCH v5 15/15] gdb, solib-svr4: support namespaces in DSO iteration Markus Metzger
2022-06-25  0:42   ` Kevin Buettner
2022-07-15 10:30 ` [PATCH v5 00/15] basic linker namespace support Metzger, Markus T
2022-07-16  0:04   ` Kevin Buettner
2022-07-18  5:33     ` Metzger, Markus T
2022-10-05 11:16       ` Metzger, Markus T

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220602132514.957983-6-markus.t.metzger@intel.com \
    --to=markus.t.metzger@intel.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).