2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 06:26:18 +00:00

Swap 'alpha' and 'beta'. Happy debugging!

This commit is contained in:
John Preston
2018-09-26 17:58:09 +03:00
parent a949c5e287
commit 6e566e0165
32 changed files with 379 additions and 727 deletions

View File

@@ -1069,172 +1069,6 @@ BOOL _getModuleInfo(HANDLE hProcess, DWORD64 baseAddr, IMAGEHLP_MODULEW64 *pModu
void psWriteDump() {
}
char ImageHlpSymbol64[sizeof(IMAGEHLP_SYMBOL64) + StackEntryMaxNameLength];
QString psPrepareCrashDump(const QByteArray &crashdump, QString dumpfile) {
if (!LoadDbgHelp(true) || cExeName().isEmpty()) {
return qsl("ERROR: could not init dbghelp.dll!");
}
HANDLE hProcess = GetCurrentProcess();
QString initial = QString::fromUtf8(crashdump), result;
QStringList lines = initial.split('\n');
result.reserve(initial.size());
int32 i = 0, l = lines.size();
QString versionstr;
uint64 version = 0, betaversion = 0;
for (; i < l; ++i) {
result.append(lines.at(i)).append('\n');
QString line = lines.at(i).trimmed();
if (line.startsWith(qstr("Version: "))) {
versionstr = line.mid(qstr("Version: ").size()).trimmed();
version = versionstr.toULongLong();
if (versionstr.endsWith(qstr("beta"))) {
if (version % 1000) {
betaversion = version;
} else {
version /= 1000;
}
}
++i;
break;
}
}
// maybe need to launch another executable
QString tolaunch;
if ((betaversion && betaversion != cBetaVersion()) || (!betaversion && version && version != AppVersion)) {
QString path = cExeDir();
QRegularExpressionMatch m = QRegularExpression("deploy/\\d+\\.\\d+/\\d+\\.\\d+\\.\\d+(/|\\.dev/|\\.alpha/|_\\d+/)(Telegram/)?$").match(path);
if (m.hasMatch()) {
QString base = path.mid(0, m.capturedStart()) + qstr("deploy/");
int32 major = version / 1000000, minor = (version % 1000000) / 1000, micro = (version % 1000);
base += qsl("%1.%2/%3.%4.%5").arg(major).arg(minor).arg(major).arg(minor).arg(micro);
if (betaversion) {
base += qsl("_%1").arg(betaversion);
} else if (QDir(base + qstr(".dev")).exists()) {
base += qstr(".dev");
} else if (QDir(base + qstr(".alpha")).exists()) {
base += qstr(".alpha");
}
if (QFile(base + qstr("/Telegram/Telegram.exe")).exists()) {
base += qstr("/Telegram");
}
tolaunch = base + qstr("Telegram.exe");
}
}
if (!tolaunch.isEmpty()) {
result.append(qsl("ERROR: for this crashdump executable '%1' should be used!").arg(tolaunch));
}
while (i < l) {
for (; i < l; ++i) {
result.append(lines.at(i)).append('\n');
QString line = lines.at(i).trimmed();
if (line == qstr("Backtrace:")) {
++i;
break;
}
}
IMAGEHLP_SYMBOL64 *pSym = NULL;
IMAGEHLP_MODULEW64 Module;
IMAGEHLP_LINEW64 Line;
pSym = (IMAGEHLP_SYMBOL64*)ImageHlpSymbol64;
memset(pSym, 0, sizeof(IMAGEHLP_SYMBOL64) + StackEntryMaxNameLength);
pSym->SizeOfStruct = sizeof(IMAGEHLP_SYMBOL64);
pSym->MaxNameLength = StackEntryMaxNameLength;
memset(&Line, 0, sizeof(Line));
Line.SizeOfStruct = sizeof(Line);
memset(&Module, 0, sizeof(Module));
Module.SizeOfStruct = sizeof(Module);
StackEntry csEntry;
for (int32 start = i; i < l; ++i) {
QString line = lines.at(i).trimmed();
if (line.isEmpty()) break;
result.append(qsl("%1. ").arg(i + 1 - start));
if (!QRegularExpression(qsl("^\\d+$")).match(line).hasMatch()) {
if (!lines.at(i).startsWith(qstr("ERROR: "))) {
result.append(qstr("BAD LINE: "));
}
result.append(line).append('\n');
continue;
}
DWORD64 address = line.toULongLong();
csEntry.offset = address;
csEntry.name[0] = 0;
csEntry.undName[0] = 0;
csEntry.undFullName[0] = 0;
csEntry.offsetFromSmybol = 0;
csEntry.offsetFromLine = 0;
csEntry.lineFileName[0] = 0;
csEntry.lineNumber = 0;
csEntry.loadedImageName[0] = 0;
csEntry.moduleName[0] = 0;
if (symGetSymFromAddr64(hProcess, address, &(csEntry.offsetFromSmybol), pSym) != FALSE) {
// TODO: Mache dies sicher...!
strcpy_s(csEntry.name, pSym->Name);
unDecorateSymbolName(pSym->Name, csEntry.undName, StackEntryMaxNameLength, UNDNAME_NAME_ONLY);
unDecorateSymbolName(pSym->Name, csEntry.undFullName, StackEntryMaxNameLength, UNDNAME_COMPLETE);
if (symGetLineFromAddr64) {
if (symGetLineFromAddr64(hProcess, address, &(csEntry.offsetFromLine), &Line) != FALSE) {
csEntry.lineNumber = Line.LineNumber;
// TODO: Mache dies sicher...!
wcscpy_s(csEntry.lineFileName, Line.FileName);
}
}
} else {
result.append("ERROR: could not get Sym from Addr! for ").append(QString::number(address)).append('\n');
continue;
}
if (_getModuleInfo(hProcess, address, &Module) != FALSE) {
// TODO: Mache dies sicher...!
wcscpy_s(csEntry.moduleName, Module.ModuleName);
}
if (csEntry.name[0] == 0) {
strcpy_s(csEntry.name, "(function-name not available)");
}
if (csEntry.undName[0] != 0) {
strcpy_s(csEntry.name, csEntry.undName);
}
if (csEntry.undFullName[0] != 0) {
strcpy_s(csEntry.name, csEntry.undFullName);
}
if (csEntry.lineFileName[0] == 0) {
if (csEntry.moduleName[0] == 0) {
wcscpy_s(csEntry.moduleName, L"module-name not available");
}
result.append(csEntry.name).append(qsl(" (%1) 0x%3").arg(QString::fromWCharArray(csEntry.moduleName)).arg(address, 0, 16)).append('\n');
} else {
QString file = QString::fromWCharArray(csEntry.lineFileName).toLower();
int32 index = file.indexOf(qstr("tbuild\\tdesktop\\telegram\\"));
if (index >= 0) {
file = file.mid(index + qstr("tbuild\\tdesktop\\telegram\\").size());
if (file.startsWith(qstr("sourcefiles\\"))) {
file = file.mid(qstr("sourcefiles\\").size());
}
}
result.append(csEntry.name).append(qsl(" (%1 - %2) 0x%3").arg(file).arg(csEntry.lineNumber).arg(address, 0, 16)).append('\n');
}
}
}
symCleanup(hProcess);
return result;
}
void psWriteStackTrace() {
#ifndef TDESKTOP_DISABLE_CRASH_REPORTS
if (!LoadDbgHelp()) {