This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFC] Allow explicit 16 or 32 char in 'x /s'


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]