From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id OLlNOX1/pWH6UAAAWB0awg (envelope-from ) for ; Mon, 29 Nov 2021 20:33:49 -0500 Received: by simark.ca (Postfix, from userid 112) id E86951F0CE; Mon, 29 Nov 2021 20:33:49 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=ham 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 0116A1ECEB for ; Mon, 29 Nov 2021 20:33:49 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A28C0385C405 for ; Tue, 30 Nov 2021 01:33:48 +0000 (GMT) Received: from gateway36.websitewelcome.com (gateway36.websitewelcome.com [192.185.194.2]) by sourceware.org (Postfix) with ESMTPS id 8069B3857C64 for ; Tue, 30 Nov 2021 01:33:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8069B3857C64 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=tromey.com Received: from cm12.websitewelcome.com (cm12.websitewelcome.com [100.42.49.8]) by gateway36.websitewelcome.com (Postfix) with ESMTP id 5FD07400FF843 for ; Mon, 29 Nov 2021 19:33:07 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id rs15m8nPVzD3Vrs15m41MO; Mon, 29 Nov 2021 19:33:07 -0600 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:References:In-Reply-To: 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:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=4v27/VJo9Gj5BW5zcuDtL/dZDYkOqMXHocpE5kGaedc=; b=e5nIxj6RNq8fxvrVk57Tqtf1d2 8keJJsmpQDym+FtY5Vr5hNkcLNvp0hIcJ6rWyYkZYuNz7+WaMObdgUL1vCORMq5CiuxKUmGCA5vgb BRNHBoeW5Upl0ZuHv8CoAjnyr; Received: from 97-122-84-67.hlrn.qwest.net ([97.122.84.67]:51980 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1mrs15-000sGC-4l; Mon, 29 Nov 2021 18:33:07 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Subject: [PATCH 2/3] Move file_and_directory to new file and C++-ize Date: Mon, 29 Nov 2021 18:33:03 -0700 Message-Id: <20211130013304.4135367-3-tom@tromey.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211130013304.4135367-1-tom@tromey.com> References: <20211130013304.4135367-1-tom@tromey.com> 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: 97.122.84.67 X-Source-L: No X-Exim-ID: 1mrs15-000sGC-4l X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-84-67.hlrn.qwest.net (localhost.localdomain) [97.122.84.67]:51980 X-Source-Auth: tom+tromey.com X-Email-Count: 3 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+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" This moves file_and_directory to a new file, and then C++-izes it -- replacing direct assignments with methods, and arranging for it to own any string that must be computed. Finally, the CU's objfile will only be used on demand; this is an important property for the new DWARF indexer's parallel mode. --- gdb/dwarf2/file-and-dir.h | 107 ++++++++++++++++++++++++++++++++++++++ gdb/dwarf2/read.c | 66 ++++++++--------------- gdb/dwarf2/read.h | 1 + 3 files changed, 129 insertions(+), 45 deletions(-) create mode 100644 gdb/dwarf2/file-and-dir.h diff --git a/gdb/dwarf2/file-and-dir.h b/gdb/dwarf2/file-and-dir.h new file mode 100644 index 00000000000..64d5a08bf0c --- /dev/null +++ b/gdb/dwarf2/file-and-dir.h @@ -0,0 +1,107 @@ +/* DWARF file and directory + + Copyright (C) 1994-2021 Free Software Foundation, Inc. + + Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology, + Inc. with support from Florida State University (under contract + with the Ada Joint Program Office), and Silicon Graphics, Inc. + Initial contribution by Brent Benson, Harris Computer Systems, Inc., + based on Fred Fish's (Cygnus Support) implementation of DWARF 1 + support. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#ifndef GDB_DWARF2_FILE_AND_DIR_H +#define GDB_DWARF2_FILE_AND_DIR_H + +#include "objfiles.h" +#include + +/* The return type of find_file_and_directory. Note, the enclosed + string pointers are only valid while this object is valid. */ + +struct file_and_directory +{ + file_and_directory (const char *name_, const char *dir_) + : name (name_), + comp_dir (dir_) + { + } + + /* Return true if the file name is unknown. */ + bool is_unknown () const + { + return name == nullptr; + } + + /* Set the compilation directory. */ + void set_comp_dir (std::string &&dir) + { + comp_dir_storage = std::move (dir); + comp_dir = nullptr; + } + + /* Fetch the compilation directory. This may return NULL in some + circumstances. Note that the return value here is not stable -- + it may change if this object is moved. To get a stable pointer, + you should call intern_comp_dir. */ + const char *get_comp_dir () const + { + if (!comp_dir_storage.empty ()) + return comp_dir_storage.c_str (); + return comp_dir; + } + + /* If necessary, intern the compilation directory using OBJFILE's + string cache. Returns the compilation directory. */ + const char *intern_comp_dir (struct objfile *objfile) + { + if (!comp_dir_storage.empty ()) + { + comp_dir = objfile->intern (comp_dir_storage); + comp_dir_storage.clear (); + } + return comp_dir; + } + + /* Fetch the filename. This never returns NULL. */ + const char *get_name () const + { + return name == nullptr ? "" : name; + } + + /* Set the filename. */ + void set_name (const char *name_) + { + name = name_; + } + +private: + + /* The filename. This is never NULL. */ + const char *name; + + /* The compilation directory. NULL if not known. If we needed to + compute a new string, it will be stored in the comp_dir_storage + member, and this will be NULL. Otherwise, points directly to the + DW_AT_comp_dir string attribute. */ + const char *comp_dir; + + /* The compilation directory, if it needed to be allocated. */ + std::string comp_dir_storage; +}; + +#endif /* GDB_DWARF2_FILE_AND_DIR_H */ diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 3cf0c9ea2a8..5802fc0ef04 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -1206,7 +1206,6 @@ static struct die_info *die_specification (struct die_info *die, static line_header_up dwarf_decode_line_header (sect_offset sect_off, struct dwarf2_cu *cu); -struct file_and_directory; static void dwarf_decode_lines (struct line_header *, const file_and_directory &, struct dwarf2_cu *, dwarf2_psymtab *, @@ -1538,21 +1537,6 @@ dwarf2_per_cu_data_deleter::operator() (dwarf2_per_cu_data *data) delete data; } -/* The return type of find_file_and_directory. Note, the enclosed - string pointers are only valid while this object is valid. */ - -struct file_and_directory -{ - /* The filename. This is never NULL. */ - const char *name; - - /* The compilation directory. NULL if not known. If we needed to - compute a new string, it will be stored in the per-BFD string - bcache; otherwise, points directly to the DW_AT_comp_dir string - attribute owned by the obstack that owns the DIE. */ - const char *comp_dir; -}; - static file_and_directory find_file_and_directory (struct die_info *die, struct dwarf2_cu *cu); @@ -3024,7 +3008,7 @@ dw2_get_file_names_reader (const struct die_reader_specs *reader, file_and_directory fnd = find_file_and_directory (comp_unit_die, cu); int offset = 0; - if (strcmp (fnd.name, "") != 0) + if (fnd.is_unknown ()) ++offset; else if (lh == nullptr) return; @@ -3053,12 +3037,12 @@ dw2_get_file_names_reader (const struct die_reader_specs *reader, } qfn->num_file_names = offset + include_names.size (); - qfn->comp_dir = fnd.comp_dir; + qfn->comp_dir = fnd.intern_comp_dir (per_objfile->objfile); qfn->file_names = XOBNEWVEC (&per_objfile->per_bfd->obstack, const char *, qfn->num_file_names); if (offset != 0) - qfn->file_names[0] = xstrdup (fnd.name); + qfn->file_names[0] = xstrdup (fnd.get_name ()); if (!include_names.empty ()) memcpy (&qfn->file_names[offset], include_names.data (), @@ -7005,15 +6989,15 @@ process_psymtab_comp_unit_reader (const struct die_reader_specs *reader, gdb::unique_xmalloc_ptr debug_filename; static const char artificial[] = ""; file_and_directory fnd = find_file_and_directory (comp_unit_die, cu); - if (strcmp (fnd.name, artificial) == 0) + if (strcmp (fnd.get_name (), artificial) == 0) { debug_filename.reset (concat (artificial, "@", sect_offset_str (per_cu->sect_off), (char *) NULL)); - fnd.name = debug_filename.get (); + fnd.set_name (debug_filename.get ()); } - pst = create_partial_symtab (per_cu, per_objfile, fnd.name); + pst = create_partial_symtab (per_cu, per_objfile, fnd.get_name ()); /* This must be done before calling dwarf2_build_include_psymtabs. */ pst->dirname = dwarf2_string_attr (comp_unit_die, DW_AT_comp_dir, cu); @@ -10493,25 +10477,16 @@ producer_is_gcc_lt_4_3 (struct dwarf2_cu *cu) static file_and_directory find_file_and_directory (struct die_info *die, struct dwarf2_cu *cu) { - file_and_directory res; - /* Find the filename. Do not use dwarf2_name here, since the filename is not a source language identifier. */ - res.name = dwarf2_string_attr (die, DW_AT_name, cu); - res.comp_dir = dwarf2_string_attr (die, DW_AT_comp_dir, cu); - - if (res.comp_dir == NULL - && producer_is_gcc_lt_4_3 (cu) && res.name != NULL - && IS_ABSOLUTE_PATH (res.name)) - { - std::string comp_dir_storage = ldirname (res.name); - if (!comp_dir_storage.empty ()) - res.comp_dir - = cu->per_objfile->objfile->intern (comp_dir_storage.c_str ()); - } + file_and_directory res (dwarf2_string_attr (die, DW_AT_name, cu), + dwarf2_string_attr (die, DW_AT_comp_dir, cu)); - if (res.name == NULL) - res.name = ""; + if (res.get_comp_dir () == nullptr + && producer_is_gcc_lt_4_3 (cu) + && res.get_name () != nullptr + && IS_ABSOLUTE_PATH (res.get_name ())) + res.set_comp_dir (ldirname (res.get_name ())); return res; } @@ -10643,7 +10618,7 @@ read_file_scope (struct die_info *die, struct dwarf2_cu *cu) file_and_directory fnd = find_file_and_directory (die, cu); - cu->start_symtab (fnd.name, fnd.comp_dir, lowpc); + cu->start_symtab (fnd.get_name (), fnd.intern_comp_dir (objfile), lowpc); gdb_assert (per_objfile->sym_cu == nullptr); scoped_restore restore_sym_cu @@ -20752,7 +20727,7 @@ compute_include_file_name (const struct line_header *lh, const file_entry &fe, gdb::unique_xmalloc_ptr hold_compare; if (!IS_ABSOLUTE_PATH (include_name) - && (dir_name != NULL || cu_info.comp_dir != NULL)) + && (dir_name != nullptr || cu_info.get_comp_dir () != nullptr)) { /* Avoid creating a duplicate name for CU_INFO. We do this by comparing INCLUDE_NAME and CU_INFO. @@ -20782,19 +20757,20 @@ compute_include_file_name (const struct line_header *lh, const file_entry &fe, include_name = name_holder->get (); include_name_to_compare = include_name; } - if (!IS_ABSOLUTE_PATH (include_name) && cu_info.comp_dir != nullptr) + if (!IS_ABSOLUTE_PATH (include_name) + && cu_info.get_comp_dir () != nullptr) { - hold_compare.reset (concat (cu_info.comp_dir, SLASH_STRING, + hold_compare.reset (concat (cu_info.get_comp_dir (), SLASH_STRING, include_name, (char *) NULL)); include_name_to_compare = hold_compare.get (); } } gdb::unique_xmalloc_ptr copied_name; - const char *cu_filename = cu_info.name; - if (!IS_ABSOLUTE_PATH (cu_filename) && cu_info.comp_dir != nullptr) + const char *cu_filename = cu_info.get_name (); + if (!IS_ABSOLUTE_PATH (cu_filename) && cu_info.get_comp_dir () != nullptr) { - copied_name.reset (concat (cu_info.comp_dir, SLASH_STRING, + copied_name.reset (concat (cu_info.get_comp_dir (), SLASH_STRING, cu_filename, (char *) NULL)); cu_filename = copied_name.get (); } diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h index fe34e3f95ae..0afcda1c3b0 100644 --- a/gdb/dwarf2/read.h +++ b/gdb/dwarf2/read.h @@ -23,6 +23,7 @@ #include #include #include "dwarf2/comp-unit-head.h" +#include "dwarf2/file-and-dir.h" #include "dwarf2/index-cache.h" #include "dwarf2/section.h" #include "filename-seen-cache.h" -- 2.31.1