From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2205) id 88DD73851ABA; Wed, 12 Oct 2022 15:07:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 88DD73851ABA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1665587258; bh=AZ1D2KERUahg8i3ptc5iKT+CMBXwmRLhA8b1qJl/a3U=; h=From:To:Subject:Date:From; b=UjZGXSJLeNcUKj2yEChshGj5VD3EzkUnYScYOM0vCL1pABvSQxA8BxOYf0x5JxIx+ +KOaRgNFtfhzLePyE8uPZ8jQwvMI5u0PkAQjhIoAbZXxEUhcNufnikg6ArA0WYYcyp i+v0KhzjtiUg/PQ58h85Je4PVPS9VX/Ku/Ga0iH4= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom de Vries To: gdb-cvs@sourceware.org Subject: [binutils-gdb] [gdb/symtab] Factor out elf_symfile_read_dwarf2 X-Act-Checkin: binutils-gdb X-Git-Author: Tom de Vries X-Git-Refname: refs/heads/master X-Git-Oldrev: 908a926ec4ecd48571aafb560d97b927b6f94b5e X-Git-Newrev: d955d17917cda6bf9950f1d6e9844d8797476d46 Message-Id: <20221012150738.88DD73851ABA@sourceware.org> Date: Wed, 12 Oct 2022 15:07:38 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Dd955d17917cd= a6bf9950f1d6e9844d8797476d46 commit d955d17917cda6bf9950f1d6e9844d8797476d46 Author: Tom de Vries Date: Wed Oct 12 17:07:35 2022 +0200 [gdb/symtab] Factor out elf_symfile_read_dwarf2 =20 Factor out elf_symfile_read_dwarf2 from elf_symfile_read. NFC. =20 Tested on x86_64-linux. Diff: --- gdb/elfread.c | 142 ++++++++++++++++++++++++++++++++----------------------= ---- 1 file changed, 78 insertions(+), 64 deletions(-) diff --git a/gdb/elfread.c b/gdb/elfread.c index 21d52f93355..88f5a713c4f 100644 --- a/gdb/elfread.c +++ b/gdb/elfread.c @@ -1166,6 +1166,83 @@ elf_read_minimal_symbols (struct objfile *objfile, i= nt symfile_flags, symtab_create_debug_printf ("done reading minimal symbols"); } =20 +/* Dwarf-specific helper for elf_symfile_read. Return true if we managed = to + load dwarf debug info. */ + +static bool +elf_symfile_read_dwarf2 (struct objfile *objfile, + symfile_add_flags symfile_flags) +{ + bool has_dwarf2 =3D true; + + if (dwarf2_has_info (objfile, NULL, true)) + dwarf2_initialize_objfile (objfile); + /* If the file has its own symbol tables it has no separate debug + info. `.dynsym'/`.symtab' go to MSYMBOLS, `.debug_info' goes to + SYMTABS/PSYMTABS. `.gnu_debuglink' may no longer be present with + `.note.gnu.build-id'. + + .gnu_debugdata is !objfile::has_partial_symbols because it contains o= nly + .symtab, not .debug_* section. But if we already added .gnu_debugdat= a as + an objfile via find_separate_debug_file_in_section there was no separ= ate + debug info available. Therefore do not attempt to search for another= one, + objfile->separate_debug_objfile->separate_debug_objfile GDB guarantee= s to + be NULL and we would possibly violate it. */ + + else if (!objfile->has_partial_symbols () + && objfile->separate_debug_objfile =3D=3D NULL + && objfile->separate_debug_objfile_backlink =3D=3D NULL) + { + std::string debugfile =3D find_separate_debug_file_by_buildid (objfi= le); + + if (debugfile.empty ()) + debugfile =3D find_separate_debug_file_by_debuglink (objfile); + + if (!debugfile.empty ()) + { + gdb_bfd_ref_ptr debug_bfd (symfile_bfd_open (debugfile.c_str ())); + + symbol_file_add_separate (debug_bfd, debugfile.c_str (), + symfile_flags, objfile); + } + else + { + has_dwarf2 =3D false; + const struct bfd_build_id *build_id + =3D build_id_bfd_get (objfile->obfd.get ()); + const char *filename =3D bfd_get_filename (objfile->obfd.get ()); + + if (build_id !=3D nullptr) + { + gdb::unique_xmalloc_ptr symfile_path; + scoped_fd fd (debuginfod_debuginfo_query (build_id->data, + build_id->size, + filename, + &symfile_path)); + + if (fd.get () >=3D 0) + { + /* File successfully retrieved from server. */ + gdb_bfd_ref_ptr debug_bfd (symfile_bfd_open (symfile_path.get ())); + + if (debug_bfd =3D=3D nullptr) + warning (_("File \"%s\" from debuginfod cannot be opened as bfd"), + filename); + else if (build_id_verify (debug_bfd.get (), build_id->size, + build_id->data)) + { + symbol_file_add_separate (debug_bfd, symfile_path.get (), + symfile_flags, objfile); + has_dwarf2 =3D true; + } + } + } + } + } + + return has_dwarf2; +} + /* Scan and build partial symbols for a symbol file. We have been initialized by a call to elf_symfile_init, which currently does nothing. @@ -1195,7 +1272,6 @@ elf_symfile_read (struct objfile *objfile, symfile_ad= d_flags symfile_flags) { bfd *abfd =3D objfile->obfd.get (); struct elfinfo ei; - bool has_dwarf2 =3D true; =20 memset ((char *) &ei, 0, sizeof (ei)); if (!(objfile->flags & OBJF_READNEVER)) @@ -1244,69 +1320,7 @@ elf_symfile_read (struct objfile *objfile, symfile_a= dd_flags symfile_flags) bfd_section_size (str_sect)); } =20 - if (dwarf2_has_info (objfile, NULL, true)) - dwarf2_initialize_objfile (objfile); - /* If the file has its own symbol tables it has no separate debug - info. `.dynsym'/`.symtab' go to MSYMBOLS, `.debug_info' goes to - SYMTABS/PSYMTABS. `.gnu_debuglink' may no longer be present with - `.note.gnu.build-id'. - - .gnu_debugdata is !objfile::has_partial_symbols because it contains o= nly - .symtab, not .debug_* section. But if we already added .gnu_debugdat= a as - an objfile via find_separate_debug_file_in_section there was no separ= ate - debug info available. Therefore do not attempt to search for another= one, - objfile->separate_debug_objfile->separate_debug_objfile GDB guarantee= s to - be NULL and we would possibly violate it. */ - - else if (!objfile->has_partial_symbols () - && objfile->separate_debug_objfile =3D=3D NULL - && objfile->separate_debug_objfile_backlink =3D=3D NULL) - { - std::string debugfile =3D find_separate_debug_file_by_buildid (objfi= le); - - if (debugfile.empty ()) - debugfile =3D find_separate_debug_file_by_debuglink (objfile); - - if (!debugfile.empty ()) - { - gdb_bfd_ref_ptr debug_bfd (symfile_bfd_open (debugfile.c_str ())); - - symbol_file_add_separate (debug_bfd, debugfile.c_str (), - symfile_flags, objfile); - } - else - { - has_dwarf2 =3D false; - const struct bfd_build_id *build_id - =3D build_id_bfd_get (objfile->obfd.get ()); - const char *filename =3D bfd_get_filename (objfile->obfd.get ()); - - if (build_id !=3D nullptr) - { - gdb::unique_xmalloc_ptr symfile_path; - scoped_fd fd (debuginfod_debuginfo_query (build_id->data, - build_id->size, - filename, - &symfile_path)); - - if (fd.get () >=3D 0) - { - /* File successfully retrieved from server. */ - gdb_bfd_ref_ptr debug_bfd (symfile_bfd_open (symfile_path.get ())); - - if (debug_bfd =3D=3D nullptr) - warning (_("File \"%s\" from debuginfod cannot be opened as bfd"), - filename); - else if (build_id_verify (debug_bfd.get (), build_id->size, build_id->= data)) - { - symbol_file_add_separate (debug_bfd, symfile_path.get (), - symfile_flags, objfile); - has_dwarf2 =3D true; - } - } - } - } - } + bool has_dwarf2 =3D elf_symfile_read_dwarf2 (objfile, symfile_flags); =20 /* Read the CTF section only if there is no DWARF info. */ if (!has_dwarf2 && ei.ctfsect)