PDA

View Full Version : segmentation fault



navid
16th December 2009, 09:40
Hello

I some times in debugging run (F5) receive segmentation fault. But in normal run (Ctrl+R) , it seems every thing is good.

and it is a trace :
level - function - file - line - address
0 - QMutex::lock - qmutex.cpp - 150 - 0x6a110bae
1 - QMutexLocker::relock - qmutex.h - 120 - 0x0043da4a
2 - QMutexLocker - qmutex.h - 102 - 0x0043daea
3 - QextSerialPort::flush - win_qextserialport.cpp - 134 - 0x00433929

where is error ?


regards
navid

Tanuki-no Torigava
16th December 2009, 12:30
Show the code sample please. And use CODE quotes ;) It is unclear what cause that error exactly.

navid
16th December 2009, 13:21
void QextSerialPort::flush() {
QMutexLocker lock(mutex); // line 134
if (isOpen()) {
FlushFileBuffers(Win_Handle);
}
}


inline explicit QMutexLocker(QMutex *m)
: mtx(m)
{
Q_ASSERT_X((val & quintptr(1u)) == quintptr(0),
"QMutexLocker", "QMutex pointer is misaligned");
relock(); // line 102
}
inline ~QMutexLocker() { unlock(); }

inline void unlock()
{
if (mtx) {
if ((val & quintptr(1u)) == quintptr(1u)) {
val &= ~quintptr(1u);
mtx->unlock();
}
}
}

inline void relock()
{
if (mtx) {
if ((val & quintptr(1u)) == quintptr(0u)) {
mtx->lock(); //line 120
val |= quintptr(1u);
}
}
}



void QMutex::lock()
{
Qt::HANDLE self;

if (d->recursive) { //line 150 ... QMutex::QMutex(RecursionMode mode)
//: d(new MutexPrivate(mode))
self = QThread::currentThreadId();
if (d->owner == self) {
++d->count;
Q_ASSERT_X(d->count != 0, "QMutex::lock", "Overflow in recursion counter");
return;
}

bool isLocked = d->contenders.fetchAndAddAcquire(1) == 0;
if (!isLocked) {
#ifndef QT_NO_DEBUG
if (d->owner == self)
qWarning("QMutex::lock: Deadlock detected in thread %ld",
long(d->owner));
#endif

isLocked = d->wait();
Q_ASSERT_X(isLocked, "QMutex::lock",
"Internal error, infinite wait has timed out.");

d->contenders.deref();
}

d->owner = self;
++d->count;
Q_ASSERT_X(d->count != 0, "QMutex::lock", "Overflow in recursion counter");
return;
}

Tanuki-no Torigava
20th December 2009, 12:40
Ok. It looks like debug dies on call FlushFileBuffers. If it is privileged call and you try to debug it without privileges - then you should get something like protection error.

Regards,
-- tanuki