From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by sourceware.org (Postfix) with ESMTPS id 347C3396DC2D for ; Thu, 2 Jun 2022 14:29:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 347C3396DC2D X-IronPort-AV: E=McAfee;i="6400,9594,10365"; a="336622120" X-IronPort-AV: E=Sophos;i="5.91,271,1647327600"; d="scan'208";a="336622120" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jun 2022 07:28:57 -0700 X-IronPort-AV: E=Sophos;i="5.91,271,1647327600"; d="scan'208";a="606866417" Received: from labpc2407.iul.intel.com (HELO localhost) ([172.28.50.61]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jun 2022 07:28:56 -0700 From: Markus Metzger 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 Message-Id: <20220602132514.957983-5-markus.t.metzger@intel.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220602132514.957983-1-markus.t.metzger@intel.com> References: <20220602132514.957983-1-markus.t.metzger@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-9.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 02 Jun 2022 14:29:15 -0000 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 `", - paddress (lm_addr), paddress (l_addr), - paddress (l_ld)); - } + string_appendf (document, "", + 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 ` 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