From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from omta034.useast.a.cloudfilter.net (omta034.useast.a.cloudfilter.net [44.202.169.33]) by sourceware.org (Postfix) with ESMTPS id ABA3038582B2 for ; Sun, 10 Dec 2023 21:41:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ABA3038582B2 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org ABA3038582B2 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=44.202.169.33 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702244487; cv=none; b=Ey8GreyJT8FYPfA0gZiZD2SGryLw29VbYn9ks45kg71eOy4hI1fgh4fRjbTe/l373QBQVsCaGJeMba22S+adUXLq09dtDleAhL3UdQ+Hx5ozRUGVUnWX5bsYWLVlcper3vdAJNCuxUXonHXpy8j4m+7+030guxZR/m/tclS5nNc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702244487; c=relaxed/simple; bh=uuAROXwtU+9YH8vbYVGMEbwSazloAiQJHQkqBDjbF8U=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=m6kd8qGHLZC4qH9dRRoJPA4TtEk4XQh3zdWDFtM0/OjxnKG4Bb+uYB7NBpbQrqqy8ul9v460FRbKXVufYbiaRo48RWYC1VX27i3z7g5GK9mm9PeridI4kqd3fHeZRWQ8WzaBC+GhNi7FUxzOoa84V24vxE3qf5N1peOFRt328fw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from eig-obgw-6010a.ext.cloudfilter.net ([10.0.30.248]) by cmsmtp with ESMTPS id BzkTr4d93jtZ3CRYIrOuTR; Sun, 10 Dec 2023 21:41:30 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id CRY9rlVh58vT0CRYArz0oJ; Sun, 10 Dec 2023 21:41:22 +0000 X-Authority-Analysis: v=2.4 cv=ffi+dmcF c=1 sm=1 tr=0 ts=65763082 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=OWjo9vPv0XrRhIrVQ50Ab3nP57M=:19 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=IkcTkHD0fZMA:10 a=e2cXIFwxEfEA:10 a=Qbun_eYptAEA:10 a=DZavHcuwyplPiQb90MwA:9 a=QEXdDO2ut3YA:10 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=To:In-Reply-To:References:Message-Id:Content-Transfer-Encoding: Content-Type:MIME-Version:Subject:Date:From:Sender:Reply-To:Cc:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=G/W/4YI3WHHPS1H9gQss2QysWL547OJJquCwVwCmlJo=; b=Ed9/4Nfs1sznqIZgLLasO2Uwec owLavWzLQGW7RrnEayGxs44aIjpy+fqhgpBqoq0LsmcQrxQVqQjEn7tRN7K8kBukDerm76DTlDDbs x6goxigRzadu2JZs+q2CmxC6J; Received: from [198.59.47.65] (port=52450 helo=[192.168.131.83]) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96.2) (envelope-from ) id 1rCRY9-000SHj-1h for gdb-patches@sourceware.org; Sun, 10 Dec 2023 14:41:21 -0700 From: Tom Tromey Date: Sun, 10 Dec 2023 14:41:21 -0700 Subject: [PATCH v4 13/19] Simplify the public DWARF API MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20231210-t-bg-dwarf-reading-v4-13-b978c32fd12f@tromey.com> References: <20231210-t-bg-dwarf-reading-v4-0-b978c32fd12f@tromey.com> In-Reply-To: <20231210-t-bg-dwarf-reading-v4-0-b978c32fd12f@tromey.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.4 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 198.59.47.65 X-Source-L: No X-Exim-ID: 1rCRY9-000SHj-1h X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: ([192.168.131.83]) [198.59.47.65]:52450 X-Source-Auth: tom+tromey.com X-Email-Count: 16 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfG/ZRcXf+FNM94fttHeAQuwBxl8Ccqye1UQMV2q4/7KtuGxc7RGUgmuMiykoyEXbhe63lrwo6xYwkV5qeF0nqoef3KtLZOQoH/fsyvaUoVesiZmSmdvd z1FbPX1IQ0+vXt6VhLxm6SfUOH/BcALnbDbEdKpJLMKsMtqcm6gr3IZblAia9WrOhsVr41+qPLPXmpz2ymISJLLtlDPYsLJXTbQ= X-Spam-Status: No, score=-3024.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,GIT_PATCH_0,JMQ_SPF_NEUTRAL,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,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 List-Id: dwarf2_has_info and dwarf2_initialize_objfile are only separate because the DWARF reader implemented lazy psymtab reading. However, now that this is gone, we can simplify the public DWARF API again. --- gdb/coffread.c | 6 +++--- gdb/dwarf2/public.h | 18 +++++++++++------- gdb/dwarf2/read.c | 49 ++++++++++++++++++++++--------------------------- gdb/elfread.c | 6 ++++-- gdb/machoread.c | 11 ++--------- gdb/xcoffread.c | 3 +-- 6 files changed, 43 insertions(+), 50 deletions(-) diff --git a/gdb/coffread.c b/gdb/coffread.c index 37363631915..3a64325a822 100644 --- a/gdb/coffread.c +++ b/gdb/coffread.c @@ -716,10 +716,10 @@ coff_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags) *info->stabsects, info->stabstrsect->filepos, stabstrsize); } - if (dwarf2_has_info (objfile, NULL)) + + if (dwarf2_initialize_objfile (objfile)) { - /* DWARF2 sections. */ - dwarf2_initialize_objfile (objfile); + /* Nothing. */ } /* Try to add separate debug file if no symbols table found. */ diff --git a/gdb/dwarf2/public.h b/gdb/dwarf2/public.h index 0e74857eb1a..efb754b5fe8 100644 --- a/gdb/dwarf2/public.h +++ b/gdb/dwarf2/public.h @@ -20,10 +20,6 @@ #ifndef DWARF2_PUBLIC_H #define DWARF2_PUBLIC_H -extern bool dwarf2_has_info (struct objfile *, - const struct dwarf2_debug_sections *, - bool = false); - /* A DWARF names index variant. */ enum class dw_index_kind { @@ -34,9 +30,17 @@ enum class dw_index_kind DEBUG_NAMES, }; -/* Initialize for reading DWARF for OBJFILE, and push the appropriate - entry on the objfile's "qf" list. */ -extern void dwarf2_initialize_objfile (struct objfile *objfile); +/* Try to locate the sections we need for DWARF 2 debugging + information. If these are found, begin reading the DWARF and + return true. Otherwise, return false. NAMES points to the dwarf2 + section names, or is NULL if the standard ELF names are used. + CAN_COPY is true for formats where symbol interposition is possible + and so symbol values must follow copy relocation rules. */ + +extern bool dwarf2_initialize_objfile + (struct objfile *, + const struct dwarf2_debug_sections * = nullptr, + bool = false); extern void dwarf2_build_frame_info (struct objfile *); diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 8a60cf91612..8778bffc485 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -1354,14 +1354,10 @@ dwarf2_per_objfile::set_symtab (const dwarf2_per_cu_data *per_cu, this->m_symtabs[per_cu->index] = symtab; } -/* Try to locate the sections we need for DWARF 2 debugging - information and return true if we have enough to do something. - NAMES points to the dwarf2 section names, or is NULL if the standard - ELF names are used. CAN_COPY is true for formats where symbol - interposition is possible and so symbol values must follow copy - relocation rules. */ +/* Helper function for dwarf2_initialize_objfile that creates the + per-BFD object. */ -bool +static bool dwarf2_has_info (struct objfile *objfile, const struct dwarf2_debug_sections *names, bool can_copy) @@ -3199,9 +3195,14 @@ static quick_symbol_functions_up make_cooked_index_funcs /* See dwarf2/public.h. */ -void -dwarf2_initialize_objfile (struct objfile *objfile) +bool +dwarf2_initialize_objfile (struct objfile *objfile, + const struct dwarf2_debug_sections *names, + bool can_copy) { + if (!dwarf2_has_info (objfile, names, can_copy)) + return false; + dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile); dwarf2_per_bfd *per_bfd = per_objfile->per_bfd; @@ -3231,48 +3232,42 @@ dwarf2_initialize_objfile (struct objfile *objfile) = create_quick_file_names_table (per_bfd->all_units.size ()); objfile->qf.emplace_front (new readnow_functions); - return; } - /* Was a GDB index already read when we processed an objfile sharing PER_BFD? */ - if (per_bfd->index_table != nullptr) + else if (per_bfd->index_table != nullptr) { dwarf_read_debug_printf ("re-using symbols"); objfile->qf.push_front (per_bfd->index_table->make_quick_functions ()); - return; } - - if (dwarf2_read_debug_names (per_objfile)) + else if (dwarf2_read_debug_names (per_objfile)) { dwarf_read_debug_printf ("found debug names"); objfile->qf.push_front (per_bfd->index_table->make_quick_functions ()); - return; } - - if (dwarf2_read_gdb_index (per_objfile, - get_gdb_index_contents_from_section, - get_gdb_index_contents_from_section)) + else if (dwarf2_read_gdb_index (per_objfile, + get_gdb_index_contents_from_section, + get_gdb_index_contents_from_section)) { dwarf_read_debug_printf ("found gdb index from file"); objfile->qf.push_front (per_bfd->index_table->make_quick_functions ()); - return; } - /* ... otherwise, try to find the index in the index cache. */ - if (dwarf2_read_gdb_index (per_objfile, + else if (dwarf2_read_gdb_index (per_objfile, get_gdb_index_contents_from_cache, get_gdb_index_contents_from_cache_dwz)) { dwarf_read_debug_printf ("found gdb index from cache"); global_index_cache.hit (); objfile->qf.push_front (per_bfd->index_table->make_quick_functions ()); - return; } - - global_index_cache.miss (); - objfile->qf.push_front (make_cooked_index_funcs (per_objfile)); + else + { + global_index_cache.miss (); + objfile->qf.push_front (make_cooked_index_funcs (per_objfile)); + } + return true; } diff --git a/gdb/elfread.c b/gdb/elfread.c index 5dc8f21d7c7..c5ba8837217 100644 --- a/gdb/elfread.c +++ b/gdb/elfread.c @@ -1198,8 +1198,10 @@ elf_symfile_read_dwarf2 (struct objfile *objfile, { bool has_dwarf2 = true; - if (dwarf2_has_info (objfile, NULL, true)) - dwarf2_initialize_objfile (objfile); + if (dwarf2_initialize_objfile (objfile, nullptr, true)) + { + /* Nothing. */ + } /* 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 diff --git a/gdb/machoread.c b/gdb/machoread.c index 87d30ec8587..f27ce63c24c 100644 --- a/gdb/machoread.c +++ b/gdb/machoread.c @@ -785,6 +785,8 @@ macho_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags) macho_symfile_read_all_oso at the end of this function. */ gdb::def_vector symbol_table; + dwarf2_initialize_objfile (objfile); + /* Get symbols from the symbol table only if the file is an executable. The symbol table of object files is not relocated and is expected to be in the executable. */ @@ -822,9 +824,6 @@ macho_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags) } /* Try to read .eh_frame / .debug_frame. */ - /* First, locate these sections. We ignore the result status - as it only checks for debug info. */ - dwarf2_has_info (objfile, NULL); dwarf2_build_frame_info (objfile); /* Check for DSYM file. */ @@ -854,12 +853,6 @@ macho_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags) } } - if (dwarf2_has_info (objfile, NULL)) - { - /* DWARF 2 sections */ - dwarf2_initialize_objfile (objfile); - } - /* Then the oso. */ if (!oso_vector.empty ()) macho_symfile_read_all_oso (&oso_vector, objfile, symfile_flags); diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c index 856fa134ed7..13ee3105baf 100644 --- a/gdb/xcoffread.c +++ b/gdb/xcoffread.c @@ -2871,8 +2871,7 @@ xcoff_initial_scan (struct objfile *objfile, symfile_add_flags symfile_flags) /* DWARF2 sections. */ - if (dwarf2_has_info (objfile, &dwarf2_xcoff_names)) - dwarf2_initialize_objfile (objfile); + dwarf2_initialize_objfile (objfile, &dwarf2_xcoff_names); } static void -- 2.43.0