iPXE
Data Structures | Macros | Functions
debug.c File Reference
#include <stdio.h>
#include <stdint.h>
#include <stdarg.h>
#include <ctype.h>
#include <ipxe/console.h>

Go to the source code of this file.

Data Structures

struct  autocolour
 A colour assigned to an autocolourised debug message stream. More...
 

Macros

#define DBGCOL_MIN   31
 Base message stream colour. More...
 
#define DBGCOL_MAX   ( DBGCOL_MIN + 6 - 1 )
 Maximum number of separately coloured message streams. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
void dbg_printf (const char *fmt,...)
 Print debug message. More...
 
void dbg_pause (void)
 Pause until a key is pressed. More...
 
void dbg_more (void)
 Indicate more data to follow and pause until a key is pressed. More...
 
static void dbg_hex_dump_da_row (unsigned long dispaddr, const void *data, unsigned long len, unsigned int offset)
 Print row of a hex dump with specified display address. More...
 
void dbg_hex_dump_da (unsigned long dispaddr, const void *data, unsigned long len)
 Print hex dump with specified display address. More...
 
static int dbg_autocolour (unsigned long stream)
 Choose colour index for debug autocolourisation. More...
 
void dbg_autocolourise (unsigned long stream)
 Select automatic colour for debug messages. More...
 
void dbg_decolourise (void)
 Revert to normal colour. More...
 

Macro Definition Documentation

◆ DBGCOL_MIN

#define DBGCOL_MIN   31

Base message stream colour.

We default to using 31 (red foreground) as the base colour.

Definition at line 131 of file debug.c.

◆ DBGCOL_MAX

#define DBGCOL_MAX   ( DBGCOL_MIN + 6 - 1 )

Maximum number of separately coloured message streams.

Six is the realistic maximum; there are 8 basic ANSI colours, one of which will be the terminal default and one of which will be invisible on the terminal because it matches the background colour.

Definition at line 142 of file debug.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ dbg_hex_dump_da_row()

static void dbg_hex_dump_da_row ( unsigned long  dispaddr,
const void *  data,
unsigned long  len,
unsigned int  offset 
)
static

Print row of a hex dump with specified display address.

Parameters
dispaddrDisplay address
dataData to print
lenLength of data
offsetStarting offset within data

Definition at line 82 of file debug.c.

83  {
84  const uint8_t *bytes = data;
85  unsigned int i;
86  uint8_t byte;
87 
88  dbg_printf ( "%08lx :", ( dispaddr + offset ) );
89  for ( i = offset ; i < ( offset + 16 ) ; i++ ) {
90  if ( i >= len ) {
91  dbg_printf ( " " );
92  continue;
93  }
94  dbg_printf ( "%c%02x",
95  ( ( ( i % 16 ) == 8 ) ? '-' : ' ' ), bytes[i] );
96  }
97  dbg_printf ( " : " );
98  for ( i = offset ; i < ( offset + 16 ) ; i++ ) {
99  if ( i >= len ) {
100  dbg_printf ( " " );
101  continue;
102  }
103  byte = bytes[i];
104  dbg_printf ( "%c", ( isprint ( byte ) ? byte : '.' ) );
105  }
106  dbg_printf ( "\n" );
107 }
static int isprint(int character)
Check if character is printable.
Definition: ctype.h:97
static userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259
unsigned char uint8_t
Definition: stdint.h:10
unsigned char byte
Definition: smc9000.h:38
uint32_t len
Length.
Definition: ena.h:14
uint8_t data[48]
Additional event data.
Definition: ena.h:22
uint8_t bytes[64]
Definition: ib_mad.h:16
void dbg_printf(const char *fmt,...)
Print debug message.
Definition: debug.c:38

References bytes, data, dbg_printf(), isprint(), len, and offset.

Referenced by dbg_hex_dump_da().

◆ dbg_autocolour()

static int dbg_autocolour ( unsigned long  stream)
static

Choose colour index for debug autocolourisation.

Parameters
streamMessage stream ID
Return values
colourColour ID

Definition at line 159 of file debug.c.

159  {
160  static struct autocolour acs[ DBGCOL_MAX - DBGCOL_MIN + 1 ];
161  static unsigned long use;
162  unsigned int i;
163  unsigned int oldest;
164  unsigned int oldest_last_used;
165 
166  /* Increment usage iteration counter */
167  use++;
168 
169  /* Scan through list for a currently assigned colour */
170  for ( i = 0 ; i < ( sizeof ( acs ) / sizeof ( acs[0] ) ) ; i++ ) {
171  if ( acs[i].stream == stream ) {
172  acs[i].last_used = use;
173  return i;
174  }
175  }
176 
177  /* No colour found; evict the oldest from the list */
178  oldest = 0;
179  oldest_last_used = use;
180  for ( i = 0 ; i < ( sizeof ( acs ) / sizeof ( acs[0] ) ) ; i++ ) {
181  if ( acs[i].last_used < oldest_last_used ) {
182  oldest_last_used = acs[i].last_used;
183  oldest = i;
184  }
185  }
186  acs[oldest].stream = stream;
187  acs[oldest].last_used = use;
188  return oldest;
189 }
#define DBGCOL_MIN
Base message stream colour.
Definition: debug.c:131
#define DBGCOL_MAX
Maximum number of separately coloured message streams.
Definition: debug.c:142
unsigned long last_used
Last recorded usage.
Definition: debug.c:150
A colour assigned to an autocolourised debug message stream.
Definition: debug.c:146
unsigned long stream
Message stream ID.
Definition: debug.c:148

References DBGCOL_MAX, DBGCOL_MIN, autocolour::last_used, and autocolour::stream.

Referenced by dbg_autocolourise().