From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id KdtzB765X2AhbwAAWB0awg (envelope-from ) for ; Sat, 27 Mar 2021 19:03:26 -0400 Received: by simark.ca (Postfix, from userid 112) id 0F5071EF7C; Sat, 27 Mar 2021 19:03:26 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=0.4 required=5.0 tests=DKIM_SIGNED,MAILING_LIST_MULTI, RCVD_IN_BL_SPAMCOP_NET,T_DKIM_INVALID,URIBL_BLOCKED autolearn=no 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 83D6A1E939 for ; Sat, 27 Mar 2021 19:03:25 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 134D8385801D; Sat, 27 Mar 2021 23:03:25 +0000 (GMT) Received: from gateway24.websitewelcome.com (gateway24.websitewelcome.com [192.185.50.71]) by sourceware.org (Postfix) with ESMTPS id 51BFB385801D for ; Sat, 27 Mar 2021 23:03:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 51BFB385801D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=tom@tromey.com Received: from cm12.websitewelcome.com (cm12.websitewelcome.com [100.42.49.8]) by gateway24.websitewelcome.com (Postfix) with ESMTP id E4E3198B9 for ; Sat, 27 Mar 2021 18:03:20 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id QHxgljtgt1cHeQHxglAUW5; Sat, 27 Mar 2021 18:03:20 -0500 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date:Subject: Cc:To:From:Sender:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=WUusPtI3yV5RjPzq9hmm3xy3EOPUlRtR9mlK9lZwL7g=; b=a5J5bvfc857efgh54ZuRKDrpZx dP3fZ2wLMX/hWoz3jZIh/TmM1x+7rDBeUxSP+Rotg5GGVEXYtgUKTqeP2KeVnaC/pJPcaBqVTPzb8 YKRqR7LhT9Q1L2DTl1JrTtL95; Received: from 71-211-130-165.hlrn.qwest.net ([71.211.130.165]:51102 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1lQHxg-002v4e-Ls; Sat, 27 Mar 2021 17:03:20 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Subject: [PATCH] Simplify DWARF reader initialization Date: Sat, 27 Mar 2021 17:03:18 -0600 Message-Id: <20210327230318.582968-1-tom@tromey.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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: 71.211.130.165 X-Source-L: No X-Exim-ID: 1lQHxg-002v4e-Ls X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 71-211-130-165.hlrn.qwest.net (localhost.localdomain) [71.211.130.165]:51102 X-Source-Auth: tom+tromey.com X-Email-Count: 1 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes 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: , Cc: Tom Tromey Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" Now that the quick functions are separate from the object file format, there's no need to have elfread.c push a new entry on the objfile 'qf' list. Instead, this detail can be pushed into the DWARF reader. That is what this patch implements. I wasn't sure whether lazy reading still makes sense or not. It's still only used by ELF, and only in certain situations (like vfork, I think). It may not be carrying its weight, so we may want to consider removing this in the future. Also, I'm unclear on why the various indices are only used for ELF. This seems sub-optimal. However, I haven't tried to address that here. gdb/ChangeLog 2021-03-27 Tom Tromey * elfread.c (can_lazily_read_symbols): Move to dwarf2/read.c. (elf_symfile_read): Simplify. * dwarf2/read.c (struct lazy_dwarf_reader): Move from elfread.c. (make_lazy_dwarf_reader): New function. (make_dwarf_gdb_index, make_dwarf_debug_names): Now static. (dwarf2_initialize_objfile): Return void. Remove index_kind parameter. Push on 'qf' list. * dwarf2/public.h (dwarf2_initialize_objfile): Change return type. Remove 'index_kind' parameter. (make_dwarf_gdb_index, make_dwarf_debug_names): Don't declare. --- gdb/ChangeLog | 13 ++++++++ gdb/dwarf2/public.h | 11 ++----- gdb/dwarf2/read.c | 73 ++++++++++++++++++++++++++++++--------------- gdb/elfread.c | 37 +---------------------- 4 files changed, 66 insertions(+), 68 deletions(-) diff --git a/gdb/dwarf2/public.h b/gdb/dwarf2/public.h index e6653f4f38d..33bb5d48217 100644 --- a/gdb/dwarf2/public.h +++ b/gdb/dwarf2/public.h @@ -34,18 +34,13 @@ enum class dw_index_kind DEBUG_NAMES, }; -/* Initialize for reading DWARF for OBJFILE. Return false if this - file will use psymtabs, or true if using an index, in which case - *INDEX_KIND is set to the index variant in use. */ -extern bool dwarf2_initialize_objfile (struct objfile *objfile, - dw_index_kind *index_kind); +/* 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); struct psymbol_functions; extern void dwarf2_build_psymtabs (struct objfile *, psymbol_functions *psf = nullptr); extern void dwarf2_build_frame_info (struct objfile *); -extern quick_symbol_functions_up make_dwarf_gdb_index (); -extern quick_symbol_functions_up make_dwarf_debug_names (); - #endif /* DWARF2_PUBLIC_H */ diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index b324541ee9f..1b98b758c35 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -2191,6 +2191,30 @@ struct dwarf2_per_cu_quick_data unsigned int no_file_data : 1; }; +/* A subclass of psymbol_functions that arranges to read the DWARF + partial symbols when needed. */ +struct lazy_dwarf_reader : public psymbol_functions +{ + using psymbol_functions::psymbol_functions; + + bool can_lazily_read_symbols () override + { + return true; + } + + void read_partial_symbols (struct objfile *objfile) override + { + if (dwarf2_has_info (objfile, nullptr)) + dwarf2_build_psymtabs (objfile, this); + } +}; + +static quick_symbol_functions_up +make_lazy_dwarf_reader () +{ + return quick_symbol_functions_up (new lazy_dwarf_reader); +} + struct dwarf2_base_index_functions : public quick_symbol_functions { bool has_symbols (struct objfile *objfile) override; @@ -2292,13 +2316,13 @@ struct dwarf2_debug_names_index : public dwarf2_base_index_functions enum search_domain kind) override; }; -quick_symbol_functions_up +static quick_symbol_functions_up make_dwarf_gdb_index () { return quick_symbol_functions_up (new dwarf2_gdb_index); } -quick_symbol_functions_up +static quick_symbol_functions_up make_dwarf_debug_names () { return quick_symbol_functions_up (new dwarf2_debug_names_index); @@ -5993,10 +6017,10 @@ get_gdb_index_contents_from_cache_dwz (objfile *obj, dwz_file *dwz) return global_index_cache.lookup_gdb_index (build_id, &dwz->index_cache_res); } -/* See symfile.h. */ +/* See dwarf2/public.h. */ -bool -dwarf2_initialize_objfile (struct objfile *objfile, dw_index_kind *index_kind) +void +dwarf2_initialize_objfile (struct objfile *objfile) { dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile); dwarf2_per_bfd *per_bfd = per_objfile->per_bfd; @@ -6016,9 +6040,9 @@ dwarf2_initialize_objfile (struct objfile *objfile, dw_index_kind *index_kind) if (per_bfd->using_index) { dwarf_read_debug_printf ("using_index already set"); - *index_kind = dw_index_kind::GDB_INDEX; per_objfile->resize_symtabs (); - return true; + objfile->qf.push_front (make_dwarf_gdb_index ()); + return; } per_bfd->using_index = 1; @@ -6037,11 +6061,11 @@ dwarf2_initialize_objfile (struct objfile *objfile, dw_index_kind *index_kind) struct dwarf2_per_cu_quick_data); } - /* Return 1 so that gdb sees the "quick" functions. However, - these functions will be no-ops because we will have expanded - all symtabs. */ - *index_kind = dw_index_kind::GDB_INDEX; - return true; + /* Arrange for gdb to see the "quick" functions. However, these + functions will be no-ops because we will have expanded all + symtabs. */ + objfile->qf.push_front (make_dwarf_gdb_index ()); + return; } /* Was a debug names index already read when we processed an objfile sharing @@ -6049,9 +6073,9 @@ dwarf2_initialize_objfile (struct objfile *objfile, dw_index_kind *index_kind) if (per_bfd->debug_names_table != nullptr) { dwarf_read_debug_printf ("re-using shared debug names table"); - *index_kind = dw_index_kind::DEBUG_NAMES; per_objfile->resize_symtabs (); - return true; + objfile->qf.push_front (make_dwarf_debug_names ()); + return; } /* Was a GDB index already read when we processed an objfile sharing @@ -6059,9 +6083,9 @@ dwarf2_initialize_objfile (struct objfile *objfile, dw_index_kind *index_kind) if (per_bfd->index_table != nullptr) { dwarf_read_debug_printf ("re-using shared index table"); - *index_kind = dw_index_kind::GDB_INDEX; per_objfile->resize_symtabs (); - return true; + objfile->qf.push_front (make_dwarf_gdb_index ()); + return; } /* There might already be partial symtabs built for this BFD. This happens @@ -6072,15 +6096,16 @@ dwarf2_initialize_objfile (struct objfile *objfile, dw_index_kind *index_kind) if (per_bfd->partial_symtabs != nullptr) { dwarf_read_debug_printf ("re-using shared partial symtabs"); - return false; + objfile->qf.push_front (make_lazy_dwarf_reader ()); + return; } if (dwarf2_read_debug_names (per_objfile)) { dwarf_read_debug_printf ("found debug names"); - *index_kind = dw_index_kind::DEBUG_NAMES; per_objfile->resize_symtabs (); - return true; + objfile->qf.push_front (make_dwarf_debug_names ()); + return; } if (dwarf2_read_gdb_index (per_objfile, @@ -6088,9 +6113,9 @@ dwarf2_initialize_objfile (struct objfile *objfile, dw_index_kind *index_kind) get_gdb_index_contents_from_section)) { dwarf_read_debug_printf ("found gdb index from file"); - *index_kind = dw_index_kind::GDB_INDEX; per_objfile->resize_symtabs (); - return true; + objfile->qf.push_front (make_dwarf_gdb_index ()); + return; } /* ... otherwise, try to find the index in the index cache. */ @@ -6100,13 +6125,13 @@ dwarf2_initialize_objfile (struct objfile *objfile, dw_index_kind *index_kind) { dwarf_read_debug_printf ("found gdb index from cache"); global_index_cache.hit (); - *index_kind = dw_index_kind::GDB_INDEX; per_objfile->resize_symtabs (); - return true; + objfile->qf.push_front (make_dwarf_gdb_index ()); + return; } global_index_cache.miss (); - return false; + objfile->qf.push_front (make_lazy_dwarf_reader ()); } diff --git a/gdb/elfread.c b/gdb/elfread.c index f5de913a5cc..1dea226242d 100644 --- a/gdb/elfread.c +++ b/gdb/elfread.c @@ -53,24 +53,6 @@ #include "debuginfod-support.h" #include "dwarf2/public.h" -/* A subclass of psymbol_functions that arranges to read the DWARF - partial symbols when needed. */ -struct lazy_dwarf_reader : public psymbol_functions -{ - using psymbol_functions::psymbol_functions; - - bool can_lazily_read_symbols () override - { - return true; - } - - void read_partial_symbols (struct objfile *objfile) override - { - if (dwarf2_has_info (objfile, nullptr)) - dwarf2_build_psymtabs (objfile, this); - } -}; - /* The struct elfinfo is available only during ELF symbol table and psymtab reading. It is destroyed at the completion of psymtab-reading. It's local to elf_symfile_read. */ @@ -1273,24 +1255,7 @@ elf_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags) } if (dwarf2_has_info (objfile, NULL, true)) - { - dw_index_kind index_kind; - - if (dwarf2_initialize_objfile (objfile, &index_kind)) - { - switch (index_kind) - { - case dw_index_kind::GDB_INDEX: - objfile->qf.push_front (make_dwarf_gdb_index ()); - break; - case dw_index_kind::DEBUG_NAMES: - objfile->qf.push_front (make_dwarf_debug_names ()); - break; - } - } - else - objfile->qf.emplace_front (new lazy_dwarf_reader); - } + 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 -- 2.26.2