gpt4 book ai didi

c++ - 如何从命令行在 OSX 上的 callgrind 输出中获取有意义的函数名称?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:42:52 27 4
gpt4 key购买 nike

目标:我希望能够分析 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 收集信息”。

编译器信息:

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

如果能提供任何帮助,我将非常感激。

最佳答案

检查您的链接器 (ld) 命令行选项。 -s 去除所有符号信息,它在编译器中优先于 -g

来自 ld 手册:

-s
--strip-all
Omit all symbol information from the output file.

ftp link

我注意到您没有使用 ld 进行链接。所以这不适用于你的问题。但是,对于使用 ld 并遇到此问题的人,我会在这里留下我的答案。

关于c++ - 如何从命令行在 OSX 上的 callgrind 输出中获取有意义的函数名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40703954/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com