I have cut out a piece of code out of a larger (C) project. The code has many many macros defined, in many place - some of them are only used by the original, larger codebase, and not used by the part of the code I cut out.
I want to quickly determine which of these macros are in actual use, and which aren't (so that I can remove those that aren't). I don't care whether the code paths which uses them get taken or not (i.e. if (1+1 == 3) { MY_MACRO(a,b,c); }
is a use as far as I'm concerned.
What's a good way to do this? The best I could think of is preprocess everything with -E and look for source position comments which mention the macro somehow.
Notes:
- If you have a solution that also lists the functions in use, that's fine too.
- I only directly call certain functions in the code I cut out of the project. If your solution can limit the macros listed to those in functions which many actually get called from the entry-points, that's even better
- My code compiles and runs (and you can assume gprof output if that helps)
- Just commenting out all macros, while obviously feasible, is a hassle; so I want a solution which does not require my doing that.
- Code excluded by the preprocessor is unused; but if you have a solution which does not observe this restriction, that's still better than nothing.
- I don't want to "dump the list of preprocessor defines" - but rather those defines that are in use.