Store crash/desync logs in crash/desync savegame

Add console command to dump loaded debug log
This commit is contained in:
Jonathan G Rennison
2019-05-21 01:49:40 +01:00
parent 951a50ddd9
commit 5a9790a196
20 changed files with 90 additions and 1 deletions

42
src/saveload/debug_sl.cpp Normal file
View File

@@ -0,0 +1,42 @@
/* $Id$ */
/*
* This file is part of OpenTTD.
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file debug_sl.cpp Code handling saving and loading of debugging information */
#include "../stdafx.h"
#include "../debug.h"
#include "saveload.h"
#include "saveload_buffer.h"
#include "../safeguards.h"
static void Save_DBGL()
{
if (_savegame_DBGL_data != nullptr) {
size_t length = strlen(_savegame_DBGL_data);
SlSetLength(length);
MemoryDumper::GetCurrent()->CopyBytes(reinterpret_cast<const byte *>(_savegame_DBGL_data), length);
} else {
SlSetLength(0);
}
}
static void Load_DBGL()
{
size_t length = SlGetFieldLength();
if (length) {
_loadgame_DBGL_data.resize(length);
ReadBuffer::GetCurrent()->CopyBytes(reinterpret_cast<byte *>(const_cast<char *>(_loadgame_DBGL_data.data())), length);
}
}
extern const ChunkHandler _debug_chunk_handlers[] = {
{ 'DBGL', Save_DBGL, Load_DBGL, nullptr, nullptr, CH_RIFF | CH_LAST},
};

View File

@@ -106,6 +106,7 @@ const SlxiSubChunkInfo _sl_xv_sub_chunk_infos[] = {
{ XSLFI_RV_OVERTAKING, XSCF_NULL, 1, 1, "roadveh_overtaking", nullptr, nullptr, nullptr },
{ XSLFI_LINKGRAPH_MODES, XSCF_NULL, 1, 1, "linkgraph_modes", nullptr, nullptr, nullptr },
{ XSLFI_GAME_EVENTS, XSCF_NULL, 1, 1, "game_events", nullptr, nullptr, nullptr },
{ XSLFI_DEBUG, XSCF_IGNORABLE_ALL, 1, 1, "debug", nullptr, nullptr, "DBGL" },
{ XSLFI_NULL, XSCF_NULL, 0, 0, nullptr, nullptr, nullptr, nullptr },// This is the end marker
};

View File

@@ -73,6 +73,7 @@ enum SlXvFeatureIndex {
XSLFI_RV_OVERTAKING, ///< Roadvehicle overtaking
XSLFI_LINKGRAPH_MODES, ///< Linkgraph additional distribution modes
XSLFI_GAME_EVENTS, ///< Game event flags
XSLFI_DEBUG, ///< Debugging info
XSLFI_RIFF_HEADER_60_BIT, ///< Size field in RIFF chunk header is 60 bit
XSLFI_HEIGHT_8_BIT, ///< Map tile height is 8 bit instead of 4 bit, but savegame version may be before this became true in trunk

View File

@@ -274,6 +274,7 @@ extern const ChunkHandler _template_replacement_chunk_handlers[];
extern const ChunkHandler _template_vehicle_chunk_handlers[];
extern const ChunkHandler _bridge_signal_chunk_handlers[];
extern const ChunkHandler _tunnel_chunk_handlers[];
extern const ChunkHandler _debug_chunk_handlers[];
/** Array of all chunks in a savegame, \c nullptr terminated. */
static const ChunkHandler * const _chunk_handlers[] = {
@@ -318,6 +319,7 @@ static const ChunkHandler * const _chunk_handlers[] = {
_template_vehicle_chunk_handlers,
_bridge_signal_chunk_handlers,
_tunnel_chunk_handlers,
_debug_chunk_handlers,
nullptr,
};

View File

@@ -197,7 +197,7 @@ struct MemoryDumper {
*this->buf++ = b;
}
inline void CopyBytes(byte *ptr, size_t length)
inline void CopyBytes(const byte *ptr, size_t length)
{
while (length) {
if (unlikely(this->buf == this->bufe)) {