6

I use a LOG_DEBUG function to print debug information to the screen. I used a #define _DEBUG to disable LOG_DEBUG function by defining _DEBUG FLAG in compile time (release time). but linux strings commands of release build app still shows debug strings which exists in the compiled app. so what is the alternatives to eliminate arguments of LOG_DEBUG?

#ifdef _DEBUG
#define LOG_DEBUG(fmt, ...) printf("[D][%s:%d %s]", __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__)
#else
#define LOG_DEBUG(fmt, ...)
#endif


LOG_DEBUG("this is a debug string");     // "this is a debug string" exists in app release build yet

the compiler I use: ARM/Thumb C/C++ Compiler, RVCT3.1 [Build 569]

optimization: -O3

jafar
  • 345
  • 4
  • 11
  • Please edit your question to include the compiler name and version. Have you tried changing the optimization settings? – r3mainer Jun 01 '17 at 21:31
  • I guess *one* way would be to surround **each** debug with an `#ifdef`, but I assume you don't want to do that ;) – Jeeter Jun 01 '17 at 21:35
  • 1
    there's a huge number of function calls, I'm looking for a cleaner way – jafar Jun 01 '17 at 21:37
  • @Manidevs Hence the winky face :D – Jeeter Jun 01 '17 at 21:41
  • What you are currently doing is the standard way of handling this situation. In a build that doesn't contain _DEBUG then that string should disappear. Why not generate the .i file and see if the string exists there. – Neil Jun 02 '17 at 14:36

1 Answers1

3

You could try using stringification:

#include <stdio.h>

#define _DEBUG

#ifdef _DEBUG
#define LOG_DEBUG(str) do { printf("[D][%s:%d %s] ", \
                               __FILE__, \
                               __LINE__, \
                               __FUNCTION__); \
                            puts(#str); } while(0)
#else
#define LOG_DEBUG(str)
#endif

int main() {
  LOG_DEBUG(this is a debug string);
  return 0;
}

Note: I tested this in clang, which doesn't exhibit the behaviour you described.

r3mainer
  • 23,981
  • 3
  • 51
  • 88