From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1805) id 075C43857C4C; Tue, 18 Oct 2022 13:24:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 075C43857C4C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1666099498; bh=o0jBLP1Ts5SvtFjXYCw2Ei/8Hzg/zvmSD6qcMnR9hc8=; h=From:To:Subject:Date:From; b=tQGvtc+GarcDbHUPRAFg20YRnrsGPYLmliJgXQkr4i9xrsGzhDm9IpvQcA3nQcXMe gTCBErCwV04ZGR7nGQw7n9CjR3vnQzNomymd8DYt+yIKouDB5FOISH95HAe+Ufnkzf Vtm9jKjUZ7uYSURo8RIWTiadjDi7BSmcT3Cfy03A= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Markus Metzger To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdbserver: move main_lm handling into caller X-Act-Checkin: binutils-gdb X-Git-Author: Markus Metzger X-Git-Refname: refs/heads/master X-Git-Oldrev: 8d56636a0ecbe6c38bf52b0683326ee21693c548 X-Git-Newrev: ad10f44e568806c2399f9405f4588f3e27f7d9ae Message-Id: <20221018132458.075C43857C4C@sourceware.org> Date: Tue, 18 Oct 2022 13:24:58 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Dad10f44e5688= 06c2399f9405f4588f3e27f7d9ae commit ad10f44e568806c2399f9405f4588f3e27f7d9ae Author: Markus Metzger Date: Tue Mar 15 17:41:13 2022 +0100 gdbserver: move main_lm handling into caller =20 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. =20 Move that code from where we enumerate libraries inside a single namesp= ace 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. =20 There should be no functional change. Diff: --- 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 af3c4b35cd9..e83ccceed83 100644 --- a/gdbserver/linux-low.cc +++ b/gdbserver/linux-low.cc @@ -6490,8 +6490,7 @@ static const link_map_offsets lmo_64bit_offsets =3D =20 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; =20 @@ -6516,37 +6515,19 @@ read_link_map (std::string &document, CORE_ADDR lm_= addr, CORE_ADDR lm_prev, break; } =20 - /* Ignore the first entry even if it has valid name as the first ent= ry - 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 =3D=3D 0) - string_appendf (document, " main-lm=3D\"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] =3D '\0'; + linux_read_memory (l_name, libname, sizeof (libname) - 1); + libname[sizeof (libname) - 1] =3D '\0'; + if (libname[0] !=3D '\0') { - /* Not checking for error because reading may stop before - we've got PATH_MAX worth of characters. */ - libname[0] =3D '\0'; - linux_read_memory (l_name, libname, sizeof (libname) - 1); - libname[sizeof (libname) - 1] =3D '\0'; - if (libname[0] !=3D '\0') - { - if (!header_done) - { - /* Terminate `'; - header_done =3D 1; - } - - string_appendf (document, "", - paddress (lm_addr), paddress (l_addr), - paddress (l_ld)); - } + string_appendf (document, "", + paddress (lm_addr), paddress (l_addr), + paddress (l_ld)); } =20 lm_prev =3D lm_addr; @@ -6567,7 +6548,6 @@ linux_process_target::qxfer_libraries_svr4 (const cha= r *annex, int pid, is_elf64; unsigned int machine; CORE_ADDR lm_addr =3D 0, lm_prev =3D 0; - int header_done =3D 0; =20 if (writebuf !=3D NULL) return -2; @@ -6624,8 +6604,10 @@ linux_process_target::qxfer_libraries_svr4 (const ch= ar *annex, =20 Otherwise, start with R_DEBUG and traverse all namespaces we find. */ if (lm_addr !=3D 0) - read_link_map (document, lm_addr, lm_prev, ptr_size, lmo, false, - header_done); + { + document +=3D ">"; + read_link_map (document, lm_addr, lm_prev, ptr_size, lmo); + } else { if (lm_prev !=3D 0) @@ -6641,7 +6623,10 @@ linux_process_target::qxfer_libraries_svr4 (const ch= ar *annex, if (r_debug =3D=3D (CORE_ADDR) -1) return -1; =20 - bool ignore_first =3D true; + /* Terminate the header if we end up with an empty list. */ + if (r_debug =3D=3D 0) + document +=3D ">"; + while (r_debug !=3D 0) { int r_version =3D 0; @@ -6668,15 +6653,36 @@ linux_process_target::qxfer_libraries_svr4 (const c= har *annex, break; } =20 - read_link_map (document, lm_addr, 0, ptr_size, lmo, - ignore_first, header_done); + /* We read the entire namespace. */ + lm_prev =3D 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 =3D=3D priv->r_debug) + { + if (lm_addr !=3D 0) + string_appendf (document, " main-lm=3D\"0x%s\">", + paddress (lm_addr)); + else + document +=3D ">"; + + lm_prev =3D lm_addr; + if (read_one_ptr (lm_addr + lmo->l_next_offset, + &lm_addr, ptr_size) !=3D 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); =20 if (r_version < 2) break; =20 - /* Only applies to the default namespace. */ - ignore_first =3D false; - if (read_one_ptr (r_debug + lmo->r_next_offset, &r_debug, ptr_size) !=3D 0) { @@ -6687,13 +6693,7 @@ linux_process_target::qxfer_libraries_svr4 (const ch= ar *annex, } } =20 - if (!header_done) - { - /* Empty list; terminate `"; - } - else - document +=3D ""; + document +=3D ""; =20 int document_len =3D document.length (); if (offset < document_len)