How to detect the GCC flag -g issued on command line?
I'm trying some flags ono GCC to see if when we issue a flag -g
at command line it's defined any macro to pre-processor.
An example is when we flag -fpie
and -fPIE
, both define the macros __pie__
and __PIE__
.
So, I'm wondering if we flag -g
or -g3
, something similary will gone happen.
I did a few tests, but nothing came up on the cpp
listing.
$ gcc -g3 -E main_debug_flags.c > main_debug_flags.LIST.c
The test code
It is quite simple:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
#ifndef DEBUG
printf("DEBUG not defined!\n");
#else
printf("DEBUG defined!\n");
#endif
#ifndef NDEBUG
printf("NDEBUG not defined!\n");
#else
printf("NDEBUG defined!\n");
#endif
return 0;
}
Does anybody has any idea? Maybe, Any one has faced the same doubt!
The alternative is to define by hand the macro -DDEBUG
to make sure the code will be compiled with some pre-processor checks.
The readings
I did a little digging into a few documents, but nothing came up!
- GCC: The Complete Reference, by Arthur Griffith (McGraw-Hill/Osborne)
- The Definitive Guide to GCC Second Edition, by William von Hagen (Apress, 2006)
- Using the GNU Compiler Collection,For gcc version 13.0.0
I have compile a simple code with debug flag on and check the pre-processor output to see if something shows up. But nothing!
What I wanna do is detect with #ifdef
the -g
flag and include addition code to help DEBUG the application itself!