Is this error from Qt or my program? - c++

I'm new to valgrind. I have written a program in C++ using Qt 5.5.1 libraries on Ubuntu 15.10. I'm using Qt Creator with Debug build set. I checked for memory leaks using Valgrind with the following command:
valgrind --leak-check=yes --track-origins=yes ./texteditor
Valgrind then gives me the following message:
==2977== Conditional jump or move depends on uninitialised value(s)
==2977== at 0x97ED1EC: ??? (in /usr/lib/i386-linux-gnu/libgtk-x11-2.0.so.0.2400.28)
==2977== by 0x97EE58A: ??? (in /usr/lib/i386-linux-gnu/libgtk-x11-2.0.so.0.2400.28)
==2977== by 0x5B3380B: g_cclosure_marshal_VOID__VOID (in /usr/lib/i386-linux-gnu/libgobject-2.0.so.0.4600.2)
==2977== by 0x5B31B8A: g_closure_invoke (in /usr/lib/i386-linux-gnu/libgobject-2.0.so.0.4600.2)
==2977== by 0x5B43FFB: ??? (in /usr/lib/i386-linux-gnu/libgobject-2.0.so.0.4600.2)
==2977== by 0x5B4CC95: g_signal_emit_valist (in /usr/lib/i386-linux-gnu/libgobject-2.0.so.0.4600.2)
==2977== by 0x5B4CFC4: g_signal_emit (in /usr/lib/i386-linux-gnu/libgobject-2.0.so.0.4600.2)
==2977== by 0x96ECD00: gtk_adjustment_changed (in /usr/lib/i386-linux-gnu/libgtk-x11-2.0.so.0.2400.28)
==2977== by 0x5B35465: ??? (in /usr/lib/i386-linux-gnu/libgobject-2.0.so.0.4600.2)
==2977== by 0x5B384FC: g_object_thaw_notify (in /usr/lib/i386-linux-gnu/libgobject-2.0.so.0.4600.2)
==2977== by 0x96ED182: gtk_adjustment_configure (in /usr/lib/i386-linux-gnu/libgtk-x11-2.0.so.0.2400.28)
==2977== by 0x4563C7F: ??? (in /home/tembo/Qt/5.5/gcc/lib/libQt5Widgets.so.5.5.1)
==2977== Uninitialised value was created by a stack allocation
==2977== at 0x456215F: ??? (in /home/tembo/Qt/5.5/gcc/lib/libQt5Widgets.so.5.5.1)
From the above message nothing points to the location of myProgram at all. Is this from Qt and other libraries or do I miss something pointing to myProgram?

By default Valgrind only shows the top 12 entries of the call stack, but this can be changed with the --num-callers=xx parameter. The functions from your own program code are likely further down on the stack.

Related

Valgrind is not showing line numbers

My fortran code gets failed if I run it without debugger. But if I use valgrind while running it runs. Surely, a case of memory issue. I thought to debug the code using valgrind and it does contain errors like...
==988381== at 0x15EA7C: __nautilus_main_MOD_init_reaction_rates (in /home/seps/Desktop/softwares/DNautilus_spin/bin/dnautilus_spin)
==988381== by 0x16AD99: __nautilus_main_MOD_initialisation (in /home/seps/Desktop/softwares/DNautilus_spin/bin/dnautilus_spin)
==988381== by 0x10B44C: MAIN__ (in /home/seps/Desktop/softwares/DNautilus_spin/bin/dnautilus_spin)
==988381== by 0x10B30E: main (in /home/seps/Desktop/softwares/DNautilus_spin/bin/dnautilus_spin)
==988381== Address 0x4fb7c98 is 8 bytes before a block of size 20,864 alloc'd
==988381== at 0x483C855: malloc (vg_replace_malloc.c:381)
==988381== by 0x150140: __global_variables_MOD_initialize_global_arrays (in /home/seps/Desktop/softwares/DNautilus_spin/bin/dnautilus_spin)
==988381== by 0x16AD2B: __nautilus_main_MOD_initialisation (in /home/seps/Desktop/softwares/DNautilus_spin/bin/dnautilus_spin)
==988381== by 0x10B44C: MAIN__ (in /home/seps/Desktop/softwares/DNautilus_spin/bin/dnautilus_spin)
==988381== by 0x10B30E: main (in /home/seps/Desktop/softwares/DNautilus_spin/bin/dnautilus_spin)
But valgrind is not showing any line numbers. I compiled the code using flags like -g3, -g, -fbacktrace, -o0. Even then, valgrind is not showing line numbers.
I tried changing the flags except -g3 while compiling the code. I tried different valgrind versions like valgrind-3.19.0, valgrind-3.20.0. These I did based on the suggestions from web search.
All I want is to get line numbers so that I can proceed further. Can anyone help me?
Thanks in advance.

Valgrind reporting memory leak in RocksDB

I am trying to profile the performance of RocksDB using Callgrind / KCacheGrind on a mac. I am running the command valgrind --tool=callgrind ./simple_example on one of the example programs that comes with RocksDB in the examples folder. I seem to be getting a memory leak, though, which prevents me from being able to do the performance profiling that I ultimately want to do.
==54628== Callgrind, a call-graph generating cache profiler
==54628== Copyright (C) 2002-2017, and GNU GPL'd, by Josef Weidendorfer et al.
==54628== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info
==54628== Command: ./simple_example
==54628==
==54628== For interactive control, run 'callgrind_control -h'.
==54628==
==54628== Process terminating with default action of signal 11 (SIGSEGV)
==54628== Access not within mapped region at address 0x18
==54628== at 0x1016D25BA: _pthread_body (in /usr/lib/system/libsystem_pthread.dylib)
==54628== by 0x1016D250C: _pthread_start (in /usr/lib/system/libsystem_pthread.dylib)
==54628== by 0x1016D1BF8: thread_start (in /usr/lib/system/libsystem_pthread.dylib)
==54628== If you believe this happened as a result of a stack
==54628== overflow in your program's main thread (unlikely but
==54628== possible), you can try to increase the size of the
==54628== main thread stack using the --main-stacksize= flag.
==54628== The main thread stack size used in this run was 8388608.
--54628:0:schedule VG_(sema_down): read returned -4
==54628==
==54628== Events : Ir
==54628== Collected : 14961779
==54628==
==54628== I refs: 14,961,779
Segmentation fault: 11

Getting signal 11 (SIGSEGV) when using libcurl in multithreaded Program

I did this
From google I found out we should build libcurl by providing --enable-threaded-resolver but it didn't help, I am still seeing the segfault
I also tried setting the NoSignal option, but that also didn't help.
From logs of program it seems one thread hungs up when calling perform function (of curlpp library ie we have curlpp::Easy request; and it hungs when we do request.perform in one thread)
Also, the issue does not appear at every run and is specific to linux , works fine on MAC OS and Windows.
curl/libcurl version
I tried 7.21.2 and 7.66 version (7.66 with --enable-threaded-resolver )
Error
With 7.21.2 version , I was getting
==8866==
==8866== Process terminating with default action of signal 11 (SIGSEGV)
==8866== Access not within mapped region at address 0x0
==8866== at 0x551FCDD: _IO_file_underflow##GLIBC_2.2.5 (in /usr/lib64/libc-2.17.so)
==8866== by 0x5520E81: _IO_default_uflow (in /usr/lib64/libc-2.17.so)
==8866== by 0x5513C33: _IO_getline_info (in /usr/lib64/libc-2.17.so)
==8866== by 0x551D6FC: fgets_unlocked (in /usr/lib64/libc-2.17.so)
==8866== by 0xF57D5AE: internal_getent (in /usr/lib64/libnss_files-2.17.so)
==8866== by 0xF57E7E2: _nss_files_gethostbyname4_r (in /usr/lib64/libnss_files-2.17.so)
==8866== by 0x558A1B3: gaih_inet.constprop.8 (in /usr/lib64/libc-2.17.so)
==8866== by 0x558B553: getaddrinfo (in /usr/lib64/libc-2.17.so)
==8866== by 0xCB6E013: Curl_getaddrinfo_ex (in /usr/local/qubole/libquboleodbc.so)
==8866== by 0xCB6AE65: Curl_getaddrinfo (in /usr/local/qubole/libquboleodbc.so)
==8866== by 0xCB51CF4: Curl_resolv (in /usr/local/qubole/libquboleodbc.so)
==8866== by 0xCB51FBA: Curl_resolv_timeout (in /usr/local/qubole/libquboleodbc.so)
With 7.66 version (with --enable-threaded-resolver) , I started getting
==11063==
==11063== Process terminating with default action of signal 11 (SIGSEGV)
==11063== Access not within mapped region at address 0x0
==11063== at 0x551FCDD: _IO_file_underflow##GLIBC_2.2.5 (in /usr/lib64/libc-2.17.so)
==11063== by 0x5520E81: _IO_default_uflow (in /usr/lib64/libc-2.17.so)
==11063== by 0x5513C33: _IO_getline_info (in /usr/lib64/libc-2.17.so)
==11063== by 0x551D6FC: fgets_unlocked (in /usr/lib64/libc-2.17.so)
==11063== by 0xFDAA5AE: internal_getent (in /usr/lib64/libnss_files-2.17.so)
==11063== by 0xFDAB7E2: _nss_files_gethostbyname4_r (in /usr/lib64/libnss_files-2.17.so)
==11063== by 0x558A1B3: gaih_inet.constprop.8 (in /usr/lib64/libc-2.17.so)
==11063== by 0x558B553: getaddrinfo (in /usr/lib64/libc-2.17.so)
==11063== by 0xCB7D2E3: Curl_getaddrinfo_ex (in /usr/local/qubole/libquboleodbc.so)
==11063== by 0xCB585C0: getaddrinfo_thread (in /usr/local/qubole/libquboleodbc.so)
==11063== by 0xCB8474A: curl_thread_create_thunk (in /usr/local/qubole/libquboleodbc.so)
==11063== by 0xF391EA4: start_thread (in /usr/lib64/libpthread-2.17.so)
The above is seen when I use Valgrind.
operating system
RHEL 7.7
Any help is appreciated.

Performance testing in C++ project

I wrote a project in c++ with 10 threads. One thread loads the data into memory(write the buffer) and other 9 threads are simultaneously read the buffer and store data in SQLite database, All threads are handled with the mutex to avoid conflicts.
Now I need to evaluate the performance of this project such as time to success per threads, memory usages etc. How can I go it in c++ environment? I used Valgrind to check these. But I think it not working.
This is the code I run with Valgrind,
valgrind --tool=memcheck --leak-check=yes ./executable
It gives a message like this,
callers=20 --track-fds=yes ./monerosci
==24262== Memcheck, a memory error detector
==24262== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==24262== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==24262== Command: ./monerosci
==24262==
valgrind: m_syswrap/syswrap-linux.c:5361
(vgSysWrap_linux_sys_fcntl_before): Assertion 'Unimplemented
functionality' failed.
valgrind: valgrind
host stacktrace:
==24262== at 0x38083F48: ??? (in /usr/lib/valgrind/memcheck-amd64-linux)
==24262== by 0x38084064: ??? (in /usr/lib/valgrind/memcheck-amd64-linux)
==24262== by 0x380841F1: ??? (in /usr/lib/valgrind/memcheck-amd64-linux)
==24262== by 0x380FB399: ??? (in /usr/lib/valgrind/memcheck-amd64-linux)
==24262== by 0x380D6234: ??? (in /usr/lib/valgrind/memcheck-amd64-linux)
==24262== by 0x380D2D2A: ??? (in /usr/lib/valgrind/memcheck-amd64-linux)
==24262== by 0x380D43DE: ??? (in /usr/lib/valgrind/memcheck-amd64-linux)
==24262== by 0x380E3946: ??? (in /usr/lib/valgrind/memcheck-amd64-linux)
How can I test the performance of the project in C++?
Well it seems there's two separate problems here:
1) memcheck is failing to run due to a bug or some limitation. Apparently one variation of a fcntl call is not supported by your version of valgrind. Maybe you should reduce the code size, remove libraries, until you can pinpoint which call is triggering this problem. Or just run it under a different version of valgrind. However, I think memcheck will not give you the data you want...
2) memcheck is not a tool for profiling. Valgrind is composed of several different tools that can be switched by using the --tool parameter. Here's an overview of them. The one that most likely will give you the info you want is callgrind.

Valgrind shows question marks

I have compiled a program using Code::Blocks. I have turned on "produce debugging symbols" under the "Debug" target, and also turned off "strip all symbols..." But when I run the program with Valgrind I get question marks in the output:
$ valgrind --leak-check=yes --track-origins=yes --log-file=valgrind_output.txt
~/bin/myprg
==3766== Memcheck, a memory error detector
==3766== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==3766== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==3766== Command: /home/xxxxxx/bin/myprg
==3766== Parent PID: 3209
==3766==
==3766== Warning: client switching stacks? SP change: 0xffefff978 --> 0xffed13da0
==3766== to suppress, use: --max-stackframe=3062744 or greater
==3766== Invalid write of size 4
==3766== at 0x40892B: ??? (in /home/xxxxxx/bin/myprg)
==3766== by 0x40275C: ??? (in /home/xxxxxx/bin/myprg)
==3766== by 0x56FB82F: (below main) (libc-start.c:291)
==3766== Address 0xffed13ddc is on thread 1's stack
==3766==
==3766== Invalid write of size 4
==3766== at 0x408931: ??? (in /home/xxxxxx/bin/myprg)
==3766== by 0x40275C: ??? (in /home/xxxxxx/bin/myprg)
==3766== by 0x56FB82F: (below main) (libc-start.c:291)
==3766== Address 0xffed13dd4 is on thread 1's stack
==3766==
...
What is the meaning of this output, and how do I find the piece of code that is causing this error?
Update: Solution
The problem was with Code::Blocks. It is necessary to correctly configure the project build options for the whole project and not just the "Debug" target. So all flags except "-std=c++11" were removed from the "whole project" options, so nothing was overriding the "Debug" options. Also the linker ".o" files need to be deleted when the options are changed, to force Code::Blocks to rebuild the executable.
The code needs to be compiled and linked with debug info (-g command line option) and -fno-omit-frame-pointer for valgrind to show correct stack traces.
See The stack traces given by Memcheck (or another tool) aren't helpful. How can I improve them? for more details.
I recently had this problem and was able to resolve it by using the "--keep-debuginfo=yes" option, as suggested by the FAQ on this page.