From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11424 invoked by alias); 3 Jul 2007 19:26:06 -0000 Received: (qmail 11407 invoked by uid 22791); 3 Jul 2007 19:26:05 -0000 X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (65.74.133.4) by sourceware.org (qpsmtpd/0.31) with ESMTP; Tue, 03 Jul 2007 19:25:59 +0000 Received: (qmail 14612 invoked from network); 3 Jul 2007 19:25:57 -0000 Received: from unknown (HELO localhost) (jimb@127.0.0.2) by mail.codesourcery.com with ESMTPA; 3 Jul 2007 19:25:57 -0000 To: Mark Kettenis Cc: drow@false.org, msnyder@sonic.net, gdb-patches@sourceware.org, gaius@glam.ac.uk Subject: Re: [RFC] logic change in m2-valprint.c References: <16087.12.7.175.2.1183076995.squirrel@webmail.sonic.net> <20070701154831.GE10872@caradoc.them.org> <004a01c7bbf8$16a2ccc0$677ba8c0@sonic.net> <20070701160224.GH10872@caradoc.them.org> <9624.12.7.175.2.1183421112.squirrel@webmail.sonic.net> <20070703011147.GA26350@caradoc.them.org> <200707030741.l637fhwb007184@brahms.sibelius.xs4all.nl> From: Jim Blandy Date: Tue, 03 Jul 2007 19:26:00 -0000 In-Reply-To: <200707030741.l637fhwb007184@brahms.sibelius.xs4all.nl> (Mark Kettenis's message of "Tue, 3 Jul 2007 09:41:43 +0200 (CEST)") Message-ID: User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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: 2007-07/txt/msg00077.txt.bz2 Mark Kettenis writes: >> Date: Mon, 2 Jul 2007 21:11:47 -0400 >> From: Daniel Jacobowitz >> >> On Mon, Jul 02, 2007 at 05:05:12PM -0700, Michael Snyder wrote: >> > is nowhere else for it to be set false), and there is no second >> > time -- we will never enter this block again because we will set >> > "element_seen" to true (and there is nowhere else for it to be >> > set false again). >> > >> > Was that clear? >> >> Clear, but not right. >> >> 152 element_seen = 0; >> >> On entry, empty_set = 1 and element_seen = 0. We see an element, >> which causes us set empty_set = 0 and element_seen = 1. Then we see a >> clear bit in the set and set element_seen to 0 and not change >> empty_set. Then we see a set bit, and element_seen == 0 with >> empty_set == 0. We print the comma. >> >> I would test it, but I don't have an M-2 compiler and the expression >> parser can't create sets. Am I missing something? > > Dunno, but it is obvious that this bit of code is in need of a rewrite. Yeah. There's actually a nested loop there, but it's not easy to see. And the name 'empty_set' suggests something one can't know until the traversal is complete... I should stay away from 'beautiful code' contents, but is this any better? static void m2_print_long_set (struct type *type, const gdb_byte *valaddr, int embedded_offset, CORE_ADDR address, struct ui_file *stream, int format, enum val_prettyprint pretty) { int field, len; LONGEST low_bound, high_bound; int printed_any = 0; struct type *target = NULL; /* We want to print runs of members using the '1..10' notation, but we don't know when a run has ended until we see a zero bit. We set run_pending when we see what may be the start of a run; when run_pending is set, run_low and run_high record the known extent of the run. */ int run_pending = 0; LONGEST run_low = 0; LONGEST run_high = 0; CHECK_TYPEDEF (type); if (! get_long_set_bounds (type, &low_bound, &high_bound)) { fprintf_filtered (stream, "{ %s }", _("")); return; } /* Walk the fields of the set, printing elements from each. */ fprintf_filtered (stream, "{"); len = TYPE_NFIELDS (type); for (field = TYPE_N_BASECLASSES (type); field < len; field++) { struct type *field_range; LONGEST field_range_low, field_range_high; int i; field_range = TYPE_INDEX_TYPE (TYPE_FIELD_TYPE (type, field)); if (get_discrete_bounds (field_range, &field_range_low, &field_range_high) < 0) break; target = TYPE_TARGET_TYPE (field_range); if (target == NULL) target = builtin_type_int; for (i = field_range_low; i <= field_range_high; i++) { int bitval = value_bit_index (TYPE_FIELD_TYPE (type, field), (TYPE_FIELD_BITPOS (type, field) / 8) + valaddr + embedded_offset, i); if (bitval < 0) error (_("bit test is out of range")); else if (bitval > 0) { if (run_pending) /* Extend the existing run. */ run_high = i; else { /* Start a new run. */ run_pending = 1; run_low = run_high = i; } /* We print things when we find the end of the run. */ } else { /* If we had a run going, we've now found its end, so print it. */ if (run_pending) { if (printed_any) fprintf_filtered (stream, ", "); print_type_scalar (target, run_low, stream); if (run_low < run_high) { fprintf_filtered (stream, ".."); print_type_scalar (target, run_high, stream); } run_pending = 0; printed_any = 1; } } } } /* Flush any pending range abutting the end of the set. */ if (run_pending) { if (printed_any) fprintf_filtered (stream, ", "); print_type_scalar (target, run_low, stream); if (run_low < run_high) { fprintf_filtered (stream, ".."); print_type_scalar (target, run_high, stream); } } fprintf_filtered (stream, "}"); }