From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id yFqRG0FGq2F2OQAAWB0awg (envelope-from ) for ; Sat, 04 Dec 2021 05:43:13 -0500 Received: by simark.ca (Postfix, from userid 112) id 5FA551F0CE; Sat, 4 Dec 2021 05:43:13 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 340041EDEE for ; Sat, 4 Dec 2021 05:43:12 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 975A53858407 for ; Sat, 4 Dec 2021 10:43:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 975A53858407 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1638614591; bh=oQq/f5BuG+pktoyTiQefWHwaVNnbjeOVwXSjO6Nc+D0=; h=Date:To:Subject:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=x3z2hwGkFCZXDe8A+yMtjqTbUXS+w6WqT3O60iOzEFJ8qjbmTo+LcFNy/7OQmD0sW 8CVr0o0p8k3xYWCaKOhhK13R4RqMUCr8KWx0uydBAgqabfBcB+zyy68Z6OlJpc6sSE heqiSGroVk9NlNfEzurCtBKL5THzBi/PhKJm80aM= Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by sourceware.org (Postfix) with ESMTPS id E73823858C60 for ; Sat, 4 Dec 2021 10:42:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E73823858C60 Received: by mail-wm1-x333.google.com with SMTP id g191-20020a1c9dc8000000b0032fbf912885so4117679wme.4 for ; Sat, 04 Dec 2021 02:42:51 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=oQq/f5BuG+pktoyTiQefWHwaVNnbjeOVwXSjO6Nc+D0=; b=QWBx8sn/wVSAKOopjPTjvu214rGsgkvlnlpdZ1xomtSlPgOwh2MOPy6j25I9PoEv6y UnaTYANwvn9FNBwbotMxgvB6fPzxC+VXSmXFjhu5TUI1YWrpk3t7qLbMyR/EzleUu9j7 wrL3CW+m61JbDEr6hX4nlYB1dI21h1aw/OvrZ1iwKau98p6Wo5kg8FjcmBLyHRgfci+D 8+AV4zHd3mcxAepjr12D4DCrqZ6jkEMQIHUtufnbyf48e5TcCyBUZ8J54R4kchpGum5u udMGJ1+Rc/kqdYiMAZsjSb9zUrOX5OK1Hgpp0TodqqUnl/08wz7A/9b7vuObh5k+Os20 PtTw== X-Gm-Message-State: AOAM531gRfo1mayqqEDsBQ5YcH/jz/WjCd+JA0fO+BPUWhjAZPcLtRZF bIx3eKsvxGj+jgaHv7i/SuOx X-Google-Smtp-Source: ABdhPJyYtKNGp8b9c0zKv6RmF6WQK/ZTNskKmp6hWY20jMkLYIPkuMy51SptWNtEbBPyp2fM43JnFA== X-Received: by 2002:a05:600c:19d0:: with SMTP id u16mr21930871wmq.111.1638614570940; Sat, 04 Dec 2021 02:42:50 -0800 (PST) Received: from takamaka.home (lfbn-reu-1-483-157.w92-130.abo.wanadoo.fr. [92.130.72.157]) by smtp.gmail.com with ESMTPSA id f15sm6548639wmg.30.2021.12.04.02.42.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Dec 2021 02:42:49 -0800 (PST) Received: by takamaka.home (Postfix, from userid 1000) id D5DA7A5A43; Sat, 4 Dec 2021 14:42:46 +0400 (+04) Date: Sat, 4 Dec 2021 14:42:46 +0400 To: Tom Tromey Subject: Re: [PATCH 3/3] Cache the result of find_file_and_directory Message-ID: References: <20211130013304.4135367-1-tom@tromey.com> <20211130013304.4135367-4-tom@tromey.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211130013304.4135367-4-tom@tromey.com> 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: Joel Brobecker via Gdb-patches Reply-To: Joel Brobecker Cc: Joel Brobecker , gdb-patches@sourceware.org Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" Hi Tom, > This changes the DWARF reader to cache the result of > find_file_and_directory. This is not especially important now, but it > will help the new DWARF indexer. With the renaming of the class members moved to patch #2 (I made the assumption that all the changes in file-and-dir.h are about that, at least from what I could see), this patch looks good to me. > --- > gdb/dwarf2/file-and-dir.h | 38 +++++++++++++++++++------------------- > gdb/dwarf2/read.c | 18 +++++++++++------- > gdb/dwarf2/read.h | 6 ++++++ > 3 files changed, 36 insertions(+), 26 deletions(-) > > diff --git a/gdb/dwarf2/file-and-dir.h b/gdb/dwarf2/file-and-dir.h > index 64d5a08bf0c..b64d304964a 100644 > --- a/gdb/dwarf2/file-and-dir.h > +++ b/gdb/dwarf2/file-and-dir.h > @@ -35,23 +35,23 @@ > > struct file_and_directory > { > - file_and_directory (const char *name_, const char *dir_) > - : name (name_), > - comp_dir (dir_) > + file_and_directory (const char *name, const char *dir) > + : m_name (name), > + m_comp_dir (dir) > { > } > > /* Return true if the file name is unknown. */ > bool is_unknown () const > { > - return name == nullptr; > + return m_name == nullptr; > } > > /* Set the compilation directory. */ > void set_comp_dir (std::string &&dir) > { > - comp_dir_storage = std::move (dir); > - comp_dir = nullptr; > + m_comp_dir_storage = std::move (dir); > + m_comp_dir = nullptr; > } > > /* Fetch the compilation directory. This may return NULL in some > @@ -60,48 +60,48 @@ struct file_and_directory > 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 (!m_comp_dir_storage.empty ()) > + return m_comp_dir_storage.c_str (); > + return m_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 ()) > + if (!m_comp_dir_storage.empty ()) > { > - comp_dir = objfile->intern (comp_dir_storage); > - comp_dir_storage.clear (); > + m_comp_dir = objfile->intern (m_comp_dir_storage); > + m_comp_dir_storage.clear (); > } > - return comp_dir; > + return m_comp_dir; > } > > /* Fetch the filename. This never returns NULL. */ > const char *get_name () const > { > - return name == nullptr ? "" : name; > + return m_name == nullptr ? "" : m_name; > } > > /* Set the filename. */ > - void set_name (const char *name_) > + void set_name (const char *name) > { > - name = name_; > + m_name = name; > } > > private: > > /* The filename. This is never NULL. */ > - const char *name; > + const char *m_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; > + const char *m_comp_dir; > > /* The compilation directory, if it needed to be allocated. */ > - std::string comp_dir_storage; > + std::string m_comp_dir_storage; > }; > > #endif /* GDB_DWARF2_FILE_AND_DIR_H */ > diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c > index 5802fc0ef04..ff5758eb0a4 100644 > --- a/gdb/dwarf2/read.c > +++ b/gdb/dwarf2/read.c > @@ -1537,8 +1537,8 @@ dwarf2_per_cu_data_deleter::operator() (dwarf2_per_cu_data *data) > delete data; > } > > -static file_and_directory find_file_and_directory (struct die_info *die, > - struct dwarf2_cu *cu); > +static file_and_directory &find_file_and_directory > + (struct die_info *die, struct dwarf2_cu *cu); > > static const char *compute_include_file_name > (const struct line_header *lh, > @@ -3005,7 +3005,7 @@ dw2_get_file_names_reader (const struct die_reader_specs *reader, > lh = dwarf_decode_line_header (line_offset, cu); > } > > - file_and_directory fnd = find_file_and_directory (comp_unit_die, cu); > + file_and_directory &fnd = find_file_and_directory (comp_unit_die, cu); > > int offset = 0; > if (fnd.is_unknown ()) > @@ -6988,7 +6988,7 @@ process_psymtab_comp_unit_reader (const struct die_reader_specs *reader, > /* Allocate a new partial symbol table structure. */ > gdb::unique_xmalloc_ptr debug_filename; > static const char artificial[] = ""; > - file_and_directory fnd = find_file_and_directory (comp_unit_die, cu); > + file_and_directory &fnd = find_file_and_directory (comp_unit_die, cu); > if (strcmp (fnd.get_name (), artificial) == 0) > { > debug_filename.reset (concat (artificial, "@", > @@ -10474,9 +10474,12 @@ producer_is_gcc_lt_4_3 (struct dwarf2_cu *cu) > return cu->producer_is_gcc_lt_4_3; > } > > -static file_and_directory > +static file_and_directory & > find_file_and_directory (struct die_info *die, struct dwarf2_cu *cu) > { > + if (cu->per_cu->fnd != nullptr) > + return *cu->per_cu->fnd; > + > /* Find the filename. Do not use dwarf2_name here, since the filename > is not a source language identifier. */ > file_and_directory res (dwarf2_string_attr (die, DW_AT_name, cu), > @@ -10488,7 +10491,8 @@ find_file_and_directory (struct die_info *die, struct dwarf2_cu *cu) > && IS_ABSOLUTE_PATH (res.get_name ())) > res.set_comp_dir (ldirname (res.get_name ())); > > - return res; > + cu->per_cu->fnd.reset (new file_and_directory (std::move (res))); > + return *cu->per_cu->fnd; > } > > /* Handle DW_AT_stmt_list for a compilation unit. > @@ -10616,7 +10620,7 @@ read_file_scope (struct die_info *die, struct dwarf2_cu *cu) > lowpc = highpc; > lowpc = gdbarch_adjust_dwarf2_addr (gdbarch, lowpc + baseaddr); > > - file_and_directory fnd = find_file_and_directory (die, cu); > + file_and_directory &fnd = find_file_and_directory (die, cu); > > cu->start_symtab (fnd.get_name (), fnd.intern_comp_dir (objfile), lowpc); > > diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h > index 0afcda1c3b0..2f849d5f9a1 100644 > --- a/gdb/dwarf2/read.h > +++ b/gdb/dwarf2/read.h > @@ -180,6 +180,12 @@ struct dwarf2_per_cu_data > should be private, but we can't make it private at the moment. */ > mutable comp_unit_head m_header {}; > > + /* The file and directory for this CU. This is cached so that we > + don't need to re-examine the DWO in some situations. This may be > + nullptr, depending on the CU; for example a partial unit won't > + have one. */ > + std::unique_ptr fnd; > + > /* When dwarf2_per_bfd::using_index is true, the 'quick' field > is active. Otherwise, the 'psymtab' field is active. */ > union > -- > 2.31.1 > -- Joel