[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH 3/3] tests/x86emul: Improve the utility of verbose mode
* 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@xxxxxxxxxx> --- CC: Jan Beulich <JBeulich@xxxxxxxx> --- 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@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |