iPhone:如何使用 gcov?
我正在尝试在 iPhone 项目上使用 gcov 并遵循此处描述的Apple说明,但事实并非如此工作。
当我构建并配置项目时,会为每个目标文件创建 .gcda 文件。 但没有执行的行记录到 .gcda 文件中。 (CoverStory 显示所有覆盖率均为 0%)
我刚刚向模板项目添加了一个简单的类,如下所示。
@interface SomeClass : NSObject
- (void)func1:(BOOL)flag;
@end
@implementation SomeClass
- (void)func1:(BOOL)flag {
if (flag) {
NSLog(@"flag is YES");
}
else {
NSLog(@"flag is NO");
}
}
@end
我分配了这个类并在应用程序中调用func1:didFinishLaunchingWithOptions, 我预计会显示 SomeClass 的覆盖率(50% 左右)。
我使用的是 OSX 10.6.4、iPhone SDK 4.0 和 Xcode 3.2.3。 还需要一些配置吗?请指导。
2010/7/15 更新:
我在 链接 @tonclon 给了我,但还没有起作用。 下面的描述是我尝试过的。
GCC 4.0编译的Cocoa应用程序 在“Cocoa”应用程序的项目设置中,
- 将 GCC_INSTRUMENT_PROGRAM_FLOW_ARCS 设置为 YES
- 将 GCC_GENERATE_TEST_COVERAGE_FILES 设置为 YES
- 将其他链接器标志设置为 -lgcov
- 将 C/C++ 编译器版本设置为 4.0
它成功了,.gcda 文件已按预期生成,其中包含覆盖率信息。 然而,在使用 SDK 4.0 的 iPhone 项目中,我无法使用相同的配置,因为 gcc 4.0 无法编译 SDK 4.0 中的某些语法(例如 Blocks)
在 google-tool-box 中使用自定义 gcov 库 而不是在其他链接器标志中设置 -lgcov, 我尝试了 google-toolbox-for-mac 中包含的自定义 gcov 库, 但生成的 .gcda 文件显示覆盖率为 0%。 (相同的结果)
你能告诉我下一步应该做什么吗?任何建议表示赞赏。
I'm trying to use gcov on iPhone Project
and followed Apple's instruction described here, but it doesn't work.
When I build and go configured project, .gcda file is created for each object file.
But no executed lines are recorded to .gcda files. (CoverStory shows all coverages are 0%)
I just added a simple class to template project as following.
@interface SomeClass : NSObject
- (void)func1:(BOOL)flag;
@end
@implementation SomeClass
- (void)func1:(BOOL)flag {
if (flag) {
NSLog(@"flag is YES");
}
else {
NSLog(@"flag is NO");
}
}
@end
I allocated this class and call func1 in application:didFinishLaunchingWithOptions,
and I expected that coverage of SomeClass is showed (50% or so).
I'm using OSX 10.6.4, iPhone SDK 4.0 and Xcode 3.2.3.
Some more configurations are needed? Please guide.
UPDATE 2010/7/15:
I tried these hints in the link @tonclon gave me, but it didn't work yet.
In the following description is what I tried.
Cocoa Application compiled by GCC 4.0
In project settings of "Cocoa" Application,- set GCC_INSTRUMENT_PROGRAM_FLOW_ARCS to YES
- set GCC_GENERATE_TEST_COVERAGE_FILES to YES
- set Other Linker Flag to -lgcov
- set C/C++ Compiler Version to 4.0
It worked, .gcda files were generated with coverage information as expected.
In iPhone project with SDK 4.0, however, I can't use same configuration because
gcc 4.0 can't compile some syntax in SDK 4.0 (ex Blocks)using custom gcov library in google-tool-box
Instead of setting -lgcov in Other Linker Flag,
I tried custom gcov library included in google-toolbox-for-mac,
but generated .gcda files shows coverage is 0%. (same result)
Can you please tell me what I should do next? Any suggestions are appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有几件事:
请查看此处的 gcov 页面 (http://code.google.com/p/google-toolbox-for-mac/w/list) 并查看如果他们有帮助的话。我让 gcov 与 Xcode 3.2.5 和 iOS4.2 一起工作。
A couple of things:
Please check out the gcov pages here (http://code.google.com/p/google-toolbox-for-mac/w/list) and see if they help at all. I have gcov working with Xcode 3.2.5 and iOS4.2.