Strange debugger behaviour



  • Hello all!

    When I am running my program without debugger it works as expected. But when I try to set breakpoints and step over them with debugger (Qt Creator 2.7.2) the following happens. Here is piece of code:
    @ QList<QVariant> fieldList(record.fieldList);
    if (column < fieldList.size())
    {
    ......
    }
    return QVariant();
    @

    When I stop at line 2 I can see that "fieldList" contains 6 items, as expected. "column" is 0. Than I am trying to step over line 2 and getting to line 6
    Q1: why if column==0 and fieldList.size() is 6?

    Also, debugger tells me that "fieldList" is now <not accessible>
    Q2: Was it already destroyed because optimizer decided it is not needed when I am at line 6?

    Than I am hitting "Continue (F5)" button. Boom!
    The inferior stopped because it received a signal from the Operating System.
    Signal name: SIGSEGV
    Signal meaning: Segmentation fault.

    Call stack shows fault at line 3 of ("qgenericatomiv.h"):
    @
    T load(const T &_q_value) Q_DECL_NOTHROW
    {
    return _q_value;
    }
    @

    called from (qbasicatomic.h)
    @
    T load() const Q_DECL_NOTHROW { return Ops::load(_q_value); }
    @

    called from line 2 of ("qrefcount.h"):
    @
    inline bool deref() Q_DECL_NOTHROW {
    int count = atomic.load();
    if (count == 0) // !isSharable
    return false;
    if (count == -1) // isStatic
    return true;
    return atomic.deref();
    }
    @

    called from line 4 of ("qlist.h")
    @
    template <typename T>
    Q_OUTOFLINE_TEMPLATE QList<T>::~QList()
    {
    if (!d->ref.deref())
    dealloc(d);
    }
    @

    called from line 6 of my code.
    Ok, I understand abut leaving scope and thus destroying "fieldList". I also know I could use
    @
    const QList<QVariant>& fieldList = record.fieldList;
    @
    and actually I had that before but QList documentation says that copy-constructor creates QList that "is implicitly shared. This makes returning a QList from a function very fast. If a shared instance is modified, it will be copied (copy-on-write), and that takes linear time." And I know I am not modifying "fieldList"

    I had different variations of this code with different appearances of this problem but actually it is all the same three points:

    1. "fieldList" becomes <not accessible>
    2. 0 is not considered valid index in "fieldList"
    3. segmentation fault at the end

    Again, without debugger everything is working as expected. No crashes and correct content in QTreeView. But I sometimes need to step over code to watch something...

    Any ideas will be appreciated!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.