From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23301 invoked by alias); 31 Aug 2008 17:52:20 -0000 Received: (qmail 23147 invoked by uid 22791); 31 Aug 2008 17:52:13 -0000 X-Spam-Check-By: sourceware.org Received: from mtagate3.de.ibm.com (HELO mtagate3.de.ibm.com) (195.212.29.152) by sourceware.org (qpsmtpd/0.31) with ESMTP; Sun, 31 Aug 2008 17:51:24 +0000 Received: from d12nrmr1607.megacenter.de.ibm.com (d12nrmr1607.megacenter.de.ibm.com [9.149.167.49]) by mtagate3.de.ibm.com (8.13.8/8.13.8) with ESMTP id m7VHpJ6s287330 for ; Sun, 31 Aug 2008 17:51:19 GMT Received: from d12av02.megacenter.de.ibm.com (d12av02.megacenter.de.ibm.com [9.149.165.228]) by d12nrmr1607.megacenter.de.ibm.com (8.13.8/8.13.8/NCO v9.0) with ESMTP id m7VHpISc1683692 for ; Sun, 31 Aug 2008 19:51:18 +0200 Received: from d12av02.megacenter.de.ibm.com (loopback [127.0.0.1]) by d12av02.megacenter.de.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id m7VHpIsl019992 for ; Sun, 31 Aug 2008 19:51:18 +0200 Received: from tuxmaker.boeblingen.de.ibm.com (tuxmaker.boeblingen.de.ibm.com [9.152.85.9]) by d12av02.megacenter.de.ibm.com (8.12.11.20060308/8.12.11) with ESMTP id m7VHpIb9019989 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Sun, 31 Aug 2008 19:51:18 +0200 Received: from tuxmaker.boeblingen.de.ibm.com (localhost.localdomain [127.0.0.1]) by tuxmaker.boeblingen.de.ibm.com (8.13.8/8.13.8) with ESMTP id m7VHpIul002301 for ; Sun, 31 Aug 2008 19:51:18 +0200 Received: (from uweigand@localhost) by tuxmaker.boeblingen.de.ibm.com (8.13.8/8.13.8/Submit) id m7VHpHfm002300 for gdb-patches@sourceware.org; Sun, 31 Aug 2008 19:51:17 +0200 Message-Id: <20080831175117.806311000@de.ibm.com> References: <20080831175045.128504000@de.ibm.com> User-Agent: quilt/0.46-1 Date: Sun, 31 Aug 2008 17:53:00 -0000 From: uweigand@de.ibm.com To: gdb-patches@sourceware.org Subject: [rfc][03/37] Eliminate builtin_type_ macros: Extract bitstring subscript handling Content-Disposition: inline; filename=diff-type-bitstring 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: 2008-08/txt/msg00702.txt.bz2 Hello, in preparation to removing use of the LA_BOOL_TYPE macro, this patch moves handling of TYPE_CODE_BITSTRING subscripts out of value_subscript into a new function value_bitstring_subscript that gets the boolean type requested by the caller as argument. Bye, Ulrich ChangeLog: * value.h (value_bitstring_subscript): New prototype. * valarith.h (value_bitstring_subscript): New function. (value_subscript): No longer handle TYPE_CODE_BITSTRING. * eval.c (evaluate_subexp_standard): Call value_bitstring_subscript instead of value_subscript to handle TYPE_CODE_BITSTRING. Index: gdb-head/gdb/eval.c =================================================================== --- gdb-head.orig/gdb/eval.c +++ gdb-head/gdb/eval.c @@ -1666,7 +1666,28 @@ evaluate_subexp_standard (struct type *e } else { - arg1 = value_subscript (arg1, arg2); + arg1 = coerce_ref (arg1); + type = check_typedef (value_type (arg1)); + + switch (TYPE_CODE (type)) + { + case TYPE_CODE_PTR: + case TYPE_CODE_ARRAY: + case TYPE_CODE_STRING: + arg1 = value_subscript (arg1, arg2); + break; + + case TYPE_CODE_BITSTRING: + arg1 = value_bitstring_subscript (LA_BOOL_TYPE, arg1, arg2); + break; + + default: + if (TYPE_NAME (type)) + error (_("cannot subscript something of type `%s'"), + TYPE_NAME (type)); + else + error (_("cannot subscript requested type")); + } } } return (arg1); Index: gdb-head/gdb/valarith.c =================================================================== --- gdb-head.orig/gdb/valarith.c +++ gdb-head/gdb/valarith.c @@ -218,34 +218,6 @@ value_subscript (struct value *array, st array = value_coerce_array (array); } - if (TYPE_CODE (tarray) == TYPE_CODE_BITSTRING) - { - struct type *range_type = TYPE_INDEX_TYPE (tarray); - LONGEST index = value_as_long (idx); - struct value *v; - int offset, byte, bit_index; - LONGEST lowerbound, upperbound; - get_discrete_bounds (range_type, &lowerbound, &upperbound); - if (index < lowerbound || index > upperbound) - error (_("bitstring index out of range")); - index -= lowerbound; - offset = index / TARGET_CHAR_BIT; - byte = *((char *) value_contents (array) + offset); - bit_index = index % TARGET_CHAR_BIT; - byte >>= (gdbarch_bits_big_endian (current_gdbarch) ? - TARGET_CHAR_BIT - 1 - bit_index : bit_index); - v = value_from_longest (LA_BOOL_TYPE, byte & 1); - set_value_bitpos (v, bit_index); - set_value_bitsize (v, 1); - VALUE_LVAL (v) = VALUE_LVAL (array); - if (VALUE_LVAL (array) == lval_internalvar) - VALUE_LVAL (v) = lval_internalvar_component; - VALUE_ADDRESS (v) = VALUE_ADDRESS (array); - VALUE_FRAME_ID (v) = VALUE_FRAME_ID (array); - set_value_offset (v, offset + value_offset (array)); - return v; - } - if (c_style) return value_ind (value_add (array, idx)); else @@ -286,6 +258,52 @@ value_subscripted_rvalue (struct value * set_value_offset (v, value_offset (array) + elt_offs); return v; } + +/* Return the value of BITSTRING[IDX] as (boolean) type TYPE. */ + +struct value * +value_bitstring_subscript (struct type *type, + struct value *bitstring, struct value *idx) +{ + + struct type *bitstring_type, *range_type; + LONGEST index = value_as_long (idx); + struct value *v; + int offset, byte, bit_index; + LONGEST lowerbound, upperbound; + + bitstring_type = check_typedef (value_type (bitstring)); + gdb_assert (TYPE_CODE (bitstring_type) == TYPE_CODE_BITSTRING); + + range_type = TYPE_INDEX_TYPE (bitstring_type); + get_discrete_bounds (range_type, &lowerbound, &upperbound); + if (index < lowerbound || index > upperbound) + error (_("bitstring index out of range")); + + index -= lowerbound; + offset = index / TARGET_CHAR_BIT; + byte = *((char *) value_contents (bitstring) + offset); + + bit_index = index % TARGET_CHAR_BIT; + byte >>= (gdbarch_bits_big_endian (current_gdbarch) ? + TARGET_CHAR_BIT - 1 - bit_index : bit_index); + + v = value_from_longest (type, byte & 1); + + set_value_bitpos (v, bit_index); + set_value_bitsize (v, 1); + + VALUE_LVAL (v) = VALUE_LVAL (bitstring); + if (VALUE_LVAL (bitstring) == lval_internalvar) + VALUE_LVAL (v) = lval_internalvar_component; + VALUE_ADDRESS (v) = VALUE_ADDRESS (bitstring); + VALUE_FRAME_ID (v) = VALUE_FRAME_ID (bitstring); + + set_value_offset (v, offset + value_offset (bitstring)); + + return v; +} + /* Check to see if either argument is a structure, or a reference to one. This is called so we know whether to go ahead with the normal Index: gdb-head/gdb/value.h =================================================================== --- gdb-head.orig/gdb/value.h +++ gdb-head/gdb/value.h @@ -405,6 +405,10 @@ extern struct value *value_repeat (struc extern struct value *value_subscript (struct value *array, struct value *idx); +extern struct value *value_bitstring_subscript (struct type *type, + struct value *bitstring, + struct value *idx); + extern struct value *register_value_being_returned (struct type *valtype, struct regcache *retbuf); -- Dr. Ulrich Weigand GNU Toolchain for Linux on System z and Cell BE Ulrich.Weigand@de.ibm.com