简体   繁体   中英

How to debug/log preprocessor macros in Xcode (iOS)?

The question is stated in title, the main purpose is to be able to efficiently debug some runtime-version-specific or scheme-specific code.

So for example, is it possible to log the value of DEBUG in xcode's console?

EDIT:

I should rephrase the question, I understand we can use NSLog("DEBUG = %d", DEBUG); to log a macro's value (thx @rmaddy), the question should be:

Is there better way? eg. not needing to add a command and recompile just to get the value of a single macro

The question seems a little confusing because of the mention of "runtime-version-specific". Preprocessor macros are compile-time settings rather than runtime settings.

If all you need is to find the iOS predefined macros for Xcode 6, type this into the terminal:

llvm-gcc -arch armv7 -dM -E – < /dev/null | sort

(Yes, there is a single dash by itself.) Change the -arch option to “armv6″ or “armv7″ or “armv7s” as needed.

This can probably be extended to preprocess your project's code and show all the preprocessor macros. But that will be a compile-time operation rather than run-time.

To print the values of your custom macros at runtime would require specifically writing at least some code for each macro. Macros are tricky things. They may be #defined to one value or another or not #defined at all. They might also be #defined as numbers, or #defined as text, or object literals such as NSString, NSDictionary or NSNumber or any kind of object pointer.

The C standard " stringification operator " ('#') may be of interest if you really need to print things out at run-time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM