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)
 
 FILE_SECBOOT (PERMITTED)
 
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 132 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 143 of file debug.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED  )

◆ 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 83 of file debug.c.

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

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 160 of file debug.c.

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

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

Referenced by dbg_autocolourise().