OpenTTD Source: src/debug.cpp File Reference

OpenTTD Source 13.2.1

Data Structures | Macros | Functions | Variables
debug.cpp File Reference
`#include "stdafx.h"`
`#include <stdarg.h>`
`#include "console_func.h"`
`#include "debug.h"`
`#include "string_func.h"`
`#include "fileio_func.h"`
`#include "settings_type.h"`
`#include <mutex>`
`#include "walltime_func.h"`
`#include "network/network_admin.h"`
`#include "safeguards.h"`

Go to the source code of this file.

## Data Structures
struct | QueuedDebugItem
| Element in the queue of debug messages that have to be passed to either NetworkAdminConsole or IConsolePrint. More...
struct | DebugLevel

## Macros
#define | DEBUG_LEVEL(x) { #x, &_debug_##x##_level }

## Functions
char * | DumpDebugFacilityNames (char *buf, char *last)
| Dump the available debug facility names in the help text. More...
void | DebugPrint (const char *level, const std::string &message)
| Internal function for outputting the debug line. More...
void | SetDebugString (const char *s, void(*error_func)(const char *))
| Set debugging levels by parsing the text in s. More...
const char * | GetDebugString ()
| Print out the current debug-level. More...
const char * | GetLogPrefix ()
| Get the prefix for logs; if show_date_in_logs is enabled it returns the date, otherwise it returns nothing. More...
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. More...
void | DebugReconsiderSendRemoteMessages ()
| Reconsider whether we need to send debug messages to either NetworkAdminConsole or IConsolePrint. More...

## Variables
SOCKET | _debug_socket = INVALID_SOCKET
std::atomic< bool > | _debug_remote_console
| Whether we need to send data to either NetworkAdminConsole or IConsolePrint.
std::mutex | _debug_remote_console_mutex
| Mutex to guard the queue of debug messages for either NetworkAdminConsole or IConsolePrint.
std::vector< QueuedDebugItem > | _debug_remote_console_queue
| Queue for debug messages to be passed to NetworkAdminConsole or IConsolePrint.
std::vector< QueuedDebugItem > | _debug_remote_console_queue_spare
| Spare queue to swap with _debug_remote_console_queue.
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_npf_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
static const DebugLevel | debug_level []

## Detailed Description

Handling of printing debug messages.

Definition in file debug.cpp.

## Function Documentation

## ◆ DebugPrint()

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

Internal function for outputting the debug line.

Parameters

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

Definition at line 117 of file debug.cpp.

## ◆ 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 294 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 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 270 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()

char* DumpDebugFacilityNames | ( | char * | buf,
|  | char * | last
| ) |  |

Dump the available debug facility names in the help text.

Parameters

  buf | Start address for storing the output.
  last | Last valid address for storing the output.

Returns
  Next free position in the output.

Definition at line 93 of file debug.cpp.

## ◆ GetDebugString()

const char* 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 229 of file debug.cpp.

## ◆ GetLogPrefix()

const char* GetLogPrefix | ( |  | ) |

Get the prefix for logs; if show_date_in_logs is enabled it returns the date, otherwise it returns nothing.

Returns
  the prefix for logs (do not free), never nullptr

Definition at line 252 of file debug.cpp.

References _settings_client, Time< T >::Format(), ClientSettings::gui, lastof, and GUISettings::show_date_in_logs.

## ◆ SetDebugString()

void SetDebugString | ( | const char * | s,
|  | void(*)(const char *) | 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 164 of file debug.cpp.

## Variable Documentation

## ◆ debug_level

const DebugLevel debug_level[]
| static

Initial value:
= {
DEBUG_LEVEL(driver),
DEBUG_LEVEL(grf),
DEBUG_LEVEL(map),
DEBUG_LEVEL(misc),
DEBUG_LEVEL(net),
DEBUG_LEVEL(sprite),
DEBUG_LEVEL(oldloader),
DEBUG_LEVEL(npf),
DEBUG_LEVEL(yapf),
DEBUG_LEVEL(fontcache),
DEBUG_LEVEL(script),
DEBUG_LEVEL(sl),
DEBUG_LEVEL(gamelog),
DEBUG_LEVEL(desync),
DEBUG_LEVEL(console),
}

Definition at line 65 of file debug.cpp.