简体   繁体   English

clang:如何在OS X中进行分析时获取源信息

[英]clang: How to get source info while profiling in OS X

I compiled a benchmark using clang 703.0.31. 我使用clang 703.0.31编制了基准。 First compiled all sources with -c -flto -O3 -g (and some other flags) into object files, then linked them using same clang (using Apple LLVM 7.3.0, using ld) with -g -flto into an executable. 首先使用-c -flto -O3 -g(和其他一些标志)将所有源代码编译成目标文件,然后使用相同的clang(使用Apple LLVM 7.3.0,使用ld)和-g -flto将它们链接成可执行文件。 When I am trying to profile the executable I can see function names and disassembler, but there is no correspondence between that and source code. 当我尝试分析可执行文件时,我可以看到函数名称和反汇编程序,但是该代码与源代码之间没有对应关系。 dsymutil on that exe produces this result: warning: (x86_x64) /tmp/lto.o unable to open object file: No such file or directory warning: no debug symbols in executable (-arch x86_64) Any idea what i am missing? 在该exe上的dsymutil会产生以下结果:警告:(x86_x64)/tmp/lto.o无法打开目标文件:没有这样的文件或目录警告:可执行文件(-arch x86_64)中没有调试符号任何想法我都缺少什么? (Note: I generally work on Windows, my knowledge of OS X is close to 0) (注意:我通常在Windows上工作,我对OS X的了解接近于0)

You are using -O3 option which explicitly says to compiler that it should optimize the instructions in the best way. 您正在使用-O3选项,该选项明确告诉编译器它应以最佳方式优化指令。 So the compiler will rearrange those instructions which may destroy correspondence between source code and executable. 因此,编译器将重新排列那些可能破坏源代码和可执行文件之间对应关系的指令。

You should use -O0 -g for debugging. 您应该使用-O0 -g进行调试。 See this . 看到这个

One of workarounds suggested elsewhere worked for me: I created xcode project and re-compiled the binary. 其他地方建议的解决方法之一对我有用:我创建了xcode项目并重新编译了二进制文件。 After that debug info was good enough to profile it with Instruments. 之后,调试信息就足以使用Instruments对其进行分析。

Unlike GCC, clang cannot produce debuginfo while optimizing. 与GCC不同,clang在优化时无法生成debuginfo。

Since you're profiling, disabling optimization would destroy the very information you're trying to collect. 由于您正在分析,因此禁用优化会破坏您要收集的信息。 So, you have to use another compiler for this task. 因此,您必须为此任务使用另一个编译器。

I have not used ICC, but from documentation it looks like it can produce debuginfo while optimizing. 我没有使用过ICC,但是从文档看来 ,它可以在优化时产生debuginfo。

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

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