From: "Pierre Muller" <pierre.muller@ics-cnrs.unistra.fr>
To: <gdb-patches@sourceware.org>
Subject: [RFC] Allow explicit 16 or 32 char in 'x /s'
Date: Wed, 17 Mar 2010 22:43:00 -0000 [thread overview]
Message-ID: <000f01cac623$2ec3a850$8c4af8f0$@muller@ics-cnrs.unistra.fr> (raw)
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')
next reply other threads:[~2010-03-17 22:43 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-03-17 22:43 Pierre Muller [this message]
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
[not found] <11484.4708740295$1268865815@news.gmane.org>
2010-03-18 22:08 ` 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
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='000f01cac623$2ec3a850$8c4af8f0$@muller@ics-cnrs.unistra.fr' \
--to=pierre.muller@ics-cnrs.unistra.fr \
--cc=gdb-patches@sourceware.org \
/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).