提交 543f3412 编写于 作者: M Markus Armbruster 提交者: Anthony Liguori

hmp: make memchar-read escape ASCII control chars except \n and \t

Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
Reviewed-by: NEric Blake <eblake@redhat.com>
Signed-off-by: NAnthony Liguori <aliguori@us.ibm.com>
上级 de1cc36e
...@@ -869,6 +869,8 @@ STEXI ...@@ -869,6 +869,8 @@ STEXI
@findex ringbuf_read @findex ringbuf_read
Read and print up to @var{size} bytes from ring buffer character Read and print up to @var{size} bytes from ring buffer character
device @var{device}. device @var{device}.
Certain non-printable characters are printed \uXXXX, where XXXX is the
character code in hexadecimal. Character \ is printed \\.
Bug: can screw up when the buffer contains invalid UTF-8 sequences, Bug: can screw up when the buffer contains invalid UTF-8 sequences,
NUL characters, after the ring buffer lost data, and when reading NUL characters, after the ring buffer lost data, and when reading
stops because the size limit is reached. stops because the size limit is reached.
......
...@@ -679,6 +679,7 @@ void hmp_ringbuf_read(Monitor *mon, const QDict *qdict) ...@@ -679,6 +679,7 @@ void hmp_ringbuf_read(Monitor *mon, const QDict *qdict)
const char *chardev = qdict_get_str(qdict, "device"); const char *chardev = qdict_get_str(qdict, "device");
char *data; char *data;
Error *errp = NULL; Error *errp = NULL;
int i;
data = qmp_ringbuf_read(chardev, size, false, 0, &errp); data = qmp_ringbuf_read(chardev, size, false, 0, &errp);
if (errp) { if (errp) {
...@@ -687,7 +688,19 @@ void hmp_ringbuf_read(Monitor *mon, const QDict *qdict) ...@@ -687,7 +688,19 @@ void hmp_ringbuf_read(Monitor *mon, const QDict *qdict)
return; return;
} }
monitor_printf(mon, "%s\n", data); for (i = 0; data[i]; i++) {
unsigned char ch = data[i];
if (ch == '\\') {
monitor_printf(mon, "\\\\");
} else if ((ch < 0x20 && ch != '\n' && ch != '\t') || ch == 0x7F) {
monitor_printf(mon, "\\u%04X", ch);
} else {
monitor_printf(mon, "%c", ch);
}
}
monitor_printf(mon, "\n");
g_free(data); g_free(data);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册