Turn DPRINTF macro use into tracepoints
In QEMU our preference for logging information that might be useful during debugging of either the device model or the guest is to use "tracepoints". These are documented in our developer docs here. The basic idea is that you put a format string in a "trace-events" file, and then in the C code you can call trace_foo() with some arguments to cause that trace information to be printed if it is enabled.
However, we still have a lot of older code that defines a debug macro (typically named "DPRINTF") so that you can only enable and disable tracing at compile time. You can find a list of these files with git grep DPRINTF
.
A useful bite-sized task would be to take one of these DPRINTF macros and convert its uses to tracepoints.
Some things to consider:
- Don't try to convert more than one file in each commit
- Start off with just doing a single file to make sure you've got the hang of how our process works
- If you have a plan to work on a particular area of QEMU (for instance, network devices), try to find a file that needs working on that's in that area rather than an unrelated one, so you can get some experience with what that part of QEMU's code looks like
- This will be easier if you have a test case or workload that uses the device you're working on
- You may find that some of the DPRINTF statements don't actually work if you compile them; in that case they'll need fixing during the conversion (see below)
- There may be opportunities for improvement either in tracing more things, or in cleaning up the output strings or information the current DPRINTF macros use. The tracepoints docs have some hints on what makes a good trace event
An intermediate conversion from:
#if 0
#define DPRINTF(fmt, ...) \
printf(fmt, ## __VA_ARGS__)
#else
#define DPRINTF(fmt, ...)
#endif
to:
#ifndef DEBUG_FOO
#define DEBUG_FOO 0
#endif
#define DPRINTF(fmt, ...) \
do { \
if (DEBUG_FOO) { \
printf(fmt, ## __VA_ARGS__); \
} \
while (false)
can be useful to at least ensure compile-time checking of format strings and arguments, even before converting to trace calls.