Improve crash debug information.

This commit is contained in:
John Preston 2018-01-03 11:23:34 +03:00
parent 6b25160e3f
commit 54dd05c556
2 changed files with 52 additions and 7 deletions

View File

@ -31,6 +31,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
#include "info/info_controller.h"
#include "window/window_controller.h"
#include "mainwindow.h"
#include "core/crash_reports.h"
namespace {
@ -224,7 +225,57 @@ base::optional<int> SharedMediaWithLastSlice::indexOfImpl(Value value) const {
}
base::optional<int> SharedMediaWithLastSlice::indexOf(Value value) const {
auto result = indexOfImpl(value);
const auto result = indexOfImpl(value);
if (result && (*result < 0 || *result >= size())) {
// Should not happen.
auto info = QStringList();
info.push_back("slice:" + QString::number(_slice.size()));
info.push_back(_slice.fullCount()
? QString::number(*_slice.fullCount())
: QString("-"));
info.push_back(_slice.skippedBefore()
? QString::number(*_slice.skippedBefore())
: QString("-"));
info.push_back(_slice.skippedAfter()
? QString::number(*_slice.skippedAfter())
: QString("-"));
info.push_back("ending:" + (_ending
? QString::number(_ending->size())
: QString("-")));
info.push_back((_ending && _ending->fullCount())
? QString::number(*_ending->fullCount())
: QString("-"));
info.push_back((_ending && _ending->skippedBefore())
? QString::number(*_ending->skippedBefore())
: QString("-"));
info.push_back((_ending && _ending->skippedAfter())
? QString::number(*_ending->skippedAfter())
: QString("-"));
if (const auto msgId = base::get_if<FullMsgId>(&value)) {
info.push_back("value:" + QString::number(msgId->channel));
info.push_back(QString::number(msgId->msg));
const auto index = _slice.indexOf(*base::get_if<FullMsgId>(&value));
info.push_back("index:" + (index
? QString::number(*index)
: QString("-")));
} else if (const auto photo = base::get_if<not_null<PhotoData*>>(&value)) {
info.push_back("value:" + QString::number((*photo)->id));
} else {
info.push_back("value:bad");
}
info.push_back("isolated:" + QString(Logs::b(isolatedInSlice())));
info.push_back("last:" + (_lastPhotoId
? QString::number(*_lastPhotoId)
: QString("-")));
info.push_back("isolated_last:" + (_isolatedLastPhoto
? QString(Logs::b(*_isolatedLastPhoto))
: QString("-")));
info.push_back("skip:" + (lastPhotoSkip()
? QString::number(*lastPhotoSkip())
: QString("-")));
CrashReports::SetAnnotation("DebugInfo", info.join(','));
Unexpected("Result in SharedMediaWithLastSlice::indexOf");
}
return _reversed
? (result | func::negate | func::add(size() - 1))
: result;

View File

@ -3037,18 +3037,12 @@ void MediaView::findCurrent() {
? (_index | func::add(*_sharedMediaData->skippedBefore()))
: base::none;
_fullCount = _sharedMediaData->fullCount();
if (_index) {
Assert(*_index >= 0 && *_index < _sharedMediaData->size());
}
} else if (_userPhotosData) {
_index = _photo ? _userPhotosData->indexOf(_photo->id) : base::none;
_fullIndex = _userPhotosData->skippedBefore()
? (_index | func::add(*_userPhotosData->skippedBefore()))
: base::none;
_fullCount = _userPhotosData->fullCount();
if (_index) {
Assert(*_index >= 0 && *_index < _userPhotosData->size());
}
} else {
_index = _fullIndex = _fullCount = base::none;
}