Kcachegrind: no source for next function

I am trying to view an annotated source using $ valgrind --tool=callgrind ./myProgramfollowed by $ kcachegrindusing Ubuntu 12.04 (and I have the same problem $ qcachegrindusing Mac OSX).

C ++ script myProgram.cppmakes calls to functions that are in the file .hpp(via #include "../include/myHeader.hpp", etc.). I compile myProgram.cppas follows:

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

where I do not need to view the annotated source for this third-party library.

What I would like to see is an annotated source for functions in myHeader.hppand for myProgram.cpp.

Instead, I see a kcachegrind Flat Profile window with a list of all the called functions, including functions in myHeader.hpp- this is great. Now kcachegrind reports the location of functions from myHeader.hppas from myProgram- it's odd. And finally, when I select any function from the Flat Profile window and request to see the source code, I am met:

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...>

What I tried:

  • added a directory containing myHeader.hppthe annotation list using the kcachegrind GUI.

  • compiled using -O0 to remove compiler optimizations

+4
source share
1 answer

n.m. - . , -g, -g.

, kcachegrind :

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 ( main, -g), valgrind --tool=callgrind ./main. callgrind.out.<PID>, kcachegrind. main() main.cpp, bisect_sine() .

, . , , , yada yada yada, .

+3

Source: https://habr.com/ru/post/1535982/


All Articles