Store crash/desync logs in crash/desync savegame

Add console command to dump loaded debug log
pull/91/head
Jonathan G Rennison 5 years ago
parent 951a50ddd9
commit 5a9790a196

@ -938,6 +938,7 @@
<ClCompile Include="..\src\saveload\cargopacket_sl.cpp" />
<ClCompile Include="..\src\saveload\cheat_sl.cpp" />
<ClCompile Include="..\src\saveload\company_sl.cpp" />
<ClCompile Include="..\src\saveload\debug_sl.cpp" />
<ClCompile Include="..\src\saveload\depot_sl.cpp" />
<ClCompile Include="..\src\saveload\economy_sl.cpp" />
<ClCompile Include="..\src\saveload\engine_sl.cpp" />

@ -1908,6 +1908,9 @@
<ClCompile Include="..\src\saveload\company_sl.cpp">
<Filter>Save/Load handlers</Filter>
</ClCompile>
<ClCompile Include="..\src\saveload\debug_sl.cpp">
<Filter>Save/Load handlers</Filter>
</ClCompile>
<ClCompile Include="..\src\saveload\depot_sl.cpp">
<Filter>Save/Load handlers</Filter>
</ClCompile>

@ -938,6 +938,7 @@
<ClCompile Include="..\src\saveload\cargopacket_sl.cpp" />
<ClCompile Include="..\src\saveload\cheat_sl.cpp" />
<ClCompile Include="..\src\saveload\company_sl.cpp" />
<ClCompile Include="..\src\saveload\debug_sl.cpp" />
<ClCompile Include="..\src\saveload\depot_sl.cpp" />
<ClCompile Include="..\src\saveload\economy_sl.cpp" />
<ClCompile Include="..\src\saveload\engine_sl.cpp" />

@ -1908,6 +1908,9 @@
<ClCompile Include="..\src\saveload\company_sl.cpp">
<Filter>Save/Load handlers</Filter>
</ClCompile>
<ClCompile Include="..\src\saveload\debug_sl.cpp">
<Filter>Save/Load handlers</Filter>
</ClCompile>
<ClCompile Include="..\src\saveload\depot_sl.cpp">
<Filter>Save/Load handlers</Filter>
</ClCompile>

@ -938,6 +938,7 @@
<ClCompile Include="..\src\saveload\cargopacket_sl.cpp" />
<ClCompile Include="..\src\saveload\cheat_sl.cpp" />
<ClCompile Include="..\src\saveload\company_sl.cpp" />
<ClCompile Include="..\src\saveload\debug_sl.cpp" />
<ClCompile Include="..\src\saveload\depot_sl.cpp" />
<ClCompile Include="..\src\saveload\economy_sl.cpp" />
<ClCompile Include="..\src\saveload\engine_sl.cpp" />

@ -1908,6 +1908,9 @@
<ClCompile Include="..\src\saveload\company_sl.cpp">
<Filter>Save/Load handlers</Filter>
</ClCompile>
<ClCompile Include="..\src\saveload\debug_sl.cpp">
<Filter>Save/Load handlers</Filter>
</ClCompile>
<ClCompile Include="..\src\saveload\depot_sl.cpp">
<Filter>Save/Load handlers</Filter>
</ClCompile>

@ -652,6 +652,7 @@ saveload/cargomonitor_sl.cpp
saveload/cargopacket_sl.cpp
saveload/cheat_sl.cpp
saveload/company_sl.cpp
saveload/debug_sl.cpp
saveload/depot_sl.cpp
saveload/economy_sl.cpp
saveload/engine_sl.cpp

@ -2054,6 +2054,18 @@ DEF_CONSOLE_CMD(ConDumpGameEvents)
return true;
}
DEF_CONSOLE_CMD(ConDumpLoadDebugLog)
{
if (argc == 0) {
IConsoleHelp("Dump load debug log.");
return true;
}
std::string dbgl = _loadgame_DBGL_data;
PrintLineByLine(const_cast<char *>(_loadgame_DBGL_data.c_str()));
return true;
}
DEF_CONSOLE_CMD(ConCheckCaches)
{
if (argc == 0) {
@ -2329,6 +2341,7 @@ void IConsoleStdLibRegister()
IConsoleCmdRegister("dump_veh_stats", ConVehicleStats, nullptr, true);
IConsoleCmdRegister("dump_map_stats", ConMapStats, nullptr, true);
IConsoleCmdRegister("dump_game_events", ConDumpGameEvents, nullptr, true);
IConsoleCmdRegister("dump_load_debug_log", ConDumpLoadDebugLog, nullptr, true);
IConsoleCmdRegister("check_caches", ConCheckCaches, nullptr, true);
/* NewGRF development stuff */

@ -587,6 +587,7 @@ bool CrashLog::MakeCrashLog() const
}
SetScreenshotAuxiliaryText("Crash Log", buffer);
_savegame_DBGL_data = buffer;
if (IsNonMainThread()) {
printf("Asking main thread to write crash savegame and screenshot...\n\n");
@ -633,6 +634,7 @@ bool CrashLog::MakeDesyncCrashLog() const
ret = false;
}
_savegame_DBGL_data = buffer;
bret = this->WriteSavegame(filename, lastof(filename), name_buffer);
if (bret) {
printf("Desync savegame written to %s. Please add this file and the last (auto)save to any bug reports.\n\n", filename);
@ -640,6 +642,7 @@ bool CrashLog::MakeDesyncCrashLog() const
ret = false;
printf("Writing desync savegame failed. Please attach the last (auto)save to any bug reports.\n\n");
}
_savegame_DBGL_data = nullptr;
if (!(_screen.width < 1 || _screen.height < 1 || _screen.dst_ptr == nullptr)) {
SetScreenshotAuxiliaryText("Desync Log", buffer);

@ -54,6 +54,9 @@ int _debug_sound_level;
int _debug_random_level;
#endif
const char *_savegame_DBGL_data = nullptr;
std::string _loadgame_DBGL_data;
uint32 _realtime_tick = 0;
struct DebugLevel {

@ -14,6 +14,7 @@
#include "cpu.h"
#include <chrono>
#include <string>
/* Debugging messages policy:
* These should be the severities used for direct DEBUG() calls
@ -58,6 +59,9 @@ extern int _debug_sound_level;
extern int _debug_random_level;
#endif
extern const char *_savegame_DBGL_data;
extern std::string _loadgame_DBGL_data;
void CDECL debug(const char *dbg, const char *format, ...) WARN_FORMAT(2, 3);
char *DumpDebugFacilityNames(char *buf, char *last);

@ -81,6 +81,7 @@ void InitializeGame(uint size_x, uint size_y, bool reset_date, bool reset_settin
_thd.redsq = INVALID_TILE;
_game_events_since_load = (GameEventFlags) 0;
_game_events_overall = (GameEventFlags) 0;
_loadgame_DBGL_data.clear();
if (reset_settings) MakeNewgameSettingsLive();
if (reset_date) {

@ -384,6 +384,7 @@ static void ShutdownGame()
_game_events_since_load = (GameEventFlags) 0;
_game_events_overall = (GameEventFlags) 0;
_loadgame_DBGL_data.clear();
}
/**

@ -16,6 +16,7 @@
#include "../../saveload/saveload.h"
#include "../../thread.h"
#include "../../screenshot.h"
#include "../../debug.h"
#include "macos.h"
#include <errno.h>
@ -427,6 +428,7 @@ public:
}
printf("Writing crash savegame...\n");
_savegame_DBGL_data = buffer;
if (!this->WriteSavegame(filename_save, lastof(filename_save))) {
filename_save[0] = '\0';
ret = false;

@ -23,6 +23,7 @@
#include "../../video/video_driver.hpp"
#include "../../openttd.h"
#include "../../screenshot.h"
#include "../../debug.h"
#if defined(WITH_DEMANGLE)
#include <cxxabi.h>
#endif
@ -708,6 +709,7 @@ static INT_PTR CALLBACK CrashDialogFunc(HWND wnd, UINT msg, WPARAM wParam, LPARA
CrashLog::AfterCrashLogCleanup();
ExitProcess(2);
case 13: // Emergency save
_savegame_DBGL_data = CrashLogWindows::current->crashlog;
char filename[MAX_PATH];
if (CrashLogWindows::current->WriteSavegame(filename, lastof(filename))) {
size_t len = _tcslen(_save_succeeded) + _tcslen(OTTD2FS(filename)) + 1;
@ -717,6 +719,7 @@ static INT_PTR CALLBACK CrashDialogFunc(HWND wnd, UINT msg, WPARAM wParam, LPARA
} else {
MessageBox(wnd, _T("Save failed"), _T("Save failed"), MB_ICONINFORMATION);
}
_savegame_DBGL_data = nullptr;
break;
case 15: // Expand window to show crash-message
_expanded ^= 1;

@ -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},
};

@ -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
};

@ -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

@ -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,
};

@ -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)) {

Loading…
Cancel
Save