From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23543 invoked by alias); 24 Sep 2010 11:25:18 -0000 Received: (qmail 23518 invoked by uid 22791); 24 Sep 2010 11:25:16 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL,BAYES_00,TW_BJ,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (38.113.113.100) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 24 Sep 2010 11:25:11 +0000 Received: (qmail 3771 invoked from network); 24 Sep 2010 11:25:09 -0000 Received: from unknown (HELO orlando.localnet) (pedro@127.0.0.2) by mail.codesourcery.com with ESMTPA; 24 Sep 2010 11:25:09 -0000 From: Pedro Alves To: gdb-patches@sourceware.org Subject: Re: [PING]RE: [RFA] Fix maint translate command Date: Fri, 24 Sep 2010 15:55:00 -0000 User-Agent: KMail/1.13.2 (Linux/2.6.33-29-realtime; KDE/4.4.2; x86_64; ; ) Cc: Joel Brobecker , Pierre Muller References: <002101cb49b3$50d60cd0$f2822670$@muller@ics-cnrs.unistra.fr> <20100922170111.GE3063@adacore.com> <201009221959.03816.pedro@codesourcery.com> In-Reply-To: <201009221959.03816.pedro@codesourcery.com> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201009241225.05267.pedro@codesourcery.com> X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2010-09/txt/msg00433.txt.bz2 On Wednesday 22 September 2010 19:59:03, Pedro Alves wrote: > On Wednesday 22 September 2010 18:01:11, Joel Brobecker wrote: > > I think that this is a useful comment to add to the macro. And perhaps > > explain that the purpose is to allow `break' to exit the ALL_OBJSECTIONS > > (double-) loop. > > I'll extend the current comment in that direction. Done now. Tested on x86_64-unknown-linux-gnu and applied. -- Pedro Alves 2010-09-24 Pedro Alves * objfiles.h (ALL_OBJSECTIONS): Handle breaks in the inner loop. --- gdb/objfiles.h | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) Index: src/gdb/objfiles.h =================================================================== --- src.orig/gdb/objfiles.h 2010-09-24 10:22:44.000000000 +0100 +++ src/gdb/objfiles.h 2010-09-24 11:32:44.000000000 +0100 @@ -611,9 +611,44 @@ extern int gdb_bfd_close_or_warn (struct #define ALL_OBJFILE_OSECTIONS(objfile, osect) \ for (osect = objfile->sections; osect < objfile->sections_end; osect++) -#define ALL_OBJSECTIONS(objfile, osect) \ - ALL_OBJFILES (objfile) \ - ALL_OBJFILE_OSECTIONS (objfile, osect) +/* Traverse all obj_sections in all objfiles in the current program + space. + + Note that this detects a "break" in the inner loop, and exits + immediately from the outer loop as well, thus, client code doesn't + need to know that this is implemented with a double for. The extra + hair is to make sure that a "break;" stops the outer loop iterating + as well, and both OBJFILE and OSECT are left unmodified: + + - The outer loop learns about the inner loop's end condition, and + stops iterating if it detects the inner loop didn't reach its + end. In other words, the outer loop keeps going only if the + inner loop reached its end cleanly [(osect) == + (objfile)->sections_end]. + + - OSECT is initialized in the outer loop initialization + expressions, such as if the inner loop has reached its end, so + the check mentioned above succeeds the first time. + + - The trick to not clearing OBJFILE on a "break;" is, in the outer + loop's loop expression, advance OBJFILE, but iff the inner loop + reached its end. If not, there was a "break;", so leave OBJFILE + as is; the outer loop's conditional will break immediately as + well (as OSECT will be different from OBJFILE->sections_end). +*/ + +#define ALL_OBJSECTIONS(objfile, osect) \ + for ((objfile) = current_program_space->objfiles, \ + (objfile) != NULL ? ((osect) = (objfile)->sections_end) : 0; \ + (objfile) != NULL \ + && (osect) == (objfile)->sections_end; \ + ((osect) == (objfile)->sections_end \ + ? ((objfile) = (objfile)->next, \ + (objfile) != NULL ? (osect) = (objfile)->sections_end : 0) \ + : 0)) \ + for ((osect) = (objfile)->sections; \ + (osect) < (objfile)->sections_end; \ + (osect)++) #define SECT_OFF_DATA(objfile) \ ((objfile->sect_index_data == -1) \