Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. How to QT Creator not stopping at OS Signals while debugging multithreaded programms
Forum Updated to NodeBB v4.3 + New Features

How to QT Creator not stopping at OS Signals while debugging multithreaded programms

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
qt creator debuc++ thread
1 Posts 1 Posters 425 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    schnedan
    wrote on 2 Apr 2021, 11:47 last edited by schnedan 4 Feb 2021, 11:50
    #1

    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...
    e4e1bba0-4ee2-42a3-8a52-6b0a6ea0f39e-grafik.png
    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...
    760d358c-2e60-4572-95ec-248fcc999481-grafik.png

    ... any solution / help welcome!

    1 Reply Last reply
    0

    1/1

    2 Apr 2021, 11:47

    • Login

    • Login or register to search.
    1 out of 1
    • First post
      1/1
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved