From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Xen-devel <xen-devel@lists.xen.org>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
Jan Beulich <JBeulich@suse.com>
Subject: [PATCH 3/3] tests/x86emul: Improve the utility of verbose mode
Date: Tue, 6 Mar 2018 20:24:52 +0000 [thread overview]
Message-ID: <1520367892-15055-4-git-send-email-andrew.cooper3@citrix.com> (raw)
In-Reply-To: <1520367892-15055-1-git-send-email-andrew.cooper3@citrix.com>
* Align the function call names, which aligns all subsequent data on the
line.
* Convert x86_segment and X86EMUL_ constants to strings rather than printing
raw numbers.
* Move the printing to the end of the function, and either hexdump the result
or print the failure code.
No change by default as verbose is off.
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>
---
tools/tests/x86_emulator/test_x86_emulator.c | 99 ++++++++++++++++++++++++----
1 file changed, 87 insertions(+), 12 deletions(-)
diff --git a/tools/tests/x86_emulator/test_x86_emulator.c b/tools/tests/x86_emulator/test_x86_emulator.c
index a764d99..6e24637 100644
--- a/tools/tests/x86_emulator/test_x86_emulator.c
+++ b/tools/tests/x86_emulator/test_x86_emulator.c
@@ -16,6 +16,53 @@
#include "xop.h"
#define verbose false /* Switch to true for far more logging. */
+#define fn_width (int)(sizeof("cmpxchg") - 1)
+
+static const char *seg_to_str(enum x86_segment seg)
+{
+ switch ( seg )
+ {
+#define CASE(x) case x86_seg_ ## x: return # x
+ CASE(es);
+ CASE(cs);
+ CASE(ss);
+ CASE(ds);
+ CASE(fs);
+ CASE(gs);
+ CASE(tr);
+ CASE(ldtr);
+ CASE(gdtr);
+ CASE(idtr);
+ CASE(none);
+#undef CASE
+ default: return "??";
+ }
+}
+
+static const char *x86emul_to_str(int rc)
+{
+ switch ( rc )
+ {
+#define CASE(x) case X86EMUL_ ## x: return # x
+ CASE(OKAY);
+ CASE(UNHANDLEABLE);
+ CASE(EXCEPTION);
+ CASE(RETRY);
+ CASE(DONE);
+ CASE(UNIMPLEMENTED);
+#undef CASE
+ default: return "??";
+ }
+}
+
+static void hexdump_newline(const void *ptr, size_t size)
+{
+ const unsigned char *p = ptr;
+
+ for ( ; size; --size, ++p )
+ printf(" %02x", *p);
+ printf("\n");
+}
static void blowfish_set_regs(struct cpu_user_regs *regs)
{
@@ -230,9 +277,6 @@ static int read(
emul_save_fpu_state();
- if ( verbose )
- printf("** %s(%u, %p,, %u,)\n", __func__, seg, (void *)offset, bytes);
-
switch ( seg )
{
uint64_t value;
@@ -292,6 +336,17 @@ static int read(
memcpy(p_data, (void *)offset, bytes);
out:
+ if ( verbose )
+ {
+ printf("** %*s(%s, %p,, %u,) =>",
+ fn_width, __func__, seg_to_str(seg), (void *)offset, bytes);
+
+ if ( rc )
+ printf(" fail %s\n", x86emul_to_str(rc));
+ else
+ hexdump_newline(p_data, bytes);
+ }
+
emul_restore_fpu_state();
return rc;
@@ -306,11 +361,15 @@ static int fetch(
{
emul_save_fpu_state();
- if ( verbose )
- printf("** %s(%u, %p,, %u,)\n", __func__, seg, (void *)offset, bytes);
-
memcpy(p_data, (void *)offset, bytes);
+ if ( verbose )
+ {
+ printf("** %*s(%s, %p,, %u,) =>",
+ fn_width, __func__, seg_to_str(seg), (void *)offset, bytes);
+ hexdump_newline(p_data, bytes);
+ }
+
emul_restore_fpu_state();
return X86EMUL_OKAY;
@@ -327,9 +386,6 @@ static int write(
emul_save_fpu_state();
- if ( verbose )
- printf("** %s(%u, %p,, %u,)\n", __func__, seg, (void *)offset, bytes);
-
if ( !is_x86_user_segment(seg) )
{
rc = X86EMUL_UNHANDLEABLE;
@@ -339,6 +395,17 @@ static int write(
memcpy((void *)offset, p_data, bytes);
out:
+ if ( verbose )
+ {
+ printf("** %*s(%s, %p,, %u,) =>",
+ fn_width, __func__, seg_to_str(seg), (void *)offset, bytes);
+
+ if ( rc )
+ printf(" fail %s\n", x86emul_to_str(rc));
+ else
+ hexdump_newline(p_data, bytes);
+ }
+
emul_restore_fpu_state();
return rc;
@@ -356,9 +423,6 @@ static int cmpxchg(
emul_save_fpu_state();
- if ( verbose )
- printf("** %s(%u, %p,, %u,)\n", __func__, seg, (void *)offset, bytes);
-
if ( !is_x86_user_segment(seg) )
{
rc = X86EMUL_UNHANDLEABLE;
@@ -368,6 +432,17 @@ static int cmpxchg(
memcpy((void *)offset, new, bytes);
out:
+ if ( verbose )
+ {
+ printf("** %*s(%s, %p,, %u,) =>",
+ fn_width, __func__, seg_to_str(seg), (void *)offset, bytes);
+
+ if ( rc )
+ printf(" fail %s\n", x86emul_to_str(rc));
+ else
+ hexdump_newline(new, bytes);
+ }
+
emul_restore_fpu_state();
return rc;
--
2.1.4
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
next prev parent reply other threads:[~2018-03-06 20:24 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-06 20:24 [PATCH 0/3] tests/x86emul: Fix register corruption in the test harness Andrew Cooper
2018-03-06 20:24 ` [PATCH 1/3] tests/x86emul: Helpers to save and restore FPU state Andrew Cooper
2018-03-09 11:21 ` Jan Beulich
2018-03-09 12:37 ` Jan Beulich
2018-03-09 13:38 ` Jan Beulich
2018-03-09 13:43 ` Andrew Cooper
2018-03-06 20:24 ` [PATCH 2/3] tests/x86emul: Save and restore FPU state in the emulator callbacks Andrew Cooper
2018-03-09 11:41 ` Jan Beulich
2018-03-09 11:45 ` Andrew Cooper
2018-03-09 11:57 ` Jan Beulich
2018-03-06 20:24 ` Andrew Cooper [this message]
2018-03-09 11:48 ` [PATCH 3/3] tests/x86emul: Improve the utility of verbose mode Jan Beulich
2018-03-06 20:37 ` [PATCH 4/3] tests/x86emul: Save and restore FPU state in the middle of emulation Andrew Cooper
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=1520367892-15055-4-git-send-email-andrew.cooper3@citrix.com \
--to=andrew.cooper3@citrix.com \
--cc=JBeulich@suse.com \
--cc=xen-devel@lists.xen.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 NNTP newsgroup(s).