From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7851 invoked by alias); 31 Mar 2010 16:11:51 -0000 Received: (qmail 7841 invoked by uid 22791); 31 Mar 2010 16:11:49 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=BAYES_00,MSGID_MULTIPLE_AT X-Spam-Check-By: sourceware.org Received: from mailhost.u-strasbg.fr (HELO mailhost.u-strasbg.fr) (130.79.200.152) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 31 Mar 2010 16:11:43 +0000 Received: from baal.u-strasbg.fr (baal.u-strasbg.fr [IPv6:2001:660:2402::41]) by mailhost.u-strasbg.fr (8.14.3/jtpda-5.5pre1) with ESMTP id o2VGBIOW006141 ; Wed, 31 Mar 2010 18:11:18 +0200 (CEST) (envelope-from pierre.muller@ics-cnrs.unistra.fr) Received: from mailserver.u-strasbg.fr (ms2.u-strasbg.fr [IPv6:2001:660:2402:d::11]) by baal.u-strasbg.fr (8.14.0/jtpda-5.5pre1) with ESMTP id o2VGBHBi072255 ; Wed, 31 Mar 2010 18:11:18 +0200 (CEST) (envelope-from pierre.muller@ics-cnrs.unistra.fr) Received: from d620muller (gw-ics.u-strasbg.fr [130.79.210.225]) (user=mullerp mech=LOGIN) by mailserver.u-strasbg.fr (8.14.3/jtpda-5.5pre1) with ESMTP id o2VGBHik031230 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NO) ; Wed, 31 Mar 2010 18:11:17 +0200 (CEST) (envelope-from pierre.muller@ics-cnrs.unistra.fr) From: "Pierre Muller" To: Cc: "'Eli Zaretskii'" , References: <11484.4708740295$1268865815@news.gmane.org> <83r5ngix6d.fsf@gnu.org> <15103.6087111153$1269298497@news.gmane.org> In-Reply-To: Subject: [RFC-v2] Allow explicit 16 or 32 char in 'x /s' Date: Wed, 31 Mar 2010 16:11:00 -0000 Message-ID: <006101cad0ec$cb7915d0$626b4170$@muller@ics-cnrs.unistra.fr> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable 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: 2010-03/txt/msg01115.txt.bz2 > -----Message d'origine----- > De=A0: gdb-patches-owner@sourceware.org [mailto:gdb-patches- > owner@sourceware.org] De la part de Tom Tromey > Envoy=E9=A0: Tuesday, March 30, 2010 10:33 PM > =C0=A0: Pierre Muller > Cc=A0: 'Eli Zaretskii'; gdb-patches@sourceware.org > Objet=A0: Re: [RFC] Allow explicit 16 or 32 char in 'x /s' >=20 > >>>>> "Pierre" =3D=3D Pierre Muller > writes: >=20 > Pierre> But I don't know exactly for other languages and I would like > Pierre> to be sure about what you want me to add to the docs... >=20 > I think no other language has been updated to deal with wide > characters. At least pascal language was able to display "simple" wide characters correctly (i.e. 16-bit strings with numeric values in the 32-127 range) before the patch that explicitly discarded the size modifier for /s. =20 > Pierre> Furthermore if you look into charset_for_string_type > Pierre> function in c-lang.c source, you will see that there are two > FIXME > Pierre> just right at the position of these charset name settings. >=20 > Yeah ... those are actually pedantic FIXMEs, in that (IIRC) nothing > guarantees that char16_t=3D=3DUTF-16, even though that is the common > meaning. >=20 > Pierre> To answer Tom's concern about the change in classify_type > function, > Pierre> I modified my patch to change the elttype in do_examine to > match exactly > Pierre> what is expected by charset_for_string_type function. > Pierre> Thus this new version has no modification in c-lang.c file. >=20 > Suppose the inferior does not define char16_t. Won't this new code > allocate a new type each time the user uses x/hs? That seems bad. =20 Well, I supposed (wrongly) that the arch_type call would make that newly defined type accessible to the next call to lookup_typename but, after verification, it appears that you are right and that the newly type is lost... I don't know how we should handle this case, but I don't think that it is= =20 the first time we use arch_type function inside GDB. Should I add two new fields to builtin_type struct? That is what I tried below. =20 > What about passing the desired encoding to LA_PRINT_STRING, via a new > argument to val_print_string? That makes the patch a lot bigger, > though > it is mostly mechanical. >=20 > Pierre> I also added a very basic check for string display using 'x > Pierre> /hs' and 'x /ws'. >=20 > Thanks. >=20 > Pierre> + case 's': > Pierre> + /* Display strings with byte size chars unless explicitly > specified. > Pierre> */ > Pierre> + val.size =3D 'b'; > Pierre> + break; >=20 > I think x/hs followed by x should probably print another wide string. > I couldn't tell offhand if it does this or not. This is what I wrote in the documentation part of the patch, the idea was to limit the behavior change as compared to previous versions of GDB:=20 only 'x /hs' or 'x /ws' would display 16 or 32 bit strings, any use without the explicit size specifier would fall back to implicit 'x /bs' this of course also would happen if you use 'x ' command without any specifier at all. It seems nevertheless that the patch I sent out finally=20 failed to do this properly. This new version seems to be closer to the documentation I gave. Here is a new version of the patch using builtin_char16 and builtin_char32. Pierre 2010-03-31 Pierre Muller * gdbtypes.h (builtin_type): Add BUILTIN_CHAR16 and BUILTIN_CHAR32 fields. * gdbtypes.c (gdbtypes_post_init): Set BUILTIN_CHAR16 and=20 BUILTIN_CHAR32 fields. * printcmd.c (decode_format): Set char size to '\0' for strings unless explicit size is given. (print_formatted): Correct calculation of NEXT_ADDRESS for 16 or 32 bit strings. (do_examine): Do not force byte size for strings. Use builtin_char16 and builtin_char32 types to display 16 or 32 bit-wide strings.=20 (x_command): Set LAST_SIZE to 'b' for string type. 2010-03-31 Pierre Muller * gdb.texinfo (Examining memory): Update for change in string display with explicit size. 2010-03-31 Pierre Muller * gdb.base/charset.c (Strin16, String32): New variables. * gdb.base/charset.exp (gdb_test): Test correct display of 16 or 32 bit strings. =09 Index: src/gdb/gdbtypes.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/gdb/gdbtypes.h,v retrieving revision 1.125 diff -u -p -r1.125 gdbtypes.h --- src/gdb/gdbtypes.h 15 Mar 2010 02:42:54 -0000 1.125 +++ src/gdb/gdbtypes.h 31 Mar 2010 12:57:26 -0000 @@ -1099,6 +1099,9 @@ struct builtin_type struct type *builtin_int128; struct type *builtin_uint128; =20 + /* Multi-byte character types. */ + struct type *builtin_char16; + struct type *builtin_char32; =20 /* Pointer types. */ =20 Index: src/gdb/gdbtypes.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/gdb/gdbtypes.c,v retrieving revision 1.188 diff -u -p -r1.188 gdbtypes.c --- src/gdb/gdbtypes.c 1 Mar 2010 17:19:22 -0000 1.188 +++ src/gdb/gdbtypes.c 31 Mar 2010 12:57:25 -0000 @@ -3474,6 +3474,13 @@ gdbtypes_post_init (struct gdbarch *gdba TYPE_NOTTEXT (builtin_type->builtin_int8) =3D 1; TYPE_NOTTEXT (builtin_type->builtin_uint8) =3D 1; =20 + /* Multi-byte character types. */ + builtin_type->builtin_char16 + =3D arch_integer_type (gdbarch, 16, 0, "char16_t"); + builtin_type->builtin_char32 + =3D arch_integer_type (gdbarch, 32, 0, "char32_t"); +=09 + /* Default data/code pointer types. */ builtin_type->builtin_data_ptr =3D lookup_pointer_type (builtin_type->builtin_void); Index: src/gdb/printcmd.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/gdb/printcmd.c,v retrieving revision 1.173 diff -u -p -r1.173 printcmd.c --- src/gdb/printcmd.c 5 Mar 2010 20:18:14 -0000 1.173 +++ src/gdb/printcmd.c 31 Mar 2010 15:20:22 -0000 @@ -260,6 +260,11 @@ decode_format (char **string_ptr, int of /* Characters default to one byte. */ val.size =3D osize ? 'b' : osize; break; + case 's': + /* Display strings with byte size chars unless explicitly specified. */ + val.size =3D '\0'; + break; + default: /* The default is the size most recently specified. */ val.size =3D osize; @@ -295,7 +300,7 @@ print_formatted (struct value *val, int=20 next_address =3D (value_address (val) + val_print_string (elttype, value_address (val), -1, - stream, options)); + stream, options) * len); } return; =20 @@ -802,9 +807,11 @@ do_examine (struct format_data fmt, stru next_gdbarch =3D gdbarch; next_address =3D addr; =20 - /* String or instruction format implies fetch single bytes - regardless of the specified size. */ - if (format =3D=3D 's' || format =3D=3D 'i') + /* Instruction format implies fetch single bytes + regardless of the specified size. + The case of strings is handled n decode_format, only explicit + size operator are not changed to 'b'. */ + if (format =3D=3D 'i') size =3D 'b'; =20 if (size =3D=3D 'a') @@ -831,6 +838,27 @@ do_examine (struct format_data fmt, stru else if (size =3D=3D 'g') val_type =3D builtin_type (next_gdbarch)->builtin_int64; =20 + if (format =3D=3D 's') + { + struct type *char_type =3D NULL; + /* Search for "char16_t" or "char32_t" types or fall back to 8-bit char + if type is not found. */ + if (size =3D=3D 'h') + char_type =3D builtin_type (next_gdbarch)->builtin_char16; + else if (size =3D=3D 'w') + char_type =3D builtin_type (next_gdbarch)->builtin_char32; + if (char_type) + val_type =3D char_type; + else + { + if (size !=3D '\0' && size !=3D 'b') + warning (_("Unable to display strings with size '%c', using 'b' \ +instead."), size); + size =3D 'b'; + val_type =3D builtin_type (next_gdbarch)->builtin_int8; + } + } + maxelts =3D 8; if (size =3D=3D 'w') maxelts =3D 4; @@ -1412,8 +1440,11 @@ x_command (char *exp, int from_tty) do_examine (fmt, next_gdbarch, next_address); =20 /* If the examine succeeds, we remember its size and format for next - time. */ - last_size =3D fmt.size; + time. Set last_size to 'b' for strings. */ + if (fmt.format =3D=3D 's') + last_size =3D 'b' + else + last_size =3D fmt.size; last_format =3D fmt.format; =20 /* Set a couple of internal variables if appropriate. */ Index: src/gdb/doc/gdb.texinfo =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v retrieving revision 1.680 diff -u -p -r1.680 gdb.texinfo --- src/gdb/doc/gdb.texinfo 12 Mar 2010 19:15:52 -0000 1.680 +++ src/gdb/doc/gdb.texinfo 18 Mar 2010 20:43:12 -0000 @@ -7236,8 +7236,11 @@ Giant words (eight bytes). @end table Each time you specify a unit size with @code{x}, that size becomes the -default unit the next time you use @code{x}. (For the @samp{s} and -@samp{i} formats, the unit size is ignored and is normally not written.) +default unit the next time you use @code{x}. For the @samp{i} format, +the unit size is ignored and is normally not written. For the @samp{s} format, +the unit size defaults to @samp{b}, unless it is explicitly given. +Use @kbd{x /hs} to display 16-bit char strings and @kbd{x /ws} to display +32-bit strings. The next use of @kbd{x /s} will again display 8-bit strings. @item @var{addr}, starting display address @var{addr} is the address where you want @value{GDBN} to begin displaying Index: src/gdb/testsuite/gdb.base/charset.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/gdb/testsuite/gdb.base/charset.c,v retrieving revision 1.12 diff -u -p -r1.12 charset.c --- src/gdb/testsuite/gdb.base/charset.c 1 Jan 2010 07:32:00 -0000 1.12 +++ src/gdb/testsuite/gdb.base/charset.c 22 Mar 2010 22:25:34 -0000 @@ -65,6 +65,9 @@ typedef unsigned int char32_t; char16_t uvar; char32_t Uvar; =20 +char16_t *String16; +char32_t *String32; + /* A typedef to a typedef should also work. */ typedef wchar_t my_wchar_t; my_wchar_t myvar; Index: src/gdb/testsuite/gdb.base/charset.exp =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/gdb/testsuite/gdb.base/charset.exp,v retrieving revision 1.21 diff -u -p -r1.21 charset.exp --- src/gdb/testsuite/gdb.base/charset.exp 17 Feb 2010 22:05:58 -0000 1.21 +++ src/gdb/testsuite/gdb.base/charset.exp 22 Mar 2010 22:25:35 -0000 @@ -616,4 +616,21 @@ gdb_test "print 'a' =3D=3D 'a' || 'b' =3D=3D 'b' ".* =3D 1" \ "EVAL_SKIP cleanup handling regression test" =20 + +proc string_display { var_name set_prefix x_size x_type} { + gdb_test "set ${var_name} =3D ${set_prefix}\"Test String\\0with zeroes\"" "" "Assign ${var_name} with prefix ${set_prefix}" + gdb_test "x /2${x_size}s ${var_name}" ".* ${x_type}\"Test String\"\[\r\n\]+.* ${x_type}\"with zeroes\"" "Display String ${var_name} with x/${x_size}s" +} + +string_display String16 u h u +if {$wchar_size =3D=3D 2} { + string_display String16 L h u +} +=20 +string_display String32 U w U +if {$wchar_size =3D=3D 4} { + string_display String32 L w U +} + + gdb_exit=20 =20=20