How to QT Creator not stopping at OS Signals while debugging multithreaded programms
-
I have this Problem since several month now...
whenever I debug a multi-threaded Program, the debugger stops at Operating system Signals (you can turn of the popup Dialog, but not the stopping itself...) which makes it impossible to debug a program!
Here a small demo program:
#include <iostream> #include <iomanip> #include <thread> #include <vector> #include <cstdint> #include <functional> #include <atomic> using namespace std; int main(){ constexpr int32_t const max = 1000; bool volatile run = false; int32_t volatile cnt = 0; std::atomic_int8_t state; state.store(0); auto worker = [&cnt,&state,&run](){ uint32_t active = 0; while(run && (cnt<max)){ if(0==state){ ++state; if(1==state){ cnt = (1+cnt); cout << "[" << std::this_thread::get_id() << "] - Value: " << cnt << endl; ++active; } --state; } std::this_thread::sleep_for(std::chrono::microseconds(100*cnt)); } cout << "[" << std::this_thread::get_id() << "] - Active: " << active << endl; return; }; static constexpr int const numthreads = 10; std::vector<std::thread> tlst(numthreads); for(auto& _t:tlst){ auto tmp = std::thread(worker); _t.swap(tmp); } run = true; while(cnt<max){} run = false; for(auto& _t:tlst){ _t.join(); } return 0; }
plus the QT-Creator Project file:
TEMPLATE = app CONFIG += console CONFIG -= app_bundle CONFIG -= qt QMAKE_CXXFLAGS += -std=c++11 -pthread QMAKE_CFLAGS += -std=c99 -pthread LIBS += -pthread SOURCES += \ main.cpp
If you set a Breakpoint to the line with "run = true;", you need to continue debugging (because the debugger stops at OS Signals) lets say 20-30 times like that...
prior to reaching the Breakpoint.So if you have a cyclic process, loops, whatever, you end in a "continue debug" hell as you never know if your click ends in the next wrong stop or a line with a breakpoint.... and only 5% or less of your clicks ending up in a usefull position (a real breakpoint)
How to get normal debugging behaviour with QT Creator (like in any decent IDE)???
What it is needed: Only Stop at real breakpoints - no OS Signals! Or only Stop at OS Signals when a certain condition is meet - like only after a certain event in Code or after a certain breakpoint.
Also if a OS event is received I do not want to end in Assembler of some clib code, but in the line (after the line) of my code, where the signal was received (but again - if pthread code causes / reacts on OS Signals, I am not interested in these Signals at all! - I am Only interested in Signals which are intended for or caused by my code)
PS:
gcc (GCC) 10.2.0 - but it was the same with 9.x versions...
Linux 5.11.10-arch1-1 #1 SMP PREEMPT - but it was the same with all versions of the last lets say 12 month...
... any solution / help welcome!