OpenTTD Source: src/debug.h File Reference

OpenTTD Source 15.0-beta1

Data Structures | Macros | Functions | Variables
debug.h File Reference

Functions related to debugging. More...

`#include "cpu.h"`
`#include <chrono>`
`#include "core/format.hpp"`

Go to the source code of this file.

## Data Structures
struct | TicToc
| TicToc profiling. More...
struct | TicToc::State
| Persistent state for TicToc profiling. More...

## Macros
#define | Debug(category, level, format_string, ...) do { if ((level) == 0 || _debug_ ## category ## _level >= (level)) DebugPrint(#category, level, fmt::format(FMT_STRING(format_string) __VA_OPT__(,) __VA_ARGS__)); } while (false)
| Ouptut a line of debugging information.
#define | ShowInfo(format_string, ...) ShowInfoI(fmt::format(FMT_STRING(format_string) __VA_OPT__(,) __VA_ARGS__))

## Functions
void | DebugPrint (const char *category, int level, const std::string &message)
| Internal function for outputting the debug line.
void | DumpDebugFacilityNames (std::back_insert_iterator< std::string > &output_iterator)
| Dump the available debug facility names in the help text.
void | SetDebugString (const char *s, void(*error_func)(const std::string &))
| Set debugging levels by parsing the text in s.
std::string | GetDebugString ()
| Print out the current debug-level.
void | ShowInfoI (const std::string &str)
std::string | GetLogPrefix (bool force=false)
| Get the prefix for logs.
void | DebugSendRemoteMessages ()
| Send the queued Debug messages to either NetworkAdminConsole or IConsolePrint from the GameLoop thread to prevent concurrent accesses to both the NetworkAdmin's packet queue as well as IConsolePrint's buffers.
void | DebugReconsiderSendRemoteMessages ()
| Reconsider whether we need to send debug messages to either NetworkAdminConsole or IConsolePrint.

## Variables
int | _debug_driver_level
int | _debug_grf_level
int | _debug_map_level
int | _debug_misc_level
int | _debug_net_level
int | _debug_sprite_level
int | _debug_oldloader_level
int | _debug_yapf_level
int | _debug_fontcache_level
int | _debug_script_level
int | _debug_sl_level
int | _debug_gamelog_level
int | _debug_desync_level
int | _debug_console_level

## Detailed Description

Functions related to debugging.

Definition in file debug.h.

## Macro Definition Documentation

## ◆ Debug

#define Debug | ( |  | category,
|  |  | level,
|  |  | format_string,
|  |  | ...
| ) |  | do { if ((level) == 0 || _debug_ ## category ## _level >= (level)) DebugPrint(#category, level, fmt::format(FMT_STRING(format_string) __VA_OPT__(,) __VA_ARGS__)); } while (false)

Ouptut a line of debugging information.

Parameters

  category | The category of debug information.
  level | The maximum debug level this message should be shown at. When the debug level for this category is set lower, then the message will not be shown.
  format_string | The formatting string of the message.

Definition at line 37 of file debug.h.

## ◆ ShowInfo

#define ShowInfo | ( |  | format_string,
|  |  | ...
| ) |  | ShowInfoI(fmt::format(FMT_STRING(format_string) __VA_OPT__(,) __VA_ARGS__))

Definition at line 96 of file debug.h.

## Function Documentation

## ◆ DebugPrint()

void DebugPrint | ( | const char * | category,
|  | int | level,
|  | const std::string & | message
| ) |  |

Internal function for outputting the debug line.

Parameters

  level | Debug category.
  message | The message to output.

Definition at line 109 of file debug.cpp.

References _debug_remote_console, _debug_remote_console_mutex, _debug_remote_console_queue, AUTOSAVE_DIR, FioFOpenFile(), GetLogPrefix(), and lock.

## ◆ DebugReconsiderSendRemoteMessages()

void DebugReconsiderSendRemoteMessages | ( |  | ) |

Reconsider whether we need to send debug messages to either NetworkAdminConsole or IConsolePrint.

The former is when they have enabled console handling whereas the latter depends on the gui.developer setting's value.

This is to be called from the GameLoop thread.

Definition at line 264 of file debug.cpp.

References _debug_remote_console, _settings_client, ADMIN_FREQUENCY_AUTOMATIC, ADMIN_UPDATE_CONSOLE, GUISettings::developer, ClientSettings::gui, and ServerNetworkAdminSocketHandler::IterateActive().

Referenced by LoadFromConfig(), ServerNetworkAdminSocketHandler::Receive_ADMIN_UPDATE_FREQUENCY(), and ServerNetworkAdminSocketHandler::~ServerNetworkAdminSocketHandler().

## ◆ DebugSendRemoteMessages()

void DebugSendRemoteMessages | ( |  | ) |

Send the queued Debug messages to either NetworkAdminConsole or IConsolePrint from the GameLoop thread to prevent concurrent accesses to both the NetworkAdmin's packet queue as well as IConsolePrint's buffers.

This is to be called from the GameLoop thread.

Definition at line 240 of file debug.cpp.

References _debug_remote_console, _debug_remote_console_mutex, _debug_remote_console_queue, _debug_remote_console_queue_spare, _settings_client, CC_DEBUG, GUISettings::developer, ClientSettings::gui, IConsolePrint(), lock, and NetworkAdminConsole().

## ◆ DumpDebugFacilityNames()

void DumpDebugFacilityNames | ( | std::back_insert_iterator< std::string > & | output_iterator | ) |

Dump the available debug facility names in the help text.

Parameters

  output_iterator | The iterator to write the string to.

Definition at line 87 of file debug.cpp.

Referenced by ShowHelp().

## ◆ GetDebugString()

std::string GetDebugString | ( |  | ) |

Print out the current debug-level.

Just return a string with the values of all the debug categories.

Returns
  string with debug-levels

Definition at line 206 of file debug.cpp.

## ◆ GetLogPrefix()

std::string GetLogPrefix | ( | bool | force | ) |

Get the prefix for logs.

If show_date_in_logs or `force` is enabled it returns the date, otherwise it returns an empty string.

Returns
  the prefix for logs.

Definition at line 224 of file debug.cpp.

References _settings_client, ClientSettings::gui, and GUISettings::show_date_in_logs.

Referenced by DebugPrint(), and IConsolePrint().

## ◆ SetDebugString()

void SetDebugString | ( | const char * | s,
|  | void(*)(const std::string &) | error_func
| ) |  |

Set debugging levels by parsing the text in s.

For setting individual levels a string like `"net=3,grf=6"` should be used. If the string starts with a number, the number is used as global debugging level.

Parameters

  s | Text describing the wanted debugging levels.
  error_func | The function to call if a parse error occurs.

Definition at line 143 of file debug.cpp.

Referenced by openttd_main().

## ◆ ShowInfoI()

void ShowInfoI | ( | const std::string & | str | ) |

Definition at line 187 of file unix.cpp.

## Variable Documentation

## ◆ _debug_console_level

int _debug_console_level
| extern

Definition at line 51 of file debug.cpp.

## ◆ _debug_desync_level

int _debug_desync_level
| extern

Definition at line 50 of file debug.cpp.

## ◆ _debug_driver_level

int _debug_driver_level
| extern

Definition at line 38 of file debug.cpp.

## ◆ _debug_fontcache_level

int _debug_fontcache_level
| extern

Definition at line 46 of file debug.cpp.

## ◆ _debug_gamelog_level

int _debug_gamelog_level
| extern

Definition at line 49 of file debug.cpp.

## ◆ _debug_grf_level

int _debug_grf_level
| extern

Definition at line 39 of file debug.cpp.

## ◆ _debug_map_level

int _debug_map_level
| extern

Definition at line 40 of file debug.cpp.

## ◆ _debug_misc_level

int _debug_misc_level
| extern

Definition at line 41 of file debug.cpp.

## ◆ _debug_net_level

int _debug_net_level
| extern

Definition at line 42 of file debug.cpp.

## ◆ _debug_oldloader_level

int _debug_oldloader_level
| extern

Definition at line 44 of file debug.cpp.

## ◆ _debug_script_level

int _debug_script_level
| extern

Definition at line 47 of file debug.cpp.

## ◆ _debug_sl_level

int _debug_sl_level
| extern

Definition at line 48 of file debug.cpp.

## ◆ _debug_sprite_level

int _debug_sprite_level
| extern

Definition at line 43 of file debug.cpp.

## ◆ _debug_yapf_level

int _debug_yapf_level
| extern

Definition at line 45 of file debug.cpp.