diff options
author | Pierre Muller <muller@sourceware.org> | 2010-04-21 23:21:04 +0000 |
---|---|---|
committer | Pierre Muller <muller@sourceware.org> | 2010-04-21 23:21:04 +0000 |
commit | 9a22f0d0aeec70f4ee1908008f3a2defaad6f7dd (patch) | |
tree | a36134950efba04d0c0104c79b7714b47e7e5d49 | |
parent | 32d7376d07d6b1ae69b5e15d6b546a07f9fee446 (diff) | |
download | binutils-gdb-9a22f0d0aeec70f4ee1908008f3a2defaad6f7dd.tar.gz |
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.
-rw-r--r-- | gdb/ChangeLog | 15 | ||||
-rw-r--r-- | gdb/doc/ChangeLog | 5 | ||||
-rw-r--r-- | gdb/doc/gdb.texinfo | 12 | ||||
-rw-r--r-- | gdb/gdbtypes.c | 7 | ||||
-rw-r--r-- | gdb/gdbtypes.h | 3 | ||||
-rw-r--r-- | gdb/printcmd.c | 43 | ||||
-rw-r--r-- | gdb/testsuite/ChangeLog | 8 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/charset.c | 3 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/charset.exp | 17 |
9 files changed, 104 insertions, 9 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 995aa804dbe..4fe34f5f317 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,18 @@ +2010-04-22 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-21 H.J. Lu <hongjiu.lu@intel.com> PR corefiles/11523 diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog index 243ef326688..84814a0223c 100644 --- a/gdb/doc/ChangeLog +++ b/gdb/doc/ChangeLog @@ -1,3 +1,8 @@ +2010-04-22 Pierre Muller <muller@ics.u-strasbg.fr> + + * gdb.texinfo (Examining memory): Update for change in string + display with explicit size. + 2010-04-19 Pedro Alves <pedro@codesourcery.com> PR breakpoints/8554. diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 09244300480..97a5531c47d 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -7262,8 +7262,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 diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index f6de8784b84..a40b717a8cb 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -3474,6 +3474,13 @@ gdbtypes_post_init (struct gdbarch *gdbarch) TYPE_NOTTEXT (builtin_type->builtin_int8) = 1; TYPE_NOTTEXT (builtin_type->builtin_uint8) = 1; + /* Wide 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); diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h index b1e1d0cac79..76716db3781 100644 --- a/gdb/gdbtypes.h +++ b/gdb/gdbtypes.h @@ -1099,6 +1099,9 @@ struct builtin_type struct type *builtin_int128; struct type *builtin_uint128; + /* Wide character types. */ + struct type *builtin_char16; + struct type *builtin_char32; /* Pointer types. */ diff --git a/gdb/printcmd.c b/gdb/printcmd.c index c2468d01353..be6a8a5fa4b 100644 --- a/gdb/printcmd.c +++ b/gdb/printcmd.c @@ -260,6 +260,11 @@ decode_format (char **string_ptr, int oformat, int osize) /* 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 size, 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, struct gdbarch *gdbarch, CORE_ADDR addr) 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 in 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, struct gdbarch *gdbarch, CORE_ADDR addr) 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; @@ -1413,8 +1441,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. */ diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index a096256b811..5bba1976973 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,4 +1,10 @@ -Wed Apr 21 12:47:26 2010 Chris Moller <cmoller@redhat.com> +2010-04-22 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. + +2010-04-21 Chris Moller <cmoller@redhat.com> PR 9167 * gdb.cp/Makefile.in (EXECUTABLES): Added pr9167. diff --git a/gdb/testsuite/gdb.base/charset.c b/gdb/testsuite/gdb.base/charset.c index 6cd01f759f6..d7ed8659d4d 100644 --- a/gdb/testsuite/gdb.base/charset.c +++ b/gdb/testsuite/gdb.base/charset.c @@ -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; diff --git a/gdb/testsuite/gdb.base/charset.exp b/gdb/testsuite/gdb.base/charset.exp index 9820632e964..8d1d6543ad8 100644 --- a/gdb/testsuite/gdb.base/charset.exp +++ b/gdb/testsuite/gdb.base/charset.exp @@ -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 |