iPXE
Data Structures | Defines | 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...

Defines

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

Functions

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

Define Documentation

#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.

Referenced by dbg_autocolourise(), and dbg_decolourise().

#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 ( GPL2_OR_LATER_OR_UBDL  )
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.

References byte, bytes, data, dbg_printf(), and isprint().

Referenced by dbg_hex_dump_da().

                                                                           {
        const uint8_t *bytes = data;
        unsigned int i;
        uint8_t byte;

        dbg_printf ( "%08lx :", ( dispaddr + offset ) );
        for ( i = offset ; i < ( offset + 16 ) ; i++ ) {
                if ( i >= len ) {
                        dbg_printf ( "   " );
                        continue;
                }
                dbg_printf ( "%c%02x",
                             ( ( ( i % 16 ) == 8 ) ? '-' : ' ' ), bytes[i] );
        }
        dbg_printf ( " : " );
        for ( i = offset ; i < ( offset + 16 ) ; i++ ) {
                if ( i >= len ) {
                        dbg_printf ( " " );
                        continue;
                }
                byte = bytes[i];
                dbg_printf ( "%c", ( isprint ( byte ) ? byte : '.' ) );
        }
        dbg_printf ( "\n" );
}
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.

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

Referenced by dbg_autocolourise().

                                                   {
        static struct autocolour acs[ DBGCOL_MAX - DBGCOL_MIN + 1 ];
        static unsigned long use;
        unsigned int i;
        unsigned int oldest;
        unsigned int oldest_last_used;

        /* Increment usage iteration counter */
        use++;

        /* Scan through list for a currently assigned colour */
        for ( i = 0 ; i < ( sizeof ( acs ) / sizeof ( acs[0] ) ) ; i++ ) {
                if ( acs[i].stream == stream ) {
                        acs[i].last_used = use;
                        return i;
                }
        }

        /* No colour found; evict the oldest from the list */
        oldest = 0;
        oldest_last_used = use;
        for ( i = 0 ; i < ( sizeof ( acs ) / sizeof ( acs[0] ) ) ; i++ ) {
                if ( acs[i].last_used < oldest_last_used ) {
                        oldest_last_used = acs[i].last_used;
                        oldest = i;
                }
        }
        acs[oldest].stream = stream;
        acs[oldest].last_used = use;
        return oldest;
}