Skip to content

Commit 9a22f0d

Browse files
gdb ChangeLog
* 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. gdb/doc ChangeLog * gdb.texinfo (Examining memory): Update for change in string display with explicit size. gdb/testsuite ChangeLog * gdb.base/charset.c (Strin16, String32): New variables. * gdb.base/charset.exp (gdb_test): Test correct display of 16 or 32 bit strings.
1 parent 32d7376 commit 9a22f0d

File tree

9 files changed

+104
-9
lines changed

9 files changed

+104
-9
lines changed

gdb/ChangeLog

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
2010-04-22 Pierre Muller <muller@ics.u-strasbg.fr>
2+
3+
* gdbtypes.h (builtin_type): Add builtin_char16 and builtin_char32
4+
fields.
5+
* gdbtypes.c (gdbtypes_post_init): Set builtin_char16 and
6+
builtin_char32 fields.
7+
* printcmd.c (decode_format): Set char size to '\0'
8+
for strings unless explicit size is given.
9+
(print_formatted): Correct calculation of NEXT_ADDRESS
10+
for 16 or 32 bit strings.
11+
(do_examine): Do not force byte size for strings.
12+
Use builtin_char16 and builtin_char32 types to display
13+
16 or 32 bit-wide strings.
14+
(x_command): Set LAST_SIZE to 'b' for string type.
15+
116
2010-04-21 H.J. Lu <hongjiu.lu@intel.com>
217

318
PR corefiles/11523

gdb/doc/ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2010-04-22 Pierre Muller <muller@ics.u-strasbg.fr>
2+
3+
* gdb.texinfo (Examining memory): Update for change in string
4+
display with explicit size.
5+
16
2010-04-19 Pedro Alves <pedro@codesourcery.com>
27

38
PR breakpoints/8554.

gdb/doc/gdb.texinfo

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7262,8 +7262,16 @@ Giant words (eight bytes).
72627262
@end table
72637263

72647264
Each time you specify a unit size with @code{x}, that size becomes the
7265-
default unit the next time you use @code{x}. (For the @samp{s} and
7266-
@samp{i} formats, the unit size is ignored and is normally not written.)
7265+
default unit the next time you use @code{x}. For the @samp{i} format,
7266+
the unit size is ignored and is normally not written. For the @samp{s} format,
7267+
the unit size defaults to @samp{b}, unless it is explicitly given.
7268+
Use @kbd{x /hs} to display 16-bit char strings and @kbd{x /ws} to display
7269+
32-bit strings. The next use of @kbd{x /s} will again display 8-bit strings.
7270+
Note that the results depend on the programming language of the
7271+
current compilation unit. If the language is C, the @samp{s}
7272+
modifier will use the UTF-16 encoding while @samp{w} will use
7273+
UTF-32. The encoding is set by the programming language and cannot
7274+
be altered.
72677275

72687276
@item @var{addr}, starting display address
72697277
@var{addr} is the address where you want @value{GDBN} to begin displaying

gdb/gdbtypes.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3474,6 +3474,13 @@ gdbtypes_post_init (struct gdbarch *gdbarch)
34743474
TYPE_NOTTEXT (builtin_type->builtin_int8) = 1;
34753475
TYPE_NOTTEXT (builtin_type->builtin_uint8) = 1;
34763476

3477+
/* Wide character types. */
3478+
builtin_type->builtin_char16
3479+
= arch_integer_type (gdbarch, 16, 0, "char16_t");
3480+
builtin_type->builtin_char32
3481+
= arch_integer_type (gdbarch, 32, 0, "char32_t");
3482+
3483+
34773484
/* Default data/code pointer types. */
34783485
builtin_type->builtin_data_ptr
34793486
= lookup_pointer_type (builtin_type->builtin_void);

gdb/gdbtypes.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,6 +1099,9 @@ struct builtin_type
10991099
struct type *builtin_int128;
11001100
struct type *builtin_uint128;
11011101

1102+
/* Wide character types. */
1103+
struct type *builtin_char16;
1104+
struct type *builtin_char32;
11021105

11031106
/* Pointer types. */
11041107

gdb/printcmd.c

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,11 @@ decode_format (char **string_ptr, int oformat, int osize)
260260
/* Characters default to one byte. */
261261
val.size = osize ? 'b' : osize;
262262
break;
263+
case 's':
264+
/* Display strings with byte size chars unless explicitly specified. */
265+
val.size = '\0';
266+
break;
267+
263268
default:
264269
/* The default is the size most recently specified. */
265270
val.size = osize;
@@ -295,7 +300,7 @@ print_formatted (struct value *val, int size,
295300
next_address = (value_address (val)
296301
+ val_print_string (elttype,
297302
value_address (val), -1,
298-
stream, options));
303+
stream, options) * len);
299304
}
300305
return;
301306

@@ -802,9 +807,11 @@ do_examine (struct format_data fmt, struct gdbarch *gdbarch, CORE_ADDR addr)
802807
next_gdbarch = gdbarch;
803808
next_address = addr;
804809

805-
/* String or instruction format implies fetch single bytes
806-
regardless of the specified size. */
807-
if (format == 's' || format == 'i')
810+
/* Instruction format implies fetch single bytes
811+
regardless of the specified size.
812+
The case of strings is handled in decode_format, only explicit
813+
size operator are not changed to 'b'. */
814+
if (format == 'i')
808815
size = 'b';
809816

810817
if (size == 'a')
@@ -831,6 +838,27 @@ do_examine (struct format_data fmt, struct gdbarch *gdbarch, CORE_ADDR addr)
831838
else if (size == 'g')
832839
val_type = builtin_type (next_gdbarch)->builtin_int64;
833840

841+
if (format == 's')
842+
{
843+
struct type *char_type = NULL;
844+
/* Search for "char16_t" or "char32_t" types or fall back to 8-bit char
845+
if type is not found. */
846+
if (size == 'h')
847+
char_type = builtin_type (next_gdbarch)->builtin_char16;
848+
else if (size == 'w')
849+
char_type = builtin_type (next_gdbarch)->builtin_char32;
850+
if (char_type)
851+
val_type = char_type;
852+
else
853+
{
854+
if (size != '\0' && size != 'b')
855+
warning (_("Unable to display strings with size '%c', using 'b' \
856+
instead."), size);
857+
size = 'b';
858+
val_type = builtin_type (next_gdbarch)->builtin_int8;
859+
}
860+
}
861+
834862
maxelts = 8;
835863
if (size == 'w')
836864
maxelts = 4;
@@ -1413,8 +1441,11 @@ x_command (char *exp, int from_tty)
14131441
do_examine (fmt, next_gdbarch, next_address);
14141442

14151443
/* If the examine succeeds, we remember its size and format for next
1416-
time. */
1417-
last_size = fmt.size;
1444+
time. Set last_size to 'b' for strings. */
1445+
if (fmt.format == 's')
1446+
last_size = 'b';
1447+
else
1448+
last_size = fmt.size;
14181449
last_format = fmt.format;
14191450

14201451
/* Set a couple of internal variables if appropriate. */

gdb/testsuite/ChangeLog

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
Wed Apr 21 12:47:26 2010 Chris Moller <cmoller@redhat.com>
1+
2010-04-22 Pierre Muller <muller@ics.u-strasbg.fr>
2+
3+
* gdb.base/charset.c (Strin16, String32): New variables.
4+
* gdb.base/charset.exp (gdb_test): Test correct display
5+
of 16 or 32 bit strings.
6+
7+
2010-04-21 Chris Moller <cmoller@redhat.com>
28

39
PR 9167
410
* gdb.cp/Makefile.in (EXECUTABLES): Added pr9167.

gdb/testsuite/gdb.base/charset.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ typedef unsigned int char32_t;
6565
char16_t uvar;
6666
char32_t Uvar;
6767

68+
char16_t *String16;
69+
char32_t *String32;
70+
6871
/* A typedef to a typedef should also work. */
6972
typedef wchar_t my_wchar_t;
7073
my_wchar_t myvar;

gdb/testsuite/gdb.base/charset.exp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,4 +616,21 @@ gdb_test "print 'a' == 'a' || 'b' == 'b'" \
616616
".* = 1" \
617617
"EVAL_SKIP cleanup handling regression test"
618618

619+
620+
proc string_display { var_name set_prefix x_size x_type} {
621+
gdb_test "set ${var_name} = ${set_prefix}\"Test String\\0with zeroes\"" "" "Assign ${var_name} with prefix ${set_prefix}"
622+
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"
623+
}
624+
625+
string_display String16 u h u
626+
if {$wchar_size == 2} {
627+
string_display String16 L h u
628+
}
629+
630+
string_display String32 U w U
631+
if {$wchar_size == 4} {
632+
string_display String32 L w U
633+
}
634+
635+
619636
gdb_exit

0 commit comments

Comments
 (0)