From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id aEoJIS7RgmGyTwAAWB0awg (envelope-from ) for ; Wed, 03 Nov 2021 14:13:02 -0400 Received: by simark.ca (Postfix, from userid 112) id 03F271F0C1; Wed, 3 Nov 2021 14:13:01 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id B00CD1E940 for ; Wed, 3 Nov 2021 14:13:00 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 534183858C3A for ; Wed, 3 Nov 2021 18:13:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 534183858C3A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1635963180; bh=s5gbR1FpYdK6Iyai/11Jk1TdGXPFOyIRhwrlUeV8uxc=; h=References:In-Reply-To:Date:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=vkN1WlyIKaJXbMrF23NmooDNlZmd39VtLn6uYmUuaI1Asxp1w4Clm7hRURTJVCMBA LACXEMJ0tSAwakXgQjee/3qT0KNcJSz/gnv7OMdJ9n0zcw8Z4+s3TZlxmXaCDp9wHD 03EPe89ANlFJJ1gjYCBAjFEmVRoeAeU+zSssRwJE= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 082653858D28 for ; Wed, 3 Nov 2021 18:12:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 082653858D28 Received: from mail-ua1-f69.google.com (mail-ua1-f69.google.com [209.85.222.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-162-3pWIkV4nMjOauvdMm8AEbw-1; Wed, 03 Nov 2021 14:12:33 -0400 X-MC-Unique: 3pWIkV4nMjOauvdMm8AEbw-1 Received: by mail-ua1-f69.google.com with SMTP id 63-20020a9f2345000000b002cbbc79fb71so1612363uae.0 for ; Wed, 03 Nov 2021 11:12:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=s5gbR1FpYdK6Iyai/11Jk1TdGXPFOyIRhwrlUeV8uxc=; b=tabsckp0BzYvAIFm/2wFNLZbolKDfKCCrgwIvttyrBxj9T362ThAl0vERBUjKUNhsy C8c59tUJAovNsXUuxSp9ufXaF4H1KXjxxSqr2niv4VnSWfjBOZFclrHMPzbxlG9Fq9kF cGAICllbdRm5hXWHbdH66cUJsQn/Y6XRlU+EW7Hq9tIRWIX0hj3Dv4F3LOyQmAiqd7Dy QXZYQ23oJ6Ds/+r/fXQuCdWtsOsR6nWWF4+RYHqD9VsGXtW3VGLLEtZNBQTjSlTlIj4a qA7v74djLcyWwueKQXtUiNmMBKuaaSlVW62xw07fqIWZHLoV/sSslJpNJZyKfx7ZT5fZ 1ESQ== X-Gm-Message-State: AOAM5324SMD8diSHSscTnjQFWHZYhh0e42IdgSnRnpUlzwqLqSiuQphm 9WNzcdFIlyyH8i4q0BqKYmKL3N8phspWgS0RRvrrRiym09Cufg5Gm2uk0+zxImSTkoLRZ8fOd7F cnZHumM/y+KthMIyQn8gcHZORS56poPVtfkiW X-Received: by 2002:a1f:3095:: with SMTP id w143mr11258634vkw.6.1635963152341; Wed, 03 Nov 2021 11:12:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzcrSYwx8XC2pf1G5WzJG6I8B0U8EwJ8OShlWnKiyEOAOwwoLwxwEGsYG6iNNGvRUwEn52twAvohnzqRKb4ozc= X-Received: by 2002:a1f:3095:: with SMTP id w143mr11258583vkw.6.1635963151885; Wed, 03 Nov 2021 11:12:31 -0700 (PDT) MIME-Version: 1.0 References: <6d314528-224a-3e5e-2d4b-070ea776823d@polymtl.ca> <20210819022227.62623-1-amerey@redhat.com> In-Reply-To: Date: Wed, 3 Nov 2021 14:12:21 -0400 Message-ID: Subject: [PING**3][PATCH 2/3] gdb: Add soname to build-id mapping for corefiles To: gdb-patches@sourceware.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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: , From: Aaron Merey via Gdb-patches Reply-To: Aaron Merey Cc: lsix@lancelotsix.com Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" Ping. Thanks, Aaron On Mon, Oct 18, 2021 at 7:06 PM Aaron Merey wrote: > > Ping > > Thanks, > Aaron > > On Tue, Sep 28, 2021 at 9:12 PM Aaron Merey wrote: > > > > Ping. > > > > Thanks, > > Aaron > > > > On Wed, Aug 18, 2021 at 10:22 PM Aaron Merey via Gdb-patches > > wrote: > > > > > > Hi Lancelot and Simon, > > > > > > Thanks for the reviews. The updated patch is included below. > > > > > > On Tue, Aug 17, 2021 at 9:59 AM Simon Marchi wrote: > > > >>> + /* Check that bfd is an ET_DYN ELF file. */ > > > >>> + bfd_check_format (abfd.get (), bfd_object); > > > > > > > > I asked this in my previous review, still applies here: > > > > > > > > What's the point of calling bfd_check_format without checking the > > > > result? It looks like a function without side-effects. > > > > > > I included a few comments in the [PATCH 0/3] email for this series[1]= . > > > I mentioned that for some reason bfd_check_format appears to update > > > the bfd 'flags' field with the correct value. If bfd_check_format is = not > > > called here the check for the DYNAMIC flag fails even for ET_DYN file= s. > > > > > > [1] https://sourceware.org/pipermail/gdb-patches/2021-August/181416.h= tml > > > > > > --- > > > gdb/arch-utils.c | 15 +++++---------- > > > gdb/arch-utils.h | 23 +++++++++++++---------- > > > gdb/build-id.h | 2 ++ > > > gdb/corelow.c | 13 ++++++++++++- > > > gdb/gdbarch.c | 2 +- > > > gdb/gdbarch.h | 4 ++-- > > > gdb/gdbarch.sh | 2 +- > > > gdb/linux-tdep.c | 46 ++++++++++++++++++++++++++++++++++------------ > > > gdb/progspace.c | 32 ++++++++++++++++++++++++++++++++ > > > gdb/progspace.h | 17 +++++++++++++++++ > > > gdb/solib.c | 35 +++++++++++++++++++++++++++++++++++ > > > gdb/solib.h | 5 +++++ > > > 12 files changed, 159 insertions(+), 37 deletions(-) > > > > > > diff --git a/gdb/arch-utils.c b/gdb/arch-utils.c > > > index 862f26b6cf7..ffb32cb203f 100644 > > > --- a/gdb/arch-utils.c > > > +++ b/gdb/arch-utils.c > > > @@ -1075,16 +1075,11 @@ default_get_pc_address_flags (frame_info *fra= me, CORE_ADDR pc) > > > > > > /* See arch-utils.h. */ > > > void > > > -default_read_core_file_mappings (struct gdbarch *gdbarch, > > > - struct bfd *cbfd, > > > - gdb::function_view > > > - pre_loop_cb, > > > - gdb::function_view > > - ULONGEST st= art, > > > - ULONGEST en= d, > > > - ULONGEST fi= le_ofs, > > > - const char = *filename)> > > > - loop_cb) > > > +default_read_core_file_mappings > > > + (struct gdbarch *gdbarch, > > > + struct bfd *cbfd, > > > + gdb::function_view pre_loop_cb, > > > + loop_cb_ftype loop_cb) > > > { > > > } > > > > > > diff --git a/gdb/arch-utils.h b/gdb/arch-utils.h > > > index 03e9082f6d7..2243c3fb85b 100644 > > > --- a/gdb/arch-utils.h > > > +++ b/gdb/arch-utils.h > > > @@ -294,15 +294,18 @@ extern ULONGEST default_type_align (struct gdba= rch *gdbarch, > > > extern std::string default_get_pc_address_flags (frame_info *frame, > > > CORE_ADDR pc); > > > > > > + > > > +using loop_cb_ftype =3D gdb::function_view > > + ULONGEST start, > > > + ULONGEST end, > > > + ULONGEST file_ofs, > > > + const char *filename, > > > + const bfd_build_id *bu= ild_id)>; > > > + > > > /* Default implementation of gdbarch read_core_file_mappings method.= */ > > > -extern void default_read_core_file_mappings (struct gdbarch *gdbarch= , > > > - struct bfd *cbfd, > > > - gdb::function_view > > > - pre_loop_cb, > > > - gdb::function_view > > - = ULONGEST start, > > > - = ULONGEST end, > > > - = ULONGEST file_ofs, > > > - = const char *filename)> > > > - loop_cb); > > > +extern void default_read_core_file_mappings > > > + (struct gdbarch *gdbarch, > > > + struct bfd *cbfd, > > > + gdb::function_view pre_loop_cb, > > > + loop_cb_ftype loop_cb); > > > #endif /* ARCH_UTILS_H */ > > > diff --git a/gdb/build-id.h b/gdb/build-id.h > > > index 42f8d57ede1..3c9402ee71b 100644 > > > --- a/gdb/build-id.h > > > +++ b/gdb/build-id.h > > > @@ -20,8 +20,10 @@ > > > #ifndef BUILD_ID_H > > > #define BUILD_ID_H > > > > > > +#include "defs.h" > > > #include "gdb_bfd.h" > > > #include "gdbsupport/rsp-low.h" > > > +#include > > > > > > /* Locate NT_GNU_BUILD_ID from ABFD and return its content. */ > > > > > > diff --git a/gdb/corelow.c b/gdb/corelow.c > > > index eb785a08633..31af0f22584 100644 > > > --- a/gdb/corelow.c > > > +++ b/gdb/corelow.c > > > @@ -214,7 +214,7 @@ core_target::build_file_mappings () > > > /* read_core_file_mappings will invoke this lambda for each mapp= ing > > > that it finds. */ > > > [&] (int num, ULONGEST start, ULONGEST end, ULONGEST file_ofs, > > > - const char *filename) > > > + const char *filename, const bfd_build_id *build_id) > > > { > > > /* Architecture-specific read_core_mapping methods are expect= ed to > > > weed out non-file-backed mappings. */ > > > @@ -282,6 +282,16 @@ core_target::build_file_mappings () > > > > > > /* Set target_section fields. */ > > > m_core_file_mappings.emplace_back (start, end, sec); > > > + > > > + /* If this is a bfd of a shared library, record its soname > > > + and build id. */ > > > + if (build_id !=3D nullptr) > > > + { > > > + gdb::optional soname =3D gdb_bfd_read_elf_so= name (bfd); > > > + if (soname) > > > + current_program_space->set_cbfd_soname_build_id > > > + (std::move (*soname), build_id); > > > + } > > > }); > > > > > > normalize_mem_ranges (&m_core_unavailable_mappings); > > > @@ -305,6 +315,7 @@ core_target::close () > > > comments in clear_solib in solib.c. */ > > > clear_solib (); > > > > > > + current_program_space->clear_cbfd_soname_build_ids (); > > > current_program_space->cbfd.reset (nullptr); > > > } > > > > > > diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c > > > index f89dcc57754..35464115039 100644 > > > --- a/gdb/gdbarch.c > > > +++ b/gdb/gdbarch.c > > > @@ -5411,7 +5411,7 @@ set_gdbarch_get_pc_address_flags (struct gdbarc= h *gdbarch, > > > } > > > > > > void > > > -gdbarch_read_core_file_mappings (struct gdbarch *gdbarch, struct bfd= *cbfd, gdb::function_view pre_loop_cb, gdb::functio= n_view loop_cb) > > > +gdbarch_read_core_file_mappings (struct gdbarch *gdbarch, struct bfd= *cbfd, gdb::function_view pre_loop_cb, gdb::functio= n_view loop_cb) > > > { > > > gdb_assert (gdbarch !=3D NULL); > > > gdb_assert (gdbarch->read_core_file_mappings !=3D NULL); > > > diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h > > > index 979159ba2f5..baf80580d60 100644 > > > --- a/gdb/gdbarch.h > > > +++ b/gdb/gdbarch.h > > > @@ -1710,8 +1710,8 @@ extern void set_gdbarch_get_pc_address_flags (s= truct gdbarch *gdbarch, gdbarch_g > > > > > > /* Read core file mappings */ > > > > > > -typedef void (gdbarch_read_core_file_mappings_ftype) (struct gdbarch= *gdbarch, struct bfd *cbfd, gdb::function_view pre_= loop_cb, gdb::function_view loop_cb); > > > -extern void gdbarch_read_core_file_mappings (struct gdbarch *gdbarch= , struct bfd *cbfd, gdb::function_view pre_loop_cb, = gdb::function_view loop_cb); > > > +typedef void (gdbarch_read_core_file_mappings_ftype) (struct gdbarch= *gdbarch, struct bfd *cbfd, gdb::function_view pre_= loop_cb, gdb::function_view loop_= cb); > > > +extern void gdbarch_read_core_file_mappings (struct gdbarch *gdbarch= , struct bfd *cbfd, gdb::function_view pre_loop_cb, = gdb::function_view loop_cb); > > > extern void set_gdbarch_read_core_file_mappings (struct gdbarch *gdb= arch, gdbarch_read_core_file_mappings_ftype *read_core_file_mappings); > > > > > > extern struct gdbarch_tdep *gdbarch_tdep (struct gdbarch *gdbarch); > > > diff --git a/gdb/gdbarch.sh b/gdb/gdbarch.sh > > > index 39a99d0d5f3..c24079d34f3 100755 > > > --- a/gdb/gdbarch.sh > > > +++ b/gdb/gdbarch.sh > > > @@ -1210,7 +1210,7 @@ m;ULONGEST;type_align;struct type *type;type;;d= efault_type_align;;0 > > > f;std::string;get_pc_address_flags;frame_info *frame, CORE_ADDR pc;f= rame, pc;;default_get_pc_address_flags;;0 > > > > > > # Read core file mappings > > > -m;void;read_core_file_mappings;struct bfd *cbfd, gdb::function_view<= void (ULONGEST count)> pre_loop_cb, gdb::function_view loop_cb;= cbfd, pre_loop_cb, loop_cb;;default_read_core_file_mappings;;0 > > > +m;void;read_core_file_mappings;struct bfd *cbfd, gdb::function_view<= void (ULONGEST count)> pre_loop_cb, gdb::function_view loop_cb;cbfd, pre_loop_cb, loop_cb;;default_read_core= _file_mappings;;0 > > > > > > EOF > > > } > > > diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c > > > index ae2f7c14f6d..812ca1f99bf 100644 > > > --- a/gdb/linux-tdep.c > > > +++ b/gdb/linux-tdep.c > > > @@ -44,6 +44,7 @@ > > > #include "solib-svr4.h" > > > > > > #include > > > +#include > > > > > > /* This enum represents the values that the user can choose when > > > informing the Linux kernel about which memory mappings will be > > > @@ -1097,16 +1098,11 @@ linux_info_proc (struct gdbarch *gdbarch, con= st char *args, > > > for each mapping. */ > > > > > > static void > > > -linux_read_core_file_mappings (struct gdbarch *gdbarch, > > > - struct bfd *cbfd, > > > - gdb::function_view > > > - pre_loop_cb, > > > - gdb::function_view > > - ULONGEST star= t, > > > - ULONGEST end, > > > - ULONGEST file= _ofs, > > > - const char *f= ilename)> > > > - loop_cb) > > > +linux_read_core_file_mappings > > > + (struct gdbarch *gdbarch, > > > + struct bfd *cbfd, > > > + gdb::function_view pre_loop_cb, > > > + loop_cb_ftype loop_cb) > > > { > > > /* Ensure that ULONGEST is big enough for reading 64-bit core file= s. */ > > > gdb_static_assert (sizeof (ULONGEST) >=3D 8); > > > @@ -1175,6 +1171,23 @@ linux_read_core_file_mappings (struct gdbarch = *gdbarch, > > > if (f !=3D descend) > > > warning (_("malformed note - filename area is too big")); > > > > > > + const bfd_build_id *orig_build_id =3D cbfd->build_id; > > > + std::unordered_map vma_map; > > > + std::unordered_map filename_map; > > > + > > > + /* Search for solib build-ids in the core file. Each time one is = found, > > > + map the start vma of the corresponding elf header to the build-= id. */ > > > + for (bfd_section *sec =3D cbfd->sections; sec !=3D nullptr; sec = =3D sec->next) > > > + { > > > + cbfd->build_id =3D nullptr; > > > + > > > + if (sec->flags & SEC_LOAD > > > + && get_elf_backend_data (cbfd)->elf_backend_core_find_build= _id > > > + (cbfd, (bfd_vma) sec->filepos)) > > > + vma_map[sec->vma] =3D cbfd->build_id; > > > + } > > > + > > > + cbfd->build_id =3D orig_build_id; > > > pre_loop_cb (count); > > > > > > for (int i =3D 0; i < count; i++) > > > @@ -1188,8 +1201,17 @@ linux_read_core_file_mappings (struct gdbarch = *gdbarch, > > > descdata +=3D addr_size; > > > char * filename =3D filenames; > > > filenames +=3D strlen ((char *) filenames) + 1; > > > + const bfd_build_id *build_id =3D vma_map[start]; > > > + > > > + /* Map filename to the build-id associated with this start vma= , > > > + if such a build-id was found. Otherwise use the build-id > > > + already associated with this filename if it exists. */ > > > + if (build_id !=3D nullptr) > > > + filename_map[filename] =3D build_id; > > > + else > > > + build_id =3D filename_map[filename]; > > > > > > - loop_cb (i, start, end, file_ofs, filename); > > > + loop_cb (i, start, end, file_ofs, filename, build_id); > > > } > > > } > > > > > > @@ -1218,7 +1240,7 @@ linux_core_info_proc_mappings (struct gdbarch *= gdbarch, const char *args) > > > } > > > }, > > > [=3D] (int num, ULONGEST start, ULONGEST end, ULONGEST file_ofs, > > > - const char *filename) > > > + const char *filename, const bfd_build_id *build_id) > > > { > > > if (gdbarch_addr_bit (gdbarch) =3D=3D 32) > > > printf_filtered ("\t%10s %10s %10s %10s %s\n", > > > diff --git a/gdb/progspace.c b/gdb/progspace.c > > > index 7080bf8ee27..8b7b949d959 100644 > > > --- a/gdb/progspace.c > > > +++ b/gdb/progspace.c > > > @@ -17,6 +17,7 @@ > > > You should have received a copy of the GNU General Public License > > > along with this program. If not, see . */ > > > > > > +#include "build-id.h" > > > #include "defs.h" > > > #include "gdbcmd.h" > > > #include "objfiles.h" > > > @@ -358,6 +359,37 @@ print_program_space (struct ui_out *uiout, int r= equested) > > > } > > > } > > > > > > +/* See progspace.h. */ > > > + > > > +void > > > +program_space::set_cbfd_soname_build_id (std::string soname, > > > + const bfd_build_id *build_id= ) > > > +{ > > > + cbfd_soname_to_build_id[std::move (soname)] =3D build_id_to_string= (build_id); > > > +} > > > + > > > +/* See progspace.h. */ > > > + > > > +const char * > > > +program_space::get_cbfd_soname_build_id (const char *soname) > > > +{ > > > + gdb_assert (soname); > > > + > > > + auto it =3D cbfd_soname_to_build_id.find (basename (soname)); > > > + if (it =3D=3D cbfd_soname_to_build_id.end ()) > > > + return nullptr; > > > + > > > + return it->second.c_str (); > > > +} > > > + > > > +/* See progspace.h. */ > > > + > > > +void > > > +program_space::clear_cbfd_soname_build_ids () > > > +{ > > > + cbfd_soname_to_build_id.clear (); > > > +} > > > + > > > /* Boolean test for an already-known program space id. */ > > > > > > static int > > > diff --git a/gdb/progspace.h b/gdb/progspace.h > > > index fb348ca7539..b42b3ffc4f1 100644 > > > --- a/gdb/progspace.h > > > +++ b/gdb/progspace.h > > > @@ -30,6 +30,7 @@ > > > #include "gdbsupport/safe-iterator.h" > > > #include > > > #include > > > +#include > > > > > > struct target_ops; > > > struct bfd; > > > @@ -324,6 +325,19 @@ struct program_space > > > /* Binary file diddling handle for the core file. */ > > > gdb_bfd_ref_ptr cbfd; > > > > > > + /* Associate a core file SONAME with BUILD_ID so that it can be re= trieved > > > + with get_cbfd_soname_build_id. */ > > > + void set_cbfd_soname_build_id (std::string soname, > > > + const bfd_build_id *build_id); > > > + > > > + /* If a core file SONAME had a build-id associated with it by a pr= evious > > > + call to set_cbfd_soname_build_id then return the build-id as a > > > + NULL-terminated hex string. */ > > > + const char *get_cbfd_soname_build_id (const char *soname); > > > + > > > + /* Clear all core file soname to build-id mappings. */ > > > + void clear_cbfd_soname_build_ids (); > > > + > > > /* The address space attached to this program space. More than on= e > > > program space may be bound to the same address space. In the > > > traditional unix-like debugging scenario, this will usually > > > @@ -378,6 +392,9 @@ struct program_space > > > /* The set of target sections matching the sections mapped into > > > this program space. Managed by both exec_ops and solib.c. */ > > > target_section_table m_target_sections; > > > + > > > + /* Mapping of a core file's library sonames to their respective bu= ild-ids. */ > > > + std::unordered_map cbfd_soname_to_build_= id; > > > }; > > > > > > /* An address space. It is used for comparing if > > > diff --git a/gdb/solib.c b/gdb/solib.c > > > index e30affbb7e7..1b99c8ab985 100644 > > > --- a/gdb/solib.c > > > +++ b/gdb/solib.c > > > @@ -23,6 +23,7 @@ > > > #include > > > #include "symtab.h" > > > #include "bfd.h" > > > +#include "build-id.h" > > > #include "symfile.h" > > > #include "objfiles.h" > > > #include "gdbcore.h" > > > @@ -1585,6 +1586,40 @@ gdb_bfd_scan_elf_dyntag (const int desired_dyn= tag, bfd *abfd, CORE_ADDR *ptr, > > > return 0; > > > } > > > > > > +/* See solib.h. */ > > > + > > > +gdb::optional > > > +gdb_bfd_read_elf_soname (struct bfd *bfd) > > > +{ > > > + gdb_assert (bfd !=3D nullptr); > > > + > > > + gdb_bfd_ref_ptr abfd =3D gdb_bfd_open (bfd->filename, gnutarget); > > > + > > > + if (abfd =3D=3D nullptr) > > > + return {}; > > > + > > > + /* Check that bfd is an ET_DYN ELF file. */ > > > + bfd_check_format (abfd.get (), bfd_object); > > > + if (!(bfd_get_file_flags (abfd.get ()) & DYNAMIC)) > > > + return {}; > > > + > > > + /* Determine soname of shared library. If found map soname to bui= ld-id. */ > > > + CORE_ADDR idx; > > > + if (!gdb_bfd_scan_elf_dyntag (DT_SONAME, abfd.get (), &idx, nullpt= r)) > > > + return {}; > > > + > > > + struct bfd_section *dynstr =3D bfd_get_section_by_name (abfd.get (= ), ".dynstr"); > > > + if (dynstr =3D=3D nullptr || bfd_section_size (dynstr) <=3D idx) > > > + return {}; > > > + > > > + /* Read the soname from the string table. */ > > > + gdb::byte_vector dynstr_buf; > > > + if (!gdb_bfd_get_full_section_contents (abfd.get (), dynstr, &dyns= tr_buf)) > > > + return {}; > > > + > > > + return std::string ((const char *)dynstr_buf.data () + idx); > > > +} > > > + > > > /* Lookup the value for a specific symbol from symbol table. Look u= p symbol > > > from ABFD. MATCH_SYM is a callback function to determine whether= to pick > > > up a symbol. DATA is the input of this callback function. Retur= n NULL > > > diff --git a/gdb/solib.h b/gdb/solib.h > > > index c50f74e06bf..51cc047463f 100644 > > > --- a/gdb/solib.h > > > +++ b/gdb/solib.h > > > @@ -118,6 +118,11 @@ extern CORE_ADDR gdb_bfd_lookup_symbol_from_symt= ab (bfd *abfd, > > > extern int gdb_bfd_scan_elf_dyntag (const int desired_dyntag, bfd *a= bfd, > > > CORE_ADDR *ptr, CORE_ADDR *ptr_ad= dr); > > > > > > +/* If BFD is an ELF shared object then attempt to return the string > > > + referred to by its DT_SONAME tag. */ > > > + > > > +extern gdb::optional gdb_bfd_read_elf_soname (struct bf= d *bfd); > > > + > > > /* Enable or disable optional solib event breakpoints as appropriate= . */ > > > > > > extern void update_solib_breakpoints (void); > > > -- > > > 2.31.1 > > >