You should explain how you do your debugging printf. A simple way could be to have a macro like
bool debug_flag; // to be set in the debugger or at initialization pthread_mutex_t debug_mutex = PTHREAD_MUTEX_INITIALIZER; #define debugprintf(Fmt,...) debugprintf_at(__FILE__,__LINE__,Fmt,__VA_ARGS__) #ifndef NDEBUG #define debugprintf_at(Fil,Lin,Fmt,...) do {if (debug_flag) { \ pthread_mutex_lock(&debug_mutex); \ fprintf (stderr, "%s:%d %s:" Fmt, Fil, Lin, __func__, \ ##__VA_ARGS__); \ pthread_mutex_unlock(&debug_mutex); } \ } while(0) #else #define debugprintf(Fmt,...) do {} while(0) #endif
(it uses a mutex because you don't want to mix debug printf messages from different threads; if you don't use any thread, remove the mutex and its locking.)
If your question is how to find all debug printf in a huge software (having its source code), you could try with grep or with much fancier things like GCC plugins or MELT extension. But such an approach (GCC customization) takes time (week or more of your work) and is worth only for huge software base (eg million of lines of source).
For a not too big software, just examine manually all printf in your code and replace those you think are for debugging with a debugprintf macro invocation.