From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2788 invoked by alias); 17 Mar 2010 22:43:27 -0000 Received: (qmail 2755 invoked by uid 22791); 17 Mar 2010 22:43:25 -0000 X-SWARE-Spam-Status: No, hits=-0.6 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.157) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 17 Mar 2010 22:42:55 +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 o2HMgpZi035758 for ; Wed, 17 Mar 2010 23:42:51 +0100 (CET) (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 o2HMgpaq037222 for ; Wed, 17 Mar 2010 23:42:51 +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 o2HMgoGh095882 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NO) for ; Wed, 17 Mar 2010 23:42:50 +0100 (CET) (envelope-from pierre.muller@ics-cnrs.unistra.fr) From: "Pierre Muller" To: Subject: [RFC] Allow explicit 16 or 32 char in 'x /s' Date: Wed, 17 Mar 2010 22:43:00 -0000 Message-ID: <000f01cac623$2ec3a850$8c4af8f0$@muller@ics-cnrs.unistra.fr> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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/msg00638.txt.bz2 The patch below allows to print strings that are made of 16 bit or 32 bit char using: 'x /hs ' or 'x /ws ' commands. I tried to enable this feature, keeping it to a minimum: The size modifier is not remembered for /s format, thus any subsequent use of /s alone will still print out byte char strings. I found out a c-language specific issue that made a wrong calculation of the position of the next string, if you used 'x /2hs ' command and have two consecutive Unicode strings. This patch also fixes that problem, but I am not sure that this problem could really appear before as the char size was fored to 1 byte... Pierre Muller 2010-03-17 Pierre Muller * c-lang.c (classify_type): Recognize also types used for /hs or /ws format specifier in 'x' command. * 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. Index: c-lang.c =================================================================== RCS file: /cvs/src/src/gdb/c-lang.c,v retrieving revision 1.81 diff -u -p -r1.81 c-lang.c --- c-lang.c 5 Mar 2010 20:18:11 -0000 1.81 +++ c-lang.c 17 Mar 2010 22:11:08 -0000 @@ -100,13 +100,19 @@ classify_type (struct type *elttype, str goto done; } - if (!strcmp (name, "char16_t")) + /* Also recognize the type used by 'x /hs' command. */ + if (!strcmp (name, "char16_t") + || (TYPE_CODE (elttype) == TYPE_CODE_INT + && TYPE_LENGTH (elttype) == 2)) { result = C_CHAR_16; goto done; } - if (!strcmp (name, "char32_t")) + /* Also recognize the type used by 'x /ws' command. */ + if (!strcmp (name, "char32_t") + || (TYPE_CODE (elttype) == TYPE_CODE_INT + && TYPE_LENGTH (elttype) == 4)) { result = C_CHAR_32; goto done; Index: printcmd.c =================================================================== 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 17 Mar 2010 22:11:08 -0000 @@ -260,6 +260,11 @@ decode_format (char **string_ptr, int of /* Characters default to one byte. */ val.size = osize ? 'b' : osize; break; + case 's': + /* Display strings with byte size chars unless explicitly specified. */ + val.size = 'b'; + break; + default: /* The default is the size most recently specified. */ val.size = osize; @@ -295,7 +300,7 @@ print_formatted (struct value *val, int next_address = (value_address (val) + val_print_string (elttype, value_address (val), -1, - stream, options)); + stream, options) * len); } return; @@ -802,9 +807,11 @@ do_examine (struct format_data fmt, stru next_gdbarch = gdbarch; next_address = addr; - /* String or instruction format implies fetch single bytes - regardless of the specified size. */ - if (format == 's' || format == '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 == 'i') size = 'b'; if (size == 'a')