2014-04-10 29 views
4

我想查看注释的源使用$ valgrind --tool=callgrind ./myProgram其次$ kcachegrind使用Ubuntu 12.04(和我有与使用Mac OSX $ qcachegrind相同的问题)。kcachegrind:没有来源可用于以下功能

C++脚本myProgram.cpp调用文件中的函数(通过#include "../include/myHeader.hpp"等)。我编译myProgram.cpp这样的:

g++ -g -o myProgram myProgram.o -l<some third party lib> 

,我不关心观看注明出处为第三方库。

我想看到的是myHeader.hppmyProgram.cpp中功能的注释源

相反,我看到 kcachegrind的扁平型窗口的那个被调用的所有功能,包括功能myHeader.hpp列表 - 这是伟大的。现在,kcachegrind报告从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...> 

我已经试过:

  • 添加目录使用kcachegrind的GUI将myHeader.hpp保存到注释列表中。

  • 使用-O0删除编译器优化

+1

提供一个独立的示例,可以复制,粘贴,编译并通过valgrind运行。我们不可能在''处检查''有什么问题。 –

+0

你懂了!谢谢。 –

回答

3

我回答我的问题感谢用户n.m.编译 - 我发现这一点的同时运行一个简单的例子。问题在于我的编译指令,我编译的目标文件是-g,而不是编译为-g的可执行文件。

下面是如何获得kcachegrind显示注释的源代码工作的例子:在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

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生活

# Makefile 
CXX = g++ 
main: 
    $(CXX) -g -o main main.cpp 
    chmod 700 main 
clean: 
    rm main 

这一切后,只需运行make(产生可执行main这是调试-g编译),其次是valgrind --tool=callgrind ./main。这将产生预期的callgrind.out.<PID>文件,该文件可以通过kcachegrind读取。然后源注释将可用于main的main()函数。cpp以及来自头文件的bisect_sine()

所以,这竟然是一个编译问题。如果我更了解编译成可执行文件,目标文件,共享对象,我不会陷入这个混乱。

相关问题