public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [RFC] Allow explicit 16 or 32 char in 'x /s'
@ 2010-03-17 22:43 Pierre Muller
  2010-03-18  7:01 ` Eli Zaretskii
  0 siblings, 1 reply; 24+ messages in thread
From: Pierre Muller @ 2010-03-17 22:43 UTC (permalink / raw)
  To: gdb-patches

 
  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  <muller@ics.u-strasbg.fr>

	* 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')

^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2010-07-20 22:13 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <11484.4708740295$1268865815@news.gmane.org>
2010-03-18 22:08 ` [RFC] Allow explicit 16 or 32 char in 'x /s' 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                       ` [PING] " Pierre Muller
     [not found]                       ` <48335.255837492$1271407316@news.gmane.org>
2010-04-21 22:49                         ` 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
2010-03-17 22:43 [RFC] Allow explicit 16 or 32 char in 'x /s' Pierre Muller
2010-03-18  7:01 ` Eli Zaretskii
2010-03-18 14:20   ` Pierre Muller
     [not found]   ` <001e01cac69a$75167630$5f436290$%muller@ics-cnrs.unistra.fr>
2010-03-18 18:26     ` Eli Zaretskii

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).