OpenTTD Source: CrashLog Class Reference

OpenTTD Source 13.1

Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Private Member Functions | Static Private Attributes
CrashLog Class Referenceabstract

Helper class for creating crash logs. More...

`#include <crashlog.h>`

Inheritance diagram for CrashLog:

## Public Member Functions
virtual | ~CrashLog ()
| Stub destructor to silence some compilers.
char * | FillCrashLog (char *buffer, const char *last) const
| Fill the crash log buffer with all data of a crash log. More...
bool | WriteCrashLog (const char *buffer, char *filename, const char *filename_last) const
| Write the crash log to a file. More...
virtual int | WriteCrashDump (char *filename, const char *filename_last) const
| Write the (crash) dump to a file. More...
bool | WriteSavegame (char *filename, const char *filename_last) const
| Write the (crash) savegame to a file. More...
bool | WriteScreenshot (char *filename, const char *filename_last) const
| Write the (crash) screenshot to a file. More...
bool | MakeCrashLog () const
| Makes the crash log, writes it to a file and then subsequently tries to make a crash dump and crash savegame. More...

## Static Public Member Functions
static void | InitialiseCrashLog ()
| Initialiser for crash logs; do the appropriate things so crashes are handled by our crash handler instead of returning straight to the OS. More...
static void | InitThread ()
| Prepare crash log handler for a newly started thread. More...
static void | SetErrorMessage (const char *message)
| Sets a message for the error message handler. More...
static void | AfterCrashLogCleanup ()
| Try to close the sound/video stuff so it doesn't keep lingering around incorrect video states or so, e.g. More...

## Protected Member Functions
virtual char * | LogOSVersion (char *buffer, const char *last) const =0
| Writes OS' version to the buffer. More...
virtual char * | LogCompiler (char *buffer, const char *last) const
| Writes compiler (and its version, if available) to the buffer. More...
virtual char * | LogError (char *buffer, const char *last, const char *message) const =0
| Writes actually encountered error to the buffer. More...
virtual char * | LogStacktrace (char *buffer, const char *last) const =0
| Writes the stack trace to the buffer, if there is information about it available. More...
virtual char * | LogRegisters (char *buffer, const char *last) const
| Writes information about the data in the registers, if there is information about it available. More...
virtual char * | LogModules (char *buffer, const char *last) const
| Writes the dynamically linked libraries/modules to the buffer, if there is information about it available. More...
char * | LogOpenTTDVersion (char *buffer, const char *last) const
| Writes OpenTTD's version to the buffer. More...
char * | LogConfiguration (char *buffer, const char *last) const
| Writes the (important) configuration settings to the buffer. More...
char * | LogLibraries (char *buffer, const char *last) const
| Writes information (versions) of the used libraries. More...
char * | LogGamelog (char *buffer, const char *last) const
| Writes the gamelog data to the buffer. More...
char * | LogRecentNews (char *buffer, const char *list) const
| Writes up to 32 recent news messages to the buffer, with the most recent first. More...
int | CreateFileName (char *filename, const char *filename_last, const char *ext, bool with_dir=true) const
| Create a timestamped filename. More...

## Static Private Member Functions
static void | GamelogFillCrashLog (const char *s)
| Helper function for printing the gamelog. More...

## Static Private Attributes
static const char * | message = nullptr
| Pointer to the error message.
static char * | gamelog_buffer = nullptr
| Temporary 'local' location of the buffer.
static const char * | gamelog_last = nullptr
| Temporary 'local' location of the end of the buffer.

## Detailed Description

Helper class for creating crash logs.

Definition at line 16 of file crashlog.h.

## Member Function Documentation

## ◆ AfterCrashLogCleanup()

void CrashLog::AfterCrashLogCleanup | ( |  | ) |
| static

Try to close the sound/video stuff so it doesn't keep lingering around incorrect video states or so, e.g.

keeping dpmi disabled.

Definition at line 526 of file crashlog.cpp.

References SoundDriver::GetInstance(), MusicDriver::GetInstance(), VideoDriver::GetInstance(), and Driver::Stop().

Referenced by HandleCrash().

## ◆ CreateFileName()

int CrashLog::CreateFileName | ( | char * | filename,
|  | const char * | filename_last,
|  | const char * | ext,
|  | bool | with_dir = `true`
| ) |  | const
| protected

Create a timestamped filename.

Parameters

  filename | The begin where to write at.
  filename_last | The last position in the buffer to write to.
  ext | The extension for the filename.
  with_dir | Whether to prepend the filename with the personal directory.

Returns
  the number of added characters.

Definition at line 335 of file crashlog.cpp.

References _personal_dir, Time< T >::Format(), and seprintf().

Referenced by WriteCrashLog(), and WriteSavegame().

## ◆ FillCrashLog()

char * CrashLog::FillCrashLog | ( | char * | buffer,
|  | const char * | last
| ) |  | const

Fill the crash log buffer with all data of a crash log.

Parameters

  buffer | The begin where to write at.
  last | The last position in the buffer to write to.

Returns
  the position of the `'\0'` character after the buffer.

Definition at line 352 of file crashlog.cpp.

References _date, _date_fract, ConvertDateToYMD(), YearMonthDay::day, Time< T >::Format(), LogCompiler(), LogConfiguration(), LogError(), LogGamelog(), LogLibraries(), LogModules(), LogOpenTTDVersion(), LogOSVersion(), LogRecentNews(), LogRegisters(), LogStacktrace(), message, YearMonthDay::month, seprintf(), and YearMonthDay::year.

Referenced by CrashLogOSX::MakeCrashLog().

## ◆ GamelogFillCrashLog()

void CrashLog::GamelogFillCrashLog | ( | const char * | s | ) |
| staticprivate

Helper function for printing the gamelog.

Parameters

  s | the string to print.

Definition at line 286 of file crashlog.cpp.

References gamelog_buffer, gamelog_last, and seprintf().

Referenced by LogGamelog().

## ◆ InitialiseCrashLog()

void CrashLog::InitialiseCrashLog | ( |  | ) |
| static

Initialiser for crash logs; do the appropriate things so crashes are handled by our crash handler instead of returning straight to the OS.

Note
  must be implemented by all implementers of CrashLog.

Definition at line 254 of file crashlog_osx.cpp.

References _signals_to_handle, endof, and HandleCrash().

## ◆ InitThread()

void CrashLog::InitThread | ( |  | ) |
| static

Prepare crash log handler for a newly started thread.

Note
  must be implemented by all implementers of CrashLog.

Definition at line 261 of file crashlog_osx.cpp.

## ◆ LogCompiler()

char * CrashLog::LogCompiler | ( | char * | buffer,
|  | const char * | last
| ) |  | const
| protectedvirtual

Writes compiler (and its version, if available) to the buffer.

Parameters

  buffer | The begin where to write at.
  last | The last position in the buffer to write to.

Returns
  the position of the `'\0'` character after the buffer.

Definition at line 74 of file crashlog.cpp.

References seprintf().

Referenced by FillCrashLog().

## ◆ LogConfiguration()

char * CrashLog::LogConfiguration | ( | char * | buffer,
|  | const char * | last
| ) |  | const
| protected

Writes the (important) configuration settings to the buffer.

E.g. graphics set, sound set, blitter and AIs.

Parameters

  buffer | The begin where to write at.
  last | The last position in the buffer to write to.

Returns
  the position of the `'\0'` character after the buffer.

Definition at line 155 of file crashlog.cpp.

References BlitterFactory::GetCurrentBlitter(), BaseMedia< GraphicsSet >::GetUsedSet(), and seprintf().

Referenced by FillCrashLog().

## ◆ LogError()

virtual char* CrashLog::LogError | ( | char * | buffer,
|  | const char * | last,
|  | const char * | message
| ) |  | const
| protectedpure virtual

Writes actually encountered error to the buffer.

Parameters

  buffer | The begin where to write at.
  last | The last position in the buffer to write to.
  message | Message passed to use for possible errors. Can be nullptr.

Returns
  the position of the `'\0'` character after the buffer.

Implemented in CrashLogOSX, CrashLogUnix, and CrashLogWindows.

Referenced by FillCrashLog().

## ◆ LogGamelog()

char * CrashLog::LogGamelog | ( | char * | buffer,
|  | const char * | last
| ) |  | const
| protected

Writes the gamelog data to the buffer.

Parameters

  buffer | The begin where to write at.
  last | The last position in the buffer to write to.

Returns
  the position of the `'\0'` character after the buffer.

Definition at line 297 of file crashlog.cpp.

References gamelog_buffer, gamelog_last, GamelogFillCrashLog(), GamelogPrint(), and seprintf().

Referenced by FillCrashLog().

## ◆ LogLibraries()

char * CrashLog::LogLibraries | ( | char * | buffer,
|  | const char * | last
| ) |  | const
| protected

Writes information (versions) of the used libraries.

Parameters

  buffer | The begin where to write at.
  last | The last position in the buffer to write to.

Returns
  the position of the `'\0'` character after the buffer.

Definition at line 217 of file crashlog.cpp.

References seprintf().

Referenced by FillCrashLog().

## ◆ LogModules()

char * CrashLog::LogModules | ( | char * | buffer,
|  | const char * | last
| ) |  | const
| protectedvirtual

Writes the dynamically linked libraries/modules to the buffer, if there is information about it available.

Parameters

  buffer | The begin where to write at.
  last | The last position in the buffer to write to.

Returns
  the position of the `'\0'` character after the buffer.

Reimplemented in CrashLogWindows.

Definition at line 104 of file crashlog.cpp.

Referenced by FillCrashLog().

## ◆ LogOpenTTDVersion()

char * CrashLog::LogOpenTTDVersion | ( | char * | buffer,
|  | const char * | last
| ) |  | const
| protected

Writes OpenTTD's version to the buffer.

Parameters

  buffer | The begin where to write at.
  last | The last position in the buffer to write to.

Returns
  the position of the `'\0'` character after the buffer.

Definition at line 116 of file crashlog.cpp.

References seprintf().

Referenced by FillCrashLog().

## ◆ LogOSVersion()

virtual char* CrashLog::LogOSVersion | ( | char * | buffer,
|  | const char * | last
| ) |  | const
| protectedpure virtual

Writes OS' version to the buffer.

Parameters

  buffer | The begin where to write at.
  last | The last position in the buffer to write to.

Returns
  the position of the `'\0'` character after the buffer.

Implemented in CrashLogOSX, CrashLogWindows, and CrashLogUnix.

Referenced by FillCrashLog().

## ◆ LogRecentNews()

char * CrashLog::LogRecentNews | ( | char * | buffer,
|  | const char * | last
| ) |  | const
| protected

Writes up to 32 recent news messages to the buffer, with the most recent first.

Parameters

  buffer | The begin where to write at.
  last | The last position in the buffer to write to.

Returns
  the position of the `'\0'` character after the buffer.

Definition at line 311 of file crashlog.cpp.

References _latest_news, ConvertDateToYMD(), YearMonthDay::day, YearMonthDay::month, NewsItem::prev, seprintf(), and YearMonthDay::year.

Referenced by FillCrashLog().

## ◆ LogRegisters()

char * CrashLog::LogRegisters | ( | char * | buffer,
|  | const char * | last
| ) |  | const
| protectedvirtual

Writes information about the data in the registers, if there is information about it available.

Parameters

  buffer | The begin where to write at.
  last | The last position in the buffer to write to.

Returns
  the position of the `'\0'` character after the buffer.

Reimplemented in CrashLogWindows.

Definition at line 98 of file crashlog.cpp.

Referenced by FillCrashLog().

## ◆ LogStacktrace()

virtual char* CrashLog::LogStacktrace | ( | char * | buffer,
|  | const char * | last
| ) |  | const
| protectedpure virtual

Writes the stack trace to the buffer, if there is information about it available.

Parameters

  buffer | The begin where to write at.
  last | The last position in the buffer to write to.

Returns
  the position of the `'\0'` character after the buffer.

Implemented in CrashLogUnix, CrashLogOSX, and CrashLogWindows.

Referenced by FillCrashLog().

## ◆ MakeCrashLog()

bool CrashLog::MakeCrashLog | ( |  | ) | const

Makes the crash log, writes it to a file and then subsequently tries to make a crash dump and crash savegame.

It uses DEBUG to write information like paths to the console.

Returns
  true when everything is made successfully.

Definition at line 458 of file crashlog.cpp.

Referenced by HandleCrash().

## ◆ SetErrorMessage()

void CrashLog::SetErrorMessage | ( | const char * | message | ) |
| static

Sets a message for the error message handler.

Parameters

  message | The error message of the error.

Definition at line 517 of file crashlog.cpp.

References message.

## ◆ WriteCrashDump()

int CrashLog::WriteCrashDump | ( | char * | filename,
|  | const char * | filename_last
| ) |  | const
| virtual

Write the (crash) dump to a file.

Note
  On success the filename will be filled with the full path of the crash dump file. Make sure filename is at least `MAX_PATH` big.

Parameters

  filename | Output for the filename of the written file.
  filename_last | The last position in the filename buffer.

Returns
  if less than 0, error. If 0 no dump is made, otherwise the dump was successful (not all OSes support dumping files).

Definition at line 400 of file crashlog.cpp.

## ◆ WriteCrashLog()

bool CrashLog::WriteCrashLog | ( | const char * | buffer,
|  | char * | filename,
|  | const char * | filename_last
| ) |  | const

Write the crash log to a file.

Note
  On success the filename will be filled with the full path of the crash log file. Make sure filename is at least `MAX_PATH` big.

Parameters

  buffer | The begin of the buffer to write to the disk.
  filename | Output for the filename of the written file.
  filename_last | The last position in the filename buffer.

Returns
  true when the crash log was successfully written.

Definition at line 386 of file crashlog.cpp.

References CreateFileName(), FioFCloseFile(), FioFOpenFile(), and NO_DIRECTORY.

Referenced by CrashLogOSX::MakeCrashLog().

## ◆ WriteSavegame()

bool CrashLog::WriteSavegame | ( | char * | filename,
|  | const char * | filename_last
| ) |  | const

Write the (crash) savegame to a file.

Note
  On success the filename will be filled with the full path of the crash save file. Make sure filename is at least `MAX_PATH` big.

Parameters

  filename | Output for the filename of the written file.
  filename_last | The last position in the filename buffer.

Returns
  true when the crash save was successfully made.

Definition at line 414 of file crashlog.cpp.

References _m, CreateFileName(), DFT_GAME_FILE, GamelogEmergency(), NO_DIRECTORY, SaveOrLoad(), SL_OK, and SLO_SAVE.

Referenced by CrashLogOSX::MakeCrashLog().

## ◆ WriteScreenshot()

bool CrashLog::WriteScreenshot | ( | char * | filename,
|  | const char * | filename_last
| ) |  | const

Write the (crash) screenshot to a file.

Note
  On success the filename will be filled with the full path of the screenshot. Make sure filename is at least `MAX_PATH` big.

Parameters

  filename | Output for the filename of the written file.
  filename_last | The last position in the filename buffer.

Returns
  true when the crash screenshot was successfully made.

Definition at line 440 of file crashlog.cpp.

Referenced by CrashLogOSX::MakeCrashLog().

The documentation for this class was generated from the following files:

- src/crashlog.h
- src/crashlog.cpp
- src/os/macosx/crashlog_osx.cpp
- src/os/unix/crashlog_unix.cpp
- src/os/windows/crashlog_win.cpp