mirror of
https://github.com/telegramdesktop/tdesktop
synced 2024-12-14 18:34:49 +00:00
fixed debug logs in os x crashes
This commit is contained in:
parent
a9a01cf396
commit
898f8e66c1
@ -164,7 +164,7 @@ void DialogsListWidget::peopleResultPaint(UserData *user, QPainter &p, int32 w,
|
||||
p.setPen(st::dlgSystemColor->p);
|
||||
p.drawText(tr.left(), tr.top() + st::dlgHistFont->ascent, first);
|
||||
p.setPen(st::dlgTextColor->p);
|
||||
p.drawText(tr.left() + w, tr.top() + st::dlgHistFont->ascent, second);
|
||||
p.drawText(tr.left() + w, tr.top() + st::dlgHistFont->ascent, st::dlgHistFont->m.elidedText(second, Qt::ElideRight, tr.width() - w));
|
||||
}
|
||||
} else {
|
||||
p.setPen((act ? st::dlgActiveColor : st::dlgSystemColor)->p);
|
||||
|
@ -255,21 +255,25 @@ def addTextSerialize(dct):
|
||||
|
||||
if len(result):
|
||||
result += '\n';
|
||||
result += '\t\tcase mtpc_' + name + ':\n';
|
||||
result += '\t\t\tto.add("{ ' + name + '");\n';
|
||||
result += '\t\t\tcase mtpc_' + name + ':\n';
|
||||
if (len(prms)):
|
||||
result += '\t\t\tto.add("\\n").add(add);\n';
|
||||
result += '\t\t\t\tif (stage) {\n';
|
||||
result += '\t\t\t\t\tto.add(",\\n").addSpaces(lev);\n';
|
||||
result += '\t\t\t\t} else {\n';
|
||||
result += '\t\t\t\t\tto.add("{ ' + name + '");\n';
|
||||
result += '\t\t\t\t\tto.add("\\n").addSpaces(lev);\n';
|
||||
result += '\t\t\t\t}\n';
|
||||
result += '\t\t\t\tswitch (stage) {\n';
|
||||
stage = 0;
|
||||
for k in prmsList:
|
||||
v = prms[k];
|
||||
result += '\t\t\tto.add(" ' + k + ': "); mtpTextSerializeType(to, from, end';
|
||||
result += '\t\t\t\tcase ' + str(stage) + ': to.add(" ' + k + ': "); ++stages.back(); types.push_back(';
|
||||
vtypeget = re.match(r'^[Vv]ector<MTP([A-Za-z0-9\._]+)>', v);
|
||||
if (vtypeget):
|
||||
if (not re.match(r'^[A-Z]', v)):
|
||||
result += ', mtpc_vector';
|
||||
result += 'mtpc_vector';
|
||||
else:
|
||||
result += ', 0';
|
||||
result += ', level + 1';
|
||||
|
||||
result += '0';
|
||||
restype = vtypeget.group(1);
|
||||
try:
|
||||
if boxed[restype]:
|
||||
@ -291,18 +295,26 @@ def addTextSerialize(dct):
|
||||
if (len(conses) > 1):
|
||||
print('Complex bare type found: "' + restype + '" trying to serialize "' + k + '" of type "' + v + '"');
|
||||
continue;
|
||||
result += ', mtpc_' + conses[0][0];
|
||||
if (vtypeget):
|
||||
result += '); vtypes.push_back(';
|
||||
result += 'mtpc_' + conses[0][0];
|
||||
if (not vtypeget):
|
||||
result += '); vtypes.push_back(0';
|
||||
except KeyError:
|
||||
result += ', mtpc_' + restype;
|
||||
if (not vtypeget):
|
||||
result += ', level + 1';
|
||||
if (vtypeget):
|
||||
result += '); vtypes.push_back(';
|
||||
result += 'mtpc_' + restype;
|
||||
if (not vtypeget):
|
||||
result += '); vtypes.push_back(0';
|
||||
else:
|
||||
if (not vtypeget):
|
||||
result += ', 0, level + 1';
|
||||
result += '); to.add(",\\n").add(add);\n';
|
||||
result += '0); vtypes.push_back(0';
|
||||
result += '); stages.push_back(0); break;\n';
|
||||
stage = stage + 1;
|
||||
result += '\t\t\t\tdefault: to.add("}"); types.pop_back(); vtypes.pop_back(); stages.pop_back(); break;\n';
|
||||
result += '\t\t\t\t}\n';
|
||||
else:
|
||||
result += '\t\t\tto.add(" ");\n';
|
||||
result += '\t\t\tto.add("}");\n\t\tbreak;\n';
|
||||
result += '\t\t\t\tto.add("{ ' + name + ' }"); types.pop_back(); vtypes.pop_back(); stages.pop_back();\n';
|
||||
result += '\t\t\tbreak;\n';
|
||||
return result;
|
||||
|
||||
textSerialize += addTextSerialize(typesDict) + '\n';
|
||||
@ -573,23 +585,39 @@ for restype in typesList:
|
||||
typesText += 'typedef MTPBoxed<MTP' + restype + '> MTP' + resType + ';\n'; # boxed type definition
|
||||
|
||||
textSerializeFull = '\nvoid mtpTextSerializeType(MTPStringLogger &to, const mtpPrime *&from, const mtpPrime *end, mtpPrime cons, uint32 level, mtpPrime vcons) {\n';
|
||||
textSerializeFull += '\tQString add = QString(" ").repeated(level * 2);\n\n';
|
||||
textSerializeFull += '\tQVector<mtpTypeId> types, vtypes;\n';
|
||||
textSerializeFull += '\tQVector<int32> stages;\n';
|
||||
textSerializeFull += '\ttypes.reserve(20); vtypes.reserve(20); stages.reserve(20);\n';
|
||||
textSerializeFull += '\ttypes.push_back(mtpTypeId(cons)); vtypes.push_back(mtpTypeId(vcons)); stages.push_back(0);\n\n';
|
||||
textSerializeFull += '\tconst mtpPrime *start = from;\n';
|
||||
textSerializeFull += '\tmtpTypeId type = cons, vtype = vcons;\n';
|
||||
textSerializeFull += '\tint32 stage = 0;\n';
|
||||
textSerializeFull += '\ttry {\n';
|
||||
textSerializeFull += '\t\tif (!cons) {\n';
|
||||
textSerializeFull += '\t\t\tif (from >= end) {\n';
|
||||
textSerializeFull += '\t\t\t\tthrow Exception("from >= 2");\n';
|
||||
textSerializeFull += '\t\twhile (!types.isEmpty()) {\n';
|
||||
textSerializeFull += '\t\t\ttype = types.back();\n';
|
||||
textSerializeFull += '\t\t\tvtype = vtypes.back();\n';
|
||||
textSerializeFull += '\t\t\tstage = stages.back();\n';
|
||||
textSerializeFull += '\t\t\tif (!type) {\n';
|
||||
textSerializeFull += '\t\t\t\tif (from >= end) {\n';
|
||||
textSerializeFull += '\t\t\t\t\tthrow Exception("from >= end");\n';
|
||||
textSerializeFull += '\t\t\t\t} else if (stage) {\n';
|
||||
textSerializeFull += '\t\t\t\t\tthrow Exception("unknown type on stage > 0");\n';
|
||||
textSerializeFull += '\t\t\t\t}\n';
|
||||
textSerializeFull += '\t\t\t\ttypes.back() = type = *from;\n';
|
||||
textSerializeFull += '\t\t\t\tstart = ++from;\n';
|
||||
textSerializeFull += '\t\t\t}\n\n';
|
||||
textSerializeFull += '\t\t\tint32 lev = level + types.size() - 1;\n';
|
||||
textSerializeFull += '\t\t\tswitch (type) {\n' + textSerialize + '\n';
|
||||
textSerializeFull += '\t\t\tdefault:\n';
|
||||
textSerializeFull += '\t\t\t\tmtpTextSerializeCore(to, from, end, type, lev, vtype);\n';
|
||||
textSerializeFull += '\t\t\t\ttypes.pop_back(); vtypes.pop_back(); stages.pop_back();\n';
|
||||
textSerializeFull += '\t\t\tbreak;\n';
|
||||
textSerializeFull += '\t\t\t}\n';
|
||||
textSerializeFull += '\t\t\tcons = *from;\n';
|
||||
textSerializeFull += '\t\t\t++from;\n';
|
||||
textSerializeFull += '\t\t\t++start;\n';
|
||||
textSerializeFull += '\t\t}\n\n';
|
||||
textSerializeFull += '\t\tswitch (mtpTypeId(cons)) {\n' + textSerialize;
|
||||
textSerializeFull += '\n\n\t\tdefault:\n\t\t\tmtpTextSerializeCore(to, from, end, cons, level, vcons);\n\t\tbreak;\n\t\t}\n\n';
|
||||
textSerializeFull += '\t\t}\n';
|
||||
textSerializeFull += '\t} catch (Exception &e) {\n';
|
||||
textSerializeFull += '\t\tto.add("[ERROR] ");\n';
|
||||
textSerializeFull += '\t\tto.add("(").add(e.what()).add("), cons: 0x").add(mtpWrapNumber(cons, 16));\n';
|
||||
textSerializeFull += '\t\tif (vcons) to.add(", vcons: 0x").add(mtpWrapNumber(vcons));\n';
|
||||
textSerializeFull += '\t\tto.add("(").add(e.what()).add("), cons: 0x").add(mtpWrapNumber(type, 16));\n';
|
||||
textSerializeFull += '\t\tif (vtype) to.add(", vcons: 0x").add(mtpWrapNumber(vtype));\n';
|
||||
textSerializeFull += '\t\tto.add(", ").add(mb(start, (end - start) * sizeof(mtpPrime)).str());\n';
|
||||
textSerializeFull += '\t}\n';
|
||||
textSerializeFull += '}\n';
|
||||
|
@ -334,7 +334,7 @@ QString MTProtoConnection::transport() const {
|
||||
namespace {
|
||||
mtpBuffer _handleHttpResponse(QNetworkReply *reply) {
|
||||
QByteArray response = reply->readAll();
|
||||
TCP_LOG(("HTTP Info: read %1 bytes %2").arg(response.size()).arg(mb(response.constData(), response.size()).str()));
|
||||
TCP_LOG(("HTTP Info: read %1 bytes").arg(response.size()));
|
||||
|
||||
if (response.isEmpty()) return mtpBuffer();
|
||||
|
||||
@ -544,7 +544,7 @@ void MTPabstractTcpConnection::socketRead() {
|
||||
}
|
||||
int32 bytes = (int32)sock.read(readTo, toRead);
|
||||
if (bytes > 0) {
|
||||
TCP_LOG(("TCP Info: read %1 bytes %2").arg(bytes).arg(mb(readTo, bytes).str()));
|
||||
TCP_LOG(("TCP Info: read %1 bytes").arg(bytes));
|
||||
|
||||
packetRead += bytes;
|
||||
currentPos += bytes;
|
||||
@ -676,7 +676,7 @@ void MTPautoConnection::tcpSend(mtpBuffer &buffer) {
|
||||
buffer[0] = len;
|
||||
buffer[1] = packetNum++;
|
||||
buffer[size - 1] = hashCrc32(&buffer[0], len - 4);
|
||||
TCP_LOG(("TCP Info: write %1 packet %2 bytes %3").arg(packetNum).arg(len).arg(mb(&buffer[0], len).str()));
|
||||
TCP_LOG(("TCP Info: write %1 packet %2 bytes").arg(packetNum).arg(len));
|
||||
|
||||
sock.write((const char*)&buffer[0], len);
|
||||
}
|
||||
@ -688,7 +688,7 @@ void MTPautoConnection::httpSend(mtpBuffer &buffer) {
|
||||
request.setHeader(QNetworkRequest::ContentLengthHeader, QVariant(requestSize));
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, QVariant(qsl("application/x-www-form-urlencoded")));
|
||||
|
||||
TCP_LOG(("HTTP Info: sending %1 len request %2").arg(requestSize).arg(mb(&buffer[2], requestSize).str()));
|
||||
TCP_LOG(("HTTP Info: sending %1 len request").arg(requestSize));
|
||||
requests.insert(manager.post(request, QByteArray((const char*)(&buffer[2]), requestSize)));
|
||||
}
|
||||
|
||||
@ -1702,7 +1702,7 @@ void MTProtoConnectionPrivate::handleReceived() {
|
||||
conn->received().pop_front();
|
||||
return restart();
|
||||
}
|
||||
TCP_LOG(("TCP Info: decrypted message %1,%2,%3 is %4").arg(msgId).arg(seqNo).arg(logBool(needAck)).arg(mb(data, msgLen + 8 * sizeof(mtpPrime)).str()));
|
||||
TCP_LOG(("TCP Info: decrypted message %1,%2,%3 is %4 len").arg(msgId).arg(seqNo).arg(logBool(needAck)).arg(msgLen + 8 * sizeof(mtpPrime)));
|
||||
|
||||
uint64 serverSession = sessionData->getSession();
|
||||
if (session != serverSession) {
|
||||
|
@ -25,8 +25,6 @@ QString mtpWrapNumber(float64 number) {
|
||||
}
|
||||
|
||||
void mtpTextSerializeCore(MTPStringLogger &to, const mtpPrime *&from, const mtpPrime *end, mtpTypeId cons, uint32 level, mtpPrime vcons) {
|
||||
QString add = QString(" ").repeated(level * 2);
|
||||
|
||||
switch (mtpTypeId(cons)) {
|
||||
case mtpc_int: {
|
||||
MTPint value(from, end, cons);
|
||||
@ -77,11 +75,11 @@ void mtpTextSerializeCore(MTPStringLogger &to, const mtpPrime *&from, const mtpP
|
||||
int32 cnt = *(from++);
|
||||
to.add("[ vector<0x").add(mtpWrapNumber(vcons, 16)).add(">");
|
||||
if (cnt) {
|
||||
to.add("\n").add(add);
|
||||
to.add("\n").addSpaces(level);
|
||||
for (int32 i = 0; i < cnt; ++i) {
|
||||
to.add(" ");
|
||||
mtpTextSerializeType(to, from, end, vcons, level + 1);
|
||||
to.add(",\n").add(add);
|
||||
to.add(",\n").addSpaces(level);
|
||||
}
|
||||
} else {
|
||||
to.add(" ");
|
||||
@ -91,9 +89,9 @@ void mtpTextSerializeCore(MTPStringLogger &to, const mtpPrime *&from, const mtpP
|
||||
|
||||
case mtpc_error: {
|
||||
to.add("{ error");
|
||||
to.add("\n").add(add);
|
||||
to.add(" code: "); mtpTextSerializeType(to, from, end, mtpc_int, level + 1); to.add(",\n").add(add);
|
||||
to.add(" text: "); mtpTextSerializeType(to, from, end, mtpc_string, level + 1); to.add(",\n").add(add);
|
||||
to.add("\n").addSpaces(level);
|
||||
to.add(" code: "); mtpTextSerializeType(to, from, end, mtpc_int, level + 1); to.add(",\n").addSpaces(level);
|
||||
to.add(" text: "); mtpTextSerializeType(to, from, end, mtpc_string, level + 1); to.add(",\n").addSpaces(level);
|
||||
to.add("}");
|
||||
} break;
|
||||
|
||||
@ -105,26 +103,26 @@ void mtpTextSerializeCore(MTPStringLogger &to, const mtpPrime *&from, const mtpP
|
||||
|
||||
case mtpc_rpc_result: {
|
||||
to.add("{ rpc_result");
|
||||
to.add("\n").add(add);
|
||||
to.add(" req_msg_id: "); mtpTextSerializeType(to, from, end, mtpc_long, level + 1); to.add(",\n").add(add);
|
||||
to.add(" result: "); mtpTextSerializeType(to, from, end, 0, level + 1); to.add(",\n").add(add);
|
||||
to.add("\n").addSpaces(level);
|
||||
to.add(" req_msg_id: "); mtpTextSerializeType(to, from, end, mtpc_long, level + 1); to.add(",\n").addSpaces(level);
|
||||
to.add(" result: "); mtpTextSerializeType(to, from, end, 0, level + 1); to.add(",\n").addSpaces(level);
|
||||
to.add("}");
|
||||
} break;
|
||||
|
||||
case mtpc_msg_container: {
|
||||
to.add("{ msg_container");
|
||||
to.add("\n").add(add);
|
||||
to.add(" messages: "); mtpTextSerializeType(to, from, end, mtpc_vector, level + 1, mtpc_core_message); to.add(",\n").add(add);
|
||||
to.add("\n").addSpaces(level);
|
||||
to.add(" messages: "); mtpTextSerializeType(to, from, end, mtpc_vector, level + 1, mtpc_core_message); to.add(",\n").addSpaces(level);
|
||||
to.add("}");
|
||||
} break;
|
||||
|
||||
case mtpc_core_message: {
|
||||
to.add("{ core_message");
|
||||
to.add("\n").add(add);
|
||||
to.add(" msg_id: "); mtpTextSerializeType(to, from, end, mtpc_long, level + 1); to.add(",\n").add(add);
|
||||
to.add(" seq_no: "); mtpTextSerializeType(to, from, end, mtpc_int, level + 1); to.add(",\n").add(add);
|
||||
to.add(" bytes: "); mtpTextSerializeType(to, from, end, mtpc_int, level + 1); to.add(",\n").add(add);
|
||||
to.add(" body: "); mtpTextSerializeType(to, from, end, 0, level + 1); to.add(",\n").add(add);
|
||||
to.add("\n").addSpaces(level);
|
||||
to.add(" msg_id: "); mtpTextSerializeType(to, from, end, mtpc_long, level + 1); to.add(",\n").addSpaces(level);
|
||||
to.add(" seq_no: "); mtpTextSerializeType(to, from, end, mtpc_int, level + 1); to.add(",\n").addSpaces(level);
|
||||
to.add(" bytes: "); mtpTextSerializeType(to, from, end, mtpc_int, level + 1); to.add(",\n").addSpaces(level);
|
||||
to.add(" body: "); mtpTextSerializeType(to, from, end, 0, level + 1); to.add(",\n").addSpaces(level);
|
||||
to.add("}");
|
||||
} break;
|
||||
|
||||
|
@ -1026,19 +1026,35 @@ struct MTPStringLogger {
|
||||
if (len < 0) len = strlen(data);
|
||||
if (!len) return (*this);
|
||||
|
||||
if (size + len > alloced) {
|
||||
int32 newsize = size + len;
|
||||
if (newsize % MTPDebugBufferSize) newsize += MTPDebugBufferSize - (newsize % MTPDebugBufferSize);
|
||||
char *b = new char[newsize];
|
||||
memcpy(b, p, size);
|
||||
alloced = newsize;
|
||||
delete p;
|
||||
p = b;
|
||||
}
|
||||
ensureLength(len);
|
||||
memcpy(p + size, data, len);
|
||||
size += len;
|
||||
return (*this);
|
||||
}
|
||||
|
||||
MTPStringLogger &addSpaces(int32 level) {
|
||||
int32 len = level * 2;
|
||||
if (!len) return (*this);
|
||||
|
||||
ensureLength(len);
|
||||
for (char *ptr = p + size, *end = ptr + len; ptr != end; ++ptr) {
|
||||
*ptr = ' ';
|
||||
}
|
||||
size += len;
|
||||
return (*this);
|
||||
}
|
||||
|
||||
void ensureLength(int32 add) {
|
||||
if (size + add <= alloced) return;
|
||||
|
||||
int32 newsize = size + add;
|
||||
if (newsize % MTPDebugBufferSize) newsize += MTPDebugBufferSize - (newsize % MTPDebugBufferSize);
|
||||
char *b = new char[newsize];
|
||||
memcpy(b, p, size);
|
||||
alloced = newsize;
|
||||
delete p;
|
||||
p = b;
|
||||
}
|
||||
char *p;
|
||||
int32 size, alloced;
|
||||
};
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -19,9 +19,9 @@ Copyright (c) 2014 John Preston, https://tdesktop.com
|
||||
|
||||
extern bool gDebug;
|
||||
inline bool cDebug() {
|
||||
#if defined _DEBUG && !defined Q_OS_MAC
|
||||
#if defined _DEBUG
|
||||
return true;
|
||||
#elif defined _WITH_DEBUG || (defined _DEBUG && defined Q_OS_MAC)
|
||||
#elif defined _WITH_DEBUG
|
||||
return gDebug;
|
||||
#else
|
||||
return false;
|
||||
|
Loading…
Reference in New Issue
Block a user