From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29011 invoked by alias); 7 Jan 2013 16:23:32 -0000 Received: (qmail 29002 invoked by uid 22791); 7 Jan 2013 16:23:29 -0000 X-SWARE-Spam-Status: No, hits=-4.1 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,KHOP_THREADED,MSGID_FROM_MTA_HEADER,RCVD_IN_HOSTKARMA_W,RCVD_IN_HOSTKARMA_WL,RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from e06smtp12.uk.ibm.com (HELO e06smtp12.uk.ibm.com) (195.75.94.108) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 07 Jan 2013 16:23:22 +0000 Received: from /spool/local by e06smtp12.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 7 Jan 2013 16:22:27 -0000 Received: from b06cxnps4076.portsmouth.uk.ibm.com (9.149.109.198) by e06smtp12.uk.ibm.com (192.168.101.142) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 7 Jan 2013 16:22:24 -0000 Received: from d06av02.portsmouth.uk.ibm.com (d06av02.portsmouth.uk.ibm.com [9.149.37.228]) by b06cxnps4076.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r07GN9aq37290060 for ; Mon, 7 Jan 2013 16:23:09 GMT Received: from d06av02.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av02.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r07GNEBV015870 for ; Mon, 7 Jan 2013 09:23:16 -0700 Received: from tuxmaker.boeblingen.de.ibm.com (tuxmaker.boeblingen.de.ibm.com [9.152.85.9]) by d06av02.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with SMTP id r07GNBP3015665; Mon, 7 Jan 2013 09:23:11 -0700 Message-Id: <201301071623.r07GNBP3015665@d06av02.portsmouth.uk.ibm.com> Received: by tuxmaker.boeblingen.de.ibm.com (sSMTP sendmail emulation); Mon, 07 Jan 2013 17:23:11 +0100 Subject: Re: [PATCH] Vector to scalar casting and widening To: aburgess@broadcom.com (Andrew Burgess) Date: Mon, 07 Jan 2013 16:23:00 -0000 From: "Ulrich Weigand" Cc: tromey@redhat.com, gdb-patches@sourceware.org, ken@linux.vnet.ibm.com In-Reply-To: <50E6EB05.8010600@broadcom.com> from "Andrew Burgess" at Jan 04, 2013 02:45:25 PM MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit x-cbid: 13010716-8372-0000-0000-000004CEAAF1 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: 2013-01/txt/msg00111.txt.bz2 Andrew Burgess wrote: > In addressing the two problems you pointed out above, I first created a > new function opencl_value_cast, which I use throughout opencl-lang.c, > however, a quick grep of the codebase shows other places that call > value_cast, for example, within the varobj.c code. I suspect that > creating an opencl_value_cast function will mean that I am introducing > bugs when, for example, we create varobj objects for opencl code. > > The first issue you pointed out above "vector scalar" seems even > harder to fix. The current problem with my patch is that I call > value_vector_widen from value_binop, which will error if the scalar > value is truncated when casting to the vector type. For OpenCL this is > the wrong thing to do. I don't want to add an "if (language == opencl)" > switch to value_binop, and value_binop is called extensively throughout > the codebase. This would suggest then that it is value_vector_widen > that should change, however, this feels very much like the original > patch to which you objected. > > So, to summarise the problem as I see it, your suggested solution was to > filter the different behaviours within opencl-lang.c, however, the > problem behaviours live within value_cast and value_binop, both of which > I believe are called from core gdb code, not just from opencl-lang.c, I > therefore believe there's no reliable way to intercept all calls to > these functions. I don't actually think you need (or even *should*) intercept all such calls. Taking a step back, the underlying problem is that GDB supports operating on expressions in various different languages that all have their own special rules on how to perform certain operations, but maps them all to a single GDB "value" type, with a single set of operations on them. My understanding of how this is supposed to work out is that GDB "value" operations *do not* actually implement the precise semantics of any of the languages GDB supports; rather, they implement a GDB private semantics of "GDB value" objects. Now, as those are private to GDB, we are free to implement them however we wish; for pragmatic and historical reasons, they do mostly (but not completely!) match C semantics. When evaluating language expressions, the eval* routines are free to use value_* operations directly **when their semantics match the language semantics**, but must use a different implementation when the language requires special semantics. (Note how e.g. the particular C type promotions rules for binary operations are *not* implemented in value_binop, but are handled specially in the C expression evaluation code.) [ For historical reasons, some of the value_* operations currently change aspects of their behaviour depending on current_language. This is really a bug, and we ought to (and slowly do) move away from this. For example, in a program employing multiple languages simultaneously, GDB value objects might have been created from values in a different language than the "current" one. ] Now, as you point out, value_* operations are also used throughout the rest of GDB (not part of expression evaluation). This is fine, as long as those parts **do not assume they follow any particular language semantics, but rather the generic GDB value semantics**. In general, I think this is in fact the case. For example, the value_cast uses in varobj.c you mention appear to only rely on common properties of the GDB value semantics (casting C++ objects between base and derived types). If there are indeed instances of value_ operations that assume specific C (or OpenCL) semantics, those would have to be fixed. [ In particular for OpenCL, I'm quite sure that no-one outside of opencl-lang.c relies on any particular OpenCL semantics of the value_ operations. ] > I'd like to put two other possible solutions on the table (they are > really just variations on the same theme), these would be (1) go back to > my original flag on the language structure, handle all the different > variations within value_cast or value_vector_widen, or (2) have a set of > "vector_ops" function pointers on the language structure, currently > there would be just two, "scalar_to_vector_widen" and > "scalar_to_vector_cast". The defaults would be standard gcc C behaviour > implemented in (probably) valops.c, while opencl would provide its own > within opencl-lang.c. Both of these would go back to make value_ operations change their behaviour depending on a language, which goes against the general direction I've outlined above ... Bye, Ulrich -- Dr. Ulrich Weigand GNU Toolchain for Linux on System z and Cell BE Ulrich.Weigand@de.ibm.com