Skip to content

Commit ed174ba

Browse files
adding debugging messages to QtCore
1 parent 2598674 commit ed174ba

8 files changed

+71
-19
lines changed

src/corelib/io/qnoncontiguousbytedevice.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ QNonContiguousByteDevice::QNonContiguousByteDevice() : QObject((QObject*)nullptr
9999

100100
QNonContiguousByteDevice::~QNonContiguousByteDevice()
101101
{
102+
printf("~QNonContiguousByteDevice %p (%s)\n", (void*)this, typeid(*this).name());
102103
}
103104

104105
QNonContiguousByteDeviceByteArrayImpl::QNonContiguousByteDeviceByteArrayImpl(QByteArray ba)

src/network/access/qhttp2connection.cpp

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include <algorithm>
1717
#include <memory>
18+
#include <thread>
1819

1920
QT_BEGIN_NAMESPACE
2021

@@ -43,6 +44,7 @@ QHttp2Stream::QHttp2Stream(QHttp2Connection *connection, quint32 streamID) noexc
4344
}
4445

4546
QHttp2Stream::~QHttp2Stream() noexcept {
47+
printf("~QHttp2Stream\n");
4648
if (auto *connection = getConnection()) {
4749
if (m_state == State::Open || m_state == State::HalfClosedRemote) {
4850
qCDebug(qHttp2ConnectionLog, "[%p] stream %u, destroyed while still open", connection,
@@ -290,6 +292,7 @@ bool QHttp2Stream::sendDATA(const QByteArray &payload, bool endStream)
290292
auto *byteDevice = QNonContiguousByteDeviceFactory::create(payload);
291293
m_owningByteDevice = true;
292294
byteDevice->setParent(this);
295+
printf("QHttp2Stream::sendDATA, byteDevice = %p\n", (void*)byteDevice);
293296
return sendDATA(byteDevice, endStream);
294297
}
295298

@@ -310,6 +313,7 @@ bool QHttp2Stream::sendDATA(const QByteArray &payload, bool endStream)
310313
*/
311314
bool QHttp2Stream::sendDATA(QIODevice *device, bool endStream)
312315
{
316+
printf("QHttp2Stream::sendDATA(QIODevice *%p, bool %d)\n", (void*)device, endStream);
313317
Q_ASSERT(!m_uploadDevice);
314318
Q_ASSERT(!m_uploadByteDevice);
315319
Q_ASSERT(device);
@@ -326,6 +330,7 @@ bool QHttp2Stream::sendDATA(QIODevice *device, bool endStream)
326330
m_owningByteDevice = true;
327331
byteDevice->setParent(this);
328332
m_uploadDevice = device;
333+
printf("QHttp2Stream::sendDATA, m_uploadDevice = %p, byteDevice = %p\n", (void*)device, (void*)byteDevice);
329334
return sendDATA(byteDevice, endStream);
330335
}
331336

@@ -346,6 +351,7 @@ bool QHttp2Stream::sendDATA(QIODevice *device, bool endStream)
346351
*/
347352
bool QHttp2Stream::sendDATA(QNonContiguousByteDevice *device, bool endStream)
348353
{
354+
printf("QHttp2Stream::sendDATA(QNonContiguousByteDevice *%p, bool %d)\n", (void*)device, endStream);
349355
Q_ASSERT(!m_uploadByteDevice);
350356
Q_ASSERT(device);
351357
if (m_state != State::Open && m_state != State::HalfClosedRemote) {
@@ -359,8 +365,11 @@ bool QHttp2Stream::sendDATA(QNonContiguousByteDevice *device, bool endStream)
359365
getConnection(), m_streamID, device);
360366
m_uploadByteDevice = device;
361367
m_endStreamAfterDATA = endStream;
368+
printf("QHttp2Stream::sendDATA, m_uploadByteDevice = %p\n", (void*)device);
362369
connect(m_uploadByteDevice, &QNonContiguousByteDevice::readyRead, this,
363370
&QHttp2Stream::maybeResumeUpload);
371+
auto functor = [p=m_uploadByteDevice](QObject*o){printf("m_uploadByteDevice %p destroyed %p\n",(void*)p, (void*)o);};
372+
QObject::connect(m_uploadByteDevice, &QObject::destroyed, m_uploadByteDevice, functor);
364373
connect(m_uploadByteDevice, &QObject::destroyed, this, &QHttp2Stream::uploadDeviceDestroyed);
365374

366375
internalSendDATA();
@@ -396,17 +405,22 @@ void QHttp2Stream::internalSendDATA()
396405
};
397406

398407
bool sentEND_STREAM = false;
408+
bool enteredFirstWhile = false;
409+
bool enteredSecondWhile = false;
399410
while (remainingWindowSize && deviceCanRead()) {
411+
enteredFirstWhile = true;
400412
quint32 bytesWritten = 0;
401413
qint32 remainingBytesInFrame = qint32(connection->maxFrameSize);
402414
frameWriter.start(FrameType::DATA, FrameFlag::EMPTY, streamID());
403415

404416
while (remainingWindowSize && deviceCanRead() && remainingBytesInFrame) {
417+
enteredSecondWhile = true;
405418
const qint32 maxToWrite = std::min(remainingWindowSize, remainingBytesInFrame);
406419

407420
qint64 outBytesAvail = 0;
408421
const char *readPointer = m_uploadByteDevice->readPointer(maxToWrite, outBytesAvail);
409422
if (!readPointer || outBytesAvail <= 0) {
423+
printf("not writing, readPointer: %s, outBytesAvail: %d\n", readPointer?"notnull":"null", (int)outBytesAvail);
410424
qCDebug(qHttp2ConnectionLog,
411425
"[%p] stream %u, cannot write data, device (%p) has %lld bytes available",
412426
connection, m_streamID, m_uploadByteDevice, outBytesAvail);
@@ -417,6 +431,7 @@ void QHttp2Stream::internalSendDATA()
417431
m_uploadByteDevice->advanceReadPointer(bytesToWrite);
418432

419433
bytesWritten += bytesToWrite;
434+
printf("bytesWritten: %d\n", (int)bytesWritten);
420435

421436
m_sendWindow -= bytesToWrite;
422437
Q_ASSERT(m_sendWindow >= 0);
@@ -435,26 +450,47 @@ void QHttp2Stream::internalSendDATA()
435450
frameWriter.addFlag(FrameFlag::END_STREAM);
436451
}
437452
if (!frameWriter.write(*socket)) {
453+
printf("failed to write to socket\n");
438454
qCDebug(qHttp2ConnectionLog, "[%p] stream %u, failed to write to socket", connection,
439455
m_streamID);
440456
return finishWithError(INTERNAL_ERROR, "failed to write to socket"_L1);
441457
}
442458

443459
totalBytesWritten += bytesWritten;
444460
}
461+
if(!enteredFirstWhile){
462+
printf("Did not enter first while, remainingWindowSize: %d, deviceCanRead(): %d\n", (int)remainingWindowSize, deviceCanRead());
463+
} else if(!enteredSecondWhile) {
464+
printf("Did not enter second while, remainingWindowSize: %d, deviceCanRead(): %d, remainingBytesInFrame: %d\n", (int)remainingWindowSize, deviceCanRead(), int(connection->maxFrameSize));
465+
}
445466

446467
qCDebug(qHttp2ConnectionLog,
447468
"[%p] stream %u, wrote %lld bytes total, if the device is not exhausted, we'll write "
448469
"more later. Remaining window size: %d",
449470
connection, m_streamID, totalBytesWritten, remainingWindowSize);
450471

472+
printf("emit totalBytesWritten(%d)\n", (int)totalBytesWritten);
451473
emit bytesWritten(totalBytesWritten);
452-
if (sentEND_STREAM || (!deviceCanRead() && m_uploadByteDevice->atEnd())) {
453-
qCDebug(qHttp2ConnectionLog,
454-
"[%p] stream %u, exhausted device %p, sent END_STREAM? %d, %ssending end stream "
455-
"after DATA",
456-
connection, m_streamID, m_uploadByteDevice, sentEND_STREAM,
457-
m_endStreamAfterDATA ? "" : "not ");
474+
printf("sentEND_STREAM: %d\n", sentEND_STREAM);
475+
bool dcr;
476+
bool ae;
477+
if(!sentEND_STREAM) {
478+
dcr = deviceCanRead();
479+
printf("deviceCanRead(): %d\n", dcr);
480+
if(!dcr) {
481+
ae = m_uploadByteDevice->atEnd();
482+
printf("m_uploadByteDevice->atEnd(): %d\n", ae);
483+
}
484+
}
485+
if (sentEND_STREAM || (!dcr && ae)) {
486+
//qDebug(qHttp2ConnectionLog,
487+
// "[%p] stream %u, exhausted device %p, sent END_STREAM? %d, %ssending end stream "
488+
// "after DATA",
489+
// connection, m_streamID, m_uploadByteDevice, sentEND_STREAM,
490+
// m_endStreamAfterDATA ? "" : "not ");
491+
if(!sentEND_STREAM) {
492+
printf("m_endStreamAfterDATA: %d\n", m_endStreamAfterDATA);
493+
}
458494
if (!sentEND_STREAM && m_endStreamAfterDATA) {
459495
// We need to send an empty DATA frame with END_STREAM since we
460496
// have exhausted the device, but we haven't sent END_STREAM yet.
@@ -465,13 +501,17 @@ void QHttp2Stream::internalSendDATA()
465501
}
466502
finishSendDATA();
467503
} else if (isUploadBlocked()) {
468-
qCDebug(qHttp2ConnectionLog, "[%p] stream %u, upload blocked", connection, m_streamID);
504+
printf("Upload is blocked\n");
505+
//qDebug(qHttp2ConnectionLog, "[%p] stream %u, upload blocked", connection, m_streamID);
469506
emit uploadBlocked();
507+
} else {
508+
printf("Upload is not blocked\n");
470509
}
471510
}
472511

473512
void QHttp2Stream::finishSendDATA()
474513
{
514+
printf("QHttp2Stream::finishSendDATA()\n");
475515
if (m_endStreamAfterDATA)
476516
transitionState(StateTransition::CloseLocal);
477517

@@ -593,7 +633,9 @@ void QHttp2Stream::sendWINDOW_UPDATE(quint32 delta)
593633

594634
void QHttp2Stream::uploadDeviceDestroyed()
595635
{
636+
printf("uploadDeviceDestroyed\n");
596637
if (isUploadingDATA()) {
638+
printf("isUploadingDATA is true\n");
597639
// We're in the middle of sending DATA frames, we need to abort
598640
// the stream.
599641
streamError(CANCEL, QLatin1String("Upload device destroyed while uploading"));
@@ -694,6 +736,7 @@ void QHttp2Stream::handleDATA(const Frame &inboundFrame)
694736
inboundFrame.dataSize());
695737
if (endStream)
696738
transitionState(StateTransition::CloseRemote);
739+
printf("dataReceived: `%s` endStream: %d\n", fragment.toStdString().c_str(), endStream);
697740
emit dataReceived(fragment, endStream);
698741
m_downloadBuffer.append(std::move(fragment));
699742
}
@@ -712,6 +755,12 @@ void QHttp2Stream::handleHEADERS(Http2::FrameFlags frameFlags, const HPack::Http
712755
if (endStream)
713756
transitionState(StateTransition::CloseRemote);
714757
if (!headers.empty()) {
758+
for(auto&h:headers){
759+
if( h.name.toStdString() == ":status"){
760+
printf("header ':status' %s received\n", h.value.toStdString().c_str());
761+
break;
762+
}
763+
}
715764
m_headers.insert(m_headers.end(), headers.begin(), headers.end());
716765
emit headersUpdated();
717766
}

src/network/access/qhttpthreaddelegate.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (C) 2016 The Qt Company Ltd.
22
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
33

4-
//#define QHTTPTHREADDELEGATE_DEBUG
4+
#define QHTTPTHREADDELEGATE_DEBUG
55
#include "qhttpthreaddelegate_p.h"
66

77
#include <QThread>
@@ -171,6 +171,7 @@ QThreadStorage<QNetworkAccessCache *> QHttpThreadDelegate::connections;
171171

172172
QHttpThreadDelegate::~QHttpThreadDelegate()
173173
{
174+
printf("~QHttpThreadDelegate\n");
174175
// It could be that the main thread has asked us to shut down, so we need to delete the HTTP reply
175176
if (httpReply) {
176177
delete httpReply;
@@ -181,6 +182,7 @@ QHttpThreadDelegate::~QHttpThreadDelegate()
181182
if (connections.hasLocalData() && !cacheKey.isEmpty()) {
182183
connections.localData()->releaseEntry(cacheKey);
183184
}
185+
printf("~QHttpThreadDelegate DONE\n");
184186
}
185187

186188

src/network/access/qhttpthreaddelegate_p.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ class QNonContiguousByteDeviceThreadForwardImpl : public QNonContiguousByteDevic
218218
m_pos += a;
219219

220220
// To main thread to inform about our state. The m_pos will be sent as a sanity check.
221+
printf("QNonContiguousByteDeviceThreadForwardImpl::advanceReadPointer, emit processedData(%d, %d)", (int)m_pos, (int)a);
221222
emit processedData(m_pos, a);
222223

223224
return true;
@@ -263,6 +264,8 @@ public slots:
263264
// From user thread:
264265
void haveDataSlot(qint64 pos, const QByteArray &dataArray, bool dataAtEnd, qint64 dataSize)
265266
{
267+
printf("QNonContiguousByteDeviceThreadForwardImpl::haveDataSlot(%d, dataArray with size %d, %d, %d)\n",
268+
(int)pos, (int)dataArray.size(), dataAtEnd, (int)dataSize);
266269
if (pos != m_pos) {
267270
// Sometimes when re-sending a request in the qhttpnetwork* layer there is a pending haveData from the
268271
// user thread on the way to us. We need to ignore it since it is the data for the wrong(later) chunk.
@@ -274,6 +277,9 @@ public slots:
274277
m_data = const_cast<char*>(m_dataArray.constData());
275278
m_amount = dataArray.size();
276279

280+
if(!m_atEnd && dataAtEnd) {
281+
printf("m_atEnd: false -> true\n");
282+
}
277283
m_atEnd = dataAtEnd;
278284
m_size = dataSize;
279285

src/network/access/qnetworkaccesscachebackend.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (C) 2016 The Qt Company Ltd.
22
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
33

4-
//#define QNETWORKACCESSCACHEBACKEND_DEBUG
4+
#define QNETWORKACCESSCACHEBACKEND_DEBUG
55

66
#include "qnetworkaccesscachebackend_p.h"
77
#include "qabstractnetworkcache.h"

src/network/access/qnetworkdiskcache.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (C) 2016 The Qt Company Ltd.
22
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
33

4-
//#define QNETWORKDISKCACHE_DEBUG
4+
#define QNETWORKDISKCACHE_DEBUG
55

66

77
#include "qnetworkdiskcache.h"
@@ -511,13 +511,6 @@ qint64 QNetworkDiskCache::expire()
511511
if (totalSize < goal)
512512
break;
513513
}
514-
#if defined(QNETWORKDISKCACHE_DEBUG)
515-
if (removedFiles > 0) {
516-
qDebug() << "QNetworkDiskCache::expire()"
517-
<< "Removed:" << removedFiles
518-
<< "Kept:" << cacheItems.count() - removedFiles;
519-
}
520-
#endif
521514
return totalSize;
522515
}
523516

src/network/access/qnetworkreplyhttpimpl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
33
// Qt-Security score:critical reason:network-protocol
44

5-
//#define QNETWORKACCESSHTTPBACKEND_DEBUG
5+
#define QNETWORKACCESSHTTPBACKEND_DEBUG
66

77
#include "qnetworkreplyhttpimpl_p.h"
88
#include "qnetworkaccessmanager_p.h"
@@ -1588,6 +1588,7 @@ void QNetworkReplyHttpImplPrivate::sentUploadDataSlot(qint64 pos, qint64 amount)
15881588
error(QNetworkReply::UnknownNetworkError, QString());
15891589
return;
15901590
}
1591+
printf("QNetworkReplyHttpImplPrivate::sentUploadDataSlot(%d, %d)\n",(int)pos,(int)amount);
15911592
uploadByteDevice->advanceReadPointer(amount);
15921593
uploadByteDevicePosition += amount;
15931594
}

src/network/socket/qtcpsocket.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (C) 2016 The Qt Company Ltd.
22
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
33

4-
//#define QTCPSOCKET_DEBUG
4+
#define QTCPSOCKET_DEBUG
55

66
/*!
77
\class QTcpSocket

0 commit comments

Comments
 (0)