From b46805224b81b08335947252fc23d474b4bbc0a0 Mon Sep 17 00:00:00 2001 From: Per Bothner Date: Tue, 19 Sep 1995 22:39:04 +0000 Subject: [PATCH] * gdbtypes.c (create_set_type): Set TYPE_LENGTH in bytes, not bits. * valops.c (value_bitstring): TYPE_LENGTH is bytes, not bits. * gdbtypes.c (force_to_range_type): Calculate upper limit of TYPE_CODE_CHAR depending on TYPE_LENGTH (instead of just using 255). --- gdb/ChangeLog | 8 ++++++++ gdb/gdbtypes.c | 6 +++--- gdb/valops.c | 22 ++++++++++++++++++---- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 7760952652..50de98f3c9 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,11 @@ +Tue Sep 19 15:28:58 1995 Per Bothner + + * gdbtypes.c (create_set_type): Set TYPE_LENGTH in bytes, not bits. + * valops.c (value_bitstring): TYPE_LENGTH is bytes, not bits. + + * gdbtypes.c (force_to_range_type): Calculate upper limit of + TYPE_CODE_CHAR depending on TYPE_LENGTH (instead of just using 255). + Mon Sep 18 01:43:42 1995 Jeff Law (law@snake.cs.utah.edu) * somsolib.c (auto_solib_add_at_startup): Delete definition. No diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index de3de3e6a1..ca27e4cebd 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -368,7 +368,8 @@ force_to_range_type (type) } case TYPE_CODE_CHAR: { - struct type *range_type = create_range_type (NULL, type, 0, 255); + int char_max = 1 << (TYPE_LENGTH (type) * HOST_CHAR_BIT) - 1; + struct type *range_type = create_range_type (NULL, type, 0, char_max); TYPE_NAME (range_type) = TYPE_NAME (range_type); TYPE_DUMMY_RANGE (range_type) = 1; return range_type; @@ -469,8 +470,7 @@ create_set_type (result_type, domain_type) high_bound = TYPE_HIGH_BOUND (domain_type); bit_length = high_bound - low_bound + 1; TYPE_LENGTH (result_type) - = ((bit_length + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT) - * TARGET_CHAR_BIT; + = (bit_length + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT; } TYPE_FIELD_TYPE (result_type, 0) = domain_type; return (result_type); diff --git a/gdb/valops.c b/gdb/valops.c index 79a72a3fd9..323f296540 100644 --- a/gdb/valops.c +++ b/gdb/valops.c @@ -16,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software -Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "defs.h" #include "symtab.h" @@ -577,6 +577,21 @@ Can't handle bitfield which doesn't fit in a single register."); error ("Left operand of assignment is not an lvalue."); } + /* If the field does not entirely fill a LONGEST, then zero the sign bits. + If the field is signed, and is negative, then sign extend. */ + if ((VALUE_BITSIZE (toval) > 0) + && (VALUE_BITSIZE (toval) < 8 * sizeof (LONGEST))) + { + LONGEST fieldval = value_as_long (fromval); + LONGEST valmask = (((unsigned LONGEST) 1) << VALUE_BITSIZE (toval)) - 1; + + fieldval &= valmask; + if (!TYPE_UNSIGNED (type) && (fieldval & (valmask ^ (valmask >> 1)))) + fieldval |= ~valmask; + + fromval = value_from_longest (type, fieldval); + } + /* Return a value just like TOVAL except with the contents of FROMVAL (except in the case of the type if TOVAL is an internalvar). */ @@ -586,8 +601,7 @@ Can't handle bitfield which doesn't fit in a single register."); type = VALUE_TYPE (fromval); } - val = allocate_value (type); - memcpy (val, toval, VALUE_CONTENTS_RAW (val) - (char *) val); + val = value_copy (toval); memcpy (VALUE_CONTENTS_RAW (val), VALUE_CONTENTS (fromval), TYPE_LENGTH (type)); VALUE_TYPE (val) = type; @@ -1404,7 +1418,7 @@ value_bitstring (ptr, len) struct type *type = create_set_type ((struct type*) NULL, domain_type); TYPE_CODE (type) = TYPE_CODE_BITSTRING; val = allocate_value (type); - memcpy (VALUE_CONTENTS_RAW (val), ptr, TYPE_LENGTH (type) / TARGET_CHAR_BIT); + memcpy (VALUE_CONTENTS_RAW (val), ptr, TYPE_LENGTH (type)); return val; }