From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30143 invoked by alias); 16 Nov 2005 14:34:05 -0000 Received: (qmail 30130 invoked by uid 22791); 16 Nov 2005 14:34:00 -0000 Received: from lon-del-01.spheriq.net (HELO lon-del-01.spheriq.net) (195.46.50.97) by sourceware.org (qpsmtpd/0.30-dev) with ESMTP; Wed, 16 Nov 2005 14:34:00 +0000 Received: from lon-out-03.spheriq.net ([195.46.50.131]) by lon-del-01.spheriq.net with ESMTP id jAGEXQ03024212 for ; Wed, 16 Nov 2005 14:33:34 GMT Received: from lon-cus-02.spheriq.net (lon-cus-02.spheriq.net [195.46.50.38]) by lon-out-03.spheriq.net with ESMTP id jAGEXOFp008338 for ; Wed, 16 Nov 2005 14:33:25 GMT Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by lon-cus-02.spheriq.net with ESMTP id jAGEXMYr006768 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=OK) for ; Wed, 16 Nov 2005 14:33:24 GMT Received: from zeta.dmz-eu.st.com (ns2.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 8D1C9DA46 for ; Wed, 16 Nov 2005 14:33:18 +0000 (GMT) Received: by zeta.dmz-eu.st.com (STMicroelectronics, from userid 60012) id D891F47532; Wed, 16 Nov 2005 14:36:16 +0000 (GMT) Received: from zeta.dmz-eu.st.com (localhost [127.0.0.1]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 688E575969 for ; Wed, 16 Nov 2005 14:36:16 +0000 (UTC) Received: from mail1.bri.st.com (mail1.bri.st.com [164.129.8.218]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 5F73A47534 for ; Wed, 16 Nov 2005 14:36:15 +0000 (GMT) Received: from [164.129.15.13] (terrorhawk.bri.st.com [164.129.15.13]) by mail1.bri.st.com (MOS 3.5.8-GR) with ESMTP id CGZ37473 (AUTH "andrew stubbs"); Wed, 16 Nov 2005 14:33:15 GMT Message-ID: <437B4291.3050006@st.com> Date: Wed, 16 Nov 2005 15:13:00 -0000 From: Andrew STUBBS User-Agent: Mozilla Thunderbird 1.0.2 (Windows/20050317) MIME-Version: 1.0 To: gdb-patches@sources.redhat.com Subject: [PATCH] Fixup convenience variables on endian switch Content-Type: multipart/mixed; boundary="------------090309060000070800050905" X-O-Spoofed: Not Scanned X-O-General-Status: No X-O-Spam1-Status: Not Scanned X-O-Spam2-Status: Not Scanned X-O-URL-Status: Not Scanned X-O-Virus1-Status: No X-O-Virus2-Status: Not Scanned X-O-Virus3-Status: No X-O-Virus4-Status: No X-O-Virus5-Status: Not Scanned X-O-Image-Status: Not Scanned X-O-Attach-Status: Not Scanned X-SpheriQ-Ver: 4.1.07 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2005-11/txt/msg00229.txt.bz2 This is a multi-part message in MIME format. --------------090309060000070800050905 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 2186 Hi, The attached patch attempts to do the Right Thing for internal variables when 'set endian' is used (explicitly or implicitly). I have not (and cannot) test it with all varieties of host machine and type, but I am confident that it works on x86 Linux and sparc Solaris for integer (including pointer) and float types. I have run the regression test suite on i686-pc-linux-gnu native and sh-elf cross. Demonstration: Before (gdb) set $a = 1 (gdb) set $b = (float)1.1 (gdb) set $c = (double)1.2 (gdb) set $d = (long double)1.3 (gdb) set $e = (long long)10000000 (gdb) show conv $e = 10000000 $d = 1.3000000000000000444089209850062616 $c = 1.2 $b = 1.10000002 $a = 1 $trace_frame = -1 $tpnum = 0 (gdb) show endian The target endianness is set automatically (currently little endian) (gdb) set endian big The target is assumed to be big endian (gdb) show conv $e = -9180983664580755456 $d = 1.3000000000000000444089209850062616 $c = 1.2 $b = 1.10000002 $a = 16777216 $trace_frame = -1 $tpnum = 0 (gdb) set endian little The target is assumed to be little endian (gdb) show conv $e = 10000000 $d = 1.3000000000000000444089209850062616 $c = 1.2 $b = 1.10000002 $a = 1 $trace_frame = -1 $tpnum = 0 After (gdb) set $a = 1 (gdb) set $b = (float)1.1 (gdb) set $c = (double)1.2 (gdb) set $d = (long double)1.3 (gdb) set $e = (long long)10000000 (gdb) show conv $e = 10000000 $d = 1.3000000000000000444089209850062616 $c = 1.2 $b = 1.10000002 $a = 1 $trace_frame = -1 $tpnum = 0 (gdb) show endian The target endianness is set automatically (currently little endian) (gdb) set endian big The target is assumed to be big endian (gdb) show conv $e = 10000000 $d = 1.3000000000000000444089209850062616 $c = 1.2 $b = 1.10000002 $a = 1 $trace_frame = -1 $tpnum = 0 (gdb) set endian little The target is assumed to be little endian (gdb) show conv $e = 10000000 $d = 1.3000000000000000444089209850062616 $c = 1.2 $b = 1.10000002 $a = 1 $trace_frame = -1 $tpnum = 0 Andrew Stubbs --------------090309060000070800050905 Content-Type: text/plain; name="internalvar_endian.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="internalvar_endian.patch" Content-length: 4396 2005-11-16 Andrew Stubbs * arch-utils.c: Include value.h. (set_endian): Call fixup_all_internalvars_endian(). * value.h (struct internalvar): Add endian field. (fixup_all_internalvars_endian): New prototype. * value.c (fixup_internalvar_endian): New function. (fixup_all_internalvars_endian): New function. (lookup_internalvar): Initialize endian field. (set_internalvar): Reset endian field. * Makefile.in (arch-utils.o): Add value.h to dependencies. Index: src/gdb/arch-utils.c =================================================================== --- src.orig/gdb/arch-utils.c 2005-11-07 11:50:22.000000000 +0000 +++ src/gdb/arch-utils.c 2005-11-07 16:40:56.000000000 +0000 @@ -32,6 +32,7 @@ #include "sim-regno.h" #include "gdbcore.h" #include "osabi.h" +#include "value.h" #include "version.h" @@ -417,6 +418,8 @@ internal_error (__FILE__, __LINE__, _("set_endian: bad value")); show_endian (gdb_stdout, from_tty, NULL, NULL); + + fixup_all_internalvars_endian (); } /* Functions to manipulate the architecture of the target */ Index: src/gdb/value.h =================================================================== --- src.orig/gdb/value.h 2005-11-07 11:50:22.000000000 +0000 +++ src/gdb/value.h 2005-11-07 16:40:56.000000000 +0000 @@ -245,6 +245,7 @@ struct internalvar *next; char *name; struct value *value; + int endian; }; @@ -416,6 +417,8 @@ extern struct internalvar *lookup_internalvar (char *name); +extern void fixup_all_internalvars_endian (void); + extern int value_equal (struct value *arg1, struct value *arg2); extern int value_less (struct value *arg1, struct value *arg2); Index: src/gdb/value.c =================================================================== --- src.orig/gdb/value.c 2005-11-07 16:40:54.000000000 +0000 +++ src/gdb/value.c 2005-11-07 16:40:56.000000000 +0000 @@ -768,6 +768,49 @@ } +/* Reverse the endianess of the variable. + This is used when the the endianness is changed with 'set endian' + or when a new file of opposite endianess is loaded. */ + +static void +fixup_internalvar_endian (struct internalvar *var) +{ + int i, j; + gdb_byte temp; + gdb_byte *array = value_contents_raw (var->value); + + /* Don't do anything if the endian has not changed. + Also disregard FP types because they don't seem to vary with + endian - at least, not on i686 Linux or sparc Solaris. */ + if (var->endian != TARGET_BYTE_ORDER + && TYPE_CODE (value_type (var->value)) != TYPE_CODE_FLT) + { + /* Reverse the bytes. + This may not be the right thing for some types + so don't be afraid of messing with it if you encounter problems. */ + for (i=0,j=TYPE_LENGTH (var->value->enclosing_type)-1; iendian = TARGET_BYTE_ORDER; + } +} + + +/* Swap the endianness of all the internal variables. */ + +void +fixup_all_internalvars_endian (void) +{ + struct internalvar *iv; + + for (iv=internalvars; iv!=NULL; iv=iv->next) + fixup_internalvar_endian (iv); +} + + /* Look up an internal variable with name NAME. NAME should not normally include a dollar sign. @@ -786,6 +829,7 @@ var = (struct internalvar *) xmalloc (sizeof (struct internalvar)); var->name = concat (name, (char *)NULL); var->value = allocate_value (builtin_type_void); + var->endian = TARGET_BYTE_ORDER; release_value (var->value); var->next = internalvars; internalvars = var; @@ -840,6 +884,7 @@ long. */ xfree (var->value); var->value = newval; + var->endian = TARGET_BYTE_ORDER; release_value (newval); /* End code which must not call error(). */ } Index: src/gdb/Makefile.in =================================================================== --- src.orig/gdb/Makefile.in 2005-11-07 16:40:46.000000000 +0000 +++ src/gdb/Makefile.in 2005-11-07 16:45:08.000000000 +0000 @@ -1732,7 +1732,7 @@ arch-utils.o: arch-utils.c $(defs_h) $(arch_utils_h) $(buildsym_h) \ $(gdbcmd_h) $(inferior_h) $(gdb_string_h) $(regcache_h) \ $(gdb_assert_h) $(sim_regno_h) $(gdbcore_h) $(osabi_h) $(version_h) \ - $(floatformat_h) + $(floatformat_h) $(value_h) arm-linux-nat.o: arm-linux-nat.c $(defs_h) $(inferior_h) $(gdbcore_h) \ $(gdb_string_h) $(regcache_h) $(arm_tdep_h) $(gregset_h) \ $(target_h) $(linux_nat_h) --------------090309060000070800050905--