From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id YXsfMhovf2purSUAWB0awg (envelope-from ) for ; Fri, 14 Aug 2026 11:07:06 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ZDYxYivR; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id C492E1E09E; Fri, 14 Aug 2026 11:07:06 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-6.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id F0DF61E09E for ; Fri, 14 Aug 2026 11:07:04 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B64CD4B9DB6C for ; Fri, 14 Aug 2026 15:07:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B64CD4B9DB6C Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ZDYxYivR Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id AB4464BA902F for ; Fri, 14 Aug 2026 15:06:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AB4464BA902F Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org AB4464BA902F Authentication-Results: sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1786719997; cv=none; b=tXICS0Vpg4GPCAam2QGJN0skWDkq4CF+Chjqw1p/RzSf8mFcs/fEqeStjF9xMLqVR8UHQUZ1yWcxO/ILfVeqA7iFkyfVBWiL4K3sF5mc8R2GwZ02VRmm/ypv3wU73WVoJ8Nw03u8MLdbEjC5i2gYhP8E+cbsyP6zF998CTLqgXk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1786719997; c=relaxed/simple; bh=CWp1iad7oHjRu6rRy07kVdwkyEuhCYbtZaWp4uSVXHM=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=DxT6H4mR5LLzGIca2SoFP2BTG0Ir6bvBvmyoiEKxjr6z2PS6bx9UGWj1q7VVD6Eke6DWl6+MzpR9xoEbZlkSgn9DcJOzvg40XRTHBHkXF22ZPRUx0buIHRDPffBFaM/sSvtl1iLvR2vMrofuDUUCO/6Ry0DtU4c0qJztvsA6Wb0= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ZDYxYivR DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AB4464BA902F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1786719997; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XIGpxpkJtLyvZcM/0wNpH1QYNHWA/n1NhwV/vKMG0wE=; b=ZDYxYivRH2HtytqFXoA5kBHYCTAr3rYeqzMoyibNwuGNUljxYWEAU6MD4WXU9V2x6JorIn +s/ucUCgqZ2UNrfN8nPdB7f94Gh3UdXd5QbwSvHbiFMEJWsWHjtfPuTmtJYSlyWgR8mYEv 1F0+5ugaAnRW+GuOP6Iq/b/tVpU0cqc= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-50-mS4fcIzDMDelPiZFtJkslw-1; Fri, 14 Aug 2026 11:06:25 -0400 X-MC-Unique: mS4fcIzDMDelPiZFtJkslw-1 X-Mimecast-MFC-AGG-ID: mS4fcIzDMDelPiZFtJkslw_1786719984 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-493fa6e28a7so11415245e9.1 for ; Fri, 14 Aug 2026 08:06:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786719984; x=1787324784; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=XIGpxpkJtLyvZcM/0wNpH1QYNHWA/n1NhwV/vKMG0wE=; b=JgKg3JsbiL/qDOX/fXTSMv57zgn7rzIRwm9PpRwdU6uJau9JWtdzYWbup62HJLMi0/ NGw/rY4j7oi3MUw18WlUH6nBSywOcumnSuGnqBhXoh+NTzRtqg55nt2cT33erfGPFL+L FtWWVoPpxdQLtSB+ABvkKXqqRNw+0rVVbEvRO/i2BIGo5BlsbXToLrEQ0xW5IHRQV8O9 GsXNYurxmBAlRgVHG5MG9D1E2Ak/hk1qyuxUs1L4+fZV1rvXgcJPXUXPXZPtIS3USBBD /CY6pWU/bBmfYuuIzkderS08ysifnAZHVJHvPsJXdFMCogh9AoJGT3d1//vXsOSNujCw XczQ== X-Gm-Message-State: AOJu0YxT/PzOquf0JC/YGT3B/vWo/B03rHpT+++xhtXi/r98+yYi7tTp Z5sB1mSiG6WoOD5ikle5LY72jIKjQGJ9YWvIeWd9xW5F10nWxvWpPQuU4yYAKYoxrhnfHYxPIgD OVJ7OP3bC6IQbyDPHrSjyzvXuFiO2t4L+diodX64Nx5NObIWo3+Tjk1lll2P5IOcgpNzFSmMimx hC6dpap5OpGy5M3xp/l7zb13NLEdEFGiLipOZRC+DLa1MTdc4= X-Gm-Gg: AR+sD13jrO8VUXMMefwGSARyPTkh7BCxbs+XcW6Chp2MOik7SVamkgGF5oHc3T+IwqT 2wWdLPuxSu3KT1dI92MZhdVUlCejs6sdvQz9pn719E4+XnF+QAihk/tPrxtMhCcZwS9XZ2c097b 8WZNcdYOoSF/f/SH6oj9CNCtQYvB9r14yKevVSggqBTwGen2ZR1E23QSkAujb1hwzAukPE5WAAi 15BXG6ky5/iRRogyDcNSfU487sq5TOAJuHYgvT2ght7A58TW2NLGWorNgOSe6tNb3Hi6ZqfU3FO BJIBZY15xpU0/EO/wfchlEdjONPU8EHUw9E+3iznSsCgCxbOwVi36lIV7Ica6jfe49+zpTYXw8O 2fk2W1ySDFTzMbIZK/oA= X-Received: by 2002:a05:600c:5286:b0:499:621a:2ec2 with SMTP id 5b1f17b1804b1-4998933fd79mr70472885e9.3.1786719983894; Fri, 14 Aug 2026 08:06:23 -0700 (PDT) X-Received: by 2002:a05:600c:5286:b0:499:621a:2ec2 with SMTP id 5b1f17b1804b1-4998933fd79mr70471475e9.3.1786719983311; Fri, 14 Aug 2026 08:06:23 -0700 (PDT) Received: from localhost (67.72.115.87.dyn.plus.net. [87.115.72.67]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49988ae8af3sm50633525e9.4.2026.08.14.08.06.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Aug 2026 08:06:21 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Aaron Merey Subject: [RFC 2/3] gdb: use basic_safe_range to iterate over objfile::qf Date: Fri, 14 Aug 2026 16:06:07 +0100 Message-Id: <4337714baed7b5b73e4b2168fc0e61d395e95322.1786715843.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: i7qQNlDHeMyINJ8IhaUlkJktGdq5QRoHiA8bFBm0U04_1786719984 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org From: Aaron Merey Change objfile's quick_symbol_function iteration to use a safe iterator which allows for a quick_symbol_function to be deleted while iterating over the list. The next patch adds deferred debug information downloading. To make this work GDB needs to be able to delete a quick_symbol_function from an objfile's list while iterating over the quick_symbol_function list. Such deletion requires that we use a deletion safe iterator. Make objfile::qf private and rename to objfile::m_qf. Add member function objfile::add_qf and objfile::clear_qf for manipulating the quick_symbol_function list now that it is private. A new member function objfile::qf returns a basic_safe_range object suitably templated to allow iteration over objfile::m_qf. All the other changes are straight forward updates to handle the objfile API changes. --- gdb/ctfread.c | 4 ++-- gdb/dwarf2/read.c | 4 ++-- gdb/jit.c | 4 ++-- gdb/objfiles.h | 33 ++++++++++++++++++++++++++++++--- gdb/symfile-debug.c | 32 ++++++++++++++++---------------- gdb/symfile.c | 4 ++-- 6 files changed, 54 insertions(+), 27 deletions(-) diff --git a/gdb/ctfread.c b/gdb/ctfread.c index 5f8c54a34df..c5d623a9b11 100644 --- a/gdb/ctfread.c +++ b/gdb/ctfread.c @@ -1324,8 +1324,8 @@ elfctf_build_symtabs (objfile *objfile) styled_string (file_name_style.style (), bfd_get_filename (abfd)), ctf_errmsg (err)); - objfile->qf.emplace_front (std::make_unique - (std::move (iter_data.compunit_symtabs))); + objfile->add_qf (std::make_unique + (std::move (iter_data.compunit_symtabs))); } #else diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 114c608fde3..3557d88833a 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -2139,7 +2139,7 @@ dwarf2_initialize_objfile (struct objfile *objfile, dwarf_read_debug_printf ("readnow requested"); create_all_units (per_objfile); - objfile->qf.emplace_front (new readnow_functions); + objfile->add_qf (std::make_unique ()); } /* Was a GDB index already read when we processed an objfile sharing PER_BFD? */ @@ -2169,7 +2169,7 @@ dwarf2_initialize_objfile (struct objfile *objfile, { if (dwarf_synchronous) per_bfd->index_table->wait_completely (); - objfile->qf.push_front (per_bfd->index_table->make_quick_functions ()); + objfile->add_qf (per_bfd->index_table->make_quick_functions ()); } return true; diff --git a/gdb/jit.c b/gdb/jit.c index c0aeb41e5aa..73e16e0a704 100644 --- a/gdb/jit.c +++ b/gdb/jit.c @@ -683,8 +683,8 @@ jit_object_close_impl (struct gdb_symbol_callbacks *cb, for (gdb_symtab &symtab : obj->symtabs) compunit_symtabs.emplace_back (finalize_symtab (&symtab, objfile)); - objfile->qf.emplace_front (std::make_unique - (std::move (compunit_symtabs))); + objfile->add_qf (std::make_unique + (std::move (compunit_symtabs))); add_objfile_entry (objfile, priv_data->entry_addr, priv_data->entry.symfile_addr, diff --git a/gdb/objfiles.h b/gdb/objfiles.h index 406ab36b39d..12e77d51b74 100644 --- a/gdb/objfiles.h +++ b/gdb/objfiles.h @@ -344,6 +344,12 @@ class separate_debug_iterator using separate_debug_range = iterator_range; +/* See objfile::qf_safe. */ + +using qf_list = std::forward_list; +using qf_range = iterator_range; +using qf_safe_range = basic_safe_range; + /* Sections in an objfile. The section offsets are stored in the OBJFILE. */ @@ -743,9 +749,22 @@ struct objfile : intrusive_list_node const struct sym_fns *sf = nullptr; - /* The "quick" (aka partial) symbol functions for this symbol - reader. */ - std::forward_list qf; + /* Returns an iterable object that allows for safe deletion during + iteration. See gdbsupport/safe-iterator.h. */ + qf_safe_range qf () + { + return qf_safe_range (qf_range (m_qf.begin (), m_qf.end ())); + } + + void add_qf (quick_symbol_functions_up qf) + { + m_qf.push_front (std::move (qf)); + } + + void clear_qf () + { + m_qf.clear (); + } /* Per objfile data-pointers required by other GDB modules. */ @@ -861,6 +880,14 @@ struct objfile : intrusive_list_node mechanism as ELF should set this flag too. This flag is used in conjunction with the minimal_symbol::maybe_copied method. */ bool object_format_has_copy_relocs = false; + +private: + /* The "quick" (aka partial) symbol functions for this symbol + reader. Many quick_symbol_functions methods may result + in the deletion of a quick_symbol_functions from this + qf_list. It is recommended that qf_safe be used to iterate + over the qf_list. */ + qf_list m_qf; }; /* A deleter for objfile. */ diff --git a/gdb/symfile-debug.c b/gdb/symfile-debug.c index 2432a709ddf..e009821f78c 100644 --- a/gdb/symfile-debug.c +++ b/gdb/symfile-debug.c @@ -83,7 +83,7 @@ objfile::has_partial_symbols () them, then that is an indication that they are in fact available. Without this function the symbols may have been already read in but they also may not be present in this objfile. */ - for (const auto &iter : qf) + for (const auto &iter : qf ()) { retval = iter->has_symbols (this); if (retval) @@ -106,7 +106,7 @@ objfile::has_unexpanded_symtabs () objfile_debug_name (this)); bool result = false; - for (const auto &iter : qf) + for (const auto &iter : qf ()) { if (iter->has_unexpanded_symtabs (this)) { @@ -131,7 +131,7 @@ objfile::find_last_source_symtab () gdb_printf (gdb_stdlog, "qf->find_last_source_symtab (%s)\n", objfile_debug_name (this)); - for (const auto &iter : qf) + for (const auto &iter : qf ()) { retval = iter->find_last_source_symtab (this); if (retval != nullptr) @@ -155,7 +155,7 @@ objfile::forget_cached_source_info () for (compunit_symtab &cu : compunits ()) cu.forget_cached_source_info (); - for (const auto &iter : qf) + for (const auto &iter : qf ()) iter->forget_cached_source_info (this); } @@ -273,7 +273,7 @@ objfile::find_symtab_matching_filename (const char *name, : iteration_status::stop); }; - for (const auto &iter : qf) + for (const auto &iter : qf ()) if (iter->search (this, match_one_filename, nullptr, nullptr, compunit_callback, SEARCH_GLOBAL_BLOCK | SEARCH_STATIC_BLOCK, @@ -325,7 +325,7 @@ objfile::lookup_symbol (block_enum kind, const lookup_name_info &name, return iteration_status::keep_going; }; - for (const auto &iter : qf) + for (const auto &iter : qf ()) { if (iter->search (this, nullptr, &name, nullptr, search_one_symtab, kind == GLOBAL_BLOCK @@ -352,7 +352,7 @@ objfile::print_stats (bool print_bcache) gdb_printf (gdb_stdlog, "qf->print_stats (%s, %d)\n", objfile_debug_name (this), print_bcache); - for (const auto &iter : qf) + for (const auto &iter : qf ()) iter->print_stats (this, print_bcache); } @@ -363,7 +363,7 @@ objfile::dump () gdb_printf (gdb_stdlog, "qf->dump (%s)\n", objfile_debug_name (this)); - for (const auto &iter : qf) + for (const auto &iter : qf ()) iter->dump (this); } @@ -374,7 +374,7 @@ objfile::expand_all_symtabs () gdb_printf (gdb_stdlog, "qf->expand_all_symtabs (%s)\n", objfile_debug_name (this)); - for (const auto &iter : qf) + for (const auto &iter : qf ()) iter->expand_all_symtabs (this); } @@ -392,7 +392,7 @@ objfile::expand_symtabs_with_fullname (const char *fullname) return filename_cmp (basenames ? basename : fullname, filename) == 0; }; - for (const auto &iter : qf) + for (const auto &iter : qf ()) iter->search (this, file_matcher, nullptr, nullptr, nullptr, SEARCH_GLOBAL_BLOCK | SEARCH_STATIC_BLOCK, SEARCH_ALL_DOMAINS); @@ -419,7 +419,7 @@ objfile::search (search_symtabs_file_matcher file_matcher, host_address_to_string (&compunit_callback), domain_name (domain).c_str ()); - for (const auto &iter : qf) + for (const auto &iter : qf ()) if (iter->search (this, file_matcher, lookup_name, symbol_matcher, compunit_callback, search_flags, domain, lang_matcher) == iteration_status::stop) @@ -445,7 +445,7 @@ objfile::find_pc_sect_compunit_symtab (bound_minimal_symbol msymbol, host_address_to_string (section), warn_if_readin); - for (const auto &iter : qf) + for (const auto &iter : qf ()) { retval = iter->find_pc_sect_compunit_symtab (this, msymbol, pc, section, warn_if_readin); @@ -472,7 +472,7 @@ objfile::map_symbol_filenames (symbol_filename_listener fun, bool need_fullname) objfile_debug_name (this), need_fullname); - for (const auto &iter : qf) + for (const auto &iter : qf ()) iter->map_symbol_filenames (this, fun, need_fullname); } @@ -484,7 +484,7 @@ objfile::compute_main_name () "qf->compute_main_name (%s)\n", objfile_debug_name (this)); - for (const auto &iter : qf) + for (const auto &iter : qf ()) iter->compute_main_name (this); } @@ -498,7 +498,7 @@ objfile::find_symbol_by_address (CORE_ADDR address) hex_string (address)); struct symbol *result = NULL; - for (const auto &iter : qf) + for (const auto &iter : qf ()) { result = iter->find_symbol_by_address (this, address); if (result != nullptr) @@ -523,7 +523,7 @@ objfile::lookup_global_symbol_language (const char *name, enum language result = language_unknown; *symbol_found_p = false; - for (const auto &iter : qf) + for (const auto &iter : qf ()) { result = iter->lookup_global_symbol_language (this, name, domain, symbol_found_p); diff --git a/gdb/symfile.c b/gdb/symfile.c index 017f7a49d8d..ce37d764485 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -881,7 +881,7 @@ syms_from_objfile_1 (struct objfile *objfile, scoped_objfile_unlinker objfile_holder (objfile); objfile_set_sym_fns (objfile, find_sym_fns (objfile->obfd.get ())); - objfile->qf.clear (); + objfile->clear_qf (); if (objfile->sf == NULL) { @@ -2603,7 +2603,7 @@ reread_symbols (int from_tty) based on whether .gdb_index is present, and we need it to start over. PR symtab/15885 */ objfile_set_sym_fns (&objfile, find_sym_fns (objfile.obfd.get ())); - objfile.qf.clear (); + objfile.clear_qf (); build_objfile_section_table (&objfile); -- 2.25.4