Error Using Valgrind's callgrind and kcachegrind on a C++

32 views Asked by At

I've been trying to analyze a simple C++ program that uses fork() to create a child process. The program compiles and runs fine. But, when I try to use Valgrind's callgrind tool to profile the program, I encounter an error related to QSocketNotifier and a symbol lookup error for __libc_pthread_init in libpthread.so.0.

Here is the code that reproduces my issue:

#include <cstdio>
#include <vector>
#include <iostream>
#include <unistd.h>
#include <sys/types.h>

int main()
{
    std::cout << "Parent ID: " << getpid() << std::endl;
    std::vector<char> parent_vec_1(100000);
    std::vector<char> parent_vec_2(100000);

    pid_t pid = fork();

    if (pid == -1)
    {
        std::cout << "Error, could not fork." << std::endl;
        return -1;
    }
    else if (pid == 0)
    {
        std::cout << "Child ID: " << getpid() << std::endl;
        std::vector<char> child_vec_1(100000);
        return 1;
    }
    else
    {
        std::cout << "Executing Parent Again" << std::endl;
    }
    return 0;
}

This is the command that I am using compile and run callgrind:

g++ main.cpp && valgrind --tool=callgrind ./a.out 
kcachegrind callgrind.out.<pid>

This results in following error:

QSocketNotifier: Can only be used with threads started with QThread
kcachegrind: symbol lookup error: /snap/core20/current/lib/x86_64-linux-gnu/libpthread.so.0: undefined symbol: __libc_pthread_init, version GLIBC_PRIVATE
0

There are 0 answers