wavelength 1.0.0
Loading...
Searching...
No Matches
debug.h File Reference

Go to the source code of this file.

Macros

#define DEBUG_ANSI_RESET   "\033[0m"
 Report output of the DMAdebug packet checker.
#define DEBUG_ANSI_BOLD   "\033[1m"
#define DEBUG_ANSI_YELLOW   "\033[33m"
#define DEBUG_ANSI_GREEN   "\033[32m"
#define DEBUG_ANSI_MAGENTA   "\033[35m"
#define DEBUG_ANSI_CYAN   "\033[36m"
#define DEBUG_ANSI_WHITE   "\033[37m"
#define DEBUG_ANSI_ON_GREEN   "\033[42m\033[30m"
#define DEBUG_ANSI_ON_MAGENTA   "\033[45m\033[30m"
#define DEBUG_ANSI_ON_CYAN   "\033[46m\033[30m"
#define DEBUG_ANSI_ON_WHITE   "\033[47m\033[30m"
#define DEBUG_ANSI_ON_RED   "\033[41m\033[30m"
#define DEBUG_ANSI_ALERT   "\033[41m\033[30m\033[5m"
#define DEBUG_ANSI_CAUTION   "\033[43m\033[30m\033[5m"
#define DEBUG_ABORT(line, message)
 Print a source line and a message, and end the program.

Enumerations

enum  { DEBUG_ERROR = 2 , DEBUG_FATAL = 4 , DEBUG_WARNING = 8 }
 Severity of a message, and the flags DEBUG_message() and DEBUG_print() return. More...
enum  { DEBUG_FIELD_COLUMN = 0 , DEBUG_FIELD_INLINE = 1 , DEBUG_FIELD_LINE = 2 }
 How DEBUG_addField() places a field in a line. More...
enum  { DEBUG_COLUMN_WIDTH = 24 }
 Width of the first column of a report line. More...
enum  { DEBUG_MAX_WARNING_MASKS = 100 }
 Capacity of the warning numbers the -W option can mask. More...
enum  { DEBUG_SCRATCH_SIZE = 1024 }
 Capacity of g_szDebugScratch. More...

Functions

void DEBUG_init (const char *options)
 Configure the module and allocate the output buffer.
void DEBUG_reset (void)
 Empty the output buffer and the pending message line.
int DEBUG_print (const char *text)
 Append a line to the output buffer.
int DEBUG_message (int number, int severity, const char *text)
 Report an error or a warning.
void DEBUG_addField (int placement, char *line, char *format,...)
 Format a field and add it to a report line.

Variables

char g_szDebugScratch [DEBUG_SCRATCH_SIZE]
 Text the checker formats a message into before reporting it.

Macro Definition Documentation

◆ DEBUG_ANSI_RESET

#define DEBUG_ANSI_RESET   "\033[0m"

Report output of the DMAdebug packet checker.

The messages of the image ("DMAdebug - too many errors, exiting." and "LOGIC ERROR in DEBUG_addField") establish that the checker is vendored into it. The routine names other than DEBUG_addField() are inferred.

Reports are built a field at a time into a line with DEBUG_addField() and then appended to the output buffer with DEBUG_print(). Messages that the checker raises go through DEBUG_message(). DEBUG_message() counts them and returns DEBUG_FATAL once a limit is passed. Terminal escape sequences the reports are coloured with.

◆ DEBUG_ANSI_BOLD

#define DEBUG_ANSI_BOLD   "\033[1m"

◆ DEBUG_ANSI_YELLOW

#define DEBUG_ANSI_YELLOW   "\033[33m"

◆ DEBUG_ANSI_GREEN

#define DEBUG_ANSI_GREEN   "\033[32m"

◆ DEBUG_ANSI_MAGENTA

#define DEBUG_ANSI_MAGENTA   "\033[35m"

◆ DEBUG_ANSI_CYAN

#define DEBUG_ANSI_CYAN   "\033[36m"

◆ DEBUG_ANSI_WHITE

#define DEBUG_ANSI_WHITE   "\033[37m"

◆ DEBUG_ANSI_ON_GREEN

#define DEBUG_ANSI_ON_GREEN   "\033[42m\033[30m"

◆ DEBUG_ANSI_ON_MAGENTA

#define DEBUG_ANSI_ON_MAGENTA   "\033[45m\033[30m"

◆ DEBUG_ANSI_ON_CYAN

#define DEBUG_ANSI_ON_CYAN   "\033[46m\033[30m"

◆ DEBUG_ANSI_ON_WHITE

#define DEBUG_ANSI_ON_WHITE   "\033[47m\033[30m"

◆ DEBUG_ANSI_ON_RED

#define DEBUG_ANSI_ON_RED   "\033[41m\033[30m"

◆ DEBUG_ANSI_ALERT

#define DEBUG_ANSI_ALERT   "\033[41m\033[30m\033[5m"

◆ DEBUG_ANSI_CAUTION

#define DEBUG_ANSI_CAUTION   "\033[43m\033[30m\033[5m"

◆ DEBUG_ABORT

#define DEBUG_ABORT ( line,
message )
Value:
do { \
printf("Line %d: ", line); \
printf(message); \
printf("\n"); \
exit(1); \
} while (0)

Print a source line and a message, and end the program.

Parameters
lineThe line of the original source file the message names.
messageA format with no conversions.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Severity of a message, and the flags DEBUG_message() and DEBUG_print() return.

Enumerator
DEBUG_ERROR 

A message counted as an error.

DEBUG_FATAL 

Too many messages, or no room for the output.

DEBUG_WARNING 

A message counted as a warning, unless warnings are errors.

◆ anonymous enum

anonymous enum

How DEBUG_addField() places a field in a line.

Enumerator
DEBUG_FIELD_COLUMN 

Append, padded to a 24-character column.

DEBUG_FIELD_INLINE 

Append after a space, wrapping a line longer than 100.

DEBUG_FIELD_LINE 

Start a new line indented to the first column.

◆ anonymous enum

anonymous enum

Width of the first column of a report line.

Enumerator
DEBUG_COLUMN_WIDTH 

◆ anonymous enum

anonymous enum

Capacity of the warning numbers the -W option can mask.

Enumerator
DEBUG_MAX_WARNING_MASKS 

◆ anonymous enum

anonymous enum

Capacity of g_szDebugScratch.

Enumerator
DEBUG_SCRATCH_SIZE 

Function Documentation

◆ DEBUG_init()

void DEBUG_init ( const char * options)

Configure the module and allocate the output buffer.

The options are found anywhere in the text: -w masks every warning, -E followed by a number sets how many errors end the program, -W followed by a number masks that warning, -We counts warnings as errors, -S sends messages to the output buffer, -B followed by a number sets the buffer size in kilobytes, and -noscroll stops the buffer from discarding old lines when it fills.

Parameters
optionsThe options, or null for the defaults.
Ghidra address:
NTSC-U/C: 0x002a0920
Ghidra address:
PAL: 0x002aa890

◆ DEBUG_reset()

void DEBUG_reset ( void )

Empty the output buffer and the pending message line.

Ghidra address:
NTSC-U/C: 0x002a0d40
Ghidra address:
PAL: 0x002aacb0

◆ DEBUG_print()

int DEBUG_print ( const char * text)

Append a line to the output buffer.

When the line does not fit, the oldest 20 lines are discarded, unless -noscroll was given.

Parameters
textThe line, without its newline.
Returns
0, or DEBUG_FATAL when the buffer is full and may not scroll.
Ghidra address:
NTSC-U/C: 0x002a0d88
Ghidra address:
PAL: 0x002aacf8

◆ DEBUG_message()

int DEBUG_message ( int number,
int severity,
const char * text )

Report an error or a warning.

A warning whose number -W masked, or any warning after -w, is not reported.

Parameters
numberThe message number.
severityDEBUG_WARNING, or another value for an error.
textThe message.
Returns
severity, with DEBUG_FATAL added when the limit of messages is passed, and with the result of DEBUG_print() added after -S. 0 for a masked warning.
Ghidra address:
NTSC-U/C: 0x002a0f48
Ghidra address:
PAL: 0x002aaeb8

◆ DEBUG_addField()

void DEBUG_addField ( int placement,
char * line,
char * format,
... )

Format a field and add it to a report line.

Each conversion of the format reads one int argument. The routine writes to the format while it formats the field and restores it afterwards. The format must not be read-only.

Parameters
placementDEBUG_FIELD_COLUMN, DEBUG_FIELD_INLINE, or DEBUG_FIELD_LINE.
lineThe line to add the field to.
formatThe field format.
Ghidra address:
NTSC-U/C: 0x002a1200
Ghidra address:
PAL: 0x002ab170

Variable Documentation

◆ g_szDebugScratch

char g_szDebugScratch[DEBUG_SCRATCH_SIZE]
extern

Text the checker formats a message into before reporting it.

Ghidra address:
NTSC-U/C: 0x00518718