From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3498 invoked by alias); 22 Mar 2010 22:54:48 -0000 Received: (qmail 3488 invoked by uid 22791); 22 Mar 2010 22:54:45 -0000 X-SWARE-Spam-Status: No, hits=-0.5 required=5.0 tests=AWL,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.158) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 22 Mar 2010 22:54:40 +0000 Received: from baal.u-strasbg.fr (baal.u-strasbg.fr [IPv6:2001:660:2402::41]) by mailhost.u-strasbg.fr (8.14.2/jtpda-5.5pre1) with ESMTP id o2MMsM20000559 ; Mon, 22 Mar 2010 23:54:22 +0100 (CET) (envelope-from pierre.muller@ics-cnrs.unistra.fr) Received: from mailserver.u-strasbg.fr (ms1.u-strasbg.fr [IPv6:2001:660:2402:d::10]) by baal.u-strasbg.fr (8.14.0/jtpda-5.5pre1) with ESMTP id o2MMsL62078180 ; Mon, 22 Mar 2010 23:54:22 +0100 (CET) (envelope-from pierre.muller@ics-cnrs.unistra.fr) Received: from d620muller (lec67-4-82-230-53-140.fbx.proxad.net [82.230.53.140]) (user=mullerp mech=LOGIN) by mailserver.u-strasbg.fr (8.14.3/jtpda-5.5pre1) with ESMTP id o2MMsKWD019324 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NO) ; Mon, 22 Mar 2010 23:54:20 +0100 (CET) (envelope-from pierre.muller@ics-cnrs.unistra.fr) From: "Pierre Muller" To: "'Eli Zaretskii'" , Cc: References: <11484.4708740295$1268865815@news.gmane.org> <83r5ngix6d.fsf@gnu.org> In-Reply-To: <83r5ngix6d.fsf@gnu.org> Subject: RE: [RFC] Allow explicit 16 or 32 char in 'x /s' Date: Mon, 22 Mar 2010 22:54:00 -0000 Message-ID: <001501caca12$a4dab860$ee902920$@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/msg00783.txt.bz2 > -----Message d'origine----- > De=A0: gdb-patches-owner@sourceware.org [mailto:gdb-patches- > owner@sourceware.org] De la part de Eli Zaretskii > Envoy=E9=A0: Friday, March 19, 2010 8:32 AM > =C0=A0: tromey@redhat.com > Cc=A0: pierre.muller@ics-cnrs.unistra.fr; gdb-patches@sourceware.org > Objet=A0: Re: [RFC] Allow explicit 16 or 32 char in 'x /s' >=20 > > From: Tom Tromey > > Cc: > > Date: Thu, 18 Mar 2010 16:08:27 -0600 > > > > I think the documentation should reflect that the user can't choose > the > > encoding used here. >=20 > I agree. It should also say which encoding is used by GDB in this > case. Not that I do not agree with you, but I would like to=20 stress that how the string is displayed also depend on the current language, so that, for C or any other language using c_printstr function, /hs will use UTF-16LE or UTF-16BE according to current gdbarch endianess. /ws will use UTF-32LE or UTF-32BE. But I don't know exactly for other languages and I would like to be sure about what you want me to add to the docs... Furthermore if you look into charset_for_string_type function in c-lang.c source, you will see that there are two FIXME just right at the position of these charset name settings. To answer Tom's concern about the change in classify_type function, I modified my patch to change the elttype in do_examine to match exactly what is expected by charset_for_string_type function. Thus this new version has no modification in c-lang.c file. I also added a very basic check for string display using 'x /hs' and 'x /ws'. Pierre Muller 2010-03-22 Pierre Muller * printcmd.c (decode_format): Set char size to byte 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 'char16_t' and 'char32_t' types to allow for correct recognition in classify_type. =09 2010-03-22 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. Index: 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 --- printcmd.c 5 Mar 2010 20:18:14 -0000 1.173 +++ printcmd.c 22 Mar 2010 22:25:34 -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 'b'; + 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,36 @@ 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; + if (size =3D=3D 'h') + { + char_type =3D lookup_typename (current_language, next_gdbarch, + "char16_t", NULL, 1); + if (!char_type) + char_type =3D arch_type (next_gdbarch, TYPE_CODE_INT, 2, "char16_t"); + check_typedef (char_type); + if (TYPE_LENGTH (char_type) =3D=3D 2) + val_type =3D char_type; + } + else if (size =3D=3D 'w') + { + char_type =3D lookup_typename (current_language, next_gdbarch, + "char32_t", NULL, 1); + if (!char_type) + char_type =3D arch_type (next_gdbarch, TYPE_CODE_INT, 4, "char32_t"); + check_typedef (char_type); + if (char_type && TYPE_LENGTH (char_type) =3D=3D 4) + val_type =3D char_type; + } + else + { + size =3D 'b'; + val_type =3D builtin_type (next_gdbarch)->builtin_int8; + } + } + maxelts =3D 8; if (size =3D=3D 'w') maxelts =3D 4; Index: 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 --- testsuite/gdb.base/charset.c 1 Jan 2010 07:32:00 -0000 1.12 +++ 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: 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 --- testsuite/gdb.base/charset.exp 17 Feb 2010 22:05:58 -0000 1.21 +++ 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