简体   繁体   English

如何在Xcode(iOS)中调试/记录预处理器宏?

[英]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? 因此,例如,是否可以在xcode的控制台中记录DEBUG的值?

EDIT: 编辑:

I should rephrase the question, I understand we can use NSLog("DEBUG = %d", DEBUG); 我应该改一下这个问题,我知道我们可以使用NSLog("DEBUG = %d", DEBUG); to log a macro's value (thx @rmaddy), the question should be: 要记录宏的值(thx @rmaddy),问题应该是:

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: 如果只需要找到Xcode 6的iOS 预定义宏,请在终端中输入以下内容:

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. (是的,它本身只有一个短划线。)根据需要将-arch选项更改为“ armv6”或“ armv7”或“ armv7s”。

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. 它们可能被#defined定义为一个值或另一个值,或者根本没有#defined。 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. 它们也可能被#定义为数字,或#定义为文本,或对象文字,例如NSString,NSDictionary或NSNumber或任何类型的对象指针。

The C standard " stringification operator " ('#') may be of interest if you really need to print things out at run-time. 如果您确实需要在运行时将内容打印出来,则可能需要使用C标准的“ 字符串运算符 ”(“#”)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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