On 06/05/2015 09:55 AM, Alex Bennée wrote: > To avoid cluttering the code with #ifdef legs we wrap up the print > statements into a tlb_debug() macro. As access to the virtual TLB can > get quite heavy defining DEBUG_TLB_LOG will ensure all the logs go to > the qemu_log target of CPU_LOG_MMU instead of stderr. > > I've also removed DEBUG_TLB_CHECK which wasn't used. > > Signed-off-by: Alex Bennée > --- > cputlb.c | 47 ++++++++++++++++++++++++++++------------------- > 1 file changed, 28 insertions(+), 19 deletions(-) > > diff --git a/cputlb.c b/cputlb.c > index 7606548..ddb7b59 100644 > --- a/cputlb.c > +++ b/cputlb.c > @@ -30,8 +30,23 @@ > #include "exec/ram_addr.h" > #include "tcg/tcg.h" > > -//#define DEBUG_TLB > -//#define DEBUG_TLB_CHECK > +/* DEBUG defines, enable DEBUG_TLB_LOG to log to the CPU_LOG_MMU target */ > +/* #define DEBUG_TLB */ > +/* #define DEBUG_TLB_LOG */ > + > +#ifdef DEBUG_TLB > +#ifdef DEBUG_TLB_LOG > +#define tlb_debug(fmt, ...) do { \ > + qemu_log_mask(CPU_LOG_MMU, "%s: " fmt, __func__, ## __VA_ARGS__); \ > + } while (0) > +#else > +#define tlb_debug(fmt, ...) do { \ > + fprintf(stderr, "%s: " fmt, __func__, ## __VA_ARGS__); \ > + } while (0) > +#endif > +#else > +#define tlb_debug(fmt, ...) do { } while (0) This is prone to bitrot. Better would be: #ifdef DEBUG_TLB # define DEBUG_TLB_GATE 1 # ifdef DEBUG_TLB_LOG # define DEBUG_TLB_LOG_GATE 1 # else # define DEBUG_TLB_LOG_GATE 0 # endif #else # define DEBUG_TLB_GATE 0 # define DEBUG_TLB_LOG_GATE 0 #endif #define tlb_debug(fmt, ...) do { \ if (DEBUG_TLB_LOG_GATE) { \ qemu_log_mask(CPU_LOG_MMU, "%s: " fmt, __func__, \ ## __VA_ARGS__); \ } else if (DEBUG_TLB_GATE) { \ fprintf(stderr, "%s: " fmt, __func__, ## __VA_ARGS__); \ } \ } while (0) because then tlb_debug() will automatically guarantee compiler compliance to correct fmt vs. argument, while still benefitting from no increase in code size (all compilers can properly optimize if(0) blocks). -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org