# CrashLog Class Reference

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.
bool | WriteCrashLog (const char *buffer, char *filename, const char *filename_last) const
| Write the crash log to a file.
virtual int | WriteCrashDump (char *filename, const char *filename_last) const
| Write the (crash) dump to a file.
bool | WriteSavegame (char *filename, const char *filename_last) const
| Write the (crash) savegame to a file.
bool | WriteScreenshot (char *filename, const char *filename_last) const
| Write the (crash) screenshot to a file.
bool | MakeCrashLog () const
| Makes the crash log, writes it to a file and then subsequently tries to make a crash dump and crash savegame.

## 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.
static void | SetErrorMessage (const char *message)
| Sets a message for the error message handler.
static void | AfterCrashLogCleanup ()
| Try to close the sound/video stuff so it doesn't keep lingering around incorrect video states or so, e.g.

## Protected Member Functions

virtual char * | LogOSVersion (char *buffer, const char *last) const =0
| Writes OS' version to the buffer.
virtual char * | LogCompiler (char *buffer, const char *last) const
| Writes compiler (and its version, if available) to the buffer.
virtual char * | LogError (char *buffer, const char *last, const char *message) const =0
| Writes actually encountered error to the buffer.
virtual char * | LogStacktrace (char *buffer, const char *last) const =0
| Writes the stack trace to the buffer, if there is information about it available.
virtual char * | LogRegisters (char *buffer, const char *last) const
| Writes information about the data in the registers, if there is information about it available.
virtual char * | LogModules (char *buffer, const char *last) const
| Writes the dynamically linked libaries/modules to the buffer, if there is information about it available.
char * | LogOpenTTDVersion (char *buffer, const char *last) const
| Writes OpenTTD's version to the buffer.
char * | LogConfiguration (char *buffer, const char *last) const
| Writes the (important) configuration settings to the buffer.
char * | LogLibraries (char *buffer, const char *last) const
| Writes information (versions) of the used libraries.
char * | LogGamelog (char *buffer, const char *last) const
| Writes the gamelog data to the buffer.

## Static Private Member Functions

static void | GamelogFillCrashLog (const char *s)
| Helper function for printing the gamelog.

## Static Private Attributes

static const char * | message = NULL
| Pointer to the error message.
static char * | gamelog_buffer = NULL
| Temporary 'local' location of the buffer.
static const char * | gamelog_last = NULL
| Temporary 'local' location of the end of the buffer.

## Detailed Description

Helper class for creating crash logs.

Definition at line 18 of file crashlog.h.

## Constructor & Destructor Documentation

virtual CrashLog::~CrashLog | ( |  | ) | `[inline, virtual]`

Stub destructor to silence some compilers.

Definition at line 123 of file crashlog.h.

## Member Function Documentation

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 381 of file crashlog.cpp.

Referenced by HandleCrash().

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 `'` ' character after the buffer.

Definition at line 248 of file crashlog.cpp.

References _date, ConvertDateToYMD(), YearMonthDay::day, LogCompiler(), LogConfiguration(), LogError(), LogGamelog(), LogLibraries(), LogModules(), LogOpenTTDVersion(), LogOSVersion(), LogRegisters(), LogStacktrace(), message, YearMonthDay::month, seprintf(), and YearMonthDay::year.

Referenced by CrashLogOSX::MakeCrashLog(), and MakeCrashLog().

void CrashLog::GamelogFillCrashLog | ( | const char * | s | ) | `[static, private]`

Helper function for printing the gamelog.

Parameters:

  | s | the string to print.

Definition at line 235 of file crashlog.cpp.

References gamelog_buffer, gamelog_last, and seprintf().

Referenced by LogGamelog().

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 249 of file crashlog_osx.cpp.

References _signals_to_handle, endof, and HandleCrash().

char * CrashLog::LogCompiler | ( | char * | buffer,
|  | const char * | last |
| ) |  |  | const`[protected, virtual]`

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 `'` ' character after the buffer.

Definition at line 39 of file crashlog.cpp.

References seprintf().

Referenced by FillCrashLog().

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 `'` ' character after the buffer.

Definition at line 107 of file crashlog.cpp.

References _dynlang, _network_server, _networking, DynamicLanguages::curr_file, BlitterFactoryBase::GetCurrentBlitter(), ScriptFileInfo::GetName(), BaseMedia< SoundsSet >::GetUsedSet(), BaseMedia< MusicSet >::GetUsedSet(), BaseMedia< GraphicsSet >::GetUsedSet(), ScriptFileInfo::GetVersion(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >::index, BaseSet< T, Tnum_files, Tsubdir >::name, seprintf(), and StrEmpty().

Referenced by FillCrashLog().

virtual char* CrashLog::LogError | ( | char * | buffer,
|  | const char * | last,
|  | const char * | message |
| ) |  |  | const`[protected, pure 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 NULL.

Returns:
  the position of the `'` ' character after the buffer.

Implemented in CrashLogOSX, CrashLogUnix, and CrashLogWindows.

Referenced by FillCrashLog().

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 `'` ' character after the buffer.

Definition at line 240 of file crashlog.cpp.

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

Referenced by FillCrashLog().

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 `'` ' character after the buffer.

Definition at line 177 of file crashlog.cpp.

References seprintf().

Referenced by FillCrashLog().

char * CrashLog::LogModules | ( | char * | buffer,
|  | const char * | last |
| ) |  |  | const`[protected, virtual]`

Writes the dynamically linked libaries/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 `'` ' character after the buffer.

Reimplemented in CrashLogWindows.

Definition at line 69 of file crashlog.cpp.

Referenced by FillCrashLog().

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 `'` ' character after the buffer.

Definition at line 75 of file crashlog.cpp.

References seprintf().

Referenced by FillCrashLog().

virtual char* CrashLog::LogOSVersion | ( | char * | buffer,
|  | const char * | last |
| ) |  |  | const`[protected, pure 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 `'` ' character after the buffer.

Implemented in CrashLogOSX, CrashLogUnix, and CrashLogWindows.

Referenced by FillCrashLog().

char * CrashLog::LogRegisters | ( | char * | buffer,
|  | const char * | last |
| ) |  |  | const`[protected, virtual]`

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 `'` ' character after the buffer.

Reimplemented in CrashLogWindows.

Definition at line 63 of file crashlog.cpp.

Referenced by FillCrashLog().

virtual char* CrashLog::LogStacktrace | ( | char * | buffer,
|  | const char * | last |
| ) |  |  | const`[protected, pure 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 `'` ' character after the buffer.

Implemented in CrashLogOSX, CrashLogUnix, and CrashLogWindows.

Referenced by FillCrashLog().

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 321 of file crashlog.cpp.

References FillCrashLog(), lastof, WriteCrashDump(), WriteCrashLog(), WriteSavegame(), and WriteScreenshot().

Referenced by HandleCrash().

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 376 of file crashlog.cpp.

References message.

Referenced by error().

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 successfull (not all OSes support dumping files).

Definition at line 287 of file crashlog.cpp.

Referenced by MakeCrashLog().

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 273 of file crashlog.cpp.

References _personal_dir, FioFCloseFile(), FioFOpenFile(), NO_DIRECTORY, and seprintf().

Referenced by CrashLogOSX::MakeCrashLog(), and MakeCrashLog().

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 293 of file crashlog.cpp.

References _m, _personal_dir, GamelogEmergency(), NO_DIRECTORY, SaveOrLoad(), seprintf(), and SL_OK.

Referenced by CrashLogOSX::MakeCrashLog(), and MakeCrashLog().

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 311 of file crashlog.cpp.

References MakeScreenshot(), SC_RAW, and strecpy().

Referenced by CrashLogOSX::MakeCrashLog(), and MakeCrashLog().

## Field Documentation

char * CrashLog::gamelog_buffer = NULL`[static, private]`

Temporary 'local' location of the buffer.

Definition at line 24 of file crashlog.h.

Referenced by GamelogFillCrashLog(), and LogGamelog().

const char * CrashLog::gamelog_last = NULL`[static, private]`

Temporary 'local' location of the end of the buffer.

Definition at line 27 of file crashlog.h.

Referenced by GamelogFillCrashLog(), and LogGamelog().

const char * CrashLog::message = NULL`[static, private]`

Pointer to the error message.

Definition at line 21 of file crashlog.h.

Referenced by CrashLogOSX::DisplayCrashDialog(), FillCrashLog(), and SetErrorMessage().

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