public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: "Pierre Muller" <pierre.muller@ics-cnrs.unistra.fr>
To: <tromey@redhat.com>, <gdb-patches@sourceware.org>
Cc: "'Eli Zaretskii'" <eliz@gnu.org>
Subject: [PING] [RFA-v3] Allow explicit 16 or 32 char in 'x /s'
Date: Fri, 16 Apr 2010 08:41:00 -0000	[thread overview]
Message-ID: <001d01cadd40$97435c20$c5ca1460$@muller@ics-cnrs.unistra.fr> (raw)
In-Reply-To: <001201cad75e$2ef3fcc0$8cdbf640$@muller@ics-cnrs.unistra.fr>

  Tom,
would you have some time to 
take again a look at this?

Pierre

> -----Message d'origine-----
> De : gdb-patches-owner@sourceware.org [mailto:gdb-patches-
> owner@sourceware.org] De la part de Pierre Muller
> Envoyé : Thursday, April 08, 2010 10:58 PM
> À : gdb-patches@sourceware.org
> Cc : tromey@redhat.com; 'Eli Zaretskii'
> Objet : [RFA-v3] Allow explicit 16 or 32 char in 'x /s'
> 
> I added the comment from Eli about the documentation
> and send this one out as a RFA.
> 
> 
> Pierre
> 
> 
> 2010-04-08  Pierre Muller  <muller@ics.u-strasbg.fr>
> 
> 	* gdbtypes.h (builtin_type): Add BUILTIN_CHAR16 and
> BUILTIN_CHAR32
> 	fields.
> 	* gdbtypes.c (gdbtypes_post_init): Set BUILTIN_CHAR16 and
> 	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.
> 	(x_command): Set LAST_SIZE to 'b' for string type.
> 
> 2010-04-08  Pierre Muller  <muller@ics.u-strasbg.fr>
> 
>       * gdb.texinfo (Examining memory): Update for
> 	change in string display with explicit size.
> 
> 2010-04-08  Pierre Muller  <muller@ics.u-strasbg.fr>
> 
> 	* gdb.base/charset.c (Strin16, String32): New variables.
> 	* gdb.base/charset.exp (gdb_test): Test correct display
> 	of 16 or 32 bit strings.
> Index: src/gdb/gdbtypes.c
> ===================================================================
> 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	5 Apr 2010 22:53:39 -0000
> @@ -3474,6 +3474,13 @@ gdbtypes_post_init (struct gdbarch *gdba
>    TYPE_NOTTEXT (builtin_type->builtin_int8) = 1;
>    TYPE_NOTTEXT (builtin_type->builtin_uint8) = 1;
> 
> +  /* Multi-byte character types.  */
> +  builtin_type->builtin_char16
> +    = arch_integer_type (gdbarch, 16, 0, "char16_t");
> +  builtin_type->builtin_char32
> +    = arch_integer_type (gdbarch, 32, 0, "char32_t");
> +
> +
>    /* Default data/code pointer types.  */
>    builtin_type->builtin_data_ptr
>      = lookup_pointer_type (builtin_type->builtin_void);
> Index: src/gdb/gdbtypes.h
> ===================================================================
> 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	5 Apr 2010 22:53:39 -0000
> @@ -1099,6 +1099,9 @@ struct builtin_type
>    struct type *builtin_int128;
>    struct type *builtin_uint128;
> 
> +  /* Multi-byte character types.  */
> +  struct type *builtin_char16;
> +  struct type *builtin_char32;
> 
>    /* Pointer types.  */
> 
> Index: src/gdb/printcmd.c
> ===================================================================
> 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	5 Apr 2010 22:53:40 -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 = '\0';
> +	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')
> @@ -831,6 +838,27 @@ do_examine (struct format_data fmt, stru
>    else if (size == 'g')
>      val_type = builtin_type (next_gdbarch)->builtin_int64;
> 
> +  if (format == 's')
> +    {
> +      struct type *char_type = NULL;
> +      /* Search for "char16_t"  or "char32_t" types or fall back to 8-
> bit
> char
> +	 if type is not found.  */
> +      if (size == 'h')
> +	char_type = builtin_type (next_gdbarch)->builtin_char16;
> +      else if (size == 'w')
> +	char_type = builtin_type (next_gdbarch)->builtin_char32;
> +      if (char_type)
> +        val_type = char_type;
> +      else
> +        {
> +	  if (size != '\0' && size != 'b')
> +	    warning (_("Unable to display strings with size '%c', using
> 'b'
> \
> +instead."), size);
> +	  size = 'b';
> +	  val_type = builtin_type (next_gdbarch)->builtin_int8;
> +        }
> +    }
> +
>    maxelts = 8;
>    if (size == 'w')
>      maxelts = 4;
> @@ -1412,8 +1440,11 @@ x_command (char *exp, int from_tty)
>    do_examine (fmt, next_gdbarch, next_address);
> 
>    /* If the examine succeeds, we remember its size and format for next
> -     time.  */
> -  last_size = fmt.size;
> +     time.  Set last_size to 'b' for strings.  */
> +  if (fmt.format == 's')
> +    last_size = 'b';
> +  else
> +    last_size = fmt.size;
>    last_format = fmt.format;
> 
>    /* Set a couple of internal variables if appropriate. */
> Index: src/gdb/doc/gdb.texinfo
> ===================================================================
> RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v
> retrieving revision 1.696
> diff -u -p -r1.696 gdb.texinfo
> --- src/gdb/doc/gdb.texinfo	5 Apr 2010 17:14:57 -0000	1.696
> +++ src/gdb/doc/gdb.texinfo	5 Apr 2010 22:53:53 -0000
> @@ -7236,8 +7236,16 @@ 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.
> +Note that the results depend on the programming language of the
> +current compilation unit.  If the language is C, the @samp{s}
> +modifier will use the UTF-16 encoding while @samp{w} will use
> +UTF-32.  The encoding is set by the programming language and cannot
> +be altered.
> 
>  @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
> ===================================================================
> 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	5 Apr 2010 22:53:54 -0000
> @@ -65,6 +65,9 @@ typedef unsigned int char32_t;
>  char16_t uvar;
>  char32_t Uvar;
> 
> +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
> ===================================================================
> 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	5 Apr 2010 22:53:54 -
> 0000
> @@ -616,4 +616,21 @@ gdb_test "print 'a' == 'a' || 'b' == 'b'
>    ".* = 1" \
>    "EVAL_SKIP cleanup handling regression test"
> 
> +
> +proc string_display { var_name set_prefix x_size x_type} {
> +  gdb_test "set ${var_name} = ${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 == 2} {
> +  string_display String16 L h u
> +}
> +
> +string_display String32 U w U
> +if {$wchar_size == 4} {
> +  string_display String32 L w U
> +}
> +
> +
>  gdb_exit


  reply	other threads:[~2010-04-16  8:41 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <11484.4708740295$1268865815@news.gmane.org>
2010-03-18 22:08 ` [RFC] " Tom Tromey
2010-03-19  7:32   ` Eli Zaretskii
2010-03-22 22:54     ` Pierre Muller
     [not found]     ` <15103.6087111153$1269298497@news.gmane.org>
2010-03-30 20:33       ` Tom Tromey
2010-03-31 16:11         ` [RFC-v2] " Pierre Muller
     [not found]         ` <006101cad0ec$cb7915d0$626b4170$%muller@ics-cnrs.unistra.fr>
2010-03-31 16:17           ` Eli Zaretskii
2010-04-01  9:34             ` Pierre Muller
     [not found]             ` <000f01cad17e$7686f140$6394d3c0$%muller@ics-cnrs.unistra.fr>
2010-04-01 13:17               ` Eli Zaretskii
2010-04-05 23:01                 ` Pierre Muller
     [not found]                 ` <002701cad513$e44a7420$acdf5c60$%muller@ics-cnrs.unistra.fr>
2010-04-06 17:51                   ` Eli Zaretskii
2010-04-08 20:58                     ` [RFA-v3] " Pierre Muller
2010-04-16  8:41                       ` Pierre Muller [this message]
     [not found]                       ` <48335.255837492$1271407316@news.gmane.org>
2010-04-21 22:49                         ` [PING] " Tom Tromey
2010-04-21 23:22                           ` Pierre Muller
2010-06-11 17:38                       ` Ulrich Weigand
2010-07-02 19:09                         ` Tom Tromey
2010-07-05 10:17                           ` Ulrich Weigand
2010-07-20 20:13                             ` [patch] testsuite: regression on failed charset.exp compilation [Re: [RFA-v3] Allow explicit 16 or 32 char in 'x /s'] Jan Kratochvil
2010-07-20 22:00                               ` Tom Tromey
2010-07-20 22:13                                 ` Jan Kratochvil

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='001d01cadd40$97435c20$c5ca1460$@muller@ics-cnrs.unistra.fr' \
    --to=pierre.muller@ics-cnrs.unistra.fr \
    --cc=eliz@gnu.org \
    --cc=gdb-patches@sourceware.org \
    --cc=tromey@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).