目标:我希望能够分析callgrind(以及后来的cachegrind)的输出,并希望在使用callgrind_annotate CLI时看到有意义的变量名称。
之前的研究:我知道Valgrind(http://valgrind.org/docs/manual/manual-core.html)中的dsym标志,并且相信我已经了解调试符号如何在osx(LLDB not showing source code)上工作。我在这个网站上看到的这个问题的少数提及要么没有得到答复,要么就是没有包含-g标志的情况。
理论(可能是错误的......):基于valgrind输出中的“dym =”行,我想知道valgrind是否正在努力寻找dsym目录的路径。“< / p>
我可以提供哪些数据?
给出以下源代码:
#include <iostream>
#include <cmath>
bool isPrime(int x)
{
int limit = std::sqrt(x);
for (int i = 2; i <= limit; ++i)
{
if (x % i == 0)
{
return false;
}
}
return true;
}
int main()
{
int primeCount = 0;
for (int i = 0; i < 1000000; ++i)
{
if (isPrime(i))
{
++primeCount;
}
}
}
使用了以下命令行说明:
g++ -g -c badprime.cpp
g++ badprime.o -o badprime
nm -pa badprime
dsymutil badprime
valgrind --tool=callgrind --dsymutil=yes ./badprime
callgrind_annotate --auto=yes callgrind.out.45056 badprime.cpp
nm -pa位用于确保存在调试映射信息。我还在dSYM文件夹上运行了dwarfdump,以确保存在调试信息。我收到了“没有收集badprime.cpp的信息”这一行作为annotate命令的输出。
编译器信息:
Apple LLVM version 8.0.0 (clang-800.0.42.1)
Target: x86_64-apple-darwin15.6.0
Valgrind信息:
valgrind-3.11.0
valgrind的初始详细输出:
$ valgrind --tool=callgrind --dsymutil=yes -v ./badprime
==45056== Callgrind, a call-graph generating cache profiler
==45056== Copyright (C) 2002-2015, and GNU GPL'd, by Josef Weidendorfer et al.
==45056== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==45056== Command: ./badprime
==45056==
--45056-- Valgrind options:
--45056-- --tool=callgrind
--45056-- --dsymutil=yes
--45056-- -v
--45056-- Output from sysctl({CTL_KERN,KERN_VERSION}):
--45056-- Darwin Kernel Version 15.6.0: Thu Jun 23 18:25:34 PDT 2016; root:xnu-3248.60.10~1/RELEASE_X86_64
--45056-- Arch and hwcaps: AMD64, LittleEndian, amd64-cx16-lzcnt-rdtscp-sse3-avx-avx2-bmi
--45056-- Page sizes: currently 4096, max supported 4096
--45056-- Valgrind library directory: /usr/local/Cellar/valgrind/3.11.0/lib/valgrind
==45056== For interactive control, run 'callgrind_control -h'.
--45056-- /usr/lib/dyld (rx at 0x7fff5fc00000, rw at 0x7fff5fc38000)
--45056-- reading syms from primary file (6 1229)
--45056-- Scheduler: using generic scheduler lock implementation.
==45056== embedded gdbserver: reading from /var/folders/7h/d91hqksj7bdfxp0km10b2qn40000gp/T//vgdb-pipe-from-vgdb-to-45056-by-dudett-on-???
==45056== embedded gdbserver: writing to /var/folders/7h/d91hqksj7bdfxp0km10b2qn40000gp/T//vgdb-pipe-to-vgdb-from-45056-by-dudett-on-???
==45056== embedded gdbserver: shared mem /var/folders/7h/d91hqksj7bdfxp0km10b2qn40000gp/T//vgdb-pipe-shared-mem-vgdb-45056-by-dudett-on-???
==45056==
==45056== TO CONTROL THIS PROCESS USING vgdb (which you probably
==45056== don't want to do, unless you know exactly what you're doing,
==45056== or are doing some strange experiment):
==45056== /usr/local/Cellar/valgrind/3.11.0/lib/valgrind/../../bin/vgdb --pid=45056 ...command...
==45056==
==45056== TO DEBUG THIS PROCESS USING GDB: start GDB like this
==45056== /path/to/gdb ./badprime
==45056== and then give GDB the following command
==45056== target remote | /usr/local/Cellar/valgrind/3.11.0/lib/valgrind/../../bin/vgdb --pid=45056
==45056== --pid is optional if only one valgrind process is running
==45056==
--45056-- /usr/local/Cellar/valgrind/3.11.0/lib/valgrind/vgpreload_core-amd64-darwin.so (rx at 0x100002000, rw at 0x100004000)
--45056-- reading syms from primary file (3 21)
--45056-- dSYM= /usr/local/Cellar/valgrind/3.11.0/lib/valgrind/vgpreload_core-amd64-darwin.so.dSYM/Contents/Resources/DWARF/vgpreload_core-amd64-darwin.so
callgrind_annotate输出:
--------------------------------------------------------------------------------
Profile data file 'callgrind.out.45056' (creator: callgrind-3.11.0)
--------------------------------------------------------------------------------
I1 cache:
D1 cache:
LL cache:
Timerange: Basic block 0 - 278668477
Trigger: Program termination
Profiled target: ./badprime (PID 45056, part 1)
Events recorded: Ir
Events shown: Ir
Event sort order: Ir
Thresholds: 99
Include dirs:
User annotated: badprime.cpp
Auto-annotation: on
--------------------------------------------------------------------------------
Ir
--------------------------------------------------------------------------------
913,332,521 PROGRAM TOTALS
--------------------------------------------------------------------------------
Ir file:function
--------------------------------------------------------------------------------
893,174,739 ???:0x0000000100000ee0 [???]
12,157,012 ???:0x0000000100000f50 [???]
--------------------------------------------------------------------------------
-- User-annotated source: badprime.cpp
--------------------------------------------------------------------------------
No information has been collected for badprime.cpp
我非常感谢能提供的任何帮助。
答案 0 :(得分:2)
检查链接器(ld
)命令行选项。 -s
删除所有符号信息,它优先于编译器中的-g
。
来自ld
手册:
-s
--strip-all
Omit all symbol information from the output file.
我注意到您没有使用ld
进行链接。所以这不适用于您的问题。但是,对于使用ld
并遇到此问题的人,我会在此留下我的答案。