From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-il1-x133.google.com (mail-il1-x133.google.com [IPv6:2607:f8b0:4864:20::133]) by sourceware.org (Postfix) with ESMTPS id 26D9A3858D20 for ; Fri, 27 Jan 2023 21:11:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 26D9A3858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-il1-x133.google.com with SMTP id f8so2829387ilj.5 for ; Fri, 27 Jan 2023 13:11:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; h=mime-version:user-agent:message-id:in-reply-to:date:references :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=Jfl/irOiAAE3skXcmrhd0ZNSXaGvJb+i/aruE8qS0PE=; b=QTlXay514rRlg3peUuBtLjeB0h7UsC/kAXrXDWXSkZgre4MzV6DR/bEQWBv70mShT2 8LlHe2yWz6cn0YSjmbPCEQxZIIu/O0Auz5dF7/f87H9At6Lft29+Pb3MfLzbreMeGhLx U0E1jdxyF7KbiM0tSuTJsWUl9Pe7xfMcbrvCogpWgHGwocr/ls6odfftbOIkxQfDq/EY skX0esChg0+V/dM0qHpkI/+9RMxrtJKVPKZdPN5lKITtVExGmg0XrRIPs8R7Dq/4CQ5q 95cka738m/8NlnllVFLvtkN8U2Z/c3TXqY37OfTNBtNrN6Bab+rE2GmNGOqATSvuLXwY FcCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:user-agent:message-id:in-reply-to:date:references :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Jfl/irOiAAE3skXcmrhd0ZNSXaGvJb+i/aruE8qS0PE=; b=yKMBdeW8zVjK3brDgSHQymdv33n5z4E+qDy6Im0D/oqqHu1+VPdEWnrb3jzJoWnAcw h6ZMJ3i9uJYsqNCEbmzU9ClZ9mB10uAnE28N0EZfRg6POa4O5JDgTTwDvRH8SbzrGPKo IOaDllYMouHaUm7ycN2tsYrOQ1vPU8Jaqv/41+RxybeM1yfosL+xstcJ+/WMwN0Zs+p2 Px9SnKOQqjXj37X9ECEfEPaEYk6tenalk6P9/OiA121BsvdQ3ywAIBa5P7j1UfWSbCLH mBROVkNAbeb0SR/kccenDQGkfLY2fSNqpfNWoIIHLXrrCjoumggd+L7+NCUZbJaXbGsI sxpQ== X-Gm-Message-State: AO0yUKUKO6Fm8T4qE3ZcAYnh4kWNn48jrAs3JNl2v6dUuwrs5RF1BT6X miGNtJQCAR13LnQHx31DBeX72w== X-Google-Smtp-Source: AK7set+IZTlTuo84VTwJS2Qxt/r0rqkgzG64TMm3RQrcbprwOeUM+SuL2GbNHwMhrMbKUv0rmR01YA== X-Received: by 2002:a05:6e02:1bcf:b0:310:b758:c1a with SMTP id x15-20020a056e021bcf00b00310b7580c1amr5705577ilv.30.1674853898363; Fri, 27 Jan 2023 13:11:38 -0800 (PST) Received: from murgatroyd (75-166-146-144.hlrn.qwest.net. [75.166.146.144]) by smtp.gmail.com with ESMTPSA id r6-20020a02c846000000b0039d724c2416sm1138686jao.134.2023.01.27.13.11.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Jan 2023 13:11:37 -0800 (PST) From: Tom Tromey To: Simon Marchi Cc: Tom Tromey , gdb-patches@sourceware.org Subject: Re: [PATCH] More const-correctness in cooked indexer References: <20230127162205.4125816-1-tromey@adacore.com> X-Attribution: Tom Date: Fri, 27 Jan 2023 14:11:36 -0700 In-Reply-To: (Simon Marchi's message of "Fri, 27 Jan 2023 15:11:00 -0500") Message-ID: <87lelnptrr.fsf@tromey.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP 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: >>>>> "Simon" == Simon Marchi writes: Simon> On 1/27/23 11:22, Tom Tromey via Gdb-patches wrote: >> I noticed that iterating over the index yields non-const >> cooked_index_entry objects. However, after finalization, they should >> not be modified. This patch enforces this by adding const where >> needed. Simon> I think you could constify these methods at the same time (it would help Simon> me for my dump patch): Simon> - cooked_index::wait Simon> - cooked_index::all_entries Simon> - cooked_index_vector::wait Simon> - cooked_index_vector::all_entries I also made find const. I'm going to check in the appended. Tom commit bd2e1e5511ac7c267544e5ce17b8dd41057d7fdb Author: Tom Tromey Date: Fri Jan 27 09:20:43 2023 -0700 More const-correctness in cooked indexer I noticed that iterating over the index yields non-const cooked_index_entry objects. However, after finalization, they should not be modified. This patch enforces this by adding const where needed. v2 makes the find, all_entries, and wait methods const as well. diff --git a/gdb/dwarf2/cooked-index.c b/gdb/dwarf2/cooked-index.c index 09b3fd70b26..1a568e6aae7 100644 --- a/gdb/dwarf2/cooked-index.c +++ b/gdb/dwarf2/cooked-index.c @@ -355,11 +355,11 @@ cooked_index::do_finalize () /* See cooked-index.h. */ cooked_index::range -cooked_index::find (const std::string &name, bool completing) +cooked_index::find (const std::string &name, bool completing) const { wait (); - auto lower = std::lower_bound (m_entries.begin (), m_entries.end (), name, + auto lower = std::lower_bound (m_entries.cbegin (), m_entries.cend (), name, [=] (const cooked_index_entry *entry, const std::string &n) { @@ -367,7 +367,7 @@ cooked_index::find (const std::string &name, bool completing) completing); }); - auto upper = std::upper_bound (m_entries.begin (), m_entries.end (), name, + auto upper = std::upper_bound (m_entries.cbegin (), m_entries.cend (), name, [=] (const std::string &n, const cooked_index_entry *entry) { @@ -413,7 +413,7 @@ cooked_index_vector::get_addrmaps () /* See cooked-index.h. */ cooked_index_vector::range -cooked_index_vector::find (const std::string &name, bool completing) +cooked_index_vector::find (const std::string &name, bool completing) const { std::vector result_range; result_range.reserve (m_vector.size ()); diff --git a/gdb/dwarf2/cooked-index.h b/gdb/dwarf2/cooked-index.h index 55eaf9955ab..e12376cdf98 100644 --- a/gdb/dwarf2/cooked-index.h +++ b/gdb/dwarf2/cooked-index.h @@ -217,7 +217,7 @@ class cooked_index void finalize (); /* Wait for this index's finalization to be complete. */ - void wait () + void wait () const { m_future.wait (); } @@ -225,19 +225,20 @@ class cooked_index friend class cooked_index_vector; /* A simple range over part of m_entries. */ - typedef iterator_range::iterator> range; + typedef iterator_range::const_iterator> + range; /* Return a range of all the entries. */ - range all_entries () + range all_entries () const { wait (); - return { m_entries.begin (), m_entries.end () }; + return { m_entries.cbegin (), m_entries.cend () }; } /* Look up an entry by name. Returns a range of all matching results. If COMPLETING is true, then a larger range, suitable for completion, will be returned. */ - range find (const std::string &name, bool completing); + range find (const std::string &name, bool completing) const; private: @@ -317,7 +318,7 @@ class cooked_index_vector : public dwarf_scanner_base /* Wait until the finalization of the entire cooked_index_vector is done. */ - void wait () + void wait () const { for (auto &item : m_vector) item->wait (); @@ -340,10 +341,10 @@ class cooked_index_vector : public dwarf_scanner_base /* Look up an entry by name. Returns a range of all matching results. If COMPLETING is true, then a larger range, suitable for completion, will be returned. */ - range find (const std::string &name, bool completing); + range find (const std::string &name, bool completing) const; /* Return a range of all the entries. */ - range all_entries () + range all_entries () const { std::vector result_range; result_range.reserve (m_vector.size ());