From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id mVuVJ9wc4WUfvTIAWB0awg (envelope-from ) for ; Thu, 29 Feb 2024 19:10:04 -0500 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=ML9gjxwA; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 950EF1E0D2; Thu, 29 Feb 2024 19:10:04 -0500 (EST) Received: from server2.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 ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 7819F1E030 for ; Thu, 29 Feb 2024 19:10:02 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1B71C3858C39 for ; Fri, 1 Mar 2024 00:10:02 +0000 (GMT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 4DDAC3858D34 for ; Fri, 1 Mar 2024 00:09:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4DDAC3858D34 Authentication-Results: sourceware.org; dmarc=pass (p=none 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 4DDAC3858D34 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709251779; cv=none; b=hxkeh0mTJoRGvOa1LfKOq9lBEyCC+/IrBD98dnvP0YbYq1/hNerLyV3VLh9mtRdCiphDoJCRWfDWAE3889myY06BJ1o3lSHe8+OmjXon/CilnDHw8dKPuBlIhjnVguU3M4F+acUWHLis0xPYn5w74im0tQqxp1p+rxPF3hQNTWA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709251779; c=relaxed/simple; bh=lJaGe1Ey06UomKN1PGOBBNSGzPOO1r+AkPuEnV3CLiI=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=CRdDjJv3bE4U4mctVlCti+ArttMJLt9fTA0+LrE9wafkJpbBGTl4DTCFDeNQn1dghzGbZB3jDYhAOulo1MdbZgWW/sX5XmcRapfVJXkyRihwOGG8ZdngwBzIh48HGoY55OSW1liMXuxV64N3VFxwJAjiVh+8FZVha7xwYO/bis4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709251774; 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=QZ0uJ1XKtMLGtsMqNX7Sy5S673nmcRhlJPJnRJFxrAU=; b=ML9gjxwAWIM8EkdJMEHjvDr8B3IQ1XiCig2MUAZDdhdVC0xHl1Ox3Ksa5X7/0lkZKaSOLY /XatbCFxj8tmXt5d1k59Lk0SZt9MYN6e6fmAhoBDtswqyXaCaH8w9UhMn+eN6V4AmsU+9o jQaOl3+USGkxamnpGdKDqguUebcdRBI= Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-604-O9jjnp9pNZmK9cYSLgVYcw-1; Thu, 29 Feb 2024 19:09:31 -0500 X-MC-Unique: O9jjnp9pNZmK9cYSLgVYcw-1 Received: by mail-pg1-f197.google.com with SMTP id 41be03b00d2f7-5d8bcf739e5so1063833a12.1 for ; Thu, 29 Feb 2024 16:09:31 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709251770; x=1709856570; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QZ0uJ1XKtMLGtsMqNX7Sy5S673nmcRhlJPJnRJFxrAU=; b=HZ88WWYmV9H+LZ7OS4SLocB8Hn91KN5TygERcR8qkNzOdYHa5P2cFSNCbEM5paPh1H t+q+NoKxhS4ajkP9UmC4Yfj3jnXvR4tlk+JRzBoLU+KysPh5S07AaKiSDNZP20Yq72yt hkMCaOk1UF/xEsYB51ElKFXndIIrHWM+QZZ8+4nEMDC3zDOCkTJzMrw/f0RirSLR9ZOJ 1M5K/TmmM7OZobq/Lo2LO5094N+Sh2RO9GL4PbWPxYl0SNR9UKJvd35pXnQMNuXug6XV hdaucaK4GTIG2A9oAoUzLvFqtWyIo/Lk4t1yUgeeK4P6hQDU7LJ0CIxEXmHlpfjZqQFk mQnA== X-Gm-Message-State: AOJu0YziMQ8RDsKKoWFmbUAlNE/qOSqGoggiQ/Usn1RfAmS7rO40jAx5 IRoTJ/SF4b/dAdAkImeElFkbVT9SM9xFLW0INAKMSsEjgKChoLLFHUuo9lRdcH0/+Zq9InzmyTT Hpe0VpcVLtdoumYlwFcfOESeuw6quN8y8elXkM59Od2DBJNIojLYz10kd+uMck9wA7nQWvvD7VG jYdsc83ESalCwVzy84P+xHjpQpUWjO8vJuq2e4nj6W X-Received: by 2002:a17:90a:fd8f:b0:298:bce9:47b4 with SMTP id cx15-20020a17090afd8f00b00298bce947b4mr184663pjb.48.1709251770067; Thu, 29 Feb 2024 16:09:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IERHxPfv9d8u8lihMLju6XNxiBh/IFmk8GUyEbGAtKP1rd8M2+MxlpP/jDEXN3u5Kw6sYaJ3q7p0dJXUtPlfZA= X-Received: by 2002:a17:90a:fd8f:b0:298:bce9:47b4 with SMTP id cx15-20020a17090afd8f00b00298bce947b4mr184626pjb.48.1709251769427; Thu, 29 Feb 2024 16:09:29 -0800 (PST) MIME-Version: 1.0 References: <87o7di6e8h.fsf@redhat.com> <20240119050923.2502614-1-amerey@redhat.com> In-Reply-To: From: Aaron Merey Date: Thu, 29 Feb 2024 19:09:18 -0500 Message-ID: Subject: [PING*3][PATCH 2/4 v3] gdb/progspace: Add reverse safe iterator To: Andrew Burgess Cc: gdb-patches@sourceware.org, Thiago Jung Bauermann X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-14.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, RCVD_IN_SORBS_WEB, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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 Ping. Ready to be pushed to master? Thanks, Aaron On Thu, Feb 22, 2024 at 5:22=E2=80=AFPM Aaron Merey wro= te: > > Ping. Ready to be pushed to master? > > Aaron > > On Wed, Feb 7, 2024 at 4:24=E2=80=AFPM Aaron Merey wr= ote: > > > > Ping > > > > Thanks, > > Aaron > > > > On Fri, Jan 19, 2024 at 12:09=E2=80=AFAM Aaron Merey wrote: > > > > > > Hi Andrew, > > > > > > Thanks for the review. > > > > > > On Thu, Jan 18, 2024 at 7:03=E2=80=AFAM Andrew Burgess wrote: > > > > > > > > Aaron Merey writes: > > > > > +using qf_list =3D std::forward_list; > > > > > +using qf_range =3D iterator_range; > > > > > +using qf_safe_range =3D basic_safe_range; > > > > > + > > > > > /* Sections in an objfile. The section offsets are stored in th= e > > > > > OBJFILE. */ > > > > > > > > > > @@ -764,6 +770,10 @@ struct objfile > > > > > reader. */ > > > > > std::forward_list qf; > > > > > > > > I think this should be updated to use qf_list. > > > > > > Done. > > > > > > > > --- a/gdb/symfile-debug.c > > > > > +++ b/gdb/symfile-debug.c > > > > > @@ -85,7 +85,7 @@ objfile::has_partial_symbols () > > > > > them, then that is an indication that they are in fact avai= lable. 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_safe ()) > > > > > > > > I read the commit message a couple of times, but I'm still not 100%= sure > > > > I understand what's happening here. Is the change from qf -> qf_sa= fe() > > > > because calling (in this case has_symbols()) might download the ful= l > > > > debug info, and in doing do, might delete a previously downloaded > > > > .debug_info section? > > > > > > quick_functions_up made from a separately downloaded .gdb_index is at > > > first associated with the parent objfile (i.e. the objfile of the sha= red > > > library containing a .gnu_debuglink that refers to the separate debug= info > > > which actually contains this .gdb_index section). > > > > > > When the separate debuginfo is downloaded (possibly during iteration > > > over the parent's qf_list), we need to remove the gdb_index qf from > > > the parent's qf_list. This prevents gdb from later attempting to rea= d > > > the parent objfile for debug info that is actually in the correspondi= ng > > > separate debug objfile. > > > > > > > If this is the case then is it true that we will almost never want = to > > > > iterate over `qf` directly as most quick_symbol_functions methods m= ight > > > > result in this download/delete behaviour? > > > > > > > > If I'm right, then I think it might be useful to place a warning in= the > > > > comment before `qf` explaining this. > > > > > > Done. > > > > > > > > +/* A reverse basic_safe_iterator. See basic_safe_iterator for i= ntended use. */ > > > > > + > > > > > +template > > > > > +class basic_safe_reverse_iterator > > > > > +{ > > > > > +public: > > > > > + typedef basic_safe_reverse_iterator self_type; > > > > > + typedef typename Iterator::value_type value_type; > > > > > + typedef typename Iterator::reference reference; > > > > > + typedef typename Iterator::pointer pointer; > > > > > + typedef typename Iterator::iterator_category iterator_category= ; > > > > > + typedef typename Iterator::difference_type difference_type; > > > > > + > > > > > + /* Construct the iterator using ARG, and construct the end ite= rator > > > > > + using ARG2. */ > > > > > > > > Maybe this is a standard thing, and I'm just showing my lack of > > > > experience, but, given the existence of methods like rbegin() and > > > > rend(), I think the comments here should be doing more to explain w= hat's > > > > expected of this input. > > > > > > > > Plus this comment seems confusing, though I can sort of see what it= 's > > > > trying to say. > > > > > > > > We're creating a *_iterator object, which itself contains other > > > > iterators. We need to be super clear which particular "iterator" w= e're > > > > talking about in the comments. > > > > > > > > Also, I think we need to be explicit that for this reverse iterator= , the > > > > first argument to the constructor is going to be the LAST element t= hat > > > > is iterated over. One might be tempted to think that a safe revers= e iterator > > > > should be initialised with rbegin() and rend(), which isn't going t= o be > > > > correct (unless I'm not understand, please correct me if so). > > > > > > That's right, the arguments to basic_safe_reverse_iterator should be > > > forward iterators. This will not work with reverse iterators. > > > > > > I added more information to this comment to hopefully clear up any > > > confusion. > > > > > > > > + > > > > > +/* A range adapter that wraps a forward range, and then returns > > > > > + safe reverse iterators wrapping the original range's iterator= s. */ > > > > > > > > I think the fact that this takes a FORWARD range is really importan= t, > > > > and we should do more to advertise this. E.g. I think there should= be a > > > > comment on the constructor saying that RANGE is a forward range ove= r > > > > which we will iterate backwards. > > > > > > > > > > Done. The updated patch is included below. > > > > > > Aaron > > > > > > Commit message: > > > > > > This patch changes progspace objfile_list insertion so that separate > > > debug objfiles are placed into the list after the parent objfile, > > > instead of before. Additionally qf_require_partial_symbols now retur= ns > > > a safe_range. > > > > > > These changes are intended to prepare gdb for on-demand debuginfo > > > downloading and the downloading of .gdb_index sections. > > > > > > With on-demand downloading enabled, gdb might need to delete a > > > .gdb_index quick_symbol_functions from a parent objfile while looping > > > the objfile's list of quick_symbol_functions because the separate > > > debug objfile has just been downloaded. The use of a safe_range > > > prevents this removal from causing iterator invalidation. > > > > > > gdb might also download a debuginfo file during symtab expansion. > > > In this case an objfile will be added to the current progspace's > > > objfiles_list during iteration over the list (for example, in > > > iterate_over_symtabs). We want these loops to also iterate over > > > newly downloaded objfiles. So objfiles need to be inserted into > > > objfiles_list after their parent since it is during the search of > > > the parent objfile for some symbol or filename that the separate > > > debug objfile might be downloaded. > > > > > > To facilitate the safe deletion of objfiles, this patch also adds > > > basic_safe_reverse_range and basic_safe_reverse_iterator. This allow= s > > > objfiles to be removed from the objfiles_list in a loop without itera= tor > > > invalidation. > > > > > > If a forward safe iterator were to be used, the deletion of an > > > objfile could invalidate the safe iterator's reference to the next > > > objfile in the objfiles_list. This can happen when the deletion > > > of an objfile causes the deletion of a separate debug objfile that > > > happens to the be next element in the objfiles_list. > > > > > > The standard reverse iterator is not suitable for safe objfile deleti= on. > > > In order to safely delete the first objfile in the objfiles_list, the > > > standard reverse iterator's underlying begin iterator would have to b= e > > > decremented, resulting in undefined behavior. > > > > > > A small change was also made to a testcase in py-objfile.exp to > > > account for the new placement of separate debug objfiles in > > > objfiles_list. > > > --- > > > gdb/jit.c | 7 +- > > > gdb/objfiles.c | 14 +-- > > > gdb/objfiles.h | 17 +++- > > > gdb/progspace.c | 19 +++- > > > gdb/progspace.h | 31 ++++--- > > > gdb/symfile-debug.c | 34 +++---- > > > gdb/testsuite/gdb.python/py-objfile.exp | 2 +- > > > gdbsupport/safe-iterator.h | 115 ++++++++++++++++++++++= ++ > > > 8 files changed, 195 insertions(+), 44 deletions(-) > > > > > > diff --git a/gdb/jit.c b/gdb/jit.c > > > index 85a10be3055..10ee5f9b749 100644 > > > --- a/gdb/jit.c > > > +++ b/gdb/jit.c > > > @@ -1240,11 +1240,10 @@ jit_breakpoint_re_set (void) > > > static void > > > jit_inferior_exit_hook (struct inferior *inf) > > > { > > > - for (objfile *objf : current_program_space->objfiles_safe ()) > > > + current_program_space->unlink_objfiles_if ([&] (const objfile *obj= f) > > > { > > > - if (objf->jited_data !=3D nullptr && objf->jited_data->addr != =3D 0) > > > - objf->unlink (); > > > - } > > > + return (objf->jited_data !=3D nullptr) && (objf->jited_data->a= ddr !=3D 0); > > > + }); > > > } > > > > > > void > > > diff --git a/gdb/objfiles.c b/gdb/objfiles.c > > > index 8f085b1bb7c..d53dfaca90b 100644 > > > --- a/gdb/objfiles.c > > > +++ b/gdb/objfiles.c > > > @@ -470,6 +470,12 @@ objfile::unlink () > > > current_program_space->remove_objfile (this); > > > } > > > > > > +qf_safe_range > > > +objfile::qf_safe () > > > +{ > > > + return qf_safe_range (qf_range (qf.begin (), qf.end ())); > > > +} > > > + > > > /* Free all separate debug objfile of OBJFILE, but don't free OBJFIL= E > > > itself. */ > > > > > > @@ -793,14 +799,12 @@ have_full_symbols (void) > > > void > > > objfile_purge_solibs (void) > > > { > > > - for (objfile *objf : current_program_space->objfiles_safe ()) > > > + current_program_space->unlink_objfiles_if ([&] (const objfile *obj= f) > > > { > > > /* We assume that the solib package has been purged already, o= r will > > > be soon. */ > > > - > > > - if (!(objf->flags & OBJF_USERLOADED) && (objf->flags & OBJF_SH= ARED)) > > > - objf->unlink (); > > > - } > > > + return !(objf->flags & OBJF_USERLOADED) && (objf->flags & OBJF= _SHARED); > > > + }); > > > } > > > > > > > > > diff --git a/gdb/objfiles.h b/gdb/objfiles.h > > > index 621342d22b7..b917886988d 100644 > > > --- a/gdb/objfiles.h > > > +++ b/gdb/objfiles.h > > > @@ -370,6 +370,12 @@ class separate_debug_iterator > > > > > > typedef iterator_range separate_debug_range= ; > > > > > > +/* See objfile::qf_safe. */ > > > + > > > +using qf_list =3D std::forward_list; > > > +using qf_range =3D iterator_range; > > > +using qf_safe_range =3D basic_safe_range; > > > + > > > /* Sections in an objfile. The section offsets are stored in the > > > OBJFILE. */ > > > > > > @@ -761,8 +767,15 @@ struct objfile > > > const struct sym_fns *sf =3D nullptr; > > > > > > /* The "quick" (aka partial) symbol functions for this symbol > > > - reader. */ > > > - std::forward_list qf; > > > + 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 qf; > > > + > > > + /* Returns an iterable object that allows for safe deletion during > > > + iteration. See gdbsupport/safe-iterator.h. */ > > > + qf_safe_range qf_safe (); > > > > > > /* Per objfile data-pointers required by other GDB modules. */ > > > > > > diff --git a/gdb/progspace.c b/gdb/progspace.c > > > index 0fc1fdd57ab..c4cc2e2e8af 100644 > > > --- a/gdb/progspace.c > > > +++ b/gdb/progspace.c > > > @@ -141,19 +141,19 @@ program_space::free_all_objfiles () > > > > > > void > > > program_space::add_objfile (std::unique_ptr &&objfile, > > > - struct objfile *before) > > > + struct objfile *after) > > > { > > > - if (before =3D=3D nullptr) > > > + if (after =3D=3D nullptr) > > > objfiles_list.push_back (std::move (objfile)); > > > else > > > { > > > auto iter =3D std::find_if (objfiles_list.begin (), objfiles_l= ist.end (), > > > [=3D] (const std::unique_ptr<::objfil= e> &objf) > > > { > > > - return objf.get () =3D=3D before; > > > + return objf.get () =3D=3D after; > > > }); > > > gdb_assert (iter !=3D objfiles_list.end ()); > > > - objfiles_list.insert (iter, std::move (objfile)); > > > + objfiles_list.insert (++iter, std::move (objfile)); > > > } > > > } > > > > > > @@ -182,6 +182,17 @@ program_space::remove_objfile (struct objfile *o= bjfile) > > > > > > /* See progspace.h. */ > > > > > > +void > > > +program_space::unlink_objfiles_if > > > + (gdb::function_view predicate) > > > +{ > > > + for (auto &it : objfiles_safe ()) > > > + if (predicate (it.get ())) > > > + it->unlink (); > > > +} > > > + > > > +/* See progspace.h. */ > > > + > > > struct objfile * > > > program_space::objfile_for_address (CORE_ADDR address) > > > { > > > diff --git a/gdb/progspace.h b/gdb/progspace.h > > > index 163cbf6a0f8..f23a57dc842 100644 > > > --- a/gdb/progspace.h > > > +++ b/gdb/progspace.h > > > @@ -250,28 +250,32 @@ struct program_space > > > unwrapping_objfile_iterator (objfiles_list.end ())); > > > } > > > > > > - using objfiles_safe_range =3D basic_safe_range; > > > + using objfiles_it_range =3D iterator_range= ; > > > + using objfiles_safe_reverse_range > > > + =3D basic_safe_reverse_range; > > > > > > /* An iterable object that can be used to iterate over all objfile= s. > > > The basic use is in a foreach, like: > > > > > > for (objfile *objf : pspace->objfiles_safe ()) { ... } > > > > > > - This variant uses a basic_safe_iterator so that objfiles can be > > > - deleted during iteration. */ > > > - objfiles_safe_range objfiles_safe () > > > + This variant uses a basic_safe_reverse_iterator so that objfile= s > > > + can be deleted during iteration. > > > + > > > + The use of a reverse iterator helps ensure that separate debug > > > + objfiles are deleted before their parent objfile. This prevent= s > > > + iterator invalidation due to the deletion of a parent objfile. = */ > > > + objfiles_safe_reverse_range objfiles_safe () > > > { > > > - return objfiles_safe_range > > > - (objfiles_range > > > - (unwrapping_objfile_iterator (objfiles_list.begin ()), > > > - unwrapping_objfile_iterator (objfiles_list.end ()))); > > > + return objfiles_safe_reverse_range > > > + (objfiles_it_range (objfiles_list.begin (), objfiles_list.end = ())); > > > } > > > > > > - /* Add OBJFILE to the list of objfiles, putting it just before > > > - BEFORE. If BEFORE is nullptr, it will go at the end of the > > > + /* Add OBJFILE to the list of objfiles, putting it just after > > > + AFTER. If AFTER is nullptr, it will go at the end of the > > > list. */ > > > void add_objfile (std::unique_ptr &&objfile, > > > - struct objfile *before); > > > + struct objfile *after); > > > > > > /* Remove OBJFILE from the list of objfiles. */ > > > void remove_objfile (struct objfile *objfile); > > > @@ -286,6 +290,11 @@ struct program_space > > > /* Free all the objfiles associated with this program space. */ > > > void free_all_objfiles (); > > > > > > + /* Unlink all objfiles associated with this program space for whic= h > > > + PREDICATE evaluates to true. */ > > > + void unlink_objfiles_if > > > + (gdb::function_view predicate); > > > + > > > /* Return the objfile containing ADDRESS, or nullptr if the addres= s > > > is outside all objfiles in this progspace. */ > > > struct objfile *objfile_for_address (CORE_ADDR address); > > > diff --git a/gdb/symfile-debug.c b/gdb/symfile-debug.c > > > index 32c3ed9d349..c684f9cdd43 100644 > > > --- a/gdb/symfile-debug.c > > > +++ b/gdb/symfile-debug.c > > > @@ -85,7 +85,7 @@ objfile::has_partial_symbols () > > > them, then that is an indication that they are in fact availabl= e. Without > > > this function the symbols may have been already read in but the= y also may > > > not be present in this objfile. */ > > > - for (const auto &iter : qf) > > > + for (const auto &iter : qf_safe ()) > > > { > > > retval =3D iter->has_symbols (this); > > > if (retval) > > > @@ -108,7 +108,7 @@ objfile::has_unexpanded_symtabs () > > > objfile_debug_name (this)); > > > > > > bool result =3D false; > > > - for (const auto &iter : qf) > > > + for (const auto &iter : qf_safe ()) > > > { > > > if (iter->has_unexpanded_symtabs (this)) > > > { > > > @@ -133,7 +133,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_safe ()) > > > { > > > retval =3D iter->find_last_source_symtab (this); > > > if (retval !=3D nullptr) > > > @@ -166,7 +166,7 @@ objfile::forget_cached_source_info () > > > } > > > } > > > > > > - for (const auto &iter : qf) > > > + for (const auto &iter : qf_safe ()) > > > iter->forget_cached_source_info (this); > > > } > > > > > > @@ -213,7 +213,7 @@ objfile::map_symtabs_matching_filename > > > return result; > > > }; > > > > > > - for (const auto &iter : qf) > > > + for (const auto &iter : qf_safe ()) > > > { > > > if (!iter->expand_symtabs_matching (this, > > > match_one_filename, > > > @@ -278,7 +278,7 @@ objfile::lookup_symbol (block_enum kind, const ch= ar *name, domain_enum domain) > > > return true; > > > }; > > > > > > - for (const auto &iter : qf) > > > + for (const auto &iter : qf_safe ()) > > > { > > > if (!iter->expand_symtabs_matching (this, > > > nullptr, > > > @@ -309,7 +309,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_safe ()) > > > iter->print_stats (this, print_bcache); > > > } > > > > > > @@ -320,7 +320,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_safe ()) > > > iter->dump (this); > > > } > > > > > > @@ -335,7 +335,7 @@ objfile::expand_symtabs_for_function (const char = *func_name) > > > lookup_name_info base_lookup (func_name, symbol_name_match_type::F= ULL); > > > lookup_name_info lookup_name =3D base_lookup.make_ignore_params ()= ; > > > > > > - for (const auto &iter : qf) > > > + for (const auto &iter : qf_safe ()) > > > iter->expand_symtabs_matching (this, > > > nullptr, > > > &lookup_name, > > > @@ -354,7 +354,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_safe ()) > > > iter->expand_all_symtabs (this); > > > } > > > > > > @@ -372,7 +372,7 @@ objfile::expand_symtabs_with_fullname (const char= *fullname) > > > return filename_cmp (basenames ? basename : fullname, filename) = =3D=3D 0; > > > }; > > > > > > - for (const auto &iter : qf) > > > + for (const auto &iter : qf_safe ()) > > > iter->expand_symtabs_matching (this, > > > file_matcher, > > > nullptr, > > > @@ -406,7 +406,7 @@ objfile::expand_symtabs_matching > > > host_address_to_string (&expansion_notify), > > > search_domain_name (kind)); > > > > > > - for (const auto &iter : qf) > > > + for (const auto &iter : qf_safe ()) > > > if (!iter->expand_symtabs_matching (this, file_matcher, lookup_n= ame, > > > symbol_matcher, expansion_not= ify, > > > search_flags, domain, kind)) > > > @@ -431,7 +431,7 @@ objfile::find_pc_sect_compunit_symtab (struct bou= nd_minimal_symbol msymbol, > > > host_address_to_string (section), > > > warn_if_readin); > > > > > > - for (const auto &iter : qf) > > > + for (const auto &iter : qf_safe ()) > > > { > > > retval =3D iter->find_pc_sect_compunit_symtab (this, msymbol, = pc, section, > > > warn_if_readin); > > > @@ -459,7 +459,7 @@ objfile::map_symbol_filenames (gdb::function_view= fun, > > > objfile_debug_name (this), > > > need_fullname); > > > > > > - for (const auto &iter : qf) > > > + for (const auto &iter : qf_safe ()) > > > iter->map_symbol_filenames (this, fun, need_fullname); > > > } > > > > > > @@ -471,7 +471,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_safe ()) > > > iter->compute_main_name (this); > > > } > > > > > > @@ -485,7 +485,7 @@ objfile::find_compunit_symtab_by_address (CORE_AD= DR address) > > > hex_string (address)); > > > > > > struct compunit_symtab *result =3D NULL; > > > - for (const auto &iter : qf) > > > + for (const auto &iter : qf_safe ()) > > > { > > > result =3D iter->find_compunit_symtab_by_address (this, addres= s); > > > if (result !=3D nullptr) > > > @@ -510,7 +510,7 @@ objfile::lookup_global_symbol_language (const cha= r *name, > > > enum language result =3D language_unknown; > > > *symbol_found_p =3D false; > > > > > > - for (const auto &iter : qf) > > > + for (const auto &iter : qf_safe ()) > > > { > > > result =3D iter->lookup_global_symbol_language (this, name, do= main, > > > symbol_found_p); > > > diff --git a/gdb/testsuite/gdb.python/py-objfile.exp b/gdb/testsuite/= gdb.python/py-objfile.exp > > > index 61b9942de79..0bf49976b73 100644 > > > --- a/gdb/testsuite/gdb.python/py-objfile.exp > > > +++ b/gdb/testsuite/gdb.python/py-objfile.exp > > > @@ -135,7 +135,7 @@ gdb_test "p main" "=3D {} $hex
" \ > > > gdb_py_test_silent_cmd "python objfile.add_separate_debug_file(\"${b= infile}\")" \ > > > "Add separate debug file file" 1 > > > > > > -gdb_py_test_silent_cmd "python sep_objfile =3D gdb.objfiles()\[0\]" = \ > > > +gdb_py_test_silent_cmd "python sep_objfile =3D gdb.objfiles()\[1\]" = \ > > > "Get separate debug info objfile" 1 > > > > > > gdb_test "python print (sep_objfile.owner.filename)" "${testfile}2" = \ > > > diff --git a/gdbsupport/safe-iterator.h b/gdbsupport/safe-iterator.h > > > index b4891328f1a..d1b9ce21ffc 100644 > > > --- a/gdbsupport/safe-iterator.h > > > +++ b/gdbsupport/safe-iterator.h > > > @@ -136,4 +136,119 @@ class basic_safe_range > > > Range m_range; > > > }; > > > > > > +/* A reverse basic_safe_iterator. See basic_safe_iterator for inten= ded use. */ > > > + > > > +template > > > +class basic_safe_reverse_iterator > > > +{ > > > +public: > > > + typedef basic_safe_reverse_iterator self_type; > > > + typedef typename Iterator::value_type value_type; > > > + typedef typename Iterator::reference reference; > > > + typedef typename Iterator::pointer pointer; > > > + typedef typename Iterator::iterator_category iterator_category; > > > + typedef typename Iterator::difference_type difference_type; > > > + > > > + /* Construct the iterator using ARG, and construct the end iterato= r > > > + using ARG2. ARG and ARG2 should be forward iterators, typicall= y > > > + from begin and end methods, respectively. > > > + > > > + For example if ARG1 is created with container.begin and ARG2 is > > > + is created with container.end, then the basic_safe_reverse_iter= ator > > > + will traverse from the last element in the container to the fir= st > > > + element in the container. */ > > > + template > > > + explicit basic_safe_reverse_iterator (Arg &&arg, Arg &&arg2) > > > + : m_begin (std::forward (arg)), > > > + m_end (std::forward (arg2)), > > > + m_it (m_end), > > > + m_next (m_end) > > > + { > > > + /* M_IT and M_NEXT are initialized as one-past-end. Set M_IT to= point > > > + to the last element and set M_NEXT to point to the second las= t element, > > > + if such elements exist. */ > > > + if (m_it !=3D m_begin) > > > + { > > > + --m_it; > > > + > > > + if (m_it !=3D m_begin) > > > + { > > > + --m_next; > > > + --m_next; > > > + } > > > + } > > > + } > > > + > > > + typename std::invoke_result::type > > > + operator* () const > > > + { return *m_it; } > > > + > > > + self_type &operator++ () > > > + { > > > + m_it =3D m_next; > > > + > > > + if (m_it !=3D m_end) > > > + { > > > + /* Use M_BEGIN only if we sure that it is valid. */ > > > + if (m_it =3D=3D m_begin) > > > + m_next =3D m_end; > > > + else > > > + --m_next; > > > + } > > > + > > > + return *this; > > > + } > > > + > > > + bool operator=3D=3D (const self_type &other) const > > > + { return m_it =3D=3D other.m_it; } > > > + > > > + bool operator!=3D (const self_type &other) const > > > + { return m_it !=3D other.m_it; } > > > + > > > +private: > > > + /* The first element. */ > > > + Iterator m_begin {}; > > > + > > > + /* A one-past-end iterator. */ > > > + Iterator m_end {}; > > > + > > > + /* The current element. */ > > > + Iterator m_it {}; > > > + > > > + /* The next element. Always one element ahead of M_IT. */ > > > + Iterator m_next {}; > > > +}; > > > + > > > +/* A range adapter that wraps a forward range, and then returns > > > + safe reverse iterators wrapping the original range's iterators. = */ > > > + > > > +template > > > +class basic_safe_reverse_range > > > +{ > > > +public: > > > + > > > + typedef basic_safe_reverse_iterator iter= ator; > > > + > > > + /* RANGE must be a forward range. basic_safe_reverse_iterators > > > + will be used to traverse the forward range from the last elemen= t > > > + to the first. */ > > > + explicit basic_safe_reverse_range (Range range) > > > + : m_range (range) > > > + { > > > + } > > > + > > > + iterator begin () > > > + { > > > + return iterator (m_range.begin (), m_range.end ()); > > > + } > > > + > > > + iterator end () > > > + { > > > + return iterator (m_range.end (), m_range.end ()); > > > + } > > > + > > > +private: > > > + > > > + Range m_range; > > > +}; > > > #endif /* COMMON_SAFE_ITERATOR_H */ > > > -- > > > 2.43.0 > > >