From: Julian Seward Date: Fri, 29 Oct 2004 00:41:29 +0000 (+0000) Subject: Majorly improve debug printing. Now vex_traceflags contains 8 bits X-Git-Tag: svn/VALGRIND_3_0_1^2~881 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e21aacdd35e10e546442eb88a6cf07cdee1ec544;p=thirdparty%2Fvalgrind.git Majorly improve debug printing. Now vex_traceflags contains 8 bits which control phase printing. git-svn-id: svn://svn.valgrind.org/vex/trunk@453 --- diff --git a/VEX/priv/guest-x86/toIR.c b/VEX/priv/guest-x86/toIR.c index ab64b8c71f..906a601d0d 100644 --- a/VEX/priv/guest-x86/toIR.c +++ b/VEX/priv/guest-x86/toIR.c @@ -48,10 +48,6 @@ /* CONST */ static Bool host_is_bigendian; -/* Are we being verbose? */ -/* CONST */ -static Bool print_codegen; - /* Pointer to the guest code area. */ /* CONST */ static UChar* guest_code; @@ -68,12 +64,12 @@ static IRBB* irbb; /*--- Debugging output ---*/ /*------------------------------------------------------------*/ -#define DIP(format, args...) \ - if (print_codegen) \ +#define DIP(format, args...) \ + if (vex_traceflags & VEX_TRACE_FE) \ vex_printf(format, ## args) -#define DIS(buf, format, args...) \ - if (print_codegen) \ +#define DIS(buf, format, args...) \ + if (vex_traceflags & VEX_TRACE_FE) \ vex_sprintf(buf, format, ## args) @@ -162,15 +158,12 @@ IRBB* bbToIR_X86Instr ( UChar* x86code, /* Set up globals. */ host_is_bigendian = host_bigendian; - print_codegen = vex_verbosity >= 1; guest_code = x86code; guest_eip_bbstart = (Addr32)guest_eip_start; irbb = emptyIRBB(); vassert((guest_eip_start >> 32) == 0); - DIP("Original x86 code to IR:\n\n"); - /* Delta keeps track of how far along the x86code array we have so far gone. */ delta = 0; @@ -193,7 +186,7 @@ IRBB* bbToIR_X86Instr ( UChar* x86code, dres = disInstr( resteerOK, delta, &size, &guest_next ); /* Print the resulting IR, if needed. */ - if (print_codegen) { + if (vex_traceflags & VEX_TRACE_FE) { for (i = first_stmt_idx; i < irbb->stmts_used; i++) { vex_printf(" "); ppIRStmt(irbb->stmts[i]); @@ -203,7 +196,7 @@ IRBB* bbToIR_X86Instr ( UChar* x86code, if (dres == Dis_StopHere) { vassert(irbb->next != NULL); - if (print_codegen) { + if (vex_traceflags & VEX_TRACE_FE) { vex_printf(" "); vex_printf( "goto {"); ppIRJumpKind(irbb->jumpkind); @@ -2503,7 +2496,7 @@ UInt dis_Grp2 ( UChar sorb, /* Save result, and finish up. */ if (epartIsReg(modrm)) { putIReg(sz, eregOfRM(modrm), mkexpr(dst1)); - if (print_codegen) { + if (vex_traceflags & VEX_TRACE_FE) { vex_printf("%s%c ", nameGrp2(gregOfRM(modrm)), nameISize(sz) ); if (shift_expr_txt) @@ -2514,7 +2507,7 @@ UInt dis_Grp2 ( UChar sorb, } } else { storeLE(mkexpr(addr), mkexpr(dst1)); - if (print_codegen) { + if (vex_traceflags & VEX_TRACE_FE) { vex_printf("%s%c ", nameGrp2(gregOfRM(modrm)), nameISize(sz) ); if (shift_expr_txt) diff --git a/VEX/priv/host-x86/isel.c b/VEX/priv/host-x86/isel.c index 551950b26a..e63a557077 100644 --- a/VEX/priv/host-x86/isel.c +++ b/VEX/priv/host-x86/isel.c @@ -208,7 +208,7 @@ static void lookupIRTemp64 ( HReg* vrHI, HReg* vrLO, ISelEnv* env, IRTemp tmp ) static void addInstr ( ISelEnv* env, X86Instr* instr ) { addHInstr(env->code, instr); - if (vex_verbosity > 0) { + if (vex_traceflags & VEX_TRACE_VCODE) { ppX86Instr(instr); vex_printf("\n"); } @@ -2014,8 +2014,8 @@ static HReg iselDblExpr ( ISelEnv* env, IRExpr* e ) static void iselStmt ( ISelEnv* env, IRStmt* stmt ) { - if (vex_verbosity > 0) { - vex_printf("-- "); + if (vex_traceflags & VEX_TRACE_VCODE) { + vex_printf("\n-- "); ppIRStmt(stmt); vex_printf("\n"); } @@ -2219,8 +2219,8 @@ static void iselStmt ( ISelEnv* env, IRStmt* stmt ) static void iselNext ( ISelEnv* env, IRExpr* next, IRJumpKind jk ) { X86RI* ri; - if (vex_verbosity > 0) { - vex_printf("-- goto {"); + if (vex_traceflags & VEX_TRACE_VCODE) { + vex_printf("\n-- goto {"); ppIRJumpKind(jk); vex_printf("} "); ppIRExpr(next); diff --git a/VEX/priv/main/vex_globals.c b/VEX/priv/main/vex_globals.c index 1ab0866824..137311aca0 100644 --- a/VEX/priv/main/vex_globals.c +++ b/VEX/priv/main/vex_globals.c @@ -28,8 +28,8 @@ void (*vex_log_bytes) ( Char*, Int nbytes ) = NULL; /* debug paranoia level */ Int vex_debuglevel = 0; -/* verbosity level */ -Int vex_verbosity = 0; +/* trace flags */ +Int vex_traceflags = 0; /* Are we supporting valgrind checking? */ Bool vex_valgrind_support = False; @@ -42,3 +42,4 @@ VexControl vex_control = { 0,0,False,0,0,0 }; /*---------------------------------------------------------------*/ /*--- end vex_globals.c ---*/ /*---------------------------------------------------------------*/ + diff --git a/VEX/priv/main/vex_globals.h b/VEX/priv/main/vex_globals.h index 0c1417d6f4..e14b0812a1 100644 --- a/VEX/priv/main/vex_globals.h +++ b/VEX/priv/main/vex_globals.h @@ -29,8 +29,8 @@ extern void (*vex_log_bytes) ( Char*, Int nbytes ); /* debug paranoia level */ extern Int vex_debuglevel; -/* verbosity level */ -extern Int vex_verbosity; +/* trace flags */ +extern Int vex_traceflags; /* Are we supporting valgrind checking? */ extern Bool vex_valgrind_support; @@ -39,6 +39,17 @@ extern Bool vex_valgrind_support; extern VexControl vex_control; +/* vex_traceflags values */ +#define VEX_TRACE_FE (1 << 7) /* show conversion into IR */ +#define VEX_TRACE_OPT1 (1 << 6) /* show after initial opt */ +#define VEX_TRACE_INST (1 << 5) /* show after instrumentation */ +#define VEX_TRACE_OPT2 (1 << 4) /* show after second opt */ +#define VEX_TRACE_TREES (1 << 3) /* show after tree building */ +#define VEX_TRACE_VCODE (1 << 2) /* show selected insns */ +#define VEX_TRACE_RCODE (1 << 1) /* show after reg-alloc */ +#define VEX_TRACE_ASM (1 << 0) /* show final assembly */ + + #endif /* ndef __VEX_GLOBALS_H */ /*---------------------------------------------------------------*/ diff --git a/VEX/priv/main/vex_main.c b/VEX/priv/main/vex_main.c index c1887dff7a..410e5f7ca4 100644 --- a/VEX/priv/main/vex_main.c +++ b/VEX/priv/main/vex_main.c @@ -44,8 +44,6 @@ void LibVEX_Init ( void (*log_bytes) ( Char*, Int nbytes ), /* debug paranoia level */ Int debuglevel, - /* initial verbosity level */ - Int verbosity, /* Are we supporting valgrind checking? */ Bool valgrind_support, /* Control ... */ @@ -62,7 +60,6 @@ void LibVEX_Init ( vassert(failure_exit); vassert(log_bytes); vassert(debuglevel >= 0); - vassert(verbosity >= 0); vassert(vcon->iropt_verbosity >= 0); vassert(vcon->iropt_level >= 0); @@ -103,7 +100,6 @@ void LibVEX_Init ( /* Really start up .. */ vex_debuglevel = debuglevel; - vex_verbosity = verbosity; vex_valgrind_support = valgrind_support; vex_control = *vcon; vex_initdone = True; @@ -135,8 +131,8 @@ TranslateResult LibVEX_Translate ( HWord (*tool_findhelper) ( Char* ), /* IN: optionally, an access check function for guest code. */ Bool (*byte_accessible) ( Addr64 ), - /* IN: if > 0, use this verbosity for this bb */ - Int bb_verbosity + /* IN: debug: trace vex activity at various points */ + Int traceflags ) { /* This the bundle of functions we need to do the back-end stuff @@ -164,7 +160,7 @@ TranslateResult LibVEX_Translate ( IRBB* irbb; HInstrArray* vcode; HInstrArray* rcode; - Int i, j, k, out_used, saved_verbosity, guest_sizeB; + Int i, j, k, out_used, guest_sizeB; UChar insn_bytes[32]; IRType guest_word_size; @@ -186,9 +182,7 @@ TranslateResult LibVEX_Translate ( preciseMemExnsFn = NULL; guest_word_size = Ity_INVALID; - saved_verbosity = vex_verbosity; - if (bb_verbosity > 0) - vex_verbosity = bb_verbosity; + vex_traceflags = traceflags; vassert(vex_initdone); LibVEX_ClearTemporary(False); @@ -228,6 +222,11 @@ TranslateResult LibVEX_Translate ( vpanic("LibVEX_Translate: unsupported guest insn set"); } + if (vex_traceflags & VEX_TRACE_FE) + vex_printf("\n------------------------" + " Front end " + "------------------------\n\n"); + irbb = bbToIR ( guest_bytes, guest_bytes_addr, guest_bytes_read, @@ -237,18 +236,17 @@ TranslateResult LibVEX_Translate ( if (irbb == NULL) { /* Access failure. */ LibVEX_ClearTemporary(False); - vex_verbosity = saved_verbosity; + vex_traceflags = 0; return TransAccessFail; } /* If debugging, show the raw guest bytes for this bb. */ - if (vex_verbosity >= 2) { + if (vex_traceflags & VEX_TRACE_FE) { UChar* p = guest_bytes; - vex_printf("\n"); vex_printf(". 0 %llx %d\n.", guest_bytes_addr, *guest_bytes_read ); for (i = 0; i < *guest_bytes_read; i++) vex_printf(" %02x", (Int)p[i] ); - vex_printf("\n"); + vex_printf("\n\n"); } /* Sanity check the initial IR. */ @@ -259,8 +257,10 @@ TranslateResult LibVEX_Translate ( guest_bytes_addr ); sanityCheckIRBB(irbb, guest_word_size); - if (vex_verbosity > 0) { - vex_printf("\n-------- After IR optimisation --------\n"); + if (vex_traceflags & VEX_TRACE_OPT1) { + vex_printf("\n------------------------" + " After pre-instr IR optimisation " + "------------------------\n\n"); ppIRBB ( irbb ); vex_printf("\n"); } @@ -271,15 +271,41 @@ TranslateResult LibVEX_Translate ( if (instrument2) irbb = (*instrument2)(irbb, guest_layout); + if (vex_traceflags & VEX_TRACE_INST) { + vex_printf("\n------------------------" + " After instrumentation " + "------------------------\n\n"); + ppIRBB ( irbb ); + vex_printf("\n"); + } + if (instrument1 || instrument2) sanityCheckIRBB(irbb, guest_word_size); /* Turn it into virtual-registerised code. */ do_deadcode_BB( irbb ); do_treebuild_BB( irbb ); + + if (vex_traceflags & VEX_TRACE_TREES) { + vex_printf("\n------------------------" + " After tree-building " + "------------------------\n\n"); + ppIRBB ( irbb ); + vex_printf("\n"); + } + + if (vex_traceflags & VEX_TRACE_VCODE) + vex_printf("\n------------------------" + " Instruction selection " + "------------------------\n"); + vcode = iselBB ( irbb, findHelper, tool_findhelper ); - if (vex_verbosity > 0) { + if (vex_traceflags & VEX_TRACE_VCODE) + vex_printf("\n"); + +#if 0 + if (vex_traceflags & VEX_TRACE_VCODE) { vex_printf("\n-------- Virtual registerised code --------\n"); for (i = 0; i < vcode->arr_used; i++) { vex_printf("%3d ", i); @@ -288,6 +314,7 @@ TranslateResult LibVEX_Translate ( } vex_printf("\n"); } +#endif /* Register allocate. */ rcode = doRegisterAllocation ( vcode, available_real_regs, @@ -296,8 +323,10 @@ TranslateResult LibVEX_Translate ( genSpill, genReload, guest_sizeB, ppInstr, ppReg ); - if (vex_verbosity > 0) { - vex_printf("\n-------- Post-regalloc code --------\n"); + if (vex_traceflags & VEX_TRACE_RCODE) { + vex_printf("\n------------------------" + " Register-allocated code " + "------------------------\n\n"); for (i = 0; i < rcode->arr_used; i++) { vex_printf("%3d ", i); ppInstr(rcode->arr[i]); @@ -307,14 +336,20 @@ TranslateResult LibVEX_Translate ( } /* Assemble */ + if (vex_traceflags & VEX_TRACE_ASM) { + vex_printf("\n------------------------" + " Assembly " + "------------------------\n\n"); + } + out_used = 0; /* tracks along the host_bytes array */ for (i = 0; i < rcode->arr_used; i++) { - if (vex_verbosity > 2) { + if (vex_traceflags & VEX_TRACE_ASM) { ppInstr(rcode->arr[i]); vex_printf("\n"); } j = (*emit)( insn_bytes, 32, rcode->arr[i] ); - if (vex_verbosity > 2) { + if (vex_traceflags & VEX_TRACE_ASM) { for (k = 0; k < j; k++) if (insn_bytes[k] < 16) vex_printf("0%x ", (UInt)insn_bytes[k]); @@ -324,7 +359,7 @@ TranslateResult LibVEX_Translate ( } if (out_used + j > host_bytes_size) { LibVEX_ClearTemporary(False); - vex_verbosity = saved_verbosity; + vex_traceflags = 0; return TransOutputFull; } for (k = 0; k < j; k++) { @@ -335,10 +370,9 @@ TranslateResult LibVEX_Translate ( } *host_bytes_used = out_used; - // LibVEX_ClearTemporary(True); LibVEX_ClearTemporary(False); - vex_verbosity = saved_verbosity; + vex_traceflags = 0; return TransOK; } diff --git a/VEX/pub/libvex.h b/VEX/pub/libvex.h index dd168407d7..58412ee735 100644 --- a/VEX/pub/libvex.h +++ b/VEX/pub/libvex.h @@ -64,8 +64,6 @@ extern void LibVEX_Init ( void (*log_bytes) ( Char*, Int nbytes ), /* debug paranoia level */ Int debuglevel, - /* verbosity level */ - Int verbosity, /* Are we supporting valgrind checking? */ Bool valgrind_support, /* Control ... */ @@ -134,8 +132,8 @@ TranslateResult LibVEX_Translate ( HWord (*tool_findhelper) ( Char* ), /* IN: optionally, an access check function for guest code. */ Bool (*byte_accessible) ( Addr64 ), - /* IN: if > 0, use this verbosity for this bb */ - Int bb_verbosity + /* IN: debug: trace vex activity at various points */ + Int traceflags );