简体   繁体   中英

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

I compiled a benchmark using 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. 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? (Note: I generally work on Windows, my knowledge of OS X is close to 0)

You are using -O3 option which explicitly says to compiler that it should optimize the instructions in the best way. So the compiler will rearrange those instructions which may destroy correspondence between source code and executable.

You should use -O0 -g for debugging. See this .

One of workarounds suggested elsewhere worked for me: I created xcode project and re-compiled the binary. After that debug info was good enough to profile it with Instruments.

Unlike GCC, clang cannot produce debuginfo while optimizing.

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.

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