From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13653 invoked by alias); 22 Apr 2002 15:35:08 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 13630 invoked from network); 22 Apr 2002 15:35:05 -0000 Received: from unknown (HELO kerberos.suse.cz) (195.47.106.10) by sources.redhat.com with SMTP; 22 Apr 2002 15:35:05 -0000 Received: from chimera.suse.cz (chimera.suse.cz [10.20.0.2]) by kerberos.suse.cz (SuSE SMTP server) with ESMTP id 6F68C59D36F for ; Mon, 22 Apr 2002 17:35:04 +0200 (CEST) Received: from suse.cz (leviathan.suse.cz [10.20.1.56]) by chimera.suse.cz (8.11.0/8.11.0/SuSE Linux 8.11.0-0.4) with ESMTP id g3MFZ4f23728 for ; Mon, 22 Apr 2002 17:35:04 +0200 X-Authentication-Warning: chimera.suse.cz: Host leviathan.suse.cz [10.20.1.56] claimed to be suse.cz Message-ID: <3CC42DA0.9070906@suse.cz> Date: Mon, 22 Apr 2002 08:35:00 -0000 From: Michal Ludvig Organization: SuSE CR User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0rc1) Gecko/20020417 X-Accept-Language: cs, cz, en MIME-Version: 1.0 To: gdb-patches@sources.redhat.com Subject: [RFA] New bitflags type and eflags on i386/x86-64 Content-Type: multipart/mixed; boundary="------------030302020401050602070203" X-SW-Source: 2002-04/txt/msg00794.txt.bz2 This is a multi-part message in MIME format. --------------030302020401050602070203 Content-Type: text/plain; charset=ISO-8859-2; format=flowed Content-Transfer-Encoding: 7bit Content-length: 1482 (Once again, now with Changelog :-) Hi all, I've created a new typecode TYPE_CODE_FLAGS with appropriate functions and used it in builtin_type_i386_eflags type. I did this to be able to print i386's and x86-64's FLAGS register in a symbolic form, instead of printing it in a hexadecimal and decimal notation. Now it looks like this: (gdb) info registers eflags eflags 0x747 [ DF IF TF ZF PF CF ] I've chosen quite a generic way for implementation, so that the others could use this for their types as well. For now I'm using this type only on x86-64, but using it on i386 should be possible without modifications. (BTW Should I do it or the maintainer will?) 2002-04-22 Michal Ludvig * c-valprint.c (c_val_print): Added handling of TYPE_CODE_FLAGS. * gdbtypes.c (builtin_type_i386_eflags): Added. (add_flag_ignore, add_flag_name, init_flags_type): Added. (is_integral_type, rank_one_type, recursive_dump_type): Added TYPE_CODE_FLAGS handling. (build_gdbtypes): Added builtin_type_i386_eflags initialization. * gdbtypes.h (type_code): Added TYPE_CODE_FLAGS. (builtin_type_i386_eflags): Added. * values.c (unpack_long: Added TYPE_CODE_FLAGS handling. * x86-64-tdep.c (x86_64_register_info_table): Changed type of eflags. Any comments? Can I commit? Michal Ludvig -- * SuSE CR, s.r.o * mludvig@suse.cz * +420 2 9654 5373 * http://www.suse.cz --------------030302020401050602070203 Content-Type: text/plain; name="eflags.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="eflags.diff" Content-length: 8136 Index: c-valprint.c =================================================================== RCS file: /cvs/src/src/gdb/c-valprint.c,v retrieving revision 1.13 diff -u -r1.13 c-valprint.c --- c-valprint.c 5 Feb 2002 21:41:29 -0000 1.13 +++ c-valprint.c 22 Apr 2002 14:50:12 -0000 @@ -70,6 +70,7 @@ int deref_ref, int recurse, enum val_prettyprint pretty) { register unsigned int i = 0; /* Number of characters printed */ + register int j; unsigned len; struct type *elttype; unsigned eltlen; @@ -483,6 +484,30 @@ TYPE_TARGET_TYPE (type), stream); fprintf_filtered (stream, " * I"); + break; + + case TYPE_CODE_FLAGS: + if (format) + { + print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream); + break; + } + len = TYPE_NFIELDS (type); + val = unpack_long (type, valaddr + embedded_offset); + fputs_filtered("[", stream); + for (j = len-1; j >= 0; j--) + { + QUIT; + if (TYPE_FIELD_BITPOS (type, j) != -1 && val & (1 << j)) + { + if(TYPE_FIELD_NAME (type, j)) + fprintf_filtered (stream, " %s", TYPE_FIELD_NAME (type, j)); + else + fprintf_filtered (stream, " #%d", j); + + } + } + fputs_filtered(" ]", stream); break; default: Index: gdbtypes.c =================================================================== RCS file: /cvs/src/src/gdb/gdbtypes.c,v retrieving revision 1.43 diff -u -r1.43 gdbtypes.c --- gdbtypes.c 20 Apr 2002 01:09:28 -0000 1.43 +++ gdbtypes.c 22 Apr 2002 14:50:13 -0000 @@ -99,6 +99,7 @@ struct type *builtin_type_void_func_ptr; struct type *builtin_type_CORE_ADDR; struct type *builtin_type_bfd_vma; +struct type *builtin_type_i386_eflags; int opaque_type_resolution = 1; int overload_debug = 0; @@ -777,6 +778,67 @@ return (result_type); } +/* + * - The following three functions are intended to be used for BitFlags + * types (ie i386's EFLAGS register). + * - As a BitFlag we understand an integer where some bits may have + * a symbolic names that would be printed when the bit is set. + * - Printing is done in c_val_print() under a TYPE_CODE_FLAGS label. + * - All bits are set to be ignored (ie. not printed even when set) + * by default. + * - Add a symbolic name of relevant bits using add_flag_name() after + * an initialisation of your type. + */ +void +add_flag_ignore (struct type *type, int bitpos) +{ + TYPE_FIELD_BITPOS (type, bitpos) = -1; +} + +void +add_flag_name (struct type *type, int bitpos, char *name) +{ + int namelen; + + gdb_assert (TYPE_CODE (type) == TYPE_CODE_FLAGS); + gdb_assert (bitpos < TYPE_NFIELDS (type)); + gdb_assert (bitpos >= 0); + + namelen=strlen(name)+1; + TYPE_FIELD_NAME (type, bitpos) = xmalloc (namelen); + snprintf(TYPE_FIELD_NAME (type, bitpos), namelen, "%s", name); + + TYPE_FIELD_BITPOS (type, bitpos) = bitpos; +} + +struct type * +init_flags_type (int bitlength, char *name, struct objfile *objfile) +{ + register struct type *type; + int i; + + type = alloc_type (objfile); + + TYPE_CODE (type) = TYPE_CODE_FLAGS; + TYPE_LENGTH (type) = bitlength / 8 + ( bitlength % 8 ? 1 : 0 ); + TYPE_FLAGS (type) = TYPE_FLAG_UNSIGNED; + TYPE_NFIELDS (type) = bitlength; + TYPE_FIELDS (type) = (struct field *) + TYPE_ALLOC (type, bitlength * sizeof (struct field)); + memset (TYPE_FIELDS (type), 0, sizeof (struct field)); + + if ((name != NULL) && (objfile != NULL)) + TYPE_NAME (type) = + obsavestring (name, strlen (name), &objfile->type_obstack); + else + TYPE_NAME (type) = name; + + for(i=0; i