Data Structures | Defines | Functions | Variables

# debug.cpp File Reference

Handling of printing debug messages. More...

`#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 <time.h>`
`#include "network/network_admin.h"`

Go to the source code of this file.

## Data Structures
struct | DebugLevel
## Defines
#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.
static void | debug_print (const char *dbg, const char *buf)
| Internal function for outputting the debug line.
void CDECL | debug (const char *dbg, const char *format,...)
| Output a debug line.
void | SetDebugString (const char *s)
| Set debugging levels by parsing the text in s.
const char * | GetDebugString ()
| Print out the current debug-level.
const char * | GetLogPrefix ()
| Get the prefix for logs; if show_date_in_logs is enabled it returns the date, otherwise it returns nothing.
## Variables
SOCKET | _debug_socket = INVALID_SOCKET
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_freetype_level
int | _debug_script_level
int | _debug_sl_level
int | _debug_gamelog_level
int | _debug_desync_level
int | _debug_console_level
uint32 | _realtime_tick = 0
| The real time in the game.
static const DebugLevel | debug_level []

## Detailed Description

Handling of printing debug messages.

Definition in file debug.cpp.

## Function Documentation

void CDECL debug | ( | const char * | dbg,
|  | const char * | format,
|  |  | ... |
| ) |  |  |

Output a debug line.

Note:
  Do not call directly, use the DEBUG macro instead.

Parameters:

  | dbg | Debug category.
  | format | Text string a la printf, with optional arguments.

Definition at line 158 of file debug.cpp.

References debug_print(), and lengthof.

static void debug_print | ( | const char * | dbg,
|  | const char * | buf |
| ) |  |  | `[static]`

Internal function for outputting the debug line.

Parameters:

  | dbg | Debug category.
  | buf | Text line to output.

Definition at line 108 of file debug.cpp.

References AUTOSAVE_DIR, FioFOpenFile(), GetLogPrefix(), IConsoleDebug(), lastof, lengthof, NetworkAdminConsole(), OTTD2FS(), and seprintf().

Referenced by debug().

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 82 of file debug.cpp.

References endof, and strecpy().

Referenced by ShowHelp().

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 231 of file debug.cpp.

References endof, lastof, and strecat().

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 NULL

Definition at line 254 of file debug.cpp.

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

Referenced by debug_print(), and IConsolePrint().

void SetDebugString | ( | const char * | s | ) |

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.

Definition at line 177 of file debug.cpp.

References endof, and ShowInfoF().

Referenced by openttd_main().

## Variable Documentation

uint32 _realtime_tick = 0

The real time in the game.

Definition at line 46 of file debug.cpp.

Referenced by GRFFileScanner::AddFile(), ClientNetworkGameSocketHandler::CheckConnection(), ClientNetworkContentSocketHandler::Connect(), DrawDirtyBlocks(), HandleMouseEvents(), NetworkGameSocketHandler::HandlePacket(), VideoDriver_Win32::MainLoop(), VideoDriver_SDL::MainLoop(), VideoDriver_Dedicated::MainLoop(), NetworkAddChatMessage(), NetworkChatMessageLoop(), NetworkServer_Tick(), ClientNetworkGameSocketHandler::Receive_SERVER_MAP_DONE(), ServerNetworkAdminSocketHandler::Send(), ClientNetworkContentSocketHandler::SendReceive(), and ServerNetworkAdminSocketHandler::ServerNetworkAdminSocketHandler().

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(freetype),
      DEBUG_LEVEL(script),
      DEBUG_LEVEL(sl),
      DEBUG_LEVEL(gamelog),
      DEBUG_LEVEL(desync),
      DEBUG_LEVEL(console),

      }

Definition at line 54 of file debug.cpp.