我试图使用$ valgrind --tool=callgrind ./myProgram查看带注释的源代码,然后使用Ubuntu12.04查看$ kcachegrind (使用Mac的$ qcachegrind也有同样的问题)。
C++脚本myProgram.cpp调用驻留在.hpp文件中的函数(通过#include "../include/myHeader.hpp"等)。我像这样编译myProgram.cpp:
g++ -g -o myProgram myProgram.o -l<some third party lib>在这里,我不关心查看第三方库的带注释的源代码。
我希望看到的是为myHeader.hpp和myProgram.cpp中的函数注释的源代码。
相反,我看到了的平面配置文件窗口,其中列出了调用的所有函数,包括myHeader.hpp中的函数--这很棒。现在,kcache差伦将来自myHeader.hpp的函数的位置报告为来自myProgram --这是很奇怪的。最后,当我从平面配置文件窗口选择任何函数并请求查看源代码时,都会遇到以下情况:
There is no source available for the following function
<name of the selected function>
This is because no debug information is present.
Recompile the source and redo the profile run.
The function is located in the ELF object:
<some location...>我尝试过的:
myHeader.hpp的目录添加到注释列表中。发布于 2014-04-13 22:05:44
感谢用户n.m.,我正在回答自己的问题--我在运行一个简化的示例时发现了这一点。问题在于我的编译指令,我是用-g编译到一个对象文件,而不是用-g编译到一个可执行文件。
下面是一个关于如何让kcache差使显示带注释的源代码的工作示例:
main.cpp生活在someDirectory/example目录中
// main.cpp
#include <iostream>
#include <math.h>
#include "../include/header.hpp"
using namespace std;
int main() {
double a=1.0; double b=4.0;
double tol = 1E-10;
double zero = -99;
if (sin(a)*sin(b) < 0 && (b-a) >= tol)
zero = bisect_sine(a,b,tol);
cout << zero << endl;
return 0;
}头文件header.hpp位于someDirectory/include中
// header.hpp
#include <math.h>
#include <iostream>
using namespace std;
double bisect_sine(double a, double b, double tol) {
double c;
int step = 0; int maxsteps = 100;
while (step < maxsteps) {
c = (a+b)/2.0;
if (sin(c) == 0 || (b-a)/2 < tol)
return c;
if (sin(a)*sin(c) >= 0)
a = c;
else
b = c;
step+=1;
}
}Makefile
# Makefile
CXX = g++
main:
$(CXX) -g -o main main.cpp
chmod 700 main
clean:
rm main在所有这些之后,只需运行make (生成与调试-g一起编译的可执行main ),然后是valgrind --tool=callgrind ./main。这将产生预期的callgrind.out.<PID>文件,该文件可以由kcache差事读取。然后,源注释将用于main.cpp的main()函数以及头文件中的bisect_sine()。
因此,--这是一个编译问题,。如果我对编译成可执行文件、对象文件、共享对象、yada yada有更多的了解,我就不会陷入这种混乱。
https://stackoverflow.com/questions/22995407
复制相似问题