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 04/15] gdbserver: move main_lm handling into caller
Date: Thu,  2 Jun 2022 15:25:03 +0200	[thread overview]
Message-ID: <20220602132514.957983-5-markus.t.metzger@intel.com> (raw)
In-Reply-To: <20220602132514.957983-1-markus.t.metzger@intel.com>

When listing SVR4 shared libraries, special care has to be taken about the
first library in the default namespace as that refers to the main
executable.  The load map address of this main executable is provided in
an attribute of the library-list-svr4 element.

Move that code from where we enumerate libraries inside a single namespace
to where we generate the rest of the library-list-svr4 element.  This
allows us to complete the library-list-svr4 element inside one function.

There should be no functional change.
---
 gdbserver/linux-low.cc | 96 +++++++++++++++++++++---------------------
 1 file changed, 48 insertions(+), 48 deletions(-)

diff --git a/gdbserver/linux-low.cc b/gdbserver/linux-low.cc
index d765139e816..4b4d38b75bc 100644
--- a/gdbserver/linux-low.cc
+++ b/gdbserver/linux-low.cc
@@ -6482,8 +6482,7 @@ static const link_map_offsets lmo_64bit_offsets =
 
 static void
 read_link_map (std::string &document, CORE_ADDR lm_addr, CORE_ADDR lm_prev,
-	       int ptr_size, const link_map_offsets *lmo, bool ignore_first,
-	       int &header_done)
+	       int ptr_size, const link_map_offsets *lmo)
 {
   CORE_ADDR l_name, l_addr, l_ld, l_next, l_prev;
 
@@ -6508,37 +6507,19 @@ read_link_map (std::string &document, CORE_ADDR lm_addr, CORE_ADDR lm_prev,
 	  break;
 	}
 
-      /* 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 (ignore_first && lm_prev == 0)
-	string_appendf (document, " main-lm=\"0x%s\"", paddress (lm_addr));
-      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')
 	{
-	  /* 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')
-	    {
-	      if (!header_done)
-		{
-		  /* Terminate `<library-list-svr4'.  */
-		  document += '>';
-		  header_done = 1;
-		}
-
-	      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\"/>",
-			      paddress (lm_addr), paddress (l_addr),
-			      paddress (l_ld));
-	    }
+	  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\"/>",
+			  paddress (lm_addr), paddress (l_addr),
+			  paddress (l_ld));
 	}
 
       lm_prev = lm_addr;
@@ -6559,7 +6540,6 @@ linux_process_target::qxfer_libraries_svr4 (const char *annex,
   int pid, is_elf64;
   unsigned int machine;
   CORE_ADDR lm_addr = 0, lm_prev = 0;
-  int header_done = 0;
 
   if (writebuf != NULL)
     return -2;
@@ -6616,8 +6596,10 @@ linux_process_target::qxfer_libraries_svr4 (const char *annex,
 
      Otherwise, start with R_DEBUG and traverse all namespaces we find.  */
   if (lm_addr != 0)
-    read_link_map (document, lm_addr, lm_prev, ptr_size, lmo, false,
-		   header_done);
+    {
+      document += ">";
+      read_link_map (document, lm_addr, lm_prev, ptr_size, lmo);
+    }
   else
     {
       if (lm_prev != 0)
@@ -6633,7 +6615,10 @@ linux_process_target::qxfer_libraries_svr4 (const char *annex,
       if (r_debug == (CORE_ADDR) -1)
 	return -1;
 
-      bool ignore_first = true;
+      /* Terminate the header if we end up with an empty list.  */
+      if (r_debug == 0)
+	document += ">";
+
       while (r_debug != 0)
 	{
 	  int r_version = 0;
@@ -6660,15 +6645,36 @@ linux_process_target::qxfer_libraries_svr4 (const char *annex,
 	      break;
 	    }
 
-	  read_link_map (document, lm_addr, 0, ptr_size, lmo,
-			 ignore_first, header_done);
+	  /* We read the entire namespace.  */
+	  lm_prev = 0;
+
+	  /* The first entry corresponds to the main executable unless the
+	     dynamic loader was loaded late by a static executable.  But
+	     in such case the main executable does not have PT_DYNAMIC
+	     present and we would not have gotten here.  */
+	  if (r_debug == priv->r_debug)
+	    {
+	      if (lm_addr != 0)
+		string_appendf (document, " main-lm=\"0x%s\">",
+				paddress (lm_addr));
+	      else
+		document += ">";
+
+	      lm_prev = lm_addr;
+	      if (read_one_ptr (lm_addr + lmo->l_next_offset,
+				&lm_addr, ptr_size) != 0)
+		{
+		  warning ("unable to read l_next from 0x%s",
+			   paddress (lm_addr + lmo->l_next_offset));
+		  break;
+		}
+	    }
+
+	  read_link_map (document, lm_addr, lm_prev, ptr_size, lmo);
 
 	  if (r_version < 2)
 	    break;
 
-	  /* Only applies to the default namespace.  */
-	  ignore_first = false;
-
 	  if (read_one_ptr (r_debug + lmo->r_next_offset, &r_debug,
 			    ptr_size) != 0)
 	    {
@@ -6679,13 +6685,7 @@ linux_process_target::qxfer_libraries_svr4 (const char *annex,
 	}
     }
 
-  if (!header_done)
-    {
-      /* Empty list; terminate `<library-list-svr4'.  */
-      document += "/>";
-    }
-  else
-    document += "</library-list-svr4>";
+  document += "</library-list-svr4>";
 
   int document_len = document.length ();
   if (offset < document_len)
-- 
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 ` Markus Metzger [this message]
2022-06-19  4:22   ` [PATCH v5 04/15] gdbserver: move main_lm handling into caller Kevin Buettner
2022-06-02 13:25 ` [PATCH v5 05/15] gdb, gdbserver: extend RSP to support namespaces Markus Metzger
2022-06-02 16:09   ` 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-5-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).