The debug information in gem5 is really amazing.
You only need to use DPRINTF(FLAGA,"%d",value);
where you want to output debug information.
If you add --debug-flag=FLAGA
when compiling. DPRINTF(FLAGA,"%d",value);
will become printf("%d", value);
otherwise it will become empty
.
This is achieved through conditional compilation. But I don't know how to compile according to FLAG as above. What I think of is this:
#include<stdio.h>
#define NOOP //(void(0))
#undef DCOUT
#undef DPRINTF
#ifdef DEBUG_OUT
#define DPRINTF(...) printf(__VA_ARGS__)
#else
#define DPRINTF(...) NOOP
#endif
#undef DEBUG_OUT
I can use DPRINTF() in some places, but all the debug information is either preserved or disappeared. Can’t it be kept under which option when compiling like gem5? This sentence means that I wrote some debug output.
A(){
DPRINTF("DEBUGA", "%d",val1);
}
B(){
DPRINTF("DEBUGB", "%d", val2);
}
When compiling, if I add --debugflag=DEBUGA
.
`DPRINTF("DEBUGA","%d",val1);` --> `printf("%d",val1);`,
`DPRINTF("DEBUGB", "%d", val2); --> empty
When compiling, if I add --debugflag=DEBUGB
.
`DPRINTF("DEBUGA","%d",val1);` --> empty,
`DPRINTF("DEBUGB", "%d", val2);` -->`printf("%d",val2);.
Can someone give me some suggestions?